xml - 检查 XSLT 中是否存在 XML 节点

标签 xml xslt xmlnode

是否有更好的方法来查找 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 很好地涵盖了条件表达式。 更好需要根据一些标准进行衡量,但没有提供。不过,您可以根据需要评估以下一些替代方案:

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

关于xml - 检查 XSLT 中是否存在 XML 节点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37015762/

相关文章:

java - 带 namespace 的 XPath - 查询未给出结果

xml使用xsl合并两个文件?

XSLT 格式数字转换百分比

XSLT 函数获取节点的 xpath

javascript - Visual Studio 创建新的 Javascript 代码段

javascript - 如何在客户端从灵活的 xml 生成 html 中的 TreeView

xml - xsl :sort an XML file using multiple elements

c# - 有什么简单的方法可以将 XML 输出从共享点 GetListItems() 转换为 DataTable

java - 如何使用java获取xml节点的属性值

xml - 使用 Powershell 的 .csproj 文件中特定节点中的节点列表