[jdom-interest] Doctype cannot be added after a root element

Prashant Deva prashant.deva at gmail.com
Thu Apr 5 19:03:53 PDT 2007


Hi,
 I am trying to do an xslt transformation on an xml file using jdom
and i am getting this error msg-
ERROR:  'A DocType cannot be added after the root element'

the xslt file looks something like this -

  	 		 .c9Y6TC { color:#0000ff; } .c194KG { color:#602020; } .c49DIK {
color:#ac306d; } .c18YC0 { color:#d00020; } .c5M9S0 { color:#000090; }
.cLUY2 { color:#ea8f0f; } 		 	 <?xml version='1.0'?>

 <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">


 <xsl:output method="xml" doctype-system="taskDtd.dtd"/>
 <xsl:template match="/">

 <element>
     <xsl:apply-templates select="html/body/h2[1]/a"/>
     <xsl:apply-templates select="html/body/table[1]/tr[not(position()=1)]"/>
 </element>
 </xsl:template> 	

and the code that does the transformation looks something like this -

public Document transform(File sourceXml, File stylesheetFile)
    {

Document sourceDoc= new SAXBuilder().build(sourceXml);
       Transformer processor =
TransformerFactory.newInstance().newTemplates(new
StreamSource(stylesheetFile)).newTransformer();

        JDOMSource source = new JDOMSource(sourceDoc);
        JDOMResult result = new JDOMResult();


        processor.transform(source, result);

        return result.getDocument();
}


Can someone tell me why the error is happening?
Note that if i instead use the java's built xsl transformation instead
of jdom, it works perfectly.

Prashant


More information about the jdom-interest mailing list