<html>
<head>
<title>normalize-space() Function</title>
</head>
<body bgcolor="#FFFFFF" text="#000000">
<div id="Description">
<table cellpadding="0" cellspacing="0" border="0" width="100%" class="main">
<tr>
<td valign="top" class="NAME">normalize-space() Function</td>
<td valign="top" class="COMPATIBILITY">&nbsp;</td>
</tr>
<tr>
<td colspan="2" class="divider"><img src="dwres:18084" width="100%" height="1"></td>
</tr>
<tr>
<td valign="top" colspan="2" class="description">
Removes extra whitespace from its argument string.</td></tr>
<tr>
<td colspan="2" class="CLEARSEPARATION">&nbsp;</td>
</tr>
<tr>
<td colspan="2" class="TITLE">Inputs</td>
</tr>
<tr>
<td colspan="2" class="description">
<p>An optional string. If the argument is omitted, the <span class="LITERAL">normalize-space()</span> function uses the string value of the context node. </p>
</td>
</tr>
<tr>
<td colspan="2" class="CLEARSEPARATION">&nbsp;</td>
</tr>
<tr>
<td colspan="2" class="TITLE">Output</td>
</tr>
<tr>
<td colspan="2" class="description">
<p>The argument string, with whitespace removed as follows:</p>
<ul>
        <dd>All leading whitespace is removed.</p>
        </li>
        <dd>All trailing whitespace is removed.</p>
        </li>
        <dd>Within the string, any sequence of whitespace characters is replaced with a single space.</p>
        </li>
      </ul>
</td>
</tr>
<tr>
<td colspan="2" class="CLEARSEPARATION">&nbsp;</td>
</tr>
<tr>
<td colspan="2" class="TITLE">Defined in</td>
</tr>
<tr>
<td colspan="2" class="description">
<p>XPath section 4.2, String Functions.</p>
</td>
</tr>
<tr>
<td colspan="2" class="CLEARSEPARATION">&nbsp;</td>
</tr>
<tr>
<td colspan="2" class="TITLE">Example</td>
</tr>
<tr>
<td colspan="2" class="description">
<p>Here is a short example that demonstrates how <span class="LITERAL">normalize-space()</span> works:</p>
<span class="PROGRAMLISTING"><pre>
&lt;?xml version="1.0"?&gt;
&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;

  &lt;xsl:output method="text"/&gt;

  &lt;xsl:variable name="newline"&gt;
&lt;xsl:text&gt;
&lt;/xsl:text&gt;
  &lt;/xsl:variable&gt;

<!--<?troff .Nd 10?>-->
  &lt;xsl:variable name="testString"&gt;
    &lt;xsl:text&gt;                 This
is


a string
with lots of


whitespace.

&lt;/xsl:text&gt;
    &lt;/xsl:variable&gt;

  &lt;xsl:template match="/"&gt;
    &lt;xsl:value-of select="$newline"/&gt;
    &lt;xsl:text&gt;Tests of the normalize-space() function:&lt;/xsl:text&gt;

    &lt;xsl:value-of select="$newline"/&gt;
    &lt;xsl:value-of select="$newline"/&gt;
    &lt;xsl:text&gt;   normalize-space('       Hello,            World!')="&lt;/xsl:text&gt;
    &lt;xsl:value-of select="normalize-space('       Hello,            World!')"/&gt;
    &lt;xsl:text&gt;"&lt;/xsl:text&gt;
    &lt;xsl:value-of select="$newline"/&gt;
    &lt;xsl:text&gt;   normalize-space($newline)="&lt;/xsl:text&gt;
    &lt;xsl:value-of select="normalize-space($newline)"/&gt;
    &lt;xsl:text&gt;"&lt;/xsl:text&gt;
    &lt;xsl:value-of select="$newline"/&gt;
    &lt;xsl:text&gt;   normalize-space($testString)="&lt;/xsl:text&gt;
    &lt;xsl:value-of select="normalize-space($testString)"/&gt;
    &lt;xsl:text&gt;"&lt;/xsl:text&gt;
    &lt;xsl:value-of select="$newline"/&gt;
  &lt;/xsl:template&gt;

&lt;/xsl:stylesheet&gt;</pre></span>
<p>The stylesheet generates this output:</p>
<span class="PROGRAMLISTING"><pre>

Tests of the normalize-space() function:

   normalize-space('       Hello,            World!')="Hello, World!"
   normalize-space($newline)="
   normalize-space($testString)="This is a string with lots of whitespace."
</pre></span>
</td>
</tr>
</table>
</div>
</body>
</html>