www.webdeveloper.com
Results 1 to 2 of 2

Thread: xslt sorting by attribute

Hybrid View

  1. #1
    Join Date
    Mar 2006
    Location
    Sacramento
    Posts
    73

    xslt sorting by attribute

    Hey guys,
    I've used the Muenchian Method for sorting and grouping but I've not had any success in using it to group by an attribute. I'm hoping someone here has had this experience and made it work.

    Here's a node example from the xml...
    Code:
    <Products>
        <itm num="123456">
            <properties oid="3897936" cat="8" type="Stuff" series="My Series"/>
            <legacy brand="MyOldBrand" oldNum="654321"/>
        </itm>
    </Products>
    I'm needing to get a list of all the legacy/@brands that are in the data file

    Here's the portion of xslt I've been attempting to do this with...
    Code:
    <xsl:key name="ProdByBrand" match="itm" use="legacy/@brand"/>
    
      <xsl:template match="Products"><xsl:for-each select="itm/legacy[generate-id() = generate-id(key('ProdByBrand', /@brand)[1])]"><xsl:value-of select="/@brand" />|</xsl:for-each></xsl:template>
    Any help would be appreciated.
    Thanks!

  2. #2
    Join Date
    Mar 2006
    Location
    Sacramento
    Posts
    73

    resolved

    Thanks for all the help

    I found a solution that works. I knew it was just a matter of getting it all configured just right.

    Here it is
    Code:
    <xsl:key name="ProdByBrand"  match="//legacy" use="@brand" />
      <xsl:template match="Products"><xsl:for-each select="itm/legacy[generate-id() = generate-id(key('ProdByBrand', @brand)[1])]"><xsl:value-of select="@brand" />|</xsl:for-each>
    </xsl:template>

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles