[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
Re: [xsl] simple question
Subject: Re: [xsl] simple question From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx> Date: Mon, 25 Feb 2002 17:14:07 +0000 |
Hi Arun, > Thanks for ur reply. It was extensive and addressed my need very well. I > want the number to be formatted in USD currency. > > for example, 123456789, needs to be formatted to $123.46M ... OK. I'll take it that you mean: - if the number is over 1000000000 then you need to have a dollar sign, then the number divided by 1000000000 and formatted with two decimal places, then the word 'billion'. - if the number is over 1000000 then you need to have a dollar sign, then the number divided by 1000000 and formatted with two decimal places, then the letter 'M'. - otherwise, then you need a dollar sign, then the number formatted with no decimal places. Which translates to templates that look like: <xsl:template name="format-price"> <xsl:param name="price" select="number()" /> <xsl:text>$</xsl:text> <xsl:call-template name="format-number"> <xsl:with-param name="number" select="$price" /> </xsl:call-template> </xsl:template> <xsl:template name="format-number"> <xsl:param name="number" select="0" /> <xsl:choose> <xsl:when test="$number > 1000000000"> <xsl:value-of select="format-number($number div 1000000000, '0.00')" /> <xsl:text> billion</xsl:text> </xsl:when> <xsl:when test="$number > 1000000"> <xsl:value-of select="format-number($number div 1000000, '0.00')" /> <xsl:text>M</xsl:text> </xsl:when> <xsl:otherwise> <xsl:value-of select="format-number($number, '#,##0')" /> </xsl:otherwise> </xsl:choose> </xsl:template> Cheers, Jeni --- Jeni Tennison http://www.jenitennison.com/ XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] simple question, Arun Ramdas | Thread | [xsl] XSL-List guidelines, Mulberry Technologie |
Re: [xsl] XSL navigation, Jeni Tennison | Date | Re: Re: [xsl] creating sequence dia, Roland Lechner |
Month |