This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
RE: append-pad
- From: Mulberry Technologies List Owner<xsl-list-owner at lists dot mulberrytech dot com>
- To: xsl-list <xsl-list at lists dot mulberrytech dot com>
- Date: Wed, 22 May 2002 15:13:32 -0400
- Subject: [xsl] RE: append-pad
- Reply-to: xsl-list at lists dot mulberrytech dot com
>From: Nate Austin <naustin@idsgrp.com>
>To: "'AXRAMAKR@UP.COM'" <AXRAMAKR@UP.COM>
>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@UP.COM [mailto:AXRAMAKR@UP.COM]
>Sent: Wednesday, May 22, 2002 8:44 AM
>To: naustin@decisionsys.com
>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@up.com
>----- Forwarded by Akila X. Ramakrishnan on 05/22/02 08:42 AM -----
>
>
> Akila X.
>
> Ramakrishnan To:
>naustin@decisionsys.com
> 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) < $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@up.com
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list