[ return to listing ]
Creating Duplex-Marginalia Notes in XSL-FO
Document Prepared By:
Nestor Martinez, Consultant
For information or questions regarding this document or Wrycan's services, please contact us.
Table of Contents
1.0 Overview
2.0 Creating the Page Layout
2.1 Margin Attribute (Odd & Even)
3.0 Creating the Main Body Flow
4.0 Utilizing the Marginalia Area
5.0 Technology
The purpose of this document is to discuss in detail how to implement marginalia notes using XSL-FO.
Marginalia notes can either be left-aligned, right-aligned or both. In order to create marginalia notes that appear on either side of the page depending on its parity, the page layout needs to be setup as follows. There are two separate page masters, one for odd pages and one for even pages. The @margin attribute on the <fo:simple-page-master> element indicates the overall margin for the page. The @margin attribute in the <fo:region-body> element signifies the margins from the <fo:simple-page-master> margins as shown in figure 1 below.
<fo:root>
<fo:layout-master-set>
<fo:simple-page-master master-name="odd-page" margin="0.5in">
<fo:region-body margin="0.5in 0.5in 0.5in -1.5in"/>
</fo:simple-page-master>
<fo:simple-page-master master-name="even-page" margin="0.5in">
<fo:region-body margin="0.5in -1.5in 0.5in 0.5in"/>
</fo:simple-page-master>
<fo:page-sequence-master master-name="main">
<fo:repeatable-page-master-alternatives>
<fo:conditional-page-master-reference master-reference="odd-page" odd-or-even="odd"/>
<fo:conditional-page-master-reference master-reference="even-page" odd-or-even="even"/>
</fo:repeatable-page-master-alternatives>
</fo:page-sequence-master>
</fo:layout-master-set>
</fo:root>
The @margin attribute above can also be replaced with separate individual attributes as well. As shown below, the numbers in the @margin attribute correspond to the following margins.
margin = "margin-top margin-right margin-bottom margin-left"
The negative values for the left margin (odd pages) and right margin (even pages) counteract the @start-indent and @end-indent attributes of the <fo:xsl-region-body> element which is described below.
Odd: <fo:region-body margin="0.5in 0.5in 0.5in -1.5in"/>
Even: <fo:region-body margin="0.5in -1.5in 0.5in 0.5in"/>

Figure 1. Creating the Page Layout
For the regular flow region of the document, the following should be specified for the text flow. This creates the layout shown in figure 2 below.
<fo:flow flow-name="xsl-region-body" start-indent="2in" end-indent="2in">
The start-indent and end-indent values are needed to create the area for the marginalia notes. If we have positive values for the margin-left on odd pages and margin-right on even pages, the start-indent and end-indent would make those margins even greater and the body area would diminish that much more.
The start-indent working together with the negative margin-left value (Odd) serves to create the left margin for the odd pages. The start-indent creates the marginalia notes area for the even pages.
The end-indent working together with the negative margin-right value (Even) serves to create the right margin for the even pages. The end-indent creates the marginalia notes area for the odd pages.

Figure 2. Finished Layout with main Flow Included
The element and attribute float can be used for the purpose of creating marginalia notes and can be set to values of either inside or outside. If <fo:float float="inside"> is used, it will align the floating block to the inner edge of the page. This aligns to the left side for odd pages and right side for even pages. If <fo:float float="outside"> is used, it will align the floating block to the outer edge of the page. This aligns to the right side for odd pages and left side for even pages. The value of outside is used for this example, see figure 3 below.
Here is an example of what an <fo:float> block should look like:
<fo:float float="outside" start-indent="0pt" end-indent="0pt" clear="both>
<fo:block-container width="1.5in">
<fo:block>Right aligned marginalia float</fo:block>
</fo:block-container>
</fo:float>
<fo:block>This is the body of the document, this example assumes we are at page one and therefore will apply the rules for the odd pages.</fo:block>
Notice two things; first the clear attribute has a value of both, this means that the generated box is moved below all floating boxes of earlier elements in the source document, either left or right aligned.
Second, the width for the fo:block-container is set to 1.5in. This is so that we have a small gap between the floating block and the body of the document.
Below is an example of what the page would look like:

Figure 3. Output PDF including all margins and indents
The technologies used while writing this document are:
XSL - Extensible Stylesheet Language
XSL-FO - XSL Formatting Objects
XEP - XEP Engine from RenderX
The XSL language and the XSL-FO vocabulary are used together inside an XSL stylesheet which is used to convert a regular XML file into another XML file containing Formatting Objects. The resulting XML file is rendered using XEP which is an XSL-FO processor, and converts the Formatting Objects into PDF.
|