Skip to content

Commit

Permalink
Fixes to generate-toc.xsl
Browse files Browse the repository at this point in the history
- The href attributes should start with #
- In HTML, id attributes may contain # or any other characters, so they
  need to be URL encoded when part of URL fragment (see
  #24)
  • Loading branch information
bertfrees committed Sep 15, 2020
1 parent 8a0893b commit cd195dd
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<xsl:param name="heading-names" select="''"/>

<xsl:include href="http://www.daisy.org/pipeline/modules/common-utils/generate-id.xsl"/>
<xsl:include href="http://www.daisy.org/pipeline/modules/file-utils/library.xsl"/>

<xsl:variable name="depth" as="xs:integer" select="if ($toc-depth) then xs:integer($toc-depth) else 6"/>

Expand Down Expand Up @@ -262,7 +263,7 @@
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:attribute name="href" select="$id"/>
<xsl:attribute name="href" select="concat('#',encode-for-uri($id))"/>
<xsl:if test="not(@xml:base)">
<xsl:variable name="header-base-uri" as="xs:anyURI" select="base-uri(.)"/>
<xsl:if test="not($header-base-uri=$root-base-uri)">
Expand Down
32 changes: 16 additions & 16 deletions braille/xml-to-pef/src/test/xprocspec/test_generate-toc.xprocspec
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<p>...</p>
<h2 xml:id="b">Heading 1.2</h2>
<p>...</p>
<h1>Heading 2</h1>
<h1 id="#c">Heading 2</h1>
<h2>Heading 2.1</h2>
<p>...</p>
<h2>Heading 2.2</h2>
Expand All @@ -34,33 +34,33 @@
<html xmlns="http://www.w3.org/1999/xhtml">
<ol id="generated-document-toc">
<li>
<a href="h_1">Heading 1</a>
<a href="#h_1">Heading 1</a>
<ol>
<li><a href="a">Heading 1.1</a></li>
<li><a href="b">Heading 1.2</a></li>
<li><a href="#a">Heading 1.1</a></li>
<li><a href="#b">Heading 1.2</a></li>
</ol>
</li>
<li>
<a href="h_2">Heading 2</a>
<a href="#%23c">Heading 2</a>
<ol>
<li><a href="h_3">Heading 2.1</a></li>
<li><a href="h_4">Heading 2.2</a></li>
<li><a href="#h_2">Heading 2.1</a></li>
<li><a href="#h_3">Heading 2.2</a></li>
</ol>
</li>
</ol>
<ol id="generated-volume-toc">
<li>
<a href="h_1">Heading 1</a>
<a href="#h_1">Heading 1</a>
<ol>
<li><a href="a">Heading 1.1</a></li>
<li><a href="b">Heading 1.2</a></li>
<li><a href="#a">Heading 1.1</a></li>
<li><a href="#b">Heading 1.2</a></li>
</ol>
</li>
<li>
<a href="h_2">Heading 2</a>
<a href="#%23c">Heading 2</a>
<ol>
<li><a href="h_3">Heading 2.1</a></li>
<li><a href="h_4">Heading 2.2</a></li>
<li><a href="#h_2">Heading 2.1</a></li>
<li><a href="#h_3">Heading 2.2</a></li>
</ol>
</li>
</ol>
Expand All @@ -70,10 +70,10 @@
<p>...</p>
<h2 xml:id="b">Heading 1.2</h2>
<p>...</p>
<h1 xml:id="h_2">Heading 2</h1>
<h2 xml:id="h_3">Heading 2.1</h2>
<h1 id="#c">Heading 2</h1>
<h2 xml:id="h_2">Heading 2.1</h2>
<p>...</p>
<h2 xml:id="h_4">Heading 2.2</h2>
<h2 xml:id="h_3">Heading 2.2</h2>
<p>...</p>
</body>
</html>
Expand Down

0 comments on commit cd195dd

Please sign in to comment.