10

我想在 Xslt 中检查当前节点的父节点是否为根节点。我该怎么做?请指导我摆脱这个问题......

谢谢和问候, P.SARAVANAN

4

2 回答 2

9

在 XPath 1.0 (XSLT 1.0) 中

not(parent::*)

或者您可以使用:

generate-id(..) = generate-id(/)

在 XPath 2.0 (XSLT 2.0) 中

.. is root()
于 2011-09-07T13:25:14.103 回答
8

您可以使用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>
于 2011-09-07T05:52:34.973 回答