RE: XPath help

Subject: RE: XPath help
From: "edmund mitchell" <edmund_mitchell@xxxxxxxxxxx>
Date: Sat, 11 Nov 2000 09:01:27 HST
Hello Mathias
Thanks for trying, but that didn't seem to do it.
It allowed every element in the document to be output, so
maybe the fault lies with my description, so here's a
small chunk of the data:
<System name="ABC">...</System>
<System name="Whatever">...</System>
<System name="mail">
<Function name="Routing DB">...</Function>
<Function name="client">...</Function>
<System name="mail">
<Function name="pop3">...</Function>
<Function name="smtp">...</Function>
<System name="news">...</System>
<System name="account">...</System>
<System name="Authentication">...</System>
There will be many other System elements, some with matching values in their 'name' attributes, but to focus on this example, I'm trying get all the children of <System name="mail"> under one instance of <System name="mail">, which was easy, thanks to Ken Holman (and Steve Meunch, of course) and then output all the other elements as they are.
This was the stylesheet:
<xsl:stylesheet xmlns:xsl="";
<xsl:key name='systems' match='System[*]' use='@name'/>
<xsl:template match="/">

<xsl:for-each select="//System[generate-id(.)
=generate-id(key('systems', @name))]">
<xsl:copy-of select="@name"/>
<xsl:copy-of select="key('systems', @name)/*"/>
<xsl:if test="//*[@name and not (@name = following::*/@name)
and not (@name =preceding::*/@name)]">
<xsl:copy-of select='.'/>
It grouped all the Function children of System name="mail" under one instance, but then it output the second instance of <System name="mail"> and all the children thereof, too. I was hoping that the if test would detect that another element had a 'name' attribute value of 'mail', and therefore it wouldn't be output. Maybe the flaw is in my thinking (not unlikely).

Try :
//*[@name and not (@name = following::*/@name) and not (@name =
which should select all element nodes that have a 'name' attribute and
whose 'name' attribute's value is not present in the rest of the document
as an 'name' attribute...

There might be a simpler version (especially avoiding the double test on
preceding and following)...

Hope this helps.

Mathias Bonnard

Get Your Private, Free E-mail from MSN Hotmail at

Share information about yourself, create your own public profile at

XSL-List info and archive:

Current Thread