2012-02-29 42 views
1

我在Windows XP上使用Apache FOP v.1.0(最新版),我想使用参数。我使用了不同的参数语法,但“fop”不使用它。在文档中写有:“-param name value”。我的XML文件的“-param”的Apache FOP用法

配件:

<letter position="1"> 

我在XSLT文件:

<xsl:param name="position"/> 
<xsl:for-each select="letter[@position=$position]"> 

以下工作:

<xsl:for-each select="letter[@position=1]"> 

而这个作品也:

<xsl:param name="position" select="1"/> 
<xsl:for-each select="letter[@position=$position]"> 

所以FOP只是没有得到任何输入。

命令我试过了,没有工作:

fop -param position 1 -xml data.xml -xsl stylesheet.xsl -pdf output.pdf 
fop -xml data.xml -param position 1 -xsl stylesheet.xsl -pdf output.pdf 
fop -xml data.xml -xsl stylesheet.xsl -param position 1 -pdf output.pdf 
fop -xml data.xml -xsl stylesheet.xsl -pdf output.pdf -param position 1 

fop -xml data.xml -xsl stylesheet.xsl -pdf output.pdf -param "position" 1 
fop -xml data.xml -xsl stylesheet.xsl -pdf output.pdf -param position "1" 
fop -xml data.xml -xsl stylesheet.xsl -pdf output.pdf -param "position" "1" 

fop -xml data.xml -xsl stylesheet.xsl -param "position" 1 -pdf output.pdf 
fop -xml data.xml -xsl stylesheet.xsl -param position "1" -pdf output.pdf 
fop -xml data.xml -xsl stylesheet.xsl -param "position" "1" -pdf output.pdf 

fop -xml data.xml -param "position" 1 -xsl stylesheet.xsl -pdf output.pdf 
fop -xml data.xml -param position "1" -xsl stylesheet.xsl -pdf output.pdf 
fop -xml data.xml -param "position" "1" -xsl stylesheet.xsl -pdf output.pdf 

fop -param "position" 1 -xml data.xml -xsl stylesheet.xsl -pdf output.pdf 
fop -param position "1" -xml data.xml -xsl stylesheet.xsl -pdf output.pdf 
fop -param "position" "1" -xml data.xml -xsl stylesheet.xsl -pdf output.pdf 

我看着Processing FOP with parameters,但他们不给工作的例子。

非常感谢,

回答

0

是您xsl:paramxsl:stylesheet一个孩子或者你有它在xsl:template?它应该是xsl:stylesheet的直接子女。

下面是一个工作示例...

XML输入(param_test.xml)

<doc> 
    <letter position="1">position 1</letter> 
    <letter position="2">position 2</letter> 
    <letter position="3">position 3</letter> 
    <letter position="4">position 4</letter> 
</doc> 

XSLT 1.0(param_test.xsl)

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
    <xsl:output indent="yes"/> 
    <xsl:strip-space elements="*"/> 

    <xsl:param name="position"/> 

    <xsl:template match="/doc"> 
    <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format"> 
     <fo:layout-master-set> 
     <fo:simple-page-master master-name="my-page" page-width="8.5in" page-height="11in"> 
      <fo:region-body margin="1in" margin-top="1.5in" margin-bottom="1.5in"/> 
     </fo:simple-page-master> 
     </fo:layout-master-set> 
     <fo:page-sequence master-reference="my-page"> 
     <fo:flow flow-name="xsl-region-body"> 
      <xsl:for-each select="letter[@position=$position]"> 
      <fo:block> 
       <xsl:value-of select="."/> 
      </fo:block> 
      </xsl:for-each> 
     </fo:flow> 
     </fo:page-sequence> 
    </fo:root> 
    </xsl:template> 
</xsl:stylesheet> 

FOP命令行(Windows XP上的版本1.0)

fop -xml param_test.xml -xsl param_test.xsl -pdf param_test.pdf -param position 1 

PDF输出(param_test.pdf)

enter image description here

+0

我放置在参数在模板(的 user74952 2012-03-01 08:18:35

+0

因此,现在我有: '<?xml version =“1.0”encoding =“utf-8”?>' '' '' '' '' – user74952 2012-03-01 08:26:13

+0

@ user74952 - 非常欢迎您! – 2012-03-01 08:38:24