Lists and enumerations

In this example ordered and unordered lists (enumerations) are generated.

For ordered lists (lists in which the list elements are consecutively numbered) and for unordered lists (lists in which each list element gets the same leading sign) a coherent stylesheet concept is demonstrated.

Excerpt from the DTD:

<!ELEMENT OL (LE+)>                                                ❶
<!ATTLIST OL
   Type (numeric | alpha-small | alpha-large) "numeric">           ❷
<!ELEMENT UL (LE+)>                                                ❶
<!ATTLIST UL
   Prefix (Dash | Dot | Without | Square) "Dash">                  ❸
<!ELEMENT LE (P+)>
<!ELEMENT P (#PCDATA | ... | UL | OL)*>                            ❹

❶ The content models for ordered and unordered lists are the same. In both cases the sub-elements are list elements (LE).

❷ The list elements of the ordered lists have to be formatted differently. But the counting method does not change.

❸ The list elements of the unordered lists have to be provided with different leading signs.

❹ List elements consist of one or several text paragraphs which may contain lists. So, lists are used recursively.

 

Stylesheet:

<xsl:template match="UL | OL">                                             ❶
   <fo:list-block margin-left="0mm"                                        ❷
    provisional-distance-between-starts="10mm" 
    space-before="2mm" space-after="2mm">
      <xsl:apply-templates/>
   </fo:list-block>
</xsl:template>
...
<xsl:template match="LE">                                                  ❸
   <xsl:if test="parent::OL">                                              ❸
      <fo:list-item>                                                       ❹
         <fo:list-item-label end-indent="label-end()">                     ❹
            <fo:block>
               <xsl:choose>                                                ❺
                  <xsl:when test="parent::node()/@Type='alpha-small'">     ❻
                     <xsl:number format="a"/>)
                  </xsl:when>
                  <xsl:when test="parent::node()/@Type='alpha-large'">
                     <xsl:number format="A"/>)
                  </xsl:when>
                     <xsl:otherwise>
                        <xsl:number/>.                                     ❼
                     </xsl:otherwise>
               </xsl:choose>
            </fo:block>
         </fo:list-item-label>
         <fo:list-item-body start-indent="body-start()">                   ❹
            <fo:block>
               <xsl:apply-templates/>
            </fo:block>
         </fo:list-item-body>
      </fo:list-item>
   </xsl:if>
   <xsl:if test="parent::UL">                                             
      <fo:list-item>                                                       ❸
         <fo:list-item-label end-indent="label-end()">                  
            <fo:block>                                                     ❹
               <xsl:choose>
                  <xsl:when test="parent::node()/@Prefix='Dot'">           ❽
                     <fo:block font-family="Arial Unicode MS">&#x2022;     ❾
                     </fo:block> 
                  </xsl:when>
                  <xsl:when test="parent::node()/@Prefix='Without'">       ❾
                  </xsl:when> 
                  <xsl:when test="parent::node()/@Prefix='Square'">
                     <fo:block font-family="Arial Unicode MS">&#x25A1;
                     </fo:block>                                   
                  </xsl:when>
                  <xsl:otherwise>                                          ❼
                     <fo:block font-family="Arial Unicode MS">&#x2012;
                     </fo:block>
                  </xsl:otherwise>
               </xsl:choose>
            </fo:block>
         </fo:list-item-label>
         <fo:list-item-body start-indent="body-start()">                   ❹
            <fo:block>
               <xsl:apply-templates/>
            </fo:block>
         </fo:list-item-body>
      </fo:list-item> 
   </xsl:if>
</xsl:template>

❶ Ordered and unordered lists can be specified in a template. Also nested lists do not require their own templates. They are automatically indented because their left margin is the indented margin of the superordinated list paragraphs.

❷ For the lists a list block (<fo:list-block>) is defined in which the distance from the left margin, the room for the counting or the leading sign of the list elements, as well as the spaces at the top and at the bottom are specified. Further typographical attributes which collectively apply for lists and are inheritable can be added here. The list block consists of any number of list elements (<fo:list-item>).

❸ Also the list elements only need one template. The different treatment of list elements in ordered and unordered lists is regulated by the <xsl:if> condition.

❹ Each list element consists of the pair of <fo:list-item-label> and <fo:list-item-body>.

❺ The <xsl:choose> construct has to be used here in order to take account of the default for the formatting of the numbering within the ordered list.

❻ If in the <OL> parent element the attribute value alpha-small is specified for the Type attribute, the numbering shall be done with lower case letters and the closing bracket as punctuation mark.

❼ The case distinction <xsl:otherwise> applies for the attribute value which is specified as default value in the DTD or in case where the attribute is not specified at all.

❽ The <xsl:choose> construct has to be applied here in order to take account of the default for the leading signs within the unordered lists.

❾ If in the <UL> parent element the Dot attribute value for the Prefix attribute is specified, the leading sign shall be a bold dot set to the centre. The sign is displayed by an Unicode character entity reference. For the Without attribute value applies that no leading sign appears (a so-called simple list).

 

<< back next >>

Copyright © dpunkt.verlag GmbH 2004
Printing of the online version is permitted exclusively for private use. Otherwise this chapter from the book "XSL-FO in der Praxis" ("XSL-FO in practice") is subject to the same provisions as those applicable for the hardcover edition: The work including all its components is protected by copyright. All rights reserved, including reproduction, translation, microfilming as well as storage and processing in electronic systems.

dpunkt.verlag GmbH, Ringstraße 19B, 69115 Heidelberg, fon 06221-14830, fax 06221-148399, hallo@dpunkt.de