2011-06-28 35 views
11

我不能得到這個工作......我只是想更改全局定義的變量的值:如何改變的<xsl:變量>值

    <xsl:variable name="isBusiness"></xsl:variable> 
        <xsl:choose> 
         <xsl:when test="yes this is a business"> 
           <xsl:variable name="isBusiness">true</xsl:variable>       
         </xsl:when> 
         <xsl:otherwise> 
          <xsl:variable name="isBusiness">false</xsl:variable> 
         </xsl:otherwise> 
        </xsl:choose>  

顯然,代碼是無效的,因爲是已經定義,但我將如何更改值?

+1

投票關閉爲[精確複製(http://stackoverflow.com/問題/ 6436272 /如何到更新的變量值的功能於XSLT/6438323#6438323)。 –

回答

15

檢查此鏈接了:

http://www.dpawson.co.uk/xsl/sect2/N8090.html#d10874e187

基本上,你的代碼應該是這樣的:

<xsl:variable name="x"> 
    <xsl:choose> 
    <xsl:when test="a">z</xsl:when> 
    <xsl:when test="b">zz</xsl:when> 
    <xsl:otherwise>zzz</xsl:otherwise> 
    </xsl:choose> 
</xsl:variable> 
+0

是的,除了示例將值true和false綁定到x,所以它執行'x:= if(c)then true else false',可以簡化爲'x:= c'。 –

+0

@MichaelKay:對於復活舊帖子感到抱歉,但我只是再次碰到這個帖子,看到了你的評論。我想指出的是,測試標準是針對文本「是的,這是一項業務」,而不是布爾評估。 xslt表示這不是一個簡單的二元評估,而是2個或多個*項的選擇,其中只有一個對於評估是重要的。 eval的結果表示xslt上的真/假響應。乾杯! – code4life