Subject: RE: [xsl] Generating a collection of unique elements. From: "Scott Trenda" <Scott.Trenda@xxxxxxxx> Date: Tue, 10 Jun 2008 12:04:52 -0500 |
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> ~ Scott -----Original Message----- From: Michael Kay [mailto:mike@xxxxxxxxxxxx] Sent: Tuesday, June 10, 2008 11:58 AM To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx 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@xxxxxxxxxxxxxxxxxxxx] > Sent: 10 June 2008 17:51 > To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx > 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
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] Generating a collection o, Michael Kay | Thread | Re: [xsl] Generating a collection o, Andrew Welch |
RE: [xsl] Generating a collection o, Michael Kay | Date | [xsl] Numbering in XSLT, shruta satam |
Month |