"It’s Nice to Be Important, But It’s More Important to Be Nice"
22
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.

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks

One Comment on “DataViewWebPart (DVWP) show unique Items only”

  1. 1 Showing Subtotals in a DVWP, Sorted by the Subtotals « Marc D Anderson’s Blog said at 12:56 on May 21st, 2009:

    [...] 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, [...]


Leave a Reply