fn:string

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

Signatures

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

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

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 [Data Model (XDM) 3.1] (see string-value Accessor).

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

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

Error Conditions

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

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

Notes

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.

Examples

The expression string(23) returns "23".

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

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

The expression string((1, 2, 3)) raises error XPTY0004.

The expression string([[1, 2], [3, 4]]) raises error FOTY0014.

The expression string(abs#1) raises error FOTY0014.

let $para := 
<para>In a hole in the ground there lived a <term author="Tolkien">hobbit</term>.</para>
         

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