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:
- In XSLT how do I increment a global variable from a different scope?
- Increment a value in XSLT
- Use recursion effectively in XSL
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.