Conversion from number to string is locale dependent
When implicitly or explicitly (using the string()
function) converting a number into a string, the result is locale dependent (more specifically the C locale as set via setlocale()
function)
This can be seen with the sample program (derived from libxslt Tutorial) attached here: sample_program.zip
Example results:
-
./libxslt_tutorial --locale C y.xsl x.xml > x_C.html
- x2_C.html
-
./libxslt_tutorial --locale de_DE.utf8 y.xsl x.xml > x_de_DE.utf8.html
- x2_de_DE.utf8.html
It's apparent number()
only converts numbers using a dot as decimal separator (independent of locale).
However string()
(or the implicit string conversion) uses a locale-dependent decimal separator and introduces a comma for de_DE
(German) locale.
This is quite problematic as the numbers using a comma would not be readable by number()
anymore.
It also conflicts with the specification which states
otherwise, the number is represented in decimal form as a Number including a decimal point with at least one digit before the decimal point and at least one digit after the decimal point [...]
as well as
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.
So a dot as decimial separator is explicitly mentioned and the fact that this function is not meant to convert for presentation to users underlines this should not take locale-specifics into consideration.