Skip to Content
XSLT
book

XSLT

by Doug Tidwell
August 2001
Intermediate to advanced
480 pages
11h 16m
English
O'Reilly Media, Inc.
Content preview from XSLT

Name

normalize-space() Function — Removes extra whitespace from its argument string.

Synopsis

string normalize-space(
               string?
               )

Inputs

An optional string. If the argument is omitted, the normalize-space() function uses the string value of the context node.

Output

The argument string, with whitespace removed as follows:

  • All leading whitespace is removed.

  • All trailing whitespace is removed.

  • Within the string, any sequence of whitespace characters is replaced with a single space.

Defined in

XPath section 4.2, String Functions.

Example

Here is a short example that demonstrates how normalize-space() works:

<?xml version="1.0"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="text"/> <xsl:variable name="newline"> <xsl:text> </xsl:text> </xsl:variable> <xsl:variable name="testString"> <xsl:text> This is a string with lots of whitespace. </xsl:text> </xsl:variable> <xsl:template match="/"> <xsl:value-of select="$newline"/> <xsl:text>Tests of the normalize-space() function:</xsl:text> <xsl:value-of select="$newline"/> <xsl:value-of select="$newline"/> <xsl:text> normalize-space(' Hello, World!')="</xsl:text> <xsl:value-of select="normalize-space(' Hello, World!')"/> <xsl:text>"</xsl:text> <xsl:value-of select="$newline"/> <xsl:text> normalize-space($newline)="</xsl:text> <xsl:value-of select="normalize-space($newline)"/> <xsl:text>"</xsl:text> <xsl:value-of select="$newline"/> <xsl:text> normalize-space($testString)="</xsl:text> <xsl:value-of select="normalize-space($testString)"/> ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Learning XSLT

Learning XSLT

Michael Fitzgerald
Inside XSLT

Inside XSLT

Steven Holzner
XSLT Cookbook

XSLT Cookbook

Sal Mangano

Publisher Resources

ISBN: 0596000537Supplemental ContentCatalog PageErrata