[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

 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="/">

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

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 =

        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.


More information about the jdom-interest mailing list