The only way I can think of to make this change globally is to
 
(a) define a schema for your source document that defines these fields (e.g. fo:con, fo:acc) to be of type xs:decimal, and
 
(b) run the stylesheet under a schema-aware processor.
 
If you've already got a schema, this may not be much effort. You don't actually need to change the stylesheet to reference the schema, you just need to ensure the input document is validated against the schema (by using -val:strict on the command line) when the transformation is run. If you don't already have a schema, you could generate one from the instance - there are a number of tools to do that.

Regards,

Michael Kay
http://www.saxonica.com/
http://twitter.com/michaelhkay



From: Andrei.Mihu@MandG.co.UK [mailto:Andrei.Mihu@MandG.co.UK]
Sent: 21 August 2009 10:04
To: Mailing list for the SAXON XSLT and XQuery processor
Subject: Re: [saxon] Saxon 9.1 and scientific notation


Thanks for the quick reply, you've given me much to think on.

The stylesheets are currently version 1.0 but changing that to 2.0 is unfortunately not an option. I'm working within some tight constraints, both in terms of requirements and time. The amount of regression testing I'd be required to perform for that change means it's not an option.

I'm afraid the only example I can give you is very basic:

<xsl:value-of select="fo:con+fo:acc"/>        (this is what currently produces a scientific notation result)

<xsl:value-of select="format-number(fo:con+fo:acc, '0.##')"/>        (changed to this to avoid scientific notation)

Both fo:con and fo:acc are in the format 1234.56789... (with variable precision.)

I will definitely look into forcing the numbers to decimal rather than double, but that may still leave me with the problem of a large - possibly too large - number of stylesheets/fields to alter in the time I have.

Is there anything else you can suggest, possibly something that would affect more than one field at a time? (the entire stylesheet would be nice - if a bit wishful)

Again, thanks for your help!

Regards,

Andrei Mihu



"Michael Kay" <mike@saxonica.com>


20/08/2009 20:05
Please respond to
Mailing list for the SAXON XSLT and XQuery processor        <saxon-help@lists.sourceforge.net>

To
"'Mailing list for the SAXON XSLT and XQuery processor'" <saxon-help@lists.sourceforge.net>
cc
Andrei Mihu/LON/M&G@M&G
Subject
Re: [saxon] Saxon 9.1 and scientific notation





Do you specify version="1.0" or version="2.0" in your stylesheets? It's probably better to specify 2.0, because arithmetic is more likely then to result in an integer or decimal value rather than a double, and only doubles will be formatted in exponential notation.
 
However, an expression such as (@x + 1) will still return a double, which you could avoid by doing xs:integer(@x) + 1.
 
Of course, schema-awareness would help as well, but that may not be a practical option.
 
Apart from that, it's difficult to give advice without seeing the code that causes the problem.
 
Generally rather than using format-number to display the double value differently, I would look at why the value is a double in the first place, and change the code to ensure that it is an integer or decimal instead.
 

Regards,

Michael Kay

http://www.saxonica.com/
http://twitter.com/michaelhkay



From: Andrei.Mihu@MandG.co.UK [mailto:Andrei.Mihu@MandG.co.UK]
Sent:
20 August 2009 14:13
To:
saxon-help@lists.sourceforge.net
Subject:
[saxon] Saxon 9.1 and scientific notation


Hello,

I have an application that uses Saxon 6.5.3 and XSLT 1.0 (mostly).

This is currently being upgraded to Saxon 9.1 (with Saxon 9.2 a possibility) and I've run into some issues.

Some of the numbers being processed are coming out in scientific notation and it's giving me no end of trouble. From what I've read this is expected behaviour when numbers are outside a certain range (outside 10^6 to 10^-6 or so i believe) and I am aware of the format-number function.

My question is if there is any way around using format-number() as the application uses a significant number of stylesheets which would need changing and the format required is not consistent across numeric fields. Possibly a way to disable this behaviour from within Saxon or another solution?

Any help or suggestions would be most welcome!

Regards,

Andrei Mihu

[snip]

The information contained in this message may be CONFIDENTIAL and is intended for the addressee only. Any unauthorised use, dissemination of the information, or copying of this message is prohibited. If you are not the addressee, please notify the sender immediately by return e-mail and delete this message. Although this e-mail and any attachments are believed to be free of any virus, or other defect which might affect any computer or system into which they are received and opened, it is the responsibility of the recipient to ensure that they are virus free and no responsibility is accepted by M & G for any loss or damage from receipt or use thereof. Please note that all e-mail messages are subject to interception for lawful business purposes.

M & G Limited is incorporated and registered in England and Wales under registered number 1048359. Registered office: Laurence Pountney Hill, London, EC4R 0HH. M & G Limited is a wholly owned subsidiary of Prudential plc.