This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 6517 - [XQuery] Default namespace undeclarations
Summary: [XQuery] Default namespace undeclarations
Status: CLOSED INVALID
Alias: None
Product: XPath / XQuery / XSLT
Classification: Unclassified
Component: XQuery 1.0 (show other bugs)
Version: Recommendation
Hardware: PC Windows NT
: P2 normal
Target Milestone: ---
Assignee: Jonathan Robie
QA Contact: Mailing list for public feedback on specs from XSL and XML Query WGs
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-02-02 14:55 UTC by Michael Kay
Modified: 2010-11-30 23:52 UTC (History)
1 user (show)

See Also:


Attachments

Description Michael Kay 2009-02-02 14:55:40 UTC
An equivalent bug was raised some time ago against XSLT 2.0 - see bug #5857. This arose "in real life" from a user trying to generate an XML Schema as the output of a transformation.

Consider the following query:

<s:complexType xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns="http://t.com/">
  <s:element ref="abcd" xmlns=""/>
</s:complexType>

Intuitively, one might imagine that the output would be the same:

<s:complexType xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns="http://t.com/">
  <s:element ref="abcd" xmlns=""/>
</s:complexType>

But it is not. The correct output is:

<s:complexType xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns="http://t.com/">
  <s:element ref="abcd"/>
</s:complexType>

Which is not what the user wants: the xmlns="" is there to ensure that the QName-valued ref attribute is a QName in the null namespace, not in namespace http://t/com/. 

(As it happens, Saxon produces the output the user would like, which is incorrect against the current spec.)

The reason is that we construct the result tree bottom-up. First we construct the s:element element, with a single in-scope namespace xmlns:s="http://www.w3.org/2001/XMLSchema". Then we construct the s:complexType element with two in-scope namespaces corresponding to those declared in the source. Then the child element is copied, and namespace inheritance is in force, so the copied child acquires a namespace binding for http://t.com/ from its new parent.

The solution being proposed (not yet approved) for XSLT is that the default namespace should never be inherited. Specifically, change 3.7.1.3 rule 1.e.ii.D.II to read:

If copy-namespaces mode specifies inherit, the copied node inherits all the in-scope namespaces of the constructed node *other than any binding for the default namespace*, augmented and overridden by the in-scope namespaces of the original element that were preserved by the preceding rule. If copy-namespaces mode specifies no-inherit, the copied node does not inherit any in-scope namespaces from the constructed node.

The justification for treating the default namespace differently from other namespaces is that the semantics of a namespace undeclaration are different. Whereas the undeclaration xmlns:p="" makes the prefix p unavailable for use, the undeclaration xmlns="" causes the prefix "" to refer to the null namespace "" - so in many ways it behaves more like a redeclaration than an undeclaration. In particular, in the example under study, the user wrote xmlns="" because they wanted to define a specific binding between the empty prefix and the null namespace.

(Another approach that might work is to treat xmlns="" as creating a namespace binding. But that would create compatibility problems for applications using the namespace axis, or its equivalent in-scope-prefixes().)
Comment 1 Andrew Eisenberg 2009-02-09 21:47:47 UTC
I believe that the query you provide:

<s:complexType xmlns:s="http://www.w3.org/2001/XMLSchema"
xmlns="http://t.com/">
  <s:element ref="abcd" xmlns=""/>
</s:complexType>

should produce:

<s:complexType xmlns:s="http://www.w3.org/2001/XMLSchema"
xmlns="http://t.com/">
  <s:element ref="abcd" xmlns=""/>
</s:complexType>

I believe that the use of an enclosed expression:

<s:complexType xmlns:s="http://www.w3.org/2001/XMLSchema"
xmlns="http://t.com/">
  { <s:element ref="abcd" xmlns=""/> }
</s:complexType>

will produce: 

<s:complexType xmlns:s="http://www.w3.org/2001/XMLSchema"
xmlns="http://t.com/">
  <s:element ref="abcd"/>
</s:complexType>


In section 3.7.1.3 Content, rule 1)d applies to nested direct element constructors, and simply connects child to parent. Rule 1)e applies to enclosed expressions, copying the children and modifiying the in-scope-namespaces property.
 
Comment 2 Jonathan Robie 2009-02-24 16:55:54 UTC
The Working Group agrees with http://www.w3.org/Bugs/Public/show_bug.cgi?id=6517#c1, and is therefore closing this.