The solution in the DITA Open Toolkit: multiple page sequences
Modifying the transformation process to create multiple page sequences and preventing them from wrapping each other eliminates the memory problem. Example 8 and Example 9 show the solution. The altered code processes all topics and subtopics inside their own page sequences. Therefore, the map template does not start any page sequence at all. Each topic template (including the top-level topic template) creates a page sequence and also places the <apply-templates> for child topics outside the fo:page-sequence element, so fo:page-sequences are not nested.
Example 8 shows the changes in dita-ot/xsl/dita2fo-shell.xsl.
| NOTE: | Bold type indicates where code is added to or deleted from the original templates. |
<xsl:template name="main-doc3">
<!--deleted all the page sequence stuff.
-->
<xsl:apply-templates></xsl:apply-templates>
</xsl:template>
Example 9 shows the modified templates in dita-ot/xsl/topic2foImpl.xsl.
Example 9<xsl:template match="*[contains(@contains(@class,'topic/topic')]" name="toptopic"
mode="toplevel">
<xsl:call-template name="chapter-setup"/>
</xsl:template>
<xsl:template match="*[contains(@class,'topic/topic')]">
<fo:page-sequence master-reference="chapter-master">
...
<fo:static-content flow-name="xsl-region-before">
</fo:static-content>
<fo:static-content flow-name="xsl-region-after">
</fo:static-content>
<fo:flow flow-name="xsl-region-body">
Now, instead of a generic apply-templates, use select attributes to process child elements in the same order they occur in DITA. However, place the apply-templates that selects child topics outside the fo:page-sequence tags.
<fo:block>
<!-- The generic apply-templates is replaced
with specific apply-templates -->
<xsl:apply-templates select="*[contains(@class,'topic/title')]"/>
<xsl:apply-templates select="*[contains(@class,'topic/titlealts')]"/>
<xsl:apply-templates select="*[contains(@class,'topic/shortdesc')]"/>
<xsl:apply-templates select="*[contains(@class,'topic/prolog')]"/>
<xsl:apply-templates select="*[contains(@class,'topic/body')]"/>
<xsl:apply-templates select="*[contains(@class,'topic/related-links')]"/>
</fo:block>
</fo:flow>
</fo:page-sequence>
<!-- The apply-templates for child topics
is invoked outside the page sequence. -->
<xsl:apply-templates select="*[contains(@class,'topic/topic')]"/>
</xsl:template>
<xsl:template name="chapter-setup">
<!--Newline character (capture the native file
newline)-->
<xsl:variable name="newline"/>
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
<fo:layout-master-set>
...
</fo:layout-master set>
<fo:page-sequence master-reference="common-page"
force-page-count="no-force">
<fo:static-content flow-name="xsl-region-before"
font-size="9pt" font-family="Helvetica">
...
</fo:static-content>
<fo:static-content flow-name="xsl-region-after">
...
</fo:static-content>
<!-- body -->
<fo:flow flow-name-"xsl-region-body">
Again, instead of a generic apply-templates, use select attributes to process child elements in the same order they occur in DITA. Place the apply-templates that select children topics outside the page sequence tags.
<xsl:apply-templates select="*[contains(@class,'topic/title')]"/>
<xsl:apply-templates select="*[contains(@class,'topic/titlealts')]"/>
<xsl:apply-templates select="*[contains(@class,'topic/shortdesc')]"/>
<xsl:apply-templates select="*[contains(@class,'topic/prolog')]"/>
<xsl:apply-templates select="*[contains(@class,'topic/body')]"/>
<xsl:apply-templates select="*[contains(@class,'topic/related-links')]"/>
</fo:flow>
</fo:page-sequence>
<xsl:apply-templates select="*[contains(@class,'topic/topic')]"/>
</fo:root>
</xsl:template>
This solution puts every topic in its own page sequence. This approach is adjustable and can separate topics into individual page sequences down to a specified level in the hierarchy, as described in The default XSL:FO approach.
Next Page:
Conclusion
