开发者

How to concat two variables in different scopes?

开发者 https://www.devze.com 2022-12-10 23:13 出处:网络
I have the following scenario: <xsl:variable name=\"var1\" select=\"\'SOME_DATA1\'\" /> <xsl:if test=\"\'some_condition\'\">

I have the following scenario:

<xsl:variable name="var1" select="'SOME_DATA1'" />
<xsl:if test="'some_condition'">
                <xsl:variable name="var2" >
                    <xsl:value-of select="'SOME_DATA2'"/>
       开发者_如何学编程         </xsl:variable>
</xsl:if>
<data> <!-- I need here to concat var1 with var2 --> </data>


How about:

<data>
  <xsl:variable name="var1" select="'SOME_DATA1'" />
  <xsl:text><xsl:value-of select="var1"/></xsl:text>
  <xsl:if test="'some_condition'">
     <xsl:variable name="var2" >
        <xsl:value-of select="'SOME_DATA2'"/>
     </xsl:variable>
     <xsl:text><xsl:value-of select="var2"/></xsl:text>
  </xsl:if>
</data>

The way you wrote it, var2 does not exist after the /xsl:if.

Another way would be like this:

<xsl:variable name="var1" select="'SOME_DATA1'" />
<xsl:variable name="var2" >
  <xsl:if test="'some_condition'">
     <xsl:value-of select="'SOME_DATA2'"/>
  </xsl:if>
</xsl:variable>
<data> <!-- Use var1 and var2 here --> </data>

In this way, you have a var2 regarardeless of the condition, but it is empty if the condition is false. And you still have the variable after the condition.

0

精彩评论

暂无评论...
验证码 换一张
取 消