Re: [xsl] position() returns what?

Subject: Re: [xsl] position() returns what?
From: David Carlisle <davidc@xxxxxxxxx>
Date: Fri, 24 Oct 2003 10:03:39 +0100

> But this outputs equal numbers: 2,4,6,8,10,...
> I did expect that it would output 0,1,2,3,4,5

This is a FAQ (I'm sure itmustbe in teh faq file for this list)
position() returns a number that is not a property of teh node (teh same
node can have any number of position() values, for example if you select
it with .. or . it always has position() =1.

position() returns the position of the node in the current node list,
and if that is the default selection for apply-templates this is
child::node(0 which is all nodes including text nodes, so
in your case the odd numbered nodes are all white space text nodes, if
you added a template for them,
<xsl:template match="text()">
     <xsl:value-of select="position()"/>
then you'd see it.

change you apply tempaltes to use select="*" if you only want to process
element children, or use xsl:strip-space to discard teh white space
before processing begins.

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