Is there a better way of finding if XML node exists (in XSLT) rather than using:
有没有更好的方法来查找XML节点是否存在(在XSLT中)而不是使用:
<xsl:choose>
<xsl:when test="...........">body node exists</xsl:when>
<xsl:otherwise>body node missing</xsl:otherwise>
</xsl:choose>
1 个解决方案
#1
9
Alternatives to xsl:choose
Define better; xsl:choose
covers conditional expression quite well. Being better requires measurement against some criteria, and none were provided. Nevertheless, here are some alternatives which you can assess as you see fit:
定义更好; xsl:选择覆盖条件表达式。更好要求根据某些标准进行测量,并且没有提供任何标准。不过,这里有一些您可以根据需要评估的替代方案:
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'"/>
#1
9
Alternatives to xsl:choose
Define better; xsl:choose
covers conditional expression quite well. Being better requires measurement against some criteria, and none were provided. Nevertheless, here are some alternatives which you can assess as you see fit:
定义更好; xsl:选择覆盖条件表达式。更好要求根据某些标准进行测量,并且没有提供任何标准。不过,这里有一些您可以根据需要评估的替代方案:
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'"/>