[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

question about position()

Subject: question about position()
From: "Denis Kranjcec" <denis.kranjcec@xxxxxxxxxx>
Date: Thu, 17 May 2001 14:46:25 +0200
question about position
There is two examples, first is with position() in <xsl:apply-templates> and
second is with position() in <xsl:for-each>.
I don't understand why is output different.
If I have understand correctly, function position() should return position
in current context, and for-each example is OK, but I don't understand why
is output from example with apply-templates different.
Can somebody explain me what is the difference between examples?
Thanks in advance.

xml:
<r>
	<a at="1">1</a>
	<a at="4">4</a>
	<a at="2">2</a>
	<a at="3">3</a>
</r>

first xsl example:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

	<xsl:template match="/">
		<xsl:apply-templates select="r/a">
			<xsl:sort data-type="number" select="@at"/>
			<xsl:with-param name="p" select="position()"/>
		</xsl:apply-templates>
	</xsl:template>

	<xsl:template match="a">
		<xsl:param name="p"/>
		<xsl:value-of select="$p"/><xsl:text>,</xsl:text>
	</xsl:template>

</xsl:stylesheet>

output from first example:
-1,-1,-1,-1,


second xsl example:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

	<xsl:template match="/">
		<xsl:for-each select="r/a">
			<xsl:sort data-type="number" select="@at"/>
			<xsl:apply-templates select=".">
				<xsl:with-param name="p" select="position()"/>
			</xsl:apply-templates>
		</xsl:for-each>
	</xsl:template>

	<xsl:template match="a">
		<xsl:param name="p"/>
		<xsl:value-of select="$p"/><xsl:text>,</xsl:text>
	</xsl:template>

</xsl:stylesheet>

output from second example:
1,2,3,4,


Denis Kranjcec


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.