XSL 条带填充

发布于 2024-09-18 23:48:18 字数 66 浏览 3 评论 0原文

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

Is there a simple way to strip padding, IE leading and/or trailing white space. EXSLT padding function seems to only create padding or trim strings to a certain length.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

薄荷→糖丶微凉 2024-09-25 23:48:18

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

"  this         string    " 

将变为:

"this string"

如果您确实需要“修剪”功能,您可能可以 从已经实现了它的其他人那里偷一个与 normalizse-space()...

Would normalize-space() do the job for you? This will also reduce spaces inside the string, e.g.

"  this         string    " 

would become:

"this string"

If you really need a "trim" function, you can probably steal one from someone else who's already implemented it with normalizse-space()...

时光是把杀猪刀 2024-09-25 23:48:18

尝试标准化空间

<xsl:value-of select='normalize-space(string)'/>

Try normalize-space

<xsl:value-of select='normalize-space(string)'/>
一百个冬季 2024-09-25 23:48:18

目前还不清楚想要什么——什么是“条状填充”?

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

FXSL库提供了一个方便的trim< /code> 模板函数

此转换:

<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'

It isn't clear what is wanted -- what is "strip padding"?

If you meant the trim() function, then

The FXSL library provides a convenient trim template function.

This transformation:

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

when applied on this XML document:

<someText>

   This is    some text   

</someText>

produces the wanted, correct result:

'This is    some text'
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文