wood burning stoves 2.0*
The moose likes XML and Related Technologies and the fly likes  'Could not compile stylesheet' with XSLTInputHandler(InputSource, InputSource) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark " Watch " New topic

'Could not compile stylesheet' with XSLTInputHandler(InputSource, InputSource)

Pham Duy Hung

Joined: Apr 07, 2009
Posts: 6
Hi, please help me to resolve this debug, im using FOP to render Report using XML and XSL. But this's a problem when using XSLTInputHandler. I'd tried 2 way

1> With Syntax: XSLTInputHandler(File, File) -> its run ok

public void generateReport(
HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {

XSLTInputHandler input = new XSLTInputHandler(new File("C:\\glossary.xsl"), new File("C:\\glossary.xsl"));
FOPRender render = new FOPRender(response);


2> With Synxtax: XSLTInputHandler(InputSource, InputSource) -> Error: 'Could not compile stylesheet'


[Fatal Error] :1:1: Premature end of file.
ERROR: 'Premature end of file.'
FATAL ERROR: 'Could not compile stylesheet'
org.apache.fop.apps.FOPException: Could not compile stylesheet
at org.apache.fop.apps.TraxInputHandler.initTransformer(TraxInputHandler.java:108)
at org.apache.fop.apps.TraxInputHandler.<init>(TraxInputHandler.java:100)
at org.apache.fop.apps.XSLTInputHandler.<init>(XSLTInputHandler.java:81)
at com.n2n.report.bean.test.generateReport(test.java:60)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.n2n.report.servlet.ReportSerlvet.doPost(ReportSerlvet.java:75)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:172)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:875)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)
at java.lang.Thread.run(Thread.java:619)

My code is very simple for test:

public void generateReport(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {

InputStream inXSL = new FileInputStream("C:/glossary.xsl");
DataInputStream dis;
dis = new DataInputStream(inXSL);

InputStream inXML = new FileInputStream("C:/glossary.xml");
dis = new DataInputStream(inXML);

FOPRender render = new FOPRender(response);
XSLTInputHandler input = null;
try {
input = new XSLTInputHandler(new InputSource(inXML), new InputSource(inXSL));
} catch (FOPException e) {
// TODO Auto-generated catch block

When im using :

DataInputStream dis;
dis = new DataInputStream(inXSL);

The Content of 2 files is displayed successfully

Please help me and Reply to me as soon as you can. Thanks very much
William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 12761
[Fatal Error] :1:1: Premature end of file.

I would bet that you failed to check for errors in the creation of those InputSource objects.

Paul Clapham

Joined: Oct 14, 2005
Posts: 18541

First you read the contents of the InputStream (in a rather peculiar way) until it's finished. Then you tell your transformer to read from that InputStream. Naturally there isn't anything left in the InputStream and you get that error message.
Pham Duy Hung

Joined: Apr 07, 2009
Posts: 6
Thank, i've resolved this problem. my fop version is 0.25. i tried using fop 0.95, it run ok
It is sorta covered in the JavaRanch Style Guide.
subject: 'Could not compile stylesheet' with XSLTInputHandler(InputSource, InputSource)
Similar Threads
Reading Data from a file and extracting the data
how exactly can i make out if a file in linux has just been updated or has been replaced.
Convert file to a String
how to read line by line and pass each line value to a method
Dynamically reading a file