XSL-FO is an XML language designed for describing all visual aspects of paginated documents. The well known HTML is another language used for specifying formatting semantics, but is more usable for documents that are presented on screen, and less for materials created for printing, because it does not support pagination elements like headers and footers, page size specifications, footnotes, etc.
XSL-FO is part of XSL language family:
• XSLT - (XSL Transformations) a language for transforming XML.
• XSL-FO - (XSL Formatting Objects) a language that can be used in XSLT for the purpose of "presenting" the XML.
XSL Formatting Objects is a W3C standard used by Ecrion XF Rendering Server to produce print-ready documents in PDF, AFP, WordML, Postscript, TIFF and other formats.
XF Designer can edit XSL-FO documents the same way like a HTML editor can edit HTML pages.
The following image depicts the steps required to produce a PDF document (or any other supported output format) using XSL:
As it can be noticed, the XML data is transformed together with the XSL stylesheet to produce an XSL-FO document and the document is then converted to PDF.
How hard it is to learn?
The XSL-FO language uses CSS (Cascading Style Sheets) to describe formatting attributes like fonts, colors and borders, so from this point of view, it should be easy to learn by HTML developers. This manual will help all users understand the language and accomplish more complicated tasks.
Here is the traditional Hello World, XSL-FO style:
<?xml version="1.0" encoding="utf-8" ?>
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format"> (1)
<fo:layout-master-set> (2)
<fo:simple-page-master master-name="LetterPage" page-width="6.5in"
page-height="1in"> (3)
<fo:region-body region-name="PageBody" margin="0.2in"/>
</fo:simple-page-master>
</fo:layout-master-set>
<fo:page-sequence master-reference="LetterPage">
<fo:flow flow-name="PageBody" font-family="Times New Roman"
font-size="24pt">
<fo:block> Hello World </fo:block> (4)
</fo:flow>
</fo:page-sequence>
</fo:root>
Key observations:
(1) Any XML document must have only one root, and XSL- FO makes no exception. The root element for an XSL-FO document is fo:root. The word "fo" before column character ":" is called a namespace prefix. An XML namespace is collection of names identified by an unique URL. Its main role is to avoid collisions when a single XML document contains elements and attributes defined by multiple software modules. The "fo" namespace prefix is linked with an unique URL, in this case "http://www.w3.org/1999/XSL/Format" using xmlns attribute. This syntax is based on W3C XML Namespace Spec.
(2)(3) The page's structure is defined using fo:layout-master-set; more information regarding the structure of page sequences can be found in the Pagination chapter. For now, it is enough to say that it declares one type of page, 11.5 x 8 inches (US Letter).
(4) The "Hello World" paragraph is added to the page.
The result of the rendering should be the following:
To convert this document into PDF, the user can use XF Designer. The document must be opened in the application and generate the PDF from the Generate group located under the Home tab.
An alternative is the Render.exe tool, that is, a console program located in "C:\Program Files\Ecrion Software\XF Rendering Server 2013 vvX.X.X\bin" (where vX.X.Xstands for XF Rendering Server's version).
The command line used for rendering the document is the following:
Render.exe -fo HelloWorld.fo -pdf C:\Temp\HelloWorld.pdf
The command line flag -pdf is optional; if it not present, the server will generate a PDF file with a name identical with the input file's name, at the same location and with the .pdf extension.