fn:root( [$arg as node()?] ) as node()?
Returns the root of the tree to which $arg belongs. This will usually, but not necessarily, be a document node.
If $arg is the empty sequence, the empty sequence is returned.
If $arg is a document node, $arg is returned.
If the function is called without an argument, the context item is used as the default argument. If the context item is undefined an error is raised: [err:XPDY0002]. If the context item is not a node an error is raised: [err:XPTY0004].
Parameters | |
---|---|
arg | The node whose root node will be returned. |
Assume the following variable definitions: let $i := <tool>wrench</tool> let $o := <order> {$i} <quantity>5</quantity> </order> let $odoc := document {$o} let $newi := $o/tool fn:root($i) returns $i fn:root($o/quantity) returns $o fn:root($odoc//quantity) returns $odoc fn:root($newi) returns $o
var doc = fn.head(xdmp.unquote('<a><quantity>5.0</quantity></a>') ); var elem = doc.root; fn.root(elem).xpath("/a/quantity"); => <quantity>5.0</quantity>
Stack Overflow: Get the most useful answers to questions from the MarkLogic community, or ask your own question.