[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: XSLT Feature request

Subject: Re: XSLT Feature request
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Mon, 17 Dec 2001 15:48:09 +0000
xslt decimal separator
Hi Frank,

> As it seems, there is only one setting in the above element and this
> affects everything. So we cannot change the stylesheet only, but
> switching output format means changing the decimal-format, every
> format in the stylesheet and every incoming data-source. Couldn't
> there be a spearate setting for output-decimal-separator,
> stylesheet-decimal-separator and input-decimal-separator (maybe with
> default value taken from decimal-separator for compatibility
> reasons) in the next (whatever) XSLT standard??

I *think* that XSLT already gives you what you need, but I might have
missed something in your description.

XPath can only convert a string to a number if it uses a '.' as a
decimal separator and doesn't have any other non-decimal,
non-whitespace characters (so input numbers can't have grouping
separators).  So the results of number() are *always*:

  <number>  12.5   </number>  =>  12.5
  <number>  foo    </number>  =>  NaN
  <number>  12,5   </number>  =>  NaN
  <number> 1,234.5 </number>  =>  NaN

You said that the data holds numbers in the "usual programming way" so
I guess that this will allow you to get the numbers as they should be?

The point of the xsl:decimal-format element is solely to interpret the
format pattern string that you use in format-number(). By default it
uses '.' for decimal points and ',' as the grouping separator so:

  format-number(1234.5, '#,##0.00') => '1,234.5'

But you can override the default decimal format so that you can use a
different decimal point and grouping separator:

<xsl:decimal-format
  decimal-separator=","
  grouping-separator="." />

If you want to use that decimal format, you have to change the format
pattern in the format-number() function:

  format-number(1234.5, '#.##0,00') => '1.234,5'

If you want to chop and change between different numerical formats in
different parts of the stylesheet, you should create named
xsl:decimal-formats for each of the different formats you want to use:

<xsl:decimal-format name="German"
  decimal-separator=","
  grouping-separator="." />

<xsl:decimal-format name="AltGerman"
  decimal-separator=","
  grouping-separator="'" />

<xsl:decimal-format name="US"
  decimal-separator="."
  grouping-separator="," />

Then you can use different formats in different places:

  format-number(1234.5, '#,##0.00', 'US')        => '1,234.5'
  format-number(1234.5, '#.##0,00', 'German')    => '1.234,5'
  format-number(1234.5, "#'##0,00", 'AltGerman') => "1'234,5"

Does that enable you to do what you need to do? Or is there something
further that you need?

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.