Question

I'm creating custom PDF output from a DITA bookmap using the AntennaHouse formatting engine. I'm trying to create a custom header that appears only on the first page of the book. These books can have multiple chapters, so the strategy I'm using is to create one page sequence for the first chapter, and then a different page sequence for the remaining chapters.

I distinguish between the first chapter processing and the rest of the chapters to be processed like this (in the file commons.xsl). The first block determines the chapter number and puts it in the variable "chapterNumber". The second block describes how to process chapters, depending on the content of the chapterNumber variable:

    <xsl:variable name="id" select="@id"/>
    <xsl:variable name="topicChapters">
        <xsl:copy-of select="$map//*[contains(@class, ' bookmap/chapter ')]"/>
    </xsl:variable>
    <xsl:variable name="chapterNumber">
        <xsl:number format="1" value="count($topicChapters/*[@id = $id]/preceding-sibling::*) + 1"/>
    </xsl:variable>

    <xsl:when test="$topicType = 'topicChapter'">
    <xsl:choose>
        <xsl:when test="$chapterNumber = '1'">
            <xsl:call-template name="processFirstChapter"/>
        </xsl:when>
        <xsl:otherwise>
            <xsl:call-template name="processTopicChapter"/>
        </xsl:otherwise>
    </xsl:choose>

The page sequence for the first chapter looks like this:

    <fo:page-sequence-master master-name="body-first-sequence">
        <fo:repeatable-page-master-alternatives>
            <fo:conditional-page-master-reference page-position="first" master-reference="body-first"/>
            <fo:conditional-page-master-reference page-position="rest" master-reference="body-rest"/>
            <fo:conditional-page-master-reference master-reference="body-rest"/>
        </fo:repeatable-page-master-alternatives>
    </fo:page-sequence-master>

The page sequence for the remaining chapters looks like this:

    <fo:page-sequence-master master-name="body-sequence">
        <fo:repeatable-page-master-alternatives>
            <fo:conditional-page-master-reference page-position="any" master-reference="body-rest"/>
        </fo:repeatable-page-master-alternatives>
    </fo:page-sequence-master>

During processing, I call two templates, one for the first chapter, and one for the rest of the chapters:

    <xsl:template name="insertBodyStaticContents">
        <xsl:call-template name="insertBodyFootnoteSeparator"/>
        <xsl:call-template name="insertBodyRestHeader"/>          
        <xsl:call-template name="insertBodyFooter"/>
    </xsl:template>

    <xsl:template name="insertBodyFirstStaticContents">
        <xsl:call-template name="insertBodyFootnoteSeparator"/>
        <xsl:call-template name="insertBodyFirstHeader"/>
        <xsl:call-template name="insertBodyFooter"/>
    </xsl:template>

Those templates in turn call header templates, one for the first page of the first chapter, the other one for all remaining pages:

    <xsl:template name="insertBodyFirstHeader">
        <fo:static-content flow-name="first-body-header">
            <fo:block-container z-index="-1" position="absolute" top="0pt" left="0pt" height="1.5in" width="100%">
                <fo:block>
                    <fo:external-graphic src="Configuration/OpenTopic/cfg/common/artwork/qrgraphic.png"/>
                </fo:block>
            </fo:block-container>
            <!-- set the title -->
            <fo:block xsl:use-attribute-sets="__qrc__title__header">
                <xsl:value-of select="//*[contains(@class,' bookmap/mainbooktitle ')]"/>
            </fo:block>
            <!-- set the subtitle -->
            <fo:block xsl:use-attribute-sets="__first__heading__qrctext">
                    Quick Reference Card
            </fo:block>
        </fo:static-content>
    </xsl:template>

    <xsl:template name="insertBodyRestHeader">
        <fo:static-content flow-name="rest-body-header">
            <!-- set the title -->
            <fo:block xsl:use-attribute-sets="__qrc__title__header2">
                <xsl:value-of select="//*[contains(@class,' bookmap/mainbooktitle ')]"/>
            </fo:block>
            <!-- set the subtitle -->
            <fo:block xsl:use-attribute-sets="__firstheading__subtitle">
                Quick Reference Card
            </fo:block>
        </fo:static-content>
    </xsl:template>

Everything works except for one strange glitch--if the first chapter of the book is longer than one page, then the first page of the first chapter has the correct header (the one with the flow name called first-body-header) but on subsequent pages of that chapter, the header is blank. Chapters two and greater also have the correct header (the one with the flow name called rest-body-header). I know that the code for that header is correct, since it appears in chapter two and beyond. But that exact same header is supposed to appear on pages 2+ of the first chapter, and it doesn't appear. I can't for the life of me figure out what's going wrong with my code. Any help is appreciated.

No correct solution

OTHER TIPS

You may be making things more complicated than you need to. If the geometry of the page regions is the same for all the chapters, then you shouldn't need a different page sequence master for the first chapter, just different content in the header region's static content.

The other thing to do is to save the .fo file and inspect it to make sure it is being generated the way you thing it is. Set the Ant parameter "retain.topic.fo" to "yes" and clean.temp to "no".

Cheers,

Eliot

I'm not sure where you're making some of your calls, but basically you need two simple page masters (4, counting blankpage). 1 is your first chapter opener, one is your every-other-page-in-the-book.

Define an fo:region-before for each of those. Then, in your flow, call the applicable static-contents. Right now, it doesn't look like your BodyRestHeader is getting called at all when you generate your first chapter.

A very basic example:

<fo:root>
    <fo:layout-master-set>
        <fo:simple-page-master master-name="chapfirstopen">
            <fo:region-body/>
            <fo:region-before region-name="firstopenhead"/>
        </fo:simple-page-master>
        <fo:simple-page-master master-name="everythingelse">
            <fo:region-body/>
            <fo:region-before region-name="elsehead"/>
        </fo:simple-page-master>
        <fo:page-sequence-master master-name="firstchap">
          <fo:repeatable-page-master-alternatives>
            <fo:conditional-page-master-reference master-reference="chapfirstopen" page-position="first">
            <fo:conditional-page-master-reference master-reference="everythingelse">
          </fo:repeatable-page-master-alternatives>
        </fo:page-sequence-master>
        <fo:page-sequence-master master-name="everyotherchap">
          <fo:repeatable-page-master-alternatives>
            <fo:conditional-page-master-reference master-reference="everythingelse">
          </fo:repeatable-page-master-alternatives>
        </fo:page-sequence-master>
    </fo:layout-master-set>
    <fo:page-sequence master-reference="firstchap">
        <fo:static-content flow-name="firstopenhead">
            <!--your first page static content.-->
        </fo:static-content>
        <fo:static-content flow-name="elsehead">
            <!--your every-other-page static content.-->
        </fo:static-content>
        <fo:flow><!--first chapter--></fo:flow>
    </fo:page-sequence>
    <fo:page-sequence master-reference="everyotherchap">
        <fo:static-content flow-name="elsehead">
            <!--your every-other-page static content.-->
        </fo:static-content>
        <fo:flow><!--other chapter--></fo:flow>
    </fo:page-sequence>
</fo:root>

Something along those lines.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top