Skip to content

Commit

Permalink
Fix numbering chapters inside parts
Browse files Browse the repository at this point in the history
  • Loading branch information
jelovirt committed Oct 19, 2024
1 parent 6df4c04 commit 2a966d6
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 32 deletions.
75 changes: 45 additions & 30 deletions src/generator/com/elovirta/pdf/commons.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -187,18 +187,23 @@
</axsl:for-each>
</fo:block>

<axsl:choose>
<axsl:when test="$partLayout = 'BASIC'">
<axsl:apply-templates select="* except(*[contains(@class, ' topic/title ') or
<axsl:apply-templates select="* except(*[contains(@class, ' topic/title ') or
contains(@class,' ditaot-d/ditaval-startprop ') or
contains(@class, ' topic/prolog ') or
contains(@class, ' topic/topic ')])"/>

<axsl:choose>
<axsl:when test="$partLayout = 'BASIC'">
<!--axsl:apply-templates select="." mode="buildRelationships"/-->
</axsl:when>
<axsl:otherwise>
<axsl:apply-templates select="." mode="createPartToc"/>
<fo:block axsl:use-attribute-sets="e:part_toc">
<axsl:apply-templates select="*[contains(@class, ' topic/topic ')]" mode="part-toc"/>
</fo:block>
<!-- <axsl:apply-templates select="." mode="createPartToc"/>-->
</axsl:otherwise>
</axsl:choose>

<axsl:for-each select="*[contains(@class,' topic/topic ')]">
<axsl:variable name="topicType" as="xs:string">
<axsl:call-template name="determineTopicType"/>
Expand All @@ -211,8 +216,10 @@
</fo:block>
</axsl:template>

<axsl:template match="*" mode="createPartToc">
<!-- <axsl:template match="*" mode="createPartToc">-->
<!-- Part introduction -->
<!--
<axsl:apply-templates select="*[contains(@class,' topic/titlealts ')]"/>
<axsl:if test="*[contains(@class,' topic/shortdesc ')
or contains(@class, ' topic/abstract ')]/node()">
Expand All @@ -223,13 +230,15 @@
</axsl:if>
<axsl:apply-templates select="*[contains(@class,' topic/body ')]/*"/>
<axsl:apply-templates select="*[contains(@class, ' ditaot-d/ditaval-endprop ')]"/>
<axsl:if test="*[contains(@class,' topic/related-links ')]//
*[contains(@class,' topic/link ')]
[not(@role) or @role != 'child']">
<axsl:apply-templates select="*[contains(@class,' topic/related-links ')]"/>
</axsl:if>
-->
<!-- Part TOC -->
<axsl:apply-templates select="*[contains(@class, ' topic/topic ')]" mode="part-toc"/>
<!-- <axsl:apply-templates select="*[contains(@class, ' topic/topic ')]" mode="part-toc"/>-->
<!--
<axsl:if test="*[contains(@class, ' topic/topic ')]">
<fo:block axsl:use-attribute-sets="__toc__mini">
Expand All @@ -244,7 +253,7 @@
</fo:block>
</axsl:if>
-->
</axsl:template>
<!-- </axsl:template>-->

<!-- Chapter -->

Expand Down Expand Up @@ -285,40 +294,46 @@

<axsl:choose>
<axsl:when test="$chapterLayout='BASIC'">
<axsl:apply-templates select="* except(*[contains(@class, ' topic/title ') or contains(@class,' ditaot-d/ditaval-startprop ') or
contains(@class, ' topic/prolog ') or contains(@class, ' topic/topic ')])"/>
<!--xsl:apply-templates select="." mode="buildRelationships"/-->
</axsl:when>
<axsl:otherwise>
<axsl:apply-templates select="." mode="createMiniToc"/>
<fo:block axsl:use-attribute-sets="e:chapter_toc">
<axsl:apply-templates select="*[contains(@class, ' topic/topic ')]" mode="chapter-toc"/>
</fo:block>
<!-- <axsl:apply-templates select="." mode="createMiniToc"/>-->
</axsl:otherwise>
</axsl:choose>

<axsl:apply-templates select="* except(*[contains(@class, ' topic/title ') or
contains(@class,' ditaot-d/ditaval-startprop ') or
contains(@class, ' topic/prolog ') or
contains(@class, ' topic/topic ')])"/>

<axsl:apply-templates select="*[contains(@class,' topic/topic ')]"/>
<axsl:call-template name="pullPrologIndexTerms.end-range"/>
</fo:block>
</axsl:template>

<axsl:template match="*" mode="createMiniToc">
<!-- Chapter TOC -->
<axsl:apply-templates select="*[contains(@class, ' topic/topic ')]" mode="chapter-toc"/>
<!-- Chapter introduction -->
<axsl:apply-templates select="*[contains(@class,' topic/titlealts ')]"/>
<axsl:if test="*[contains(@class,' topic/shortdesc ')
or contains(@class, ' topic/abstract ')]/node()">
<fo:block axsl:use-attribute-sets="p">
<axsl:apply-templates select="*[contains(@class,' topic/shortdesc ')
or contains(@class, ' topic/abstract ')]/node()"/>
</fo:block>
</axsl:if>
<axsl:apply-templates select="*[contains(@class,' topic/body ')]/*"/>
<axsl:apply-templates select="*[contains(@class, ' ditaot-d/ditaval-endprop ')]"/>
<axsl:if test="*[contains(@class,' topic/related-links ')]//
*[contains(@class,' topic/link ')]
[not(@role) or @role != 'child']">
<axsl:apply-templates select="*[contains(@class,' topic/related-links ')]"/>
</axsl:if>
</axsl:template>
<!-- <axsl:template match="*" mode="createMiniToc">-->
<!-- &lt;!&ndash; Chapter TOC &ndash;&gt;-->
<!-- <axsl:apply-templates select="*[contains(@class, ' topic/topic ')]" mode="chapter-toc"/>-->
<!-- &lt;!&ndash; Chapter introduction &ndash;&gt;-->
<!-- <axsl:apply-templates select="*[contains(@class,' topic/titlealts ')]"/>-->
<!-- <axsl:if test="*[contains(@class,' topic/shortdesc ')-->
<!-- or contains(@class, ' topic/abstract ')]/node()">-->
<!-- <fo:block axsl:use-attribute-sets="p">-->
<!-- <axsl:apply-templates select="*[contains(@class,' topic/shortdesc ')-->
<!-- or contains(@class, ' topic/abstract ')]/node()"/>-->
<!-- </fo:block>-->
<!-- </axsl:if>-->
<!-- <axsl:apply-templates select="*[contains(@class,' topic/body ')]/*"/>-->
<!-- <axsl:apply-templates select="*[contains(@class, ' ditaot-d/ditaval-endprop ')]"/>-->
<!-- <axsl:if test="*[contains(@class,' topic/related-links ')]//-->
<!-- *[contains(@class,' topic/link ')]-->
<!-- [not(@role) or @role != 'child']">-->
<!-- <axsl:apply-templates select="*[contains(@class,' topic/related-links ')]"/>-->
<!-- </axsl:if>-->
<!-- </axsl:template>-->

</axsl:stylesheet>
</xsl:template>
Expand Down
11 changes: 11 additions & 0 deletions src/generator/com/elovirta/pdf/toc.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,17 @@
<xsl:with-param name="properties" select="$allProperties[. ne 'start-indent']"/>
</xsl:call-template>
</axsl:attribute-set>

<axsl:attribute-set name="e:part_toc">
<xsl:call-template name="generate-attribute-set">
<xsl:with-param name="prefix" select="'style-part-toc'"/>
</xsl:call-template>
</axsl:attribute-set>
<axsl:attribute-set name="e:chapter_toc">
<xsl:call-template name="generate-attribute-set">
<xsl:with-param name="prefix" select="'style-chapter-toc'"/>
</xsl:call-template>
</axsl:attribute-set>
</xsl:if>
</axsl:stylesheet>
</xsl:template>
Expand Down
38 changes: 36 additions & 2 deletions src/generator/com/elovirta/pdf/topic.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
xmlns:fo="http://www.w3.org/1999/XSL/Format"
xmlns:map="http://www.w3.org/2005/xpath-functions/map"
xmlns:array="http://www.w3.org/2005/xpath-functions/array"
xmlns:opentopic="http://www.idiominc.com/opentopic"
exclude-result-prefixes="xs axsl map array">

<xsl:import href="utils.xsl"/>
Expand Down Expand Up @@ -46,10 +47,43 @@
<axsl:apply-templates/>
</axsl:template>

<axsl:variable name="map-without-parts" as="document-node()">
<axsl:document>
<opentopic:map>
<axsl:apply-templates select="$map/*[contains(@class, ' map/topicref ')]" mode="gen-map-without-parts"/>
</opentopic:map>
</axsl:document>
</axsl:variable>

<axsl:template match="*[contains(@class, ' map/topicref ')]" mode="gen-map-without-parts">
<axsl:copy>
<axsl:copy-of select="@*"/>
<axsl:apply-templates select="*[contains(@class, ' map/topicref ')]" mode="#current"/>
</axsl:copy>
</axsl:template>

<axsl:template match="*[contains(@class, ' bookmap/part ')]" mode="gen-map-without-parts" priority="10">
<axsl:apply-templates select="*[contains(@class, ' map/topicref ')]" mode="#current"/>
</axsl:template>

<axsl:key name="map-without-parts-id"
match="*"
use="@id"/>

<axsl:function name="e:get-title-number" as="node()*">
<axsl:param name="topic" as="element()"/>
<axsl:variable name="topicref" as="element()*" select="key('map-id', $topic/@id, root($topic))"/>
<axsl:apply-templates select="$topicref[1]" mode="e:title-number"/>
<axsl:variable name="topicref" as="element()?" select="key('map-id', $topic/@id, root($topic))[1]"/>
<!-- <axsl:if test="empty($topicref)">-->
<!-- <axsl:message terminate="yes" select="'empty topicref', $topic/title"/>-->
<!-- </axsl:if>-->
<axsl:choose>
<axsl:when test="contains($topicref/@class, ' bookmap/part ')">
<axsl:apply-templates select="$topicref" mode="e:title-number"/>
</axsl:when>
<axsl:otherwise>
<axsl:apply-templates select="key('map-without-parts-id', $topicref/@id, $map-without-parts)" mode="e:title-number"/>
</axsl:otherwise>
</axsl:choose>
</axsl:function>

<axsl:template match="*[contains(@class, ' map/topicref')]" mode="e:title-number">
Expand Down

0 comments on commit 2a966d6

Please sign in to comment.