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

traversing up nodes until a certain attribute, then ba

Subject: traversing up nodes until a certain attribute, then back to current node
From: xslt user <xsltacct@xxxxxxxxx>
Date: Tue, 27 Mar 2007 08:14:01 -0700 (PDT)
 traversing up nodes until a certain attribute
Hello,

Here is sample XML

<root>
  <zero>
	<one id="a">
	  <two>
		<three id="c">
		  <four id="d">
			<five>
			  <six>
				<seven/>
			  </six>
			</five>
		  </four>
		</three>
	  </two>
	</one>
  </zero>
</root>

which I want to transform into this:

root
zero
a
a two
c
d
d five
d five six
d five six seven

just giving the element name if no ancestor has the
attribute "id" and giving the closest ancestor "id" as
the starting point and all element names back to the
current node if it does have an ancestor with
attribute "id".

Here is what I have so far, but it's not enough.

<?xml version="1.0" encoding="utf-8"
standalone="yes"?>
<xsl:transform version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" version="1.0"
encoding="utf-8" omit-xml-declaration="yes"
standalone="no" indent="no" media-type="text/plain"/>

<xsl:template match="*">
	<xsl:choose>
	<xsl:when test="ancestor-or-self::*[@id]">
		<xsl:for-each select="ancestor-or-self::*[@id]">
		<xsl:if test="position() = last()">
		<xsl:value-of select="@id"/>
		</xsl:if>
		</xsl:for-each>
	</xsl:when>
	<xsl:otherwise>
		<xsl:value-of select="name(.)"/>
	</xsl:otherwise>
	</xsl:choose>
<xsl:apply-templates/>
</xsl:template>

</xsl:transform>


That results in:

root
  zero
	a
	  a
		c
		  d
			d
			  d
				d

but I need to process back until the current node (not
beyond it...) giving all element names along the way,
starting after the closest ancestor node with an
attribute "id".

I've done some searching and I might need to do some
XSLT grouping, but I'm not sure yet.  Can anyone help?


 
____________________________________________________________________________________
No need to miss a message. Get email on-the-go 
with Yahoo! Mail for Mobile. Get started.
http://mobile.yahoo.com/mail 

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.