[jdom-interest] XSLT processing fails with JDOM, but not with Xalan/Xerces

Peter Schuller peter.schuller at infidyne.com
Sat Mar 8 15:25:33 PST 2003


I am about to use XSLT for a real project for the first time, and I have
immediately ran into a problem :(

I have a very simple XML file as input, and a very simple XSLT file at:


The XSLT is not meant to produce anything meaningful at the moment, as I
was in the process of incrementally moving towards what I wanted,
testing it at each step of the way.

In short, the XSLT contains:

   <xsl:template match="/document/body">
      ... bunch of stuff

And the XML file contains a single "document" tag with one of its children
being a body tag.

Running this with Xalan/Xerces works:

java org.apache.xalan.xslt.Process -IN /tmp/test.xml \
    -XSL document_html_sheet.xsl

It produces the expected output. However, when I try to transform it
with JDOM, I get:

Caused by: org.xml.sax.SAXException: Ill-formed XML document (multiple
root elements detected)

(I can produce a full stack trace if needed.)

This is using the following simple code, mostly inspired by the example
in CVS (reformatted/ for E-Mail):

Transformer transformer = 
      new StreamSource(this.getClass().getClassLoader() 
JDOMSource source = new JDOMSource(sourceDocument);
JDOMResult result = new JDOMResult();
transformer.transform(source, result);

Now. If I change the matching pattern from "/document/body" to "/" or
"/document" it works. And I can't see how matching "/document/body" is
in anyway incorrect.

Am I doing something wrong or is this some form of bug?

I can't really do much of anything. I kept getting the same error about
multiple root elements when I did other things aswell (such as certain
types of value-of tags and others).

/ Peter Schuller, InfiDyne Technologies HB

PGP userID: 0xE9758B7D or 'Peter Schuller <peter.schuller at infidyne.com>'
Key retrival: Send an E-Mail to getpgpkey at scode.org
E-Mail: peter.schuller at infidyne.com Web: http://www.scode.org

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://jdom.org/pipermail/jdom-interest/attachments/20030309/c79d1ef5/attachment.bin

More information about the jdom-interest mailing list