# xf:normalize-space

Removes the leading and trailing white space and replaces the duplicate white space characters by a single space from $string-var.

As part of the removal process, the following steps occur:

1. All occurrences of tabs (#x9), line feeds (#xA) and carriage returns (#xD) are replaced with spaces (#x20).
2. Contiguous sequences of spaces (#x20) are collapsed to a single space (#x20)
3. Leading and trailing spaces (#x20) are removed.

If the value of $string-var is the empty sequence, the empty sequence is returned. The empty sequence is a sequence containing zero items (), which is similar to null in SQL.

### Signatures

xf:normalize-space(xs:string? $string-var) —> xs:string?

### Arguments

Data Type | Argument | Description
--- | --- | ---
xs:string? | $string-var | Represents the string for conversion.

### Returns

Returns the $string-var after it has gone through the white space removal process (described above).

### Examples

#### Collapse Spaces

As part of the conversion process, contiguous sequences of spaces (#x20) are collapsed to a single space (#x20) and leading and trailing spaces (#x20) are removed, as shown in the following example query:

    <result>{xf:normalize-space("   x   y   z   ")}</result>

The preceding query, generates the following XML result:

    <result>x y z</result>

#### Pass in Null

Invoking normalize-space(()) returns the null string as shown in the following example query:

    <result>{xf:normalize-space(())}</result>

Note: The string: () is the empty sequence (similar to a SQL null) which is a sequence containing zero items.

The preceding query generates the following result:

    <result/>

Related Topics

W3C normalize-space function description.