<?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>30382</bug_id>
          
          <creation_ts>2018-12-20 19:18:29 +0000</creation_ts>
          <short_desc>[XSLT30] xsl:merge-key is defined in terms of xsl:sort, this leads to conflicting results when neither select or sequence constructor are present</short_desc>
          <delta_ts>2019-02-18 16:06:51 +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>XSLT 3.0</component>
          <version>Recommendation</version>
          <rep_platform>PC</rep_platform>
          <op_sys>Windows NT</op_sys>
          <bug_status>NEW</bug_status>
          <resolution></resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>major</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Abel Braaksma">abel.online</reporter>
          <assigned_to name="Michael Kay">mike</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>129459</commentid>
    <comment_count>0</comment_count>
    <who name="Abel Braaksma">abel.online</who>
    <bug_when>2018-12-20 19:18:29 +0000</bug_when>
    <thetext>Currently xsl:merge-key is defined mostly in terms of xsl:sort and refers to that section, specifically, section 15.5 says:

&quot;The syntax and semantics of an xsl:merge-key element are closely based on the rules for the xsl:sort element (the only exception being the absence of the stable attribute)&quot;

However, xsl:sort defines the absence of both the sequence constructor and the select attribute to be treated as select=&quot;.&quot;. In contrast, the text on xsl:merge-key says:

&quot;[...] the result of the expression in the select attribute of the Nth xsl:merge-key child of the corresponding xsl:merge-source element, or in the absence of the select attribute, the result of the contained sequence constructor.&quot;

Further paragraphs don&apos;t specify this, which means that an empty xsl:merge-key returns the empty-sequence(), and not the context item.

This leads to two possible ways of interpretation of the text:

(1) Merge by the rules of xsl:sort, meaning the context item is selected
(2) Merge using the empty-sequence(), which results in declaration-order sorting (by virtue of the stability conflict resolution rules)

I think the second option is not what was intended as it seems a very uncommon use case. But it is easy to go either way with the current rules.

Since it is not uncommon for instructions to have a default for the absence of the select attribute and users are accustomed to that behavior, I think we should fix this omission by choosing option (1) above in an erratum.

I have not researched (yet) how it is presently implemented in existing processors.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>129497</commentid>
    <comment_count>1</comment_count>
    <who name="Michael Kay">mike</who>
    <bug_when>2019-02-13 15:07:52 +0000</bug_when>
    <thetext>I think that the intent, given the way the rules are written, is to delegate the specification to xsl:sort except where otherwise specified. Therefore I think that where there is no select attribute and an empty sequence constructor, select=&quot;.&quot; should be assumed. I am drafting erratum E42 on that basis.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>129510</commentid>
    <comment_count>2</comment_count>
    <who name="Michael Kay">mike</who>
    <bug_when>2019-02-18 16:06:51 +0000</bug_when>
    <thetext>Note there is an overlap here with changes previously agreed by the WG in bug #30130.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>