why to bother with namespaces

I found a non-obvious issue in the Namespace Recommendation and fixed my converter. Then I decided to look at other popular de-facto stanadrd tools. They are buggy. So I don't understand why I work so hard to make my program as correct as possible.

I've written total nonsense. See the "Update" section below.

Back to the issue. As I understand the specification, if an attribute has no ns prefix and its element has a ns prefix, then the attribute inherits the ns from the elements. So the following XML examples are identical. An attribute has prefix:

<ns:elem xmlns:ns="ns:ns:ns" ns:attr="smth" />

Now the attribute has no prefix, but it still in the same namespace URI:

<ns:elem xmlns:ns="ns:ns:ns" attr="smth" />

Using the James Clark notation, the both examples defines the following XML:

<{ns:ns:ns}elem {ns:ns:ns}attr="smth" />

It was theory. Now let switch to practice. Let apply XSLT stylesheet to itself ysing saxon 8.5.3 and xsltproc CVS version of 3 May 2005.

attribute is prefixed in XML and in XPath

XSLT:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xsl:version="1.0">

<xsl:template match="/">
  <x>
    <xsl:copy-of select="/xsl:stylesheet/@xsl:version"/>
  </x>
</xsl:template>

</xsl:stylesheet>

Expected result:

<x xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xsl:version="1.0"/>

saxon (failed):

Error at xsl:stylesheet on line 1 of file:/home/prof/tmp/xml/20050503/test11.xsl:
  Attribute xsl:version is not allowed on this element
Transformation failed: Failed to compile stylesheet. 1 error detected.

xsltproc (ok):

<?xml version="1.0"?>
<x xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xsl:version="1.0"/>

attribute is prefixed in XML and not prefixed in XPath

XSLT:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xsl:version="1.0">

<xsl:template match="/">
  <x>
    <xsl:copy-of select="/xsl:stylesheet/@version"/>
  </x>
</xsl:template>

</xsl:stylesheet>

Expected result:

<x/>

saxon (failed):

Error at xsl:stylesheet on line 1 of file:/home/prof/tmp/xml/20050503/test01.xsl:
  Attribute xsl:version is not allowed on this element
Transformation failed: Failed to compile stylesheet. 1 error detected.

xsltproc (ok):

<?xml version="1.0"?>
<x/>

attribute is not prefixed in XML and is prefixed in XPath

XSLT:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

<xsl:template match="/">
  <x>
    <xsl:copy-of select="/xsl:stylesheet/@xsl:version"/>
  </x>
</xsl:template>

</xsl:stylesheet>

Expected result:

<x xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xsl:version="1.0"/>

saxon (failed):

<?xml version="1.0" encoding="utf-8"?><x/>

xsltproc (failed):

<?xml version="1.0"?>
<x/>

attribute is not prefixed both in XML and XPath

XSLT:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

<xsl:template match="/">
  <x>
    <xsl:copy-of select="/xsl:stylesheet/@version"/>
  </x>
</xsl:template>

</xsl:stylesheet>

Expected result:

<x/>

saxon (failed):

<?xml version="1.0" encoding="utf-8"?><x version="1.0"/>

xsltproc (failed):

<?xml version="1.0"?>
<x version="1.0"/>

5 May 2005, Update

Before submitting bugs to XSLT processors, I asked in xml-dev if my understanding is correct. Fortunately, I was answered that I'm wrong. The only I could do is to say thank you and note:

I've re-read the Recommendation and found the phrase that misled me: "the interpretation of unprefixed attributes is determined by the element on which they appear." I must have read more attentive and found the phrase which is similar to what you said: "The namespace name for an unprefixed attribute name always has no value."

25 May 2005, Update

Now it's my turn to answer on a similar question: Re: Clarification needed on attribute names without namespace prefix.

Categories: Generative XML

Updated: