Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SAXOutputter should not fire NO_NAMESPACE delaration for attributes #60

Closed
rolfl opened this issue Jan 24, 2012 · 0 comments · May be fixed by karianna/jdom#1
Closed

SAXOutputter should not fire NO_NAMESPACE delaration for attributes #60

rolfl opened this issue Jan 24, 2012 · 0 comments · May be fixed by karianna/jdom#1

Comments

@rolfl
Copy link
Collaborator

rolfl commented Jan 24, 2012

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.

@rolfl rolfl closed this as completed in 1c453a9 Jan 25, 2012
rolfl added a commit that referenced this issue Jan 25, 2012
It is... by virtue of the new NamespaceStack which does 'the right thing'.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant