[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: append-pad

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

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

Thanks,
Akila
axramakr@xxxxxx


                                                                                                      
                      Nate Austin                                                                     
                      <naustin@xxxxxxxx        To:       "'AXRAMAKR@xxxxxx'" <AXRAMAKR@xxxxxx>        
                      om>                      cc:       "XSL-List (xsl-list@xxxxxxxxxxxxxxxxxxxxxx)" 
                                                <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
is
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
http://www.mulberrytech.com/xsl/xsl-list/index.html).

> <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
want:

  <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'"/>
  </xsl:call-template>

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/
(
http://www.amazon.com/exec/obidos/ASIN/1861005067/qid=1022078929/sr=1-3/ref
=sr_1_3/102-3714411-3675320) is a great book, and Jeni Tennison's
/Beginning
XSLT/
(
http://www.amazon.com/exec/obidos/ASIN/1861005946/qid%3D/102-3714411-367532
0) promises to be great.  (Anyone read it yet?)

HTH,

Nate

-----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 ?
Thanks,

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


                      Akila X.

                      Ramakrishnan             To:
naustin@xxxxxxxxxxxxxxx
                                               cc:

                      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:choose>
      <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:call-template>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="substring($padVar,1,$length)"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

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'"/>
            </xsl:call-template>
            <xsl:text>*</xsl:text>
</xsl:template>

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

Thanks,

Akila Ramakrishnan
(314) 768 5809
axramakr@xxxxxx






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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.