[xsl] RE: append-pad

Subject: [xsl] RE: append-pad
From: AXRAMAKR@xxxxxx
Date: Wed, 22 May 2002 10:30:43 -0500

Tried it....did'nt work. Tried assigning carid to a variable and sending
carid as is and it did not work.


                      Nate Austin                                                                     
                      <naustin@xxxxxxxx        To:       "'AXRAMAKR@xxxxxx'" <AXRAMAKR@xxxxxx>        
                      om>                      cc:       "XSL-List (xsl-list@xxxxxxxxxxxxxxxxxxxxxx)" 
                      05/22/02 09:45 AM        Subject:  RE: append-pad                               

Akila -

I copied XSL-List on this.  If you have any other questions, feel free to
post them there (after you have searched the archives/faq of course).  It
a great community of very intelligent people that can answer any XSLT
question you may have much clearer than I can. :)  (You can get more
information about the list and subscribe to it at

> <xsl:template match = "/ceo_di_msg/car_msg/carid">
>            <xsl:value-of select = "$carId"/>
>            <xsl:call-template name="append-pad">
>                  <xsl:with-param name="padChar" select = "' '"/>
>                  <xsl:with-param name="padVar" select = "$carId"/>
>                  <xsl:with-param name="length" select = "'10'"/>
>            </xsl:call-template>
>            <xsl:text>*</xsl:text>
> </xsl:template>

There are a couple of things wrong with this.  For starters, xsl:value-of
outputs whatever it selects to the result tree.  In this case, you're
selecting $carId which doesn't have a value from what I can see.  I guess
it's possible that it is a global variable.  If you want to create a new
variable, do something like this:

<xsl:variable name="carId" select="."/>
Selecting . selects the context node, which in this case is the node that
matched the template.  In this case, creating a variable is not necessary
though.  If you change the call to look like this, it should do what you

  <xsl:call-template name="append-pad">
    <xsl:with-param name="padChar" select = "' '"/>
    <xsl:with-param name="padVar" select = "."/>
    <xsl:with-param name="length" select = "'10'"/>

Also, you can search the archives to find post by Dimitre Novatchev
regarding his Divide and Conquer method of padding and/or visit exslt.org
for their method.

I'd also highly recommend that you pick up a good book if you can.  Michael
Kay's /XSLT Programmer's Reference/
=sr_1_3/102-3714411-3675320) is a great book, and Jeni Tennison's
0) promises to be great.  (Anyone read it yet?)



-----Original Message-----
From: AXRAMAKR@xxxxxx [mailto:AXRAMAKR@xxxxxx]
Sent: Wednesday, May 22, 2002 8:44 AM
To: naustin@xxxxxxxxxxxxxxx
Subject: append-pad

How should I modify the code if I were to call the append-pad passing the
attribute as the string ?

Akila Ramakrishnan
(314) 768 5809
----- Forwarded by Akila X. Ramakrishnan on 05/22/02 08:42 AM -----

                      Akila X.

                      Ramakrishnan             To:

                      05/22/02 07:59 AM        Subject:  append-pad

I saw this code example in your FAQ for padding in XSL

  <xsl:template name="append-pad">
  <!-- recursive template to left justify and append  -->
  <!-- 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="append-pad">
          <xsl:with-param name="padChar" select="$padChar"/>
          <xsl:with-param name="padVar" select="concat($padVar,$padChar)"/>
          <xsl:with-param name="length" select="$length"/>
        <xsl:value-of select="substring($padVar,1,$length)"/>

I called this function from my code base like this. I am trying to make
carId a fixed text of length 10 and want to append spaces to the right if
the length is <10.

<xsl:template match = "/ceo_di_msg/car_msg/carid">
            <xsl:value-of select = "$carId"/>
            <xsl:call-template name="append-pad">
                  <xsl:with-param name="padChar" select = "' '"/>
                  <xsl:with-param name="padVar" select = "$carId"/>
                  <xsl:with-param name="length" select = "'10'"/>

Why is it not working? What is wrong with the template call?


Akila Ramakrishnan
(314) 768 5809

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

Current Thread