<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://www.w3.org/Bugs/Public/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4"
          urlbase="https://www.w3.org/Bugs/Public/"
          
          maintainer="sysbot+bugzilla@w3.org"
>

    <bug>
          <bug_id>29588</bug_id>
          
          <creation_ts>2016-04-23 20:43:45 +0000</creation_ts>
          <short_desc>[fo31] xml-to-json - rules for duplicate keys</short_desc>
          <delta_ts>2016-07-21 15:20:19 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>XPath / XQuery / XSLT</product>
          <component>Functions and Operators 3.1</component>
          <version>Candidate Recommendation</version>
          <rep_platform>PC</rep_platform>
          <op_sys>All</op_sys>
          <bug_status>CLOSED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Michael Kay">mike</reporter>
          <assigned_to name="Michael Kay">mike</assigned_to>
          <cc>andrew_coleman</cc>
          
          <qa_contact name="Mailing list for public feedback on specs from XSL and XML Query WGs">public-qt-comments</qa_contact>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>126070</commentid>
    <comment_count>0</comment_count>
    <who name="Michael Kay">mike</who>
    <bug_when>2016-04-23 20:43:45 +0000</bug_when>
    <thetext>The spec for xml-to-json states that duplicate keys are disallowed, as a consequence of the requirement for the input XML to be valid against our published schema. Our schema says that the @key attribute must be unique for all the element children of a &lt;j:map&gt; element.

This doesn&apos;t quite achieve the desired effect. For example the following are disallowed as duplicates, when in fact they are different keys:

&lt;j:null key=&quot;\n&quot; escaped-key=&quot;true&quot;/&gt;
&lt;j:null key=&quot;\n&quot; escaped-key=&quot;false&quot;/&gt;

and the following pair are not disallowed, although they are different representations of the same key:

&lt;j:null key=&quot;\n&quot; escaped-key=&quot;true&quot;/&gt;
&lt;j:null key=&quot;&amp;#xa;&quot;/&gt;

It&apos;s possible to solve the first problem by tweaking the schema (make the uniqueness constraint apply to the combination of @key and @escaped-key). Solving the second problem is harder. It could potentially be done using an XSD 1.1 assertion, using a regex to unescape the key values and compare them in unescaped form. (But handling escaped surrogate pairs - even well-formed ones - using regular expressions is not easy!). It would be simpler to state the constraint in prose as part of the xml-to-json function specification, rather than relying on the schema.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>126361</commentid>
    <comment_count>1</comment_count>
    <who name="Andrew Coleman">andrew_coleman</who>
    <bug_when>2016-05-06 09:48:22 +0000</bug_when>
    <thetext>At the meeting on 2016-05-03, the WG agreed to make this change by making the prose normative for duplicate keys. Action A-642-02 was raised to track this</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>126711</commentid>
    <comment_count>2</comment_count>
    <who name="Michael Kay">mike</who>
    <bug_when>2016-06-09 10:29:13 +0000</bug_when>
    <thetext>The following changes are made to implement this decision:

(A) The schema for JSON is changed: the uniqueness constraint for maps changes from

        &lt;xs:unique name=&quot;unique-key&quot;&gt;
            &lt;xs:selector xpath=&quot;*&quot;/&gt;
            &lt;xs:field xpath=&quot;@key&quot;/&gt;
        &lt;/xs:unique&gt;

to

        &lt;xs:unique name=&quot;unique-key&quot;&gt;
            &lt;xs:selector xpath=&quot;*&quot;/&gt;
            &lt;xs:field xpath=&quot;@key&quot;/&gt;
            &lt;xs:field xpath=&quot;@escaped-key&quot;/&gt;
        &lt;/xs:unique&gt;

(Note: the semantics of xs:unique ensure that (a) if there is no @escaped-key value, then the default (false) is used; (b) evaluation of the constraint effectively uses the typed value rather than the string value of the attribute, so &quot;true&quot;, &quot;1&quot;, and &quot; 1 &quot; are equivalent.)

(B) In the rules for fn:xml-to-json, after the first numbered list, add:

Furthermore, the input must satisfy the following constraint (which cannot be conveniently expressed in the schema). Every element M in the input tree having local name &quot;map&quot; must satisfy the following rule: there must not be two distinct children of M (say C1 and C2) such that the normalized key of C1 is equal to the normalized key of C2. The normalized key of an element C is as follows:

1. If C has the attribute value escaped-key=&apos;true&apos;, then the value of the key attribute, with all JSON escape sequences expanded to the corresponding Unicode characters according to the JSON escaping rules.

2. Otherwise (the escaped-key attribute is absent or set to false), the value of the key attribute.

(C) In the second error condition (FOJS0006) add the condition &quot;or if a map element has two children whose normalized key values are the same&quot;.

(D) Expand Note 4. &quot;Duplicate key values are not permitted. Most cases of duplicate keys are prevented by the rules in the schema; additional cases (where the keys are equal only after expanding JSON escape sequences) are prevented by the prose rules of this function.&quot;

(E) If time permits, add some examples.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>126712</commentid>
    <comment_count>3</comment_count>
    <who name="Michael Kay">mike</who>
    <bug_when>2016-06-09 12:01:16 +0000</bug_when>
    <thetext>The changes have been applied to both the F+O3.1 and the XSLT3.0 specifications.

XSLT 3.0 test cases have been updated.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>126713</commentid>
    <comment_count>4</comment_count>
    <who name="Michael Kay">mike</who>
    <bug_when>2016-06-09 12:06:50 +0000</bug_when>
    <thetext>QT3 test cases fn-xml-to-json-D-501|2|3 have been updated.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>