Search code examples
xsltxsl-foapache-fop

Print something every nth page


I am producing a document which will be wrapped automatically in envelopes.

For that purpose, the document needs to feature a marker every 5 pages and on its last page.

The problem is that AFAIK, XSL can't rely on < fo:page > provided by FO.

Can anyone think of a solution?


Solution

  • The best that I have been able to do does also require that you put enough repetitions in your fo:page-sequence-master to handle the maximum number of pages.

    For the sake of making a smaller screenshot, this example puts a mark on every third page and on the last page:

    <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format"
        xmlns:axf="http://www.antennahouse.com/names/XSL/Extensions"
        font-size="36pt">
        <fo:layout-master-set>
            <fo:simple-page-master master-name="spm" page-width="5in" page-height="5in">
                <fo:region-body margin="36pt"/>
            </fo:simple-page-master>
            <fo:simple-page-master master-name="marked" page-width="5in" page-height="5in">
                <fo:region-body margin="36pt"/>
                <fo:region-start extent="36pt"/>
            </fo:simple-page-master>
            <fo:page-sequence-master master-name="psm">
                <fo:repeatable-page-master-alternatives maximum-repeats="2">
                    <fo:conditional-page-master-reference master-reference="marked" page-position="last"/>
                    <fo:conditional-page-master-reference master-reference="spm"/>
                </fo:repeatable-page-master-alternatives>
                <fo:single-page-master-reference master-reference="marked"/>
                <fo:repeatable-page-master-alternatives maximum-repeats="2">
                    <fo:conditional-page-master-reference master-reference="marked" page-position="last"/>
                    <fo:conditional-page-master-reference master-reference="spm"/>
                </fo:repeatable-page-master-alternatives>
                <fo:single-page-master-reference master-reference="marked"/>
                <!-- Repeat as often as necessary. -->
                <fo:repeatable-page-master-alternatives maximum-repeats="2">
                    <fo:conditional-page-master-reference master-reference="marked" page-position="last"/>
                    <fo:conditional-page-master-reference master-reference="spm"/>
                </fo:repeatable-page-master-alternatives>
                <fo:single-page-master-reference master-reference="marked"/>
            </fo:page-sequence-master>
        </fo:layout-master-set>
        <fo:page-sequence master-reference="psm">
            <fo:static-content flow-name="xsl-region-start">
                <fo:block margin-top="2in"><fo:external-graphic width="100%" src="logo-antenna.svg" content-width="scale-down-to-fit"/></fo:block>
            </fo:static-content>
            <fo:flow flow-name="xsl-region-body">
                <fo:block break-after="page">1</fo:block>
                <fo:block break-after="page">2</fo:block>
                <fo:block break-after="page">3</fo:block>
                <fo:block break-after="page">4</fo:block>
                <fo:block>5</fo:block>
            </fo:flow>
        </fo:page-sequence>
    </fo:root>
    

    enter image description here