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

Counting indent level

Subject: Counting indent level
From: Nicholas Orr <nick@xxxxxxxxxxx>
Date: Mon, 29 Sep 2008 11:22:43 +1000
 Counting indent level
G'day all,

I've got some XML that contains a list of items and groups, and each group could contain either more items or more groups like so :

<catalog>
	<item />
	<group>
		< group >
		< item />
		< item />
		< group >
			< group >
				< item />
etc

So groups can contain either items or more groups or nothing. Items only exist at the root (catalog) of this part of the tree or inside groups. I'm outputting a single list of all of the items and group currently using this :

<xsl:for-each select="item|descendant::group|descendant::group/item">

The reason for that is that a item node might also contain child nodes that are also called <item> nodes that I don't want. I only want a item node that has it's immediate parent a group node. (There may be an easier way to do that...)

How do I count the "indent" level - so how many parent "groups" each item or group has, right back up to the catalog node? Eg in the example above, it would be 0 for the first item and group, 1 for the next 4 etc.

I can change the for-each that I'm using, although it has to remain in the same order, so I can't process them out of order.

Is the easiest way to count back up the tree for each one, or is there a way to build that into the for-each? If I use count, how do I count the path back up to the catalog node?

Thanks in advance,
Nick

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.