(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

Reply via email to