Getting an area tree within your XSLT transform
Posted on:The Print and Page Layout Community Group is developing a series of open-source extensions for XSLT processors so you can run any number of iterations of your XSL-FO processor from within your XSLT transformation, which allows you to make decisions based on formatted sizes of areas.
The extensions are currently available for Java and DotNet and use either the Apache FOP XSL formatter or Antenna House AHF formatter to produce the area trees. Contributions supporting more XSLT–XSL-FO combinations would, of course, be welcome.
A single Java jar file covers four combinations of XSLT processor and XSL-FO formatter:
- Saxon 9.5 and FOP
- Saxon 9.5 and Antenna House
- Xalan and FOP
- Xalan and Antenna House
The DotNet version supports:
- DotNet 4.0 and FOP
- DotNet 4.0 and Antenna House
The graphic below is from a poster done for the Balisage 2014 conference. It shows four ways that the XSLT extensions can be used. Can you see what they are?
Size text to fill available width
The title text is formatted at a known size, then formatted “for real” with the font-size multiplied by the ratio of the available width to the formatted width.
Size text to fill available height
The ‘do-box’ template recursively calls itself until one of these conditions is true:
- The formatted area fits within the box within a specified tolerance
- The change in font size between successive runs is less than the font size tolerance
- The maximum number of iterations is reached.
Adjust fo:list-block
start-indent
Just the list item labels are formatted, then the longest length is found and the provisional-distance-between-starts
is set on the fo:list-block
is set to that length.
Make list item body avoid a long label
Each fo:list-item-body
formats its fo:list-item-label
and, if the fo:list-item-label
is too long, adds space above itself to get out of the way.
Where can I get it?
The main page for the XSLT extensions on on the PPL CG wiki at http://www.w3.org/community/ppl/wiki/XSLTExtensions. The source code for the extensions and the examples are available from the Mercurial repository at https://dvcs.w3.org/hg/ppl and are manually mirrored on GitHub at https://github.com/pplcg/XSLTExtensions.