XSL带填充的左右对齐 [英] XSL left-right justification with Padding
问题描述
XSLT 1.0中是否有任何可用的标准模板,可以将字段对齐并填充到最大长度?
Is there any standard template in XSLT 1.0 available which does justification and pad the field to max length?
谢谢, 帕布赫特(Prabhjot)
Thanks, Prabhjot
推荐答案
不幸的是,XSLT没有附带padding函数,优点是这样做非常简单,如本博客文章所指出:
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.
例如,如果您想右填充10个空格字符串,则可以执行以下操作:
For example if you want to right pad a 10 spaces string you can do:
<xsl:value-of
select="substring(concat($string, ' '), 1, 10))"/>
如果需要左键盘,则可以按以下方式更改concat参数的顺序:
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))"/>
请注意,带空格的字符串应包含与填充所需字符数量相同的字符,因此,如果要使用10个填充,则将需要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.
这篇关于XSL带填充的左右对齐的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!