Creating Lists

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:

  • fo: list-block

  • fo:list-item

  • fo:list-item-label

  • fo:list-item-body

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.

graphics/14fig04.gif

I'll take a look at the list-formatting objects in more detail now.

fo:list-block

You 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:

  • Common accessibility properties: source-document , role

  • Common aural properties: azimuth , cue-after , cue-before , elevation , pause-after , pause-before , pitch , pitch-range , play-during , richness , speak , speak-header , speak-numeral , speak-punctuation , speech-rate , stress , voice-family , volume

  • Common border, padding, and background properties: background-attachment , background- color , background-image , background-repeat , background-position-horizontal , background-position-vertical , border-before-color , border-before-style , border-before-width , border-after-color , border-after-style , border-after-width , border-start-color , border-start-style , border-start-width , border-end-color , border-end-style , border-end-width , border-top-color , border-top-style , border-top-width , border-bottom-color , border-bottom-style , border-bottom-width , border-left-color , border-left-style , border-left-width , border-right-color , border-right-style , border-right-width , padding-before , padding-after , padding-start , padding-end , padding-top , padding-bottom , padding-left , padding-right

  • Common margin properties: margin-top , margin-bott om, margin-left , margin-right , space-before , space-after , start-indent , end-indent

  • break-after

  • break-before

  • id

  • keep-together

  • keep-with- next

  • keep-with-previous

  • provisional-distance-between-starts

  • provisional-label-separation

  • relative-position

fo:list-item

You 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:

  • Common accessibility properties: source-document , role

  • Common aural properties: azimuth , cue-after , cue-before , elevation , pause-after , pause-before , pitch , pitch-range , play-during , richness , speak , speak-header , speak-numeral , speak-punctuation , speech-rate , stress , voice-family , volume

  • Common border, padding, and background properties: background-attachment , background-col or, background-image , background-repeat , background-position-horizontal , background-position-vertical , border-before-color , border-before-style , border-before-width , border-after-color , border-after-style , border-after-width , border-start-color , border-start-style , border-start-width , border-end-color , border-end-style , border-end-width , border-top-color , border-top-style , border-top-width , border-bottom-color , border-bottom-style , border-bottom-width , border-left-color , border-left-style , border-left-width , border-right-color , border-right-style , border-right-width , padding-before , padding-after , padding-start , padding-end , padding-top , padding-bottom , padding-left , padding-right

  • Common margin properties, block: margin-top , margin-bottom , margin-left , margin-right , space-before , space-after , start-indent , end-indent

  • break-after

  • break-before

  • id

  • keep-together

  • keep-with-next

  • keep-with-previous

  • relative-align

  • relative-position

fo:list-item-label

You 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:

  • Common accessibility properties: source-document , role

  • id

  • keep-together

fo:list-item-body

You 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:

  • Common accessibility properties: source-document , role

  • id

  • keep-together

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.



Real World XML
Real World XML (2nd Edition)
ISBN: 0735712867
EAN: 2147483647
Year: 2005
Pages: 440
Authors: Steve Holzner

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net