Re: [xsl] Generating a collection of unique elements.

Subject: Re: [xsl] Generating a collection of unique elements.
From: "Andrew Welch" <andrew.j.welch@xxxxxxxxx>
Date: Wed, 11 Jun 2008 09:51:23 +0100
2008/6/10 Scott Trenda <Scott.Trenda@xxxxxxxx>:
> XSLT 2.0 makes 1.0 look stupidly complicated in comparison, but here's
> the 1.0 usage case:
>
> <xsl:stylesheet version="1.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
>  <xsl:key name="FooName" match="foo" use="@name" />
>  <xsl:template match="/">
>    <newDoc>
>      <xsl:for-each select="//foo[generate-id() =
> generate-id(key('FooName', @name))]">
>        <xsl:element name="{@name}" />
>      </xsl:for-each>
>    </newDoc>
>  </xsl:template>
> </xsl:stylesheet>
>

Relying on 1.0's first item quirk isn't really good practice, much
better imho to explicitly select the first..
generate-id(key('FooName', @name)[1])



-- 
Andrew Welch
http://andrewjwelch.com
Kernow: http://kernowforsaxon.sf.net/

Current Thread