我想检查当前节点的父节点是否是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>