以下是一个例子,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="<Webs Scope='Recursive'></Webs><View><Lists ServerTemplate='100'></Lists><Query><Where><And><Eq><FieldRef Name='FSObjType' /><Value Type='int'>0</Value></Eq><Eq>
<FieldRef Name='ContentType' />
<Value Type='Computed'>ProjectList</Value>
</Eq></And></Where><OrderBy><ListProperty Name='Title'/></OrderBy></Query><ViewFields><ListProperty Name="Title" /><FieldRef Name='Function'/><FieldRef Name='StartDate'/><FieldRef Name='TaskDueDate'/><FieldRef Name='PM'/><FieldRef Name='Milestone'/><FieldRef Name='trafficelight'/><FieldRef Name='FSObjType' /><FieldRef Name="ID"/><FieldRef Name="Title"/><FieldRef Name="FileRef"/><FieldRef Name="FileDirRef"/><FieldRef Name="FileLeafRef"/><FieldRef Name="Editor"/><FieldRef Name="Modified"/><FieldRef Name='Region'/></ViewFields></ViewFields></View>" 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) > 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() <= $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>