XSL-FO - Block and Inline Areas
Part:
1
2
3
(Continued from previous part...)
XSL-FO Example - simple_page.fo
Let's apply what we have learned so far to create a simple XSL-FO example
file to illustrate how to handle some basic formatting features like:
page margin, paragraph spacing, font family and size, page header and footer,
etc.
<?xml version="1.0" encoding="utf-8"?>
<!-- simple_page.fo
Copyright (c) 2002 by Dr. Herong Yang
-->
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
<fo:layout-master-set>
<fo:simple-page-master master-name="simple_page" margin="0.5in">
<fo:region-before region-name="header" extent="0.5in"
background-color="#cfcfcf" display-align="after"/>
<fo:region-after region-name="footer" extent="0.5in"
background-color="#cfcfcf" display-align="before"/>
<fo:region-body region-name="body" margin="1.0in"
background-color="#cfcfcf"/>
</fo:simple-page-master>
</fo:layout-master-set>
<fo:page-sequence master-reference="simple_page">
<fo:static-content flow-name="header"
font-family="sans-serif" font-size="12pt" font-style="normal">
<fo:block border-bottom-width="2px" border-bottom-style="solid"
text-align="end">Introduction to XSL</fo:block>
</fo:static-content>
<fo:static-content flow-name="footer"
font-family="sans-serif" font-size="12pt" font-style="italic">
<fo:block border-top-width="1px" border-top-style="solid"
text-align="end">The text is copied from XSL specification by W3C
</fo:block>
</fo:static-content>
<fo:flow flow-name="body"
font-family="serif" font-size="18pt" font-style="normal"
font-weight="normal">
<fo:block padding-before="12pt" padding-after="6pt"
font-size="150%" font-weight="bold"
background-color="#afafaf">Introduction to XSL</fo:block>
<fo:block padding-before="9pt" padding-after="3pt"
text-indent="0.5in" text-align="justify">
This specification defines the Extensible Stylesheet Language (XSL).
XSL is a language for expressing stylesheets. Given a class of
arbitrarily structured XML [XML] documents or data files, designers
use an XSL stylesheet to express their intentions about how that
structured content should be presented; that is, how the source content
should be styled, laid out, and paginated onto some presentation
medium, such as a window in a Web browser or a hand-held device,
or a set of physical pages in a catalog, report, pamphlet, or book.
</fo:block>
<fo:block padding-before="12pt" padding-after="3pt"
font-weight="bold">Processing a Stylesheet</fo:block>
<fo:block padding-before="9pt" padding-after="3pt"
text-indent="0.5in" text-align="justify">
An XSL stylesheet processor accepts a document or data in XML and an XSL
stylesheet and produces the presentation of that XML source content that
was intended by the designer of that stylesheet. There are two aspects
of this presentation process: first, constructing a result tree from the
XML source tree and second, interpreting the result tree to produce
formatted results suitable for presentation on a display, on paper, in
speech, or onto other media. The first aspect is called tree
transformation and the second is called formatting. The process of
formatting is performed by the formatter. This formatter may simply be
a rendering engine inside a browser.
</fo:block>
<fo:block padding-before="9pt" padding-after="3pt"
text-indent="0.5in" text-align="justify">
Tree transformation allows the structure of the result tree to be
significantly different from the structure of the source tree. For
example, one could add a table-of-contents as a filtered selection of
an original source document, or one could rearrange source data into
sorted tabular presentation. In constructing the result tree, the tree
transformation process also adds the information necessary to format
that result tree.
</fo:block>
</fo:flow>
</fo:page-sequence>
</fo:root>
If you use FOP to convert simple_page.fo to PDF:
run_fop -fo simple_page.fo -pdf simple_page.pdf
Exam this 2-page PDF output carefully, you will see:
- The background-color attribute at the block level overrides the same attribute
at the region level. See the first block of the body region.
- The border-bottom-x attributes in the text block of the header region give
a good solid line in the header area. But it is not what I want. I want a solid
line at the bottom edge of the header region. I have no idea on how to do that.
- The display-align="after" doesn't work in region-before with FOP (Could be a bug).
The header text is still align to the top edge.
Part:
1
2
3
|