DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=6011>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=6011

position() returns zero inside xsl:apply-templates

           Summary: position() returns zero inside xsl:apply-templates
           Product: XalanJ2
           Version: 2.2.0
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: Major
          Priority: Other
         Component: org.apache.xpath
        AssignedTo: [EMAIL PROTECTED]
        ReportedBy: [EMAIL PROTECTED]


XML for input:

<root>
        <a>
                <b/>
                <b/>
        </a>
        <a>
                <b/>
                <b/>
                <b/>
                <b/>
        </a>
</root>

XSL:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
 version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>

        <xsl:output method="xml" omit-xml-declaration="yes"/>

        <xsl:template match="/root">
                <xsl:apply-templates select="a" />
        </xsl:template>

        <!-- 1 -->
        <xsl:template match="a">
                <xsl:variable name="position" select="position()"/>
                <xsl:message>a->$position '<xsl:value-of 
select="$position"/>'</xsl:message>
                <xsl:message>a->position() '<xsl:value-of 
select="position()"/>'</xsl:message>
                <xsl:apply-templates select="b">
<!-- !!!! -->           <xsl:with-param name="lastpos" select="position()"/>
                </xsl:apply-templates>
        </xsl:template>

        <!-- 2 -->
        <xsl:template match="b">
                <xsl:param name="lastpos" />
                <xsl:message>b->lastpos '<xsl:value-of 
select="$lastpos"/>'</xsl:message>
                <xsl:message>b->position() '<xsl:value-of 
select="position()"/>'</xsl:message>
        </xsl:template>
</xsl:stylesheet>

Explanation:
When parameter is passed from template [1] to template [2], value of position()
function is calculated as 0, which is wrong. When $position is used instead of
position() in with-param select expression, correct value is passed to the
template [2].

This behaviour is specific to version 2.2.0 and all this worked fine in 2.1.0.

Reply via email to