Subject: Re: [xsl] Counting indent level From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx> Date: Sun, 28 Sep 2008 21:38:51 -0400 |
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">
<xsl:template match="catalog"> <xsl:apply-templates select="*"/> </xsl:template> <xsl:template match="group"> <!--report on the group--> <xsl:apply-templates select="item"/> </xsl:template> <xsl:template match="item"> <!--report on the item--> </xsl:template>
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.
<xsl:template match="catalog"> <xsl:apply-templates select="*"/> </xsl:template>
(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?
-- Upcoming XSLT/XSL-FO hands-on courses: Wellington, NZ 2009-01 Training tools: Comprehensive interactive XSLT/XPath 1.0/2.0 video G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/ Male Cancer Awareness Nov'07 http://www.CraneSoftwrights.com/s/bc Legal business disclaimers: http://www.CraneSoftwrights.com/legal
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Counting indent level, Nicholas Orr | Thread | Re: [xsl] Counting indent level, Nicholas Orr |
[xsl] Counting indent level, Nicholas Orr | Date | Re: [xsl] Counting indent level, Nicholas Orr |
Month |