我已将 fop 嵌入到 java 程序中:
public class run {
public static void main(String [ ] args){
FopFactory fopFactory = FopFactory.newInstance();
OutputStream out = null;
try {
out = new BufferedOutputStream(new FileOutputStream(new File("F:/test.pdf")));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
try {
Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, out);
TransformerFactory factory = TransformerFactory.newInstance();
Source xslt = new StreamSource(new File("F:/main_structure.xsl"));
Transformer transformer = factory.newTransformer(xslt);
Source src = new StreamSource(new File("F:/source.xml"));
Result res = new SAXResult(fop.getDefaultHandler());
transformer.transform(src, res);
} catch (FOPException e) {
e.printStackTrace();
} catch (TransformerConfigurationException e) {
e.printStackTrace();
} catch (TransformerException e) {
e.printStackTrace();
} finally {
try {
out.close();
System.out.println("ende");
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
现在我的 xsl (main_struct.xsl) 需要一个参数才能运行
<xsl:param name="OFFSET_LEFT" select="1"/>
在控制台中,我将使用“-param name value”属性将该参数传递给 fop。
那么如何将参数传递到嵌入式版本的 fop 中的 xsl 文件中?
最佳答案
例如:http://www.onlamp.com/pub/a/onjava/excerpt/java_xslt_ch5/index.html?page=4
Transformer transformer = factory.newTransformer(xslt);
transformer.setParameter("PARAMETER", "VALUE");
关于java - 将参数从 java 嵌入式 fop 传递到 xsl 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24239122/