[xsl] Problem Running Dave Pawson's Example Code from XSL-FO

Subject: [xsl] Problem Running Dave Pawson's Example Code from XSL-FO
From: cfisher@xxxxxxx
Date: Tue, 14 Dec 2004 08:34:10 -0600
I am trying to use an example from Dave Pawson's book XSL-FO from chapt 10.
I am having problems with FOP blowing up with a Null Pointer exception on
the class and function of:  CommandLineStarter.run(...).

I am using FOP 20.5 and running these files with ithe command line:
fop -d -xsl main.xslt -xml book.xml -pdf output.pdf

Would someone else be kind enough to run these on their system and let me
know what the results were?  I have some other files that approximate this
same behavior so I used his example to trace what I thought was my problem,
and his stuff won't run either, so I am a bit flummoxed...

Thank you,

Curtis Fisher

Here are the 3 files:

 ------------  The XML File (book.xml) --------------------

<?xml version="1.0" encoding="UTF-8"?>
<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>

--------------------------- The main.xsl file
----------------------------------

<?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: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>


------------------------------  The Parameter File (pl.xsl)
--------------------------------

<?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">0.1mm</xsl:attribute>
      <xsl:attribute name="border-after-width">0.1mm</xsl:attribute>
      <xsl:attribute name="border-start-width">0.1mm</xsl:attribute>
      <xsl:attribute name="border-end-width">0.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>

-------------------------  The Page Layout (pl.xsl)
-------------------------------

<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 -->


 <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 -->
 <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>
                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>

Current Thread