|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: simple question
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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








