XSL Alternative to Eliminating Duplicates Using ddwrt:NameChanged

I like using the ddwrt namespace functions, as they give you a lot of power in your DVWP’s XSL.  I just found an alternative approach to using the ddwrt:NameChanged function which may make more sense in some situations.  I included this approach in an update to my prior post, but it seemed worth a post of its own.

If you want to eliminate duplicates only with XSL, you can use the select below in your dvt_1.body template’s xsl:for-each, which is the clause which determines which rows to pass to the dvt_1.rowview template.

<xsl:template name="dvt_1.body">
<xsl:param name="Rows"/>
<xsl:for-each select="$Rows[not(@Title = preceding-sibling::*[1]/@Title)]">
<xsl:call-template name="dvt_1.rowview"/>
</xsl:for-each>
</xsl:template>

Similar Posts

11 Comments

  1. hello
    thank you very much for such interesting post, though I have a question, is it possible to group multiple columns without actually nesting them, cause its been bothering me using ddwrt:NameChanged(string(@xxx), id) specially setting the id for multiple columns.

    thanx again,
    Zafer

    1. Which part of it is “bothering you”? ;+) You can group on as many columns as you want. One thing that you could do is concatenate the multiple columns together and just look for a change in that concatenation. However, that wouldn’t tell you *which* column has changed. You can have as many NameChanged-based variables as you want simply by bumping up the value of id for each.
      See the documentation for gthe ddwrt:NameChaged function here: http://msdn.microsoft.com/en-us/library/dd583143(office.11).aspx#officesharepointddwrt_namechanged

      M.

      1. thank you again for your quick reply, I’ve thought about concatenating those columns, but this would require javascript to get in the business, and js is not really an option in my app, I know it doesnt seem right to group multiple columns without nesting them, but all I want is to count those rows of those grouped columns, thats why I took the approach of grouping in the first palce.

        thank you so much, :)
        Zafer

        1. You don’t need JavaScript to do the concatenation. You can do it right in the XSL:

          <xsl:variable name="AllGroups" select="concat(@Column1, @Column2, @Column3)"/>

          and if you want to count rows with a certain value:

          <xsl:variable name="CountGroup1" select="count($Rows[@Column1 = current()/@Column1])"/>

          M.

  2. Marc,

    Thanks for this informative post, along with the other instructional information that you have posted in many sites. The education that I have learned from your posts on using SPD to manipulate SP has been invaluable.

    I have a question is regards to this post. I have a very large flat list that contains a Year and Category field…..both of which have choice values. What I am trying to achieve is bring back a view in a DVWP that first groups the list by Year (2010, 2011, etc.) which is easy enough, but then I want to bring back the distinct categories, with a count of the total rows per category and sum of an associated currency field for each row. It would look similar to the following structure:

    Year1
    CategoryChoice1 (count) Sum of Currency Field for rows of Choice1
    CategoryChoice2 (count) Sum of Currency Field for rows of Choice2
    Year2
    CategoryChoice1 (count) Sum of Currency Field for rows of Choice1
    CategoryChoice2 (count) Sum of Currency Field for rows of Choice2

    Can I use your approach that you describe in this post to bring back the distinct (non duplicate) Category choices per year within the year grouping? If so, can you educate me on the best approach? I had initial success per your instructions above, but it does not allow the initial grouping by Year.

    Thank you for all of your time and instructive posts that you provide the community….

    Jeff

    1. Jeff:

      The grouping is one thing, and it sounds like you’ve got a handle on that. The counts and sums are another thing.

      What you’ll need to end up with is filtered rowsets per Year and Category grouping. It’ll need to look something like this:

      <xsl:value-of select="count($Rows[@Year = current()/@Year and @Category = current()/@Category])"/>
      

      Hopefully that’ll give you enough to go on…

      M.

  3. Marc,

    Thanks for the information and response. The guidance you provided makes sense. I will give it a shot and post on my results.

    Thanks again….

    Jeff

  4. hey,

    thanks for your all great post.

    i have an issue, hope (i wish) you may help me.

    i have created a dataview task list, with short and filter option.

    filter showing multiple username in filter drop down. i tried everything which is specified here and at http://social.msdn.microsoft.com/Forums/en/sharepointcustomization/thread/8db1ce99-6853-4a89-88a5-891aecef7dd7

    did not got any success, can you please help me or email me at [email protected]

    Thanks Bro for ur support

  5. Hi Marc,

    Thanks for the wonderful post.

    I have an issue in my xsl as I need get the distinct count of lookup colum.
    Ex: List 1 – ABC (1000 items)
    List 2 – DEF (2000 items)
    I have lookup column in DEF (2000 item) which is retrieving duplicated items from ABC such as title therefore I need display the distinct count from List- ABC which is 1000 items in List -DEF.

    Thanks in advance
    Rgrds
    HH

Leave a Reply to bhupesh Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.