hunterhacker/jdom — Issue #60: SAXOutputter should not fire NO_NAMESPACE delaration for attributes
Author: rolfl
Created: 2012-01-24 23:39:28+00:00
State: open

Has anyone encountered this? It doesn't happen with JDOM 1.1.1, but it does happen with JDOM 1.1.2.

Vanilla XSLT transform:

Document with default namespace change and any attribute on the element: FAILS:

...

Document with default namespace change and no attribute on the element: WORKS:

...

Here's the error:

org.jdom.IllegalAddException: The namespace xmlns="" could not be added as a namespace to "bar": The namespace prefix "" collides with the element namespace prefix
at org.jdom.Element.addNamespaceDeclaration(Element.java:363)
at org.jdom.input.SAXHandler.transferNamespaces(SAXHandler.java:714)
at org.jdom.input.SAXHandler.startElement(SAXHandler.java:563)
at net.sf.saxon.event.ContentHandlerProxy.startContent(ContentHandlerProxy.java:366)
at net.sf.saxon.event.NamespaceReducer.startContent(NamespaceReducer.java:192)
at net.sf.saxon.event.ComplexContentOutputter.startContent(ComplexContentOutputter.java:583)
at net.sf.saxon.tree.tiny.TinyElementImpl.copy(TinyElementImpl.java:350)
at net.sf.saxon.expr.instruct.CopyOf.processLeavingTail(CopyOf.java:510)
at net.sf.saxon.expr.instruct.Template.applyLeavingTail(Template.java:212)
at net.sf.saxon.trans.Mode.applyTemplates(Mode.java:1032)
at net.sf.saxon.trans.TextOnlyCopyRuleSet.process(TextOnlyCopyRuleSet.java:58)
at net.sf.saxon.trans.Mode.applyTemplates(Mode.java:1020)
at net.sf.saxon.Controller.transformDocument(Controller.java:1957)
at net.sf.saxon.Controller.transform(Controller.java:1803)
at net.sf.saxon.s9api.XsltTransformer.transform(XsltTransformer.java:430)

I'm using this code fragment to tell Saxon9 to serialize to JDOM:

import net.sf.saxon.s9api.SAXDestination;
import org.jdom.input.SAXHandler;
import net.sf.saxon.s9api.Destination;

SAXHandler saxHandler = new SAXHandler();
Destination saxDestination = new SAXDestination(saxHandler);
xsltTransformer.setSource(new JDOMSource(document));
xsltTransformer.setDestination(saxDestination);
xsltTransformer.transform();

If this isn't a JDOM bug, then I guess it must be a Saxon one.

Leigh.