When I have this in xsl:
<xsl:choose>
<xsl:when test="something > 0">
<xsl:variable name="myVar" select="true()"/>
</xsl:when>
<xsl:otherwise>
<xsl:variable name="myVar" select="false()"/>
</xsl:otherwise>
</xsl:choose>
How can I then print out the value of “myVar”? Or more importantly, how can I use this boolean in another choose statement?
This is quite wrong and useless, because the variable
$myVargoes out of scope immediately.One correct way to conditionally assign to the variable is:
However, you really don’t need this — much simpler is:
Use:
Here is a simple example:
And here is a complete example:
when this transformation is applied on the following XML document:
the wanted, correct result is produced: