Attribute sets

XSL supports the definition of named sets of attributes. An attribute-set is like a complex parameter that lets you define a collection of attribute names and values that can be referenced by a single attribute-set name. That permits you to "define once, use globally" any groups of attributes that apply in more than one place. The DocBook FO stylesheet defines many attribute-sets in the fo/param.xsl stylesheet file. The DocBook attribute-sets are documented in the FO Parameter Reference.

The DocBook attribute-sets can be customized like parameters in your customization layer. The following is an example of the original definition of an attribute-set named section.title.properties in fo/param.xsl:

<xsl:attribute-set name="section.title.properties">
  <xsl:attribute name="font-family">
    <xsl:value-of select="$title.font.family"/>
  </xsl:attribute>
  <xsl:attribute name="font-weight">bold</xsl:attribute>
  <!-- font size is added dynamically by section.heading template -->
  <xsl:attribute name="keep-with-next.within-column">always</xsl:attribute>
  <xsl:attribute name="space-before.minimum">0.8em</xsl:attribute>
  <xsl:attribute name="space-before.optimum">1.0em</xsl:attribute>
  <xsl:attribute name="space-before.maximum">1.2em</xsl:attribute>
  <xsl:attribute name="text-align">left</xsl:attribute>
  <xsl:attribute name="start-indent">0pt</xsl:attribute>
</xsl:attribute-set>

It consists of a set of xsl:attribute elements enclosed in a xsl:attribute-set wrapper. The name of the set is assigned to the wrapper. This attribute-set is used for all section titles, on the assumption that they share many formatting properties.

These attributes are to be inserted into the fo:block start tag for the section title. That is accomplished in a DocBook XSL template with a xsl:use-attribute-sets attribute. The following is an example from the fo/sections.xsl stylesheet file:

<xsl:template name="section.heading">
  <xsl:param name="level" select="1"/>
  <xsl:param name="title"/>

  <fo:block  xsl:use-attribute-sets="section.title.properties">
  ...

Note that this attribute-set contains all the properties except the font-size. The section.heading template also determines what level of heading is currently being processed and adds a font-size property using another attribute-set specific to each level. For example, the attribute-set named section.title.level1.properties is used for level 1 section headings. With this design, you can specify common properties for all section headings by customizing the general section.title.properties attribute set, and customize individual heading levels with the more specific attribute-sets.

To customize an attribute-set, you do not have to copy the whole thing to your customization layer. It is a feature of attribute-sets that if more than one set has the same name, then they are effectively merged. That means you can add or modify just a few attributes and leave the rest as they are in the DocBook stylesheet. For example, if you want to left-align all your section headings and turn off boldface, you could add this to your customization layer:

<xsl:attribute-set name="section.title.properties">
  <xsl:attribute name="font-weight">normal</xsl:attribute>
  <xsl:attribute name="text-align">left</xsl:attribute>
</xsl:attribute-set>

The font-weight attribute overrides the value in the original attribute-set, and the text-align attribute adds a new property to the set. These attributes are merged with the other attributes at processing time. If two attributes have the same name within an attribute set, then the rules of import precedence apply. Basically this means your customization's value will override the default value in that attribute set in the stylesheet.