<?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>27189</bug_id>
          
          <creation_ts>2014-10-29 12:28:32 +0000</creation_ts>
          <short_desc>[XSLT30] xsl:copy on-empty and document nodes ambiguities</short_desc>
          <delta_ts>2015-10-29 09:50:39 +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>Last Call drafts</version>
          <rep_platform>PC</rep_platform>
          <op_sys>Windows NT</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="Abel Braaksma">abel.braaksma</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>114205</commentid>
    <comment_count>0</comment_count>
    <who name="Abel Braaksma">abel.braaksma</who>
    <bug_when>2014-10-29 12:28:32 +0000</bug_when>
    <thetext>The spec says two things in 11.9.1.1:

(1) &quot;If the selected item is not an element node, the attribute has no effect, except that static errors must be reported and type errors may be reported.&quot;

(2) &quot;If the result of the instruction in the absence of the on-empty attribute would be an element or document node ....&quot;

While I think it is possible to create a document node inside xsl:copy, it would be a document-node as a child of a copied element node, which would be ignored and it won&apos;t change the item type.

There are two ways to solve this ambiguity:
1) remove the reference to document nodes in quote (2)
2) allow document node creation and allow the on-empty type to be document-node

The second solution has the preference (see mail 0057.html below), but if we allow that, we also need to make sure that the type of on-empty is the same as the type of the selected item.

This bug is created as a result of WG email discussion, see 
- https://lists.w3.org/Archives/Member/w3c-xsl-wg/2014Oct/0056.html (member only)
- https://lists.w3.org/Archives/Member/w3c-xsl-wg/2014Oct/0057.html (member only)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>114404</commentid>
    <comment_count>1</comment_count>
    <who name="Abel Braaksma">abel.braaksma</who>
    <bug_when>2014-10-31 22:28:14 +0000</bug_when>
    <thetext>As a self-reminder, after this bug is resolved, review rev #765 in the XT3 repository, 2014-10-29 (commit comment refers to this bug number and bug 24049).</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>114565</commentid>
    <comment_count>2</comment_count>
    <who name="Abel Braaksma">abel.braaksma</who>
    <bug_when>2014-11-05 21:06:47 +0000</bug_when>
    <thetext>We should also consider the following scenario, when solving this:

&lt;xsl:copy select=&quot;(document-node(root) | somechild)[1]&quot;
    on-empty=&quot;my:create-element()&quot;&gt;
    &lt;xsl:apply-templates /&gt;
&lt;/xsl:copy&gt;


This instruction creates either an empty element or empty document. If it creates an empty document, the on-empty creates the wrong type to replace this. Should we, in this case, allow the implicit creation of the document node?

Also, semantically, @on-empty is very vague: many of my attempts assumed that it fires when the selection is empty, but in fact, it fires when the resulting sequence constructor returns emptiness. 

I believe we should make this very, very clear, or rename to something like &quot;on-empty-content&quot;, or even (rigorous, I know), an instruction &lt;xsl:on-empty select=&quot;&apos;foo&apos;&quot;&gt;...&lt;/xsl:on-empty&gt;, which would be more universally applicable and less complex in rules. More importantly, it is semantically clearer (at least imho) and does not suffer from the type-safety rules.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>116519</commentid>
    <comment_count>3</comment_count>
    <who name="Michael Kay">mike</who>
    <bug_when>2014-12-18 21:27:08 +0000</bug_when>
    <thetext>The WG agreed to make changes as defined in message

https://lists.w3.org/Archives/Member/w3c-xsl-wg/2014Nov/0027.html
(member-only link)

The effect of the changes is, in summary:

(1) Drop the existing on-empty attribute from the instructions on which it appears

(2) Introduce a new instruction xsl:on-empty which is evaluated only if the result of the containing sequence constructor would otherwise be an empty sequence

(3) Introduce a new instruction xsl:on-non-empty which is evaluated only if the result of the containing sequence constructor would otherwise be a non-empty sequence

(4) Introduce a new instruction xsl:conditional-content whose effect is to filter the results of evaluating its contained sequence constructor, by removing any items with &quot;empty content&quot;. For document and element nodes this is defined to mean &quot;no child nodes&quot;, for other items it is defined to mean string(.) = &quot;&quot;.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>