XSL条件语句

时间:2011-12-30 15:50:18

标签: xslt conditional

我对此声明有疑问:

<xsl:choose>
 <xsl:when test="cars[@id='1']">    
      <xsl:choose>
        <xsl:when test="cars[@id='1']='1'">true</xsl:when>
        <xsl:otherwise>false</xsl:otherwise>
      </xsl:choose>
 </xsl:when>
 <xsl:otherwise>
      true
 </xsl:otherwise>
</xsl:choose>

&#34;真&#34;即使我的&#34;汽车[@id =&#39; 1&#39;])=&#39; 0&#39; (不存在)。 谢谢你的帮助

2 个答案:

答案 0 :(得分:1)

您的输入是否完全匹配?

<xsl:choose>
 <xsl:when test="cars[@id='1']">    
      <xsl:choose>
        <xsl:when test="cars[@id='1']='1'">true</xsl:when>
        <xsl:otherwise>false</xsl:otherwise>
      </xsl:choose>
 </xsl:when>
 <xsl:otherwise>
      true <!-- change this and see what it returns -->
 </xsl:otherwise>
</xsl:choose>

答案 1 :(得分:0)

根据所提供的信息,可能有许多原因。普通初学者的错误会提出以下可能性:

(a)'cars'元素实际上在命名空间中

(b)执行此代码的上下文节点不是'cars'元素的父元素