This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 28179 - [F+O 3.1] handling of numbers in json-to-xml() is underspecified
Summary: [F+O 3.1] handling of numbers in json-to-xml() is underspecified
Status: CLOSED FIXED
Alias: None
Product: XPath / XQuery / XSLT
Classification: Unclassified
Component: Functions and Operators 3.1 (show other bugs)
Version: Candidate Recommendation
Hardware: PC All
: P2 normal
Target Milestone: ---
Assignee: Michael Kay
QA Contact: Mailing list for public feedback on specs from XSL and XML Query WGs
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-03-09 15:40 UTC by Michael Kay
Modified: 2016-12-16 19:55 UTC (History)
0 users

See Also:


Attachments

Description Michael Kay 2015-03-09 15:40:00 UTC
The spec for json-to-xml() does not make it clear whether the JSON input

23e0

should generate

<number>23</number>

or

<number>23e0</number>

or something else.

Two options that one could use are:

(a) retain the JSON lexical form

(b) convert the JSON lexical form to xs:double using string-to-double conversion, and then convert the xs:double to string

The advantage of (a) is that there is never any loss of precision (there's nothing in JSON that limits the number of digits in a number). But the spec hints that (b) was intended, in that it mentions the rules for string-to-double conversion.

Note however that in the reverse mapping, xml-to-json(), retaining the lexical form is not an option, because the lexical space of xs:double is a superset of the JSON number format (for example, JSON does not allow 015, or .12).
Comment 1 Michael Kay 2015-03-11 12:24:44 UTC
This was accepted by the WG on 10 Mar 2015, and has been applied to the spec.

Specifically: json-to-xml() retains the lexical form of the number in the string value of the generated node (except when the XDM implementation reconstructs the string value from the typed value). xml-to-json()starts with the typed value of the node, or converts the string value to xs:double, and then outputs the result of casting this xs:double to xs:string.