Managing Pages

Earlier when I explained page masters, I mentioned that the size of a page is controlled by a page master but I didn't actually show you how. The size of a page is set using the page-width and page-height attributes of the fo:simple-page-master element. As with most measurements in XSL-FO, you can use a variety of different units when specifying the page size, such as inches (in), centimeters (cm), and points (pt). The page size refers to the physical size of the printed page in most cases, which you will likely set to either 8.5x11 (inches) or 11x17 (inches), to note a few popular page sizes. Following is an example of specifying an 8.5x11 page size:

<fo:simple-page-master master-name="main" page-width="8.5in"
page-height="11in" margin-left="1in" margin-right="1in"
margin-top="0.5in" margin-bottom="0.5in">
  <fo:region-body margin-top="0.25in" margin-bottom="0.25in"/>

This code also shows how to establish margins for both the master page and the region body within the content area of the page.

Managing pages in an XSL-FO document isn't just about setting their size. It's also important to keep up with page numbers and ensure that they are displayed appropriately, if so desired. The <fo:page-number> tag is used to insert the page number into the content of a page. This page number is automatically calculated, meaning that you don't have to do any more than insert the tag to get automatic page numbering. Of course, you will likely want the page number to be displayed in the header or footer for the page, which means you'll need to allocate some space via the extent attribute. Following is an example of how to establish a quarter-inch footer to house the page number:

<fo:region-after extent="0.25in" />

This code should be placed in the page master so that the footer gets established. The next step is then to use the <fo:page-number> tag to place the page number in content that results in the displaying of the page number:

<fo:static-content flow-name="xsl-region-before">
  <fo:block text-align="end" font-size="10pt" font-family="serif"
  line-height="14pt" >
    Great Sporting Events - p. <fo:page-number/>

Earlier in the lesson I talked about static content but I didn't show you an example. Here is a perfect example of static content, which means content that doesn't flow down the page. Static content isn't static in a sense that it can certainly change, as with the page number, but its position and spacing on the page are static.

This code contains one other new wrinkle that you haven't learned about yet: the line-height attribute. This attribute is used to establish the minimum height of a block. You can use this attribute to ensure that a block is a certain minimum height regardless of the content contained within it.

Validating an XSL-FO Document

As with any XML documents that you create, it's important to be able to validate XSL-FO documents to ensure that they are coded properly according to the XSL-FO language. The W3C doesn't offer an official XSL-FO DTD, which is necessary in order to validate XSL-FO documents. However, RenderX, the makers of the XEP XSL-FO processor, offer an experimental DTD that works fine for validating XSL-FO documents. Relying on RenderX's DTD, you can still use the standard W3C online validation tool to validate your XSL-FO documents. But first you need to wire the RenderX DTD to your XSL-FO documents.

The RenderX XSL-FO DTD is located online at http://xep.xattic.com/xep/resources/validators/dtd/fo.dtd. You wire this DTD into your XSL-FO documents via the following line of code just after the XML processor directive near the top of a document:


With this code in place, you can now pass your XSL-FO documents into the standard W3C Markup Validation Service at http://validator.w3.org/.

by BrainBellupdated