Query regarding XSLT "Root element not set"
Hi All,
I am getting below exception will running program:
************* exception start **********
false
Exception in thread "main" java.lang.IllegalStateException: Root
element not set
at org.jdom.Document.getContent(Document.java:408)
at SimpleXalan1.main(SimpleXalan1.java:70)
************* exception ends **********
**************** Java Program Start *************
public class SimpleXalan1{
public static void main(String[] args)
throws MalformedURLException, SAXException, Exception{
SAXBuilder builder = new SAXBuilder();
Document xsltdoc = builder.build("C://Workspace//xsltdemo//
classes//message.xsl");
Document inputDoc = builder.build("C://Workspace//xsltdemo//
classes//message.xml");
JDOMResult jdomResult = new JDOMResult();
Transformer obj = TransformerFactory.newInstance().newTransformer
(new JDOMSource(xsltdoc));
obj.transform(new JDOMSource(inputDoc), jdomResult);
Document resultDoc = jdomResult.getDocument();
System.out.println(resultDoc.hasRootElement());
System.out.println(resultDoc.getContent());
}
}
*************** Java Program Ends *************
*************** message.xml Start *************
<?xml version="1.0" encoding="UTF-8"?>
<message>Yep, it worked!</message>
*************** message.xml Ends *************
*************** message.xsl Start *************
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" encoding="UTF-8"/>
<!-- simply copy the message to the result tree -->
<xsl:template match="/">
<xsl:value-of select="message"/>
</xsl:template>
</xsl:stylesheet>
*************** message.xsl Ends *************
Is there any problem with Java code or xml or xsl file.
Please suggest me.
Thanks & regards,
Amit Jain