IMPORTANT:
this is not a Support Forum! Experienced users might answer from time to time questions posted here. If you need a professional and reliable answer, or if you want to report a bug, please contact Altova Support instead.

Local XSLT Variable Options · View
chrislada
Posted: Wednesday, June 5, 2019 4:18:08 PM
Rank: Newbie

Joined: 6/5/2019
Posts: 1
I am getting a 'Parameter or variable with this name already defined name="nested-refs"' error on the following code even though the variable is local to the individual templates. I can run this code with no problem in our Linus XSL processor. Is it the case that there is a param with the same name?

Code:
<xsl:template match="item.reference">
        <xsl:value-of select="$newline"/>
        <xsl:variable name="ref-kids" select="*[local-name() != 'name.block'                                                    and local-name() != 'item.reference']"/>
        <xsl:variable name="nested-refs" select="*[local-name() = 'item.reference']"/>
        <xsl:element name="ref">
            <xsl:element name="n">
                <xsl:call-template name="get_name_label_designator"/>
            </xsl:element>
            <xsl:apply-templates select="$ref-kids"/>
        </xsl:element>
        <xsl:call-template name="process-item-references">
            <xsl:with-param name="nested-refs" select="$nested-refs"/>
        </xsl:call-template>
    </xsl:template>
    <xsl:template name="process-item-references">
        <xsl:param name="nested-refs"/>
        <xsl:for-each select="$nested-refs">
            <xsl:variable name="ref-kids" select="*[local-name() != 'name.block' and local-name() != 'item.reference']"/>
            <xsl:variable name="nested-refs" select="*[local-name() = 'item.reference']"/>
            <xsl:element name="ref">
                <xsl:element name="n">
                    <xsl:call-template name="get_name_label_designator"/>
                </xsl:element>
                <xsl:apply-templates select="$ref-kids"/>
            </xsl:element>
            <xsl:call-template name="process-item-references">
                <xsl:with-param name="nested-refs" select="$nested-refs"/>
            </xsl:call-template>
        </xsl:for-each>
    </xsl:template>

Thanks
Chris
K101
Posted: Thursday, June 6, 2019 9:41:27 AM
Rank: Advanced Member

Joined: 2/27/2009
Posts: 558
Your XSLT is invalid XSLT 1.0, but could be valid XSLT 2.0. At least, the error you mention isn't shown when you treat it as XSLT 2.0.

XSLT 1.0, you couldn't define a local variable in the same scope as another local variable or param with the same name. Apparently some XSLT 1.0 processors did not enforce this. In XSLT 2.0 it's allowed though still not recommended.
Users browsing this topic
guest

Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Use of the Altova User Forum(s) is governed by the Altova Terms of Use.