我想在 Xslt 中检查当前节点的父节点是否为根节点。我该怎么做?请指导我摆脱这个问题......
谢谢和问候, P.SARAVANAN
在 XPath 1.0 (XSLT 1.0) 中:
not(parent::*)
或者您可以使用:
generate-id(..) = generate-id(/)
在 XPath 2.0 (XSLT 2.0) 中:
.. is root()
您可以使用not(ancestor::*)
.
使用示例:
<xsl:template match="node()|@*">
<xsl:if test="not(ancestor::*)">
<xsl:message>The root element is "<xsl:value-of select="name()"/>".</xsl:message>
</xsl:if>
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>