EXSLT - str:padding - XSLT Template Implementation

Supported Version: 1
XML Definition: str.padding.xml
Source: str.padding.template.xsl

Source

<xsl:template name="str:padding">
   <xsl:param name="length"
              select="0" />
   <xsl:param name="chars"
              select="' '" />
   <xsl:choose>
      <xsl:when test="not($length) or not($chars)" />
      <xsl:otherwise>
         <xsl:variable name="string"
                       select="concat($chars, $chars, $chars, $chars, $chars,                                        $chars, $chars, $chars, $chars, $chars)" />
         <xsl:choose>
            <xsl:when test="string-length($string) >= $length">
               <xsl:value-of select="substring($string, 1, $length)" />
            </xsl:when>
            <xsl:otherwise>
               <xsl:call-template name="str:padding">
                  <xsl:with-param name="length"
                                  select="$length" />
                  <xsl:with-param name="chars"
                                  select="$string" />
               </xsl:call-template>
            </xsl:otherwise>
         </xsl:choose>
      </xsl:otherwise>
   </xsl:choose>
</xsl:template>

Change History

Submitted: 2001-07-18
Creator: Jeni Tennison(http://www.jenitennison.com)

Altered implementation following suggestions from Dimitre Novatchev on XSL-List. It now creates a longer string using concatenation before recursing rather than during recursion, and also copies the string ten times rather than three to limit the amount of recursion. The tail recursiveness of the template has been retained, however.

http://www.exslt.org/str/functions/padding/str.padding.template.xsl.html last modified 2001-07-18