EXSLT - str:align - XSLT Template Implementation

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

Source

<xsl:template name="str:align">
   <xsl:param name="string"
              select="''" />
   <xsl:param name="padding"
              select="''" />
   <xsl:param name="alignment"
              select="'left'" />
   <xsl:variable name="str-length"
                 select="string-length($string)" />
   <xsl:variable name="pad-length"
                 select="string-length($padding)" />
   <xsl:choose>
      <xsl:when test="$str-length >= $pad-length">
         <xsl:value-of select="substring($string, 1, $pad-length)" />
      </xsl:when>
      <xsl:when test="$alignment = 'center'">
         <xsl:variable name="half-remainder"
                       select="floor(($pad-length - $str-length) div 2)" />
         <xsl:value-of select="substring($padding, 1, $half-remainder)" />
         <xsl:value-of select="$string" />
         <xsl:value-of select="substring($padding, $str-length + $half-remainder + 1)" />
      </xsl:when>
      <xsl:when test="$alignment = 'right'">
         <xsl:value-of select="substring($padding, 1, $pad-length - $str-length)" />
         <xsl:value-of select="$string" />
      </xsl:when>
      <xsl:otherwise>
         <xsl:value-of select="$string" />
         <xsl:value-of select="substring($padding, $str-length + 1)" />
      </xsl:otherwise>
   </xsl:choose>
</xsl:template>

Change History

Submitted: 2001-06-08
Creator: Jeni Tennison(http://www.jenitennison.com/)

The str:align function aligns a string within another string.
VersionModifiedByDetails
1.12001-06-21Jeni Tennison Added Javascript and MSXML implementations.
1.22002-08-21Craig Stewart

Added 4XSLT and libxslt implementation to the list.

1.32002-11-12Craig Stewart

Updated 4XSLT version to 0.12.0a3.

http://www.exslt.org/str/functions/align/str.align.template.xsl.html last modified 2002-11-12