Layout Sequence Example - Odd and Even Pages

This section provides a tutorial example on how to use page-sequence-master to generate odd pages and event pages in different layouts in a single page sequence.

As the second tutorial example of "page-sequence-master", I wrote the following XSL-FO document, Odd-and-Even-Layout-Sequence.fo, that uses two layouts, one for odd pages and one for event pages, to build a layout sequence:

<?xml version="1.1" encoding="utf-8"?>
<!-- Odd-and-Even-Layout-Sequence.fo
 - Copyright (c) 2006 HerongYang.com. All Rights Reserved.
-->
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
 <fo:layout-master-set>
  <fo:simple-page-master master-name="cover" 
   margin-left="0.25in" margin-right="0.25in" 
   margin-top="1in" margin-bottom="1in" 
   page-height="2.3in" page-width="2.1in">
   <fo:region-body region-name="body" margin="0.25in"/>
  </fo:simple-page-master>
  <fo:simple-page-master master-name="odd" 
   margin-left="0.45in" margin-right="0.05in" 
   margin-top="0.25in" margin-bottom="0.25in" 
   page-height="2.3in" page-width="2.1in">
   <fo:region-body region-name="body" margin="0.25in"
   background-color="#eeeeee"/>
   <fo:region-after region-name="footer" extent="0.2in"/>
  </fo:simple-page-master>
  <fo:simple-page-master master-name="even" 
   margin-left="0.05in" margin-right="0.45in" 
   margin-top="0.25in" margin-bottom="0.25in" 
   page-height="2.3in" page-width="2.1in">
   <fo:region-body region-name="body" margin="0.25in"
   background-color="#eeeeee"/>
   <fo:region-after region-name="footer" extent="0.2in"/>
  </fo:simple-page-master>
  <fo:page-sequence-master master-name="content">
   <fo:repeatable-page-master-alternatives>
    <fo:conditional-page-master-reference master-reference="odd" 
     odd-or-even="odd"/>
    <fo:conditional-page-master-reference master-reference="even" 
     odd-or-even="even"/>
   </fo:repeatable-page-master-alternatives>
  </fo:page-sequence-master>
 </fo:layout-master-set>
 <fo:page-sequence master-reference="cover">
  <fo:flow flow-name="body">
   <fo:block>RIVER BANK</fo:block>
  </fo:flow>
 </fo:page-sequence>
 <fo:page-sequence master-reference="content">
  <fo:static-content flow-name="footer">
   <fo:block font-size="8pt" text-align="center">
    herongyang.com
   </fo:block>
  </fo:static-content> 
  <fo:flow flow-name="body">
   <fo:block>
    The Mole had been working very hard all the morning, 
    spring-cleaning his little home. First with brooms, then with 
    dusters; then on ladders and steps and chairs, with a brush and 
    a pail of whitewash; till he had dust in his throat and eyes, and
    splashes of whitewash all over his black fur, and an aching back 
    and weary arms. Spring was moving in the air above and in the 
    earth below and around him, penetrating even his dark and lowly 
    little house with its spirit of divine discontent and longing. 
    It was small wonder, then, that he suddenly flung down his brush 
    on the floor, said 'Bother!' and 'O blow!' and also 'Hang 
    spring-cleaning!' and bolted out of the house without even waiting
    to put on his coat...
   </fo:block>
  </fo:flow>
 </fo:page-sequence>
</fo:root>

When you process the above sample XSL-FO document to a PDF file and open it, you should see a number of pages with odd pages being formatted differently than even pages:

Layout Sequence Example - Odd and Even Pages
Layout Sequence Example - Odd and Even Pages

Note that how the "odd" layout and the "even" layout being alternatively selected to form the layout sequence.

Table of Contents

 About This Book

 Introduction of XSL-FO

 Apache™ FOP (Formatting Objects Processor)

 RenderX XEP as an XSL-FO Tool

 Introduction of Area Model

 XSL-FO Document Basics and Examples

Page Layout Masters

 Layout Declarations

 simple-page-master - Simple Page Layout

 simple-page-master Attributes and Sub Elements

 simple-page-master/region-body Sub Element

 region-before and region-after Sub Elements

 region-start and region-end Sub Elements

 "Body" Region Margin and "Side" Region Extent

 Precedence of Side Region Corners

 Page Layout and Page Sequence Mapping

 What Is "page-sequence-master"

 Layout Sequence Example - Cover and Content

 Wheat Is "repeatable-page-master-alternatives"?

Layout Sequence Example - Odd and Even Pages

 Block-Level Formatting Objects

 Inline-Level Formatting Objects

 Including Graphics in XSL-FO document

 Table of Rows and Columns

 List, Item, Label, and Body

 Floating Blocks - "float" and "footnote"

 Hyperlinks, Table of Contents and Indexes

 Headers and Footers using "static-content"

 Font Attributes and Font Families

 Apache FOP Font Configurations

 RenderX XEP Font Configurations

 Converting HTML to PDF

 References

 Full Version in PDF/ePUB