[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: XPath help

Subject: RE: XPath help
From: "edmund mitchell" <edmund_mitchell@xxxxxxxxxxx>
Date: Sat, 11 Nov 2000 09:01:27 HST
edmund mitchell
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:
<weird_doc>
<System name="ABC">...</System>
<System name="Whatever">...</System>
<System name="mail">
<Function name="Routing DB">...</Function>
<Function name="client">...</Function>
</System>
<System name="mail">
<Function name="pop3">...</Function>
<Function name="smtp">...</Function>
</System>
<System name="news">...</System>
<System name="account">...</System>
<System name="Authentication">...</System>
</weird_doc>
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="http://www.w3.org/1999/XSL/Transform"
version='1.0'>
<xsl:key name='systems' match='System[*]' use='@name'/>
<xsl:template match="/">


<xsl:for-each select="//System[generate-id(.)
=generate-id(key('systems', @name))]">
<System>
<xsl:copy-of select="@name"/>
<xsl:copy-of select="key('systems', @name)/*"/>
</System>
</xsl:for-each>
<xsl:if test="//*[@name and not (@name = following::*/@name)
and not (@name =preceding::*/@name)]">
<xsl:copy-of select='.'/>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
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).
Edmund


Try :
//*[@name and not (@name = following::*/@name) and not (@name =
preceding::*/@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 http://www.hotmail.com.

Share information about yourself, create your own public profile at http://profiles.msn.com.


XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list



Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.