https://saxonica.plan.io/https://saxonica.plan.io/favicon.ico2021-08-10T08:58:22ZSaxonica Developer CommunitySaxon - Support #5059: NS default empty declaration added by transformerhttps://saxonica.plan.io/issues/5059?journal_id=182312021-08-10T08:58:22ZMichael Kaymike@saxonica.com
<ul></ul><p>Please use <code>setNamespaceAware(true)</code> on the <code>DocumentBuilder</code>. XPath and XSLT are defined in terms of the XDM model, which is always namespace-aware. The Java DOM by default isn't, and there's no defined "correct" mapping for a non-namespace-aware DOM to XDM.</p>
<p>However, I think that the behaviour of Saxon 10 here is reasonable. The Javadoc for <code>Document.createElement(tagName)</code> says:</p>
<p><em>returns a new Element object with the nodeName attribute set to <code>tagName</code>, and localName, prefix, and namespaceURI set to null.</em></p>
<p>This implies that the new Element node is in no namespace, and should therefore be serialized with <code>xmlns=""</code>, because without that, it would be in the SVG namespace.</p> Saxon - Support #5059: NS default empty declaration added by transformerhttps://saxonica.plan.io/issues/5059?journal_id=182322021-08-10T09:11:10ZMichael Kaymike@saxonica.com
<ul></ul><p>I decided to take a more detailed look at the specs to see if they confirmed this view.</p>
<p>If there is an "official" mapping from DOM to XDM, then it's obtained by first mapping the DOM to an Infoset, and then mapping the Infoset to XDM.</p>
<p>The DOM-to-Infoset mapping in <a href="https://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/infoset-mapping.html" class="external">https://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/infoset-mapping.html</a> (section C.2.2) says that the infoset <code>[namespace.name]</code> property is taken from the <code>Node.namespaceURI</code> property in the DOM, and the Javadoc for <code>createElement()</code> says that this is null: therefore the element is in no namespace.</p>
<p>The DOM-to-Infoset mapping also says that the infoset <code>[local name]</code> property is taken from the DOM <code>Node.localName</code> property, which the JavaDoc says is null, and this would make the infoset local name null, which means it cannot be mapped to a valid XDM instance.</p>
<p>It all comes back to this: you need to define the DOM as namespace-aware, and use namespace-aware methods such as <code>createElementNS()</code> to create nodes.</p> Saxon - Support #5059: NS default empty declaration added by transformerhttps://saxonica.plan.io/issues/5059?journal_id=182332021-08-10T09:34:11ZYoussouf MHOMA
<ul></ul><p>So i should assume that the previous versions of Saxons (<10) were not handling correctly the specification on this point. The transformer filtered the namespace attribute with null value and did not rendered it (which was good for me), whereas version 10 behaves like the specification. It sounds right.</p> Saxon - Support #5059: NS default empty declaration added by transformerhttps://saxonica.plan.io/issues/5059?journal_id=182342021-08-10T10:04:32ZMichael Kaymike@saxonica.com
<ul></ul><p>I would prefer to say that the behaviour on a non-namespace-aware DOM is unspecified: it's not clear how it should be handled, and the case is best avoided.</p>
<p>(Incidentally, although you can set whether a DOM is namespace-aware or not when creating the DocumentBuilder, Saxon, when given a DOM, has no way of finding out whether it was built to be namespace-aware or not. If there were a way of asking, we would probably raise an error and reject a non-namespace-aware DOM.)</p> Saxon - Support #5059: NS default empty declaration added by transformerhttps://saxonica.plan.io/issues/5059?journal_id=182642021-08-11T15:10:51ZMichael Kaymike@saxonica.com
<ul><li><strong>Tracker</strong> changed from <i>Bug</i> to <i>Support</i></li><li><strong>Status</strong> changed from <i>New</i> to <i>Closed</i></li><li><strong>Assignee</strong> set to <i>Michael Kay</i></li></ul><p>I've decided to close this with no action.</p>