Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

XSLT from DOM to DOM : javax.xml.transform.TransformerException

8 views
Skip to first unread message

xxgeorge

unread,
Feb 27, 2002, 4:58:38 AM2/27/02
to
hi all,

This may be a simple question but I get stuck. I want to reformat a
XML document into another XML document, with the following code:

...
Source xmlSource = new DOMSource(xmlDoc);
Source xslSource = new StreamSource(ssURL.openStream());
Result result = new DOMResult();

TransformerFactory factory = TransformerFactory.newInstance();
Transformer transformer = factory.newTransformer(xslSource);
transformer.transform(xmlSource, result);
...

at the last line running the transform() method, I get the exception
attached at the bottom.

seems if I use a streamResult instead of a DOMResult, there will be no
such problem. So I guess it is the root of DOMSource and DOMResult
having conflict?

Please advice. Many thanks

George


my exception:

javax.xml.transform.TransformerException: Can't have more than one
root on a DOM
!
at org.apache.xalan.transformer.TransformerImpl.transformNode(Transforme
rImpl.java:1269)
at org.apache.xalan.transformer.TransformerImpl.transform(TransformerImp
l.java:504)
at org.apache.xalan.transformer.TransformerImpl.transform(TransformerImp
l.java:1174)
at hgc.lib.structs.taglib.list.ReportItemsTag.doEndTag(ReportItemsTag.ja
va:89)
at _0002finMilestoneListing_0002ejspinMilestoneListing_jsp_17._jspServic
e(_0002finMilestoneListing_0002ejspinMilestoneListing_jsp_17.java:279)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:119)
...

Andreas Wollschlaeger

unread,
Feb 27, 2002, 7:18:26 PM2/27/02
to
xxgeorge wrote:

> hi all,
>
> This may be a simple question but I get stuck. I want to reformat a
> XML document into another XML document, with the following code:
>
> ...
> Source xmlSource = new DOMSource(xmlDoc);
> Source xslSource = new StreamSource(ssURL.openStream());
> Result result = new DOMResult();
>
> TransformerFactory factory = TransformerFactory.newInstance();
> Transformer transformer = factory.newTransformer(xslSource);
> transformer.transform(xmlSource, result);
> ...
>
> at the last line running the transform() method, I get the exception
> attached at the bottom.
>
> seems if I use a streamResult instead of a DOMResult, there will be no
> such problem. So I guess it is the root of DOMSource and DOMResult
> having conflict?
>
> Please advice. Many thanks

> my exception:


>
> javax.xml.transform.TransformerException: Can't have more than one
> root on a DOM

Hello,
well, your code looks reasonable. Have you checked if your style sheet
produces valid XML? You could try to invoke Xalan with some sample data
from the command prompt and check the produced XML for errors.

HTH
<Andreas value="EUR 0.02"/>

--
/toe/ff
el@/treu/
f/uss.
de//

xxgeorge

unread,
Feb 28, 2002, 1:12:02 AM2/28/02
to
hi there,

Yeah thanks for your suggestion. You've got the point, it's the xsl
that not generating a valid xml. Thanks a lot.

cheers
george

Andreas Wollschlaeger <postm...@1.0.0.127.in-addr.arpa> wrote in message news:<a5jt0i$oub$06$1...@news.t-online.com>...

0 new messages