使用ApacheFop和StyleVision使用Saxon在Java中将XSLT2.0转换为PDF
我正在使用Altova StyleVision生成XSLT和XSLT-FO模板,当我生成XSLT 1.0 FO文件时,我使用下面的代码通过Apache FOP转换成功地转换为PDF使用ApacheFop和StyleVision使用Saxon在Java中将XSLT2.0转换为PDF,java,xml,xslt-2.0,saxon,apache-fop,Java,Xml,Xslt 2.0,Saxon,Apache Fop,我正在使用Altova StyleVision生成XSLT和XSLT-FO模板,当我生成XSLT 1.0 FO文件时,我使用下面的代码通过Apache FOP转换成功地转换为PDF DefaultConfigurationBuilder cfgBuilder = new DefaultConfigurationBuilder(); Configuration cfg = cfgBuilder .buildFromFile(new F
DefaultConfigurationBuilder cfgBuilder = new DefaultConfigurationBuilder();
Configuration cfg = cfgBuilder
.buildFromFile(new File("fop.xconf"));
FopFactoryBuilder fopFactoryBuilder = new FopFactoryBuilder(
new File("fopbase").toURI()).setConfiguration(cfg);
FopFactory fopFactory = fopFactoryBuilder.build();
File xsltFile = new File(
"xslt1File.xslt");
StreamSource xmlSource = new StreamSource(
new File("xmlData.xml"));
FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
OutputStream out;
out = new java.io.FileOutputStream("GeneratedPDF.pdf");
try {
Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, foUserAgent, out);
TransformerFactory factory = TransformerFactory.newInstance();
Transformer transformer = factory.newTransformer(new StreamSource(xsltFile));
Result res = new SAXResult(fop.getDefaultHandler());
transformer.transform(xmlSource, res);
} finally {
out.close();
}
这段代码非常有效
XSLT-FO 2.0
当我从StyleVision生成XSLT-FO2.0模板时,问题一直在尝试使用XSLT2.0的特性
我读了一篇文章,所以我下载了saxon9.jar[并添加到构建路径],我更改了Transformer工厂,如下所示
DefaultConfigurationBuilder cfgBuilder = new DefaultConfigurationBuilder();
Configuration cfg = cfgBuilder
.buildFromFile(new File("fop.xconf"));
FopFactoryBuilder fopFactoryBuilder = new FopFactoryBuilder(
new File("fopbase").toURI()).setConfiguration(cfg);
FopFactory fopFactory = fopFactoryBuilder.build();
File xsltFile = new File(
"xslt1File.xslt");
StreamSource xmlSource = new StreamSource(
new File("xmlData.xml"));
FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
OutputStream out;
out = new java.io.FileOutputStream("GeneratedPDF.pdf");
try {
Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, foUserAgent, out);
TransformerFactory factory = new net.sf.saxon.TransformerFactoryImpl();
Transformer transformer = factory.newTransformer(new StreamSource(xsltFile));
Result res = new SAXResult(fop.getDefaultHandler());
transformer.transform(xmlSource, res);
} finally {
out.close();
}
TransformerFactory=new net.sf.saxon.TransformerFactoryImpl()强>
当我运行代码时,我得到一个错误
Error at xsl:import-schema on line 12 column 67 of xsltfile.xslt:
XTSE1650: xsl:import-schema requires Saxon-EE
javax.xml.transform.TransformerConfigurationException: net.sf.saxon.s9api.SaxonApiException: xsl:import-schema requires Saxon-EE
at net.sf.saxon.jaxp.SaxonTransformerFactory.newTemplates(SaxonTransformerFactory.java:157)
at net.sf.saxon.jaxp.SaxonTransformerFactory.newTransformer(SaxonTransformerFactory.java:110)
at main.FopTransformer.convertToPDF(FopTransformer.java:60)
at main.FopTransformer.main(FopTransformer.java:29)
你们中有谁知道一个完整的解决方案,可以使用saxon HE将xml+XSLT2.0转换为java中的PDF
任何帮助都将不胜感激
谢谢
你们中有谁知道一个完整的转换xml的解决方案吗+
使用saxon HE将java中的XSLT2.0转换为PDF
错误信息非常清楚:如果您想使用支持模式的XSLT2.0,您需要Saxon EE。你的问题的答案是:
如果您想用Saxon HE来实现,那么样式表就不能使用xsl:import schema
你们中有谁知道一个完整的转换xml的解决方案吗+
使用saxon HE将java中的XSLT2.0转换为PDF
错误信息非常清楚:如果您想使用支持模式的XSLT2.0,您需要Saxon EE。你的问题的答案是:
如果你想使用Saxon HE,那么你的样式表就不能使用
xsl:import schema
嗨,很抱歉,我添加了saxon9ee.jar,但是我还是有同样的错误。哦,我的天啊。我简直不敢相信我收到了XSLT2.0和XPath2.0第四版作者的回复。尽管saxon9ee.jar仍在失败,但感谢您帮助我解决问题。除了将Saxon EE jar放在类路径上,您还需要使用TransformerFactory factory=new com.saxonica.config.EnterpriseTransformerFactory()调用它代码>谢谢。现在我需要一个许可证。嗨,很抱歉,我添加了saxon9ee.jar,但是我仍然有同样的错误。哦,我的上帝。我简直不敢相信我收到了XSLT2.0和XPath2.0第四版作者的回复。尽管saxon9ee.jar仍在失败,但感谢您帮助我解决问题。除了将Saxon EE jar放在类路径上,您还需要使用TransformerFactory factory=new com.saxonica.config.EnterpriseTransformerFactory()调用它代码>谢谢。现在我需要执照。