XSL-FO Tutorials - Herong's Tutorial Examples - v2.20, by __author__
Page Layout and Page Sequence Mapping
This section provides a tutorial example on how to apply a layout of 'simple-page-master' to a 'page-sequence'. The master-reference must match the master-name. And flow-name must match the region-name.
In previous tutorials, we have learned how to declare layouts with simple-page-master. In this tutorial, we will look at how to apply a layout to a page sequence.
Applying a layout of "simple-page-master" to a page sequence generated from "page-sequence" consists of 3 types of mapping:
Layout Mapping (page-sequence[@master-reference] = simple-page-master[@master-name]) - This mapping determines which "simple-page-master" to use when generating pages from the content of this "page-sequence". This mapping is required.
Body Flow Mapping (page-sequence/flow[@flow-name] = simple-page-master/region-body[@region-name]) - This mapping determines which flow to use to fill the "body" region. If the flow is "longer" than the "body" region of first page, more pages will be generated using the same layout to allow the flow to overflow to multiple pages.
Static Flow Mapping (page-sequence/static-content[@flow-name] = simple-page-master/region-before[@region-name] or simple-page-master/region-after[@region-name] or simple-page-master/region-start[@region-name] or simple-page-master/region-end[@region-name]) - This mapping determines which flow to use to fill a "side" region on each page repeatedly. If the flow is "longer" than the "side" region, it will overflow to the "body" region.
To demonstrate how a "simple-page-master" can be applied to a "page-sequence", I wrote the following example XSL-FO document, Page-Layout-Page-Sequence-Mapping.fo, to generate a sequence of pages with a simple layout: a "body" region and a "footer" region:
<?xml version="1.1" encoding="utf-8"?> <!-- Page-Layout-Page-Sequence-Mapping.fo - Copyright (c) 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="page" margin="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:layout-master-set> <fo:page-sequence master-reference="page"> <fo:static-content flow-name="footer"> <fo:block font-size="8pt">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>
You can process this example XSL-FO document with Apache FOP tool to generate pages in PDF format:
herong> fop -fo Page-Layout-Page-Sequence-Mapping.fo \ -pdf Page-Layout-Page-Sequence-Mapping.pdf
When you open the PDF file, you should see a number of pages with the same layout:
Table of Contents