4

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

Prabhjot
  • 695
  • 3
  • 8
  • 21

2 Answers2

9

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.

sergiol
  • 4,122
  • 4
  • 47
  • 81
mtrovo
  • 879
  • 1
  • 6
  • 15
-1

If the goal is to add spaces either to the right or to the left

  <xsl:text>&#xA0;&#xA0;&#xA0;</xsl:text>
Odwori
  • 1,460
  • 13
  • 14