检索不同页面上的标记(第一个,最后一个和中间个)

时间:2015-04-27 09:22:10

标签: xsl-fo apache-fop

我的XSL代码:

            <fo:layout-master-set>

                <fo:simple-page-master master-name="page-even" page-height="210mm" page-width="148mm"> 
                    <fo:region-body region-name="xsl-region-body" margin="28mm 8mm 10mm 2mm" />
                    <fo:region-before region-name="xsl-region-before-even"/>
                    <fo:region-after region-name="xsl-region-after-even" extent="12mm"/>
                </fo:simple-page-master>

                <fo:simple-page-master master-name="page-odd" page-height="210mm" page-width="148mm"> 
                    <fo:region-body region-name="xsl-region-body" margin="28mm 2mm 10mm 8mm" />
                    <fo:region-before region-name="xsl-region-before-odd"/>
                    <fo:region-after region-name="xsl-region-after-odd" extent="12mm"/>
                </fo:simple-page-master>

                 <fo:simple-page-master master-name="last-page-even" page-height="210mm" page-width="148mm">
                    <fo:region-body />
                    <fo:region-before region-name="header-blank" extent="210mm"/>
                    <fo:region-after region-name="xsl-region-after-even" extent="12mm"/>
                </fo:simple-page-master>

                <fo:page-sequence-master master-name="document">
                    <fo:repeatable-page-master-alternatives>
                        <fo:conditional-page-master-reference odd-or-even="odd" master-reference="page-odd" blank-or-not-blank="not-blank"/>
                        <fo:conditional-page-master-reference odd-or-even="even" master-reference="page-even" blank-or-not-blank="not-blank"/>
                        <fo:conditional-page-master-reference blank-or-not-blank="blank" odd-or-even="even" master-reference="last-page-even"/>
                    </fo:repeatable-page-master-alternatives>
                </fo:page-sequence-master>

            </fo:layout-master-set>

                <fo:page-sequence master-reference="document" force-page-count="end-on-even" id="TheVeryLastPage">

                    <!--Headers-->
                    <fo:static-content flow-name="xsl-region-before-odd">
                        <fo:block font-weight="normal" font-family="Helvetica" text-align="center" margin="6mm 2mm 0mm 8mm">

                       </fo:block>
                       <fo:retrieve-marker retrieve-class-name="amarker"/>
                    </fo:static-content>

                    <fo:static-content flow-name="xsl-region-before-even">
                        <fo:block font-weight="normal" font-family="Helvetica" text-align="center" margin="6mm 8mm 0mm 2mm">

                       </fo:block>
                       <fo:retrieve-marker retrieve-class-name="amarker"/>
                    </fo:static-content>

                    <fo:static-content flow-name="header-blank">
                        <fo:block font-weight="normal" font-family="Helvetica" text-align="center" margin="6mm 8mm 0mm 2mm">

                       </fo:block>
                        <fo:block text-align-last="center" font-size="9.5" margin-top="75mm">
                             Intentionally left blank
                        </fo:block>
                        <fo:retrieve-marker retrieve-class-name="amarker"/>
                   </fo:static-content>

                    <!--Footers-->
                    <fo:static-content flow-name="xsl-region-after-odd">
                        <fo:block font-size="9pt" font-weight="normal" font-family="Helvetica" margin="0mm 2mm 0mm 8mm">

                        </fo:block>
                        <fo:retrieve-marker retrieve-class-name="amarker"/>
                    </fo:static-content>

                    <fo:static-content flow-name="xsl-region-after-even">
                        <fo:block font-size="9pt" font-weight="normal" font-family="Helvetica" margin="0mm 8mm 0mm 2mm">

                        </fo:block>
                        <fo:retrieve-marker retrieve-class-name="amarker"/>
                    </fo:static-content>

                    <!--Body-->
                    <fo:flow flow-name="xsl-region-body">
                        <fo:block-container font-size="9.5pt" font-weight="normal" font-family="Helvetica">
                            <fo:block>
                                <fo:marker marker-class-name="amarker">
                                    <fo:block>xxx</fo:block>
                                </fo:marker>
                            </fo:block>

                        </fo:block-container>
                    </fo:flow>

我试图将&#34; 继续放在下一页&#34;每当页面中断时页脚上的标签(但不是下一页故意留空时)和&#34; 接上页&#34;上一页打破时的标签(但不是当页面有意留空时)。

我尝试了很多东西,但似乎没有什么能给我想要的输出。

我正在使用Apache Fop。

任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:2)

这不是那么容易......

这是一个解决方案,它与FOP一起使用(我发现另一个与Antenna House表现良好,但没有与Apache FOP一起表现):

还必须为故意留空设置特定页脚;我在代码中写下了一些评论;如果您有其他问题,请不要犹豫。

请注意:

  1. 小心添加<fo:marker>的位置;它们需要作为<fo:block> s。
  2. 的第一个孩子(ren)插入
  3. 要输出第一个块进行特殊处理。
  4. <fo:layout-master-set>
    
        <fo:simple-page-master master-name="page-even" page-height="210mm" page-width="148mm">
            <fo:region-body region-name="xsl-region-body" margin="28mm 8mm 10mm 2mm"/>
            <fo:region-before region-name="xsl-region-before-even" extent="12mm"/>
            <fo:region-after region-name="xsl-region-after-even" extent="12mm"/>
        </fo:simple-page-master>
    
        <fo:simple-page-master master-name="page-odd" page-height="210mm" page-width="148mm">
            <fo:region-body region-name="xsl-region-body" margin="28mm 2mm 10mm 8mm"/>
            <fo:region-before region-name="xsl-region-before-odd" extent="12mm"/>
            <fo:region-after region-name="xsl-region-after-odd" extent="12mm"/>
        </fo:simple-page-master>
    
        <fo:simple-page-master master-name="last-page-even" page-height="210mm" page-width="148mm">
            <fo:region-body/>
            <fo:region-before region-name="header-blank" extent="210mm"/>
            <!-- created a specific footer for the conditionally inserted page -->
            <fo:region-after region-name="footer-blank" extent="12mm"/>
        </fo:simple-page-master>
    
        <fo:page-sequence-master master-name="document">
            <fo:repeatable-page-master-alternatives>
                <fo:conditional-page-master-reference odd-or-even="odd" master-reference="page-odd"
                    blank-or-not-blank="not-blank"/>
                <fo:conditional-page-master-reference odd-or-even="even"
                    master-reference="page-even" blank-or-not-blank="not-blank"/>
                <fo:conditional-page-master-reference blank-or-not-blank="blank" odd-or-even="even"
                    master-reference="last-page-even"/>
            </fo:repeatable-page-master-alternatives>
        </fo:page-sequence-master>
     </fo:layout-master-set>
    
      <fo:page-sequence master-reference="document" force-page-count="end-on-even" id="TheVeryLastPage">
            <!-- Headers -->
        <fo:static-content flow-name="xsl-region-before-odd">
            <fo:block font-weight="normal" font-family="Helvetica" text-align="center"
                margin="6mm 2mm 0mm 8mm"> </fo:block>
            <fo:retrieve-marker retrieve-class-name="continued"
                retrieve-position="first-starting-within-page" retrieve-boundary="page-sequence"/>
        </fo:static-content>
    
        <fo:static-content flow-name="xsl-region-before-even">
            <fo:block font-weight="normal" font-family="Helvetica" text-align="center"
                margin="6mm 8mm 0mm 2mm"> header even </fo:block>
            <fo:retrieve-marker retrieve-class-name="continued"
                retrieve-position="first-starting-within-page" retrieve-boundary="page-sequence"/>
        </fo:static-content>
    
        <fo:static-content flow-name="header-blank">
            <fo:block font-weight="normal" font-family="Helvetica" text-align="center"
                margin="6mm 8mm 0mm 2mm"> </fo:block>
            <fo:block text-align-last="center" font-size="18" font-weight="bold">Intentionally left
                blank
            </fo:block>
        </fo:static-content>
    
        <!--Footers-->
        <fo:static-content flow-name="xsl-region-after-odd">
            <fo:block font-size="9pt" font-weight="normal" font-family="Helvetica"
                margin="0mm 2mm 0mm 8mm"> </fo:block>
            <fo:retrieve-marker retrieve-class-name="tobefollowed"
                retrieve-position="last-ending-within-page" retrieve-boundary="page-sequence"/>
        </fo:static-content>
    
        <fo:static-content flow-name="xsl-region-after-even">
            <fo:block font-size="9pt" font-weight="normal" font-family="Helvetica"
                margin="0mm 8mm 0mm 2mm"> </fo:block>
            <fo:retrieve-marker retrieve-class-name="tobefollowed"
                retrieve-position="last-ending-within-page" retrieve-boundary="page-sequence"/>
        </fo:static-content>
    
        <fo:static-content flow-name="footer-blank">
            <fo:block font-size="9pt" font-weight="normal" font-family="Helvetica"
                margin="0mm 8mm 0mm 2mm"> </fo:block>
        </fo:static-content>
    
        <!--Body-->
        <fo:flow flow-name="xsl-region-body" font-size="9.5pt" font-weight="normal"
            font-family="Helvetica">
    
    
            <fo:block>
                <!-- set up the first marker as empty, in order to have nothing of the first page -->
                <fo:marker marker-class-name="continued"><fo:block><!-- No text --></fo:block></fo:marker>
                <!-- Prepare to insert "to be continued" -->
                <fo:marker marker-class-name="tobefollowed">
                    <fo:block>Continued on the following page</fo:block>
                </fo:marker>
            </fo:block>
            <!-- !!!! FIRST BLOCK !!!! -->
            <fo:block>
                <!-- the other pages may have "continued" mentined in the header --> 
                <fo:marker marker-class-name="continued"><fo:block>Continued from the previous page</fo:block></fo:marker>
                Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla suscipit sem
                ut sollicitudin imperdiet. Donec pulvinar arcu quis diam scelerisque vestibulum.
                Curabitur et rhoncus ipsum, at molestie tellus. Vestibulum ante ipsum primis in
                faucibus orci luctus et ultrices posuere cubilia Curae; Integer vitae faucibus dui.
                Nullam laoreet felis a tristique varius. Proin urna tellus, dignissim ut laoreet
                eget, rhoncus non diam. In nisl nibh, ultricies malesuada nibh eu, imperdiet
                fermentum tortor. Donec id aliquam ante, ut posuere sapien. Vivamus et gravida
                velit, quis dictum libero. Suspendisse porttitor, risus quis luctus malesuada, elit
                felis sollicitudin ante, eu vestibulum justo lectus nec metus. Vestibulum nec
                bibendum dui, accumsan ultrices turpis. </fo:block>
    
                <!-- ... output all your text here ... -->
            <fo:block>
                <!-- This one is empty so that the end is not without any text -->
                <fo:marker marker-class-name="tobefollowed"><fo:block><!-- No text --></fo:block></fo:marker>
                <!-- And this one is to know that text may cut up onto different pages -->
                <fo:marker marker-class-name="continued"><fo:block>Continued from the previous page</fo:block></fo:marker>
    
            </fo:block>
        </fo:flow>
    </fo:page-sequence>