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 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, normally this isn’t written as directly as it is 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 one or more fo:page-sequence
s. 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 page master 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 ...
Get XML in a Nutshell, 3rd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.