SharePoint DataFormWebPart 通过Caml和xslt聚合内容

以下是一个例子,SPDataSource用于查询内容,DatasourceMode属性指定查询范围(网站集,网站,列表),SelectCommand是Caml查询;Xsl展示内容,下面列子是用table展示。

<WebPartPages:DataFormWebPart runat="server" EnableOriginalValue="False" ViewFlag="8" ViewContentTypeId="" ListUrl="" ListDisplayName="" ListName="{31A35C42-E326-4EE3-A2F0-7DBDC154C7D1}" ListId="31a35c42-e326-4ee3-a2f0-7dbdc154c7d1" PageSize="-1" UseSQLDataSourcePaging="True" DataSourceID="" ShowWithSampleData="False" AsyncRefresh="False" ManualRefresh="False" AutoRefresh="False" AutoRefreshInterval="60" NoDefaultStyle="TRUE" CacheXslStorage="False" InitialAsyncDataFetch="False" Title="Project report" FrameType="Default" SuppressWebPartChrome="False" Description="" IsIncluded="True" PartOrder="8" FrameState="Normal" AllowRemove="True" AllowZoneChange="True" AllowMinimize="True" AllowConnect="True" AllowEdit="True" AllowHide="True" IsVisible="True" DetailLink="" HelpLink="" HelpMode="Modeless" Dir="Default" PartImageSmall="" MissingAssembly="Cannot import this Web Part." PartImageLarge="" IsIncludedFilter="" ExportControlledProperties="True" ConnectionID="00000000-0000-0000-0000-000000000000" ID="g_2b53a84e_bf26_4583_af64_ac20e428b458" ExportMode="All" __MarkupType="vsattributemarkup" __WebPartId="{EF95A2DE-36BD-4787-97DB-994A2F40E75C}" __AllowXSLTEditing="true" WebPart="true" Height="" Width=""><DataSources>
<SharePoint:SPDataSource runat="server" DataSourceMode="CrossList" SelectCommand="&lt;Webs Scope=&#39;Recursive&#39;&gt;&lt;/Webs&gt;&lt;View&gt;&lt;Lists ServerTemplate=&#39;100&#39;&gt;&lt;/Lists&gt;&lt;Query&gt;&lt;Where&gt;&lt;And&gt;&lt;Eq&gt;&lt;FieldRef Name=&#39;FSObjType&#39; /&gt;&lt;Value Type=&#39;int&#39;&gt;0&lt;/Value&gt;&lt;/Eq&gt;&lt;Eq&gt;
&lt;FieldRef Name=&#39;ContentType&#39; /&gt;
&lt;Value Type=&#39;Computed&#39;&gt;ProjectList&lt;/Value&gt;
&lt;/Eq&gt;&lt;/And&gt;&lt;/Where&gt;&lt;OrderBy&gt;&lt;ListProperty Name=&#39;Title&#39;/&gt;&lt;/OrderBy&gt;&lt;/Query&gt;&lt;ViewFields&gt;&lt;ListProperty Name=&quot;Title&quot; /&gt;&lt;FieldRef Name=&#39;Function&#39;/&gt;&lt;FieldRef Name=&#39;StartDate&#39;/&gt;&lt;FieldRef Name=&#39;TaskDueDate&#39;/&gt;&lt;FieldRef Name=&#39;PM&#39;/&gt;&lt;FieldRef Name=&#39;Milestone&#39;/&gt;&lt;FieldRef Name=&#39;trafficelight&#39;/&gt;&lt;FieldRef Name=&#39;FSObjType&#39; /&gt;&lt;FieldRef Name=&quot;ID&quot;/&gt;&lt;FieldRef Name=&quot;Title&quot;/&gt;&lt;FieldRef Name=&quot;FileRef&quot;/&gt;&lt;FieldRef Name=&quot;FileDirRef&quot;/&gt;&lt;FieldRef Name=&quot;FileLeafRef&quot;/&gt;&lt;FieldRef Name=&quot;Editor&quot;/&gt;&lt;FieldRef Name=&quot;Modified&quot;/&gt;&lt;FieldRef Name=&#39;Region&#39;/&gt;&lt;/ViewFields&gt;&lt;/ViewFields&gt;&lt;/View&gt;" UpdateCommand="" InsertCommand="" DeleteCommand="" UseInternalName="True" UseServerDataFormat="True" ID="dataformwebpart1"><SelectParameters><asp:Parameter DefaultValue="SubWeb" Name="WebID"></asp:Parameter><asp:Parameter DefaultValue="ProjectOverview" Name="ListName"></asp:Parameter>
</SelectParameters>
</SharePoint:SPDataSource>
</DataSources>
<Xsl>

 


<xsl:stylesheet xmlns:x="http://www.w3.org/2001/XMLSchema" xmlns:d="http://schemas.microsoft.com/sharepoint/dsp" version="1.0" exclude-result-prefixes="xsl msxsl ddwrt" xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime" xmlns:asp="http://schemas.microsoft.com/ASPNET/20" xmlns:__designer="http://schemas.microsoft.com/WebParts/v2/DataView/designer" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:SharePoint="Microsoft.SharePoint.WebControls" xmlns:ddwrt2="urn:frontpage:internal">

<xsl:output method="html" indent="no"/>

<xsl:param name="URL"/>

<xsl:param name="TopN">3</xsl:param>
<xsl:template match="/" xmlns:x="http://www.w3.org/2001/XMLSchema" xmlns:d="http://schemas.microsoft.com/sharepoint/dsp" xmlns:asp="http://schemas.microsoft.com/ASPNET/20" xmlns:__designer="http://schemas.microsoft.com/WebParts/v2/DataView/designer" xmlns:SharePoint="Microsoft.SharePoint.WebControls">

<xsl:call-template name="dvt_1"/>

</xsl:template>

 

<xsl:template name="dvt_1">

<xsl:variable name="Rows" select="/dsQueryResponse/Rows/Row"/>

<table border="0" width="100%" cellpadding="2" cellspacing="0">
<tr valign="top">

<!--<th class="ms-vh" nowrap="nowrap" style="padding-left:0;">Project title</th>-->
<th class="ms-vh" nowrap="nowrap" style="padding-left:0;">Region</th>
<th class="ms-vh" nowrap="nowrap" style="padding-left:0;">Fuction</th>

<th class="ms-vh" nowrap="nowrap" style="padding-left:0;">Start Date</th>
<th class="ms-vh" nowrap="nowrap" style="padding-left:0;">Due Date</th>

<th class="ms-vh" nowrap="nowrap" style="padding-left:0;">PM</th>
<th class="ms-vh" nowrap="nowrap" style="padding-left:0;">Milestone</th>
<th class="ms-vh" nowrap="nowrap" style="padding-left:0;">Traffic light</th>


</tr>

<xsl:call-template name="dvt_1.body">

<xsl:with-param name="Rows" select="$Rows"/>

</xsl:call-template>

</table>

</xsl:template>

 

<xsl:template name="dvt_1.body">

<xsl:param name="Rows"/>

<xsl:for-each select="$Rows">

<xsl:variable name="NewList" select="ddwrt:NameChanged(string(@ListProperty.Title), 0)"/>

<xsl:if test="string-length($NewList) &gt; 0">
<xsl:call-template name="dvt_1.body2">

<xsl:with-param name="Rows" select="$Rows[@ListProperty.Title = current()/@ListProperty.Title]"/>

</xsl:call-template>

</xsl:if>

</xsl:for-each>

</xsl:template>

 

<xsl:template name="dvt_1.body2">

<xsl:param name="Rows"/>

<xsl:for-each select="$Rows">

<xsl:sort select="ddwrt:FormatDateTime(string(@Modified), 1033, 'yyyyMMdd HHmmss')" order="descending"/>

<xsl:if test="position() &lt;= $TopN">

<xsl:call-template name="dvt_1.rowview" />

</xsl:if>

</xsl:for-each>

</xsl:template>

 

<xsl:template name="dvt_1.rowview">

<tr>

<xsl:if test="position() mod 2 = 1">

<xsl:attribute name="class">ms-alternating</xsl:attribute>

</xsl:if>

<!--<td class="ProjectReport-td">
<a href="/{substring-after(@FileDirRef, ';#')}/DispForm.aspx?ID={@ID}"><xsl:value-of select="@Title" /></a>
</td>-->
<td class="ProjectReport-td">
<xsl:value-of select="@Region" />
</td>
<td class="ProjectReport-td"><xsl:value-of select="@Function" /></td>
<td><xsl:value-of select="ddwrt:FormatDate(string(@StartDate), 1033, 1)" /></td>
<td><xsl:value-of select="ddwrt:FormatDate(string(@TaskDueDate), 1033, 1)" /></td>
<td><xsl:value-of select="@PM" /></td>
<td><xsl:value-of select="@Milestone" /></td>
<td><img src="{substring-before(@trafficelight, ',')}" /></td>
</tr>
</xsl:template>

</xsl:stylesheet></Xsl>
<DataFields>


@ListId,ListId;@WebId,WebId;@ID,ID;@ListProperty.Title,ListProperty.Title;@FSObjType,FSObjType;@Title,Title;@FileRef,FileRef;@FileDirRef,FileDirRef;@FileLeafRef,FileLeafRef;@Editor,Editor;@Modified,Modified;
</DataFields>
<ParameterBindings>
<ParameterBinding Name="URL" Location="ServerVariable(URL)" DefaultValue=""/>
</ParameterBindings>
</WebPartPages:DataFormWebPart>

posted @ 2014-07-16 11:43  大刀客  阅读(323)  评论(0编辑  收藏  举报