22
Apr
Apr
DataViewWebPart (DVWP) show unique Items only
SharePoint 2007 | 1 Comment »I’ve been trying to display only unique items from a list for some time now. I found a way through someones blog but I can’t seem to remember wich one..
Anyway, to do this set a sort on the column you want to show in SPD. eg. Sort by Title.
Then in the template for dvt_1.body add the following code after $Rows
<xsl:template name=”dvt_1.body”>
<xsl:param name=”Rows”/>
<xsl:for-each select=”$Rows[not(@Title = preceding-sibling::*/@Title)]“>
<xsl:call-template name=”dvt_1.rowview”/>
</xsl:for-each>
</xsl:template>
This will check the preceeding sibling if it has the same name and if so It won’t display that Item and only the first “unique” item will be displayed. I use this alot for eg. when doing a A – Z filter webpart etc.
[...] 2009-05-21: I just found another approach over at Christian’s Pampigt blog. By changing the xsl:for-each to test for unique Titles, [...]