Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change <xsl:variable> value

Tags:

xml

xslt

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?

like image 964
FaNIX Avatar asked Jun 28 '11 01:06

FaNIX


People also ask

How do you change a variable value in XSLT?

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.

What is Number () in XSLT?

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.

What is text () in XSLT?

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.

What is xsl value?

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.


1 Answers

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>
like image 105
code4life Avatar answered Oct 07 '22 16:10

code4life