首页 > 其他 > 详细

xsl: normalize-space(string str) 函数

时间:2014-03-11 15:17:45      阅读:504      评论:0      收藏:0      [点我收藏+]

本文出自http://technet.microsoft.com/zh-cn/magazine/ms256063%28VS.90%29.aspx

 

通过去掉前导和尾随空白并使用单个空格替换一系列空白字符,使空白标准化。 如果省略了该参数,上下文节点的字符串值将标准化并返回。

以下函数调用返回“abc def”:

normalize-space(" abc def ")

如果参数不是字符串类型,将先转换成字符串再计算。 请参见下面的示例。

如果参数不是字符串类型,将先使用 string() 函数转换为字符串,然后计算该转换的结果。

bubuko.com,布布扣警告

作为参数传递给此函数的节点集的字符串转换可能会产生意外的结果。 有关更多信息,请参见 string 函数

此函数区分大小写。

 

以下示例使用非标准化的空白(单词间的制表符、前导和尾随的空格以及多个空格)标准化文本字符串块。 文本字符串是 <text> 元素的值。

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>

该 XSLT 生成以下输出:

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."

xsl: normalize-space(string str) 函数,布布扣,bubuko.com

xsl: normalize-space(string str) 函数

原文:http://www.cnblogs.com/asjlove/p/3593256.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!