Page templates and simple page sequence templates

This example demonstrates and explains how page templates and simple page sequence templates are generated.

In the first step the structure and the layout of pages which are used as page templates, for example for a title page or left and right sides of pages, are demonstrated (<fo:simple-page-master>). In the second step these page templates are combined to page sequences (<fo:page-sequence-master>). In the third step the page templates are filled with contents within a page sequence (<fo:page-sequence>).

Source code:

<xsl:template match="/">                                                            ❶ 
   <fo:root>
      <fo:layout-master-set>
         <fo:simple-page-master master-name="PageMaster.Content-right"              ❷ 
          margin="15mm 25mm 30mm 13mm" page-height="297mm" page-width="210mm">
            <fo:region-before region-name="Content-right-before" extent="20mm"      ❸
             display-align="before" border-after-style="solid" border-after-width="1pt"/>
            <fo:region-after region-name="Content-right-after"                      ❸
             border-before-style="none" extent="10mm" display-align="after" />
            <fo:region-body margin="25mm 0mm 15mm 0mm"/>
         </fo:simple-page-master>
         <fo:simple-page-master master-name="PageMaster.Content-left"               ❷
          margin="15mm 13mm 30mm 25mm" page-height="297mm" page-width="210mm">
            <fo:region-before region-name="Content-left-before" extent="20mm"       ❸
             display-align="before" border-after-style="solid" border-after-width="1pt"/>
            <fo:region-after region-name="Content-left-after"                       ❸
             border-before-style="none" extent="10mm" display-align="after"/>
            <fo:region-body margin="5mm 0mm 7mm 0mm"/>                              ❸
         </fo:simple-page-master>
         <fo:page-sequence-master master-name="Content-Pages">                      ❹
            <fo:repeatable-page-master-alternatives>
               <fo:conditional-page-master-reference 
                master-reference="PageMaster.Content-right" odd-or-even="odd"/>
               <fo:conditional-page-master-reference 
                master-reference="PageMaster.Content-left" odd-or-even="even"/>
             </fo:repeatable-page-master-alternatives>
          </fo:page-sequence-master>
       </fo:layout-master-set>
       <fo:page-sequence master-reference="Content-Pages" initial-page-number="1">  ❺
          <fo:static-content flow-name="Content-right-before">                      ❻
             <fo:block font-family="Arial" font-size="8pt" text-align="right">
                Page <page:number/>
             </fo:block>
          </fo:static-content>
          <fo:static-content flow-name="Content-left-before"/> 
             <fo:block font-family="Arial" font-size="8pt" text-align="left">
                Page <page:number/>
             </fo:block>
          </fo:static-content>
          <fo:static-content flow-name="Content-right-after">                       ❻
             <fo:block font-family="Arial" font-size="8pt" text-align="center">
                Content in the footer, right page
             </fo:block> 
          </fo:static-content>
          <fo:static-content flow-name="Content-left-after">                        ❻
             <fo:block font-family="Arial" font-size="8pt" text-align="center">
                Content in the footer, left page
             </fo:block>
          </fo:static-content>
          <fo:flow flow-name="xsl-region-body">
             <fo:block font-family="Arial" font-size="10pt">                        ❼
                <xsl:apply-templates/>
             </fo:block> 
          </fo:flow>
       </fo:page-sequence>
    </fo:root>
</xsl:template>

❶ The specifications for the page templates and page sequence templates are written into the root template in <fo:layout-master-set> within <fo:root>.

❷ The example contains two page templates (<fo:simple-page-master>), one for the left pages and one for the right pages of a book. The master-name attribute gives the page defined in this example a name which is referenced below. In further attributes the height and the width of the page as well as the margins of the page are determined. The attribute values for margin are to be read as top, right, bottom and left margin. So, the right margin of a right page is bigger than the gutter (left margin). The reverse case applies for the left pages.

❸ With the <fo:region-before>, <fo:region-after>, <fo:region-start>, <fo:region-end> and <fo:region-body> elements the sizes and characteristics of the different regions (header, footer, start region, end region and body) are specified. Apart from the body, the remaining regions only need to be specified if they are required in the page template. The region-name attribute gives the relevant region a name which is needed below in order to assign contents to the regions. In this example, it is specified for the header and footer which height they shall have (20mm and 10mm), how they shall be vertically aligned (in the header they are placed at the top, in the footer at the bottom) as well as whether and how they shall be separated from the body (the header with a solid line, the footer not). For the body of the pages the margins within the remaining region are determined with the margin attribute. In this example a top margin (to the header) and a bottom margin (to the footer) are specified (5mm and 7mm).

❹ With the <fo:page-sequence-master> element the page sequence is determined. The master-name attribute gives the page sequence a name to which reference is made in the <fo:page-sequence> element. When using a repetitive page sequence (typically for right and left pages), the specifications are embedded in the <fo:repeatable-page-master-alternatives> element. With the <fo:conditional-page-master-reference> element the conditions for the use of the relevant page sequences are determined. It is determined for the PageMaster.Content-right page sequence that it shall apply for a right page with odd page numbers (odd-or-even="odd"). For the left pages the value even (even page numbers) applies accordingly.

❺ In the <fo:page-sequence> element the determinations for the page templates and page sequence templates are connected with the contents to be displayed in them. The initial-page-number attribute determines the initial page number for this sequence.

❻ For the different <fo:static-content> elements (header right side, header left side, footer right side, footer left side) the static contents are determined in blocks. The contents shown in the example are only used for demonstration. For the contents and their layouts see the section "Header and footer".

❼ Within the <fo:flow> element with the preset name xsl-region-body, the content of the XML instance is embedded in the page sequence. A page sequence has exactly one <fo:flow> element which has to appear after each <fo:static-content> element. In this example the entire content below the root element of the XML instance is embedded in this page sequence with <xsl:apply-templates> without the select attribute. Of course this does not apply for each defined page sequence.

<< back next >>

Copyright © dpunkt.verlag GmbH 2004
Printing of the online version is permitted exclusively for private use. Otherwise this chapter from the book "XSL-FO in der Praxis" ("XSL-FO in practice") is subject to the same provisions as those applicable for the hardcover edition: The work including all its components is protected by copyright. All rights reserved, including reproduction, translation, microfilming as well as storage and processing in electronic systems.

dpunkt.verlag GmbH, Ringstraße 19B, 69115 Heidelberg, fon 06221-14830, fax 06221-148399, hallo@dpunkt.de