我有一个关于xsl的问题,我正在尝试使用xsl:choose。下面是代码片段。问题是<xsl:otherwise>标记总是会触发,这让我相信<xsl:when>没有正确计算。
有线索知道我哪里做错了吗?
<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> 发布于 2011-11-22 22:44:29
尝试将[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元素。
另外,我假设你的源元素看起来像这样:
<node>
<Property Name="RecoveryModel">Full</Property>
<node>https://stackoverflow.com/questions/8228561
复制相似问题