Martin --
You need to be using the DOM Level 2 namespace-aware APIs. Have a look
at createElementNS and at the "XML Namespaces" section of the DOM Level
2 Core Recommendation at http://www.w3.org.
Gary
Martin Sparenberg wrote:
>
> Hi!
> Here a problem from someone (me) new to xalan:
> I'm working on a tool that generates an XSLT automatically and then
> puts it to xalan for applying it to a (given) XML-document.
> I build the DOM for the XSLT somehow like:
>
> DocumentBuilderFactory dFactory =
> DocumentBuilderFactory.newInstance();
> DocumentBuilder dBuilder = dFactory.newDocumentBuilder();
> Document dummyDoc = dBuilder.newDocument();
> Element root = dummyDoc.createElement( "xsl:stylesheet" );
> root.setAttribute( "version", "1.1" );
> root.setAttribute( "xmlns:xsl",
> "http://www.w3.org/1999/XSL/Transform" );
> Element el1 = dummyDoc.createElement( "xsl:template" );
> el1.setAttribute( "match", "title" );
> Element el2 = dummyDoc.createElement( "hr" );
> el1.appendChild( el2 );
> root.appendChild( el1 );
> dummyDoc.appendChild( root );
>
> (shortened example - I don't think you would like to read my whole code
> here... ;-) )
>
> So I get a DOM-tree of my XSLT which I can print out on screen and be
> happy, so far. But when I call xalan with:
>
> DOMSource xslDomSource = new DOMSource( dummyDoc);
> xslDomSource.setSystemId("blah");
> TransformerFactory tFactory = TransformerFactory.newInstance();
> Transformer transformer = tFactory.newTransformer(xslDomSource);
>
> I get at this point a "ParserConfigurationException" telling "stylesheet
> requires attribute: version" and talking about some "Line 0; Column 0;".
> The stylesheet-element has a version-attribute, as you can see in the
> code above. The "Line 0; Column 0;" lets me guess the problem isn't the
> stylesheet but the created DOM itself.
> When I use a DOM read from a file as in the DOM2DOM-example from the
> xalan-samples, everything works fine - but I have to use my
> in-memory-contructed XSLT.
>
> Does anybody have an idea, what I made wrong or where the problem lies?
>
> Thanks
>
> Martin Sparenberg