using xslt key for finding unique values

sexyonlinefree

New Member
\[code\]<ROOT><AA Aattr="xyz1"> <BB bAttr1="firefox" bAttr2="aaa" > </BB> <BB bAttr1="chrome" bAttr2="aaa" > </BB> <BB bAttr1="firefox" bAttr2="bbb" > </BB> <BB bAttr1="chrome" bAttr2="bbb" > </BB></AA><AA Aattr="xyz2"> <BB bAttr1="firefox" bAttr2="aaa" > </BB> <BB bAttr1="chrome" bAttr2="ccc" > </BB> <BB bAttr1="firefox" bAttr2="ddd" > </BB></AA>\[/code\]I want to select distinct\unique values of attibute 'bAttr2' in node 'BB', from node 'AA' where attribute 'Aattr' is xyz1say for the given xml, i need to output as "aaa","bbb"I tried the following logic using key. But didnt worked. Please help\[code\]<xsl:key name="nameDistinct" match="BB" use="@bAttr1"/><xsl:template match="/"><xsl:for-each select="ROOT/AA[@Aattr='xyz1']"> <xsl:for-each select="BB[generate-id()=generate-id(key('nameDistinct',@bAttr2)[1])]"> <xsl:value-of select="@bAttr2"/> </xsl:for-each></xsl:for-each></xsl:template>\[/code\]
 
Back
Top