Table of contents

Abstract

Considerations in creating multiple page sequences

XML document structure and fo:page-sequences

The default XSL:FO approach

The XSL:FO solution

The default implementation in the DITA Open Toolkit: single page sequence

The solution in the DITA Open Toolkit: multiple page sequences

Conclusion

About the author

The XSL:FO solution

To break the content into multiple page sequences, you modify the XSL templates to defer the creation of fo:page-sequence and fo:flow until it gets to the section element, specifically the top-level sections and the second-level sections. These functions are accomplished with two templates for sections with different modes. The solution uses a condition for selecting one template or the other based on the level of the section within the hierarchy.

The following code shows the solution. It generates the output in Example 3 (the “good” example) from the input in Example 1.

NOTE: The code shown is conceptual code. It is based on working and tested code, but has been simplified and has not itself been tested.
Example 5

<xsl:template match="/book">

   <xsl:apply-templates select="section" mode="page"/>

   <!-- This takes care of all the top-level section tags. -->

</xsl:template>

<!-- The following template matches section at the top level and second level. -->

<xsl:template match="section" mode="page">

   <fo:page-sequence>

     <fo:flow>

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

       <xsl:if test="count(ancestor::section)=2"/>

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

       </xsl:if>

The preceding “if” condition selects third-level sections while it is processing a second-level section. You could adjust the condition to select any level of section you wanted, depending on how far down you wanted to start chunking. At this point, processing of section elements is taken over by the other “section” template. This way, the hierarchy of descendant sections is preserved within the current fo:page-sequence.

     </fo:flow>

   </fo:page-sequence>

   <xsl:if test="count(ancestor::section) &lt; 2">

The preceding condition selects the second-level sections. You could adjust this to any level of section you wanted, depending on how far down you wanted to start the chunking. (You could also create a “chunking” variable to set at the top of this template so you could change it in only one place instead of two.)

     <xsl:apply-templates select="section" mode="page"/>

This apply-templates invokes the current template, so the second-level sections will have the page sequence wrapped around them as well. The fo:page-sequence tag in this template is closed before this apply-templates is invoked. This is how the element hierarchy is flattened into a series of fo:page-sequences.

   </xsl:if>

</xsl:template>

<xsl:template match="section">

   <fo:block>

     <xsl:apply-templates/>

   </fo:block>

</xsl:template>

<xsl:template match="body">

   <fo:block>

     <xsl:apply-templates/>

   </fo:block>

</xsl:template>

Two tricks worth mentioning are:

For the DITA OT, the solution is a little trickier. That solution is described in the following sections.

 

Next Page:
The default implementation in the DITA Open Toolkit: single page sequence


Scriptorium Publishing | Post Office Box 12761 Research Triangle Park, NC 27709 | (919) 481 2701 | info@scriptorium.com