<?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>27463</bug_id>
          
          <creation_ts>2014-11-28 11:49:46 +0000</creation_ts>
          <short_desc>[XQ31] Arrays within element constructors</short_desc>
          <delta_ts>2015-07-06 09:09:11 +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>XQuery 3.1</component>
          <version>Last Call drafts</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="Jonathan Robie">jonathan.robie</assigned_to>
          
          
          <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>115662</commentid>
    <comment_count>0</comment_count>
    <who name="Michael Kay">mike</who>
    <bug_when>2014-11-28 11:49:46 +0000</bug_when>
    <thetext></thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>115663</commentid>
    <comment_count>1</comment_count>
    <who name="Michael Kay">mike</who>
    <bug_when>2014-11-28 12:00:54 +0000</bug_when>
    <thetext>The XQuery 3.1 specification states that when an array appears within the content of an element constructor, it is atomized. For example

&lt;a&gt;{[&lt;b/&gt;, &lt;c/&gt;, &lt;d/&gt;]}&lt;/a&gt;

produces the output

&lt;a/&gt;

This seems to conflict with the decision we made for serialization, where we said that if nodes appear within an array during JSON serialization, the nodes are expanded using XML serialization. It also seems counter-intuitive since element constructors do not normally atomize any nodes appearing within their content; it seems odd to treat enclosed nodes differently just because they appear within an array.

I think it would cause fewer surprises if an array appearing in such a context were recursively flattened (that is, replacing $A by $A?*) rather than being atomized.

Incidentally, there is also a problem with the way the rules are given in section 3.9.1.3: rule 1.e.ii should appear before 1.e.i, because otherwise, arrays are rejected by virtue of the fact that they are functions.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>115772</commentid>
    <comment_count>2</comment_count>
    <who name="Jonathan Robie">jonathan.robie</who>
    <bug_when>2014-12-01 23:00:19 +0000</bug_when>
    <thetext>I agree with both statements in comment 1.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>115787</commentid>
    <comment_count>3</comment_count>
    <who name="Michael Kay">mike</who>
    <bug_when>2014-12-02 14:31:17 +0000</bug_when>
    <thetext>If we&apos;re going to accept this then we need to define what we mean by &quot;recursively flattening&quot;. Here&apos;s a candidate definition.

To (recursively) flatten a sequence $S, apply the function

function flatten($S as item()*) as item()* {
for $s in $S return
  if $s instance of array(*)
  then flatten($s?*)
  else $s
}


Rules 1e(i) and 1e(ii) of 3.9.1.3 then become

(i) the sequence returned by the enclosed expression is flattened.
(ii) if the sequence resulting from step (i) contains a function, a type error is raised [err:XQTY0105].

and rules (iii) and (iv) should be phrased to make it clear that they refer to the sequence after applying (i) and (ii)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>115798</commentid>
    <comment_count>4</comment_count>
    <who name="Jonathan Robie">jonathan.robie</who>
    <bug_when>2014-12-02 18:01:36 +0000</bug_when>
    <thetext>Let&apos;s add the function from comment #3 to F&amp;O - fn:flatten() - and refer to it from the XQuery / XPath specifications.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>115811</commentid>
    <comment_count>5</comment_count>
    <who name="Michael Kay">mike</who>
    <bug_when>2014-12-02 22:38:34 +0000</bug_when>
    <thetext>The proposal was today accepted, including the addition of the flatten() function (which has been put in the array: namespace)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>121786</commentid>
    <comment_count>6</comment_count>
    <who name="Michael Kay">mike</who>
    <bug_when>2015-07-06 09:09:11 +0000</bug_when>
    <thetext>Confirmed fixed in the current draft.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>