user74952
user74952

Reputation: 35

Apache FOP usage of "-param"

I'm working with Apache FOP v.1.0 (latest) on Windows XP and I want to use parameters. I used different parameter syntaxes, but "fop" doesn't use it. In the documentation is written: "-param name value".

Parts of my XML file:

<letter position="1">

I have in my XSLT file:

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

The following works:

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

And this works also:

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

So FOP just doesn't gets any input.

Commands I tried, which didn't work:

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

I looked at Processing FOP with parameters but they don't give a working example.

Many thanks,

Upvotes: 2

Views: 2768

Answers (1)

Daniel Haley
Daniel Haley

Reputation: 52858

Is your xsl:param a child of xsl:stylesheet or do you have it in an xsl:template? It should be a direct child of xsl:stylesheet.

Here is a working example...

XML Input (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 command line (Version 1.0 on Windows XP)

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

PDF Output (param_test.pdf)

enter image description here

Upvotes: 1

Related Questions