和荣笔记 - XSL-FO 与 XHTML
杨和荣, 版本 2.03, 2007年

XSL-FO File Structure and Declaration Statements

Part:   1  2 

XSL-FO File Structure

Since XSL-FO files are written in XML, all statements are organized into an XML tree structure. Here is the syntax of the top level of the tree:

<fo:root> <fo:layout-master-set>
  <fo:simple-page-master>
   region declaration statements to define a single page layout
  </fo:simple-page-master>
  ...
  <fo:page-sequence-master>
   page layout reference statements to define a page sequence layout
  </fo:page-sequence-master>
  ...
 </fo:layout-master-set>
 <fo:page-sequence>
  flow declaration statements to map a flow of block areas to a region.
 </fo:page-sequence>
 ...
</fo:root>

Note that I use the words "statement" and "element" interchangeably, because the written of an XSL-FO statement is an XML element.

Statements used at the top levels are:

  • "root": The starting point of an XSL-FO file.
  • "layout-master-set": A grouping statement that keeps all layout declaration statements in one place.
  • "simple-page-master": A declaration statement that defines a single page layout.
  • "page-sequence-master": A declaration statement that defines a page sequence layout.
  • "page-sequence": An action statement that generates areas to produce a page sequence.

"simple-page-master" Statements

"simple-page-master": An XSL-FO element serving as a declaration statement to define a single page layout.

For example:

<fo:simple-page-master master-name="my_layout"
  margin-top="1.0in" margin-bottom="0.8in"
  margin-left="0.8in" margin-right="0.6in">
 <fo:region-body region-name="my_body" 
  column-count="2" column-gap="0.2in"
  background-color="#cfcfcf" margin="0.2"/>
 <fo:region-before region-name="my_header"
  extent="0.2in" display-align="after"/>
 <fo:region-after region-name="my_footer"
  extent="0.2in" display-align="before"/>
 <fo:region-start region-name="my_left_sidebar"
  extent="0.2in" display-align="after"
  reference_orientation="90"/>
 <fo:region-end region-name="my_right_sidebar"
  extent="0.2in" display-align="before"
  reference_orientation="90"/>
</fo:simple-page-master>

Obviously, a page is divided into 5 regions:

----------------
|    Before    |
|--------------|
|S |        |  |
|t |        |E |
|a |  Body  |n |
|r |        |d |
|t |        |  |
|--------------|
|    After     |
----------------

Some interesting attributes in the declaration statements:

  • margin-x: Specifies white spaces at four edges of the page, if used in simple-page-master statement.
  • region-name: A given name for this region. It will be use in the area generation statements to specify in which region the areas are placed.
  • column-count: Number of columns of text to be generated in this region.
  • reference_orientation: A rotation angle of the inline progression direction from its default - from left to right.
  • margin: Is a shorthand for four different margins with the same value.
  • extent: Specifies how deep a border region is. A border region takes a way space from the body region. So you must specify enough margin in body-region, so that text from the body region is not overlapping with the text in the border regions.
  • background-color: Specifies the background color for all areas that will be stacked into this region.
  • display-align: Forces the block areas to align to one edge of the region. For example, display-align="after" is needed in region-before to align text to the bottom of the header area.

(Continued on next part...)

Part:   1  2 

杨和荣,修改于2007年
和荣笔记 - XSL-FO 与 XHTML - XSL-FO File Structure and Declaration Statements