XSL-FO lists are created using fo:list-block element. A list can contain one or more items: fo:list-item.
Each item has a label: fo:list-item-label,usually used to display a bullet or a number, and a body: fo:list-item-body.
Example of usage:
...
<fo:block>Ecrion Products:</fo:block>
<fo:list-block> (1)
<fo:list-item> (2)
<fo:list-item-label end-indent="label-end()"> (3)
<fo:block>
1)
</fo:block>
</fo:list-item-label>
<fo:list-item-body start-indent="body-start()"> (4)
<fo:block>
XF Rendering Server
</fo:block>
</fo:list-item-body>
</fo:list-item>
<fo:list-item>
<fo:list-item-label end-indent="label-end()">
<fo:block>
2)
</fo:block>
</fo:list-item-label>
<fo:list-item-body start-indent="body-start()">
<fo:block>
XF Designer
</fo:block>
</fo:list-item-body>
</fo:list-item>
<fo:list-item>
<fo:list-item-label end-indent="label-end()">
<fo:block>
3)
</fo:block>
</fo:list-item-label>
<fo:list-item-body start-indent="body-start()">
<fo:block>
XF Desktop
</fo:block>
</fo:list-item-body>
</fo:list-item>
<fo:list-item>
<fo:list-item-label end-indent="label-end()">
<fo:block>
4)
</fo:block>
</fo:list-item-label>
<fo:list-item-body start-indent="body-start()">
<fo:block>
Data Architect
</fo:block>
</fo:list-item-body>
</fo:list-item>
<fo:list-item>
<fo:list-item-label end-indent="label-end()">
<fo:block>
5)
</fo:block>
</fo:list-item-label>
<fo:list-item-body start-indent="body-start()">
<fo:block>
Data Aggregation Server
</fo:block>
</fo:list-item-body>
</fo:list-item>
</fo:list-block>
Output:
Key observations:
(1) The list is created using fo:list-block.
(2) A list can have one or multiple items.
(3),(4) Each item has a label, usually used to display a bullet or number, and a body.
► | Numbered Lists |
XSL-FO does not provide an element to create numbered lists like HTML does; these have to generate the numbers using XSL techniques.
The following source XML document is considered:
<products>
<product>Fuji FinePix F700</product>
<product>Nikon CoolPix 5700</product>
<product>Cannon Powershot A310</product>
</products>
An XSL template that uses xsl:number element to generate numbers for each fo:list-item-label must be created.
Example of usage:
<?xml version="1.0" encoding="utf-8"?>
<?xsl-test-case type="text/xml" href=".\Numbered List.xml"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" encoding="utf-8" indent="yes"/>
<xsl:template match="/">
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
<fo:layout-master-set>
<fo:simple-page-master master-name="all" page-width="5in" page-height="1in">
<fo:region-body region-name="xsl-region-body" margin="0.2in"/>
</fo:simple-page-master>
</fo:layout-master-set>
<fo:page-sequence master-reference="all">
<fo:flow flow-name="xsl-region-body" font="10pt Arial">
<fo:list-block>
<xsl:for-each select="products/product">
<fo:list-item>
<fo:list-item-label end-indent="label-end()">
<fo:block>
<xsl:number/>
</fo:block>
</fo:list-item-label>
<fo:list-item-body start-indent="body-start()">
<fo:block>
<xsl:value-of select="."/>
</fo:block>
</fo:list-item-body>
</fo:list-item>
</xsl:for-each>
</fo:list-block>
</fo:flow>
</fo:page-sequence>
</fo:root>
</xsl:template>
</xsl:stylesheet>