xslt, two column lists

Two column lists?

1. How to get two column lists

1.

How to get two column lists

Nikolai Grigoriev

> Using FOs, I would like to lay out a list into 2 columns so that half
> the list items are in the first column and the remaining are in the
> second column.  Moreover, this should work for an arbitrary number of
> list items.  What is a direct way of coding this in XSL to produce
> FOs?

There's no special for XSL FO, the same HTML trick applies: draw a table of two cells and put the first half of items into the first cell and the rest to the second. Here's an (untested) sample for the last XSL FO draft (2000-03-27):

<xsl:template match="OL">
   <xsl:variable name="threshold" select="(count(LI) + 1) div 2"/>

   <fo:table>
      <fo:column column-width="..."/> <!-- first column -->
      <fo:column column-width="..."/> <!-- second column -->
      <fo:table-body>
         <fo:table-row>
            <fo:table-cell> <!-- First column -->
               <fo:list-block>
                  <xsl:apply-templates 
                       select="LI[position() <=threshold]"/>
               </fo:list-block>
            </fo:table-cell>
            <fo:table-cell> <!-- Second column -->
               <fo:list-block>
                  <xsl:apply-templates 
                       select="LI[position() > $threshold]"/>
               </fo:list-block>
            </fo:table-cell>
         </fo:table-row>
      <fo:table-body>
   </fo:table>
</xsl:template>

<xsl:template match="OL/LI">
   <fo:list-item>
      <fo:list-item-label end-indent="label-end()">
          <xsl:number format="1."/>
      </fo:list-item-label>
      <fo:list-item-body start-indent="body-start()">
          <xsl:apply-templates/>
      </fo:list-item-body>
   </fo:list-item>
</xsl:template>