将参数从java嵌入式fop传递到xsl文件

将参数从java嵌入式fop传递到xsl文件,java,xml,xslt,parameters,apache-fop,Java,Xml,Xslt,Parameters,Apache Fop,我已经在java程序中嵌入了fop: 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:/

我已经在java程序中嵌入了fop:

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 name value”属性将该参数传递给fop

那么,如何在嵌入式版本的fop中将参数传递到xsl文件中呢?

例如,读取:

Transformer transformer = factory.newTransformer(xslt);
transformer.setParameter("PARAMETER", "VALUE");