RenderX

Chapter 2 of the XSL-FO Tutorial

2. “Hello, World!”

Let us create the shortest XSL FO document.

<?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="my-page">
      <fo:region-body margin="1in"/>
    </fo:simple-page-master>
  </fo:layout-master-set>

  <fo:page-sequence master-reference="my-page">❹
    <fo:flow flow-name="xsl-region-body">❺
      <fo:block>Hello, world!</fo:block>❻
    </fo:flow>
  </fo:page-sequence>
</fo:root>

❶This is an XML declaration. XSL FO belongs to XML family, so this is obligatory.
❷Root element. The obligatory namespace attribute declares the XSL Formatting Objects namespace.
❸Layout master set. This element contains one or more declarations of page masters and page sequence masters — elements that define layouts of single pages and page sequences. In the example, I have defined a rudimentary page master, with only one area in it. The area should have a 1 inch margin from all sides of the page.
❹Page sequence. Pages in the document are grouped into sequences; each sequence starts from a new page. Master-reference attribute selects an appropriate layout scheme from masters listed inside <fo:layout-master-set>. Setting master-reference to a page master name means that all pages in this sequence will be formatted using this page master.
❺Flow. This is the container object for all user text in the document. Everything contained in the flow will be formatted into regions on pages generated inside the page sequence. Flow name links the flow to a specific region on the page (defined in the page master); in our example, it is the body region.
❻Block. This object roughly corresponds to <DIV> in HTML, and normally includes a paragraph of text. I need it here, because text cannot be placed directly into a flow.

Now we can save this document into a file and compile it using IREn 4.9. to produce a PDF file. Open it with Acrobat Reader, and enjoy :-).

Download the complete XSL-FO Tutorial as PDF