问题
I am having a problem to keep "region-before" only for first page. See my code:
<fo:layout-master-set>
<fo:simple-page-master master-name="first" margin-right="0.5cm" margin-left="0.5cm" margin-bottom="0.5cm" margin-top="0.75cm" page-width="21cm" page-height="29.7cm">
<fo:region-body region-name="xsl-region-body" margin-top="{$extra-body-margin-top+15.6-$header-margin}cm" margin-bottom="3.5cm" />
<fo:region-before region-name="xsl-region-before" extent="17cm" overflow="hidden" />
<fo:region-after region-name="xsl-region-after" extent="2.8cm" overflow="hidden" />
</fo:simple-page-master>
<fo:page-sequence-master master-name="psmA">
<fo:repeatable-page-master-alternatives>
<fo:conditional-page-master-reference master-reference="first" page-position="any" />
</fo:repeatable-page-master-alternatives>
</fo:page-sequence-master>
</fo:layout-master-set>
If I change the page-position="first" and my region-body exceeds the first page I got error. My idea is to keep the region-before only on the first page but the region-body and region-footer follow the next pages. Is any easy one to play with my code?
回答1:
- Set up a second
fo:simple-page-master
that does not have anfo:region-before
. - Add a second
fo:conditional-page-master-reference
so that thefirst
page master is used on the first page only (usingpage-position="first"
) and the other page master is used for the rest (usingpage-position="any"
).
This works because the formatter uses the first alternative for which all its conditions are true (see https://www.w3.org/TR/xsl11/#fo_repeatable-page-master-alternatives). Which is also why you put the one with page-position="any"
last, because that condition is always true.
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
<fo:layout-master-set>
<fo:simple-page-master master-name="first" margin-right="0.5cm" margin-left="0.5cm" margin-bottom="0.5cm" margin-top="0.75cm" page-width="21cm" page-height="29.7cm">
<fo:region-body region-name="xsl-region-body" margin-top="1cm" margin-bottom="3.5cm" />
<fo:region-before region-name="xsl-region-before" extent="17cm" overflow="hidden" />
<fo:region-after region-name="xsl-region-after" extent="2.8cm" overflow="hidden" />
</fo:simple-page-master>
<fo:simple-page-master master-name="rest" margin-right="0.5cm" margin-left="0.5cm" margin-bottom="0.5cm" margin-top="0.75cm" page-width="21cm" page-height="29.7cm">
<fo:region-body region-name="xsl-region-body" margin-top="1cm" margin-bottom="3.5cm" />
</fo:simple-page-master>
<fo:page-sequence-master master-name="psmA">
<fo:repeatable-page-master-alternatives>
<fo:conditional-page-master-reference master-reference="first" page-position="first" />
<fo:conditional-page-master-reference master-reference="rest" page-position="any" />
</fo:repeatable-page-master-alternatives>
</fo:page-sequence-master>
</fo:layout-master-set>
<fo:page-sequence master-reference="psmA">
<fo:static-content flow-name="xsl-region-before">
<fo:block>before</fo:block>
</fo:static-content>
<fo:flow flow-name="xsl-region-body" font-size="12pt" line-height="11pt">
<fo:block>content</fo:block>
<fo:block break-before="page">more content</fo:block>
</fo:flow>
</fo:page-sequence>
</fo:root>
来源:https://stackoverflow.com/questions/58341980/xslfo-keep-the-header-only-for-first-page