簡體   English   中英

檢查XSLT中是否存在XML節點

[英]Check if XML node exists in XSLT

是否有更好的方法來查找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: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'"/>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM