[xml] xpath number()/string() and locale
- From: Lars Oppermann <lars oppermann sun com>
- To: xml gnome org
- Subject: [xml] xpath number()/string() and locale
- Date: Fri, 06 Aug 2004 16:11:36 +0200
Hi all,
I think that the way the string() function in libxml2 xpath works is
wrong according to the xpath specification. Please have a look at the
following thoughts and let me know what you think so I can put together
a patch.
Consider the following xml document:
<?xml version="1.0"?>
<root>1.25</root>
and the following xpath expression:
number(string(number(/root/text())))
Should LC_NUMERIC (or LC_ALL) be set to a language that uses a decimal
seperator other then the '.' character the above expression will result
in NaN being returned, since the string() function will use snprintf()
in order to format the number to a string. The resulting string however
cannot be used as a number again.
http://www.w3.org/TR/xpath states:
3.7
[30] Number ::= Digits ('.' Digits?)? | '.' Digits
4.2:
...otherwise, the number is represented in decimal form as a Number
including a decimal point...
NOTE: The string function is not intended for converting numbers into
strings for presentation to users. The format-number function and
xsl:number element in [XSLT] provide this functionality.
With the string() function ultimately using snprintf() in order to
format it's outoput it does not fullfill the requirement of representing
a number in a language neutral form.
Also the scientific notation that might be generated from
xmlXPathFormatNumber() is not allowed by the specification since it does
not conform to 3.7[30]
I would rewrite the xmlXPathFormatNumber() in a way where it just dumps
out the numbers according to xpath 3.7 and leave the rest to
xslt:format-number. What do you think?
Cheers,
~Lars
--
Lars Oppermann <lars oppermann sun com> Sun Microsystems
Software Engineer - StarOffice Sachsenfeld 4
Phone: +49 40 23646 959 D-20097 Hamburg
Fax: +49 40 23646 550 http://www.sun.com/staroffice
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]