page-sequence-master

Contact Us or call 1-877-932-8228
page-sequence-master

page-sequence-master

The layout-master-set FO takes two child FOs, one of which is simple-page-master, which we've already seen. The other is page-sequence-master, which is used to specify the sequence of simple-page-masters to be used. The page-sequence-master FO takes three possible children:

  • single-page-master-reference - used to create a template for a single page (e.g, a cover page).
  • repeatable-page-master-reference - used to create a template to be used for n number of pages, where n is set with the maximum-repeats attribute.
  • repeatable-page-master-alternatives - used to create different templates for pages depending on where they fall in the document (e.g, first page, even pages, odd pages, blank pages, last even page, and last odd page).

Creating a Cover Page

A cover page is created using single-page-master-reference as shown in the example below.

Code Sample:

PageLayout/Demos/CoverPage.fo
<?xml version="1.0" encoding="UTF-8"?>
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
	<fo:layout-master-set>
		<fo:simple-page-master master-name="Cover" margin="1in" page-height="11in" page-width="8.5in">
			<fo:region-body margin-top="2in"/>
		</fo:simple-page-master>
		<fo:page-sequence-master master-name="CoverPage">
			<fo:single-page-master-reference master-reference="Cover"/>
		</fo:page-sequence-master>
	</fo:layout-master-set>
	<fo:page-sequence master-reference="CoverPage">
		<fo:flow flow-name="xsl-region-body">
			<fo:block text-align="center" font-weight="bold" font-size="1in">
				Cover Page
			</fo:block>
		</fo:flow>
	</fo:page-sequence>
</fo:root>

Odd and Even Pages

To create alternating odd and even pages, you follow these steps:

  1. Create a simple-page-master for the odd pages.
  2. Create a simple-page-master for the even pages.
  3. Create a page-sequence-master that references the two simple-page-masters.

The following sample illustrates this.

Code Sample:

PageLayout/Demos/OddEven.fo
<?xml version="1.0" encoding="UTF-8"?>
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
	<fo:layout-master-set>
	
		<fo:simple-page-master master-name="StoriesOdd" 
			page-height="11in" page-width="8.5in" margin=".5in">
			<fo:region-body margin=".5in" />
			<fo:region-before region-name="oddHead" extent=".5in" />
			<fo:region-after region-name="oddFoot" extent=".5in" />
		</fo:simple-page-master>
		
		<fo:simple-page-master master-name="StoriesEven" 
			page-height="11in" page-width="8.5in" margin=".5in">
			<fo:region-body margin=".5in" />
			<fo:region-before region-name="evenHead" extent=".5in" />
			<fo:region-after region-name="evenFoot" extent=".5in" />
		</fo:simple-page-master>
		
		<fo:page-sequence-master master-name="Stories">
			<fo:repeatable-page-master-alternatives>
				<fo:conditional-page-master-reference 
					master-reference="StoriesOdd" odd-or-even="odd" />
				<fo:conditional-page-master-reference 
					master-reference="StoriesEven" odd-or-even="even" />
			</fo:repeatable-page-master-alternatives>
		</fo:page-sequence-master>
	</fo:layout-master-set>
	
	<fo:page-sequence master-reference="Stories">
	
		<fo:static-content flow-name="oddHead">
			<fo:block border-bottom-width="thin" 
				border-bottom-style="solid" border-bottom-color="green" 
				font-weight="bold" text-align="outside">
					Story Title
				</fo:block>
		</fo:static-content>
		
		<fo:static-content flow-name="evenHead">
			<fo:block border-bottom-width="thin" 
				border-bottom-style="solid" border-bottom-color="green" 
				font-weight="bold" text-align="outside">
					Book of Stories
				</fo:block>
		</fo:static-content>
		
		<fo:static-content flow-name="oddFoot">
			<fo:block border-bottom-width="thin" 
				border-bottom-style="solid" border-bottom-color="green" 
				font-weight="bold" text-align="outside">
				<fo:page-number /> |
			</fo:block>
		</fo:static-content>
		
		<fo:static-content flow-name="evenFoot">
			<fo:block border-bottom-width="thin" 
				border-bottom-style="solid" border-bottom-color="green" 
				font-weight="bold" text-align="outside">
				| <fo:page-number />
			</fo:block>
		</fo:static-content>
		
		<fo:flow flow-name="xsl-region-body">
---- C O D E   O M I T T E D ----
</fo:flow>
		
	</fo:page-sequence>
</fo:root>

Let's examine the code step by step.

  1. At the top of the page, two simple-page-masters are created:
    <fo:simple-page-master master-name="StoriesOdd" page-height="11in" page-width="8.5in" margin=".5in"> <fo:region-body margin=".5in" /> <fo:region-before region-name="oddHead" extent=".5in" /> <fo:region-after region-name="oddFoot" extent=".5in" /> </fo:simple-page-master> <fo:simple-page-master master-name="StoriesEven" page-height="11in" page-width="8.5in" margin=".5in"> <fo:region-body margin=".5in" /> <fo:region-before region-name="evenHead" extent=".5in" /> <fo:region-after region-name="evenFoot" extent=".5in" /> </fo:simple-page-master>
    • Notice that <fo:region-before> and <fo:region-after> have region-name attributes. This is so that we can distinguish between these regions on odd pages and even pages.
  2. The next step is to create a page-sequence-master.
    <fo:page-sequence-master master-name="Stories"> <fo:repeatable-page-master-alternatives> <fo:conditional-page-master-reference master-reference="StoriesOdd" odd-or-even="odd" /> <fo:conditional-page-master-reference master-reference="StoriesEven" odd-or-even="even" /> </fo:repeatable-page-master-alternatives> </fo:page-sequence-master>
    As it sounds, a page-sequence-master is used for defining page sequences.
    • In this case, we want the sequence to be repeatable (e.g, odd, even, odd, even, odd, etc.). The <fo:repeatable-page-master-alternatives> tag takes care of this.
    • We also want to make sure the "StoriesOdd" simple-page-master is used for odd pages and the "StoriesEven" simple-page-master is used for even pages. This is handled with the <fo:conditional-page-master-reference> tags.
    • We name this page-sequence-master "Stories".
  3. In our page-sequence, we see four fo:static-content elements and one fo:flow element. There is nothing special about the fo:flow element; it contains the body content, which appears the same on every page. The fo-static-content elements, however, are different than the ones we've used thus far in that there are two for region-before: "oddHead" and "evenHead", and two for region-after: "oddFoot" and "evenFoot". The "oddHead" and "oddFoot" regions are defined in the "StoriesOdd" simple-page-master and the "evenHead" and "evenFoot" regions are defined in the "StoriesEven" simple-page-master. The only difference between the odd pages and the even pages is the content.
    <fo:page-sequence master-reference="Stories"> <fo:static-content flow-name="oddHead"> <fo:block border-bottom-width="thin" border-bottom-style="solid" border-bottom-color="green" font-weight="bold" text-align="outside"> Story Title </fo:block> </fo:static-content> <fo:static-content flow-name="evenHead"> <fo:block border-bottom-width="thin" border-bottom-style="solid" border-bottom-color="green" font-weight="bold" text-align="outside"> Book of Stories </fo:block> </fo:static-content> <fo:static-content flow-name="oddFoot"> <fo:block border-bottom-width="thin" border-bottom-style="solid" border-bottom-color="green" font-weight="bold" text-align="outside"> | <fo:page-number /> </fo:block> </fo:static-content> <fo:static-content flow-name="evenFoot"> <fo:block border-bottom-width="thin" border-bottom-style="solid" border-bottom-color="green" font-weight="bold" text-align="outside"> <fo:page-number /> | </fo:block> </fo:static-content> <!--fo:flow OMITTED--> </fo:page-sequence>

The first two pages of the output are shown below:

Next