Leaders and Rules

Leaders and Rules
A rule is a block-level horizontal line inserted into text similar to the line below the chapter title on the first page of this chapter. The HR element in HTML produces a rule. A leader is a line that extends from the right side of left-aligned text in the middle of a line to the left side of some right-aligned text on the same line.
It’s most commonly made up of dots, although other characters can be used. Leaders are commonly seen in menus and tables of contents. In fact, if you flip back to the table of contents at the beginning of this book, you’ll see leaders between chapter and section titles and the page numbers.
In XSL-FO both leaders and rules are produced by the fo:leader element. This is an inline element that represents a leader, although it can easily serve as a rule by placing it inside a fo:block.
Six attributes describe the appearance of a leader:
Leader-alignment: This can be set to reference-area or page to indicate that the start edge of the leader should be aligned with the start edge of the named item. It can also be set to none or inherit.
 Leader-length: The length of the leader, such as 12pc or 5in.
leader-pattern: This can be set to space, rule, dots, use-content, or inherit. The use-content value means that the leader characters should be read from the content of the fo:leader element.
leader-pattern-width: This property can be set to a specific length such as 2mm or to use-font-metrics, which indicates that the leader should simply be as big as it would naturally be. This is not the length of the entire leader (which is set by leader-length); it is the length of each repeating pattern in the leader. If necessary, white space will be added to stretch each pattern out to the requested length.
rule-style: This property has the same values as the CSS border-style properties; that is, none, dotted, dashed, solid, double, groove, ridge, and inherit.
rule-thickness: This property is the thickness (width) of the rule; 1pt by default.
In addition, a number of other common properties apply to leaders. For instance, you can use the font-family property to change the font in which a leader is drawn or the color property to change the color in which a leader is drawn.
For example, this is a green horizontal line that’s 7.5 inches long and 2 points thick:
<fo:block> <fo:leader leader-length=”7.5in” leader-pattern=”rule” rule-thickness=”2pt” color=”green”/> </fo:block>
Listing 19-6 uses fo:leader to place a rule at the top of each page footer.
Using fo:leader to separate the footer from the body with a horizontal line
<?xml version="1.0"?>

<xsl:stylesheet version="1.0"



  <xsl:template match="/">

    <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">


        <fo:simple-page-master master-name="A4"

           page-width="297mm"  page-height="210mm"

           margin-top="0.5in"  margin-bottom="0.5in"

           margin-left="0.5in" margin-right="0.5in">

          <fo:region-before extent="1.0in"/>

          <fo:region-body margin-top="1.0in"


          <fo:region-after  extent="1.0in"/>



      <fo:page-sequence master-reference`="A4"

        initial-page-number="1" language="en" country="us">

        <fo:static-content flow-name="xsl-region-before">

          <fo:block>The Periodic Table</fo:block>


        <fo:static-content flow-name="xsl-region-after">

          <fo:block><fo:leader leader-pattern="rule"

                               leader-length="18cm" />


          <fo:block>p. <fo:page-number/></fo:block>


        <fo:flow flow-name="xsl-region-body">

          <xsl:apply-templates select="//ATOM"/>





  <xsl:template match="ATOM">

    <fo:block><xsl:value-of select="NAME"/></fo:block>



Scroll to Top