Re: [xsl] Counting indent level

Subject: Re: [xsl] Counting indent level
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Mon, 29 Sep 2008 08:47:40 -0400
At 2008-09-29 12:51 +1000, Nicholas Orr wrote:
On 29/09/2008, at 11:38 AM, G. Ken Holman wrote:
<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.

Every node (except the root node above the document element) has only a single parent node, so I'm not sure what you mean by "immediate parent". Unless you meant to say "immediate ancestor" which is the parent.

Above you also state you want an item whose parent is catalogue and
not just those whose parent is group.  If I'm wrong, then you'll
have to change the above to the following to not process items that
are not a child of a group:

<xsl:template match="catalog">
 <xsl:apply-templates select="*"/>
</xsl:template>

This is the same as the above, the first three lines at least - is that what you meant?

Sorry ... if you wanted to skip item children of catalogue then in the top example it would be select="group".


The code I give you above will process groups and items in document
order.

Ken, does this mean it will retain the overall order though?

Yes.


I want
to process them (from my original), as an export (like csv) in the
same order so the export would mix and match items and groups :

item
group
group
item
item
etc

So it's one single export with both types mixed in the original
order.  This is why I used a single for-each with the "or" to pick up
everything in one go.

You didn't use "or", you used "union" (yes, there's a difference ... sometimes the union feels like and "or" and sometimes the union feels like an "and" ... your for-each statement could read "items and groups and items that are children of groups" which feels like an "and" and not an "or"). It works for you because the union is returned in document order. But in summary, in your code you are making assumptions about your data while in my code I was focused on the result. I think Mike was very eloquent (as always) in explaining the details of this in his post, especially how the words you put forward lead to a particular approach.


. . . . . . . . . Ken

--
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