如何在XSL中修改变量的值?

时间:2022-05-20 23:38:34

I have a xsl file which is fetching data and storing in a variables .I have a value 1 stored in a variable . Now i want to modify the variable value i.e. if it contains 1 it should be replaced by activated . How can i do it ?

我有一个xsl文件,它获取数据并存储在变量中。我有一个存储在变量中的值1。现在我想修改变量值,即如果它包含1,则应该被激活替换。我该怎么做 ?

Thanks in advance

提前致谢

1 个解决方案

#1


5  

Once you have set a variable's value, you cannot change or modify that value!

设置变量值后,无法更改或修改该值!

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的值),它将在您的输出中放置激活值。

<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" />

#1


5  

Once you have set a variable's value, you cannot change or modify that value!

设置变量值后,无法更改或修改该值!

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的值),它将在您的输出中放置激活值。

<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" />