I developed a way to generate multiple page-sequence on XSL without to change my XML, but the XML-XSL-PDF don't work, to make this work, first I need to generate the .fo file, then transform this to PDF.
if run:
fop.sh -xml sample.xml -xsl multiplePageSequence.xsl -pdf sample.pdf
I get follow output:
[INFO] Using org.apache.xerces.parsers.SAXParser as SAX2 Parser
[INFO] FOP 0.20.5
[INFO] Using org.apache.xerces.parsers.SAXParser as SAX2 Parser
[INFO] building formatting object tree
[INFO] setting up fonts
[ERROR] org.apache.fop.apps.FOPException: flow must be child of page-sequence, not fo:flow
but if I first generate the .fo file with:
xalan.sh -IN sample.xml -XSL multiplePageSequence.xsl -OUT sample.fo
then generate the .pdf file from .fo file with:
fop.sh -fo sample.fo -pdf sample.pdf
I get the follow output:
[INFO] Using org.apache.xerces.parsers.SAXParser as SAX2 Parser [INFO] FOP 0.20.5 [INFO] Using org.apache.xerces.parsers.SAXParser as SAX2 Parser [INFO] building formatting object tree [INFO] setting up fonts [INFO] [1] [INFO] [2] [INFO] [3] [INFO] [4] [INFO] Parsing of document complete, stopping renderer
The part of XSL that cause on the fly transformation to catch the ERROR is:
<xsl:template name="ctrlPage"> <xsl:if test="(position() mod 3) = 0">
<xsl:text disable-output-escaping="yes"><![CDATA[</fo:flow></fo:page-sequence><fo:page-sequence master-reference="A4" language="pt" country="br">]]></xsl:text>
<xsl:call-template name="header"/>
<xsl:text disable-output-escaping="yes"><![CDATA[<fo:flow flow-name="xsl-region-body">]]></xsl:text>
</xsl:if>
</xsl:template>
to close and open fo:flow and fo:page-sequence for
<xsl:template match="data">
<fo:page-sequence master-reference="A4" language="pt" country="br">
<xsl:call-template name="header"/>
<fo:flow flow-name="xsl-region-body">
<xsl:apply-templates />
</fo:flow>
</fo:page-sequence>
</xsl:template>I can't understand because on the fly don't woks and from .fo file generated from xml+xsl transformation work, maybe a bug of FOP, or I can't generate XML elements using CDATA from this form.
I post this in dev list because I think that this is a feature or a bug on FOP then I attached the XSL and XML files that the team can test this issue, and the code is better to read than my bad English ;)
Thanks for any help or tip
Clovis
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:fo="http://www.w3.org/1999/XSL/Format"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml"/>
<xsl:template match="/">
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
<fo:layout-master-set>
<fo:simple-page-master master-name="A4" page-width="297mm" page-height="210mm" margin-top="5mm" margin-bottom="5mm" margin-left="3mm" margin-right="5mm">
<fo:region-before extent="20.8mm"/>
<fo:region-body margin-top="21.8mm" margin-bottom="0in"/>
<fo:region-after extent="0in"/>
<fo:region-start extent="0in" margin-top="0mm" margin-bottom="0mm" margin-left="0mm" margin-right="0mm"/>
<fo:region-end extent="0in" margin-top="0mm" margin-bottom="0mm" margin-left="0mm" margin-right="0mm"/>
</fo:simple-page-master>
</fo:layout-master-set>
<xsl:apply-templates />
</fo:root>
</xsl:template>
<xsl:template match="info"></xsl:template>
<xsl:template match="data">
<fo:page-sequence master-reference="A4" language="pt" country="br">
<xsl:call-template name="header"/>
<fo:flow flow-name="xsl-region-body">
<xsl:apply-templates />
</fo:flow>
</fo:page-sequence>
</xsl:template>
<xsl:template match="product">
<xsl:call-template name="detail" />
</xsl:template>
<!-- Header For Pages -->
<xsl:template name="header">
<fo:static-content flow-name="xsl-region-before">
<fo:table table-layout="fixed">
<fo:table-column column-width="40mm"/>
<fo:table-column column-width="40mm"/>
<fo:table-column column-width="40mm"/>
<fo:table-body>
<fo:table-row>
<fo:table-cell>
<fo:block>HEADER CEL 1</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block>HEADER CEL 2</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block>HEADER CEL 3</fo:block>
</fo:table-cell>
</fo:table-row>
</fo:table-body>
</fo:table>
</fo:static-content>
</xsl:template>
<!-- Control Page Sequence Creation -->
<xsl:template name="ctrlPage">
<xsl:if test="(position() mod 3) = 0">
<xsl:text disable-output-escaping="yes"><![CDATA[</fo:flow></fo:page-sequence><fo:page-sequence master-reference="A4" language="pt" country="br">]]></xsl:text>
<xsl:call-template name="header"/>
<xsl:text disable-output-escaping="yes"><![CDATA[<fo:flow flow-name="xsl-region-body">]]></xsl:text>
</xsl:if>
</xsl:template>
<!-- Detail -->
<xsl:template name="detail">
<xsl:call-template name="ctrlPage"/>
<fo:table table-layout="fixed">
<fo:table-column column-width="45mm"/>
<fo:table-column column-width="45mm"/>
<fo:table-body>
<fo:table-row>
<fo:table-cell>
<fo:block><xsl:value-of select="@name"/></fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block><xsl:value-of select="@value"/></fo:block>
</fo:table-cell>
</fo:table-row>
</fo:table-body>
</fo:table>
</xsl:template>
</xsl:stylesheet><?xml version="1.0" encoding="ISO-8859-1"?>
<report version="1.0">
<info><description>A Sample report</description></info>
<data>
<product name="AAAAAAAAA" value="1.01" />
<product name="BBBBBBBBB" value="1.02" />
<product name="CCCCCCCCC" value="1.03" />
<product name="DDDDDDDDD" value="1.04" />
<product name="EEEEEEEEE" value="1.05" />
<product name="FFFFFFFFF" value="1.06" />
<product name="GGGGGGGGG" value="1.07" />
<product name="HHHHHHHHH" value="1.08" />
<product name="IIIIIIIII" value="1.09" />
<product name="JJJJJJJJJ" value="1.10" />
</data>
</report>
