How can I reassign a value to a variable previously assigned? I need it to works like this:
<xsl:variable name="variable2" select="'N'" />
....
<xsl:when test="@tip = '2' and $variable2 != 'Y'">
<xsl:variable name="variable2" select="'Y'" />
</xsl:when>
You cannot - 'variables' in XSLT are actually more like constants in other languages, they cannot change value.
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:
Reassignable variables can be declared using an accumulator, available from XSLT version 3.0. :
Just use multiple variables. Here's your example made to work...