default attributes from the DTD: xmlns unconditionally applied
With the xmllint
and xsltproc
utilities, one can choose whether the default attributes from the document's DTD are applied or not.
- With
xmllint
, they are not applied, unless the--dtdattr
option is given. From its man page:
--dtdattr
Fetch external DTD and populate the tree with inherited attributes.
- With
xsltproc
, they are applied, unless the--nodtdattr
option is given. From its man page:
--nodtdattr
Do not apply default attributes from the document's DTD.
However, whatever the choice, the xmlns
attribute is always applied. Thus the utilities do not behave as documented.
Example. With test.xml
:
<?xml version="1.0"?>
<!DOCTYPE root [
<!ELEMENT root (elem)>
<!ELEMENT elem (#PCDATA)>
<!ATTLIST elem
xmlns CDATA #FIXED "http://localhost/"
fixed CDATA #FIXED "value"
>
]>
<root>
<elem>foo</elem>
</root>
I get:
$ xmllint test.xml
<?xml version="1.0"?>
<!DOCTYPE root [
<!ELEMENT root (elem)>
<!ELEMENT elem (#PCDATA)>
<!ATTLIST elem xmlns CDATA #FIXED "http://localhost/">
<!ATTLIST elem fixed CDATA #FIXED "value">
]>
<root>
<elem xmlns="http://localhost/">foo</elem>
</root>
and with also test.xsl
:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
I get:
$ xsltproc --nodtdattr test.xsl test.xml
<?xml version="1.0"?>
<root>
<elem xmlns="http://localhost/">foo</elem>
</root>
This one may concern libxslt
, but both issues are related, and libxslt
depends on libxml2
, so that I think the issue should be first considered here. This follows the old bug 656534 on GNOME's Bugzilla I had reported in 2011; I've simplified the example.
Versions: libxml 20910, libxslt 10134 and libexslt 820.