Skip to content

Commit

Permalink
Improve colophon: suppress common corrections.:
Browse files Browse the repository at this point in the history
  • Loading branch information
jhellingman committed Dec 25, 2017
1 parent 680b51b commit 845b71b
Show file tree
Hide file tree
Showing 3 changed files with 159 additions and 40 deletions.
174 changes: 138 additions & 36 deletions colophon.xsl
Expand Up @@ -66,7 +66,7 @@
<xsl:apply-templates select="/*[self::TEI.2 or self::TEI]/teiHeader/fileDesc/publicationStmt/availability"/>

<xsl:call-template name="colophonMetadata"/>
<xsl:call-template name="catalogEntries"/>
<!-- <xsl:call-template name="catalogEntries"/> -->

<xsl:if test="f:isValid(/*[self::TEI.2 or self::TEI]/teiHeader/encodingDesc)">
<h3 class="main"><xsl:value-of select="f:message('msgEncoding')"/></h3>
Expand Down Expand Up @@ -115,6 +115,7 @@

<xsl:call-template name="keywords"/>
<xsl:call-template name="classification"/>
<xsl:call-template name="catalogReferences"/>
</table>
</xsl:template>

Expand Down Expand Up @@ -156,6 +157,27 @@
</tr>
</xsl:function>

<xsl:function name="f:metadata-line-as-url">
<xsl:param name="key" as="xs:string"/>
<xsl:param name="value" as="xs:string"/>
<xsl:param name="url" as="xs:string?"/>

<tr>
<td><b><xsl:value-of select="if ($key = '') then '' else concat($key, ':')"/></b></td>
<td>
<xsl:choose>
<xsl:when test="f:isValid($url)">
<a href="{$url}" class="{f:translate-xref-class($url)}"><xsl:value-of select="$value"/></a>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$value"/>
</xsl:otherwise>
</xsl:choose>
</td>
<td/>
</tr>
</xsl:function>

<xsl:function name="f:metadata-line">
<xsl:param name="key" as="xs:string"/>
<xsl:param name="value" as="xs:string"/>
Expand Down Expand Up @@ -313,6 +335,49 @@
</xsl:function>


<xsl:template name="catalogReferences">
<xsl:apply-templates select="//idno[@type = 'PGnum'][f:isValid(.)]" mode="catalogReferences"/>
<xsl:apply-templates select="//idno[@type != 'PGnum'][f:isValid(.)]" mode="catalogReferences">
<xsl:sort select="@type"/>
</xsl:apply-templates>
</xsl:template>

<xsl:template mode="catalogReferences" match="idno[@type='PGnum']">
<xsl:copy-of select="f:metadata-line-as-url(f:message('msgProjectGutenberg'), ., concat('https://www.gutenberg.org/ebooks/', .))"/>
</xsl:template>

<xsl:template mode="catalogReferences" match="idno[@type='LCCN']">
<xsl:copy-of select="f:metadata-line-as-url(f:message('msgLibraryOfCongress'), ., concat('https://lccn.loc.gov/', .))"/>
</xsl:template>

<xsl:template mode="catalogReferences" match="idno[@type='VIAF']">
<xsl:copy-of select="f:metadata-line-as-url(f:message('msgViaf'), ., concat('http://viaf.org/viaf/', .))"/>
</xsl:template>

<xsl:template mode="catalogReferences" match="idno[@type='OLN']">
<xsl:copy-of select="f:metadata-line-as-url(f:message('msgOpenLibraryBook'), ., concat('https://openlibrary.org/books/', .))"/>
</xsl:template>

<xsl:template mode="catalogReferences" match="idno[@type='OLW']">
<xsl:copy-of select="f:metadata-line-as-url(f:message('msgOpenLibraryWork'), ., concat('https://openlibrary.org/works/', .))"/>
</xsl:template>

<xsl:template mode="catalogReferences" match="idno[@type='OCLC']">
<xsl:copy-of select="f:metadata-line-as-url(f:message('msgOclcWorldCat'), ., concat('https://www.worldcat.org/oclc/', .))"/>
</xsl:template>

<xsl:template mode="catalogReferences" match="idno[@type='LibThing']">
<xsl:copy-of select="f:metadata-line-as-url(f:message('msgLibraryThing'), ., concat('https://www.librarything.com/work/', .))"/>
</xsl:template>

<xsl:template mode="catalogReferences" match="idno[@type='PGSrc']">
<xsl:copy-of select="f:metadata-line-as-url(f:message('msgGitHub'), ., concat('https://github.com/GutenbergSource/', .))"/>
</xsl:template>

<!-- Ignore other types of idno's -->
<xsl:template mode="catalogReferences" match="idno"/>


<!--====================================================================-->
<!-- List of Corrections -->

Expand All @@ -321,7 +386,7 @@
<xd:detail>
<p>Generate a list of corrections made to the text, as indicated by <code>corr</code>-elements. Identical
corrections are grouped together. The page numbers link back to the <code>corr</code>-element as it
appears in the text.</p>
appears in the text (except when there are too many).</p>
</xd:detail>
</xd:doc>

Expand Down Expand Up @@ -365,55 +430,92 @@
<xsl:for-each-group select="$corrections/tmp:choice" group-by="concat(tmp:sic, '@@@', tmp:corr)">
<tr>
<td class="width20">
<xsl:for-each select="current-group()">
<xsl:if test="position() != 1">
<xsl:text>, </xsl:text>
</xsl:if>
<a class="pageref" href="{@href}"><xsl:value-of select="@page"/></a>
</xsl:for-each>
<xsl:call-template name="correctionTablePageReferences"/>
</td>

<td class="width40 bottom">
<xsl:choose>
<xsl:when test="tmp:sic != ''">
<xsl:apply-templates select="tmp:sic"/>
</xsl:when>
<xsl:otherwise>
[<i><xsl:value-of select="f:message('msgNotInSource')"/></i>]
</xsl:otherwise>
</xsl:choose>
<xsl:call-template name="correctionTableSourceText"/>
</td>

<td class="width40 bottom">
<xsl:choose>
<xsl:when test="tmp:corr != ''">
<xsl:apply-templates select="tmp:corr"/>
</xsl:when>
<xsl:otherwise>
[<i><xsl:value-of select="f:message('msgDeleted')"/></i>]
</xsl:otherwise>
</xsl:choose>
<xsl:call-template name="correctionTableCorrectedText"/>
</td>

<xsl:if test="f:isSet('colophon.showEditDistance')">
<td class="bottom">
<xsl:variable name="editDistance" select="f:levenshtein(tmp:sic, tmp:corr)" as="xs:integer"/>
<xsl:variable name="normalizedEditDistance" select="f:levenshtein(f:stripDiacritics(tmp:sic), f:stripDiacritics(tmp:corr))" as="xs:integer"/>
<xsl:value-of select="$editDistance"/>
<xsl:if test="$editDistance != $normalizedEditDistance">
<xsl:text> / </xsl:text>
<xsl:value-of select="$normalizedEditDistance"/>
</xsl:if>
<xsl:call-template name="correctionTableEditDistance"/>
</td>
</xsl:if>

</tr>
</xsl:for-each-group>

</table>
</xsl:template>


<xsl:template name="correctionTablePageReferences">
<xsl:choose>
<xsl:when test="count(current-group()) &gt; number(f:getSetting('colophon.maxCorrectionCount'))">

<xsl:variable name="params">
<params>
<param name="count"><xsl:value-of select="count(current-group())"/></param>
</params>
</xsl:variable>

<i>
<xsl:attribute name="title">
<xsl:call-template name="FormatMessage">
<xsl:with-param name="name" select="'msgCountOccurrences'"/>
<xsl:with-param name="params" select="$params"/>
</xsl:call-template>
</xsl:attribute>
<xsl:value-of select="f:message('msgPassim')"/>.
</i>
</xsl:when>
<xsl:otherwise>
<xsl:for-each select="current-group()">
<xsl:if test="position() != 1">
<xsl:text>, </xsl:text>
</xsl:if>
<a class="pageref" href="{@href}"><xsl:value-of select="@page"/></a>
</xsl:for-each>
</xsl:otherwise>
</xsl:choose>
</xsl:template>


<xsl:template name="correctionTableSourceText">
<xsl:choose>
<xsl:when test="tmp:sic != ''">
<xsl:apply-templates select="tmp:sic"/>
</xsl:when>
<xsl:otherwise>
[<i><xsl:value-of select="f:message('msgNotInSource')"/></i>]
</xsl:otherwise>
</xsl:choose>
</xsl:template>


<xsl:template name="correctionTableCorrectedText">
<xsl:choose>
<xsl:when test="tmp:corr != ''">
<xsl:apply-templates select="tmp:corr"/>
</xsl:when>
<xsl:otherwise>
[<i><xsl:value-of select="f:message('msgDeleted')"/></i>]
</xsl:otherwise>
</xsl:choose>
</xsl:template>


<xsl:template name="correctionTableEditDistance">
<xsl:variable name="editDistance" select="f:levenshtein(tmp:sic, tmp:corr)" as="xs:integer"/>
<xsl:variable name="normalizedEditDistance" select="f:levenshtein(f:stripDiacritics(tmp:sic), f:stripDiacritics(tmp:corr))" as="xs:integer"/>
<xsl:value-of select="$editDistance"/>
<xsl:if test="$editDistance != $normalizedEditDistance">
<xsl:text> / </xsl:text>
<xsl:value-of select="$normalizedEditDistance"/>
</xsl:if>
</xsl:template>


<xd:doc>
<xd:short>Convert a traditional <code>corr</code> element to a <code>tmp:choice</code> element.</xd:short>
</xd:doc>
Expand Down
1 change: 1 addition & 0 deletions configuration.xsl
Expand Up @@ -89,6 +89,7 @@
<colophon.showCorrections>true</colophon.showCorrections> <!-- Show a list of corrections in the colophon. -->
<colophon.showAbbreviations>true</colophon.showAbbreviations> <!-- Show a list of abbreviations in the colophon. -->
<colophon.showExternalReferences>true</colophon.showExternalReferences> <!-- Show a section on external references in the colophon. -->
<colophon.maxCorrectionCount>20</colophon.maxCorrectionCount> <!-- Maximum number of indentical corrections that will be listed individually in the list of corrections. -->

<!-- Output format specific settings: these override the general settings defined above for a specific output format. Supported formats: "html" and "epub". -->
<output format="html">
Expand Down
24 changes: 20 additions & 4 deletions messages.xml
Expand Up @@ -38,12 +38,23 @@
-->

<msg:message name="msgPassim">Passim</msg:message>
<msg:message name="msgCountOccurrences"><msg:param name="count"/> occurrences</msg:message>
<msg:message name="msgEditDistance">Edit distance</msg:message>
<msg:message name="msgAbbreviationOverview">Overview of abbreviations used.</msg:message>
<msg:message name="msgExpansion">Expansion</msg:message>
<msg:message name="msgExpansionNotAvailable">Expansion not available</msg:message>
<msg:message name="msgLinkToInternetArchive">Link to the Internet Archive</msg:message>

<msg:message name="msgProjectGutenberg">Project Gutenberg</msg:message>
<msg:message name="msgLibraryOfCongress">Library of Congress</msg:message>
<msg:message name="msgLibraryThing">LibraryThing</msg:message>
<msg:message name="msgViaf">Virtual International Authority File</msg:message>
<msg:message name="msgOpenLibraryBook">Open Library (Book)</msg:message>
<msg:message name="msgOpenLibraryWork">Open Library (Work)</msg:message>
<msg:message name="msgOclcWorldCat">OCLC/WorldCat</msg:message>
<msg:message name="msgGitHub">GitHub</msg:message>

<msg:message name="msgTitle">Title</msg:message>
<msg:message name="msgMetadata">Metadata</msg:message>
<msg:message name="msgInfo">Info</msg:message>
Expand Down Expand Up @@ -735,8 +746,8 @@

<msg:messages xml:lang="de">

<msg:message name="msgLinkToBible">Link zu zitierte Stelle in Bibel</msg:message>
<msg:message name="msgEditDistance">Edit-Distanz</msg:message>
<msg:message name="msgLinkToBible">Link zu zitierte Stelle in Bibel</msg:message>
<msg:message name="msgEditDistance">Edit-Distanz</msg:message>
<msg:message name="msgAbbreviationOverview">Übersicht der Abkürzungen im Text.</msg:message>
<msg:message name="msgExpansion">Ersetzung</msg:message>
<msg:message name="msgExpansionNotAvailable">Ersetzung nicht verfügbar</msg:message>
Expand Down Expand Up @@ -950,14 +961,19 @@

<msg:messages xml:lang="nl">

<msg:message name="msgPassim">Passim</msg:message>
<msg:message name="msgCountOccurrences"><msg:param name="count"/> gevallen</msg:message>
<msg:message name="msgOpenLibraryBook">Open Library (Boek)</msg:message>
<msg:message name="msgOpenLibraryWork">Open Library (Werk)</msg:message>

<msg:message name="msgAuthorAddition">Toevoeging door auteur</msg:message>
<msg:message name="msgCopyrightPage">Auteursrechtpagina</msg:message>

<msg:message name="msgEditDistance">Bewerkingsafstand</msg:message>
<msg:message name="msgAbbreviationOverview">Overzicht van gebruikte afkortingen.</msg:message>
<msg:message name="msgExpansion">Uitgeschreven</msg:message>
<msg:message name="msgExpansionNotAvailable">Uitgeschreven vorm niet beschikbaar</msg:message>
<msg:message name="msgReturnToSourceLocation">Terug naar plaats in bron</msg:message>
<msg:message name="msgReturnToSourceLocation">Terug naar plaats in bron</msg:message>

<msg:message name="msgTitle">Titel</msg:message>
<msg:message name="msgMetadata">Metadata</msg:message>
Expand All @@ -974,7 +990,7 @@
<msg:message name="msgOriginalBackCover">Originele achterkant</msg:message>
<msg:message name="msgOriginalFrontCover">Originele voorkant</msg:message>
<msg:message name="msgOriginalSpine">Originele Rug</msg:message>
<msg:message name="msgAuthorOfAfterword">Auteur van nawoord</msg:message>
<msg:message name="msgAuthorOfColophon">Auteur van colofon</msg:message>
<msg:message name="msgAuthorOfPostface">Auteur van naschrift</msg:message>
Expand Down

0 comments on commit 845b71b

Please sign in to comment.