XSL-FO Examples


Table of Contents

Introduction

Introduction

This section contains content relating to my XSL-FO book. Initially it is only the examples extracted from the book.

Example 2-1. A basic page specification

<?xml version="1.0" encoding="utf-8"?>
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
<fo:layout-master-set>
      <fo:simple-page-master 
      page-height="11in" 
      page-width="8.5in"
   master-name="only">
         <fo:region-body 
   region-name="xsl-region-body"  
            margin="0.7in" />
   <fo:region-before
            region-name="xsl-region-before" 
            extent="0.7in" />
         <fo:region-after 
   region-name="xsl-region-after"
           extent="0.7in" />
      </fo:simple-page-master>
   </fo:layout-master-set>

<fo:page-sequence master-reference="only" format="A">
      <fo:flow flow-name="xsl-region-body">
      <fo:block >Some base content, containing an inline warning, 
           <fo:inline >Warning: </fo:inline>Do not touch blue paper,
           a fairly straightforward piece requiring emphasis
          <fo:inline font-weight="bold">TEXT</fo:inline>, and 
           some instructions which  require presenting in a different 
           way, such as <fo:inline font-style="italic">Now light 
           the blue paper</fo:inline>.
         </fo:block>
      </fo:flow>
   </fo:page-sequence>
</fo:root>

Example 2-2. Minimal test file

<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
  <fo:layout-master-set>
      <fo:simple-page-master master-name="only">
         <fo:region-body 
                      region-name="xsl-region-body"
                         margin="0.7in"  padding="6pt" />
         <fo:region-before 
                           region-name="xsl-region-before" 
                           extent="0.7in"  />
         <fo:region-after 
                          region-name="xsl-region-after" 
                          extent="0.7in" />
      </fo:simple-page-master>
    </fo:layout-master-set>
    <fo:page-sequence 
                  master-reference="only">

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

           <fo:block>Hello World</fo:block>             
      </fo:flow>
    </fo:page-sequence>
   </fo:root>

Example 2-3. Source XML for the examples

<doc>
<section><head> Simple sectioned title </head>
<para>Some base content, containing an inline warning,
  <emphasis role="warning">Do not touch blue paper</emphasis>,
  a fairly straightforward piece requiring emphasis
  <emphasis>TEXT</emphasis>, and some instructions which
  require presenting in a different way, such as
  <instruction>Now light the blue paper</instruction>.
</para>

</section>

....

</doc>

Example 2-4. Basic stylesheet

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:fo="http://www.w3.org/1999/XSL/Format">

   <xsl:output method="xml"/>
<xsl:template match="/">
    <fo:root>
      <fo:layout-master-set>
      <fo:simple-page-master 
        master-name="only">
        <fo:region-body 
           region-name="xsl-region-body" 
           margin="0.7in" 
            />
        <fo:region-before 
           region-name="xsl-region-before" 
           extent="0.7in" 
            display-align="before" />

          <fo:region-after 
           region-name="xsl-region-after" 
           display-align="after"
           extent="0.7in" 
           />
      </fo:simple-page-master>
      </fo:layout-master-set>


      <fo:page-sequence master-reference="only">
        <fo:flow 
           flow-name="xsl-region-body">
         <xsl:apply-templates />
        </fo:flow>
      </fo:page-sequence>

    </fo:root>
</xsl:template>
</xsl:stylesheet>

Example 2-5. Other templates

<xsl:template match="section">
 <fo:block  id="{generate-id}">
          <xsl:apply-templates/>
    </fo:block>
   </xsl:template>


<xsl:template match="head">
    <fo:block  
      font-family="Times"
      font-size="18pt"
      font-weight="bold"
      space-before="18pt"
      space-after="12pt"
      text-align="center">
          <xsl:apply-templates/>
    </fo:block>
   </xsl:template>

<xsl:template match="para">
    <fo:block  
      font-family="Times"
      font-size="12pt"
      space-before="12pt"
      space-after="12pt"
      text-align="justify">
          <xsl:apply-templates/>
    </fo:block>
   </xsl:template>

<xsl:template match="emphasis[@role='warning']">
      <fo:inline 
           color="red">Warning: </fo:inline>
          <xsl:apply-templates/>
   </xsl:template>

Example 2-6. Out-of-line processing for a table of contents

<xsl:template match="/">
 <fo:root>
   <fo:page-sequence master-reference="only">
       <fo:flow flow-name="xsl-region-body">
       <!-- Produce the frontmatter here -->
         <xsl:call-template name="toc"/>
     <xsl:apply-templates />
       </fo:flow>
     </fo:page-sequence>

 </fo:root>
</xsl:template>

<xsl:template name="toc">
 <xsl:for-each select="section">
     <fo:block text-align-last="justify"><xsl:value-of 
      select="head"/> <fo:leader 
         leader-pattern="dots"/> <fo:page-number-citation ref-id="{@id}"/>
   <xsl:for-each select="section">
      <fo:block text-indent="2em" text-align-last="justify"> <xsl:value-of 
       select="head"/> <fo:leader 
           leader-pattern="dots"/> <fo:page-number-citation ref-id="{@id}" />
      </fo:block>
     </xsl:for-each>
    </fo:block>
  </xsl:for-each>
</xsl:template>

Example 3-1. Region example

<fo:simple-page-master 
    master-name="simple"
    page-height="29.7cm" 
    page-width="21cm"
    margin-top="1cm"
    margin-bottom="2cm"
    margin-left="2.5cm"
    margin-right="2.5cm">
    <fo:region-body 
         margin-top="1cm"/>
    <fo:region-before 
         extent="3cm"/>
    <fo:region-after 
         extent="1.5cm"/>
    <fo:region-start 
         extent="2cm"/>
    <fo:region-end 
         extent="2cm"/>
</fo:simple-page-master>

Example 3-2. Correct region names

<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
<fo:layout-master-set>
<fo:simple-page-master
         master-name="odd"
         page-height="11in"
         page-width="8.5in"
         margin-top="1in"
         margin-bottom="1in"
         margin-left="1.25in"
         margin-right="0.75in">

     <fo:region-body
         region-name="xsl-region-body"
         margin-top="0.6in"
         margin-bottom="0.6in"
         margin-left="0.6in"
         margin-right="0.6in"/>

     <fo:region-before
       precedence="true"
       border="thin black solid"
       region-name="xsl-region-before"
       extent="0.5in"/>

     <fo:region-after
       border="thin black solid"
       region-name="xsl-region-after"
       extent="0.5in"
       precedence="true"/>

     <fo:region-start
       region-name="xsl-region-start"
       border="thin black solid"
       extent="0.5in"/>

     <fo:region-end
       border="thin black solid"
       region-name="xsl-region-end"
       extent="0.5in"/>

</fo:simple-page-master>

</fo:layout-master-set>

  <fo:page-sequence master-reference="odd" format="A">
     <fo:static-content
       flow-name="xsl-region-start">
       <fo:block> <fo:page-number/>
        <fo:block>Ch 1 </fo:block>
       </fo:block>
     </fo:static-content>

     <fo:static-content
       flow-name="xsl-region-end">
       <fo:block>Page <fo:page-number/>

       </fo:block>
     </fo:static-content>

     <fo:static-content flow-name="xsl-region-before" >
       <fo:block display-align="before">Part 1

       </fo:block>
     </fo:static-content>

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

       <fo:block
        text-align="center">Page <fo:page-number/>
             </fo:block>
     </fo:static-content>

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

      <fo:block>

The quick brown fox jumps over the lazy dog.
(fill out with further content to show the full page)

      </fo:block>


     </fo:flow>
</fo:page-sequence>

</fo:root>

Example 3-3. A Hello World example

<?xml version="1.0" encoding="utf-8"?>

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

  <fo:layout-master-set>

              <fo:simple-page-master 
               master-name="simple"
                  page-height="29.7cm"
                  page-width="21cm"
                  margin-left="2.5cm"
                  margin-right="2.5cm">
      <fo:region-body margin-top="3cm"/>
    </fo:simple-page-master>

  </fo:layout-master-set>

  <fo:page-sequence 
          master-reference="simple">

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

      <fo:block>Hello, World</fo:block>

    </fo:flow>
  </fo:page-sequence>
</fo:root>

Example 3-4. A single-page-master-reference

<fo:root>
<fo:layout-master-set>
<fo:simple-page-master 
        master-name="single"
        page-height="11in" 
        page-width="8.5in"
        margin-top="1in" 
        margin-bottom="1in"
        margin-left="0.5in" 
        margin-right="0.5in">
    <fo:region-body
        margin-top="0.5in" 
        margin-bottom="0.5in"/>
</fo:simple-page-master>
<fo:page-sequence-master 
       master-name="single-page">
    <fo:single-page-master-reference
        master-name="single"/>
</fo:page-sequence-master>
</fo:layout-master-set>

<fo:page-sequence 
     master-reference="single-page">
    ... CONTENT ...
</fo:page-sequence>
</fo:root>

Example 3-5. A repeatable-page-master-reference

<fo:root>
<fo:layout-master-set>
<fo:simple-page-master 
        master-name="many"
        page-height="11in" 
        page-width="8.5in"
        margin-top="1in" 
        margin-bottom="1in"
        margin-left="0.5in" 
        margin-right="0.5in">
    <fo:region-body
        margin-top="0.5in" 
        margin-bottom="0.5in"/>
</fo:simple-page-master>
<fo:page-sequence-master 
       master-name="many-pages">
    <fo:repeatable-page-master
        maximum-repeats="10"/>
</fo:page-sequence-master>
</fo:layout-master-set>

<fo:page-sequence 
    master-reference="many-pages">
    ... CONTENT ...
</fo:page-sequence>
</fo:root>

Example 3-6. Conditional page selection

<?xml version="1.0" encoding="utf-8"?>

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

    <fo:layout-master-set>

        <!-- layout for the first page -->
        <fo:simple-page-master 
            master-name="first"
            page-height="29.7cm"  
            page-width="21.0cm"
            margin-top="2cm" 
            margin-bottom="2cm"
            margin-left="2.5cm" margin-right="2.5cm">
                        <fo:region-body
                            margin-top="10cm" 
                            margin-bottom="2cm"/>
                        <fo:region-after
                            region-name="non-blank-after"
                            extent="2cm"/>
        </fo:simple-page-master>
        
        <!-- layout for odd pages -->
        <fo:simple-page-master 
            master-name="odd"
            page-height="29.7cm" 
            page-width="21.0cm"
            margin-top="2cm" 
            margin-bottom="2cm"
            margin-left="3.5cm" 
            margin-right="1.5cm">
                        <fo:region-body
                            margin-top="2cm" 
                            margin-bottom="2cm"/>
                        <fo:region-before
                            region-name="odd-before"
                            extent="2cm"/>
                        <fo:region-after
                            region-name="non-blank-after"
                            extent="2cm"/>
        </fo:simple-page-master>

        <!-- layout for even pages -->
        <fo:simple-page-master 
            master-name="even"
            page-height="29.7cm" 
            page-width="21.0cm"
            margin-top="2cm" 
            margin-bottom="2cm"
                margin-left="1.5cm" 
                margin-right="3.5cm">
                        <fo:region-body
                            margin-top="2cm" 
                            margin-bottom="2cm"/>
                        <fo:region-before
                            region-name="even-before"
                            extent="2cm"/>
                        <fo:region-after
                            region-name="non-blank-after"
                            extent="2cm"/>
        </fo:simple-page-master>
        
        <!-- layout for odd last page, blank or not-blank -->
      <!-- Note that this is redundant in the example -->

        <!-- layout for even last page, blank or not-blank -->
        <fo:simple-page-master master-name="last_even"
            page-height="29.7cm" 
            page-width="21.0cm"
            margin-top="2cm" 
            margin-bottom="2cm"
            margin-left="1.5cm" 
            margin-right="3.5cm">
                        <fo:region-body
                            margin-top="2cm" 
                            margin-bottom="2cm"/>
                        <fo:region-before
                            region-name="even-last-before"
                            extent="2cm"/>
                        <fo:region-after
                            region-name="last-after"
                            extent="2cm"/>
        </fo:simple-page-master>

        <!-- layout for blank pages (non-last) -->
        <fo:simple-page-master 
           master-name="blank"
            page-height="29.7cm" 
            page-width="21.0cm"
            margin-top="2cm" 
            margin-bottom="2cm"
                margin-left="2.5cm" 
                margin-right="2.5cm">
                        <fo:region-body
                            margin-top="2cm" 
                            margin-bottom="2cm"/>
                        <fo:region-before
                            region-name="blank-before"
                            extent="2cm"/>
                        <fo:region-after
                            region-name="blank-after"
                            extent="2cm"/>
        </fo:simple-page-master>

                <fo:page-sequence-master 
                    master-name="chapter">
                        <fo:repeatable-page-master-alternatives>
                                <fo:conditional-page-master-reference
                                        master-reference="odd"
                                        page-position="rest"
                                        odd-or-even="odd" />
                                <fo:conditional-page-master-reference
                                        master-reference="even"
                                        page-position="rest"
                                        odd-or-even="even" />
                                <fo:conditional-page-master-reference
                                        master-reference="first"
                                        page-position="first" />
                                <fo:conditional-page-master-reference
                                        master-reference="last_even"
                                        odd-or-even="even"
                                        page-position="last" />
                                
                                <fo:conditional-page-master-reference
                                        master-reference="blank"
                                        blank-or-not-blank="blank" />
                        </fo:repeatable-page-master-alternatives>
                </fo:page-sequence-master>
        </fo:layout-master-set>
        <!-- end: defines page layout -->

        <!-- actual layout -->
        <fo:page-sequence 
         master-reference="chapter" 
         force-page-count="even"
         initial-page-label="1">

        <fo:static-content 
             flow-name="non-blank-after">
            <fo:block> <fo:page-number/> 
   <!-- content for non-blank page footers --></fo:block>
        </fo:static-content>
        
        <fo:static-content 
            flow-name="blank-before">
            <fo:block> <fo:page-number/> 
               <!-- content for blank page headers -->
            </fo:block>     
        </fo:static-content>
        
        <fo:static-content 
            flow-name="blank-after">
            <fo:block> <fo:page-number/> 
                 <!-- content for blank page footers -->
            </fo:block>      
        </fo:static-content>
        
        <fo:static-content flow-name="odd-before">
            <fo:block> <fo:page-number/> 
               <!-- content for odd page headers -->
            </fo:block>      
        </fo:static-content>
        
        <fo:static-content flow-name="even-before">
            <fo:block> <fo:page-number/> 
           <!-- content for even page headers -->
            </fo:block>    
        </fo:static-content>
        
     
        
        <fo:static-content flow-name="even-last-before">
            <fo:block> <fo:page-number/> 
             <!-- content for even last page headers -->
            </fo:block>
        </fo:static-content>
        
        <fo:static-content flow-name="last-after">
            <fo:block> <fo:page-number/> 
              content for last page footers --- >
            </fo:block>   </fo:static-content>
        <fo:flow flow-name="xsl-region-body">

            <fo:block> 
              Insert sufficient content for 35 pages to complete 
              this example
            </fo:block>
            <fo:block break-before="page"/>
        </fo:flow>
    </fo:page-sequence>
<fo:page-sequence 
         master-reference="chapter" 
         force-page-count="even"
            initial-page-label="39">

        <fo:static-content 
            flow-name="non-blank-after">
            <fo:block> <fo:page-number/> 
             content for non-blank page footers --- >
            </fo:block>
        </fo:static-content>
        
        <fo:static-content flow-name="blank-before">
            <fo:block> <fo:page-number/> 
            content for blank page headers --- >
            </fo:block>     
        </fo:static-content>
        
        <fo:static-content flow-name="blank-after">
            <fo:block> <fo:page-number/> 
            content for blank page footers --- >
            </fo:block>      
        </fo:static-content>
        
        <fo:static-content 
           flow-name="odd-before">
            <fo:block> <fo:page-number/> 
             content for odd page headers --- >
            </fo:block>      
        </fo:static-content>
        
        <fo:static-content flow-name="even-before">
            <fo:block> <fo:page-number/> 
            content for even page headers --- >
            </fo:block>    
        </fo:static-content>
        
      
        
        <fo:static-content flow-name="even-last-before">
            <fo:block> <fo:page-number/> 
             content for even last page headers --- >
            </fo:block>
        </fo:static-content>
        
        <fo:static-content flow-name="last-after">
            <fo:block> <fo:page-number/> 
             content for last page footers --- >
            </fo:block>   
        </fo:static-content>
        
        <fo:flow flow-name="xsl-region-body">

            <fo:block> Insert sufficient content for some 
             more  pages to complete this example
            </fo:block>
            
        </fo:flow>
    </fo:page-sequence>
</fo:root>

Example 3-7. Forced page numbering

<fo:page-sequence 
 master-reference="chapter" 
 initial-page-label="51"
...

Example 4-1. Space resolution

<fo:block space-after.minimum="3pt">
            space-after.maximum="24pt"
             space-after.optimum="12pt">
  .....

</fo:block>
<fo:block space-before.minimum="6pt"
             space-before.maximum="18pt"
             space-before.optimum="12pt">
....
</fo:block>

Example 5-1. A simple block

<xsl:template match="para">
    <fo:block  
      border-style="solid" 
      border-width=".1mm"
      font-family="Times"
      font-size="12pt"
      space-before="12pt"
      space-after="12pt"
      text-align="justify">
          <xsl:apply-templates/>
    </fo:block>
  </xsl:template>

Example 5-2. Indentation

<xsl:template match="quote">
    <fo:block  
      start-indent="6em"
      end-indent="6em"
      font-family="Times"
      font-size="12pt"
      space-before="12pt"
      space-after="12pt"
      text-align="start">
          "<xsl:apply-templates/>"
    </fo:block>
  </xsl:template>

Example 5-3. First line indentation

<xsl:template match="para">
   <fo:block  
     space-before="12pt"
     space-after="12pt"
     text-indent="3em"
     text-align="justify">
         <xsl:apply-templates/>
   </fo:block>
 </xsl:template>

Example 5-4. Hanging indents

  <fo:block 
        text-indent='-4em'
        start-indent='4em'>

An example of a hanging indent, a paragraph with the first
line left aligned, and the remainder of the paragraph
indented by a fixed amount. Set by using the start indent
and text-indent properties on a block. The text-indent is
set to a negative value, the start indent to a positive
value.

</fo:block>

Example 5-5. XML source for block as a break

<para>This paragraph includes a quotation 
<quote>The fair breeze blew, the white foam flew <nl/>
The furrow followed free; <nl/>
We were the first that ever burst<nl/>
Into that silent sea. </quote>
<author>Samuel Taylor Coleridge</author>
And continues after it. </para>

Example 5-6. The template

 <xsl:template match="nl">
    <fo:block />
  </xsl:template>

Example 5-7. Possible line treatment

<xsl:template match="nl">
   <fo:character character = '&#x2028' />
 </xsl:template>

Example 5-8. Retaining space

<fo:block
 space-before="2in"
 space-before.conditionality = 'retain'>
...

Example 5-9. Inter-paragraph spacing

<fo:block  space-after="12pt"
border-style="solid" 
border-width=".1mm"

>
This is the first of three blocks .</fo:block>

 <fo:block 
border-style="solid" 
border-width=".1mm"
 space-after="12pt">
This block has the space-after set to 12pt, 
so there will be an interaction.</fo:block>


<fo:block 
border-style="solid" 
border-width=".1mm"
   space-before="18pt"  
   space-before.precedence="5">
This block really must have the 
larger (18pt) space before .</fo:block>

Example 5-10. Wrapper blocks to offset content from the main flow

<fo:block 
     border-style="solid" 
     border-width="2mm">
    <fo:block start-indent="4em"
          space-before="2em"
          space-after="1em"
          end-indent="4em">First contained block
    </fo:block>
    <fo:block start-indent="4em"
          space-after="2em"
          end-indent="4em">Second contained block. 
          The significant border together with the indents 
          offsets the content, 
          seperating it visually from the main flow.
    </fo:block>
</fo:block>

Example 5-11. A stylesheet snippet showing styling for a signature

<xsl:template match="signature">
<fo:block-container absolute-position="fixed"
                    top="240mm" left="100mm">
<fo:block xsl:use-attribute-sets="para">
  Yours Sincerely: <xsl:apply-templates/>
</fo:block>
</fo:block-container>
</xsl:template>

Example 5-12. A title page specification

<fo:block  
        break-before="page" 
        break-after="page"
          space-after="4in" 
          space-before="3in" 
          space-before.conditionality="retain" 
          font="24pt Times bold" 
          text-align="center">
  Document Title, using single or multiple lines.
</fo:block>

Example 5-13. External graphics

<fo:block> <fo:external-graphic src='url(pig.jpg)'/> </fo:block>
   <fo:block>
     <fo:external-graphic 
        src="url(pig.jpg)"/>
   </fo:block>
   <fo:block>A block containing the graphic wrapped in 
             an inline container,
     <fo:inline alignment-baseline="before-edge">
       <fo:external-graphic 
                            src="url(images/1.png)"/>
     </fo:inline>
   </fo:block>

Example 5-14. Titled images

<fo:block>
       <fo:block>Title for the figure</fo:block>
       <fo:external-graphic  src="url(images/filename.ext)"/>
</fo:block>

Example 5-15. A cross-reference target

<xsl:template match="chapter">
<fo:block id="{@id}">
  .....process content
</fo:block>
</xsl:template>

Example 5-16. Basic version of border specification

<xsl:attribute-set name='border'>
<xsl:attribute name='border-before-style'>solid</xsl:attribute>
<xsl:attribute name='border-after-style'>solid</xsl:attribute>
<xsl:attribute name='border-start-style'>solid</xsl:attribute>
<xsl:attribute name='border-end-style'>solid</xsl:attribute>

<xsl:attribute name='border-before-width'>.1mm</xsl:attribute>
<xsl:attribute name='border-after-width'>.1mm</xsl:attribute>
<xsl:attribute name='border-start-width'>.1mm</xsl:attribute>
<xsl:attribute name='border-end-width'>.1mm</xsl:attribute>
</xsl:attribute-set>

Example 5-17. Using a simple border

<fo:block  
       border-style="solid" 
       border-width=".1mm"
       
       width="2in">
     A simple narrow  border
   </fo:block>

Example 5-18. A more complete border example

<fo:block 
             border-after-color="red" 
             border-after-style="outset" 
             border-after-width="1em" 

             border-before-color="blue" 
             border-before-style="outset" 
             border-before-width="1.5em" 

             border-end-color="silver" 
             border-end-style="outset" 
             border-end-width="2em" 

             border-start-color="green" 
             border-start-style="outset" 
             border-start-width="2em" 

             padding="6pt" 
             width="4in">
     A paragraph with a completely specified border.
     Style is shared as 'outset', 
     color varies on each edge, 
     as does width.
   </fo:block>

Example 5-19. Specifying padding on a block

<fo:block space-before="18pt">A simple block with no
  padding. Note the proximity of the content to the page
  edge (the containing area). This may be too
  close when large blocks of text are used. </fo:block>

<fo:block border ="thin black solid" padding-end="6pt"
  padding-start="6pt" text-align="justify">A simple block
  with padding specified as 6pt. Note the proximity of the
  content to the border (the containing area). This may be
  better when large blocks of text are used. A simple block
  with padding specified as 6pt. Note the proximity of the
  content to the border (the containing area). This may be
  better when large blocks of text are used.
  </fo:block>

Example 5-20. Basic list syntax

<fo:list-block>
 <fo:list-item>
  <fo:list-item-label>
   <fo:block>&#x2022;</fo:block>
  </fo:list-item-label>
  <fo:list-item-body>
   <fo:block>List item contents.</fo:block>
  </fo:list-item-body>
 </fo:list-item>
</fo:list-block>

Example 5-21. A simple nested list

<fo:list-block 
 start-indent="5mm" 
 provisional-distance-between-starts="10mm">
  <fo:list-item>
   <fo:list-item-label end-indent="label-end(  )">
    <fo:block>&#x2022;</fo:block>
   </fo:list-item-label>
   <fo:list-item-body start-indent="body-start(  )">
      <fo:block>List item contents.</fo:block>

     <fo:list-block>                    
         <fo:list-item>
          <fo:list-item-label 
            end-indent="label-end(  )">
            <fo:block font-family="ZapfDingbats">&#x2798;
            </fo:block>
              </fo:list-item-label>
              <fo:list-item-body 
                start-indent="body-start(  )">
                <fo:block>List item contents of nested list.
                </fo:block>
              </fo:list-item-body>
            </fo:list-item>
        </fo:list-block>          

        </fo:list-item-body>
      </fo:list-item>
    </fo:list-block>

Example 5-22. Varying the label length specification

 <fo:list-block 
   start-indent="5mm" 
   provisional-distance-between-starts="40mm">
  <fo:list-item space-after="1em">
   <fo:list-item-label >
    <fo:block 
   font-weight="bold">A long label which wraps.</fo:block>
  </fo:list-item-label>
  <fo:list-item-body start-indent="body-start(  )" end-indent="5mm"> 
    <fo:block>List item contents. Note the text flow which takes 
        place when sufficient text is placed to ensure wrapping. 
        Note the text flow which takes place when sufficient text 
        is placed to ensure wrapping.</fo:block>
  </fo:list-item-body>
</fo:list-item>
<fo:list-item>
  <fo:list-item-label >
    <fo:block font-weight="bold">
      Another long label which wraps.</fo:block>
 </fo:list-item-label>
  <fo:list-item-body start-indent="body-start(  )">
    <fo:block>Second content. </fo:block>
  </fo:list-item-body>
</fo:list-item>
</fo:list-block>

Example 5-23. The simplest of table models

<table>
    <tbody>
      <row><td>R1C1</td><td>R1C2</td><td>R1C3</td></row>
      <row><td>R2C1</td><td>R2C2</td><td>R2C3</td></row>
    </tbody>
  </table>

Example 5-24. Stylesheet snippet

 <xsl:template match="table">
    <fo:table width="3in">
      <xsl:apply-templates/>
    </fo:table>
  </xsl:template>
 <xsl:template match="tbody">
   <fo:table-body>
     <xsl:apply-templates/>
   </fo:table-body>
 </xsl:template>

  <xsl:template match="row">
    <fo:table-row>
      <xsl:apply-templates/>
    </fo:table-row>
  </xsl:template>
 <xsl:template match="td">
    <fo:table-cell border="solid 1px black">
      <fo:block><xsl:apply-templates/></fo:block>
    </fo:table-cell>
  </xsl:template>

Example 5-25. Proportional-width columns

<table-column column-width="proportional-column-width(1)"/>
  <table-column column-width="proportional-column-width(3)"/>
  <table-column column-width="proportional-column-width(1)"/>

Example 5-26. Fixed columns, variable width

<fo:table>
          <fo:table-column column-label="1" column-width="20%"/>
          <fo:table-column column-label="2" column-width="60%"/>
          <fo:table-column column-label="3" column-width="20%"/>
          ... Remainder of table specification.

Example 5-27. Fixed columns, constant width

<fo:table>
          <fo:table-column 
            column-label="1" 
            column-width="33%"
            number-columns-repeated="3"/>
         
          ... Remainder of table specification.

Example 5-28. Row and column spanning

<fo:table-row>
    <fo:table-cell border="solid black 1px" 
                   border-collapse="collapse" 
                   number-columns-spanned="2">
     <fo:block>R2C1</fo:block>
    </fo:table-cell>
 <!-- R2C2 omitted-->

.... and for row 4,

<fo:table-row>
    <fo:table-cell 
                   border="solid black 1px" 
                   border-collapse="collapse" 
                   number-rows-spanned="2">
     <fo:block>R4C1</fo:block>
    </fo:table-cell>
... and for row 5
<fo:table-row>
 <!-- R5C1 omitted  -->

Example 5-29. Cell alignment

<fo:table-cell border="solid black 1px" 
                    display-align="center" 
                    border-collapse="collapse" 
                    text-align="center">
       <fo:block font-weight="bold">XXX</fo:block>
      </fo:table-cell>

Example 5-30. Full form

space-before.minimum="4.0pt"
space-before.optimum="4.0pt"
space-before.maximum="4.0pt"
space-before.precedence="0"
space-before.conditionality="discard"

Example 6-1. Inline example, XML source

<para>Some base content, containing an inline warning,
  <emphasis role="warning">Do not touch blue paper</emphasis>,
  a fairly straightforward piece requiring emphasis
  <emphasis>TEXT</emphasis>, and some instructions which
  require presenting in a different way, such as
  <instruction>Now light the blue paper</instruction>.
</para>

Example 6-2. Inline example, stylesheet snippet

  <xsl:template match="para">
<fo:block>  
      <xsl:apply-templates/>
   </fo:block>
  </xsl:template>

    <xsl:template match="emphasis[@role='warning']">
<fo:inline background-color="red">Warning:</fo:inline>  
      <xsl:apply-templates/>
    </xsl:template>

    <xsl:template match="emphasis[not(@role) or @role='']">
<fo:inline font-weight="bold">
      <xsl:apply-templates/></fo:inline>
    </xsl:template>


    <xsl:template match="instruction">
<fo:inline font-style="italic">
      <xsl:apply-templates/>
   </fo:inline>
  </xsl:template>

Example 6-3. Text decoration

<fo:block text-decoration="underline">Underline on for all 
   but one <fo:inline text-decoration="no-underline">word</fo:inline> 
   of the sentence.
</fo:block>

Example 6-4. Text shadow effect

<fo:block>
          <fo:inline 
             text-shadow="red 1mm 1mm">
          Text with a red shadow down and to the right by 1mm
          .</fo:inline>
</fo:block>

Example 6-5. The use of fo:inline-container

<fo:block>
  <fo:inline-container writing-mode="rl-tb">
    <fo:block>
     Some text with writing mode st to rl-tb.</fo:block>
  </fo:inline-container>

</fo:block>

Example 6-6. An inline graphic

<fo:inline id="ls1">The main
      <fo:external-graphic src="url(images/image.png)"/> is ....
</fo:inline>

Example 6-7. Scaled graphic

<fo:external graphic
content-height="1em"
content-width="1em" 
src="url(images/image.png)"
/>

Example 6-8. Letter spacing

<fo:inline
 letter-spacing="2mm">This is text with 2mm letter-spacing,</fo:inline>
<fo:inline word-spacing="1cm">  this has 1cm word spacing.</fo:inline>

Example 6-9. Leaders for lines

     <fo:block>        
  <fo:leader 
    leader-length="100%" 
    leader-pattern="rule" 
    rule-style="solid"  
    rule-thickness="0.1mm"  color="black"/>
     </fo:block>

Example 6-10. Leader pattern example

<fo:leader  leader-pattern="use-content" leader-length="60%">o</fo:leader>

Example 6-11. Table of contents usage

<fo:block 
 text-align-last="justify">Chapter 10 
   <fo:leader leader-pattern="dots" />Page 25</fo:block>

Example 6-12. ID generation

<xsl:template match="p">
    <fo:block>
      <xsl:call-template name="gen-id">
        <xsl:with-param name="id-val" select="@id"/>
      </xsl:call-template>
      <xsl:apply-templates/>
    </fo:block>
  </xsl:template>

 <xsl:template name="gen-id">
    <xsl:param name="id-val" select="@id"/>
    <xsl:if test="$id-val">
      <xsl:attribute name="id"><xsl:value-of 
         select="$id-val"/></xsl:attribute>
    </xsl:if>
  </xsl:template>

Example 6-13. Cross-reference generation

<section id="sect1">
   <head>Introduction</head>
   <p>A plain paragraph</p>

   <p id="referenced-para">A paragraph which is referenced,
   hence has the id value.</p>

Example 6-14. Source XML example

<p>See  <link target="sect1"/> 
on page <pgref target="referenced-para"/>.</p>

Example 6-15. Link usage

<xsl:template match='section'>
<fo:block id='{@id}'>
  <xsl:apply-templates/>
</fo:block>
</xsl:template>

<xsl:template match='para'>
  <fo:block id='{generate-id(  )}'>
   <xsl:apply-templates/>
  </fo:block>
</xsl:template>

 <xsl:template match="link">
    <xsl:value-of select="id(@target)/head"/>
  </xsl:template>

 <xsl:template match="pgref">
   <fo:page-number-citation ref-id="{@target}"/>
  </xsl:template>

Example 6-16. Leaders for lists

<fo:inline>
  <fo:character 
  character="&#x2022;" font-family="ZapfDingbats"/> <fo:leader 
        leader-pattern="space" 
        leader-length="1.5cm"/> The list item contents</fo:inline>

Example 6-17. Stretchable spaces for three area headers

<fo:block text-align-last="justify">
    <fo:inline> start1 </fo:inline>
    <fo:inline> center </fo:inline>
    <fo:inline> end </fo:inline>
</fo:block>

<fo:block text-align-last="justify">
    <fo:inline letter-spacing="0pt" word-spacing="0pt"> start2 </fo:inline>
    <fo:inline letter-spacing="0pt" word-spacing="0pt"> center </fo:inline>
    <fo:inline letter-spacing="0pt" word-spacing="0pt"> end </fo:inline>
</fo:block>

<fo:block text-align-last="justify">
    <fo:inline> start3 </fo:inline>
    <fo:leader />
    <fo:inline> center </fo:inline>
    <fo:leader />
    <fo:inline> end </fo:inline>
</fo:block>

<fo:block text-align-last="justify">
    <fo:inline> start4 longer </fo:inline>
    <fo:leader />
    <fo:inline> center </fo:inline>
    <fo:leader />
    <fo:inline> end </fo:inline>
</fo:block>



<fo:list-block>
  <fo:list-item>
    <fo:list-item-label>
      <fo:block id="A" text-align="left">start5</fo:block>
    </fo:list-item-label>
    <fo:list-item-body>
      <fo:list-block>
        <fo:list-item>
          <fo:list-item-label>
            <fo:block id="B" text-align="center">Center</fo:block>
          </fo:list-item-label>
          <fo:list-item-body>
            <fo:block id="C" text-align="right">Right</fo:block>
          </fo:list-item-body>
        </fo:list-item>
      </fo:list-block>
    </fo:list-item-body>
  </fo:list-item>
</fo:list-block>

Example 6-18. Header justification

<fo:inline text-align-last="justify">
    Left-hand text          
    <fo:leader leader-pattern="space" />
     Centre Text using inlines          
    <fo:leader leader-pattern="space" />
      Right-hand text
  </fo:inline>

Example 6-19. Lists in headers

<xsl:template name='head1'>
<xsl:param name='header-width'>

<fo:static-content flow-name="xsl-region-before">
    <!-- header-width is the width of the full header in picas -->
    <xsl:variable name="header-width" select="36"/>
    <xsl:variable name="header-field-width">
    <xsl:value-of select="$header-width * 0.3333"/><xsl:text>pc</xsl:text>
    </xsl:variable>
    <fo:list-block font-size="8pt" provisional-label-separation="0pt">
        <xsl:attribute name="provisional-distance-between-starts">
            <xsl:value-of select="$header-field-width"/>
        </xsl:attribute>
        <fo:list-item>
            <fo:list-item-label end-indent="label-end(  )">
                <fo:block text-align="left">
                    <xsl:text>The left header field which is long </xsl:text>
                </fo:block>
            </fo:list-item-label>
            <fo:list-item-body start-indent="body-start(  )">
                <fo:list-block provisional-label-separation="0pt">
                    <xsl:attribute name="provisional-distance-between-starts">
                        <xsl:value-of select="$header-field-width"/>
                    </xsl:attribute>
                    <fo:list-item>
                        <fo:list-item-label end-indent="label-end(  )">
                            <fo:block text-align="center">
                                Page - <fo:page-number/>
                            </fo:block>
                        </fo:list-item-label>
                        <fo:list-item-body start-indent="body-start(  )">
                            <fo:block text-align="right">
                                <xsl:text>short right</xsl:text>
                            </fo:block>
                        </fo:list-item-body>
                    </fo:list-item>
                </fo:list-block>
            </fo:list-item-body>
        </fo:list-item>
    </fo:list-block>
</fo:static-content>
</xsl:template>

Example 7-1. Graphics example

<fo:block>
 <fo:block  >Title for the figure</fo:block>
   <fo:external-graphic  
      src="url(images/pig.jpg)" 
        content-height="300%" 
      scaling="uniform"/>
     </fo:block>

     <fo:block>fo:external-graphic wrapped in a block, and</fo:block>
     <fo:block>a block containing the graphic wrapped in 
               an inline container,
       <fo:inline>
         <fo:external-graphic  src="url(images\1.png)"/>
       </fo:inline>
             with content both before and after the graphic. 
     </fo:block>

Example 7-2. Background and border colors

<fo:block background-color="aqua" 
             border-after-color="red" 
             border-after-width="1.2em" 

             border-before-color="blue" 
             border-before-width="1em" 

             border-end-color="silver" 
             border-end-width="1em" 

             border-start-color="green" 
             border-start-width="1em"
 
             border-style="solid" 
             padding="6pt" 
             start-indent="1in"
             end-indent="2in"

>
     A paragraph with a completely specified border.
     Style is not specified.
     color varies on each edge</fo:block>

Example 7-3. Color and nesting

<fo:block 
     background-color="yellow" color="blue">
     A paragraph with blue text on a yellow border.
     Nested in the text are two inline objects, one of which 
     specifies a different 'color' and 
     one which specifies a different 'background-color' value. 
     Here is the 
     <fo:inline color='green'>green inline</fo:inline>. 
        And here is the
        <fo:inline background-color='white'>white background inline
     </fo:inline>. More text in the block after the inlines.</fo:block>

Example 7-4. Color profile example

<fo:declarations>
<fo:color-profile src="url('./myprofile.icc')" color-profile-name="cp1"/>
</fo:declarations>
 <-- Intervening stuff -->
     <fo:block color='icc-color(200, 200, 50, cp1, 1.45, 2.22)'>
   A block whose text color is defined using the profile named cp1
     </fo:block>

Example 8-1. A color-contrasted character

<fo:character 
      character="&#x067;" 
      font-size="20pt" 
      background-color="skyblue" 
      color="red"/>

Example 8-2. fo:character example

    <fo:character  
  character="&#x067;" />

Example 8-3. treat-as-word-space example

<fo:inline>Words with<fo:character
      character="&#x2001;"
      treat-as-word-space="true"
      />spaces.
</fo:inline>

Example 8-4. Superscript

<fo:character
     character="1" 
     baseline-shift="super"
     font-size="8pt"
     font-family="'MS Serif'"/>

Example 8-5. Character-level superscript

<fo:inline>See note
 <fo:character
      character="1" 
      baseline-shift="super"
      font-family="'MS Serif'"/>
</fo:inline>

Example 8-6. Font example

    <fo:inline
     font-family="Arial, Garamond, serif"/>
    </fo:inline>

Example 8-7. Font style

<fo:inline 
      font-style="normal">This is normal.</fo:inline>
<fo:inline 
      font-style="italic">Italic.</fo:inline>
<fo:inline 
      font-style="oblique">Oblique.</fo:inline>
<fo:inline 
      font-style="backslant">Backslant.</fo:inline>

Example 8-8. Font variant

<fo:inline 
      font-variant="small-caps">A small-caps example</fo:inline>

Example 8-9. Simple font size example

<fo:inline 
      font-size="12pt">Length specification.</fo:inline>

Example 8-10. Relative font changes

<fo:inline 
      font-size="smaller">Relative Specification of font size.</fo:inline>

Example 8-11. Attribute sets for font variants

<xsl:variable name="base-font">12</xsl:variable>

<xsl:attribute-set name="head1">
  <xsl:attribute name="font-size"><xsl:value-of 
    select="concat(round($base-font *1.2),'pt')"/></xsl:attribute>
  <xsl:attribute name="font-weight">bold</xsl:attribute>
  <xsl:attribute name="font-family">Helvetica</xsl:attribute>
  ....
  <!-- other attributes as required. -->
  </xsl:attribute-set>

Example 8-12. Attribute set usage

<fo:block 
    xsl:use-attribute-sets="head1" 
    keep-with-next.within-page="always">
     <xsl:apply-templates/>
   </fo:block>

Example 8-13. Percentage font-size change

<fo:block 
    font-size="10pt"
    keep-with-next.within-page="always">
	  <fo:block font-size="80%"
	  <xsl:apply-templates/>
	  </fo:block>
   </fo:block>

Example 8-14. Negating decorations

<fo:inline
  text-decoration="line-through">Continuing, 
          <fo:inline 
            text-decoration="no-line-through">with
          </fo:inline> font-weight bold
</fo:inline>

Example 8-15. Text shadow

<fo:inline
  text-shadow="red 0.3px -0.3px 5px">Eclipse 
</fo:inline>

Example 8-16. Font short form usage

font="italic 11pt/1.5 Times"

Example 9-1. A basic link

xml source

<para>...see the figure on page <link idref="fig53"/> 
</para>

and the stylesheet
<xsl:template match="link">
<fo:basic-link background-color="lightblue"
    internal-destination="{@idref}">Page 
    <fo:page-number-citation ref-id="intro"/>
  </fo:basic-link>

</xsl:template>

Example 9-2. Cross-references using target content, XML source

<chapter>
<para>A link to <xref idref="ch2" />.
      </para></chapter>
<chapter id="ch2">
   <title>Second chapter</title>
</chapter>

Example 9-3. Cross-references using target content, XSLT stylesheet

 <xsl:template match="chapter">
       <fo:block id="{@id}">
     <xsl:apply-templates/></fo:block>
</xsl:template>

 
 <xsl:template match="xref">
  <fo:inline ><fo:basic-link
       internal-destination="{@idref}">
     Chapter 
          <xsl:for-each select="id(@idref)">
      <xsl:number level="multiple" count="chapter" format="1 "/>
    </xsl:for-each>,
    <xsl:value-of select="id(@idref)/title"/>
    on Page 
  <fo:page-number-citation ref-id="{@idref}"/>,     
  </fo:basic-link>
</fo:inline>
 </xsl:template>

Example 9-4. Cross-references using target content, resulting FO

 <fo:block font-family="Times" 
    font-size="12pt" space-before="12pt" space-after="12pt" 
 text-align="justify">A link to <fo:inline>
      <fo:basic-link 
      internal-destination="ch2">Chapter 2, Second chapter on Page 
      <fo:page-number-citation ref-id="ch2"/>, </fo:basic-link>
               </fo:inline>.
      </fo:block>
         </fo:block>

Example 9-5. Source XML requiring a table of contents

<chapter><title>one </title>
 <section><title>one one </title></section>
 <section><title>one two </title></section>
 <section><title>one three </title></section>
</chapter>

<chapter><title>two </title>
 <section><title>two one</title></section>
<section><title>two two</title></section>
<section><title>two three, with a long title to show 
  the effect of wrapping on long lines in this mode. 
   Normal layout provides a reasonable solution</title></section>
<section><title>two four</title></section>
<section><title>two five</title></section>
<section><title>two six</title></section>

Example 9-6. Table of contents stylesheet extract

 <xsl:template match="chapter" mode="toc">
   <fo:block text-align-last="justify">
     <fo:inline><xsl:value-of select="title"/>
     <fo:leader        leader-pattern="dots"/>
     <fo:page-number-citation ref-id="{@id}"/>
   </fo:inline>
 </fo:block>
<xsl:apply-templates select="section" mode="toc"/>
</xsl:template>

 <xsl:template match="section" mode="toc">
   <fo:block text-align-last="justify"
          text-indent="-1em" start-indent="1em">
     <fo:inline padding-start="1em"><xsl:value-of select="title"/>
     <fo:leader        leader-pattern="dots" />
     <fo:page-number-citation ref-id="{@id}"/>
   </fo:inline>
 </fo:block>
</xsl:template>

Example 9-7. Source XML

 <para>This is a page layout using the 
    <term id="front-page">page </term> format....
....
    <idx>
      <item idref="front-page">Background Image</item>
      <item idref="b">Bold</item>
      <item idref="cen">Centered text</item>
      <item idref="sect4">Columns</item>
    </idx>

Example 9-8. Stylesheet for the index

 <xsl:template match="idx">
 <fo:block 
   start-indent="0.5in" 
   end-indent="0.5in" 
   font-size="{$base-font-spec}"
   text-align-last="justify">
   <fo:inline font-weight="bold">Item</fo:inline> 
     <fo:leader leader-pattern="dots"/>
    <fo:inline font-weight="bold">Page</fo:inline>
 </fo:block>
   <xsl:apply-templates/>
 </xsl:template>

 <xsl:template match="idx/item">
 <fo:block 
   start-indent="0.5in" 
   end-indent="0.5in" 
   font-size="{$base-font-spec}"
   text-align-last="justify">
   <xsl:apply-templates/>
 <fo:leader leader-pattern="dots"/><fo:basic-link
 internal-destination="{@idref}"> 
    <fo:page-number-citation 
    color="blue" ref-id="{@idref}"/></fo:basic-link>
</fo:block>
 </xsl:template>

Example 9-9. XML source for a running header

<chapter><title>Introducing markers</title>
 ....

Example 9-10. Marker usage

<xsl:template match="chapter/title">
   <fo:block xsl:use-attribute-sets="head1"
    break-before="page">
     <fo:marker marker-class-name="sect-head" >
       <fo:block><xsl:value-of select="."/> 
         </fo:block>
     </fo:marker>
    <xsl:apply-templates/>
  </fo:block>
</xsl:template>

Example 9-11. Retrieve marker usage in a header

<fo:static-content 
      flow-name="xsl-region-head">          
         <fo:block>
           <fo:retrieve-marker
              retrieve-class-name="sect-head"/>
        </fo:block>
</fo:static-content>

Example 9-12. Footnote example, source XML

<para> the bicameral<footnote>The Latin
  alphabet, which you are reading, is an example of a
  bicameral font; it has an uppercase and
  lowercase. Unicameral alphabets (the Arabic and Hebrew
  alphabets) only have one case.</footnote> font presents us with two forms of
  presentation..</para>

Example 9-13. Footnote example, the transformation


(In the appropriate page-sequence-master)

  <fo:static-content 
     flow-name="xsl-footnote-separator">
      <fo:block text-align-last="justify">
	<fo:leader leader-pattern="rule"/>
      </fo:block>
    </fo:static-content>




<xsl:template match='para'>
<fo:block><xsl:apply-templates/></fo:block>
</xsl:template>


<xsl:template match='footnote'>
    <fo:footnote>
       <fo:inline>1</fo:inline>
    <fo:footnote-body>
       <fo:block text-align-last="justify">
              <fo:leader leader-pattern="rule"/>
            </fo:block>

            <fo:list-block>
              <fo:list-item>
                <fo:list-item-label end-indent="label-end(  )">
       <fo:block>1</fo:block>
                </fo:list-item-label>
                <fo:list-item-body start-indent="body-start(  )">
       <fo:block><xsl:apply-templates/></fo:block>
                </fo:list-item-body>
              </fo:list-item>
            </fo:list-block>

          </fo:footnote-body>
        </fo:footnote>

</xsl:template>

Example 9-14. Footnote example, the resulting FO

 <fo:block>the bicameral font presents us with two forms of presentation
          <fo:footnote>
          <fo:inline>1</fo:inline>

          <fo:footnote-body>
            <fo:list-block>
              <fo:list-item>
                <fo:list-item-label end-indent="label-end(  )">
                  <fo:block>1</fo:block>
                </fo:list-item-label>
                <fo:list-item-body start-indent="body-start(  )">
                  <fo:block>The Latin
                      alphabet, which you are reading, is an example of a
                      bicameral font; it has an uppercase and
                      lowercase. Unicameral alphabets (the Arabic and Hebrew
                      alphabets) only have one case.</fo:block>
                </fo:list-item-body>
              </fo:list-item>
            </fo:list-block>

          </fo:footnote-body>
        </fo:footnote>
font presents us with two forms of presentation..
</fo:block>

Example 10-1. Flow contents for the first three pages

<fo:page-sequence master-reference="first3">
  <fo:flow flow-name="xsl-region-body">     
    <xsl:apply-templates select="/book/frontmatter/title"/>
    <xsl:apply-templates select="/book/frontmatter/dedication"/>
    <xsl:call-template name="tPage"/>
  </fo:flow>
</fo:page-sequence>

Example 10-2. Preface and table of contents flow

<fo:page-sequence 
   master-reference="prefAndToc" 
initial-page-label="1"
format="I">


      <fo:static-content
                  flow-name="xsl-region-after">
     <fo:block text-align="outer"><fo:page-number/></fo:block>
   </fo:static-content>

   <fo:flow flow-name="xsl-region-body"> 
   <xsl:apply-templates select="/book/frontmatter/preface"/> 
   <xsl:apply-templates select="/" mode="toc"/>           
   </fo:flow>
 </fo:page-sequence>

Example 10-3. Chapter page-sequence

 <fo:page-sequence 
       master-reference="chaps"
          initial-page-label="1" 
       format="1">

    <fo:static-content
      flow-name="xsl-region-before">
  <fo:block text-align="outside">
       Chapter    <fo:retrieve-marker 
       retrieve-class-name="chapNum"/>
    <fo:leader leader-pattern="space" />
       <fo:retrieve-marker 
       retrieve-class-name="chap"/>
    <fo:leader leader-pattern="space" />
  Page  <fo:page-number font-style="normal" />
  of  <fo:page-number-citation ref-id='end'/>
  </fo:block>
    </fo:static-content>

    <fo:flow flow-name="xsl-region-body">     
    <fo:block  xsl:use-attribute-sets='font'>
    <xsl:apply-templates select="/book/bodymatter"/> 
    <xsl:apply-templates select="/book/rearmatter"/> 
  </fo:flow>
</fo:page-sequence>

Example 10-4. The default template

<xsl:template match="*">
 <fo:block color="red">
    Element <xsl:value-of 
            select="name(..)"/>/ <xsl:value-of 
            select="name(  )"/> found, with no template.
    </fo:block>
 </xsl:template>

Example 10-5. Template for the front page

 <xsl:template name="tPage">
 <fo:block  xsl:use-attribute-sets='font'>
   <fo:block 
     font-size='36pt'
     space-before = '50mm'
     space-after =  '25mm'
     ><xsl:value-of select='/book/title'/>
 </fo:block>
 <fo:block
   font-size='18pt'
   space-before = '25mm'
   space-after =  '12mm'
>by </fo:block>
 <fo:block  
   font-size='18pt'
   space-before = '25mm'
   space-after =  '12mm'>
   <xsl:value-of select='/book/frontmatter/author'/>
 </fo:block>
    </fo:block>
    <fo:block text-align='end'
       font-size='10pt'
       space-before = '50mm'>
     &#x00A9; <xsl:value-of 
         select="/book/frontmatter/pubdetails/pubname"/>
    </fo:block>
      <fo:block text-align='end'
       font-size='10pt'>
  <xsl:value-of 
         select="/book/frontmatter/pubdetails/pubads"/>
      </fo:block>

  </xsl:template>

Example 10-6. Fancy title page template

<xsl:template match='/' mode='ffp'>
   <fo:block break-before="odd-page" >
     <fo:block 
       xsl:use-attribute-sets="title font"     
       space-after="20mm">
    <xsl:value-of select='/book/title'/>
     </fo:block>
     <fo:table width='130mm'>
       <fo:table-body>
         <fo:table-row>
           <fo:table-cell>
             <fo:block>
             <fo:external-graphic  
                   src="images\ttlpg.jpg" 
                content-height="100%"
                   scaling="uniform"/>
           </fo:block>
           </fo:table-cell>
           <fo:table-cell display-align='bottom'>
             <fo:block/>
             <fo:block space-before='90mm'>
            © <xsl:value-of
              select='/book/frontmatter/pubdetails/pubname'/>
             </fo:block>
             <fo:block>
                <xsl:value-of 
                 select='/book/frontmatter/pubdetails/pubads'/>
             </fo:block>
           </fo:table-cell>
         </fo:table-row>
       </fo:table-body>
     </fo:table>
     <fo:block 
  font-size='{$small-sz}'>Image courtesy of Aries Cheung, Toronto
  </fo:block>
   </fo:block>

 </xsl:template>

Example 10-7. Table of contents template

<xsl:template match="/" mode="toc">
 <fo:block break-before="odd-page" >
   <fo:block xsl:use-attribute-sets="title font">
  Table of Contents
   </fo:block>

   <xsl:for-each select='book/frontmatter/preface'>
    <fo:block text-align-last="justify">
     <fo:inline><xsl:value-of select="title"/>
      <fo:leader        leader-pattern="dots"/>
   <fo:page-number-citation ref-id="{generate-id
     </fo:inline>
    </fo:block>
   </xsl:for-each>


<xsl:for-each select='book/bodymatter/chapter'>
    <fo:block text-align-last="justify">
     <fo:inline><xsl:value-of select="title"/>
      <fo:leader        leader-pattern="dots"/>
      <fo:page-number-citation ref-id="{generate-id(  )}"/>
     </fo:inline>
    </fo:block>
   </xsl:for-each>

<xsl:for-each select='book/rearmatter/appendix'>          
    <fo:block text-align-last="justify">
     <fo:inline><xsl:value-of select="title"/>
      <fo:leader        leader-pattern="dots"/>
      <fo:page-number-citation ref-id="{generate-id(  )}"/>
    </fo:inline>
   </fo:block>
  </xsl:for-each>
 </fo:block>
</xsl:template>

Example 11-1. Unexpected element processing

<xsl:template match="*">
  <xsl:message>
    <xsl:value-of select="name(.)"/>
    <xsl:text> with no styling.</xsl:text>
  </xsl:message>
  <fo:block color="red" >
    <xsl:text>
     <xsl:value-of select="name(..)"/>/<xsl:value-of select="name(.)"/>
    </xsl:text>
  </fo:block>
</xsl:template>

Example 11-2. Use of entities in a stylesheet

<?xml version="1.0" ?>
<!DOCTYPE xsl:stylesheet [
  <!ENTITY  lms SYSTEM "lms.xml">
]>
<xsl:stylesheet 
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:fo="http://www.w3.org/1999/XSL/Format"
version="1.0">

<fo:root>
<-- Include the layout-master-set -->
&lms;
......

Example 11-3. Selecting content for flows

<fo:page-sequence  
    master-name="rest">
        <xsl:call-template name="page-sequence">
        <xsl:with-param 
        name="head-R">Page <fo:page-number/> </xsl:with-param>
        <xsl:with-param name="foot-L">Chapter title</xsl:with-param>
        </xsl:call-template>
     <fo:flow flow-name="xsl-region-body"> 
        <xsl:comment>2D</xsl:comment>
            <!-- Process section contents -->
        <xsl:apply-templates select="simpdoca/section[@id='chap03']" />
     </fo:flow>
</fo:page-sequence>

Example A-1. Fixed-position blocks

       <fo:block-container 
       absolute-position="fixed"    
              top="200mm">
  <fo:block>Yours sincerely:
    <fo:inline font-style="italic">Dave Pawson</fo:inline>
  </fo:block>
</fo:block-container>

Example F-1. Initial layout

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

  <fo:layout-master-set>

    <!-- spm for first 3 pages -->
   <fo:simple-page-master master-name="first3"        
                  page-height="29.7cm"
                  page-width="21cm"
                  margin-top="1in"
                  margin-bottom="2in"
                  margin-left="2.5cm"
                  margin-right="2.5cm">
      <fo:region-body 
                      padding-start="1cm"
                      padding-end="1cm"
                      margin-top="0.6in" 
                      margin-bottom="0.6in"
                      margin-left="0.7in"
                      margin-right="0.5in"/>
    </fo:simple-page-master>
 <!-- No headers or footers required -->

    <!-- spm for preface and toc -->
    <fo:simple-page-master master-name="prefAndToc"            
                  page-height="29.7cm"
                  page-width="21cm"
                  margin-top="1in"
                  margin-bottom="1.5in"
                  margin-left="2.5cm"
                  margin-right="2.5cm">
      <fo:region-body 
                      padding-start="1cm"
                      padding-end="1cm"
                      margin-top="0.6in" 
                      margin-bottom="0.6in"
                      margin-left="0.7in"
                      margin-right="0.5in"/>
 <fo:region-before 
   extent          ="0.5in"/>  <!-- Height of the region -->

 <fo:region-after 
   extent          ="0.5in"/>        <!-- Height of region -->

    </fo:simple-page-master>



<!-- spm for main chapters, odd pages -->
  <fo:simple-page-master master-name="chapsOdd"
                  page-height="29.7cm"
                  page-width="21cm"
                  margin-top="1in"
                  margin-bottom="0.7in"
               margin-left="1.5cm"              
                  margin-right="2.5cm">

      <fo:region-body 


 border-color="red"                              
    border-style="solid" 
    border-width="1pt" 


                  padding-end="3mm" 
                  padding-start="1mm" 
                  margin-bottom="0.5in" 
                  margin-top="1in" 
                  margin-left="15mm" 
                  margin-right="15mm"/>
 <fo:region-before 

   border-color="red" 
   border-style="solid" 
   border-width="1pt" 

   extent          ="0.7in"/>  <!-- Height of the region -->

 <fo:region-after 
   border-color="red" 
   border-style="solid" 
   border-width="1pt" 

   extent          ="0.4in"/>        <!-- Height of region -->

    </fo:simple-page-master>

<!-- spm for main chapters, even pages -->
 <fo:simple-page-master master-name="chapsEven"
                  page-height="29.7cm"
                  page-width="21cm"
                  margin-top="1in"
                  margin-bottom="0.7in"
                  margin-left="2.5cm"
                  margin-right="1.5cm">

      <fo:region-body 


    border-color="red" 
    border-style="solid" 
    border-width="1pt" 


                  padding-end="3mm" 
                  padding-start="1mm" 
                  margin-bottom="0.5in" 
                  margin-top="1in" 
                  margin-left="15mm" 
                  margin-right="15mm"/>
 <fo:region-before 

   border-color="red" 
   border-style="solid" 
   border-width="1pt" 

   extent          ="0.7in"/>  <!-- Height of the region -->

 <fo:region-after 
   border-color="red" 
   border-style="solid" 
   border-width="1pt" 

   extent          ="0.4in"/>        <!-- Height of region -->

    </fo:simple-page-master>

   

<!-- Control the sequencing for odd and even pages in chapters -->

                                         

 <fo:page-sequence-master master-name="chaps">

      <fo:repeatable-page-master-alternatives>
        <fo:conditional-page-master-reference
                 master-reference="chapsOdd"
                 odd-or-even="odd" />
        
        <fo:conditional-page-master-reference
              master-reference="chapsEven"        
                 odd-or-even="even" />

      </fo:repeatable-page-master-alternatives>
    </fo:page-sequence-master>
  </fo:layout-master-set>


<!-- page-sequence for first 3 pages -->


[10] <fo:page-sequence master-reference="first3">
      <fo:flow flow-name="xsl-region-body">                  
       <fo:block break-after="page">Front page</fo:block>
       <fo:block break-after="page">Dedication page</fo:block>
       <fo:block break-after="page">Title  page</fo:block>
      </fo:flow>
     </fo:page-sequence>

<!-- Page sequence for preface and toc -->
[11] <fo:page-sequence master-reference="prefAndToc">
      <fo:static-content
                   flow-name="xsl-region-after">
          <fo:block>Preface and toc footer with roman page numbers</fo:block>
    </fo:static-content>
[12]                flow-name="xsl-region-before">
    <fo:flow flow-name="xsl-region-body">                  
      <fo:block break-after="page">Preface</fo:block>
      <fo:block break-after="page">Table of contents 1</fo:block>
    <fo:block break-after="page">Table of contents 2</fo:block>

    </fo:flow>
  </fo:page-sequence>


<!-- Page sequence for all chapters -->
  <fo:page-sequence master-reference="chaps">
    <fo:static-content

          <fo:block>Chapter header with Arabic  page numbers</fo:block>
    </fo:static-content>


    <fo:flow flow-name="xsl-region-body">                  
      <fo:block break-after="page">chapter odd page</fo:block>
      <fo:block break-after="page">chapter even pages</fo:block>
    <fo:block break-after="page">chapter odd pages</fo:block>

    </fo:flow>
  </fo:page-sequence>

</fo:root>

Example F-2. Source document outline

<book>
  <title>Book title</title>
<frontmatter>
    <author>A.N. Author</author>
    <dedication>
      <para>Dedication to all the people 
   who wrote this book for me.</para>
    </dedication>
    <pubdetails>
      <pubname>A Publisher</pubname>
      <pubads>London, 2001 </pubads>
    </pubdetails>
    
    <preface>
      <title>Preface</title>
      <para>First para of preface</para>
<para>Second para of preface</para>
    </preface>
 </frontmatter>
 <bodymatter>
    <chapter>
      <title>Introduction and first chapter title</title>
      <para>Content in the first chapter. 
    Additional paragraphs are necessary to check for 
    inter-paragraph spacing and layout. </para>
    <para>Content in the first chapter. 
    Additional paragraphs are necessary to check for 
    inter-paragraph spacing and layout. </para>
    </chapter>
    <chapter>
      <title>chapter 2 title</title>
      <para>Content </para>
    </chapter>
    <chapter>
      <title>Chapter 3 title</title>
      <para>Content </para>
    </chapter>
    <chapter>
      <title>Chapter n +2</title>
      <para>Content </para>
    </chapter>
    <chapter>
      <title>Chapter n +3</title>
      <para>Content </para>
    </chapter>
    <chapter>
      <title>Chapter n +4</title>
      <para>Content </para>
    </chapter>
    <chapter>
      <title>Chapter n +5</title>
      <para>Content </para>
    </chapter>
    <chapter>
      <title>Chapter n +6</title>
      <para>Content </para>
    </chapter>
    <chapter>
      <title>Chapter n +7</title>
      <para>Content </para>
    </chapter>
    <chapter>
      <title>Chapter n +8</title>
      <para>Content </para>
    </chapter>


 </bodymatter>
<rearmatter>
  <appendix>
    <title>Appendix title</title>
    <para>content</para>
  </appendix>
</rearmatter>
</book>

Example F-3. Main stylesheet

<?xml version="1.0" ?>
<!DOCTYPE xsl:stylesheet [
<!ENTITY  sp  "<xsl:text> </xsl:text>">
]>
<xsl:stylesheet 
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:fo="http://www.w3.org/1999/XSL/Format"
version="1.0">
  <xsl:import href="pl.xsl"/>
  <xsl:import href='ps.xsl'/>
 <xsl:template match="book">
      <xsl:apply-templates/>
  </xsl:template>



  <xsl:template match="frontmatter">
    <fo:block>
      <xsl:apply-templates/>
    </fo:block>
  </xsl:template>

  <xsl:template match="author">
    <fo:block>
      <xsl:apply-templates/>
    </fo:block>
  </xsl:template>

  <xsl:template match="frontmatter/title">
    <fo:block>
      <xsl:apply-templates/>
    </fo:block>
  </xsl:template>




  <xsl:template name="tPage">
 <fo:block  xsl:use-attribute-sets='font'>
   <fo:block 
     font-size='36pt'
     space-before = '50mm'
     space-after =  '25mm'
     ><xsl:value-of select='/book/title'/>
 </fo:block>
 <fo:block
   font-size='18pt'
   space-before = '25mm'
   space-after =  '12mm'
>by </fo:block>
 <fo:block  
   font-size='18pt'
   space-before = '25mm'
   space-after =  '12mm'>
   <xsl:value-of select='/book/frontmatter/author'/>
 </fo:block>
    </fo:block>

    <fo:block text-align='end'
       font-size='10pt'
       space-before = '60mm'>
     &#x00A9; <xsl:value-of 
              select="/book/frontmatter/pubdetails/pubname"/>
    </fo:block>
      <fo:block text-align='end'
       font-size='10pt'       >
  <xsl:value-of select="/book/frontmatter/pubdetails/pubads"/>
      </fo:block>

  </xsl:template>

  <xsl:template match="dedication">
    <fo:block break-before='page'>
      <fo:block xsl:use-attribute-sets="title font">
         Dedication.
      </fo:block>
    <xsl:apply-templates/>
    </fo:block>
  </xsl:template>

  <xsl:template match='/' mode='ffp'>
    <fo:block break-before="odd-page" >
      <fo:block xsl:use-attribute-sets="title font" 
               space-after="20mm">
        <xsl:value-of select='/book/title'/>
      </fo:block>
      <fo:table width='130mm'>
        <fo:table-body>
          <fo:table-row>
            <fo:table-cell>
              <fo:block>
              <fo:external-graphic  
                    src="images\ttlpg.jpg" 
                    content-height="100%" 
                    scaling="uniform"/>
            </fo:block>
            </fo:table-cell>
            <fo:table-cell display-align='bottom'>
              <fo:block/>
              <fo:block space-before='90mm'>
                &#x00A9; <xsl:value-of 
               select='/book/frontmatter/pubdetails/pubname'/>
              </fo:block>
              <fo:block>
                 <xsl:value-of 
                  select='/book/frontmatter/pubdetails/pubads'/>
              </fo:block>
            </fo:table-cell>
          </fo:table-row>
        </fo:table-body>
      </fo:table>
      <fo:block font-size='{$small-sz}'>Image courtesy of 
               Aries Cheung, Toronto</fo:block>
    </fo:block>


  </xsl:template>


 <xsl:template match="preface">
    <fo:block id='{generate-id(  )}'>
    <xsl:apply-templates/>
    </fo:block>
  </xsl:template>

  <xsl:template match="preface/title">
    <fo:block xsl:use-attribute-sets="title font">
    <xsl:apply-templates/>
    </fo:block>
  </xsl:template>


  <xsl:template match="/" mode="toc">
      <fo:block break-before="odd-page" >
           <fo:block xsl:use-attribute-sets="title font">
                Table of Contents
           </fo:block>

           <xsl:for-each select='book/frontmatter/preface'>
           <fo:block text-align-last="justify">
             <fo:inline><xsl:value-of select="title"/>
             <fo:leader        leader-pattern="dots"/>
             <fo:page-number-citation ref-id="{generate-id(  )}"/>
           </fo:inline>
         </fo:block>
       </xsl:for-each>


           <xsl:for-each select='book/bodymatter/chapter'>
             <fo:block text-align-last="justify">
               <fo:inline><xsl:value-of select="title"/>
               <fo:leader        leader-pattern="dots"/>
               <fo:page-number-citation ref-id="{generate-id(  )}"/>
             </fo:inline>
           </fo:block>
           </xsl:for-each>

        <xsl:for-each select='book/rearmatter/appendix'>
           <fo:block text-align-last="justify">
             <fo:inline><xsl:value-of select="title"/>
             <fo:leader        leader-pattern="dots"/>
             <fo:page-number-citation ref-id="{generate-id(  )}"/>
           </fo:inline>
         </fo:block>
       </xsl:for-each>
      </fo:block>
  </xsl:template>



  <xsl:template match="bodymatter|rearmatter">
    <xsl:apply-templates/>
  </xsl:template>

  <xsl:template match="chapter">
 <fo:block break-before="odd-page" id='{generate-id(  )}'>
    <fo:marker marker-class-name="chap">
      <xsl:value-of select="title"/>
    </fo:marker>
  <fo:marker marker-class-name="chapNum">
    <xsl:number count="chapter" level="any" from="bodymatter"/>
   
    </fo:marker>
    <xsl:apply-templates/>
    </fo:block>
  </xsl:template>

  <xsl:template match="chapter/title">
    <fo:block/>
    <fo:block xsl:use-attribute-sets="title font">
      <xsl:apply-templates/>
    </fo:block>
  </xsl:template>

  <xsl:template match="appendix">
    <fo:block id='{generate-id(  )}'>
    <xsl:apply-templates/>
    </fo:block>
  </xsl:template>


  <xsl:template match="appendix/title">
    <fo:block>
      <xsl:apply-templates/>
    </fo:block>
  </xsl:template>



<!-- minor templates -->


 <xsl:template match="para">
    <fo:block xsl:use-attribute-sets="para font">
      <xsl:apply-templates/>
    </fo:block>
  </xsl:template>



  <xsl:template match="*">
    <fo:block color="red">
 *****************     Element <xsl:value-of 
                 select="name(..)"/>/ <xsl:value-of 
                 select="name(  )"/> found, with no template. ****************
    </fo:block>
  </xsl:template>

 


</xsl:stylesheet>

Example F-4. File ps.xsl, the property sets

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE xsl:stylesheet [
<!ENTITY  sp  "<xsl:text> </xsl:text>">
]>
<xsl:stylesheet 
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:fo="http://www.w3.org/1999/XSL/Format"
version="1.0">

<xsl:variable name='base-font-size' select='12'/>   
<xsl:variable name='title-font-size' select='$base-font-size * 1.5'/>
<xsl:variable name='head-font-size' select='$base-font-size * 1.2'/>
<xsl:variable name='small-font-size' select='$base-font-size div 2'/>

<xsl:variable name='base-sz' select= 'concat ($base-font-size,"pt")'/>
<xsl:variable name='title-sz' select= 'concat ($title-font-size,"pt")'/>
<xsl:variable name='head-sz' select= 'concat ($head-font-size,"pt")'/>
<xsl:variable name='small-sz' select= 'concat ($small-font-size,"pt")'/>


<xsl:attribute-set name='font'> <!-- Font family -->
  <xsl:attribute 
    name='font-family'>'Arial' 'Helvetica' Serif</xsl:attribute>
</xsl:attribute-set>


 <xsl:attribute-set name="title"
use-attribute-sets="font ">
    <xsl:attribute name="font-size">
      <xsl:value-of select="$title-sz"/>
    </xsl:attribute>
    <xsl:attribute name="font-weight">bold</xsl:attribute>
    <xsl:attribute name="font-style">normal</xsl:attribute>
    <xsl:attribute name="space-before.optimum">
         <xsl:value-of select="$title-sz"/> 
    </xsl:attribute>
    <xsl:attribute 
      name="space-before.conditionality">retain</xsl:attribute>
    <xsl:attribute name="space-after.optimum">
      <xsl:value-of select="$small-sz"/>
    </xsl:attribute>
    <xsl:attribute name="keep-with-next">true</xsl:attribute>
    <xsl:attribute name="page-break-inside">avoid</xsl:attribute>
    <xsl:attribute name="text-align">center</xsl:attribute>
    <xsl:attribute name="background-color">white</xsl:attribute>
  </xsl:attribute-set>

  <xsl:attribute-set name='pad'>
    <xsl:attribute name='padding'>
       <xsl:value-of select="$small-sz"/>
    </xsl:attribute>
  </xsl:attribute-set>


<xsl:attribute-set name='border'>
<xsl:attribute name='border-before-style'>solid'</xsl:attribute>
<xsl:attribute name='border-after-style'>solid'</xsl:attribute>
<xsl:attribute name='border-start-style'>solid'</xsl:attribute>
<xsl:attribute name='border-end-style'>solid'</xsl:attribute>


<xsl:attribute name='border-before-width'>.1mm"</xsl:attribute>
<xsl:attribute name='border-after-width'>.1mm"</xsl:attribute>
<xsl:attribute name='border-start-width'>.1mm"</xsl:attribute>
<xsl:attribute name='border-end-width'>.1mm"</xsl:attribute>
  </xsl:attribute-set>


 <xsl:attribute-set name="para"
   use-attribute-sets='font '>
    <xsl:attribute name="space-before.optimum">
      <xsl:value-of select="$base-sz"/> 
    </xsl:attribute>
   <xsl:attribute name="space-after.optimum">
      <xsl:value-of select="$base-sz"/> 
    </xsl:attribute>
  </xsl:attribute-set>

</xsl:stylesheet>

Example F-5. Page layout stylesheet

<?xml version="1.0" ?>
<!DOCTYPE xsl:stylesheet [
  <!ENTITY  lms SYSTEM "lms.xml">
]>
<xsl:stylesheet 
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:fo="http://www.w3.org/1999/XSL/Format"
version="1.0">
<!-- Time-stamp: "2000-12-22 11:30:45 dave"  -->

<xsl:output method="xml" indent="yes"/>

<xsl:template match="/">
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
  <fo:layout-master-set>

<!-- spm for first 3 pages -->
    <fo:simple-page-master master-name="first3"            
                  page-height="29.7cm"
                  page-width="21cm"
                  margin-top="1in"
                  margin-bottom="2in"
                  margin-left="2.5cm"
                  margin-right="2.5cm">
      <fo:region-body 
                      padding-start="1cm"
                      padding-end="1cm"
                      margin-top="0.6in" 
                      margin-bottom="0.6in"
                      margin-left="0.7in"
                      margin-right="0.5in"/>
    </fo:simple-page-master>
    <!-- No headers or footers required -->

<!-- spm for preface and toc -->
    <fo:simple-page-master master-name="prefAndToc"            
                  page-height="29.7cm"
                  page-width="21cm"
                  margin-top="1in"
                  margin-bottom="1.5in"
                  margin-left="2.5cm"
                  margin-right="2.5cm">
      <fo:region-body 
                      padding-start="1cm"
                      padding-end="1cm"
                      margin-top="0.6in" 
                      margin-bottom="0.6in"
                      margin-left="0.7in"
                      margin-right="0.5in"/>
 <fo:region-before 
   extent          ="0.5in"/>  <!-- Height of the region -->

 <fo:region-after 
   extent          ="0.5in"/>        <!-- Height of region -->

    </fo:simple-page-master>



<!-- spm for main chapters, odd pages -->
    <fo:simple-page-master master-name="chapsOdd"            
                  page-height="29.7cm"
                  page-width="21cm"
                  margin-top="1in"
                  margin-bottom="0.7in"
                  margin-left="1.5cm"
                  margin-right="2.5cm">

   <!--
    border-color="red" 
    border-style="solid" 
    border-width="1pt" 
-->
      <fo:region-body 
                  padding-end="3mm" 
                  padding-start="1mm" 
                  margin-bottom="0.5in" 
                  margin-top="1in" 
                  margin-left="15mm" 
                  margin-right="15mm"/>
 <fo:region-before 
  
   extent          ="0.7in"/>  <!-- Height of the region -->
 <!--
   border-color="red" 
   border-style="solid" 
   border-width="1pt" 
-->


 <fo:region-after 
  
   extent          ="0.4in"/>        <!-- Height of region -->
 <!--
   border-color="red" 
   border-style="solid" 
   border-width="1pt" 
-->
    </fo:simple-page-master>

<!-- spm for main chapters, even pages -->
    <fo:simple-page-master master-name="chapsEven"            
                  page-height="29.7cm"
                  page-width="21cm"
                  margin-top="1in"
                  margin-bottom="0.7in"
                  margin-left="2.5cm"
                  margin-right="1.5cm">

      <fo:region-body 

                  padding-end="3mm" 
                  padding-start="1mm" 
                  margin-bottom="0.5in" 
                  margin-top="1in" 
                  margin-left="15mm" 
                  margin-right="15mm"/>


      <!--    border-color="red" 
    border-style="solid" 
    border-width="1pt" -->


 <fo:region-before 

 
   extent          ="0.7in"/>  <!-- Height of the region -->
<!--   border-color="red" 
   border-style="solid" 
   border-width="1pt" 
 -->
 <fo:region-after 

   extent          ="0.4in"/>        <!-- Height of region -->
<!--    border-color="red" 
   border-style="solid" 
   border-width="1pt" 
 -->
    </fo:simple-page-master>

   

<!-- Control the sequencing for odd and even pages in chapters -->
    <fo:page-sequence-master master-name="chaps">
      <fo:repeatable-page-master-alternatives>
        <fo:conditional-page-master-reference
                 master-reference="chapsOdd"
                 odd-or-even="odd" />
        
        <fo:conditional-page-master-reference
                 master-reference="chapsEven"
                 odd-or-even="even" />
      </fo:repeatable-page-master-alternatives>
    </fo:page-sequence-master>
  </fo:layout-master-set>


<!-- page-sequence for first 3 pages -->
  <fo:page-sequence master-reference="first3">
    <fo:flow flow-name="xsl-region-body">   
   <xsl:call-template name="tPage"/>  
     <xsl:apply-templates select="/book/frontmatter/dedication"/>
 <xsl:apply-templates select="/" mode="ffp"/>     
  </fo:flow>
</fo:page-sequence>

<!-- Page sequence for preface and toc -->
  <fo:page-sequence 
       master-reference="prefAndToc" 
       initial-page-label="F" format="I">
    <fo:static-content
                   flow-name="xsl-region-after">
      <fo:block text-align="outside"><fo:page-number/></fo:block>
    </fo:static-content>

    <fo:flow flow-name="xsl-region-body"> 
    <xsl:apply-templates select="/book/frontmatter/preface"/>                 
    <xsl:apply-templates select="/" mode="toc"/>           

    </fo:flow>
  </fo:page-sequence>


<!-- Page sequence for all chapters -->
  <fo:page-sequence master-reference="chaps">
    <fo:static-content
      flow-name="xsl-region-before">
     <fo:block text-align="outside" 
                  xsl:use-attribute-sets='para font pad'>
       Chapter    <fo:retrieve-marker retrieve-class-name="chapNum"/> 
    <fo:leader leader-pattern="space" />
       <fo:retrieve-marker retrieve-class-name="chap"/>      
    <fo:leader leader-pattern="space" />
      Page <fo:page-number 
           font-style="normal" /> of <fo:page-number-citation 
                                      ref-id='end'/>
  </fo:block>
    </fo:static-content>
    <fo:flow flow-name="xsl-region-body">  
    <fo:block xsl:use-attribute-sets='font'>
    <xsl:apply-templates select="/book/bodymatter"/> 
    <xsl:apply-templates select="/book/rearmatter"/> 
  </fo:block>
  <fo:block id='end'/>
  </fo:flow>
</fo:page-sequence>


</fo:root>

</xsl:template>
</xsl:stylesheet>