本文出自http://technet.microsoft.com/zh-cn/magazine/ms256063%28VS.90%29.aspx函數
經過去掉前導和尾隨空白並使用單個空格替換一系列空白字符,使空白標準化。 若是省略了該參數,上下文節點的字符串值將標準化並返回。spa
如下函數調用返回「abc def」:code
normalize-space(" abc def ")orm
若是參數不是字符串類型,將先轉換成字符串再計算。 請參見下面的示例。xml
若是參數不是字符串類型,將先使用 string() 函數轉換爲字符串,而後計算該轉換的結果。ip
![]() |
---|
做爲參數傳遞給此函數的節點集的字符串轉換可能會產生意外的結果。 有關更多信息,請參見 string 函數。ci |
此函數區分大小寫。字符串
如下示例使用非標準化的空白(單詞間的製表符、前導和尾隨的空格以及多個空格)標準化文本字符串塊。 文本字符串是 <text> 元素的值。get
<?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>
該 XSLT 生成如下輸出:string
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."