This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
RE: What does position() really return
- To: <xsl-list at lists dot mulberrytech dot com>
- Subject: RE: [xsl] What does position() really return
- From: "Michael Kay" <mhkay at iclway dot co dot uk>
- Date: Fri, 16 Mar 2001 09:50:11 -0000
- Reply-To: xsl-list at lists dot mulberrytech dot com
> I'm trying to find out, what the position() function really returns.
When used as an XPath expression in its own right, it returns the position
of the current node within the current node list, which is the list of nodes
selected by the innermost xsl:for-each or xsl:apply-templates.
> <xsl:template match="Personen">
> <xsl:apply-templates/>
> </xsl:template>
This one selects all child nodes of Personen, including whitespace text
nodes. Generally the whitespace text nodes will be odd-numbered, the element
children will be even numbered.
>
> Changing the "Personen" template to:
>
> <xsl:template match="Personen">
> <xsl:apply-templates>
> <xsl:sort select="."/>
> </xsl:apply-templates>
> </xsl:template>
>
> generates (result 2):
>
> Output: 6, Danny
> Output: 7, George
> Output: 8, Jan
> Output: 9, Peter
This is because the whitespace text nodes are now sorted before the
elements.
>
> and once more changing "Personen" to:
>
> <xsl:template match="Personen">
> <xsl:apply-templates select="Person">
> <xsl:sort select="."/>
> </xsl:apply-templates>
> </xsl:template>
>
> results in (result 3):
>
> Output: 1, Danny
> Output: 2, George
> Output: 3, Jan
> Output: 4, Peter
>
This time you didn't select the whitespace text nodes, you only selected the
elements.
Mike Kay
Software AG
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list