Subject: What does position() really return
From: "Jan Mazac" <jwm@xxxxxxxxxxxx>
Date: Thu, 15 Mar 2001 23:19:22 +0100
|
Hi,
I'm trying to find out, what the position() function really returns.
Browsing through the archive, some books and what's on the Internet
and experimenting with it only increases my confusion. I have the
following XML/XSL-code:
<?xml version="1.0" encoding="iso-8859-1"?>
<Personen>
<Person>Jan</Person>
<Person>Peter</Person>
<Person>George</Person>
<Person>Danny</Person>
</Personen>
<?xml version="1.0" encoding="iso-8859-1" ?>
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output encoding="iso-8859-1" method="html" indent="yes"/>
<xsl:template match="/">
<html>
<head>
<title>Testfile</title>
</head>
<body>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>
<xsl:template match="Personen">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="Person">
<p>Output: <xsl:value-of select="position()"/>
<xsl:text>, </xsl:text>
<xsl:value-of select="."/>
</p>
</xsl:template>
</xsl:stylesheet>
Running this with Saxon (Instant-Saxon, version 6.2.1 under Win98)
produces the following result (result 1):
Output: 2, Jan
Output: 4, Peter
Output: 6, George
Output: 8, Danny
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
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
My confusion comes from the following:
- I have expected the position numbers *always* in the range between 1 and 4
- Why are the position values in result 1 multiples of 2 ?
- Why are results 2 and 3 different (in terms of the position numbers) ?
Thanks in advance
Jan
___________________________________________________________________
BISS GmbH, Chaukenweg 12, D-26388 Wilhelmshaven, Germany
Phone: +49 4423 9289-0, Fax: +49 4423 9289-99
Dr. Jan Mazac, mailto: jwm@xxxxxxxxxxxx
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|