RE: [xsl] Format number problem

Subject: RE: [xsl] Format number problem
From: AXRAMAKR@xxxxxx
Date: Thu, 13 Jun 2002 09:18:10 -0500
I am using Xalan C++ and I am not sure how this is not working. Thanks for
all your responses. Pls try and let me know if something pops out as
mistake.

Thanks,

Akila Ramakrishnan
(314) 768 5809
axramakr@xxxxxx


                                                                                                               
                      "Michael Kay"                                                                            
                      <michael.h.kay@xxxxxxxxxxx        To:       <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>            
                      m>                                cc:                                                    
                      Sent by:                          Subject:  RE: [xsl] Format number problem              
                      owner-xsl-list@xxxxxxxxxxx                                                               
                      rrytech.com                                                                              
                                                                                                               
                                                                                                               
                      06/12/02 05:06 PM                                                                        
                      Please respond to xsl-list                                                               
                                                                                                               
                                                                                                               




There's nothing obviously wrong with this. What processor are you using?
Try it on a different processor to see if the bug is in your code or in
the XSLT processor.

Michael Kay
Software AG
home: Michael.H.Kay@xxxxxxxxxxxx
work: Michael.Kay@xxxxxxxxxxxxxx

> -----Original Message-----
> From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of
> AXRAMAKR@xxxxxx
> Sent: 12 June 2002 18:59
> To: Jeni Tennison
> Cc: AXRAMAKR@xxxxxx; xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: Re: [xsl] Format number problem
>
>
>
> Jeni,
> Thanks for your quick response. I too realise this should
> work. Can't tell why it is not working though.
>
> This is the rest of the code
> <xsl:stylesheet version = "1.0" xmlns:xsl
> = "http://www.w3.org/1999/XSL/Transform";>
>       <xsl:output method = "text"/>
>       <xsl:template match = "/">
>       <xsl:apply-templates/>
>       </xsl:template>
>       <xsl:template match = "/ceo_di_msg">
>             <xsl:text>CHK*</xsl:text>
>             <xsl:value-of select = "@usrid"/>
>             <xsl:text>*</xsl:text>
>             <xsl:value-of select = "@tsktmdt"/>
>             <xsl:apply-templates/>
>       </xsl:template>
>       <xsl:template match = "ceo_di_msg/car_msg">
>             <xsl:text>&#10;</xsl:text>
>             <xsl:text>EQP*</xsl:text>
>             <xsl:apply-templates/>
>       </xsl:template>
>       <xsl:template match = "/ceo_di_msg/car_msg/car_id">
>             <xsl:call-template name="append-pad">
>                   <xsl:with-param name="padVar" select ="."/>
>                   <xsl:with-param name="length" select = "'10'"/>
>             </xsl:call-template>
>             <xsl:text>*</xsl:text>
>       </xsl:template>
>       <xsl:template match = "/ceo_di_msg/car_msg/custcsn">
>              <xsl:call-template name="append-pad">
>                   <xsl:with-param name="padVar" select ="."/>
>                   <xsl:with-param name="length" select = "'9'"/>
>             </xsl:call-template>
>             <xsl:text>*</xsl:text>
>       </xsl:template>
>       <xsl:template match = "/ceo_di_msg/car_msg/csn">
>                   <xsl:call-template name="append-pad">
>                   <xsl:with-param name="padVar" select ="."/>
>                   <xsl:with-param name="length" select = "'9'"/>
>             </xsl:call-template>
>             <xsl:text>*</xsl:text>
>       </xsl:template>
>       <xsl:template match = "/ceo_di_msg/car_msg/car_data">
>             <xsl:call-template name="append-pad">
>                   <xsl:with-param name="padVar" select ="@le"/>
>                   <xsl:with-param name="length" select = "'1'"/>
>             </xsl:call-template>
>             <xsl:text>*</xsl:text>
>             <xsl:call-template name="append-pad">
>                   <xsl:with-param name="padVar" select ="@wbnbr"/>
>                   <xsl:with-param name="length" select = "'6'"/>
>             </xsl:call-template>
>             <xsl:text>*</xsl:text>
>             <xsl:call-template name="append-pad">
>                   <xsl:with-param name="padVar" select ="@wbdt"/>
>                   <xsl:with-param name="length" select = "'8'"/>
>             </xsl:call-template>
>       </xsl:template>
>       <xsl:template match = "/ceo_di_msg/car_msg/evt_data">
>             <xsl:apply-templates/>
>       </xsl:template>
>       <xsl:template match = "/ceo_di_msg/car_msg/evt_data/evt1">
>             <xsl:text>&#10;</xsl:text>
>             <xsl:text>EV1*</xsl:text>
>             <xsl:call-template name="append-pad">
>                   <xsl:with-param name="padVar" select ="@evcd"/>
>                   <xsl:with-param name="length" select = "'2'"/>
>             </xsl:call-template>
>             <xsl:text>*</xsl:text>
>             <xsl:call-template name="append-pad">
>                   <xsl:with-param name="padVar" select ="@stpcd"/>
>                   <xsl:with-param name="length" select = "'2'"/>
>             </xsl:call-template>
>             <xsl:text>*</xsl:text>
>             <xsl:call-template name="append-pad">
>                   <xsl:with-param name="padVar" select ="@dfcd"/>
>                   <xsl:with-param name="length" select = "'2'"/>
>             </xsl:call-template>
>             <xsl:text>*</xsl:text>
>             <xsl:call-template name="append-pad">
>                   <xsl:with-param name="padVar" select ="@stprncd"/>
>                   <xsl:with-param name="length" select = "'2'"/>
>             </xsl:call-template>
>             <xsl:text>*</xsl:text>
>             <xsl:call-template name="append-pad">
>                   <xsl:with-param name="padVar" select ="@iostp"/>
>                   <xsl:with-param name="length" select = "'1'"/>
>             </xsl:call-template>
>             <xsl:text>*</xsl:text>
>             <xsl:call-template name="append-pad">
>                   <xsl:with-param name="padVar" select ="@evdt"/>
>                   <xsl:with-param name="length" select = "'12'"/>
>             </xsl:call-template>
>             <xsl:text>*</xsl:text>
>             <xsl:call-template name="append-pad">
>                   <xsl:with-param name="padVar" select ="@yrd"/>
>                   <xsl:with-param name="length" select = "'5'"/>
>             </xsl:call-template>
>             <xsl:text>*</xsl:text>
>             <xsl:call-template name="append-pad">
>                   <xsl:with-param name="padVar" select ="@splc"/>
>                   <xsl:with-param name="length" select = "'9'"/>
>             </xsl:call-template>
>             <xsl:text>*</xsl:text>
>             <xsl:value-of select = 'format-number(@zne, "00")'/>
>             <xsl:text>*</xsl:text>
>             <xsl:value-of select = 'format-number(@trck, "000")'/>
>             <xsl:text>*</xsl:text>
>             <xsl:value-of select = 'format-number(@spt, "00")'/>
>             <xsl:text>*</xsl:text>
>             <xsl:call-template name="append-pad">
>                   <xsl:with-param name="padVar" select ="@rptcbr"/>
>                   <xsl:with-param name="length" select = "'4'"/>
>             </xsl:call-template>
>             <xsl:text>*</xsl:text>
>             <xsl:call-template name="append-pad">
>                   <xsl:with-param name="padVar" select ="@evcbr"/>
>                   <xsl:with-param name="length" select = "'4'"/>
>             </xsl:call-template>
>             <xsl:text>*</xsl:text>
>             <xsl:call-template name="append-pad">
>                   <xsl:with-param name="padVar" select ="@fnacbr"/>
>                   <xsl:with-param name="length" select = "'4'"/>
>             </xsl:call-template>
>             <xsl:text>*</xsl:text>
>             <xsl:call-template name="append-pad">
>                   <xsl:with-param name="padVar" select ="@hlcbr"/>
>                   <xsl:with-param name="length" select = "'4'"/>
>             </xsl:call-template>
>       </xsl:template>
>       <xsl:template match = "/ceo_di_msg/car_msg/evt_data/evt2">
>             <xsl:text>&#10;</xsl:text>
>             <xsl:text>EV2*</xsl:text>
>             <xsl:call-template name="ev2Orpl2"></xsl:call-template>
>       </xsl:template>
>       <xsl:template match = "/ceo_di_msg/car_msg/evt_data/pl2">
>             <xsl:text>&#10;</xsl:text>
>             <xsl:text>PL2*</xsl:text>
>             <xsl:call-template name="ev2Orpl2"></xsl:call-template>
>       </xsl:template>
>       <xsl:template name = "ev2Orpl2">
>             <xsl:call-template name="append-pad">
>                   <xsl:with-param name="padVar" select ="@secnb"/>
>                   <xsl:with-param name="length" select = "'1'"/>
>             </xsl:call-template>
>             <xsl:text>*</xsl:text>
>             <xsl:call-template name="append-pad">
>                   <xsl:with-param name="padVar" select ="@trnsb"/>
>                   <xsl:with-param name="length" select = "'7'"/>
>             </xsl:call-template>
>             <xsl:text>*</xsl:text>
>             <xsl:call-template name="append-pad">
>                   <xsl:with-param name="padVar" select ="@trndy"/>
>                   <xsl:with-param name="length" select = "'2'"/>
>             </xsl:call-template>
>             <xsl:text>*</xsl:text>
>             <xsl:call-template name="append-pad">
>                   <xsl:with-param name="padVar" select ="@trndte"/>
>                   <xsl:with-param name="length" select = "'8'" />
>             </xsl:call-template>
>             <xsl:text>*</xsl:text>
>             <xsl:call-template name="append-pad">
>                   <xsl:with-param name="padVar" select ="@yblk"/>
>                   <xsl:with-param name="length" select = "'4'"/>
>             </xsl:call-template>
>             <xsl:text>*</xsl:text>
>             <xsl:call-template name="append-pad">
>                   <xsl:with-param name="padVar" select ="@tblk"/>
>                   <xsl:with-param name="length" select = "'4'"/>
>             </xsl:call-template>
>             <xsl:text>*</xsl:text>
>             <xsl:call-template name="append-pad">
>                   <xsl:with-param name="padVar" select ="@ofltrn"/>
>                   <xsl:with-param name="length" select = "'10'"/>
>             </xsl:call-template>
>             <xsl:text>*</xsl:text>
>             <xsl:value-of select = 'format-number(@gswg, "000000")'/>
>       </xsl:template>
>       <xsl:template match = "/ceo_di_msg/car_msg/evt_data/evt3">
>             <xsl:text>&#10;</xsl:text>
>             <xsl:text>EV3</xsl:text>
>             <xsl:apply-templates/>
>       </xsl:template>
>       <xsl:template match = "/ceo_di_msg/car_msg/evt_data/pl3">
>             <xsl:text>&#10;</xsl:text>
>             <xsl:text>PL3</xsl:text>
>             <xsl:apply-templates/>
>       </xsl:template>
>       <xsl:template match
> =
> "/ceo_di_msg/car_msg/evt_data/evt3/evtdesc|/ceo_di_msg/car_msg
> /evt_data/pl3/evtdesc">
>
>
>             <xsl:text>*</xsl:text>
>             <xsl:call-template name="append-pad">
>                   <xsl:with-param name="padVar" select ="."/>
>                   <xsl:with-param name="length" select = "'3'"/>
>             </xsl:call-template>
>       </xsl:template>
>       <xsl:template match = "/ceo_di_msg/car_msg/evt_data/pl1">
>             <xsl:text>&#10;</xsl:text>
>             <xsl:text>PL1*</xsl:text>
>             <xsl:call-template name="append-pad">
>                   <xsl:with-param name="padVar" select ="@evcd"/>
>                   <xsl:with-param name="length" select = "'2'"/>
>             </xsl:call-template>
>             <xsl:text>*</xsl:text>
>             <xsl:call-template name="append-pad">
>                   <xsl:with-param name="padVar" select ="@stpcd"/>
>                   <xsl:with-param name="length" select = "'2'"/>
>             </xsl:call-template>
>             <xsl:text>*</xsl:text>
>             <xsl:call-template name="append-pad">
>                   <xsl:with-param name="padVar" select ="@dfcd"/>
>                   <xsl:with-param name="length" select = "'2'"/>
>             </xsl:call-template>
>             <xsl:text>*</xsl:text>
>             <xsl:call-template name="append-pad">
>                   <xsl:with-param name="padVar" select ="@stprncd"/>
>                   <xsl:with-param name="length" select = "'2'"/>
>             </xsl:call-template>
>             <xsl:text>*</xsl:text>
>             <xsl:call-template name="append-pad">
>                   <xsl:with-param name="padVar" select ="@iostp"/>
>                   <xsl:with-param name="length" select = "'1'"/>
>             </xsl:call-template>
>             <xsl:text>*</xsl:text>
>             <xsl:call-template name="append-pad">
>                   <xsl:with-param name="padVar" select ="@evdt"/>
>                   <xsl:with-param name="length" select = "'12'"/>
>             </xsl:call-template>
>             <xsl:text>*</xsl:text>
>             <xsl:call-template name="append-pad">
>                   <xsl:with-param name="padVar" select ="@yrd"/>
>                   <xsl:with-param name="length" select = "'5'"/>
>             </xsl:call-template>
>             <xsl:text>*</xsl:text>
>             <xsl:call-template name="append-pad">
>                   <xsl:with-param name="padVar" select ="@splc"/>
>                   <xsl:with-param name="length" select = "'9'"/>
>             </xsl:call-template>
>             <xsl:text>*</xsl:text>
>             <xsl:value-of select = 'format-number(@zne, "00")'/>
>             <xsl:text>*</xsl:text>
>             <xsl:value-of select = 'format-number(@trck, "000")'/>
>             <xsl:text>*</xsl:text>
>             <xsl:value-of select = 'format-number(@spt, "00")'/>
>             <xsl:text>*</xsl:text>
>             <xsl:call-template name="append-pad">
>                   <xsl:with-param name="padVar" select ="@rptcbr"/>
>                   <xsl:with-param name="length" select = "'4'"/>
>             </xsl:call-template>
>             <xsl:text>*</xsl:text>
>             <xsl:call-template name="append-pad">
>                   <xsl:with-param name="padVar" select ="@evcbr"/>
>                   <xsl:with-param name="length" select = "'4'"/>
>             </xsl:call-template>
>             <xsl:text>*</xsl:text>
>             <xsl:call-template name="append-pad">
>                   <xsl:with-param name="padVar" select ="@fnacbr"/>
>                   <xsl:with-param name="length" select = "'4'"/>
>             </xsl:call-template>
>             <xsl:text>*</xsl:text>
>             <xsl:call-template name="append-pad">
>                   <xsl:with-param name="padVar" select ="@hlcbr"/>
>                   <xsl:with-param name="length" select = "'4'"/>
>             </xsl:call-template>
>             <xsl:text>*</xsl:text>
>              <xsl:call-template name="append-pad">
>                   <xsl:with-param name="padVar" select ="@nsd"/>
>                   <xsl:with-param name="length" select = "'1'"/>
>             </xsl:call-template>
>             <xsl:text>*</xsl:text>
>             <xsl:call-template name="append-pad">
>                   <xsl:with-param name="padVar" select ="@fsd"/>
>                   <xsl:with-param name="length" select = "'1'"/>
>             </xsl:call-template>
>       </xsl:template>
>
>       <xsl:template name="append-pad">
>       <!-- recursive template to left justify and append  -->
>       <!-- the value with whatever padChar is passed in   -->
>             <xsl:param name="padVar"/>
>             <xsl:param name="length"/>
>             <xsl:variable name="padChar" select = "' '"/>
>             <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>
> </xsl:stylesheet>
> Thanks,
>
> Akila
>
>
>
>
>
>                       Jeni Tennison
>
>                       <jeni@jenitenniso        To:
> AXRAMAKR@xxxxxx
>                       n.com>                   cc:
> xsl-list@xxxxxxxxxxxxxxxxxxxxxx
>                                                Subject:  Re:
> [xsl] Format number problem
>                       06/12/02 12:49 PM
>
>                       Please respond to
>
>                       Jeni Tennison
>
>
>
>
>
>
>
>
>
> Hi Akila,
>
> > I want to append 0s to numbers to pad them to the required length.
> >
> > <xsl:value-of select = 'format-number(@zne, "00")'/>
> >
> > is my code for formatting the zne attribute to two digits.
> So if zne
> > is 1 I want to display 01. Is this code correct? It is not working.
>
> Your code is correct (assuming you haven't changed the
> default decimal format). Either there's something buggy in
> your processor or something is wrong elsewhere in your code.
>
> Cheers,
>
> Jeni
>
> ---
> Jeni Tennison
> http://www.jenitennison.com/
>
>
>
>
>
>
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
>


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






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


Current Thread