Returns the root of the tree to which $arg
belongs. This will usually, but
not necessarily, be a document node.
fn:root
( node()
fn:root
( $arg
as node()?
node()?
If the function is called without an argument, the context item (.
) is used
as the default argument. The behavior of the function if the argument is omitted is
exactly the same as if the context item had been passed as the argument.
The function returns the value of the expression
($arg/ancestor-or-self::node())[1]
.
These examples use some variables which could be defined in as:
Or they could be defined in as:
fn:root($i)
returns the element node $i
fn:root($o/quantity)
returns the element node $o
fn:root($odoc//quantity)
returns the document node $odoc
fn:root($newi)
returns the element node $o
The final three examples could be made type-safe by wrapping their operands with
fn:exactly-one()
.
The following errors may be raised when $arg
is omitted:
If the context item is absent, dynamic error
If the context item is not a node, type error .