XSL left-right justification with Padding

核能气质少年 提交于 2019-12-01 06:54:54

问题


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

Thanks, Prabhjot


回答1:


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.

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.



来源:https://stackoverflow.com/questions/7808421/xsl-left-right-justification-with-padding

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!