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



--mP3DRpeJDSE+ciuQ
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

I modified the code slightly:

<xsl:variable name=3D"format-string">
	<xsl:text>#,##0</xsl:text>
	<xsl:choose>
		<xsl:when test=3D"$currency_code/@minor_unit > 0">
			<xsl:text>.</xsl:text>
			<xsl:call-template name=3D"minor_unit">
				<xsl:with-param name=3D"minor_unit" select=3D"$currency_code/@minor_uni=
t"/>
			</xsl:call-template>
		</xsl:when>
	</xsl:choose>
</xsl:variable>

I just added the xsl:choose because I was getting a decimal point when mino=
r_unit was zero (for Yen for example).
Thanks again, and if you are ever in NYC, I owe you a beer.

On Mon, Mar 11, 2002 at 11:21:26PM +0100, Joerg Heinicke wrote:
> Here we need again recursive template: counting down the @minor_unit, for
> every processing of the template 'minor_unit' one '0'.
>=20
> the XML
>=20
> <root>
>     <number minor_unit=3D"3">1.123</number>
>     <number minor_unit=3D"2">1.000</number>
>     <number minor_unit=3D"4">0.120</number>
>     <number minor_unit=3D"3">12</number>
> </root>
>=20
> the XSL:
> <xsl:template match=3D"number">
>     <xsl:variable name=3D"format-string">
>         <xsl:text>#,##0.</xsl:text>
>         <xsl:call-template name=3D"minor_unit">
>             <xsl:with-param name=3D"minor_unit" select=3D"@minor_unit"/>
>         </xsl:call-template>
>     </xsl:variable>
>     <xsl:value-of select=3D"$format-string"/><br/>
>     <xsl:value-of select=3D"format-number(., $format-string)"/><br/>
> </xsl:template>
>=20
> <xsl:template name=3D"minor_unit">
>     <xsl:param name=3D"minor_unit" select=3D"2"/>
>     <xsl:text>0</xsl:text>
>     <xsl:if test=3D"$minor_unit > 1">
>         <xsl:call-template name=3D"minor_unit">
>             <xsl:with-param name=3D"minor_unit" select=3D"$minor_unit - 1=
"/>
>         </xsl:call-template>
>     </xsl:if>
> </xsl:template>
>=20
> the output:
> #,##0.000
> 1.123
> #,##0.00
> 1.00
> #,##0.0000
> 0.1200
> #,##0.000
> 12.000
>=20
> Regards,
>=20
> Joerg
>=20
> > 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 bui=
ld
> > the formatting string.
> >
> > I was reading this morning in the March 2002 issue of MSDN magazine abo=
ut
> > 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=3D0;i<=3D@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 numb=
er
> of
> > times?
> >
> > --
> >
> > David B. Bitton
> > david@codenoevil.com
> > www.codenoevil.com
> >
> > Diversa ab illis virtute valemus.
>=20
>=20
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

--=20

David B. Bitton
david@codenoevil.com

Diversa ab illis virtute valemus.

--mP3DRpeJDSE+ciuQ
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQE8jnXDMNOMzNRRk50RAt+qAJ9fjKort9DKL5w/KjtEszgOHXTq2wCeJX/o
Qll/tT6y2aanbkz0oR6ebY8=
=vg9C
-----END PGP SIGNATURE-----

--mP3DRpeJDSE+ciuQ--

 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]