[Previous] [Contents] [Next]


Content Formatting Objects


The following are some of the more common content formatting objects:

queue-A queue flow object isn't really a formatting object at all, but a container for other formatting so that they can be assigned to a specific area on the page (or screen).
A queue can only be a child of a page-sequence. It has a queue-name attribute with a value that is title, header, body, footer, start-side, or end-side. The body is where the main content of the XML document goes. Figure 20.2 shows the arrangement of the six queue areas on a page. Note that the title queue area only applies to scrollable (screen display) media.
Figure 20.2 The six queue areas used for constructing a page with XSL.
sequence-A sequence formatting object is used to group formatting objects that share an inherited set of properties. The following code fragment renders all the elements enclosed in an em element in italic:
         <xsl:template match="em">
           <fo:sequence font-style="italic">
          <xsl:apply-templates/>
           </fo:sequence>
         </xsl:template>
block-A block formatting object simply puts a line break both before and after the block (like a paragraph). The opposite of a block formatting object is an inline formatting object. For example, Listing 20.6 shows the template for a block formatting object and Figure 20.3 shows the result when applied to two p elements.
Note that in Listings 20.6 through 20.9, when describing the XSL code I use xsl:apply-templates, but in the practical examples I use xsl:process-children because the newer xsl:apply-templates element is not yet supported by many packages.



Listing 20.6 A Block Formatting Object Template
1:  <xsl:template match="p">
2:    <fo:block
3:      indent-start="1.5in"
4:      indent-end="1.5in"
5:      space-before-optimum="6pt"
6:      space-after-optimum="6pt">
7:      <xsl:process-children/>
8:    </fo:block>
9:  </xsl:template>


Figure 20.3 A rendered block formatting object.
inline-box-Acts as an inline container so that you can highlight text or graphics, produce borders and backgrounds, or just control the spacing surrounding an element or piece of text. For example, Listing 20.7 shows the template for an inline-box formatting object and Figure 20.4 shows the result when applied to a p element.
Listing 20.7 An Inline-Box Formatting Object Template
1:  <xsl:template match="em">
2:    <fo:inline-box
3:      background-color='yellow'
4:      graphic-line-thickness='0pt'>
5:      <xsl:process-children/>
6:    </fo:inline-box>
7:  </xsl:template>


Figure 20.4 The rendered inline-box formatting object.
list-A list formatting object acts as a container for the list-item, list-item-label, and list-item-body formatting objects. If you want to nest lists, the second list must be a child of the list-item-body formatting object.
rule-graphic-A rule-graphic formatting object corresponds to the HR (horizontal rule) element in HTML, but it can either be an inline or a block formatting object. For example, Listing 20.8 shows the template for a block formatting object and Figure 20.5 shows how the horizontal line is rendered.
Listing 20.8 A Rule-Graphic Formatting Object Template
1:  <xsl:template match="hr">
2:    <fo:rule-graphic
3:      space-before-optimum="12pt"
4:      space-after-optimum="12pt"
5:      graphic-line-thickness='3pt'>
6:      <xsl:process-children/>
7:    </fo:rule-graphic>
8:  </xsl:template>

graphic-A graphic formatting object corresponds to the IMG element in HTML but it can be either an inline or a block formatting object. For example:
           <xsl:template match="display-graphic">
         <fo:graphic
            graphic-max-width="2in"
            graphic-max-height="2in"/>

        </xsl:template>

Figure 20.5 The rendered rule-graphic formatting object.
score-A score flow object is a formatting object that can take text decoration, such as underlines, strikethroughs, overbars, and so on. A score is an inline formatting object.
block-level-box-A box provides borders, margins, and backgrounds and provides spacing between the border of a box and its content. A box can be an inline or block formatting object. For example, Listing 20.9 shows the template for a block formatting object and Figure 20.6 shows the result when applied to two p elements.
Listing 20.9 A Block-Level-Box Formatting Object Template
1:  <xsl:template match="p">
2:    <fo:block-level-box
3:      indent-start="1in"
4:      indent-end="1in"
5:      background-color='blue'
6:      graphic-line-thickness='3pt'>
7:      <xsl:process-children/>
8:    </fo:block-level-box>
9:  </xsl:template>


Figure 20.6 The rendered block-level-box formatting object.
page-number-A page-number formatting object is used to instruct the rendering engine to construct and display a page-number.
link-A link creates an area in which you can put link-end-locator flow objects.
link-end-locator-Link-end-locator flow objects provide information about the destination of a link (this is equivalent to HREF= "[URI]" in HTML).
character-Allows you to treat a single character as a flow object. Each formatting object may take certain style properties.

[Previous] [Contents] [Next]