XSL-FO is a scripting extension of XML which stands for Extensible Stylesheet Language Formatting Objects. Its main purpose is to format XML data for output to screen, paper or other media. A prior knowledge of XML is required to learn XSL-FO. In this tutorial, we would discuss the structure of XSL-FO documents in detail.
XSL-FO documents are stored in files with a .fo or a .fob file extension. You can also store XSL-FO documents with an .xml extension (to make them more accessible to XML editors). Following example would help you understand the structure of an XML document:
1 2 3 4 5 6 7 8 9 10 11 |
<?xml version="1.0" encoding="ISO-8859-1"?> <fo:root xmlns:fo="http://www.google.com/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> |
An XSL-FO document starts with an XML declaration, which in the above example was:
1 |
<?xml version="1.0" encoding="ISO-8859-1"?> |
The <fo:root> element is the root element of XSL-FO documents. The root element also declares the namespace for XSL-FO:
1 2 3 |
<fo:root xmlns:fo="http://www.google.com/1999/XSL/Format"> <!-- The full XSL-FO document goes here --> </fo:root> |
The <fo:layout-master-set> element contains one or more page templates:
1 2 3 |
<fo:layout-master-set> <!-- All page templates go here --> </fo:layout-master-set> |
Each <fo:simple-page-master> element contains a single page template. Each template must have a unique name (master-name):
1 2 3 |
<fo:simple-page-master master-name="A4"> <!-- One page template goes here --> </fo:simple-page-master> |
One or more <fo:page-sequence> elements describe the page contents. The master-reference attribute refers to the simple-page-master template with the same name:
1 2 3 |
<fo:page-sequence master-reference="A4"> <!-- Page content goes here --> </fo:page-sequence> |
Other important aspects of XSL-FO would be discussed in future tutorials.