XSL-FO (XSL Formatting Objects) is a markup language for XML document formatting which is most often used to generate printed content.
From Wikipedia
XSL-FO is part of XSL (Extensible Stylesheet Language), a set of W3C technologies designed for the transformation and formatting of XML data. The other part of XSL is XSLT (Extensible Stylesheet Language Transformations). As of December 12, 2006, the current version of XSL-FO is v1.1.
An XSL-FO document is typically generated using XSLT. An XSLT processor (such as Saxon) evaluates the templates in an XSLT stylesheet to transform your data in your XML vocabulary (or your text or JSON or Markdown or...) into XML in the XSL-FO vocabulary.
Rather than just adding styles to the fixed structure of the source document, the transformation stage is able to also reorder, duplicate, or drop parts of the source document when generating the XSL-FO document, as well as generate new content based on the structure of the source document. This is especially useful when generating tables of contents and indexes that will appear in the formatted document.
The elements in the XSL-FO document represent the formatting objects, and their attributes represent properties of the formatting objects. There are FOs for: blocks; tables and parts of tables; images; links; index entries; and so on. The properties express values such as font size, the expected space between FOs, or whether two FOs should be kept together on the same page. The XSL-FO contains the templates for the types of pages that will be used when the document is made into pages, but the XSL-FO does not contain any information about page breaks or (usually) line breaks.
XSL-FO markup can then be rendered by an FO processor, where it is most commonly used to generate document formats such as PDF, PostScript or RTF. The FO processor uses the structure of the FOs, the constraints expressed by the properties, the sizes of characters in the available fonts, the intrinsic sizes of the graphics, and other factors to lay the content of the XSL-FO out into pages. There is currently one option for viewing the pages in the FO processor application itself, but once the pages are written to a PDF file or other format, the pages can be viewed on screen or printed.
XSL-FO is well suited to applications where you have either a range of broadly similar documents that you want to format in the same style or single large document for which you want consistent styling without much manual effort. The XSLT stage takes care of specifying the right styles for the structures in your source XML and of generating the table of contents and index, and the FO processor automatically lays out the pages in accordance with the specified styles.
Links:
- W3C XSL-FO Specification
- XSL-FO Tutorial
- Apache FOP, a freeware print formatter
- Free download of book "Practical Formatting Using XSL-FO"
- Other implementations that take XSL-FO as input: Antenna House Formatter and RenderX