1

有没有一种简单的方法可以去除填充、IE 前导和/或尾随空格。EXSLT 填充函数似乎只创建填充或修剪字符串到一定长度。

4

3 回答 3

2

尝试规范化空间

<xsl:value-of select='normalize-space(string)'/>
于 2010-09-08T13:27:57.110 回答
1

normalize-space() 会为您完成这项工作吗?这也将减少字符串内的空格,例如

"  this         string    " 

会成为:

"this string"

如果你真的需要一个“修剪”功能,你可能会从已经用 normalizse-space()实现它的其他人那里窃取一个......

于 2010-09-08T13:27:05.303 回答
0

目前尚不清楚想要什么 - 什么是“条形填充”?

如果您的意思是 trim() 函数,那么

FXSL提供了一个方便的trim模板函数

这种转变:

<xsl:stylesheet version="1.0" 
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <xsl:import href="trim.xsl"/>

  <xsl:output method="text"/>
  <xsl:template match="/">
    '<xsl:call-template name="trim">
        <xsl:with-param name="pStr" select="string(/*)"/>
    </xsl:call-template>'
  </xsl:template>
</xsl:stylesheet>

应用于此 XML 文档时

<someText>

   This is    some text   

</someText>

产生想要的正确结果

'This is    some text'
于 2010-09-08T13:43:25.007 回答