xsl-list
[Top] [All Lists]

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

2008-06-11 01:51:48
2008/6/10 Scott Trenda <Scott(_dot_)Trenda(_at_)oati(_dot_)net>:
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="{(_at_)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/

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>