# EXSLT - str:align

Implementer Page: str.align.html Function Package: str.align.zip #### Function Syntax
    string str:align(string, string, string?)
#### Template Syntax
    <xsl:call-template name="str:align">
       <xsl:with-param name="string" select="string" />
       <xsl:with-param name="padding" select="string" />
       <xsl:with-param name="alignment" select="string" />?
    </xsl:call-template>
The `str:align` function aligns a string within another string. The first argument gives the target string to be aligned. The second argument gives the padding string within which it is to be aligned. If the target string is shorter than the padding string then a range of characters in the padding string are repaced with those in the target string. Which characters are replaced depends on the value of the third argument, which gives the type of alignment. It can be one of `'left'`, `'right'` or `'center'`. If no third argument is given or if it is not one of these values, then it defaults to left alignment. With left alignment, the range of characters replaced by the target string begins with the first character in the padding string. With right alignment, the range of characters replaced by the target string ends with the last character in the padding string. With center alignment, the range of characters replaced by the target string is in the middle of the padding string, such that either the number of unreplaced characters on either side of the range is the same or there is one less on the left than there is on the right. If the target string is longer than the padding string, then it is truncated to be the same length as the padding string and returned. ## Implementations The following XSLT processors support `str:align`: 4XSLT, from 4Suite. (version 0.12.0a3) libxslt from Daniel Veillard et al. (version 1.0.19) Implementations of `str:align` are available in the following languages: EXSLT Function (by Jeni Tennison) XSLT Template (by Jeni Tennison) Javascript (by Chris Bayes) Msxsl (by Chris Bayes) ## Examples ### Function The following example shows how to use the `str:align` function: #### Source
    <a>
       <c>Is this EXSLT? No. no</c>
    </a>
#### Stylesheet
    <xsl:template match="a">
       <xsl:apply-templates />
    </xsl:template>
    <xsl:template match="*">
       <xsl:value-of select="." />
     -
          <xsl:value-of select="str:align(string(.), '------------------------------', 'left')" />
       <xsl:value-of select="str:align(string(.), '  ', 'right')" />
       <xsl:apply-templates select="*" />
    </xsl:template>

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