Search code examples
htmlxsltxsl-foapache-fop

FO List Block change style


I am using XSL FO list block to show bullet points. Is it possible to change list-style-type to show square (or other shape)? In HTML, it is <ul style="list-style-type:square;">

Code:

<fo:list-block>
<fo:list-item>
 <fo:list-item-label>
   <fo:block>*</fo:block>
 </fo:list-item-label>
 <fo:list-item-body>
   <fo:block>Volvo</fo:block>
 </fo:list-item-body>
</fo:list-item>
<fo:list-item>
 <fo:list-item-label>
   <fo:block>*</fo:block>
 </fo:list-item-label>
 <fo:list-item-body>
   <fo:block>Saab</fo:block>
 </fo:list-item-body>
</fo:list-item>
</fo:list-block>

Solution

  • Put the character that you want in place of the *:

    <fo:list-item-label>
      <fo:block color="blue" font-weight="bold" font-size="1.3em">✪</fo:block>
     </fo:list-item-label>
    

    This looks like a lot of work compared to <ul style="list-style-type:square;">, but:

    • You typically only need to do this once, since you are generating the XSL-FO using XSLT
    • You have complete control over the content, size, weight, colour, alignment (see relative-align: https://www.w3.org/TR/xsl11/#relative-align), and position of the list item label (and, as above, you typically only need to set that up once)
    • If you want to, you could change, e.g., the colour of the bullet for each list item by using position() in your XSLT
    • When you look at numbering list items, you'll see that xsl:number makes it easy to generate hierarchical numbers to use in list item labels. (If you were using AH Formatter, you'd also be able to use a bunch of predefined counter styles: https://www.antenna.co.jp/AHF/help/en/ahf-ext.html#axf.counter-style.)