The simplelist
element is handy for creating, well, simple lists. It is typically used where you have a collection of one- or two-word items and you just need to list them, such as for a shopping list. The other list types such as itemizedlist
are too complex for such a simple thing. And a simplelist
has more options for presentation than the other lists.
A simplelist
can contain only member
elements, and a member
element can contain only text and inline elements. In fact, its content model is identical to the phrase
element. The following is a short example.
<simplelist type="vert" columns="2"> <member>carrots</member> <member>lettuce</member> <member>bananas</member> <member>potatoes</member> <member>cheese</member> <member>milk</member> </simplelist>
When you create the simplelist
, you can specify with the type
attribute how you want the list presented. The type
can be:
vert
Format the members in a table, with the sequence running down the columns. The column lengths are balanced to the degree possible. This is the default type if the attribute is not specified. The number of columns can be specified with a columns
attribute, which defaults to 1. So if you do not set any attributes on the simplelist
element, you get a single column list.
horiz
Format the members in a table, with the sequence running across the rows. The number of columns can be specified with a columns
attribute, which defaults to 1. If columns
is not greater than 1, then each row has a single column and the output reverts to a single-column vertical list.
inline
Format the members inline, in a sequence separated by commas. This type of simplelist
does not create a line break before and after it, and of all the DocBook list elements, it is the only one that does not. If it appears inside a para
, then the simplelist
members flow in the text lines with the other paragraph text. In XSL-FO output, a simplelist
of this type must be inside a block element or it will generate an error.
Examples of these three types can be seen on the reference page for this element in DocBook: The Definitive Guide
If you choose one of the tabular layouts, the output table has no additional text formatting, borders between cells, or outer frame. The templates do not provide any parameters or attribute-sets to customize them either. You will have to customize the templates in the lists.xsl
stylesheet module to change the output. There are separate templates for each of the type
attribute values.
The default table layout assigns equal proportional column widths to all of the columns in the output table. Proportional columns without an explicit overall table width will expand to take up the full body text measure. If all your entries are short, then they will be widely spread. If you want a narrower listing, you will have to customize the table. This works best if your XSL-FO processor supports table-layout="auto"
, which lets it measure the widths of cell content to determine the width of columns. The following example works for XEP and Antenna House for type="vert"
:
Add table-layout="auto" and turn off column settings: <xsl:template match="simplelist[@type='vert']"> <fo:table table-layout="auto" xsl:use-attribute-sets="normal.para.spacing"> <!-- Remove the call-template name="simplelist.table.columns" which sets proportional column widths --> <fo:table-body start-indent="0pt" end-indent="0pt"> <xsl:call-template name="simplelist.vert"> <xsl:with-param name="cols"> <xsl:choose> <xsl:when test="@columns"> <xsl:value-of select="@columns"/> </xsl:when> <xsl:otherwise>1</xsl:otherwise> </xsl:choose> </xsl:with-param> </xsl:call-template> </fo:table-body> </fo:table> </xsl:template> Add padding to cells so they do not abutt each other: <xsl:template name="simplelist.vert.row"> <xsl:param name="cols">1</xsl:param> <xsl:param name="rows">1</xsl:param> <xsl:param name="cell">1</xsl:param> <xsl:param name="members" select="./member"/> <xsl:param name="curcol">1</xsl:param> <xsl:if test="$curcol <= $cols"> <fo:table-cell padding-right="8pt" padding-bottom="4pt"> <fo:block> <xsl:if test="$members[position()=$cell]"> <xsl:apply-templates select="$members[position()=$cell]"/> </xsl:if> </fo:block> </fo:table-cell> <xsl:call-template name="simplelist.vert.row"> <xsl:with-param name="cols" select="$cols"/> <xsl:with-param name="rows" select="$rows"/> <xsl:with-param name="cell" select="$cell+$rows"/> <xsl:with-param name="members" select="$members"/> <xsl:with-param name="curcol" select="$curcol+1"/> </xsl:call-template> </xsl:if> </xsl:template>
This customization will result in all simplelist
elements being formatted in closely spaced tabular lists in the output.
If you are using type="inline"
, then the stylesheet provides one option. You can specify a choice
word before the last member to be output. The choice
word could be “and
” or “or
”, for example. This indicates to the reader how a choice is to be made, if that is appropriate for the list. You use a processing instruction to set the choice
word as follows:
<simplelist type="inline">
<?dbchoice choice="or"?>
<member>...
Whatever text appears in the pseudo attribute value will be output before the last member. As a special case, if the value is “and
”, it will be automatically translated to the current language because that word is one of the gentext elements already available.
DocBook XSL: The Complete Guide - 4th Edition | PDF version available | Copyright © 2002-2007 Sagehill Enterprises |