<!-- ================================================================== -->
-<refentry id="prepend-pad">
+<refentry id="pad-string">
<refnamediv>
-<refname>prepend-pad</refname>
-<refpurpose>Right-pad a string out to a certain length</refpurpose>
+<refname>pad-string</refname>
+<refpurpose>Right-pad or left-pad a string out to a certain length</refpurpose>
</refnamediv>
<refsect1><title>Description</title>
<para>This function takes string <parameter>padVar</parameter> and
-pads it out to the string-length <parameter>length</parameter>, using
-string <parameter>padChar</parameter> (a space character by default)
-as the padding string (note that <parameter>padChar</parameter> can be
-a string; it is not limited to just being a single character).</para>
+ pads it out in the direction <parameter>rightLeft</parameter> to
+ the string-length <parameter>length</parameter>, using string
+ <parameter>padChar</parameter> (a space character by default) as
+ the padding string (note that <parameter>padChar</parameter> can
+ be a string; it is not limited to just being a single
+ character).</para>
<note>
- <para>This function is a copy of Nate Austin's
+ <para>This function began as a copy of Nate Austin's
<function>prepend-pad</function> function in the <ulink
url="http://www.dpawson.co.uk/xsl/sect2/padding.html" >Padding
Content</ulink> section of Dave Pawson's <ulink
FAQ</ulink>.</para>
</note>
-<programlisting><src:fragment id='prepend-pad.frag'>
- <xsl:template name="prepend-pad">
- <!-- recursive template to right justify and prepend-->
- <!-- the value with whatever padChar is passed in -->
+<programlisting><src:fragment id='pad-string.frag'>
+ <xsl:template name="pad-string">
+ <!-- * recursive template to right/left pad the value with -->
+ <!-- * whatever padChar is passed in -->
<xsl:param name="padChar" select="' '"/>
+ <xsl:param name="leftRight">left</xsl:param>
<xsl:param name="padVar"/>
<xsl:param name="length"/>
<xsl:choose>
<xsl:when test="string-length($padVar) < $length">
- <xsl:call-template name="prepend-pad">
+ <xsl:call-template name="pad-string">
<xsl:with-param name="padChar" select="$padChar"/>
- <xsl:with-param name="padVar" select="concat($padChar,$padVar)"/>
+ <xsl:with-param name="leftRight" select="$leftRight"/>
+ <xsl:with-param name="padVar">
+ <xsl:choose>
+ <!-- * determine whether string should be -->
+ <!-- * right- or left-padded -->
+ <xsl:when test="$leftRight = 'left'">
+ <!-- * pad it to left -->
+ <xsl:value-of select="concat($padChar,$padVar)"/>
+ </xsl:when>
+ <xsl:otherwise>
+ <!-- * otherwise, right-pad the string -->
+ <xsl:value-of select="concat($padVar,$padChar)"/>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:with-param>
<xsl:with-param name="length" select="$length"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of
- select="substring($padVar,string-length($padVar) - $length + 1)"/>
+ select="substring($padVar,string-length($padVar) - $length + 1)"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<src:fragref linkend="xpath.location.frag"/>
<src:fragref linkend="comment-escape-string.frag"/>
<src:fragref linkend="comment-escape-string.recursive.frag"/>
-<src:fragref linkend="prepend-pad.frag"/>
+<src:fragref linkend="pad-string.frag"/>
<src:fragref linkend="str.tokenize.keep.delimiters.frag"/>
<src:fragref linkend="apply-string-subst-map.frag"/>
<src:fragref linkend="apply-character-map.frag"/>