Headers and footers

Referring to Figure 976, “Regions being defined in a page. ” we now want to add fixed headers and footers frequently being used for page numbers. In a textbook each page might have the actual chapter's name in its header. This name should not change as long as the text below fo:region-body still belongs to the same chapter. In FO this is achieved by:

The notion fo:static-content refers to the fact that the content is constant (static) within the given page sequence. The new version reads:

Figure 979. Parameterizing header and footer. Create comment in forum
<?xml version="1.0" encoding="utf-8"?>
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format"
  font-size="6pt">

  <fo:layout-master-set>
    <fo:simple-page-master master-name="simplePageLayout"
      page-width  = "50mm" page-height   = "80mm"
      margin-top  = "5mm"  margin-bottom = "20mm"
      margin-left = "5mm"  margin-right  = "10mm">

      <fo:region-body margin-top  = "10mm" margin-bottom = "5mm" ❶
                      margin-left = "10mm" margin-right  = "5mm"/>

      <fo:region-before extent="5mm"/> <fo:region-after  extent="5mm"/> </fo:simple-page-master>
  </fo:layout-master-set>

  <fo:page-sequence master-reference="simplePageLayout">

    <fo:static-content flow-name="xsl-region-before"> <fo:block
        font-weight="bold"
        font-size="8pt">Headertext</fo:block>
    </fo:static-content>

    <fo:static-content flow-name="xsl-region-after"> <fo:block>
        <fo:page-number/>
      </fo:block>
    </fo:static-content>

    <fo:flow flow-name="xsl-region-body">
      <fo:block space-after="8mm">Dumb text .. dumb text.</fo:block>
      <fo:block space-after="8mm">Dumb text .. dumb text.</fo:block>
      <fo:block space-after="8mm">More text .. more text.</fo:block>
      <fo:block space-after="8mm">More text .. more text.</fo:block>
      <fo:block space-after="8mm">More text .. more text.</fo:block>
    </fo:flow>
  </fo:page-sequence>
</fo:root>

Defining the body region.

Defining two regions at the top and bottom of each page. The extent attribute denotes the height of these regions. Caveat: The attribute extent's value gets subtracted from the margin-top or margin-bottom value being defined in the corresponding <fo:region-body> element. So if we consider for example the fo:region-before we have to obey:

extent <= margin-top

Otherwise we may not even see any output.

A fo:static-content denotes text portions which are decoupled from the usual text flow. For example as a book's chapter advances over multiple pages we expect the constant chapter's title to appear on top of each page. In the current example the static string Headertext will appear on each page's top for the whole <fo:page-sequence> in which it is defined. Notice the flow-name="xsl-region-after" reference to the region being defined in ❷.

We do the same here for the page's footer. Instead of static text we output fo_page-number yielding the current page's number.

This time flow-name="xsl-region-after" references the region definition in ❸. Actually the attribute flow-name is restricted to the following five values corresponding to all possible region definitions within a layout:

<fo:region-body> xsl-region-body
<fo:region-before> xsl-region-before
<fo:region-after> xsl-region-after
<fo:region-start> xsl-region-start
<fo:region-end> xsl-region-end

This results in two pages with page numbers 1 and 2:

The free chapter from [Harold2004] book contains additional information on extended layout definitions. The W3C as the holder of the FO standard defines the elements fo:layout-master-set, fo:simple-page-master and fo:page-sequence