Book HomeXML in a NutshellSearch this book

13.2. The Structure of an XSL-FO Document

The root element of all XSL-FO documents is fo:root. This element normally declares the fo prefix, which must be mapped to the http://www.w3.org/1999/XSL/Format namespace URI. As always, the prefix can change as long as the URI stays the same. In this chapter, we assume that the prefix fo has been associated with http://www.w3.org/1999/XSL/Format. Thus a typical FO document looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
  <!-- Formatting object elements -->
</fo:root>

Of course this normally isn't written directly as here. Instead, it's formed by an XSLT template like this one:

<xsl:template match="/">
  <fo:root>
    <xsl:apply-templates/>
  </fo:root>
</xsl:template>

The fo:root element must contain two things, a fo:layout-master-set and a fo:page-sequence . The fo:layout-master-set contains elements describing the overall layout of the pages themselves, that is, how large the pages are, whether they're in landscape or portrait mode, how wide the margins are, and so forth. The fo:page-sequence contains the actual text that will be placed on the pages, along with the instructions for formatting that text as italic, 20 points high, justified, and so forth. It has a master-reference attribute identifying the particular master page that will be used to layout this content. Adding these elements, a formatting objects document looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
  <fo:layout-master-set>
    <!-- page masters -->
  </fo:layout-master-set>
  <fo:page-sequence master-reference="first">
    <!-- data to place on the page -->
  </fo:page-sequence>
</fo:root>

The formatting engine uses the layout master set to create a page. Then it adds content to the page from the fo:page-sequence until the page is full. Then it creates the next page in the sequence and places the next batch of content on that page. This process continues until all the content has been positioned.



Library Navigation Links

Copyright © 2002 O'Reilly & Associates. All rights reserved.