It's hard for me to tell from the code you've shown what went wrong.  If
you can, serialize the DOM and attach it to the list and I'll have a
look.  You can serialize this by adding this to your code:

  FileOutputStream fos = new FileOutputStream("c:\\temp\\dom.ser");
  ObjectOutputStream oos = new ObjectOutputStream(fos);
  oos.writeObject(xslDoc);
  oos.flush();
  fos.close();

Also, I'm presuming that you're passing xslDoc to your transformation
and not some other Node.

Gary

Martin Sparenberg wrote:
> 
> Hi,
> 
> Thanks, Gary, for the hint, the problem with the version-attribute is
> fixed now  and made way for the next one...
> I now can create my DOM and can also print it out to screen, but when
> calling Xalan to transform a parsed xml with the generated xslt-DOM, I
> get an error:
> "TransformerException: Can't have more than one root on a DOM!"
> There is (now) only one element I create and append to the one I get
> with .getDocumentElement(); (and another el. under it), so as I
> understand it, there is no attempt to create multiple roots to the DOM-tree.
> (And as I see it, it also can't be the parsed xml-data to apply my
> transformation to, because I got that from a Xalan-sample, where it
> works very well).
> Do you have an idea, what I made wrong?
> 
> Again, some lines of my code:
> 
> String NAMESPACE = "http://www.w3.org/1999/XSL/Transform";;
> [...]
> xslDoc = domImpl.createDocument( NAMESPACE, "xsl:stylesheet", null );
> tempElement = xslDoc.getDocumentElement();
> tempElement.setAttributeNS( null, "version", "1.0");
> tempElement.setAttributeNS( "http://www.w3.org/2000/xmlns/";,
> "xmlns:xsl", "http://www.w3.org/1999/XSL/Transform"; );
> Element output = (Element) xslDoc.createElementNS( NAMESPACE,
> "xsl:output" );
> output.setAttributeNS( null, "method", "xml");
> output.setAttributeNS( null, "indent", "yes");
> tempElement.appendChild( output );
> // just dummy-elements for testing purposes:
> Element el1 = (Element) xslDoc.createElementNS( NAMESPACE, "xsl:template" );
> el1.setAttributeNS( null, "match", "Order" );
> Element el2 = (Element) xslDoc.createElementNS( null, "hr" );
> el1.appendChild( el2 );
> tempElement.appendChild( el1 );
> [...]
> 
> and then my (sample) DOM should be complete, doesn't it?
> 
> Martin
> 
> Gary L Peskin wrote:
> 
> > Martin --
> >
> > 1)  Use setAttributeNS to set your attributes.
> > 2)  I don't see where you've added the version attribute.  Be sure that
> > when you add it, it's in the default, not the XSLT, namespace:
> >
> >   tempElement.setAttributeNS(null, "version", "1.0");
> >
> > Gary

Reply via email to