Subject: Re: [xsl] Keeping track of processed nodes, to avoid redundant output. From: "Andrew Welch" <andrew.j.welch@xxxxxxxxx> Date: Tue, 11 Sep 2007 11:48:34 +0100 |
On 9/11/07, John Smith <debrief@xxxxxxxxx> wrote: > Hello, > > This is a simplified description of what I am trying to do, I have an > xml document like this: > > <main> > <someElement> > <anElement name="John" /> > </someElement> > <someElement> > <anElement name="Jane" /> > </someElement> > <someElement> > <anElement name="John" /> > </someElement> > <someElement> > <anElement name="Jane" /> > </someElement> > </main> > > > and I like to retrieve each 'name' attribute from 'anElement', but I > only want to process the name once. So if the 'John' attribute is > repeated I want to somehow keep track that I have already processed > it, hence there is no need to process it again. > > So for the given example I like to output something like: > > <out> > <name>John</name> > <name>Jane</name> > </out> It's a grouping problem, so you'll want to use xsl:for-each-group in XSLT 2.0 or the key based technique in 1.0. Or, if you only needed access to the string values and not the containing nodes, you can just use distinct-values in 2.0 eg: <xsl:for-each select="distinct-values(//anElement/@name)"> <name><xsl:value-of select="."/>... or I guess in 1.0 the expensive equivalent: <xsl:for-each select="//anElement/@name[. != preceding::anElement/@name]"> <name>.... -- Andrew Welch http://andrewjwelch.com Kernow: http://kernowforsaxon.sf.net/
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Keeping track of processed no, John Smith | Thread | Re: [xsl] Keeping track of processe, George Cristian Bina |
[xsl] Keeping track of processed no, John Smith | Date | Re: [xsl] Keeping track of processe, George Cristian Bina |
Month |