XPath/XQuery string function


Returns the value of $arg represented as an xs:string.


) as xs:string
$arg as item()?
) as xs:string


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.


In the zero-argument version of the function, $arg defaults to the context item. That is, calling fn:string() is equivalent to calling fn:string(.).

If $arg is the empty sequence, the function returns the zero-length string.

If $arg is a node, the function returns the string value of the node, as obtained using the dm:string-value accessor defined in (see ).

If $arg is an atomic value, the function returns the result of the expression $arg cast as xs:string (see ).

In all other cases, a dynamic error occurs (see below).


The expression string(23) returns "23".

The expression string(false()) returns "false".

The expression string("Paris") returns "Paris".

The expression string((1, 2, 3)) returns .

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

The expression string(abs#1) returns .

let $para :=

The expression string($para) returns "In a hole in the ground there lived a hobbit.".

Error Conditions

A dynamic error is raised by the zero-argument version of the function if the context item is absent.

A type error is raised if $arg is a function item (this includes maps and arrays).


Every node has a string value, even an element with element-only content (which has no typed value). Moreover, casting an atomic value to a string always succeeds. Functions, maps, and arrays have no string value, so these are the only arguments that satisfy the type signature but cause failure.