XSL-FO Overview


The namespace for XSL-FO is http://www.w3.org/1999/XSL/Format. The example that follows shows how the xsl-fo namespace is generally introduced using the alias “fo”.

      <?xml version="1.0"?>      <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format"> 

This and subsequent examples in this book use fo as the alias for the namespace.

Each page is split into the following types of areas:

  • q Region-The main area of the page. This is split into further sub-regions as show later in this section.

  • q Block Area-Areas of content such as tables, lists and paragraphs.

  • q Line Area-Areas inside a block that contains one line of text.

  • q Inline Area-Lowest level of an area. An inline area can be a single character. Generally, this is used to display graphics or to insert auto-text or serve as a placeholder for calculations.

Figure 4-3 shows the hierarchical nature of these areas.

image from book
Figure 4-3

You can see how the region area is split on a per page basis by the XSL-FO area tags. Figure 4-4 shows the different areas available within a page followed by a short description of each. Note that a page is contextual in that the size and length of a page is dependent on the output type. For example, a Web page is considered one long page, whereas a PDF document the size of the page is restricted by the selected paper size.

image from book
Figure 4-4

The header and footer regions are self-evident terms. The width of these regions is set to the width of the page; only the height of this region can be set. The header region is defined by the element fo:region-before and the footer is defined in by the fo:region-end element. One of the previously mentioned features of XSL-FO is support for multiple languages. When the chosen language is a dialect that is read or written from bottom to top, fo:region:start is at the foot of the page and fo:region-end is at the head.

The start and end regions are the left and right regions of the page. Notice I didn't specify which was which! Again, for multilingual support, the start and end regions can be either on the left or right side of the page. For this example, the start region is the left region of the page and the end region is the right. The height of the start and end regions, is the height of the body region. The width can be set through an attribute for each of the elements.

No width or height attributes are available for the body region these attributes are defined by the page settings. The body region is the size of the page less any margins set on the page level attributes. The page is discussed in the next section and an example clarifies how the dimensions are determined. The body can actually overlap the header and footer regions if the attributes of the regions are not correctly set.

Page Templates

Now that you understand the structure and breakdown of a page and regions, look at some of the XSLFO elements that define the settings for each. The first element is the simple page master.

fo:simple-page-master

This element is used to specify the settings for a page. More than one fo:simple-page-master can exists in an XSL-FO document, but each page references only one page master template. Each page master is hosted within the fo:layout-master-set element. The following settings for a master page template are available:

  • q Margin properties-margin-top, margin-bottom, margin-left, margin-right

  • q master-name-The name by which any subsequent elements refer to the template

  • q page-height-The height of the page

  • q page-width-The width of the page

  • q reference-orientation-Specifies the rotation (0, 90, 180, 270, 90, 180, 270) in degrees of the area content

  • q writing-mode-Specifies the direction of text. The available values are:

    • q lr-tb-l(eft)r(ight)-t(op)b(ottom)

    • q rl-tb

    • q tb-rl

    • q lr

    • q rl

    • q tb

Each of these setting is specified as an attribute of the fo:simple-page-master.

Now look at an example template. The code that follows sets a page master template with a one centimeter margin on each side on a standard A4 size page.

      <fo:layout-master-set>        <fo:simple-page-master            master-name="A4"            page-height="29.7cm"            page-width="21cm"            margin-top="1.0cm"            margin-bottom="1.0cm"            margin-left="1.0cm"            margin-right="1.0cm">            <fo:region-body/>         </fo:simple-page-master>      </fo:layout-master-set> 

The preceding code sets up the page, but you now want to specify the dimensions of the region areas such as the header, footer and body. You can achieve this by adding the appropriate elements into the page master definition. The code that follows shows how to setup the header, footer and body regions by setting the margin and extent attributes. The extent attribute is the height for header and footer regions, and width for the start and end regions. Only one dimension can be set for each of these areas.

      <fo:layout-master-set>        <fo:simple-page-master          master-name="A4"          page-height="29.7cm"          page-width="21cm"          margin-top="1.0cm"          margin-bottom="1.0cm"          margin-left="1.0cm"          margin-right="1.0cm">          <fo:region-before extent="1.0cm"/>          <fo:region-body   margin="1.0cm"/>          <fo:region-after  extent="1.0cm"/>        </fo:simple-page-master>      </fo:layout-master-set> 

Figure 4-5 shows how the settings in the preceding code render the page.

image from book
Figure 4-5

To define a page, the fo:page-sequence element is used. One of the attributes of this element is named master-reference and is a reference to the page master to be used as the layout template for the page. All the code for the page is stored within the fo:page-sequence element. The following code shows an example of this.

      <fo:layout-master-set>        <fo:simple-page-master          master-name="A4"          page-height="29.7cm"          page-width="21cm"                margin-top="1.0cm"          margin-bottom="1.0cm"          margin-left="1.0cm"          margin-right="1.0cm">          <fo:region-before extent="1.0cm"/>          <fo:region-body   margin="1.0cm"/>          <fo:region-after  extent="1.0cm"/>        </fo:simple-page-master>      </fo:layout-master-set>      <fo:page-sequence master-reference="A4">      </fo:page-sequence> 

Now that you know how the regions hang together, you can put some content into them. Here, you start with a fairly simple hello world example, but as you go through some of the formatting features, the examples should become more valuable to help you understand. After all the main features have been covered, you begin the main example of the chapter.




Professional XML
Professional XML (Programmer to Programmer)
ISBN: 0471777773
EAN: 2147483647
Year: 2004
Pages: 215

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net