http://zorba.io/modules/node

View as XML or JSON.

This module defines a set of function which can be used to determine (1) the relationship between two nodes (e.g. if one is the ancestor if another) and (2) properties of given nodes (e.g. their level in the tree). The same functionality can be achieved with simple XPath expressions. However, please note that using the functions in this modules instead of path expressions guarantees better performance.

Function Summary

ancestor-of ($node1 as node(), $node2 as node()) as xs:boolean external

Determines whether the node given as second argument is an ancestor of the node given as first argument.

child-of ($node1 as node(), $node2 as node()) as xs:boolean external

Determines whether the node given as second argument is a child of the node given as first argument.

copy ($input as node()*) as node()* external

Return a deep copy of every given node according to the properties specified in the static context of the invoking module.

descendant-of ($node1 as node(), $node2 as node()) as xs:boolean external

Determines whether the node given as second argument is a descendant of the node given as first argument.

following-of ($node1 as node(), $node2 as node()) as xs:boolean external

Determines whether the node given as second argument is following the node given as first argument.

following-sibling-of ($node1 as node(), $node2 as node()) as xs:boolean external

Determines whether the node given as second argument is a following-sibling of the node given as first argument.

least-common-ancestor ($node1 as node(), $node2 as node()) as node()? external

Computes the least common ancestor of two given nodes in the tree.

level ($node as node()) as xs:integer external

Computes the level of a given node in the tree.

parent-of ($node1 as node(), $node2 as node()) as xs:boolean external

Determines whether the node given as second argument is a parent of the node given as first argument.

preceding-of ($node1 as node(), $node2 as node()) as xs:boolean external

Determines whether the node given as second argument is preceding the node given as first argument.

preceding-sibling-of ($node1 as node(), $node2 as node()) as xs:boolean external

Determines whether the node given as second argument is a preceding-sibling of the node given as first argument.

Functions

ancestor-of#2

declare  function node:ancestor-of($node1 as node(), $node2 as node()) as xs:boolean external
Determines whether the node given as second argument is an ancestor of the node given as first argument.

Parameters

node1 as node()
the potential descendant
node2 as node()
the potential ancestor

Returns

xs:boolean
true if $node2 is an ancestor of $node1; false otherwise.

child-of#2

declare  function node:child-of($node1 as node(), $node2 as node()) as xs:boolean external
Determines whether the node given as second argument is a child of the node given as first argument.

Parameters

node1 as node()
the potential parent
node2 as node()
the potential child

Returns

xs:boolean
true if $node2 is a child of $node1; false otherwise.

copy#1

declare  function node:copy($input as node()*) as node()* external
Return a deep copy of every given node according to the properties specified in the static context of the invoking module.

Please note that a copy of a node is parentless.

Parameters

input as node()
the node to copy

Returns

node()*
a deep copy of every node in the input sequence or the empty sequence if $input is the empty sequence.

descendant-of#2

declare  function node:descendant-of($node1 as node(), $node2 as node()) as xs:boolean external
Determines whether the node given as second argument is a descendant of the node given as first argument.

Parameters

node1 as node()
the potential ancestor
node2 as node()
the potential descendant

Returns

xs:boolean
true if $node2 is a descendant of $node1; false otherwise.

following-of#2

declare  function node:following-of($node1 as node(), $node2 as node()) as xs:boolean external
Determines whether the node given as second argument is following the node given as first argument.

Parameters

node1 as node()
the potential preceding node
node2 as node()
the potential following node

Returns

xs:boolean
true if $node2 is following the node $node1; false otherwise.

following-sibling-of#2

declare  function node:following-sibling-of($node1 as node(), $node2 as node()) as xs:boolean external
Determines whether the node given as second argument is a following-sibling of the node given as first argument.

Parameters

node1 as node()
the potential preceding-sibling
node2 as node()
the potential following-sibling

Returns

xs:boolean
true if $node2 is a following-sibling of $node1; false otherwise.

least-common-ancestor#2

declare  function node:least-common-ancestor($node1 as node(), $node2 as node()) as node()? external
Computes the least common ancestor of two given nodes in the tree.

Parameters

node1 as node()
the first node
node2 as node()
the second node

Returns

node()?
the least common ancestor of the two given nodes or the empty sequence if the two nodes are not part of the same tree.

level#1

declare  function node:level($node as node()) as xs:integer external
Computes the level of a given node in the tree. Note: The first level has the number one.

Parameters

node as node()
the node for which the level should be computed

Returns

xs:integer
The level as xs:integer of the given node in the tree.

parent-of#2

declare  function node:parent-of($node1 as node(), $node2 as node()) as xs:boolean external
Determines whether the node given as second argument is a parent of the node given as first argument.

Parameters

node1 as node()
the potential child
node2 as node()
the potential parent

Returns

xs:boolean
true if $node2 is a parent of $node1; false otherwise.

preceding-of#2

declare  function node:preceding-of($node1 as node(), $node2 as node()) as xs:boolean external
Determines whether the node given as second argument is preceding the node given as first argument.

Parameters

node1 as node()
the potential following node
node2 as node()
the potential preceding node

Returns

xs:boolean
true if $node2 is preceding the node $node1; false otherwise.

preceding-sibling-of#2

declare  function node:preceding-sibling-of($node1 as node(), $node2 as node()) as xs:boolean external
Determines whether the node given as second argument is a preceding-sibling of the node given as first argument.

Parameters

node1 as node()
the potential following-sibling
node2 as node()
the potential preceding-sibling

Returns

xs:boolean
true if $node2 is a preceding-sibling of $node1; false otherwise.