Returns the argument string with the leading, trailing, and repeating white spaces stripped.
White space is normalized by stripping leading and trailing white space and replacing sequences of white space characters with a single space. If the argument is omitted, the string-value of the context node is normalized and returned.
The following function call returns "abc def":
normalize-space(" abc def ")
If an argument is not of the type string, it is first converted to a string and then evaluated. See the example below.
If an argument is not of type string, it is first converted to a string using the string() function and then the result of that conversion is evaluated.
|Stringconversions for node sets that are passed as arguments to this function may yield unexpected results. For more information, see string Function.|
This function is case-sensitive.
The following example normalizes a block of text string with unnormalized white spaces (tabs, leading and trailing spaces, and multiple spaces between words. The text string is the value of an
XML File (normSpace.xml)
XSLT File (normSpace.xsl)
<?xml version='1.0'?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="xml" omit-xml-declaration="yes"/> <xsl:template match="/text"> Unnormalized: "<xsl:value-of select='.'/>" Normalized: "<xsl:value-of select='normalize-space()'/>" </xsl:template> </xsl:stylesheet>
This XSLT produces the following output:
This is a
test, with a lot of
irregular spacing and
waiting to be normalizaed.
"This is a test, with a lot of irregular spacing and waiting to be normalized."