root function
The fn:root function returns the root node of a tree to which a node belongs.
Syntax
- node
- A node or the empty sequence. The default value for node is the context node.
Returned value
If node is not the empty sequence, the returned value is the root node of the tree to which node belongs. If node is the root node of the tree, the returned value is node.
If node is the empty sequence, the returned value is the empty sequence.
Example
Suppose that some XQuery variables are defined like this:
let $f := <first>Laura</first>
let $e := <emp> {$f} <last>Brown</last> </emp>
let $doc := document {<emps>{$e}</emps>}
Example of returning the root node of an element: The following function returns the root node of the element named last:
fn:root($e/last)
The returned value is <emp><first>Laura</first><last>Brown</last></emp>.
Example
of returning the root node of a document: The following function
returns the root node of the document that is bound to the variable $doc
:
fn:root($doc)
The returned value is a document node.