From Print and Page Layout Community Group
FOPRunXSLTExt is an (early) experiment in getting the area tree from an XSL formatter run as the result of calling an XSLT extension function in the same XSLT transform as will produce the "final" FO tree to be output for formatting as human readable pages.
It was initially developed by Arved Sandstrom of MagicLamp Software following discussion on the firstname.lastname@example.org mailing list. Further development now happens in the 'ppl' Mercurial repository at https://dvcs.w3.org/hg/ppl, with questions and comments happening on the email@example.com mailing list.
FOPRunXSLTExt is written in Java and uses the Apache FOP XSL formatter to produce the area trees.
The best way to get an up-to-date version is to clone the Mercurial repository and build it yourself.
The current version is available at Media:FOPRunXSLTExt.jar.zip
The extension requires the following libraries:
Get the current Windows distribution from File:FOPRunXSLTExt-windows-0.0.2.zip, unzip it on your system, and follow the instructions in the 'README' file.
1. Get and install Java JRE
2. Get and install Saxon
Saxon-HE is available from http://saxon.sourceforge.net/ as a Zip-encoded archive. Download the Zip file and extract its contents onto your local disk.
3. Get and install FOP 1.0
FOP distributions are available from http://xmlgraphics.apache.org/fop/download.html. Download the binary distribution of FOP 1.0 and extract its contents onto your local disk.
4. Edit 'runsaxon9he_fop10.bat' so the line beginning "set SAXON=" has the correct path to the Saxon-HE jar file on your system and so the line beginning "set FOP_HOME=" has the correct path to the "fop-1.0" folder that you extracted from the FOP binary distribution.
5. In the same directory as 'runsaxon9he_fop10.bat', run the following command:
runsaxon9he_fop10.bat example1.xml example1_saxon9_fop10.xsl out/example1_saxon9_fop10.url out example1_saxon9_fop10.at
Example 1 - Area Tree
This just writes an area tree to a file.
runsaxon9he_fop10.bat example1.xml example1_saxon9_fop10.xsl out/example1_saxon9_fop10.if out example1_saxon9_fop10.at
./runsaxon9he_fop10.sh example1.xml example1_saxon9_fop10.xsl out/example1_saxon9_fop10.url out example1_saxon9_fop10.at
./runxalan_fop10.sh example1.xml example1_xalan_fop10.xsl out/example1_xalan_fop10.url out example1_xalan_fop10.at
Example 3 - Rotate wide block
Rotates a fixed-size box if it is too wide for the page.
This is effectively a simplified version of requirement #10 from CustomerRequirements. That requirement is for knowing whether a table should be column-wide, page-wide, or rotated to to be page-high based on its formatted size. To do that, the stylesheet would have to get the sizes of the table when it's formatted to be column-wide, page-wide, and page-high and, based on those, decide which width and orientation to use for the table in the formatted result. This example reduces that to a single fixed-size block, analogous to the size of the formatted table, and the stylesheet just makes the single decision whether or not to rotate the block based on its formatted width.
The <box> element in 'example3.xml' specifies its formatted height and width:
<box id="box001" width="8in" height="5in">
With those dimensions, if you transform 'example3.xml' with 'formatting.xsl' and format the result, the box is wider than the width of the page and some of the text is lost.
If you transform 'example3.xml' with 'example3_saxon9_fop10.xsl', which uses the extension function to make an area tree during the transform and makes decisions based on formatted areas, the box is rotated when it is too wide for the page.
Run the example using one of the command lines below then then run an XSL formatter on 'out/example3_saxon9_fop10.fo' to see the result.
You can change the box/@width value in 'example3.xml' and run it again to see whether or not the box is rotated.
runsaxon9he_fop10.bat example3.xml example3_saxon9_fop10.xsl out/example3_saxon9_fop10.fo out example3_saxon9_fop10.at
./runsaxon9he_fop10.sh example3.xml example3_saxon9_fop10.xsl out/example3_saxon9_fop10.fo out example3_saxon9_fop10.at
Example 4 - List item label width
Adjusts the lengths allowed for list items to exactly fit the formatted width of the list item labels.
This demonstrates a solution to requirement #9, "Ability to modify label field width in a single list when labels are large", from CustomerRequirements.
'example4.xml' includes two lists that, when transformed with 'formatting.xsl' and formatted, have list item label widths that are either too wide or too narrow for the labels in the lists.
When transformed with 'example4_saxon9_fop10.xsl' and formatted, the list item label widths are set based on the actual maximum formatted width of the labels in each list. The 'example4_saxon9_fop10.xsl' stylesheet does this by constructing a test document containing just the list item label texts, using the extension function to format that and get the area tree, and determining the maximum widths from the area tree. The document that is formatted mid-transform is, unlike in previous examples, a different document to the one used to produce the final output.