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

RE: append-pad

Subject: RE: append-pad
From: Mulberry Technologies List Owner<xsl-list-owner@xxxxxxxxxxxxxxxxxxxxxx>
Date: Wed, 22 May 2002 15:13:32 -0400
akila x
>From: Nate Austin <naustin@xxxxxxxxxx>
>To: "'AXRAMAKR@xxxxxx'" <AXRAMAKR@xxxxxx>
>Subject: RE: append-pad
>Date: Wed, 22 May 2002 09:45:58 -0500
>MIME-Version: 1.0
>X-Mailer: Internet Mail Service (5.5.2448.0)
>Content-Type: text/plain
>
>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
  • RE: append-pad
    • AXRAMAKR - Wed, 22 May 2002 11:40:49 -0400 (EDT)
      • <Possible follow-ups>
      • Mulberry Technologies List Owner - Wed, 22 May 2002 15:23:27 -0400 (EDT) <=
      • Nate Austin - Thu, 23 May 2002 11:12:16 -0400 (EDT)

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.