Skip to content
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
91 changes: 48 additions & 43 deletions htmlbook-xsl/elements.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@

<xsl:template match="h:span[@data-type='footnote']" mode="footnote.marker" name="footnote-marker">
<xsl:param name="footnote.reset.numbering.at.chapter.level" select="$footnote.reset.numbering.at.chapter.level"/>
<sup>
<a data-type="noteref">
<xsl:attribute name="id">
<xsl:call-template name="object.id"/>
Expand All @@ -296,63 +297,67 @@
<xsl:attribute name="href">
<xsl:call-template name="href.target"/>
</xsl:attribute>
<sup>
<!-- Use numbers for footnotes -->
<!-- ToDo: Parameterize for numeration type and/or symbols? -->
<xsl:apply-templates select="." mode="footnote.number">
<xsl:with-param name="footnote.reset.numbering.at.chapter.level" select="$footnote.reset.numbering.at.chapter.level"/>
</xsl:apply-templates>
</sup>
</a>
</sup>
</xsl:template>

<!-- Handling for footnoterefs a la DocBook (cross-references to an existing footnote) -->
<xsl:template match="h:a[@data-type='footnoteref']">
<xsl:param name="footnote.reset.numbering.at.chapter.level" select="$footnote.reset.numbering.at.chapter.level"/>
<xsl:param name="process.footnotes" select="$process.footnotes"/>
<xsl:variable name="referenced-footnote-id">
<!-- Assuming that href is in the format href="#footnote_id" -->
<xsl:value-of select="substring-after(@href, '#')"/>
</xsl:variable>
<xsl:variable name="referenced-footnote" select="key('footnote-nodes-by-id', $referenced-footnote-id)"/>

<xsl:choose>
<xsl:when test="$process.footnotes = 1">
<xsl:variable name="referenced-footnote-id">
<!-- Assuming that href is in the format href="#footnote_id" -->
<xsl:value-of select="substring-after(@href, '#')"/>
</xsl:variable>
<xsl:variable name="referenced-footnote" select="key('footnote-nodes-by-id', $referenced-footnote-id)"/>
<xsl:choose>
<xsl:when test="count($referenced-footnote) &gt; 0">
<!-- Switch the context node to that of the referenced footnote -->
<xsl:for-each select="$referenced-footnote[1]">
<xsl:when test="count($referenced-footnote) &gt; 0">
<!-- Switch the context node to that of the referenced footnote -->
<xsl:for-each select="$referenced-footnote[1]">
<xsl:variable name="footnoteref.number">
<!-- Use numbers for footnotes -->
<!-- ToDo: Parameterize for numeration type and/or symbols? -->
<xsl:apply-templates select="." mode="footnote.number">
<xsl:with-param name="footnote.reset.numbering.at.chapter.level" select="$footnote.reset.numbering.at.chapter.level"/>
</xsl:apply-templates>
</xsl:variable>
<xsl:choose>
<xsl:when test="$process.footnotes = 1">
<!-- Same general handling as regular footnote markers, except footnoterefs don't get ids -->
<a data-type="noteref">
<xsl:attribute name="href">
<xsl:call-template name="href.target"/>
</xsl:attribute>
<sup>
<!-- Use numbers for footnotes -->
<!-- ToDo: Parameterize for numeration type and/or symbols? -->
<xsl:apply-templates select="." mode="footnote.number">
<xsl:with-param name="footnote.reset.numbering.at.chapter.level" select="$footnote.reset.numbering.at.chapter.level"/>
</xsl:apply-templates>
</sup>
</a>
</xsl:for-each>
</xsl:when>
<xsl:otherwise>
<!-- Uh oh, couldn't find the corresponding footnote for the footnoteref -->
<xsl:call-template name="log-message">
<xsl:with-param name="type" select="'WARNING'"/>
<xsl:with-param name="message">
<xsl:text>Error: Could not find footnote referenced by footnoteref link </xsl:text>
<xsl:value-of select="@href"/>
<xsl:text>. Footnote marker will not be generated.</xsl:text>
</xsl:with-param>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
<sup>
<a data-type="noteref">
<xsl:attribute name="href">
<xsl:call-template name="href.target"/>
</xsl:attribute>
<xsl:value-of select="$footnoteref.number"/>
</a>
</sup>
</xsl:when>
<xsl:otherwise>
<!-- If footnotes are not being processed, just output a sup with correct marker number -->
<sup class="footnoteref">
<xsl:value-of select="$footnoteref.number"/>
</sup>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:when>
<xsl:otherwise>
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
<!-- Uh oh, couldn't find the corresponding footnote for the footnoteref -->
<xsl:call-template name="log-message">
<xsl:with-param name="type" select="'WARNING'"/>
<xsl:with-param name="message">
<xsl:text>Error: Could not find footnote referenced by footnoteref link </xsl:text>
<xsl:value-of select="@href"/>
<xsl:text>. Footnote marker will not be generated.</xsl:text>
</xsl:with-param>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
Expand Down Expand Up @@ -403,19 +408,19 @@
<xsl:attribute name="id">
<xsl:call-template name="object.id"/>
</xsl:attribute>
<sup>
<a>
<xsl:attribute name="href">
<xsl:call-template name="href.target"/>
<xsl:text>-marker</xsl:text>
</xsl:attribute>
<sup>
<!-- Use numbers for footnotes -->
<!-- ToDo: Parameterize for numeration type and/or symbols? -->
<xsl:apply-templates select="." mode="footnote.number">
<xsl:with-param name="footnote.reset.numbering.at.chapter.level" select="$footnote.reset.numbering.at.chapter.level"/>
</xsl:apply-templates>
</sup>
</a>
</sup>
<xsl:text> </xsl:text>
<xsl:apply-templates/>
</p>
Expand Down
44 changes: 22 additions & 22 deletions htmlbook-xsl/xspec/elements.xspec
Original file line number Diff line number Diff line change
Expand Up @@ -1454,9 +1454,9 @@ sect5:1
<x:param name="process.footnotes" select="1"/>
</x:context>
<x:expect label="Footnote should be processed to a noteref">
<a data-type="noteref" id="fn_id_yo-marker" href="#fn_id_yo">
<sup>1</sup>
</a>
<sup>
<a data-type="noteref" id="fn_id_yo-marker" href="#fn_id_yo">1</a>
</sup>
</x:expect>
</x:scenario>
</x:scenario>
Expand Down Expand Up @@ -1502,9 +1502,9 @@ sect5:1
<x:param name="footnote.reset.numbering.at.chapter.level" select="0"/>
</x:context>
<x:expect label="Footnote should be processed to a noteref with proper number">
<a data-type="noteref" id="..." href="...">
<sup>4</sup>
</a>
<sup>
<a data-type="noteref" id="..." href="...">4</a>
</sup>
</x:expect>
</x:scenario>

Expand All @@ -1514,9 +1514,9 @@ sect5:1
<x:param name="footnote.reset.numbering.at.chapter.level" select="1"/>
</x:context>
<x:expect label="Footnote should be processed to a noteref with proper number">
<a data-type="noteref" id="..." href="...">
<sup>2</sup>
</a>
<sup>
<a data-type="noteref" id="..." href="...">2</a>
</sup>
</x:expect>
</x:scenario>

Expand All @@ -1527,7 +1527,7 @@ sect5:1
</x:context>
<x:expect label="Footnote should be processed to a para with anchor and proper number">
<p data-type="footnote" id="...">
<a href="..."><sup>4</sup></a> Footnote #2 in Chapter #2</p>
<sup><a href="...">4</a></sup> Footnote #2 in Chapter #2</p>
</x:expect>
</x:scenario>

Expand All @@ -1538,7 +1538,7 @@ sect5:1
</x:context>
<x:expect label="Footnote should be processed to a para with anchor and proper number">
<p data-type="footnote" id="...">
<a href="..."><sup>2</sup></a> Footnote #2 in Chapter #2</p>
<sup><a href="...">2</a></sup> Footnote #2 in Chapter #2</p>
</x:expect>
</x:scenario>

Expand All @@ -1548,9 +1548,9 @@ sect5:1
<x:param name="footnote.reset.numbering.at.chapter.level" select="0"/>
</x:context>
<x:expect label="Footnote should be processed to a noteref with proper number">
<a data-type="noteref" href="...">
<sup>8</sup>
</a>
<sup>
<a data-type="noteref" href="...">8</a>
</sup>
</x:expect>
</x:scenario>

Expand All @@ -1560,9 +1560,9 @@ sect5:1
<x:param name="footnote.reset.numbering.at.chapter.level" select="1"/>
</x:context>
<x:expect label="Footnote should be processed to a noteref with proper number">
<a data-type="noteref" href="...">
<sup>2</sup>
</a>
<sup>
<a data-type="noteref" href="...">2</a>
</sup>
</x:expect>
</x:scenario>

Expand Down Expand Up @@ -1649,8 +1649,8 @@ sect5:1
<x:context>
<x:param name="process.footnotes" select="0"/>
</x:context>
<x:expect label="Footnoteref should be copied to output as is">
<a data-type="footnoteref" href="#best_footnote_ever"/>
<x:expect label="Footnoteref should be processed to marker with correct number">
<sup class="footnoteref">2</sup>
</x:expect>
</x:scenario>

Expand All @@ -1659,9 +1659,9 @@ sect5:1
<x:param name="process.footnotes" select="1"/>
</x:context>
<x:expect label="Footnote should be processed to a noteref">
<a data-type="noteref" href="...">
<sup>2</sup>
</a>
<sup>
<a data-type="noteref" href="...">2</a>
</sup>
</x:expect>
</x:scenario>
</x:scenario>
Expand Down
29 changes: 29 additions & 0 deletions htmlbook-xsl/xspec/epub.xspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>

<x:description xmlns:x="http://www.jenitennison.com/xslt/xspec"
xmlns:functx="http://www.functx.com"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:ncx="http://www.daisy.org/z3986/2005/ncx/"
xmlns:dcterms="http://purl.org/dc/terms/"
xmlns:opf="http://www.idpf.org/2007/opf"
xmlns:h="http://www.w3.org/1999/xhtml"
xmlns:e="http://github.com/oreillymedia/epubrenderer"
xmlns:epub="http://www.idpf.org/2007/ops"
stylesheet="../epub.xsl">

<!-- Test suite for epub.xsl -->

<x:scenario label="When a data-type attribute is matched">
<x:context select="(/h:aside)[1]">
<aside data-type="sidebar">
<h5>Sidebar title</h5>
<p>Some text</p>
</aside>
</x:context>
<x:expect label="It should be propagated to output as is, and also in a epub:type attribute (if part of the EPUB SSV)">
<aside data-type="sidebar" epub:type="sidebar">...</aside>
</x:expect>
</x:scenario>

</x:description>
25 changes: 13 additions & 12 deletions htmlbook-xsl/xspec/ncx.xspec
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ sect5:none
<x:expect label="It should have the standard ncx root element">
<ncx xmlns="http://www.daisy.org/z3986/2005/ncx/" version="2005-1">...</ncx>
</x:expect>

<x:expect label="It should have the book title in a docTitle element" test="exists(/ncx:ncx/ncx:docTitle[. = 'Infinite Jest'])"/>

<x:expect label="It should have a navMap with navPoint children for TOC elements" test="exists(/ncx:ncx/ncx:navMap[ncx:navPoint])"/>

<x:expect label="navPoints should have playOrder attributes in consecutive order"
test="not(exists(//ncx:navPoint[not(@playOrder)])) and
count((//ncx:navPoint)[position() = @playOrder]) = count((//ncx:navPoint))"/>

<x:scenario label="With generate.cover.html disabled">
<x:call>
Expand All @@ -63,14 +71,7 @@ sect5:none
</x:scenario>
</x:pending>

<x:expect label="It should have the book title in a docTitle element" test="exists(/ncx:ncx/ncx:docTitle[. = 'Infinite Jest'])"/>

<x:expect label="It should have a navMap with navPoint children for TOC elements" test="exists(/ncx:ncx/ncx:navMap[ncx:navPoint])"/>

<x:expect label="navPoints should have playOrder attributes in consecutive order"
test="not(exists(//ncx:navPoint[not(@playOrder)])) and
count((//ncx:navPoint)[position() = @playOrder]) = count((//ncx:navPoint))"/>
</x:scenario>
</x:scenario>

<x:scenario label="When a book section/div is matched in ncx.toc.gen mode">
<x:context mode="ncx.toc.gen">
Expand Down Expand Up @@ -155,6 +156,10 @@ sect5:none
<x:expect label="A navLabel element should be generated with properly formatted heading text"
test="count(ncx:navPoint/ncx:navLabel[contains(., 'Tables of Crucial Data')]) = 1"/>

<!-- More robust testing here for src attribute value might be nice. -->
<x:expect label="A navPoint element should contain a content element with a src attribute"
test="exists(ncx:navPoint/ncx:content[@src])"/>

<x:scenario label="with $ncx.toc.include.label enabled">
<x:call>
<x:param name="ncx.toc.include.labels" select="1"/>
Expand Down Expand Up @@ -186,10 +191,6 @@ sect5:none
test="not(exists(ncx:navPoint/ncx:navLabel/ncx:text/*))"/>
</x:scenario>

<!-- More robust testing here for src attribute value might be nice. -->
<x:expect label="A navPoint element should contain a content element with a src attribute"
test="exists(ncx:navPoint/ncx:content[@src])"/>

</x:scenario>

</x:description>
13 changes: 7 additions & 6 deletions htmlbook-xsl/xspec/opf.xspec
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,7 @@ UbuntuMono-Regular.otf

<x:scenario label="When generate.opf is run">
<x:call template="generate.opf.content"/>
<x:scenario label="with generate.guide disabled">
<x:call>
<x:param name="generate.guide" select="0"/>
</x:call>
<x:expect test="not(exists(/opf:package/opf:guide))"/>
</x:scenario>

<x:expect label="A package root element should be generated with the proper namespaces">
<package xmlns="http://www.idpf.org/2007/opf"
xmlns:opf="http://www.idpf.org/2007/opf"
Expand All @@ -77,6 +72,12 @@ UbuntuMono-Regular.otf
<x:expect label="The OPF package should contain a manifest element" test="exists(/opf:package/opf:manifest)"/>
<x:expect label="The OPF package should contain a spine element" test="exists(/opf:package/opf:spine)"/>
<x:expect label="The OPF package should contain a guide element by default" test="exists(/opf:package/opf:guide)"/>
<x:scenario label="with generate.guide disabled">
<x:call>
<x:param name="generate.guide" select="0"/>
</x:call>
<x:expect label="The OPF package should not contain a guide element" test="not(exists(/opf:package/opf:guide))"/>
</x:scenario>
</x:scenario>

<x:scenario label="When opf.manifest is run">
Expand Down