fn:normalize-space

Returns the value of $arg with leading and trailing whitespace removed, and sequences of internal whitespace reduced to a single space character.

Signatures

fn:normalize-space() as xs:string
fn:normalize-space($arg as xs:string?) 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

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

The function returns a string constructed by stripping leading and trailing whitespace from the value of $arg, and replacing sequences of one or more adjacent whitespace characters with a single space, #x20.

The whitespace characters are defined in the metasymbol S (Production 3) of [XML 1.0].

If no argument is supplied, then $arg defaults to the string value (calculated using fn:string) of the context item (.).

Error Conditions

If no argument is supplied and the context item is absent then a dynamic error is raised: [ERRXPDY0002].

Notes

The definition of whitespace is unchanged in [XML 1.1]. It is repeated here for convenience:

S ::= (#x20 | #x9 | #xD | #xA)+

Examples

The expression fn:normalize-space(" The    wealthy curled darlings                                         of    our    nation. ") returns "The wealthy curled darlings of our nation.".

The expression fn:normalize-space(()) returns "".