Skip to content

Commit

Permalink
Handle sections within an LwDITA topic
Browse files Browse the repository at this point in the history
  • Loading branch information
adamretter committed Oct 24, 2024
1 parent 377fff2 commit 2cc9509
Show file tree
Hide file tree
Showing 5 changed files with 134 additions and 29 deletions.
48 changes: 47 additions & 1 deletion cityehr-quick-start-guide/src/main/xslt/common-html.xslt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:com="http://cityehr/common"
xmlns:hcom="http://cityehr/html/common"
exclude-result-prefixes="xs hcom"
version="2.0">
Expand All @@ -11,6 +12,8 @@
Author: Adam Retter
-->

<xsl:import href="common.xslt"/>

<xsl:template name="hcom:meta">
<xsl:param name="authors" as="xs:string+" required="yes"/>
<xsl:param name="created-date" as="xs:date?" required="no"/>
Expand All @@ -35,7 +38,50 @@
<meta name="author" content="{.}"/>
</xsl:for-each>
</xsl:template>


<!-- TOC (Table of Contents) -->
<xsl:template name="hcom:toc">
<xsl:param name="sections" as="element()+"/>
<ol class="toc" style="list-style-type: none;">
<xsl:for-each select="$sections">
<xsl:variable name="section" select="if (local-name(.) eq 'topicref') then com:get-topic(., .) else ."/>
<xsl:call-template name="hcom:toc-entry">
<xsl:with-param name="section" select="$section"/>
<xsl:with-param name="level">1</xsl:with-param>
<xsl:with-param name="numbers" select="position()"/>
<xsl:with-param name="page-url" select="hcom:dita-filename-to-html(@href)"/>
</xsl:call-template>
</xsl:for-each>
</ol>
</xsl:template>

<!-- Entry in the TOC (Table of Contents) -->
<xsl:template name="hcom:toc-entry">
<xsl:param name="section" as="element()" required="yes"/>
<xsl:param name="level" as="xs:integer" required="yes"/>
<xsl:param name="numbers" as="xs:integer*" required="no"/>
<xsl:param name="page-url" as="xs:string?" required="yes"/>

<xsl:variable name="section-id" select="generate-id($section)"/>

<!-- section -->
<li><xsl:value-of select="string-join($numbers, '.')"/><xsl:text>. </xsl:text><a name="{$section-id}" href="{$page-url}"><xsl:value-of select="$section/title"/></a></li>

<!-- then process sub sections recursively (no more than 4 levels deep!) -->
<xsl:if test="$level le 4">
<ol style="list-style-type: none;">
<xsl:for-each select="$section/body/section|$section/section">
<xsl:call-template name="hcom:toc-entry">
<xsl:with-param name="section" select="."/>
<xsl:with-param name="level" select="$level + 1"/>
<xsl:with-param name="numbers" select="($numbers, position())"/>
<xsl:with-param name="page-url" select="string-join(($page-url, @id), '#')"/>
</xsl:call-template>
</xsl:for-each>
</ol>
</xsl:if>
</xsl:template>

<!--
Changes a DITA filename to a HTML filename, e.g. 'thing.dita' -> 'thing.html'
-->
Expand Down
50 changes: 38 additions & 12 deletions cityehr-quick-start-guide/src/main/xslt/common-pdf.xslt
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@
</fo:flow>
</fo:page-sequence>
</xsl:template>

<!-- TOC (Table of Contents) -->
<xsl:template name="pcom:toc">
<xsl:param name="sections" as="element()+"/>
Expand All @@ -143,22 +143,48 @@
<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:variable name="section" select="if (local-name(.) eq 'topicref') then com:get-topic(., .) else ."/>
<xsl:call-template name="pcom:toc-entry">
<xsl:with-param name="section" select="$section"/>
<xsl:with-param name="level">1</xsl:with-param>
<xsl:with-param name="numbers" select="position()"/>
</xsl:call-template>
</xsl:for-each>
</fo:flow>
</fo:page-sequence>
</xsl:template>

<!-- Entry in the TOC (Table of Contents) -->
<xsl:template name="pcom:toc-entry">
<xsl:param name="section" as="element()" required="yes"/>
<xsl:param name="level" as="xs:integer" required="yes"/>
<xsl:param name="numbers" as="xs:integer*" required="no"/>

<xsl:variable name="section-id" select="generate-id($section)"/>

<!-- section -->
<fo:block text-align-last="justify">
<fo:basic-link internal-destination="section-{$section-id}" padding-left="{33 * ($level - 1)}pt">
<xsl:value-of select="string-join($numbers, '.')"/>
<!-- xsl:number level="single" count="$sections"/ -->
<xsl:text>. </xsl:text><xsl:value-of select="$section/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="section-{$section-id}"/>
</fo:basic-link>
</fo:block>
<!-- then process sub sections recursively (no more than 4 levels deep!) -->
<xsl:if test="$level le 4">
<xsl:for-each select="$section/body/section|$section/section">
<xsl:call-template name="pcom:toc-entry">
<xsl:with-param name="section" select="."/>
<xsl:with-param name="level" select="$level + 1"/>
<xsl:with-param name="numbers" select="($numbers, position())"/>
</xsl:call-template>
</xsl:for-each>
</xsl:if>
</xsl:template>

<!-- LAST PAGE -->
<xsl:template name="pcom:last-page">
<fo:page-sequence master-reference="PageMaster" id="last-page">
Expand Down
20 changes: 10 additions & 10 deletions cityehr-quick-start-guide/src/main/xslt/create-map-html.xslt
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,7 @@
<xsl:if test="exists($download-pdf-filename)">
<div id="download-pdf-version"><a href="{$download-pdf-filename}">Download PDF version</a></div>
</xsl:if>
<secton>
<h2>Table of Contents</h2>
<ol class="toc">
<xsl:apply-templates select="topicref" mode="create-topic-html"/>
<xsl:apply-templates select="topicref" mode="toc"/>
</ol>
</secton>
<xsl:apply-templates select="." mode="toc"/>
</article>
</body>
</html>
Expand All @@ -82,9 +76,15 @@
</xsl:result-document>
</xsl:template>

<!-- Put an entry in the Table of Contents for each topic that is referenced -->
<xsl:template match="topicref" mode="toc">
<li><a href="{hcom:dita-filename-to-html(@href)}"><xsl:value-of select="com:get-topic-title(., .)"/></a></li>
<!-- TOC (Table of Contents) -->
<xsl:template match="map" mode="toc">
<secton>
<h2>Table of Contents</h2>
<xsl:apply-templates select="topicref" mode="create-topic-html"/>
<xsl:call-template name="hcom:toc">
<xsl:with-param name="sections" select="topicref"/>
</xsl:call-template>
</secton>
</xsl:template>

<!-- OVERRIDE this template from create-topic-html.xsd so that we can add previous and following links -->
Expand Down
28 changes: 27 additions & 1 deletion cityehr-quick-start-guide/src/main/xslt/create-topic-html.xslt
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,33 @@
<xsl:apply-templates mode="body"/>
</a>
</xsl:template>


<xsl:template match="section" mode="body">
<section>
<xsl:apply-templates select="title|p|section" mode="body"/>
</section>
</xsl:template>

<xsl:template match="title[parent::section/parent::body]" mode="body">
<h2><xsl:value-of select="."/></h2>
</xsl:template>

<xsl:template match="title[parent::section/parent::section/parent::body]" mode="body">
<h3><xsl:value-of select="."/></h3>
</xsl:template>

<xsl:template match="title[parent::section/parent::section/parent::section/parent::body]" mode="body">
<h4><xsl:value-of select="."/></h4>
</xsl:template>

<xsl:template match="title[parent::section/parent::section/parent::section/parent::section/parent::body]" mode="body">
<h5><xsl:value-of select="."/></h5>
</xsl:template>

<xsl:template match="title[parent::section/parent::section/parent::section/parent::section/parent::section/parent::body]" mode="body">
<h6><xsl:value-of select="."/></h6>
</xsl:template>

<!--
Generates an Edit button URL for Petal
-->
Expand Down
17 changes: 12 additions & 5 deletions cityehr-quick-start-guide/src/main/xslt/create-topic-pdf.xslt
Original file line number Diff line number Diff line change
Expand Up @@ -64,27 +64,34 @@

<!-- 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" id="topic-{generate-id()}">
<fo:block background-color="#B84747" color="#FFFFFF" font-weight="bold" font-size="14pt" display-align="center" margin-bottom="11pt" id="section-{generate-id()}">
<fo:block margin-left="8pt"><xsl:value-of select="title"/></fo:block>
</fo:block>
<xsl:apply-templates select="body" mode="body"/>
</xsl:template>


<!-- PAGE CONTENT -->

<xsl:template match="body" mode="body">
<fo:block id="body-{generate-id()}">
<xsl:apply-templates select="p" mode="body"/>
<xsl:apply-templates select="p|section" mode="body"/>
</fo:block>
</xsl:template>


<xsl:template match="section" mode="body">
<fo:block background-color="#F17C7C" color="#FFFFFF" font-weight="bold" font-size="10pt" display-align="center" margin-bottom="11pt" id="section-{generate-id()}">
<fo:block margin-left="8pt"><xsl:value-of select="title"/></fo:block>
</fo:block>
<xsl:apply-templates select="p|section" mode="body"/>
</xsl:template>

<xsl:template match="p" mode="body">
<fo:block space-after="4pt"> <!-- NOTE(AR): 4pt spacing after each paragraph -->
<xsl:apply-templates select="node()" mode="body"/>
</fo:block>
</xsl:template>

<xsl:template match="i|em" mode="body">
<fo:inline font-style="italic"><xsl:apply-templates select="node()" mode="body"/></fo:inline>
</xsl:template>
Expand Down

0 comments on commit 2cc9509

Please sign in to comment.