XPath/XQuery normalize-space function


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


) as xs:string
$arg as xs:string?
) 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.


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 .

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


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 "".

Error Conditions

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


The definition of whitespace is unchanged in . It is repeated here for convenience:

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