August 2001
Intermediate to advanced
480 pages
11h 16m
English
normalize-space() Function — Removes extra whitespace from its argument string.
stringnormalize-space(string?)
An optional string. If the argument is omitted, the normalize-space() function uses the string value of the context node.
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.
XPath section 4.2, String Functions.
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)"/> ...