Re: [xsl] Why doesn't <xsl:copy> copy xmlns=""?

Subject: Re: [xsl] Why doesn't <xsl:copy> copy xmlns=""?
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Sat, 17 Nov 2012 08:54:21 -0500
At 2012-11-17 13:39 +0000, you wrote:
I want to do an identity transform of this:
----------------------------------------------------------------------------
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema";
                       targetNamespace="http://www.bar.com";
                        xmlns:bar="http://www.bar.com";
                        xmlns=""
                        elementFormDefault="qualified">

...

</xs:schema>
----------------------------------------------------------------------------

Notice the default namespace declaration, xmlns=""

I see it, but it is redundant. That isn't a namespace declaration, it is a namespace "undeclaration". This concept exists in namespaces 1.0 but the verb to "undeclare" is actually worded in namespaces 1.1:


http://www.w3.org/TR/2006/REC-xml-names11-20060816/#changes

So in XML 1.0 an "undeclaration" *removes* a namespace declaration for the default namespace, it does not add an explicit declaration of nothing.

Here is the output from transforming the <xs:schema> with my code:
----------------------------------------------------------------------------
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema";
                       targetNamespace="http://www.bar.com";
                        xmlns:bar="http://www.bar.com";
                        elementFormDefault="qualified">

And because the default namespace already is not declared, it is identical (from an information set perspective) to your original.


What happened to the default namespace declaration?

The default namespace "undeclaration" wasn't needed and so was ignored.


Questions:

1. Why is my code not copying over the default namespace declaration?

Because xmlns="" is not a namespace declaration. It is a directive to remove the default namespace declaration from the information set.


2. What change can I make to my code to ensure that it copies over the default namespace declaration?

You can already be assured that there is no declaration for the default namespace because the processor would have undeclared it if it were necessary. Thus, you can ensure that the information is correct (not that the declarations are the same) because of the namespace fix-up processes of XML serialization.


I hope this helps.

. . . . . . . . . . Ken

--
Contact us for world-wide XML consulting and instructor-led training
Free 5-hour lecture: http://www.CraneSoftwrights.com/links/udemy.htm
Crane Softwrights Ltd.            http://www.CraneSoftwrights.com/s/
G. Ken Holman                   mailto:gkholman@xxxxxxxxxxxxxxxxxxxx
Google+ profile: https://plus.google.com/116832879756988317389/about
Legal business disclaimers:    http://www.CraneSoftwrights.com/legal

Current Thread