【问题标题】:Check if XML node exists in XSLT检查 XSLT 中是否存在 XML 节点
【发布时间】: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 xmlnode


    【解决方案1】:

    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'"/>
    

    【讨论】:

      猜你喜欢
      • 2011-06-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-08
      • 1970-01-01
      • 2023-04-03
      • 1970-01-01
      相关资源
      最近更新 更多