### Constructing FO from XML documents

So far we have learnt some basic FO elements. As with HTML we typically generate FO code from other sources rather than crafting it by hand. The general picture is:

We discussed the FO standard as an input format for printable output production by a renderer. In this way a FO document is similar to HTML being a format to be rendered by a web browser for visual (screen oriented) output production. The transformation from a XML source (e.g. a memo document) to FO is still missing. As for HTML we may use XSL as a transformation means. We generate the sender's surname from a memo document instance:

A suitable XML document instance reads:

Some remarks:

1. The xsl_stylesheet element contains a namespace definition for the target FO document's namespace, namely:

xmlns:xsl="http://www.w3.org/1999/XSL/Transform"

This is required to use elements like fo:block belonging to the FO namespace.

2. The option value indent="yes" in xsl_output is usually set to "no" in a production environment to avoid whitespace related problems.

3. The generation of a print format like PDF is actually a two step process. To generate message.pdf from message.xml by a stylesheet memo2fo.xsl we need the following calls:

XML document instance to FO
xml2xml message.xml memo2fo.xsl -o message.fo
FO to PDF
fo2pdf -fo message.fo -pdf message.pdf

When debugging of the intermediate FO file is not required both steps may be combined into a single call:

fo2pdf -xml message.xml -xsl memo2fo.xsl -pdf message.pdf