Bug 22032 - [XQ30] Consistency between the node-name and namespaces of a constructed element
[XQ30] Consistency between the node-name and namespaces of a constructed element
Status: CLOSED FIXED
Product: XPath / XQuery / XSLT
Classification: Unclassified
Component: XQuery 3.0
Candidate Recommendation
PC All
: P2 normal
: ---
Assigned To: Jonathan Robie
Mailing list for public feedback on specs from XSL and XML Query WGs
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2013-05-14 20:41 UTC by Michael Kay
Modified: 2013-06-19 10:14 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Michael Kay 2013-05-14 20:41:04 UTC
(From a comment by Christian Grün <christian.gruen@gmail.com> on the saxon-help list).

Consider

element e { namespace {''} {'u'} }

The rules say that 

(a) the name of the element is Q{}e

(b) the element has a namespace binding (""=>"u")

This would violate a consistency constraint in the data model (section 6.2.1 rule 12).

Possibilities are:

(1) change the name of the element to Q{u}e

(2) don't add the namespace binding to the element node

(3) raise a dynamic error

XSLT chooses (3). Specifically 

[ERR XTDE0440] It is a non-recoverable dynamic error if the result sequence contains a namespace node with no name and the element node being constructed has a null namespace URI (that is, it is an error to define a default namespace when the element is in no namespace).

Christian was expecting (1).
Comment 1 Michael Kay 2013-05-14 20:55:37 UTC
I have added test case nscons-042 to test this situation.
Comment 2 Michael Kay 2013-05-16 11:48:23 UTC
Reclassifying as XQuery. Previously misclassified.
Comment 3 Jonathan Robie 2013-05-21 16:39:06 UTC
The Working Group has decided to raise a dynamic error for this case.
Comment 4 Jonathan Robie 2013-05-21 16:43:04 UTC
The error code for this will be XQDY0102.
Comment 5 Jonathan Robie 2013-06-17 13:12:30 UTC
Can I make this error more specific? Does the following text cover this case? I find it more readable:

It is an error to define a default namespace for an element  if the element's name is in no namespace  <errorref class="DY" code="0102"/>. For instance, the following computed constructor raises an error because the element's name is not in a namespace, but a default namespace is defined.

<eg role="parse-test">element e { namespace {''} {'u'} }</eg>
Comment 6 Michael Kay 2013-06-17 14:49:15 UTC
It's more readable, but is the term "to define a default namespace for an element" clear? You've basically taken the informal readable description of the error condition in XSLT in preference to the more formal and accurate one.

In XSLT there are several ways a namespace node can find its way into the content sequence for an element constructor; in XQuery there is only one way, namely the use of a namespace constructor. So I agree the XQuery case is a little simpler. But I don't think I would understand "define a default namespace" as used here, except by reference to the example, and it's not good if the spec can only be understood by reference to examples.
Comment 7 Jonathan Robie 2013-06-17 19:37:35 UTC
How about this:

If the name of an element in a computed element constructor is in no namespace, creating a default namespace for that element using a computed namespace constructor is an error <errorref class="DY" code="0102"/>. For instance, the following computed constructor raises an error because the element's name is not in a namespace, but a default namespace is defined.

<eg role="parse-test">element e { namespace {''} {'u'} }</eg>
Comment 8 Michael Kay 2013-06-17 20:43:16 UTC
Much better, but doesn't the rule apply equally to a direct element constructor?
Comment 9 Jonathan Robie 2013-06-17 22:45:36 UTC
(In reply to comment #8)
> Much better, but doesn't the rule apply equally to a direct element
> constructor?

Hmmmphhh, yes it does.

If the name of an element in an element constructor is in no namespace, creating a default namespace for that element using a computed namespace constructor is an error <errorref class="DY" code="0102"/>. For instance, the following computed constructor raises an error because the element's name is not in a namespace, but a default namespace is defined.

<eg role="parse-test">element e { namespace {''} {'u'} }</eg>
[reply] [-] Comment 8