This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Formatting of numbers, dynamically


Thanks alot.  I was trying to figure how to decrement the minor unit as I
popper out zero's into the format string.

--

David B. Bitton
david@codenoevil.com
www.codenoevil.com

Diversa ab illis virtute valemus.
----- Original Message -----
From: "Joerg Heinicke" <joerg.heinicke@gmx.de>
To: <xsl-list@lists.mulberrytech.com>
Sent: Monday, March 11, 2002 5:21 PM
Subject: Re: [xsl] Formatting of numbers, dynamically


> Here we need again recursive template: counting down the @minor_unit, for
> every processing of the template 'minor_unit' one '0'.
>
> the XML
>
> <root>
>     <number minor_unit="3">1.123</number>
>     <number minor_unit="2">1.000</number>
>     <number minor_unit="4">0.120</number>
>     <number minor_unit="3">12</number>
> </root>
>
> the XSL:
> <xsl:template match="number">
>     <xsl:variable name="format-string">
>         <xsl:text>#,##0.</xsl:text>
>         <xsl:call-template name="minor_unit">
>             <xsl:with-param name="minor_unit" select="@minor_unit"/>
>         </xsl:call-template>
>     </xsl:variable>
>     <xsl:value-of select="$format-string"/><br/>
>     <xsl:value-of select="format-number(., $format-string)"/><br/>
> </xsl:template>
>
> <xsl:template name="minor_unit">
>     <xsl:param name="minor_unit" select="2"/>
>     <xsl:text>0</xsl:text>
>     <xsl:if test="$minor_unit > 1">
>         <xsl:call-template name="minor_unit">
>             <xsl:with-param name="minor_unit" select="$minor_unit - 1"/>
>         </xsl:call-template>
>     </xsl:if>
> </xsl:template>
>
> the output:
> #,##0.000
> 1.123
> #,##0.00
> 1.00
> #,##0.0000
> 0.1200
> #,##0.000
> 12.000
>
> Regards,
>
> Joerg
>
> > I am current using format-number($node, '#,##0.00') for formatting
> currency.
> > We are now implementing foreign currencies into our application.  For
> every
> > transaction, I have an element, CurrencyCode, which contains the ISO
> > currencyCode and an attribute @minor_unit which tells me how many digits

> > follow the decimal seperator.  My question is how I can dynamically
build
> > the formatting string.
> >
> > I was reading this morning in the March 2002 issue of MSDN magazine
about
> > how XSLT is a "Functional programming language", and therefore
> xsl:variable
> > entities are "not really variables, rather runtime-assigned constants"
> > because once they are assigned, the values cannot be changed.  So, this
> lead
> > me to start thinking about how I could wrap an xsl:for-each with the
> > xsl:variable element to produce my output.  What I don't know if how to
> > obtain functionality like:
> >
> > for(i=0;i<=@minor_unit;i++){ ... };
> >
> > I do not want to use an enbedded JScript solution because I want the XSL
> to
> > be portable (namely between MSXML and Xalan).  So, how would I construct
> the
> > @select attribute in the xsl:for-each to just loop a predetermined
number
> of
> > times?
> >
> > --
> >
> > David B. Bitton
> > david@codenoevil.com
> > www.codenoevil.com
> >
> > Diversa ab illis virtute valemus.
>
>
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
>


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]