I’ve alluded to this in the past, but I had a client situation in the last few days that brought it top of mind again. One of the quirks of a Crosslist DVWP is that you *must* specify all columns you would like to display in the CAML for the Data Source. You can add any column in the XSL you want, but if they aren’t explicitly specified in the CAML, you will get blank results.
Here’s an example. Say you want to gather the latest announcements from across the Site Collection for display on the Home Page of your Intranet. You’re displaying the latest 5 announcements, but you realize that annoucements that are expired are still showing up. So, you add a filter to the row select, as below, and you’re not seeing what you’d expect.
<xsl:variable name="Rows" select="/dsQueryResponse/Rows/Row[ (ddwrt:FormatDateTime(string(ddwrt:Today()), 1033, 'yyyyMMdd') >= ddwrt:FormatDateTime(string(@Expires), 1033, 'yyyyMMdd')) or string-length(@Expires) = 0 ]"/>
You’ll need to add an explicit FieldRef for the Expires column in your CAML, as below. (I’ve added carriage returns and white space into the CAML above for readability, but you can’t have them in your DVWP.)
<SharePointWebControls:SPDataSource runat="server" DataSourceMode="CrossList" SelectCommand=" <View> <Webs Scope='SiteCollection'></Webs> <Lists ServerTemplate='104'></Lists> <ViewFields> <FieldRef Name='ID'/> <FieldRef Name='Title'/> <FieldRef Name='Body'/> <FieldRef Name='FileDirRef'/> <FieldRef Name='Created'/> <FieldRef Name='Author'/> <FieldRef Name='Expires'/> <FieldRef Name='PermMask'/> </ViewFields> </View>" UseInternalName="true" ID="dataformwebpart5"> </SharePointWebControls:SPDataSource>
Once you add the FieldRef to the CAML, the Expires column values are available for use in your filter.
Keep in mind that you need to be careful what you add into your <Viewfields> section. If you add a FieldRef for a column which doesn’t occur in *all* of the items which you want to retrieve, you will, in effect, be adding a filter to the CAML. Only items which have all of the columns specified in the FieldRefs will be returned.