register
other register

Monday, November 05, 2007

Select Distinct Values in XML

For the xml file like below:

<books>
<book author="Kevin Williams" title="Professional XML 2.0" />
<book author="Lewis Carroll" title="Alice in Wonderland" />
<book author="Lewis Carroll" title="Through the Looking-Glass" />
</books>

If you want to select distinct author from it, then make sure you use: xslt 2.0, and SaxonBB parser (in OxygenXML for example)

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes" />

<xsl:template match="units">
<xsl:for-each select="distinct-values(unit_instance/lev_code)">
<xsl:value-of select="."/>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>

No comments: