<!-- ==================================================================== -->
-<!-- FIXME: in the contexts where <toc> can occur, I think it's always
- the case that a page-sequence is required. Is that true? -->
+<!-- only set, book and part puts toc in its own page sequence -->
-<xsl:template match="toc">
- <xsl:variable name="master-reference">
- <xsl:call-template name="select.pagemaster"/>
+<xsl:template match="set/toc | book/toc | part/toc">
+ <xsl:variable name="toc.params">
+ <xsl:call-template name="find.path.params">
+ <xsl:with-param name="node" select="parent::*"/>
+ <xsl:with-param name="table" select="normalize-space($generate.toc)"/>
+ </xsl:call-template>
</xsl:variable>
- <xsl:choose>
- <xsl:when test="*">
- <xsl:if test="$process.source.toc != 0">
- <!-- if the toc isn't empty, process it -->
- <fo:page-sequence hyphenate="{$hyphenate}"
- master-reference="{$master-reference}">
- <xsl:attribute name="language">
- <xsl:call-template name="l10n.language"/>
- </xsl:attribute>
- <xsl:attribute name="format">
- <xsl:call-template name="page.number.format">
- <xsl:with-param name="element" select="'toc'"/>
- <xsl:with-param name="master-reference"
- select="$master-reference"/>
- </xsl:call-template>
- </xsl:attribute>
-
- <xsl:attribute name="initial-page-number">
- <xsl:call-template name="initial.page.number">
- <xsl:with-param name="element" select="'toc'"/>
- <xsl:with-param name="master-reference"
- select="$master-reference"/>
- </xsl:call-template>
- </xsl:attribute>
-
- <xsl:attribute name="force-page-count">
- <xsl:call-template name="force.page.count">
- <xsl:with-param name="master-reference"
- select="$master-reference"/>
- </xsl:call-template>
- </xsl:attribute>
-
- <xsl:attribute name="hyphenation-character">
- <xsl:call-template name="gentext">
- <xsl:with-param name="key" select="'hyphenation-character'"/>
- </xsl:call-template>
- </xsl:attribute>
- <xsl:attribute name="hyphenation-push-character-count">
- <xsl:call-template name="gentext">
- <xsl:with-param name="key" select="'hyphenation-push-character-count'"/>
- </xsl:call-template>
- </xsl:attribute>
- <xsl:attribute name="hyphenation-remain-character-count">
- <xsl:call-template name="gentext">
- <xsl:with-param name="key" select="'hyphenation-remain-character-count'"/>
- </xsl:call-template>
- </xsl:attribute>
-
- <xsl:apply-templates select="." mode="running.head.mode">
- <xsl:with-param name="master-reference" select="$master-reference"/>
- </xsl:apply-templates>
- <xsl:apply-templates select="." mode="running.foot.mode">
- <xsl:with-param name="master-reference" select="$master-reference"/>
- </xsl:apply-templates>
-
- <fo:flow flow-name="xsl-region-body">
- <xsl:call-template name="set.flow.properties">
- <xsl:with-param name="element" select="local-name(.)"/>
- <xsl:with-param name="master-reference"
- select="$master-reference"/>
- </xsl:call-template>
-
- <fo:block xsl:use-attribute-sets="toc.margin.properties">
- <xsl:call-template name="table.of.contents.titlepage"/>
- <xsl:apply-templates/>
- </fo:block>
- </fo:flow>
- </fo:page-sequence>
- </xsl:if>
- </xsl:when>
- <xsl:otherwise>
- <xsl:if test="$process.empty.source.toc != 0">
- <fo:page-sequence hyphenate="{$hyphenate}"
- master-reference="{$master-reference}">
- <xsl:attribute name="language">
- <xsl:call-template name="l10n.language"/>
- </xsl:attribute>
- <xsl:attribute name="format">
- <xsl:call-template name="page.number.format">
- <xsl:with-param name="element" select="'toc'"/>
- <xsl:with-param name="master-reference"
- select="$master-reference"/>
- </xsl:call-template>
- </xsl:attribute>
-
- <xsl:attribute name="initial-page-number">
- <xsl:call-template name="initial.page.number">
- <xsl:with-param name="element" select="'toc'"/>
- <xsl:with-param name="master-reference"
- select="$master-reference"/>
- </xsl:call-template>
- </xsl:attribute>
-
- <xsl:attribute name="hyphenation-character">
- <xsl:call-template name="gentext">
- <xsl:with-param name="key" select="'hyphenation-character'"/>
- </xsl:call-template>
- </xsl:attribute>
- <xsl:attribute name="hyphenation-push-character-count">
- <xsl:call-template name="gentext">
- <xsl:with-param name="key" select="'hyphenation-push-character-count'"/>
- </xsl:call-template>
- </xsl:attribute>
- <xsl:attribute name="hyphenation-remain-character-count">
- <xsl:call-template name="gentext">
- <xsl:with-param name="key" select="'hyphenation-remain-character-count'"/>
- </xsl:call-template>
- </xsl:attribute>
-
- <xsl:apply-templates select="." mode="running.head.mode">
- <xsl:with-param name="master-reference" select="$master-reference"/>
- </xsl:apply-templates>
- <xsl:apply-templates select="." mode="running.foot.mode">
- <xsl:with-param name="master-reference" select="$master-reference"/>
- </xsl:apply-templates>
-
- <fo:flow flow-name="xsl-region-body">
+ <!-- Do not output the toc element if one is already generated
+ by the use of $generate.toc parameter, or if
+ generating a source toc is turned off -->
+ <xsl:if test="not(contains($toc.params, 'toc')) and
+ ($process.source.toc != 0 or $process.empty.source.toc != 0)">
+ <!-- Don't generate a page sequence unless there is content -->
+ <xsl:variable name="content">
+ <xsl:choose>
+ <xsl:when test="* and $process.source.toc != 0">
+ <xsl:apply-templates select="*"/>
+ </xsl:when>
+ <xsl:when test="count(*) = 0 and $process.empty.source.toc != 0">
+ <!-- trick to switch context node to parent element -->
+ <xsl:for-each select="parent::*">
<xsl:choose>
- <xsl:when test="parent::section
- or parent::sect1
- or parent::sect2
- or parent::sect3
- or parent::sect4
- or parent::sect5">
- <xsl:apply-templates select="parent::*"
- mode="toc.for.section"/>
+ <xsl:when test="self::set">
+ <xsl:call-template name="set.toc">
+ <xsl:with-param name="toc.title.p"
+ select="contains($toc.params, 'title')"/>
+ </xsl:call-template>
</xsl:when>
- <xsl:when test="parent::article">
- <xsl:apply-templates select="parent::*"
- mode="toc.for.component"/>
+ <xsl:when test="self::book">
+ <xsl:call-template name="division.toc">
+ <xsl:with-param name="toc.title.p"
+ select="contains($toc.params, 'title')"/>
+ </xsl:call-template>
</xsl:when>
- <xsl:when test="parent::book
- or parent::part">
- <xsl:apply-templates select="parent::*"
- mode="toc.for.division"/>
+ <xsl:when test="self::part">
+ <xsl:call-template name="division.toc">
+ <xsl:with-param name="toc.title.p"
+ select="contains($toc.params, 'title')"/>
+ </xsl:call-template>
</xsl:when>
- <xsl:when test="parent::set">
- <xsl:apply-templates select="parent::*"
- mode="toc.for.set"/>
- </xsl:when>
- <!-- there aren't any other contexts that allow toc -->
- <xsl:otherwise>
- <xsl:message>
- <xsl:text>I don't know how to make a TOC in this context!</xsl:text>
- </xsl:message>
- </xsl:otherwise>
</xsl:choose>
- </fo:flow>
- </fo:page-sequence>
- </xsl:if>
- </xsl:otherwise>
- </xsl:choose>
+ </xsl:for-each>
+ </xsl:when>
+ </xsl:choose>
+ </xsl:variable>
+
+ <xsl:if test="string-length(normalize-space($content)) != 0">
+ <xsl:variable name="lot-master-reference">
+ <xsl:call-template name="select.pagemaster">
+ <xsl:with-param name="pageclass" select="'lot'"/>
+ </xsl:call-template>
+ </xsl:variable>
+
+ <xsl:call-template name="page.sequence">
+ <xsl:with-param name="master-reference"
+ select="$lot-master-reference"/>
+ <xsl:with-param name="element" select="'toc'"/>
+ <xsl:with-param name="gentext-key" select="'TableofContents'"/>
+ <xsl:with-param name="content" select="$content"/>
+ </xsl:call-template>
+ </xsl:if>
+ </xsl:if>
+</xsl:template>
+
+<xsl:template match="chapter/toc | appendix/toc | preface/toc | article/toc">
+ <xsl:variable name="toc.params">
+ <xsl:call-template name="find.path.params">
+ <xsl:with-param name="node" select="parent::*"/>
+ <xsl:with-param name="table" select="normalize-space($generate.toc)"/>
+ </xsl:call-template>
+ </xsl:variable>
+
+ <!-- Do not output the toc element if one is already generated
+ by the use of $generate.toc parameter, or if
+ generating a source toc is turned off -->
+ <xsl:if test="not(contains($toc.params, 'toc')) and
+ ($process.source.toc != 0 or $process.empty.source.toc != 0)">
+ <xsl:choose>
+ <xsl:when test="* and $process.source.toc != 0">
+ <fo:block>
+ <xsl:apply-templates/>
+ </fo:block>
+ </xsl:when>
+ <xsl:when test="count(*) = 0 and $process.empty.source.toc != 0">
+ <!-- trick to switch context node to section element -->
+ <xsl:for-each select="parent::*">
+ <xsl:call-template name="component.toc">
+ <xsl:with-param name="toc.title.p"
+ select="contains($toc.params, 'title')"/>
+ </xsl:call-template>
+ </xsl:for-each>
+ </xsl:when>
+ </xsl:choose>
+ <xsl:call-template name="component.toc.separator"/>
+ </xsl:if>
+</xsl:template>
+
+<xsl:template match="section/toc
+ |sect1/toc
+ |sect2/toc
+ |sect3/toc
+ |sect4/toc
+ |sect5/toc">
+
+ <xsl:variable name="toc.params">
+ <xsl:call-template name="find.path.params">
+ <xsl:with-param name="node" select="parent::*"/>
+ <xsl:with-param name="table" select="normalize-space($generate.toc)"/>
+ </xsl:call-template>
+ </xsl:variable>
+
+ <!-- Do not output the toc element if one is already generated
+ by the use of $generate.toc parameter, or if
+ generating a source toc is turned off -->
+ <xsl:if test="not(contains($toc.params, 'toc')) and
+ ($process.source.toc != 0 or $process.empty.source.toc != 0)">
+ <xsl:choose>
+ <xsl:when test="* and $process.source.toc != 0">
+ <fo:block>
+ <xsl:apply-templates/>
+ </fo:block>
+ </xsl:when>
+ <xsl:when test="count(*) = 0 and $process.empty.source.toc != 0">
+ <!-- trick to switch context node to section element -->
+ <xsl:for-each select="parent::*">
+ <xsl:call-template name="section.toc">
+ <xsl:with-param name="toc.title.p"
+ select="contains($toc.params, 'title')"/>
+ </xsl:call-template>
+ </xsl:for-each>
+ </xsl:when>
+ </xsl:choose>
+ <xsl:call-template name="section.toc.separator"/>
+ </xsl:if>
</xsl:template>
+<!-- ==================================================================== -->
+
<xsl:template match="tocpart|tocchap
|toclevel1|toclevel2|toclevel3|toclevel4|toclevel5">
<xsl:apply-templates select="tocentry"/>
</xsl:if>
</xsl:template>
-<xsl:template match="tocentry|tocfront|tocback">
+<xsl:template match="tocentry|lotentry|tocdiv|tocfront|tocback">
<fo:block text-align-last="justify"
end-indent="2pc"
last-line-end-indent="-2pc">
</fo:block>
</xsl:template>
+<xsl:template match="toc/title">
+ <fo:block font-weight="bold">
+ <xsl:apply-templates/>
+ </fo:block>
+</xsl:template>
+
+<xsl:template match="toc/subtitle">
+ <fo:block font-weight="bold">
+ <xsl:apply-templates/>
+ </fo:block>
+</xsl:template>
+
+<xsl:template match="toc/titleabbrev">
+</xsl:template>
+
<!-- ==================================================================== -->
-<xsl:template match="*" mode="toc.for.section">
-<!--
- <xsl:call-template name="section.toc"/>
--->
+<!-- A lot element must have content, because there is no attribute
+ to select what kind of list should be generated -->
+<xsl:template match="book/lot | part/lot">
+ <!-- Don't generate a page sequence unless there is content -->
+ <xsl:variable name="content">
+ <xsl:choose>
+ <xsl:when test="* and $process.source.toc != 0">
+ <xsl:apply-templates select="*"/>
+ </xsl:when>
+ <xsl:when test="not(child::*) and $process.empty.source.toc != 0">
+ <xsl:call-template name="process.empty.lot"/>
+ </xsl:when>
+ </xsl:choose>
+ </xsl:variable>
+
+ <xsl:if test="string-length(normalize-space($content)) != 0">
+ <xsl:variable name="lot-master-reference">
+ <xsl:call-template name="select.pagemaster">
+ <xsl:with-param name="pageclass" select="'lot'"/>
+ </xsl:call-template>
+ </xsl:variable>
+
+ <xsl:call-template name="page.sequence">
+ <xsl:with-param name="master-reference"
+ select="$lot-master-reference"/>
+ <xsl:with-param name="element" select="'toc'"/>
+ <xsl:with-param name="content" select="$content"/>
+ </xsl:call-template>
+ </xsl:if>
+</xsl:template>
+
+<xsl:template match="chapter/lot | appendix/lot | preface/lot | article/lot">
+ <xsl:choose>
+ <xsl:when test="* and $process.source.toc != 0">
+ <fo:block>
+ <xsl:apply-templates/>
+ </fo:block>
+ <xsl:call-template name="component.toc.separator"/>
+ </xsl:when>
+ <xsl:when test="not(child::*) and $process.empty.source.toc != 0">
+ <xsl:call-template name="process.empty.lot"/>
+ </xsl:when>
+ </xsl:choose>
</xsl:template>
-<xsl:template match="*" mode="toc.for.component">
- <xsl:call-template name="component.toc"/>
+<xsl:template match="section/lot
+ |sect1/lot
+ |sect2/lot
+ |sect3/lot
+ |sect4/lot
+ |sect5/lot">
+ <xsl:choose>
+ <xsl:when test="* and $process.source.toc != 0">
+ <fo:block>
+ <xsl:apply-templates/>
+ </fo:block>
+ <xsl:call-template name="section.toc.separator"/>
+ </xsl:when>
+ <xsl:when test="not(child::*) and $process.empty.source.toc != 0">
+ <xsl:call-template name="process.empty.lot"/>
+ </xsl:when>
+ </xsl:choose>
</xsl:template>
-<xsl:template match="*" mode="toc.for.division">
- <xsl:call-template name="division.toc"/>
+<xsl:template name="process.empty.lot">
+ <!-- An empty lot element does not provide any information to indicate
+ what should be included in it. You can customize this
+ template to generate a lot based on @role or something -->
+ <xsl:message>
+ <xsl:text>Warning: don't know what to generate for </xsl:text>
+ <xsl:text>lot that has no children.</xsl:text>
+ </xsl:message>
</xsl:template>
-<xsl:template match="*" mode="toc.for.set">
-<!--
- <xsl:call-template name="set.toc"/>
--->
+<xsl:template match="lot/title">
+ <fo:block font-weight="bold">
+ <xsl:apply-templates/>
+ </fo:block>
</xsl:template>
-<!-- ==================================================================== -->
+<xsl:template match="lot/subtitle">
+ <fo:block font-weight="bold">
+ <xsl:apply-templates/>
+ </fo:block>
+</xsl:template>
-<xsl:template match="lot|lotentry">
+<xsl:template match="lot/titleabbrev">
</xsl:template>
</xsl:stylesheet>