带 Padding 的 XSL 左右对齐

发布于 2024-12-10 10:48:19 字数 45 浏览 6 评论 0原文

XSLT 1.0 中是否有可用的标准模板可以进行调整并将字段填充到最大长度?

Is there any standard template in XSLT 1.0 available which does justification and pad the field to max length?

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

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

发布评论

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

评论(1

我是有多爱你 2024-12-17 10:48:20

不幸的是,XSLT 没有附带填充功能,好处是,正如这篇博客文章所指出的那样,这样做非常简单:http://www.dpawson.co.uk/xsl/sect2/padding.html

(网络存档版本:http://web.archive.org/web/20171225234313/http://www.dpawson.co.uk/xsl/sect2/padding.html

例如,如果您想右填充 a您可以执行 10 个空格字符串:

<xsl:value-of 
 select="substring(concat($string, '          '), 1, 10))"/>

如果您需要左填充,您可以更改 concat 参数的顺序,如下所示:

<xsl:value-of 
 select="substring(concat('          ', $string), 1, 10))"/>

请注意,带有空格的字符串应包含与填充相同数量的字符需要,所以如果你想要一个 10 的 pad,你将需要一个 10 个空格的字符串。

Unfortunately XSLT does not comes with the padding function, the good part is that is very simple to do so as pointed by this blog post: http://www.dpawson.co.uk/xsl/sect2/padding.html

(Web archive version: http://web.archive.org/web/20171225234313/http://www.dpawson.co.uk/xsl/sect2/padding.html )

For example if you want to right pad a 10 spaces string you can do:

<xsl:value-of 
 select="substring(concat($string, '          '), 1, 10))"/>

if you need a left pad you can change the order of the concat parameters as following:

<xsl:value-of 
 select="substring(concat('          ', $string), 1, 10))"/>

Notice that the string with spaces should contain the same amount of chars as your padding is needing, so if you want a 10 pad, you will need a 10 spaces string.

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