Re: [xsl] getting the counter for a for-each statement

Subject: Re: [xsl] getting the counter for a for-each statement
From: David Carlisle <davidc@xxxxxxxxx>
Date: Thu, 11 Dec 2003 18:05:44 GMT
> That doesn't work since the context node isn't the node for the for-each.
> In that case position() gets the parent of ROW since the template is:
> <xsl:template match="ficha_tecnica/ROWSET">

No. position() _never_ directly relates to a position of a node in the
source tree it always refers to a position in the current node list
in a for-each as you have here it will have the values 1,2,3,4,...
for each iteration of the body of the for-each.

My for-each gets the following:

so position() -1 (the first [] in each line) goes 0,1,2 
as expected. In your initial post you asked for an output of 1,2,3
which would be position() rather than position()-1

your lines
<xsl:value-of select="count(. | key('tipos', D))-1" />
are not counting anything related to the for loop (despite the subject
line of this thread) You could write it as
count(key('tipos', D))-1
which would save the system a bit of work,  as you know . is in that set
(you know it's the first element)
I doubt counting the node set is very slow as systems need to optimise
that for things like [position()=last()] which appear all over the place.
but see other thread today on the difficuties of knowing what will and
will not be fast.



This e-mail has been scanned for all viruses by Star Internet. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:

 XSL-List info and archive:

Current Thread