EXSLT - str:align - EXSLT Function Implementation

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

Source

<func:function 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">
         <func:result 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)" />
         <func:result select="concat(substring($padding, 1, $half-remainder), $string, substring($padding, $str-length + $half-remainder + 1))" />
      </xsl:when>
      <xsl:when test="$alignment = 'right'">
         <func:result select="concat(substring($padding, 1, $pad-length - $str-length), $string)" />
      </xsl:when>
      <xsl:otherwise>
         <func:result select="concat($string, substring($padding, $str-length + 1))" />
      </xsl:otherwise>
   </xsl:choose>
</func:function>

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.function.xsl.html last modified 2002-11-12