Skip to content

Commit

Permalink
Add Table of Contents to PDF
Browse files Browse the repository at this point in the history
  • Loading branch information
adamretter committed Oct 24, 2024
1 parent e7c1b14 commit fad2bab
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 3 deletions.
27 changes: 27 additions & 0 deletions cityehr-quick-start-guide/src/main/xslt/common-pdf.xslt
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@

<xsl:template name="pcom:page-sequences">
<xsl:apply-templates select="map" mode="cover-page"/>
<xsl:apply-templates select="map" mode="toc"/>
<xsl:apply-templates select="topic|map/topicref" mode="topic-pages"/>
</xsl:template>

Expand Down Expand Up @@ -132,6 +133,32 @@
</fo:page-sequence>
</xsl:template>

<!-- TOC (Table of Contents) -->
<xsl:template name="pcom:toc">
<xsl:param name="sections" as="element()+"/>
<fo:page-sequence master-reference="PageMaster" id="toc-sequence">
<fo:title>Table of Contents</fo:title>
<fo:flow flow-name="xsl-region-body" hyphenate="true">
<fo:block background-color="#B84747" color="#FFFFFF" font-weight="bold" font-size="14pt" display-align="center" margin-bottom="11pt" id="toc-{generate-id()}">
<fo:block margin-left="8pt">Table of Contents</fo:block>
</fo:block>
<xsl:for-each select="$sections">
<xsl:variable name="topic" select="com:get-topic(., .)"/>
<xsl:variable name="topic-id" select="generate-id($topic)"/>
<fo:block text-align-last="justify">
<fo:basic-link internal-destination="topic-{$topic-id}">
<xsl:number level="single" count="$sections"/>
<xsl:text>. </xsl:text><xsl:value-of select="$topic/title"/>
<fo:leader leader-length.minimum="12pt" leader-length.optimum="40pt" leader-length.maximum="100%" leader-pattern="dots"/>
<xsl:text> </xsl:text>
<fo:page-number-citation ref-id="topic-{$topic-id}"/>
</fo:basic-link>
</fo:block>
</xsl:for-each>
</fo:flow>
</fo:page-sequence>
</xsl:template>

<!-- LAST PAGE -->
<xsl:template name="pcom:last-page">
<fo:page-sequence master-reference="PageMaster" id="last-page">
Expand Down
11 changes: 9 additions & 2 deletions cityehr-quick-start-guide/src/main/xslt/common.xslt
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,19 @@
<xsl:param name="rel-href" as="xs:string" required="yes"/>
<xsl:sequence select="concat(com:parent-path(com:document-uri($context)), '/', $rel-href)"/>
</xsl:function>


<!-- Get the topic by loading the topic from a topicref -->
<xsl:function name="com:get-topic" as="element(topic)">
<xsl:param name="context" as="node()" required="yes"/>
<xsl:param name="topicref" as="element(topicref)" required="yes"/>
<xsl:sequence select="doc(com:abs-uri($context, $topicref/@href))/topic"/>
</xsl:function>

<!-- Get the title of a topic by loading the topic from a topicref -->
<xsl:function name="com:get-topic-title" as="xs:string">
<xsl:param name="context" as="node()" required="yes"/>
<xsl:param name="topicref" as="element(topicref)" required="yes"/>
<xsl:sequence select="doc(com:abs-uri($context, $topicref/@href))/topic/title"/>
<xsl:sequence select="com:get-topic($context, $topicref)/title"/>
</xsl:function>

</xsl:stylesheet>
7 changes: 7 additions & 0 deletions cityehr-quick-start-guide/src/main/xslt/create-map-pdf.xslt
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@
</xsl:call-template>
</xsl:template>

<!-- TOC (Table of Contents) -->
<xsl:template match="map" mode="toc">
<xsl:call-template name="pcom:toc">
<xsl:with-param name="sections" select="topicref"/>
</xsl:call-template>
</xsl:template>

<!-- TOPIC - each is loaded from a 'topicref/@href' and processed -->
<xsl:template match="topicref" mode="topic-pages">
<xsl:apply-templates select="doc(com:abs-uri(., @href))/topic" mode="topic-pages"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@

<!-- PAGE CONTENT HEADER -->
<xsl:template match="topic" mode="body">
<fo:block background-color="#B84747" color="#FFFFFF" font-weight="bold" font-size="14pt" display-align="center" margin-bottom="11pt">
<fo:block background-color="#B84747" color="#FFFFFF" font-weight="bold" font-size="14pt" display-align="center" margin-bottom="11pt" id="topic-{generate-id()}">
<fo:block margin-left="8pt"><xsl:value-of select="title"/></fo:block>
</fo:block>
<xsl:apply-templates select="body" mode="body"/>
Expand Down

0 comments on commit fad2bab

Please sign in to comment.