Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
.NET Framework 3.5
XPath Reference
XPath Functions
 normalize-space Function
Collapse All/Expand All Collapse All
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
normalize-space Function

Returns the argument string with the leading, trailing, and repeating white spaces stripped.

string normalize-space(string)

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.

Caution noteCaution

String conversions 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 <text> element.

Xml
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" 

href="normalizeSpace.xsl"?>      
<text>
    This is a
  test, with a   lot    of 
    irregular  spacing and
    waiting to be      normalizaed.


</text>
Xml
<?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:

Unormalized:

"

This is a

test, with a lot of

irregular spacing and

waiting to be normalizaed.

"

Normalized:

"This is a test, with a lot of irregular spacing and waiting to be normalized."

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks | Privacy Statement | Site Feedback
Page view tracker