Description
The fn:root function returns a document node if the $arg node is part of a document, but it may also return an element if the $arg node is not part of a document.
Calling the fn:root function is similar to starting a path with / or /. It is more flexible in that it can appear anywhere in a path or other expression. Also, unlike starting with a path with /, the fn:root function does not require the root to be a document node; it could be an element in the case of a document fragment.
This description is © Copyright 2007, Priscilla Walmsley. It is excerpted from the book XQuery by Priscilla Walmsley, O'Reilly, 2007. For a complete explanation of this function, please refer to Appendix A of the book. Arguments and Return TypeName | Type | Description |
$arg |
node()? |
the node to find the root of |
return value |
node()? |
Exampleslet $in-xml := | <a><x>123</x></a> | return |
XQuery Example | Results |
---|
root(
doc('http://www.datypic.com/functx./input/order.xml')
//item[1]) |
The document node of order.xml |
root($in-xml/x) |
<a>
<x>123</x>
</a> |
History |
Recommended Reading:
|