2011-06-08 81 views
2

我有兩個變量,名爲可編輯顯示我們如何根據另一個變量更改變量的值?

如果編輯true,我想顯示的值設置爲'block'

如果編輯false,我想顯示的值設置爲'none'

這是我目前:

<xsl:param name="editable" select="true()"/> 
    <xsl:choose> 
     <xsl:when test="$editable"> 
     <xsl:variable name="display" select="'block'"/> 
     </xsl:when> 
     <xsl:otherwise> 
     <xsl:variable name="display" select="'none'"/> 
     </xsl:otherwise> 
    </xsl:choose> 

上面的代碼不會的display值設置爲none

我們如何根據另一個變量更改變量的值?

回答

2

我沒有測試這一點,但對我來說,它看起來像這可能是解決這樣的範圍問題:

<xsl:param name="editable" select="true()"/> 
    <xsl:variable name="display"> 
     <xsl:choose> 
     <xsl:when test="$editable"> 
      <xsl:value-of select="'block'"/> 
     </xsl:when> 
     <xsl:otherwise> 
      <xsl:value-of select="'none'"/> 
     </xsl:otherwise> 
     </xsl:choose> 
    </xsl:variable> 
+1

你不需要'的'得到常量字符串,您可以在測試='$ editable'>塊'時寫' 2011-06-08 08:03:50

+0

@Christopher Creutzig。順便說一句,這是好的:''? – Pacerier 2011-06-08 08:26:56

+0

@Christopher Creutzig:是的,我知道;但我想保持它接近最初的例子,在這個例子中,可以輕鬆地將'block'或'non'與任何xpath函數進行交換。 – 2011-06-08 08:30:07

相關問題