<?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>4443</bug_id>
          
          <creation_ts>2007-04-02 08:10:42 +0000</creation_ts>
          <short_desc>[XQuery] Unspecified how unprefixed attributes with namespace URIs are to be treated</short_desc>
          <delta_ts>2008-06-26 14:19:46 +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 1.0</component>
          <version>Recommendation</version>
          <rep_platform>Other</rep_platform>
          <op_sys>Linux</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="Frans Englich">frans.englich</reporter>
          <assigned_to name="Don Chamberlin">chamberl</assigned_to>
          <cc>mike</cc>
    
    <cc>tim</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>14624</commentid>
    <comment_count>0</comment_count>
    <who name="Frans Englich">frans.englich</who>
    <bug_when>2007-04-02 08:10:42 +0000</bug_when>
    <thetext>The following query:

&lt;e&gt;
        {
                attribute {QName(&quot;http://example.com/&quot;, &quot;attr&quot;)} {()}
        }
&lt;/e&gt;

produce an attribute whose name doesn&apos;t have a prefix but does have a non-empty 
namespace URI, and is added to an element. This cannot be serialized without a prefix for the attribute, which above is absent. Apparently this is not discussed in the specifications.

It might be useful to see XSL-T&apos;s take on this. Sections 5.7.3 Namespace Fixup and 11.3 Creating Attribute Nodes Using xsl:attribute may be of particular importance.

(XSL-T 5.7.3 says &quot;Namespace fixup may, if necessary to resolve conflicts, change the namespace prefix contained in the QName value that holds the name of an element or attribute node,&quot; but I don&apos;t see how such conflicts can occur in XQuery due to XQDY0025. But maybe there&apos;s some other additional namespace case that XQuery doesn&apos;t cover.)

First raised on w3c-xml-query-wg@w3.org(member-only link):
http://lists.w3.org/Archives/Member/w3c-xml-query-wg/2007Apr/0000.html</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>14627</commentid>
    <comment_count>1</comment_count>
    <who name="Michael Kay">mike</who>
    <bug_when>2007-04-02 09:32:39 +0000</bug_when>
    <thetext>The phrase &quot;if necessary to resolve conflicts&quot; cited from the XSLT spec should be taken very broadly; binding the empty prefix to a non-null namespace in the case of an attribute is in conflict with the rule that for attribute nodes in the data model, the empty prefix is always bound to no-namespace.

I do think there&apos;s a rule missing from XDM here. The general policy in XDM is to define constraints that ensure every valid XDM document node can be serialized as a namespace-well-formed XML external entity.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>14649</commentid>
    <comment_count>2</comment_count>
    <who name="Don Chamberlin">chamberl</who>
    <bug_when>2007-04-03 17:35:02 +0000</bug_when>
    <thetext>Here&apos;s a possible resolution of this comment:
In XQuery Section 3.7.3.2, Computed Attribute Constructors, in the list of rules following &quot;If the keyword &apos;attribute&apos; is followed by a name expression&quot;, rewrite Rule 2 as follows:

2. If the atomized value of the name expression is of type xs:QName:

a. If the expanded QName returned by the atomized name expression has a namespace URI but has no prefix, it is given an implementation-dependent prefix. NOTE: This step is necessary because the default namespace does not apply to attributes. Therefore any attribute name that has a namespace URI must also have a prefix.

b. The resulting expanded QName (including its prefix) is used as the node-name property of the constructed attribute node.

This suggested resolution is subject to further discussion and approval by the Query Working Group.

--Don Chamberlin</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>14746</commentid>
    <comment_count>3</comment_count>
    <who name="Don Chamberlin">chamberl</who>
    <bug_when>2007-04-18 20:37:02 +0000</bug_when>
    <thetext>Frans,
On April 18, 2007, the Query Working Group approved the resolution of this bug report described in Comment #2. This resolution will be implemented in a future erratum to the XQuery specification. If you agree with this resolution, please change the status of this bug report to &quot;Closed.&quot;
Regards, 
Don Chamberlin (for the Query Working Group)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>14848</commentid>
    <comment_count>4</comment_count>
    <who name="Frans Englich">frans.englich</who>
    <bug_when>2007-04-23 08:51:04 +0000</bug_when>
    <thetext>Yes, I agree with the resolution.

For testing purposes it would be convenient if the name of the prefix was deterministic, but I see no way to achieve that.


Frans</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>14851</commentid>
    <comment_count>5</comment_count>
    <who name="Frans Englich">frans.englich</who>
    <bug_when>2007-04-23 12:38:18 +0000</bug_when>
    <thetext>While testing, I came to think of queries like this:

&lt;e&gt;
{
    attribute {QName(&quot;http://www.w3.org/XML/1998/namespace&quot;, &quot;space&quot;)} {&quot;default&quot;}
}
&lt;/e&gt;

From what I can tell, implementations cannot randomly generate prefixes, it depends on the namespace URI. For the XML namespace as above, the &quot;xml&quot; prefix Must be use.

I doubt whether this justifies reconsideration, but I suggest the editorial change of adding an explanatory Note paragraph that sheds light on this.

Mike, I don&apos;t know whether this area applies to XSL-T as well, maybe it does.


Frans</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>14852</commentid>
    <comment_count>6</comment_count>
    <who name="Michael Kay">mike</who>
    <bug_when>2007-04-23 13:29:25 +0000</bug_when>
    <thetext>The nearest equivalent in XSLT is

&lt;xsl:attribute name=&quot;space&quot; namespace=&quot;http://www.w3.org/XML/1998/namespace&quot;/&gt;

In that situation the system is required to invent a prefix, and the constraints on namespace fixup mean there is only one prefix it can validly invent...</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>20803</commentid>
    <comment_count>7</comment_count>
    <who name="Tim Mills">tim</who>
    <bug_when>2008-06-24 15:03:19 +0000</bug_when>
    <thetext>I may be wrong here, but I believe that the changes suggested in Comment 2 is unnecessary.

The query:

&lt;e&gt;
        {
                attribute {QName(&quot;http://example.com/&quot;, &quot;attr&quot;)} {()}
        }
&lt;/e&gt;

will introduce a new namespace prefix, not when the attribute is created, but rather when it is copied, as a result of the rules given in XQuery 3.7.4 In-scope Namespaces of a Constructed Element.

i.e. I expect the result of

&lt;element&gt;
{
  let $name := QName(&quot;http://example.com/&quot;, &quot;attr&quot;),
      $attr := attribute {$name} {()} return
    ( $attr, text { prefix-from-QName(node-name($attr)) } )
}
&lt;/element&gt;

to be of the form

&lt;element xmlns:generated-prefix=&quot;http://example.com/&quot; 
         generated-prefix:attr=&quot;&quot;/ &gt;

and not

&lt;element xmlns:generated-prefix=&quot;http://example.com/&quot; 
         generated-prefix:attr=&quot;&quot;&gt;generated-prefix&lt;/element&gt;

I&apos;ve given more details in Bug 5723 and how it relates to Bug 4463 	 ([XQuery] Missing rules for misuse of the xmlns namespace).
</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>20841</commentid>
    <comment_count>8</comment_count>
    <who name="Frans Englich">frans.englich</who>
    <bug_when>2008-06-25 11:28:46 +0000</bug_when>
    <thetext>I think the errata looks good as is. I think it is good to prevent isolated attribute nodes that has invalid names. For instance in the case they are part of the result set.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>20853</commentid>
    <comment_count>9</comment_count>
    <who name="Tim Mills">tim</who>
    <bug_when>2008-06-25 12:57:28 +0000</bug_when>
    <thetext>Frans - not sure what you mean here.  Bug 4463 prevents invalid attribute names.

I pieced together how the text would read with Bug 4463 and Comment #2 in place.

&quot;If the keyword attribute is followed by a name expression, the name expression is processed as follows:

   1. Atomization is applied to the result of the name expression. If the result of atomization is not a single atomic value of type xs:QName, xs:string, or xs:untypedAtomic, a type error is raised [err:XPTY0004].

   2. If the atomized value of the name expression is of type xs:QName:

	a. If the expanded QName returned by the atomized name expression has a
	namespace URI but has no prefix, it is given an implementation-dependent
	prefix. NOTE: This step is necessary because the default namespace does not
	apply to attributes. Therefore any attribute name that has a namespace URI must
	also have a prefix.

	b. The resulting expanded QName (including its prefix) is used as the node-name
	property of the constructed attribute node.


   3. If the atomized value of the name expression is of type xs:string or xs:untypedAtomic, that value is converted to an expanded QName. If the string value contains a namespace prefix, that prefix is resolved to a namespace URI using the statically known namespaces. If the string value contains no namespace prefix, it is treated as a local name in no namespace. The resulting expanded QName (including its prefix) is used as the node-name property of the constructed attribute. If conversion of the atomized name expression to an expanded QName is not successful, a dynamic error is raised [err:XQDY0074].

A dynamic error [XQDY0044] is raised if the node-name of the constructed 
attribute node has any of the following properties:
(a) Its namespace prefix is xmlns
(b) It has no namespace prefix and its local name is xmlns
(c) Its namespace URI is http://www.w3.org/2000/xmlns/
(d) Its namespace prefix is xml and its namespace URI is not 
http://www.w3.org/XML/1998/namespace
(e) Its namespace prefix is other than xml and its namespace URI is 
http://www.w3.org/XML/1998/namespace&quot;


Consider the query:

attribute { fn:QName(&apos;http://www.example.com/&apos;, &apos;xmlns&apos;) } { &apos;foo&apos; }

Because this attribute will have magically gained a prefix by rule (2a), this won&apos;t hit rule &quot;(b) It has no namespace prefix and its local name is xmlns&quot;.

That doesn&apos;t seem intuitive to me at least.  Nor does it seem intuitive that

empty(
  prefix-from-QName(
    node-name(
      attribute { fn:QName(&apos;http://www.example.com/&apos;, &apos;foo&apos;) } { &apos;foo&apos; }
    )
  )
)

should not be false.

XQuery 3.7.4 rules will introduce a namespace prefix when copying such an attribute.

</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>20894</commentid>
    <comment_count>10</comment_count>
    <who name="Tim Mills">tim</who>
    <bug_when>2008-06-26 10:55:23 +0000</bug_when>
    <thetext>For a further example, consider


let $x := attribute { fn:QName(&apos;http://www.example.com&apos;, &apos;foo&apos;) } { () } return
  &lt;root&gt;
    &lt;element xmlns:ns1=&quot;http://www.example.com&quot;&gt;
      { $x }
    &lt;/element&gt;,
    &lt;element xmlns:ns2=&quot;http://www.example.com&quot;&gt;
      { $x }
    &lt;/element&gt;,
  &lt;/root&gt;

It seems to me preferable for the result to be:

&lt;root&gt;
  &lt;element xmlns:ns1=&quot;http://www.example.com&quot; ns1:foo=&quot;&quot;/&gt;,
  &lt;element xmlns:ns2=&quot;http://www.example.com&quot; ns2:foo=&quot;&quot;/&gt;,
&lt;/root&gt;

rather than:

&lt;root&gt;
   &lt;element xmlns:ns1=&quot;http://www.example.com&quot; ns1:foo=&quot;&quot;/&gt;,
   &lt;element xmlns:ns2=&quot;http://www.example.com&quot; xmlns:ns1=&quot;http://www.example.co
m&quot; ns1:foo=&quot;&quot;/&gt;,
&lt;/root&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>20923</commentid>
    <comment_count>11</comment_count>
    <who name="Michael Kay">mike</who>
    <bug_when>2008-06-26 13:18:38 +0000</bug_when>
    <thetext>XDM erratum E004

http://www.w3.org/XML/2007/qt-errata/xpath-datamodel-errata.html#E004

makes it clear that an attribute node whose name is in a namespace must have a prefix. This is true whether or not the attribute node is attached to an element. Therefore a query processor must invent a prefix at the time the attribute node is created, it cannot leave it until the attribute acquires a parent (unless, of course, the user can&apos;t tell the difference).

Of course, it could have been done differently and perhaps even better, but that&apos;s not the point.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>20925</commentid>
    <comment_count>12</comment_count>
    <who name="Tim Mills">tim</who>
    <bug_when>2008-06-26 13:24:23 +0000</bug_when>
    <thetext>Mike - thanks for pointing that out.  Shame though...

Did Bug 4487 arise from this bug, or was it identified separately?
	

</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>20931</commentid>
    <comment_count>13</comment_count>
    <who name="Michael Kay">mike</who>
    <bug_when>2008-06-26 14:19:46 +0000</bug_when>
    <thetext>&gt; Did Bug 4487 arise from this bug, or was it identified separately?

I think we were having a general purge of such issues at the time.

Michael Kay</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>