[英]How to modify the value of variable in XSL?
I have a xsl file which is fetching data and storing in a variables .I have a value 1 stored in a variable . 我有一个xsl文件,它获取数据并存储在变量中。我有一个存储在变量中的值1。 Now i want to modify the variable value ie if it contains 1 it should be replaced by activated . 现在我想修改变量值,即如果它包含1则应该被激活替换。 How can i do it ? 我该怎么做 ?
Thanks in advance 提前致谢
Once you have set a variable's value, you cannot change or modify that value! 设置变量值后,无法更改或修改该值!
http://www.w3schools.com/xsl/el_variable.asp http://www.w3schools.com/xsl/el_variable.asp
Let's say you have this: 假设你有这个:
<xsl:variable name="var">1</xsl:variable>
Then, everywhere you need, you can use the following section (works in XSLT 1.0) and it will put activated
value in your output if $var
is equal to 1 (or the value of $var
otherwise). 然后,在您需要的任何地方,您可以使用以下部分(在XSLT 1.0中工作),如果$var
等于1(否则为$var
的值),它将在您的输出中放置activated
值。
<xsl:choose>
<xsl:when test="$var=1">activated</xsl:when>
<xsl:otherwise><xsl:value-of select="$var"/></xsl:otherwise>
</xsl:choose>
Or you can declare new variable: 或者您可以声明新变量:
<xsl:variable name="var2">
<xsl:choose>
<xsl:when test="$var=1">activated</xsl:when>
<xsl:otherwise><xsl:value-of select="$var"/></xsl:otherwise>
</xsl:choose>
</xsl:variable>
In this case, you will have to use instruction to print it in the output: 在这种情况下,您将必须使用指令在输出中打印它:
<xsl:value-of select="$var2" />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.