Thanks to both Daves for their input.  There are some great tips here.  Being a java-based program however, I have some sense that I should not have to know anything about locales and program for each possibility.  I should have some access to a generic method that will format a number in whatever locale, based on some generic format string.

The stuff below looks good, though.  Thanks for your time.
Tom
 

Dave Flanagan wrote:

The following form may be useful also:
Designed from an example in the book "XSLT and XPath On The Edge" by Jeni
Tennison
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

     <xsl:param name="region">FR</xsl:param>

     <xsl:decimal-format name="GB" decimal-separator="."
grouping-separator="," />
     <xsl:decimal-format name="FR" decimal-separator=","
grouping-separator=" " />
     <xsl:decimal-format name="IT" decimal-separator=","
grouping-separator="."/>

     <utl:formats xmlns:utl="http://www.somecompany.com/utils">
          <utl:format region="GB">&#163;#,##0.00</utl:format>
          <utl:format region="FR"># ##0,00 F</utl:format>
          <utl:format region="IT">L'.' #.##</utl:format>
     </utl:formats>

     <xsl:variable name="formats"
select="document('')/utl:formats/utl:format"
                         xmlns:utl="http://www.somecompany.com/utils"/>
     <xsl:template match="/">
          <formattedOutput>
              <xsl:value-of select="format-number(data/value,
[EMAIL PROTECTED], $region)" />
          <formattedOutput>
      </xsl:template>
</xsl:stylesheet>

this will allow you to handle the locale as being passed into the stylesheet
as a paramater

Dave Flanagan

----- Original Message -----
From: <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Cc: "Tom Mitchell Jr." <[EMAIL PROTECTED]>
Sent: Thursday, August 28, 2003 12:07 PM
Subject: The format-number function (was: release timetable...)

> (Further discussion should continue on xalan-j-users, if necessary.)
>
> Tom Mitchell Jr. writes:
> >I want to take
> >   <data>
> >      <value>12345.12345</value>
> >      <precision>2</precision>
> >   </data>
> >in the XML document and transform it into:
> >12,345.12 in American English,
> >12 345,12 in Czech,
> >and 12.345,12 in most other European locales.
> >I use <xsl:choose> based on the precision, but I cannot find a way of
> >using format-number(vlaue, "#,##0.00") to get what I want.
>
> Define three *named* decimal formats:
> <xsl:decimal-format name="American" decimal-separator="." ... />
> <xsl:decimal-format name="Czech" decimal-separator="," ... />
> <xsl:decimal-format name="OtherEuro" decimal-separator="," ... />
>
> Use an <xsl:choose> block to pick the invocation of format-number, where
> each invocation has its own second and third arguments:
> <xsl:when test="$style='Czech'">
>   <xsl:value-of select="format-number(value,'## ##0,00','Czech')"/>
> </xsl:when>
> As you already noticed, properties such as decimal-separator must be set
> using the character that you want to display, meaning that the same
> character has to be used on both input and output, so to speak. You could
> consider wrapping a translate() call around format-number() instead of the
> choose block, if you can isolate the formatting characters from
> conflicting
> uses. Choosing wacky separators would probably help.
>
> You may be worried about having nested chooses. There are other ways to
> get
> the precision, like using substring() to truncate the pattern (second
> argument to format-number()). The XSL FAQ is likely to have some ideas
> about both the precision and selection of formats.
> .................David Marston
>
>

--
=============================
Tom Mitchell,Jr.
Fathom Development Team
Progress Software
One Indian Head Plaza
Nashua, NH 03060
603.594.6905
www.progress.com
=============================
I close my eyes
And feel the water rise around me
Drown the beat of time
Let my senses fall away
I can see much clearer now,
I'm blind.
Find all you need in your mind
If you take the time.
                  -Dream Theater
==============================
 

Reply via email to