Re: [xsl] position()

Subject: Re: [xsl] position()
From: David Carlisle <davidc@xxxxxxxxx>
Date: Tue, 3 Apr 2001 11:37:08 +0100
> Close. It still needs to co-operate with last() in order to detect the
> last sibling in a sequence, though.

er no last() tells you how many elements are in the current list.
If you want to know how many siblings you have you want count(../*)

> The function you give is actually what I use.

Then you are just using simple cases that position() wasn't particularly
designed for.

<xsl:for-each select="document('a')/x/y | id('b') | //x/z">
<xsl:sort select="@label"/>

then you are going to be processing some list of nodes in some sorted
order. position() and last() let you know how far along that list you've
got. knowing the sibling count of each individual node in the original
document isn't much help. The chances are that position() is what you

> I think this is the problem: XSLT does not treat the document
> structure, it treats the file structure at a much lower level. 

A bizarre description:-) XSLT gives almost no view of the file
structure at all, you only get to see th elogical document tree.

You object to the fact that position() is easier to type than
count(preceding-sibling::*)+1 but I'd argue that position() is
more often what you want. If the current node list is anything other
than simply the list of child elements of a single parent then 
the sibling count is unlikely to be of any importance to the generated
result. In the cases where it is important you can use count() to get


This message has been checked for all known viruses by Star Internet delivered
through the MessageLabs Virus Control Centre. For further information visit

 XSL-List info and archive:

Current Thread