XPath/XQuery data function

Summary

Returns the result of atomizing a sequence. This process flattens arrays, and replaces nodes by their typed values.

Signatures

fn:data(
) as xs:anyAtomicType*
fn:data(
$arg as item()*
) as xs:anyAtomicType*

Properties

The zero-argument form of this function is deterministic, context-dependent, and focus-dependent.
The one-argument form of this function is deterministic, context-independent, and focus-independent.

Rules

If the argument is omitted, it defaults to the context item (.). 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 result of fn:data is the sequence of atomic values produced by applying the following rules to each item in $arg:

  • If the item is an atomic value, it is appended to the result sequence.

  • If the item is a node, the typed value of the node is appended to the result sequence. The typed value is a sequence of zero or more atomic values: specifically, the result of the dm:typed-value accessor as defined in (See ).

  • If the item is an array, the result of applying fn:data to each member of the array, in order, is appended to the result sequence.

Examples

The expression data(123) returns 123.

The expression data((123, 456)) returns 123, 456.

The expression data([[1,2],[3,4]]) returns 1, 2, 3, 4.

let $para :=

The expression data($para) returns xs:untypedAtomic("In a hole in the ground there lived a hobbit.").

The expression data($para/term/@author) returns xs:untypedAtomic("Tolkien").

The expression data(abs#1) returns .

Error Conditions

A type error is raised if an item in the sequence $arg is a node that does not have a typed value.

A type error is raised if an item in the sequence $arg is a function item other than an array.

A dynamic error is raised if $arg is omitted and the context item is absent.

Notes

The process of applying the fn:data function to a sequence is referred to as atomization. In many cases an explicit call on fn:data is not required, because atomization is invoked implicitly when a node or sequence of nodes is supplied in a context where an atomic value or sequence of atomic values is required.

The result of atomizing an empty sequence is an empty sequence.

The result of atomizing an empty array is an empty sequence.