http://zorba.io/modules/node

Description

Before using any of the functions below please remember to import the module namespace:

import module namespace node = "http://zorba.io/modules/node";

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.

Module code

Here is the actual XQuery module code.

Authors

Matthias Brantner

Version Declaration

xquery version "1.0" encoding "utf-8";

Namespaces

nodehttp://zorba.io/modules/node
verhttp://zorba.io/options/versioning

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.

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.

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.

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.

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.

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.

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.

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.

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

Computes the level of a given node in the tree.

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

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

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.

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

    the potential descendant

  • $node2

    the potential ancestor

Returns

  • xs:boolean

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

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

    the potential ancestor

  • $node2

    the potential descendant

Returns

  • xs:boolean

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

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

    the potential child

  • $node2

    the potential parent

Returns

  • xs:boolean

    true if $node2 is a parent 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

    the potential parent

  • $node2

    the potential child

Returns

  • xs:boolean

    true if $node2 is a child of $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

    the potential preceding-sibling

  • $node2

    the potential following-sibling

Returns

  • xs:boolean

    true if $node2 is a following-sibling of $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

    the potential following-sibling

  • $node2

    the potential preceding-sibling

Returns

  • xs:boolean

    true if $node2 is a preceding-sibling 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

    the potential preceding node

  • $node2

    the potential following node

Returns

  • xs:boolean

    true if $node2 is following the node $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

    the potential following node

  • $node2

    the potential preceding node

Returns

  • xs:boolean

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

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

    the node for which the level should be computed

Returns

  • xs:integer

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

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

    the first node

  • $node2

    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.

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

    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.