Skip to content
This repository

SAXOutputter should not fire NO_NAMESPACE delaration for attributes #60

Closed
rolfl opened this Issue January 24, 2012 · 0 comments

1 participant

Rolf
Rolf
Collaborator

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:

<?xml version="1.0"?>
<xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="*|@*|text()">
<xsl:copy-of select="." />
</xsl:template>
</xsl:transform>

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

<?xml version="1.0" encoding="UTF-8"?>
<description>
<foo xmlns="http://example.com/foo">
<bar x="...">...</bar>
</foo>
</description>

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

<?xml version="1.0" encoding="UTF-8"?>
<description>
<foo xmlns="http://example.com/foo">
<bar >...</bar>
</foo>
</description>

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.

Rolf rolfl closed this in 1c453a9 January 24, 2012
Rolf rolfl referenced this issue from a commit January 24, 2012
Rolf Issue #60 - put in a check to confirm JDOM2 is compliant.
It is... by virtue of the new NamespaceStack which does 'the right thing'.
fd2182f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.