Sunday, July 6, 2008

XSL-FO

XSL-FO is about formatting XML data for output.

XSL-FO Document Structure
<?xml version="1.0" encoding="ISO-8859-1"?>

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

<fo:layout-master-set>
<fo:simple-page-master master-name="A4">
<!-- Page template goes here -->
</fo:simple-page-master>
</fo:layout-master-set>

<fo:page-sequence master-reference="A4">
<!-- Page content goes here -->
</fo:page-sequence>

</fo:root>

The <fo:layout-master-set> element contains one or more <fo:simple-page-master>
Each <fo:simple-page-master> element contains a single page template. Each template must have a unique name (master-name).
<fo:page-sequence> elements describe the page contents. The master-reference attribute refers to the simple-page-master template with the same name.

XSL-FO Areas
  • Pages
  • Regions
  • Block areas
  • Line areas
  • Inline areas

Pages contain Regions. Regions contain Block areas...

XSL-FO output is formatted into pages. Printed output will normally go into many separate pages. Browser output will often go into one long page.

Each XSL-FO Page contains a number of Regions:
  • region-body (the body of the page)
  • region-before (the header of the page)
  • region-after (the footer of the page)
  • region-start (the left sidebar)
  • region-end (the right sidebar)



XSL-FO Regions contain Block areas. XSL-FO Block areas define small block elements (the ones that normally starts with a new line) like paragraphs, tables and lists. XSL-FO Block areas can contain other Block areas or Line areas.

XSL-FO Line areas define text lines inside Block areas.

XSL-FO Line areas contain Inline areas. XSL-FO Inline areas define text inside Lines (bullets, single character, graphics, and more).

XSL-FO defines output inside <fo:flow> elements.
Here is a real XSL-FO example.
<?xml version="1.0" encoding="ISO-8859-1"?>

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

<fo:layout-master-set>
<fo:simple-page-master master-name="A4">
<fo:region-body />
</fo:simple-page-master>
</fo:layout-master-set>

<fo:page-sequence master-reference="A4">
<fo:flow flow-name="xsl-region-body">
<fo:block>Hello W3Schools</fo:block>
</fo:flow>
</fo:page-sequence>

</fo:root>

No comments:

Post a Comment