2011-11-22 59 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