Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to check parent of current node is root node or not in xslt?

I want to check the parent of current node is root node or not in Xslt.How i do that? Please Guide me to get out of this issue...

Thanks & Regards, P.SARAVANAN

like image 624
Saravanan Avatar asked Sep 07 '11 05:09

Saravanan


2 Answers

In XPath 1.0 (XSLT 1.0):

not(parent::*)

Or you may use:

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

In XPath 2.0 (XSLT 2.0):

.. is root()
like image 73
Dimitre Novatchev Avatar answered Oct 24 '22 08:10

Dimitre Novatchev


You can use not(ancestor::*).

Usage Example:

  <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>
like image 23
Daniel Haley Avatar answered Oct 24 '22 07:10

Daniel Haley