Customizing inline text

Inline elements such as emphasis can be customized by replacing their templates in a customization layer. See the section “Replacing templates” for a description of the general method. The templates to be customized can be found in fo/inline.xsl for FO output.

Many of the templates for inline elements call one of the following named templates to change font. These template names are also used in the HTML stylesheets.

<xsl:call-template name="inline.charseq"/>Format with normal font.
<xsl:call-template name="inline.boldseq"/>Format with boldface.
<xsl:call-template name="inline.italicseq"/>Format with italics.
<xsl:call-template name="inline.monoseq"/>Format with monospace font.
<xsl:call-template name="inline.italicmonoseq"/>Format with italic monospace font.
<xsl:call-template name="inline.boldmonoseq"/>Format with bold monospace font.
<xsl:call-template name="inline.superscriptseq"/>Format with superscript.
<xsl:call-template name="inline.subscriptseq"/>Format with subscript.

Customizing inline elements that use these templates may mean just calling a different one of these templates. For example, this customization changes the font for the filename element from the default monospace to italic:

<xsl:template match="filename">
  <xsl:call-template name="inline.italicseq"/>

You can also add templates with more specific match attributes to further customize elements. For example, the filename element can also be used for directory names. You might use the class attribute to distinguish directory names, and then add a custom template to format them in boldface:

<xsl:template  match="filename[@class='directory']">
  <xsl:call-template  name="inline.boldseq"/>

The @class='directory' predicate means this template will only be considered for use on filename elements that have a class="directory" attribute. Its match attribute is more specific than the regular filename template, so it has precedence when that role value is used.

A similar template lets you customize formatting of phrase elements based on its role attribute value. A phrase with role attribute is an easy way to add specialized elements to your content, without having to customize the DTD. Here is a customization that handles genus and species names:

<xsl:template  match="phrase[@role='genus']">
  <xsl:call-template  name="inline.boldseq"/>
<xsl:template  match="phrase[@role='species']">
  <xsl:call-template  name="inline.italicseq"/>

This customization will output <phrase role="genus"> in bold, and <phrase role="species"> in italic.

If you want to select a font family that is different from the body font, then you need to customize such templates a bit further. See the section “Line annotations” for an example of customizing the font used for the lineannotation element.

Subscripts and superscripts

The DocBook XSL stylesheets provide separate attribute-sets for subscripts and superscripts. Some designers are quite picky about how those should be formatted, so these attribute-sets let you fine tune their styles.

Use the attribute-set to style subscripts, and the attribute-set to style superscripts. The default attribute-sets just reduce the font-size to 75%. You can adjust the font size, or change other font properties as in the example below. However, the shift in vertical position of sub- and superscripts is currently not handled by these attribute-sets. That's because the current FOP does not support the preferred baseline-shift property, so a different property must be used for that processor.

<xsl:attribute-set name="">
  <xsl:attribute name="font-size">60%</xsl:attribute>
  <xsl:attribute name="font-family">serif</xsl:attribute>

Underline and strike-through

Underlining can be added to inline text using the XSL-FO property text-decoration="underline". Likewise, text with a horizontal line through it can be generated using text-decoration="line-through". Although there is no enumerated value of role for these properties in the DocBook schema, the DocBook print stylesheet has support for these properties on any emphasis element with a role="underline" or role="strikethrough" attribute, respectively.

This template fragment shows how the properties are applied in the template with match="emphasis" in fo/inline.xsl:

    <xsl:when test="@role='underline'">
      <fo:inline text-decoration="underline">
        <xsl:call-template name="inline.charseq"/>
    <xsl:when test="@role='strikethrough'">
      <fo:inline text-decoration="line-through">
        <xsl:call-template name="inline.charseq"/>

The template wraps the element's content in an fo:inline element with the appropriate property added. You can use a similar technique in a customization layer to add underlining or strikethrough to other elements.

For HTML output, you can use CSS to supply the underline or strikethrough formatting. If you set the stylesheet parameter to 1, then the value of a role attribute on an emphasis element will be passed through as a class attribute in the HTML output. You can add the following two lines to your cascading stylesheet:

span.underline {text-decoration: underline;}
span.strikethrough {text-decoration: line-through;}

These CSS selectors use the output element name and class name to apply the CSS text-decoration property to the text.