Is it possible to write an XPath expression that gets the root node of a node within a node-set with only a reference to the node?
Using "/" won't work for me because that only refers to the input document root. Also I would like it to work without a context and to use it for a general node-set that may be created dynamically during processing.
For example...
<xsl:function name="my:getRoot">
<xsl:param name="n" />
<xsl:variable name="rootnode" select="some_solution($n)"/>
</xsl:function>
Thanks for the help.
A node set is a set of nodes. When you write an XPath expression to return one or more nodes, you call these nodes a node set. For example, if you use the following expression to return a node called title , you will have a set of nodes all called title (assuming there's more than one record).
XPath stands for XML Path Language. It uses a non-XML syntax to provide a flexible way of addressing (pointing to) different parts of an XML document. It can also be used to test addressed nodes within a document to determine whether they match a pattern or not.
XPath uses path expressions to select nodes or node-sets in an XML document. These path expressions look very much like the expressions you see when you work with a traditional computer file system. XPath expressions can be used in JavaScript, Java, XML Schema, PHP, Python, C and C++, and lots of other languages.
In XPath 1.0 use:
ancestor-or-self::node()[last()]
This selects the most distant of the ancestors of the current node -- which is its document-node.
In XPath 2.0 use:
root(.)
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