Talk, talk and more talk about BizTalk

Xslt snippet – Left pad a string

A quick xslt template to left pad a value:

<xsl:template name="prepend-pad">
  <!-- recursive template to right justify and prepend the value with whatever padChar is passed in   -->
  <xsl:param name="padChar"> </xsl:param>
  <xsl:param name="padVar"/>
  <xsl:param name="length"/>
    <xsl:when test="string-length($padVar) &lt; $length">
      <xsl:call-template name="prepend-pad">
        <xsl:with-param name="padChar" select="$padChar"/>
        <xsl:with-param name="padVar" select="concat($padChar,$padVar)"/>
        <xsl:with-param name="length" select="$length"/>
      <xsl:value-of select="substring($padVar,string-length($padVar) - $length + 1)"/>

August 12, 2009 - Posted by | XSLT | ,

1 Comment »

  1. Simple to use and works great! Thanks.

    Comment by CG | June 17, 2011 | Reply

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: