Altova Mailing List Archives>Archive Index >microsoft.public.xsl Archive Home >Recent entries >Thread Prev - Sorting and eliminating duplicates >Thread Next - Re: Sorting and eliminating duplicates Re: Sorting and eliminating duplicatesTo: NULL Date: 4/6/2006 6:50:00 PM Mark wrote: > I have xsl document that transforms an xml document. My xml looks like > this: > > <Data> > <Country Key='001' Name='Afghanistan'> > <Indicator KEY='001' FootnoteKEY='3' Footnote='Test3'></Indicator> > <Indicator KEY='002' FootnoteKEY='' Footnote=''></Indicator> > <Indicator KEY='003' FootnoteKEY='' Footnote=''></Indicator> > <Indicator KEY='004' FootnoteKEY='2' Footnote='Test2'></Indicator> > </Country> > <Country Key='002' Name='US'> > <Indicator KEY='005 FootnoteKEY='3' Footnote='Test3'></Indicator> > <Indicator KEY='006' FootnoteKEY='' Footnote=''></Indicator> > <Indicator KEY='007' FootnoteKEY='' Footnote=''></Indicator> > <Indicator KEY='008' FootnoteKEY='1' Footnote='Test1'></Indicator> > </Country> > </Data> > > The output I'm looking for is: > Footnotes: > 1 Test1 > 2 Test2 > 3 Test3 Well with that example input the following XSLT gives the desired result <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output method="html" indent="yes" /> <xsl:key name="unique-note" match="Indicator[@FootnoteKEY != '']" use="@FootnoteKEY" /> <xsl:template match="/"> <html> <head> <title>key and sorting example</title> </head> <body> <h1>key and sorting example</h1> <table> <caption>Footnotes</caption> <tbody> <xsl:for-each select="Data/Country/Indicator[@FootnoteKEY != ''][generate-id() = generate-id(key('unique-note', @FootnoteKEY)[1])]"> <xsl:sort select="@FootnoteKEY" /> <tr> <td><xsl:value-of select="@FootnoteKEY" /></td> <td><xsl:value-of select="@Footnote" /></td> </tr> </xsl:for-each> </tbody> </table> </body> </html> </xsl:template> </xsl:stylesheet> Wether that is really the solution you are looking for depends on the meaning and relation of those two attributes. -- Martin Honnen --- MVP XML http://JavaScript.FAQTs.com/ | ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
