aspose file tools*
The moose likes XML and Related Technologies and the fly likes Exception while processing XSL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Exception while processing XSL" Watch "Exception while processing XSL" New topic
Author

Exception while processing XSL

Nikhil Chandran
Greenhorn

Joined: Sep 10, 2007
Posts: 23
Dear All,

Currently I am working with Apache FOP to generate PDF using XSL-FO and XML

I got stuck up with an exception says like

com.sun.org.apache.bcel.internal.generic.ClassGenException: Branch target offset too large for short
at com.sun.org.apache.bcel.internal.generic.BranchInstruction.dump(BranchInstruction.java:99)
at com.sun.org.apache.bcel.internal.generic.InstructionList.getByteCode(InstructionList.java:980)
at com.sun.org.apache.bcel.internal.generic.MethodGen.getMethod(MethodGen.java:587)
at com.sun.org.apache.xalan.internal.xsltc.compiler.Mode.compileNamedTemplate(Mode.java:581)
at com.sun.org.apache.xalan.internal.xsltc.compiler.Mode.compileTemplates(Mode.java:591)
at com.sun.org.apache.xalan.internal.xsltc.compiler.Mode.compileApplyTemplates(Mode.java:843)
at com.sun.org.apache.xalan.internal.xsltc.compiler.Stylesheet.compileModes(Stylesheet.java:615)
at com.sun.org.apache.xalan.internal.xsltc.compiler.Stylesheet.translate(Stylesheet.java:730)
at com.sun.org.apache.xalan.internal.xsltc.compiler.XSLTC.compile(XSLTC.java:354)
at com.sun.org.apache.xalan.internal.xsltc.compiler.XSLTC.compile(XSLTC.java:429)
at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl.newTemplates(TransformerFactoryImpl.java:796)
at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl.newTransformer(TransformerFactoryImpl.java:623)
at com.newapp.pdf.actions.XslFoPdfExperian.main(XslFoPdfExperian.java:125)
ERROR: 'Branch target offset too large for short'
FATAL ERROR: 'Could not compile stylesheet'
javax.xml.transform.TransformerConfigurationException: Could not compile stylesheet
at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl.newTemplates(TransformerFactoryImpl.java:829)
at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl.newTransformer(TransformerFactoryImpl.java:623)
at com.newapp.pdf.actions.XslFoPdfTest.main(XslFoPdfTest.java:125)


I have around 1500 lines of code in my xsl sheet.
I believe the problem is due to the size of xsl sheet.I can't reduce the lines of code inside my xsl as its needed to generate my PDF report.

Here is my java code


Source xsltSrc = new StreamSource(new File("INPUT.XSL"));
Transformer transformer = tFactory.newTransformer(xsltSrc);
ByteArrayInputStream Bis1 = new ByteArrayInputStream(report.toString().getBytes("UTF-8"));
Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, out);
Result res = new SAXResult(fop.getDefaultHandler());
Source src = new StreamSource(Bis1);
transformer.transform(src, res);
OutputStream oustt = new java.io.FileOutputStream("OUTPUT.pdf");

Could anyone please advice me on this issue.




Thanks in advance
NikhilChandran




William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12788
    
    5
Thats a tough one.

Can you pre-process / reformat your XML to make the XSL sheet simpler? I had to do that for one FOP project.

Bill
Nikhil Chandran
Greenhorn

Joined: Sep 10, 2007
Posts: 23
Thank you for quick reply.
Is there anything we have to remember while reformatting xml , regarding the maximum size limit of xsl ...
Also what may be the root cause of this exception. Is it due to the problem with JVM or Apache FOP ?


Thanks
NikhilChandran
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12788
    
    5
The error comes from the compiler trying to create a Java method from your XSLT design, just like the error message said.

I don't know enough about how xsltc turns XSL into methods to comment authoritatively about how to break your XSL into chunks that will compile.

Bill
Nikhil Chandran
Greenhorn

Joined: Sep 10, 2007
Posts: 23
Yes...I divided the large XSL Template I had into smaller templates and called inside the parent template
Now the issue is resolved.Thank you very much for your help.

Thanks,
NikhilChandran
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12788
    
    5

Hurrah!
Thanks for posting the solution.
Bill
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Exception while processing XSL