代码之家  ›  专栏  ›  技术社区  ›  spyderman4g63

XSL条形填充

  •  1
  • spyderman4g63  · 技术社区  · 14 年前

    是否有一种简单的去除填充的方法(前导空格和/或尾随空格)。exslt padding函数似乎只创建一定长度的padding或trim字符串。

    3 回复  |  直到 14 年前
        1
  •  1
  •   Matt Gibson    14 年前

    是否将normalize-space()用于您的工作?这也会减少字符串中的空格,例如

    "  this         string    " 
    

    将成为:

    "this string"
    

    如果你真的需要一个“修剪”功能,你也许可以 steal one from someone else who's already implemented it 使用normalize-space()…

        2
  •  2
  •   StuartLC    14 年前

    尝试规范化空间

    <xsl:value-of select='normalize-space(string)'/>
    
        3
  •  0
  •   Dimitre Novatchev    14 年前

    现在还不清楚需要什么——什么是“条形填充”?

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

    这个 FXSL library 提供方便 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'