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>
~ Scott
-----Original Message-----
From: Michael Kay [mailto:mike(_at_)saxonica(_dot_)com]
Sent: Tuesday, June 10, 2008 11:58 AM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: RE: [xsl] Generating a collection of unique elements.
<xsl:template match="/">
<newdoc>
<xsl:for-each select="distinct-values(//foo/@name)">
<xsl:element name="{.}"/>
</xsl:for-each>
</newdoc>
</xsl:template>
Michael Kay
http://www.saxonica.com/
-----Original Message-----
From: Nathan Potter [mailto:ndp(_at_)coas(_dot_)oregonstate(_dot_)edu]
Sent: 10 June 2008 17:51
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Cc: Nathan Potter
Subject: [xsl] Generating a collection of unique elements.
Greetings,
I have thought about this for a couple of days, and I don't
really have an ideas about how to get the result I want.
Maybe someone here can help!
In my source document there are a number of <foo> elements.
They all have a "name" attribute. They can occur as child
elements of any other element in the document, at any level
of nesting.
My XSL needs to process these <foo> elements and produce a
list of the unique names.
Source Example:
<doc>
<foo name="a" />
<foo name="d" />
<thing1>
<foo name="a" />
<foo name="b" />
<foo name="c" />
</thing1>
<thing2>
<foo name="a" />
<thing3>
<foo name="b" />
<foo name="c" />
</thing3>
<foo name="d" />
<foo name="e" />
</thing2>
</doc>
Desired Result:
<newDoc>
<a />
<b />
<c />
<d />
<e />
</newDoc>
Anybody have a suggestion?
Thanks,
Nathan
============================================================
Nathan Potter Oregon State University, COAS
ndp at coas.oregonstate.edu 104 Ocean. Admin. Bldg.
541 737 2293 voice Corvallis, OR 97331-5503
541 737 2064 fax
--~------------------------------------------------------------------
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>
--~--
--~------------------------------------------------------------------
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>
--~--
--~------------------------------------------------------------------
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>
--~--