Borders and background shading

In HTML output, you can use CSS styles to add borders and background shading to your already generated HTML. But for print, the XSL templates have to supply the border and background properties.

If the element you want to style has its own attribute-set defined in the stylesheet, then adding borders and shading is done by simply adding attributes to the set. All of these elements have such attribute-sets:

admonitions (note, caution, etc.)qanda titles
blockquotesrefentry titles
component titles (chapter, etc.)section titles
equationssections
examplessidebars
figurestables
formal object titlesverbatims (programlisting, literallayout)
procedures 

In this example, borders and shading are added to all admonitions (note, caution, warning, tip, and important).

<xsl:attribute-set name="admonition.properties">
  <xsl:attribute name="border">0.5pt solid blue</xsl:attribute>
  <xsl:attribute name="background-color">#E0E0E0</xsl:attribute>
  <xsl:attribute name="padding">0.1in</xsl:attribute>
</xsl:attribute-set>

Likewise, this example adds a shaded background band behind each level 1 section title. The band extends across the page because the title's generated block area extends across the page, even if the text does not.

<xsl:attribute-set name="section.title.level1.properties">
  <xsl:attribute name="background-color">#E0E0E0</xsl:attribute>
  <xsl:attribute name="padding">8pt</xsl:attribute>
</xsl:attribute-set>

If the element you want to style does not have its own attribute-set, you will need to customize the template that formats the element. You may also want customize a template for an element that has such an attribute-set. For example, the admonition.properties attribute set applies to the body of a note, and does not include its title.

In your customization, you will want to find where the outer fo:block is output and add a border or background-color attribute. The following example adds them for formalpara elements:

<xsl:template match="formalpara">
  <fo:block xsl:use-attribute-sets="normal.para.spacing"
        background-color="#E0E0E0"
        border="0.5pt solid blue"
        padding="3pt">
    <xsl:apply-templates/>
  </fo:block>
</xsl:template>

The padding attribute adds a bit of shaded space around the text so the border is not almost touching the text.