i-Lab Guide To: XSL-FO

What Is It ?

XSL-FO is the second part of the XSL specification that defines an XML dialect for specifying Formatting Objects. While XSL can be used for transforming XML data into virtually any format, XSL-FO is specifically geared towards transforming XML data to a precisely defined presentation media (namely printable output).

Typically XML data is first transformed into an XML file that can be validated against the xsl-fo schema by an XSLT processor (e.g. Apache Xalan). The formatting objects are then converted to a non-XML presentation format by a Formatting Objects Processor (e.g. Apache FOP). Such a processor will provide one or more output forms, typically including :-

  • PDF
  • AWT
  • etc...
The big advantage of the XSL-FO approach is that data can be competely separated from its presentation.
   
Relative Paths  
"child"
Selects all child nodes in at the level of the current context
"@attribute" Selects the named attribute from the current context
"child/@attribute" Selects the named attribute from the child nodes
"." Selects the current context node
".." Selects the parent node

Absolute Paths

 
"/root/child/leaf"
Selects all leaf elements descended from child and root elements
"/"
Selects all nodes at the root level
Predicates  
"line[3]" 3rd line element
"line[3|7]" 3rd or 7th line element
"line[position() = 3]" 3rd line element
"line[last()]" Last line element
"line[position() mod 2]" Every other line element
"line[@type='xxx']" Elements with a type attribute whose value equals xxx
Axes  
"child::xxx" Abbreviated form "xxx"
"parent::xxx" Abbreviated form ".."
"self::xxx" Abbreviated form "."
"attribute::xxx" Abbreviated form "@xxx"
"ancestor::xxx"  
"ancestor-or-self::xxx"  
"descendant::xxx"  
"descendant-or-self::xxx"  
"preceding-sibling::xxx"  
"following-sibling::xxx"  
"preceding::xxx"  
"following::xxx"  
"namespace::xxx"  
Functions  
position()  
last() Returns the position of the last node in the node-set
   

© 2003 i-Lab Limited