[英]Pass a parameter from java-embedded fop to xsl file
我已經將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_structure.xsl)需要一個參數才能運行
<xsl:param name="OFFSET_LEFT" select="1"/>
在控制台中,我將使用“ -param名稱值”屬性將該參數傳遞給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");
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.