• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Pham Duy Hung
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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);
render.renderXML(input);

}

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

Details:

[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);
while(dis.available()!=0){
System.out.println(dis.readLine());
}

InputStream inXML = new FileInputStream("C:/glossary.xml");
dis = new DataInputStream(inXML);
while(dis.available()!=0){
System.out.println(dis.readLine());
}

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
e.printStackTrace();
}
render.renderXML(input);
}

When im using :

DataInputStream dis;
dis = new DataInputStream(inXSL);
while(dis.available()!=0){
System.out.println(dis.readLine());
}

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
Rancher
Posts: 13048
6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
[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.

Bill
 
Paul Clapham
Sheriff
Pie
Posts: 20203
26
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank, i've resolved this problem. my fop version is 0.25. i tried using fop 0.95, it run ok
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic