2011-11-22 55 views
1

我有一個xsl問題,我正在嘗試使用xsl:choose。以下是摘錄。問題是<xsl:otherwise>標籤總是被觸發,這使我相信<xsl:when>沒有正確評估。xsl:choose標籤有問題

任何線索,我做錯了什麼?

<xsl:choose> 
    <xsl:when test="./Property[@Name ='RecoveryModel']='Full'"> 
    <td align="left" bgcolor="#ff00ff"> 
     <xsl:value-of select="./Property[@Name ='RecoveryModel']"/> 
    </td> 
    </xsl:when> 
    <xsl:otherwise> 
    <td><xsl:value-of select="./Property[@Name ='RecoveryModel']"/></td> 
    </xsl:otherwise> 
</xsl:choose> 

回答

1

嘗試增加[1]<xsl:when>測試是這樣的:

<xsl:choose> 
    <xsl:when test="./Property[@Name ='RecoveryModel'][1]='Full'"> 
    <td align="left" bgcolor="#ff00ff"> 
     <xsl:value-of select="./Property[@Name ='RecoveryModel']"/> 
    </td> 
    </xsl:when> 
    <xsl:otherwise> 
    <td><xsl:value-of select="./Property[@Name ='RecoveryModel']"/></td> 
    </xsl:otherwise> 
</xsl:choose> 

否則,./Property[@Name ='RecoveryModel']選擇將返回(主要是)你的情況匹配的元素(希望只是一個列表,您需要[1]選擇第一個匹配的Property元素。


另外,I '米假設你的源元素看起來像:

<node> 
    <Property Name="RecoveryModel">Full</Property> 
<node> 
+0

它不喜歡()預期的.text令牌‘EOF’發現'。 ./Property[@Name ='RecoveryModel'] - >。< - text()='Full' – sqlpadawan

+0

編輯我的答案 - 現在應該更好地工作 –

+0

工作。萬分感謝! – sqlpadawan