[xsl] Field padding in XSLT2

Subject: [xsl] Field padding in XSLT2
From: "Jim Neff" <jneff@xxxxxxxxxxxxxxx>
Date: Fri, 21 Jan 2005 10:35:32 -0500
Greetings,

Here is the code fragment I use to pad a character for an XSL stylesheet
that generates a text document:

<!-- This code copied from
http://www.topxml.com/code/default.asp?p=3&id=v20030419195352&ms=100&l=&sw=A
ll -->

	<xsl:template name="pad">
	  <xsl:param name="num" />
	  <xsl:param name="max" />
	  <xsl:param name="char" />
		
	  <xsl:if test="not($num = $max)">
	      <xsl:value-of select="$char"/>
	    <xsl:call-template name="pad">
	      <xsl:with-param name="num" select="$num + 1"/>
	      <xsl:with-param name="max" select="$max"/>
	      <xsl:with-param name="char" select="$char"/>
	    </xsl:call-template>
	  </xsl:if>
	</xsl:template>


The template call to pad for 10 spaces looks like this:

<xsl:call-template name="pad">
      <xsl:with-param name="num"   select="0"/>
      <xsl:with-param name="max"   select="10"/>
      <xsl:with-param name="char"  select="&#x20;"/>
</xsl:call-template>


I have the luxury of using XSLT version 2.  Is there a better/faster/easier
way of doing this padding?

Thanks,
Jim Neff

Current Thread