fn:normalize-space function

The fn:normalize-space function strips leading and trailing whitespace characters from a string and replaces multiple consecutive whitespace characters in the string with a single blank character.

Syntax

Read syntax diagramSkip visual syntax diagramfn:normalize-space(source-string)
source-string
A string in which whitespace is to be normalized.

source-string is an xs:string value or the empty sequence.

If source-string is not specified, the argument of fn:normalize-space is the current context item, which is converted to an xs:string value by using the fn:string function.

Returned value

The returned value is the xs:string value that results when the following operations are performed on source-string:
  • Leading and trailing whitespace characters are removed.
  • Each internal sequence of one or more adjacent whitespace characters is replaced by a single space (U+0020) character.
Whitespace characters are the space character, (U+0020), carriage return, (U+000D), line feed, (U+000A), and tab (U+0009).

If source-string is the empty sequence, a string of length 0 is returned.

Example

The following function removes extra whitespace characters from the string "a b c d ".
fn:normalize-space(" a b c d " )

The returned value is "a b c d".