other register

Monday, November 05, 2007

Select Distinct Values in XML

For the xml file like below:

<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" />

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="">
<xsl:output method="xml" indent="yes" />

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

No comments: