In this respect XSLT is exactly like other block structured languages, you would get the same error in C or Java if you did
if (2=2) {
int x = 3;
}
print(x);
The answer is to use
<xsl:variable name="x">
<xsl:choose>
<xsl:when test="2=2">
<xsl:value-of select="3"/>
</xsl:when>
</xsl:choose>
</xsl:variable>
or in 2.0
<xsl:variable name="x" select="if (2=2) then 3 else 0"/>
Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference