ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> xsl-list
xsl-list
Re: [xsl] getting the counter for a for-each statement
by David Carlisle other posts by this author
Dec 11 2003 6:05PM messages near this date
RE: [xsl] getting the counter for a for-each statement | [xsl] Re: How do you un-escape in HTML
>  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
Thread:
Jaime A Stuardo Bahamondes
David Carlisle

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved