xsl-list
[Top] [All Lists]

Field padding in XSLT2

2005-01-21 08:35:32
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


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



<Prev in Thread] Current Thread [Next in Thread>