检查XSLT中是否存在XML节点

时间:2016-05-03 22:57:43

标签: xml xslt xmlnode

是否有更好的方法来查找XML节点是否存在(在XSLT中)而不是使用:

<xsl:choose>
  <xsl:when test="...........">body node exists</xsl:when>
  <xsl:otherwise>body node missing</xsl:otherwise>
</xsl:choose>

1 个答案:

答案 0 :(得分:10)

xsl:choose

的替代方案

更好地定义 ; xsl:choose很好地涵盖了条件表达式。 更好要求根据某些标准进行衡量,而不提供任何标准。不过,这里有一些您可以根据需要评估的替代方案:

XSLT 1.0

<xsl:if test="/path/to/node">node exists</xsl:if>
<xsl:if test="not(/path/to/node)">node missing</xsl:if>

XSLT 2.0

<xsl:value-of select="if (/path/to/node) then 'node exists' else 'node missing'"/>
相关问题