After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 709361 - xsltproc improperly casting strings to numbers
xsltproc improperly casting strings to numbers
Status: RESOLVED DUPLICATE of bug 629325
Product: libxml2
Classification: Platform
Component: general
git master
Other All
: Normal normal
: ---
Assigned To: Daniel Veillard
libxml QA maintainers
Depends on:
Blocks:
 
 
Reported: 2013-10-03 13:14 UTC by Dave Greco
Modified: 2017-06-08 12:46 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Dave Greco 2013-10-03 13:14:29 UTC
Processing a fairly simple construct, xsltproc is converting a string like "8.45" to "8.449999999999999".

Input XML:
<?xml version="1.0" encoding="UTF-8"?>
<STUFF xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
        <field_string>8.45</field_string>
</STUFF>

XSLT file:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="xs">
        <xsl:output method="xml" encoding="UTF-8" indent="yes"/>
        <xsl:template match="/">
                <STUFF>
                        <xsl:for-each select="STUFF/field_string">
                                <field_decimal>
                                        <xsl:value-of select="string(number(string(.)))"/>
                                </field_decimal>
                        </xsl:for-each>
                </STUFF>
        </xsl:template>
</xsl:stylesheet>


output from xsltproc (version 1.1.28):
creating dictionary for stylesheet
reusing dictionary from test.xslt for stylesheet
xsltParseStylesheetProcess : found stylesheet
exclude result prefix xs
xsltPrecomputeStylesheet: removing ignorable blank node
xsltCompilePattern : parsing '/'
xsltCompilePattern : parsed /, default priority 0.500000
added pattern : '/' priority 0.500000
parsed 1 templates
Resolving attribute sets references
Creating sub-dictionary from stylesheet for transformation
Registered 0 modules
reusing transformation dict for output
Registering global variables
Registering global variables from test.xslt
xsltProcessOneNode: applying template '/' for /
xsltApplySequenceConstructor: copy node STUFF
xsltForEach: select STUFF/field_string
xsltForEach: select evaluates to 1 nodes
xsltApplySequenceConstructor: copy node field_decimal
xsltValueOf: select string(number(string(.)))
xsltCopyTextString: copy text 8.449999999999999
xsltValueOf: result '8.449999999999999'
freeing transformation dictionary
<?xml version="1.0" encoding="UTF-8"?>
<STUFF>
  <field_decimal>8.449999999999999</field_decimal>
</STUFF>
freeing dictionary from stylesheet



I have confirmed this behavior differs from Microsoft's XSLT processor, Altova Mapforce, and Saxon HE. They all output <field_decimal>8.45</field_decimal>
Comment 1 Nick Wellnhofer 2013-12-17 18:13:12 UTC
This can be reproduced by simply running:

$ xmllint --xpath 'string(8.45)' dummy.xml
8.449999999999999

Since it's an issue with the XPath engine, I'm changing Product to libxml2.
Comment 2 Nick Wellnhofer 2017-06-08 12:46:40 UTC

*** This bug has been marked as a duplicate of bug 629325 ***