Is there any way to get access to the ROOT node from within another context?
The example above is just to show my intention. Getting access to ROOT_NODE without using '../../..' since changes in xml could break that type of selector.
XSLT
<div class="column">
<xsl:for-each select="languages/server/elem">
<!-- Context is ELEM node -->
<div>
<!-- How can I get access to the ROOT_NODE ?-->
<span class="text"><xsl:value-of select="ROOT_NODE/@title"/></span>
<!-- Print ELEM text -->
<span class="text"><xsl:value-of select="current()"/></span>
</div>
</xsl:for-each>
</div>
The expression "/
" selects the document node at the root of the tree containing the context node. (All trees in 1.0 are rooted at document nodes.)
In XSLT 2.0, root()
selects the root of the tree containing the context node whether or not the root is a document node.
To get the root of the principal source document even when the context node is a node in a different tree, bind a global variable
<xsl:variable name="principal-root" select="/"/>
which you can refer to anywhere as $principal-root
.
Oh, and as Mads Hansen points out, if by "root node" you actually mean the outermost element node, as distinct from the document node, then you would typically use "/*
".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With