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

Re: getting the counter for a for-each statement

Subject: Re: getting the counter for a for-each statement
From: David Carlisle <davidc@xxxxxxxxx>
Date: Thu, 11 Dec 2003 18:05:44 GMT
xsl for each counter
> 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.

David


-- 
http://www.dcarlisle.demon.co.uk/matthew

________________________________________________________________________
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:
http://www.star.net.uk
________________________________________________________________________

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


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.