2017-08-17 58 views
0

「Artproof」變量爲true。 我想改變文字的顏色,如果變量爲真在XLST中聲明和初始化變量

<xsl:variable name="ArtProof" select="'True'"/>  

<xsl:choose> 
    <xsl:when test="$ArtProof = 'True'"> 
     <xsl:variable name="color_of_artproof" select="'green'"/> 
    </xsl:when> 
    <xsl:otherwise> 
     <xsl:variable name="color_of_artproof" select="'red'"/> 
    </xsl:otherwise> 
</xsl:choose> 

設置顏色的條件是:

「color_of_artproof」變量賦予空值,和文字是黑色。

回答

0

變量的作用域爲其父元素。如果在xsl:when指令中定義一個變量,則不能在另一個上下文中使用它。

嘗試類似:

<xsl:variable name="color_of_artproof"> 
    <xsl:when test="$ArtProof = 'True'">green</xsl:when> 
    <xsl:otherwise>red</xsl:otherwise> 
</xsl:variable>