Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve support for bookmap #111

Merged
merged 19 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/generator/com/elovirta/pdf/basic-settings.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@
<axsl:variable name="antArgsChapterLayout">
<xsl:value-of select="if (map:contains($root, 'chapter-layout')) then $root ?chapter-layout else 'BASIC'"/>
</axsl:variable>
<axsl:variable name="partLayout">
<xsl:value-of select="if (map:contains($root, 'part-layout')) then $root ?part-layout else 'BASIC'"/>
</axsl:variable>
</axsl:stylesheet>
</xsl:template>

Expand Down
458 changes: 392 additions & 66 deletions src/generator/com/elovirta/pdf/commons.xsl

Large diffs are not rendered by default.

5 changes: 1 addition & 4 deletions src/generator/com/elovirta/pdf/links.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,7 @@
</axsl:template>

<axsl:template match="*[contains(@class, ' topic/topic ')]" mode="retrieveReferenceTitle">
<axsl:variable name="topicref" select="key('map-id', @id)[1]"/>
<axsl:variable name="contents" as="node()*">
<axsl:apply-templates select="$topicref[1]" mode="e:title-number"/>
</axsl:variable>
<axsl:variable name="contents" as="node()*" select="e:get-title-number(.)"/>
<axsl:if test="exists($contents)">
<axsl:copy-of select="$contents"/>
<axsl:text>
Expand Down
1 change: 1 addition & 0 deletions src/generator/com/elovirta/pdf/shell.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@
<axsl:import href="plugin:org.dita.pdf2:cfg/fo/attrs/task-elements-attr.xsl"/>
<axsl:import href="{$plugin_name}cfg/fo/attrs/task-elements-attr.xsl"/>
<axsl:import href="plugin:org.dita.pdf2:xsl/fo/task-elements.xsl"/>
<axsl:import href="{$plugin_name}xsl/fo/task-elements.xsl"/>

<axsl:import href="plugin:org.dita.pdf2:cfg/fo/attrs/reference-elements-attr.xsl"/>
<axsl:import href="plugin:org.dita.pdf2:xsl/fo/reference-elements.xsl"/>
Expand Down
3 changes: 3 additions & 0 deletions src/generator/com/elovirta/pdf/task-elements.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
<xsl:template match=".[. instance of map(*)]">
<axsl:stylesheet version="2.0">
<xsl:call-template name="generate-namespace-node"/>
<xsl:if test="$root ?style-task-labels">
<axsl:param name="GENERATE-TASK-LABELS" select="'YES'"/>
</xsl:if>
</axsl:stylesheet>
</xsl:template>

Expand Down
392 changes: 365 additions & 27 deletions src/generator/com/elovirta/pdf/toc.xsl

Large diffs are not rendered by default.

154 changes: 128 additions & 26 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 @@ -33,22 +34,68 @@
</xsl:attribute>
</axsl:variable>

<axsl:template match="*[contains(@class, ' topic/topic ')]/*[contains(@class, ' topic/title ')]" mode="getTitle">
<axsl:variable name="topic" select="ancestor-or-self::*[contains(@class, ' topic/topic ')][1]"/>
<axsl:variable name="id" select="$topic/@id"/>
<axsl:variable name="mapTopics" select="key('map-id', $id)"/>
<axsl:variable name="contents" as="node()*">
<axsl:apply-templates select="$mapTopics[1]" mode="e:title-number"/>
</axsl:variable>
<axsl:if test="exists($contents)">
<axsl:copy-of select="$contents"/>
<!-- <fo:leader leader-pattern="space" leader-length="from-nearest-specified-value(font-size)"/>-->
<axsl:text>
<xsl:text> </xsl:text>
</axsl:text>
</axsl:if>
<axsl:apply-templates/>
</axsl:template>
<!-- <axsl:template match="*[contains(@class, ' topic/topic ')]/*[contains(@class, ' topic/title ')]" mode="getTitle">-->
<!-- <axsl:variable name="topic" select="ancestor-or-self::*[contains(@class, ' topic/topic ')][1]"/>-->
<!-- <axsl:variable name="contents" as="node()*" select="e:get-title-number($topic)"/>-->
<!-- <axsl:if test="exists($contents)">-->
<!-- <axsl:copy-of select="$contents"/>-->
<!--&lt;!&ndash; <fo:leader leader-pattern="space" leader-length="from-nearest-specified-value(font-size)"/>&ndash;&gt;-->
<!-- <axsl:text>-->
<!-- <xsl:text> </xsl:text>-->
<!-- </axsl:text>-->
<!-- </axsl:if>-->
<!-- <axsl:apply-templates/>-->
<!-- </axsl:template>-->

<xsl:choose>
<xsl:when test="$root ?style-chapter-numbering = 'document'">
<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))[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>
</xsl:when>
<xsl:otherwise>
<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:function>
</xsl:otherwise>
</xsl:choose>

<axsl:template match="*[contains(@class, ' map/topicref')]" mode="e:title-number">
<axsl:variable name="depth" select="count(ancestor-or-self::*[contains(@class, ' map/topicref')])"/>
Expand All @@ -63,6 +110,58 @@
level="multiple"
format="A.1.1"/>
</axsl:when>
<xsl:choose>
<xsl:when test="$root ?style-part-title-numbering">
<axsl:when test="self::*[contains(@class, ' bookmap/part ')]">
<!-- <axsl:call-template name="getVariable">-->
<!-- <axsl:with-param name="id" select="'Part with number'"/>-->
<!-- &lt;!&ndash; <axsl:with-param name="id" select="'Table of Contents Part'"/>&ndash;&gt;-->
<!-- <axsl:with-param name="params">-->
<!-- <number>-->
<xsl:choose>
<xsl:when test="$root ?style-chapter-numbering = 'document'">
<axsl:number count="*[contains(@class, ' bookmap/part ')]"
level="single"
format="1"/>
</xsl:when>
<xsl:otherwise>
<axsl:number count="*[contains(@class, ' bookmap/part ') or contains(@class, ' bookmap/chapter ')]"
level="single"
format="1"/>
</xsl:otherwise>
</xsl:choose>
<!-- </number>-->
<!-- </axsl:with-param>-->
<!-- </axsl:call-template>-->
</axsl:when>
</xsl:when>
<xsl:when test="$root ?style-chapter-title-numbering">
<axsl:when test="self::*[contains(@class, ' bookmap/chapter ')]">
<!-- <axsl:call-template name="getVariable">-->
<!-- <axsl:with-param name="id" select="'Chapter with number'"/>-->
<!-- <axsl:with-param name="params">-->
<!-- <number>-->
<xsl:choose>
<xsl:when test="$root ?style-chapter-numbering = 'document'">
<axsl:number count="*[contains(@class, ' bookmap/chapter ')]"
level="single"
format="1"/>
</xsl:when>
<xsl:otherwise>
<axsl:number count="*[contains(@class, ' bookmap/chapter '))]"
level="single"
format="1"/>
</xsl:otherwise>
</xsl:choose>
<!-- </number>-->
<!-- </axsl:with-param>-->
<!-- </axsl:call-template>-->
</axsl:when>
</xsl:when>
<xsl:otherwise>
<axsl:when test="self::*[contains(@class, ' bookmap/part ')]"/>
</xsl:otherwise>
</xsl:choose>
<axsl:when test="$e:number-levels[$depth]">
<axsl:number count="*[contains(@class, ' map/topicref ')]
[not(ancestor-or-self::*[contains(@class, ' bookmap/frontmatter ')])]"
Expand Down Expand Up @@ -99,16 +198,14 @@

<axsl:template name="getNavTitle">
<axsl:variable name="topicref" select="key('map-id', @id)[1]"/>
<axsl:variable name="contents" as="node()*">
<axsl:apply-templates select="$topicref[1]" mode="e:title-number"/>
</axsl:variable>
<axsl:if test="exists($contents)">
<axsl:copy-of select="$contents"/>
<!-- <fo:leader leader-pattern="space" leader-length="from-nearest-specified-value(font-size)"/>-->
<axsl:text>
<xsl:text> </xsl:text>
</axsl:text>
</axsl:if>
<!-- <axsl:variable name="contents" as="node()*" select="e:get-title-number(.)"/>-->
<!-- <axsl:if test="exists($contents)">-->
<!-- <axsl:copy-of select="$contents"/>-->
<!--&lt;!&ndash; <fo:leader leader-pattern="space" leader-length="from-nearest-specified-value(font-size)"/>&ndash;&gt;-->
<!-- <axsl:text>-->
<!-- <xsl:text> </xsl:text>-->
<!-- </axsl:text>-->
<!-- </axsl:if>-->
<axsl:choose>
<axsl:when
test="$topicref/@locktitle = 'yes' and $topicref/*[contains(@class, ' map/topicmeta ')]/*[contains(@class, ' topic/navtitle ')]">
Expand Down Expand Up @@ -303,6 +400,11 @@
<axsl:stylesheet version="2.0">
<xsl:call-template name="generate-namespace-node"/>
<!-- titles -->
<axsl:attribute-set name="part.title" use-attribute-sets="topic.title">
<xsl:call-template name="generate-attribute-set">
<xsl:with-param name="prefix" select="'style-part'"/>
</xsl:call-template>
</axsl:attribute-set>
<axsl:attribute-set name="topic.title">
<xsl:call-template name="generate-attribute-set">
<xsl:with-param name="prefix" select="'style-topic'"/>
Expand Down
4 changes: 3 additions & 1 deletion src/generator/com/elovirta/pdf/utils.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@
<xsl:attribute name="ditaarch:dummy" namespace="http://dita.oasis-open.org/architecture/2005/"/>
<xsl:attribute name="opentopic:dummy" namespace="http://www.idiominc.com/opentopic"/>
<xsl:attribute name="opentopic-func:dummy" namespace="http://www.idiominc.com/opentopic/exsl/function"/>
<xsl:attribute name="fox:dummy" namespace="http://xmlgraphics.apache.org/fop/extensions"/>
</dummy>
</xsl:variable>
<xsl:variable name="namespaces" select="
Expand All @@ -345,7 +346,8 @@
$dummy/namespace::dita-ot,
$dummy/namespace::ditaarch,
$dummy/namespace::opentopic,
$dummy/namespace::opentopic-func
$dummy/namespace::opentopic-func,
$dummy/namespace::fox
"/>
<xsl:copy-of select="$namespaces"/>
<xsl:attribute name="exclude-result-prefixes">xs e dita-ot ditaarch opentopic opentopic-func</xsl:attribute>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ public void execute() throws BuildException {
generate(xdmItem, "static-content.xsl", "xsl/fo/static-content.xsl", null);
// generate(xdmItem, "task-elements.xsl", "xsl/fo/task-elements.xsl", null);
generate(xdmItem, "topic.xsl", "xsl/fo/topic.xsl", null);
generate(xdmItem, "task-elements.xsl", "xsl/fo/task-elements.xsl", null);
generate(xdmItem, "layout-masters.xsl", "cfg/fo/layout-masters.xsl", null);
generate(xdmItem, "front-matter.xsl", "cfg/fo/attrs/front-matter-attr.xsl", ATTR);
generate(xdmItem, "commons.xsl", "cfg/fo/attrs/commons-attr.xsl", ATTR);
Expand Down
Loading