Subject: [xsl] RE: append-pad From: Nate Austin <naustin@xxxxxxxxxx> Date: Thu, 23 May 2002 09:56:23 -0500 |
Using the equivalent of your code, it works for me. You have a problem somewhere else in your stylesheet. Post your XML and XSLT and we can work from there. -----Original Message----- From: AXRAMAKR@xxxxxx [mailto:AXRAMAKR@xxxxxx] Sent: Wednesday, May 22, 2002 10:31 AM To: naustin@xxxxxxxxxx Cc: 'AXRAMAKR@xxxxxx'; XSL-List (xsl-list@xxxxxxxxxxxxxxxxxxxxxx) Subject: RE: append-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@idsgr To: "'AXRAMAKR@xxxxxx'" <AXRAMAKR@xxxxxx> p.com> cc: "XSL-List (xsl-list@xxxxxxxxxxxxxxxxxxxxxx)" 05/22/02 09:45 <xsl-list@xxxxxxxxxxxxxxxxxxxxxx> 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) < $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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] RE: append-pad, Mulberry Technologie | Thread | [xsl] Testing if variable exists, gary cor |
[xsl] Same TAG name ?, longjohn | Date | Re: [xsl] Same TAG name ?, Aparna Konduri |
Month |