How to change or reassign a variable in XSLT?

Variables in XSLT may only be assigned a value once. This is done by design. See Why Functional languages? for an appreciation of the motivation in general.

Rather than reassign a variable, write conditionals against the input document directly, or call a function (or named template) recursively with varying local parameters.

Anything you need to do can be done with an approach that does not require reassignment of variables. To receive a more specific answer, provide a more specific question.

See also:


Just use multiple variables. Here's your example made to work...

    <xsl:variable name="variable1" select="'N'" />
    ....
    <xsl:variable name="variable2">
        <xsl:choose>
            <xsl:when test="@tip = '2' and $variable1 != 'Y'">
                <xsl:value-of select="'Y'" />
            </xsl:when>
            <xsl:otherwise>
                <xsl:value-of select="$variable1" />
            </xsl:otherwise>
        </xsl:choose>
    </xsl:variable>

You cannot - 'variables' in XSLT are actually more like constants in other languages, they cannot change value.

Tags:

Xml

Xslt