Closed Bug 267292 Opened 20 years ago Closed 19 years ago

In XSLT position() evaluates different in <xsl:template match="node[position()...]"> and inside template

Categories

(Core :: XSLT, defect)

x86
Windows XP
defect
Not set
major

Tracking

()

RESOLVED DUPLICATE of bug 231715

People

(Reporter: dmpetrov, Assigned: peterv)

Details

User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 5.1; rv:1.7.3) Gecko/20041001 Firefox/0.10.1
Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.1; rv:1.7.3) Gecko/20041001 Firefox/0.10.1

<xls:template match="item[position()!=last()]"> will match every item node
except the last. It's ok. But <xsl:value-of select="position()"/> will not
return correct value.

Reproducible: Always
Steps to Reproduce:
1. Create XML document (bug.xml)
<?xml version="1.0"?>
<?xml-stylesheet type="text/xml" href="bug.xsl"?>
<?xml-stylesheet type="text/xsl" href="bug.xsl"?>

<items>
	<item>1</item>
	<item>2</item>
	<item>3</item>
</items>
2. Create XSL stylesheet (bug.xsl)
<?xml version="1.0"?>
<xsl:stylesheet	version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="items">
	<html><head><title>XSLT Bug</title></head>
	<body>
		<xsl:apply-templates/>
	</body>
	</html>
</xsl:template>
<xsl:template match="items/item">
	item <xsl:value-of select="."/> - <xsl:value-of select="position()"/>, last
<xsl:value-of select="last()"/><br/>
</xsl:template>
</xsl:stylesheet>
3. That's it! Now open bug.xml in Firefox

Actual Results:  
item 1 - 2, last 7
item 2 - 4, last 7
item 3 - 6, last 7

Expected Results:  
item 1 - 1, last 3
item 2 - 2, last 3
item 3 - 3, last 3

Seems that position() returns it's actual value multiplied by 2, and last()
returns it's actual value multiplied by 2 plus 1.
-->Browser.
Assignee: firefox → peterv
Component: General → XSLT
Product: Firefox → Browser
QA Contact: firefox.general → keith
Version: unspecified → Trunk
<xsl:apply-templates/> includes the textnodes, see 
http://www.w3.org/TR/xslt#section-Applying-Template-Rules and the blurb on
whitespace stripping there. As http://www.w3.org/TR/xslt#strip continues to say,
"...Initially, the set of whitespace-preserving element names contains all element
names. ...".

So we're perfectly fine. You can get to the behaviour you expect by either using
a select="item", or by adding a 
<xsl:strip-space elements="items"/> to your xsl:stylesheet.
Status: UNCONFIRMED → RESOLVED
Closed: 20 years ago
Resolution: --- → INVALID
Status: RESOLVED → UNCONFIRMED
Resolution: INVALID → ---

*** This bug has been marked as a duplicate of 231715 ***
Status: UNCONFIRMED → RESOLVED
Closed: 20 years ago19 years ago
Resolution: --- → DUPLICATE
You need to log in before you can comment on or make changes to this bug.