Apache FOP from Java with XSLT 2.0…?

独自空忆成欢 提交于 2019-12-23 12:19:09

问题


I'm having problems using some of the features of XSLT 2.0 in an embedded use of Apache FOP 1.0. In particular I get an exception when using "current-group()".

I see that FOP is using xalan 2.6 which is throwing the exception.

I tried to exclude the transitive dependency of xalan 2.6 and replaced it with 2.7.1 but it didn't help. Is it possible to use Apache FOP with another XSLT processor that supports more 2.0 features?


回答1:


If you run FOP as standalone distribution from command line, you can

  1. copy the required jar file(s) with the XSLT processor (like e.g. saxon9he.jar) to the lib directory of your FOP distribution.

  2. and specify the processor implementation to be used by FOP by adding a VM parameter like this -Djavax.xml.transform.TransformerFactory=net.sf.saxon.TransformerFactoryImpl (example for Saxon) to the start script (fop on Linux, fop.bat on Windows) at the line where org.apache.fop.cli.Main is called.

If you embed FOP in your Java code, simply start your application with that VM parameter (and make sure the required jar files are in your CLASSPATH).




回答2:


If you need 2.0 features in XSLT, XPath... try another XSLT processor/engine different from provided by JDK or Xalan, like Saxon. Has a free version and a commercial one if you want to be schema-aware. We use with Apache-FOP in order to generate PDFs from XML data and works fine and you get some new feature in 2.0 like date and number formatting. Just use saxon9.jar and specify the XSLT engine used (saxon).



来源:https://stackoverflow.com/questions/7243136/apache-fop-from-java-with-xslt-2-0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!