XSL Formatting Objects (or XSL-FO) provide a way to transform XML input data for output, usually for formatted "printing". Please remember, "printing" is a pretty loose term when speaking of XML input. A better way to put it might be:
XSL-FO is an XML application that describes how pages will look when presented to a reader.
There are many XSL FO objects to work with. Rather than trying to cover all of them, let us walk through an example use. You can download these example files to use with our walkthrough.
Open up your copy of krusty.xml in any text editor. It should look something like this:
<?xml version="1.0" encoding="UTF-8"?> <data> <name> Krusty the Clown </name> <description> This memo explains why Krusty the Clown is our best customer. We need to take good care of him from now onwards and make sure that there are always enough bananas for his pet monkey. </description> </data>
As you can see, this is a pretty simple file. The root node is called data, and it contains a node called name and another node called description.
Now open up your copy of krusty.fo in another text editor window. It should look something like this:
<?xml version="1.0" encoding="utf-8"?>
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
<fo:layout-master-set>
<fo:simple-page-master master-name="simple"
page-height="29.7cm"
page-width="21cm"
margin-top="1cm"
margin-bottom="2cm"
margin-left="2.5cm"
margin-right="2.5cm">
<fo:region-body margin-top="3cm"/>
<fo:region-before extent="3cm"/>
<fo:region-after extent="1.5cm"/>
</fo:simple-page-master>
</fo:layout-master-set>
<fo:page-sequence master-reference="simple">
<fo:flow flow-name="xsl-region-body">
<fo:block font-size="18pt"
font-family="sans-serif"
line-height="24pt"
space-after.optimum="15pt"
background-color="blue"
color="white"
text-align="center"
padding-top="3pt">
Krusty the Clown
</fo:block>
<fo:block font-size="12pt"
font-family="sans-serif"
line-height="15pt"
space-after.optimum="3pt"
text-align="justify">
This memo explains why Krusty the Clown is our best customer. We need to take good care
of him from now onwards and make sure that there are always enough bananas for his pet monkey.
</fo:block>
</fo:flow>
</fo:page-sequence>
</fo:root>
Notice the root node of an XSLT-FO file is called root and that the convention (not required) is to declare a namespace of fo for use in the file. Notice the use of region names to designate areas to specify how to treat, and the use of the block tag within the page-sequence/regions.
You will find two files within the examples directory for this week, called all_well.xml (the xml data file) and all_well.xsd (a schema generated from that XML file). Your task this week (complete assignment and turn in URI not later than the start of the next class) will be to create a file author.xsl which contains the XSL-T and the XSL-FO in one file and can be used to transform the play XML data into PDF format. There will be one constant declared, and it is used to select whichever character you are outputting for this time.
The output should be nicely formatted, and the character specified (in the constant) should have their lines formatted to make it easy for the person playing that part to pick out their lines when reading the script (examples: change background color for that character, all lines for that character in bold, or some similar formatting choice).
Last modified: 9 Mar 2009 11:02:43 AM