Besides tables, an XSL construct that is very close to the corresponding construct in HTML are lists. An XSL list presents a vertical arrangement of items, just as in HTML. You use four formatting objects to construct lists:
You enclose the whole list in a fo:list-block object and enclose each item in the list in a fo:list-item object. To create a label for the list item, you use a fo:list-item-label object; to insert the actual data for each list item, you use a fo:list-item-body object. Here's an example creating a numbered list with three list items: Tic , Tac , and Toe : Listing ch14_10.fo<?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 margin-right="20mm" margin-left="20mm" margin-bottom="10mm" margin-top="10mm" page-width="300mm" page-height="400mm" master-name="page"> <fo:region-body margin-right="0mm" margin-left="0mm" margin-bottom="10mm" margin-top="0mm"/> <fo:region-after extent="10mm"/> </fo:simple-page-master> </fo:layout-master-set> <fo:page-sequence master-reference="page"> <fo:flow flow-name="xsl-region-body"> <fo:list-block provisional-distance-between-starts="15mm" provisional-label-separation="5mm"> <fo:list-item line-height="20mm"> <fo:list-item-label> <fo:block font-family="sans-serif" font-size="36pt"> 1. </fo:block> </fo:list-item-label> <fo:list-item-body start-indent="body-start()"> <fo:block font-family="sans-serif" font-size="36pt"> Tic. </fo:block> </fo:list-item-body> </fo:list-item> <fo:list-item line-height="20mm"> <fo:list-item-label> <fo:block font-family="sans-serif" font-size="36pt"> 2. </fo:block> </fo:list-item-label> <fo:list-item-body start-indent="body-start()"> <fo:block font-family="sans-serif" font-size="36pt"> Tac. </fo:block> </fo:list-item-body> </fo:list-item> <fo:list-item line-height="20mm"> <fo:list-item-label> <fo:block font-family="sans-serif" font-size="36pt"> 3. </fo:block> </fo:list-item-label> <fo:list-item-body start-indent="body-start()"> <fo:block font-family="sans-serif" font-size="36pt"> Toe. </fo:block> </fo:list-item-body> </fo:list-item> </fo:list-block> </fo:flow> </fo:page-sequence> </fo:root> You can see the resulting PDF file displayed in the Adobe Acrobat in Figure 14-4, showing the list. Figure 14-4. An XSL-formatted list in Adobe Acrobat.
I'll take a look at the list-formatting objects in more detail now. fo:list-blockYou use fo:list-block to format create a list; this object encloses fo:list-item objects. You can use these properties with the fo:list-block object:
fo:list-itemYou use a fo:list-item object to contain the label and the body of an item in a list. You can use these properties with the fo:list-item object:
fo:list-item-labelYou use the fo:list-item-label object to hold the label of a list item, usually to enumerate or decorate (as with a bullet) the body of the list item. You can use these properties with the fo:list-item-label object:
fo:list-item-bodyYou use the fo:list-item-body object to hold the actual body of a list item. To format the item's body the way you want it, you can enclose a fo:block object in a fo:list-item-body object. You can use these properties with the fo:list-item-body object:
As you can see, there's a lot to XSL formatting objects. In fact, there's a lot more that we don't have the space to cover here. For more details, take a look at the W3C site. Not a lot of software packages can put formatting objects to work yet, however, although that should change in the future. In the next chapter, I'm going to start taking an in-depth look at another important part of the XML specification: XLinks and XPointers. |