【发布时间】:2016-08-29 04:26:34
【问题描述】:
是否有更好的方法来查找 XML 节点是否存在(在 XSLT 中)而不是使用:
<xsl:choose>
<xsl:when test="...........">body node exists</xsl:when>
<xsl:otherwise>body node missing</xsl:otherwise>
</xsl:choose>
【问题讨论】:
是否有更好的方法来查找 XML 节点是否存在(在 XSLT 中)而不是使用:
<xsl:choose>
<xsl:when test="...........">body node exists</xsl:when>
<xsl:otherwise>body node missing</xsl:otherwise>
</xsl:choose>
【问题讨论】:
xsl:choose 的替代品
定义更好; xsl:choose 很好地涵盖了条件表达式。 更好需要根据一些标准进行衡量,但没有提供任何标准。不过,您可以根据自己的需要评估以下一些替代方案:
<xsl:if test="/path/to/node">node exists</xsl:if>
<xsl:if test="not(/path/to/node)">node missing</xsl:if>
<xsl:value-of select="if (/path/to/node) then 'node exists' else 'node missing'"/>
【讨论】: