[jdom-interest] A little more info on DOMOutputter and Xalan transformation problems...

Eric M. Burke burke_e at yahoo.com
Thu Mar 15 20:39:37 PST 2001


I have encountered some odd behavior and found the following
message in the archives, which describes the same problem
I am having:

> Hi all,
> Can anyone answer this for me?
> If I pass an xml document created by the jdom XMLOutputter class to xalan
> 2.0.0 with the appropriate stylesheet, I get the expected html output to
> outputStream. However, if I use the jdom DOMOutputter to output the same
> jdom document and pass the created DOM object to xalan as a DOMSource I
> xml output. Why do I not get the same output either way?
> Thanks for any help.
> Peter Courcoux

I know what causes this problem now, but am not sure if it
is a bug in JDOM or a bug in Xalan. In a nutshell, when you
create a JDOM Document then convert it into a DOM Document
using the DOMOutputter, each Element in the newly created
DOM Document reports an empty string as its Namespace URI:

 // reports an empty string
 System.out.println("namespace URI: '" +
		aDOMNode.getNamespaceURI() + "'");

For whatever reason, when the namespace URI is an empty
String, statements like <xsl:apply-templates select="foo"/>
won't select anything in the stylesheet.

But if I create an identical DOM Document from scratch,
using only DOM APIs such as:

  Element domElem = myDoc.createElement("foo");

then the namespace URI is 'null' for each of the Elements.
Now the XSLT stylesheet works fine.

If I then proceed to modify my manually created DOM
document as follows:

 // this is how JDOM creates DOM elements in the
 // DOMOutputter class
 Element domElem = myDoc.createElementNS("", "foo");

Now the stylesheet quits working, because the Namespace
URI is back to empty Strings instead of nulls.

My example code is a disaster right now, the result
of a few hours of intense hacking to try and track
this down.  I plan on putting together a few simplistic
example programs that demonstrate various scenarios,
and I will Email that to this list. I'm hoping that
someone who knows more about namespaces and their
interaction with Xalan will say "aha - that's the problem!"
in the meantime.  Thanks a lot.

- Eric

More information about the jdom-interest mailing list