开发者

How to concat two variables in different scopes?

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜