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