I can't get this to work... I simply want to change the value of a globally defined variable:
<xsl:variable name="isBusiness"></xsl:variable>
<xsl:choose>
<xsl:when test="yes this is a business">
<xsl:variable name="isBusiness">true</xsl:variable>
</xsl:when>
<xsl:otherwise>
<xsl:variable name="isBusiness">false</xsl:variable>
</xsl:otherwise>
</xsl:choose>
Obviously the code is invalid because is already defined, but how would I change the value?
Variables in XSLT are not really variables, as their values cannot be changed. They resemble constants from conventional programming languages. The only way in which a variable can be changed is by declaring it inside a for-each loop, in which case its value will be updated for every iteration.
If the argument is a boolean value, the value true is converted to the number 1 ; the value false is converted to the number 0 . If the argument is a node-set, the node-set is converted to a string as if it were passed to the string() function, then that string is converted to a number like any other string.
Definition and Usage. The <xsl:text> element is used to write literal text to the output. Tip: This element may contain literal text, entity references, and #PCDATA.
Definition and Usage. The <xsl:value-of> element extracts the value of a selected node. The <xsl:value-of> element can be used to select the value of an XML element and add it to the output.
Check this link out:
http://www.dpawson.co.uk/xsl/sect2/N8090.html#d10874e187
Basically, your code should look like this:
<xsl:variable name="x">
<xsl:choose>
<xsl:when test="a">z</xsl:when>
<xsl:when test="b">zz</xsl:when>
<xsl:otherwise>zzz</xsl:otherwise>
</xsl:choose>
</xsl:variable>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With