Skip to content

Commit

Permalink
tei->html: rewrote index generation
Browse files Browse the repository at this point in the history
  • Loading branch information
EsGeh authored and EsGeh committed Nov 7, 2019
1 parent 5bc9cdf commit 01cfd75
Show file tree
Hide file tree
Showing 4 changed files with 195 additions and 114 deletions.
27 changes: 25 additions & 2 deletions tei2html/tei2html.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@
<xsl:include href="utils/common.xsl"/>
<xsl:include href="utils/print.xsl"/>

<xsl:param name="output_dir" as="xs:string" select="'.'"/>
<xsl:param name="static_dir" as="xs:string" select="'static'"/>
<xsl:param name="output_dir" as="xs:string" select="'./output'"/>
<xsl:param name="static_dir" as="xs:string" select="'../static'"/>
<xsl:param name="intermediate_dir" as="xs:string?" select="concat($output_dir, '/intermediate')"/>
<xsl:param name="logo_dir" as="xs:string" select="concat($static_dir, '/assets/images')"/>
<xsl:param name="nav_items" as="element(eoa:entry)*">
<eoa:entry active="1">
Expand All @@ -40,6 +41,27 @@
<xsl:variable name="output_subdir" as="xs:string">
<xsl:value-of select="concat($output_dir, '/', $series, '/', $publication_number)"/>
</xsl:variable>
<xsl:variable name="indices" as="element(eoa:index)*">
<xsl:variable name="ctxt" select="."/>
<xsl:for-each select="$index_types">
<xsl:variable name="index_type" as="xs:string" select="."/>
<xsl:for-each select="$ctxt">
<xsl:call-template name="create_index">
<xsl:with-param name="indextype" select="$index_type"/>
</xsl:call-template>
</xsl:for-each>
</xsl:for-each>
</xsl:variable>
<xsl:if test="$intermediate_dir">
<xsl:result-document
method="xml"
encoding="UTF-8"
indent="yes"
href="{concat($intermediate_dir, '/indices.xml')}"
>
<xsl:copy-of select="$indices"/>
</xsl:result-document>
</xsl:if>
<xsl:result-document
method="html"
encoding="UTF-8"
Expand All @@ -51,6 +73,7 @@
<xsl:with-param name="static_dir" select="concat('../../', $static_dir)"/>
<xsl:with-param name="logo_dir" select="concat('../../', $logo_dir)"/>
<xsl:with-param name="nav_items" as="element(eoa:entry)*" select="$nav_items"/>
<xsl:with-param name="indices" as="element(eoa:index)*" select="$indices"/>
</xsl:call-template>
</xsl:result-document>
<xsl:for-each select="//tei:div[@type='chapter']">
Expand Down
5 changes: 4 additions & 1 deletion tei2html/tei2html_chapter_utils.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,11 @@ tex2jax: {inlineMath: [["$","$"],["\\(","\\)"]]}
<xsl:call-template name="paragraph_id"/>
</xsl:for-each>
</xsl:variable>
<xsl:variable name="footnote_id" as="xs:string">
<xsl:call-template name="footnote_id"/>
</xsl:variable>
<xsl:if test="$paragraph_id">
<li id="fn{@n}">
<li id="{$footnote_id}">
<xsl:for-each select="tei:p">
<p><xsl:apply-templates mode="html"/></p>
</xsl:for-each>
Expand Down
202 changes: 111 additions & 91 deletions tei2html/tei2html_publ_frontpage_utils.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@
<!-- index sorting, https://stackoverflow.com/questions/13763271 -->
<xsl:key name="kWith1stLetter" match="family" use="substring(.,1,1)"/>

<xsl:variable name="index_types" as="xs:string*" select="('keyword', 'location', 'person')"/>

<xsl:template name="render_publication_frontpage">
<xsl:param name="static_dir" as="xs:string"/>
<xsl:param name="logo_dir" as="xs:string"/>
<xsl:param name="nav_items" as="element(eoa:entry)*"/>
<xsl:param name="indices" as="element(eoa:index)*"/>
<xsl:call-template name="website_template">
<xsl:with-param name="static_dir" select="$static_dir"/>
<xsl:with-param name="title">
Expand Down Expand Up @@ -354,55 +357,11 @@
</xsl:for-each>
</div>
</div>
<xsl:if test="//tei:body//tei:index[@indexName='keyword']">
<div class="tabs__content-item">
<div class="publications__index-name">
<div class="accordion">
<a class="accordion__showall" href="#">Show All</a>
<xsl:call-template name="create_index">
<xsl:with-param name="indextype" select="'keyword'"/>
</xsl:call-template>
<div class="accordion__item">
<a class="accordion__title" href="#">
<h2>B</h2>
</a>
<div class="accordion__content">
<h4>Peter Becksbaum</h4>
<ul>
<li>1</li>
<li>2</li>
</ul>
<a class="accordion__pageup" href="#"/>
</div>
</div>
</div>
</div>
</div>
</xsl:if>
<xsl:if test="//tei:body//tei:index[@indexName='location']">
<div class="tabs__content-item">
<div class="publications__index-name">
<div class="accordion">
<a class="accordion__showall" href="#">Show All</a>
<xsl:call-template name="create_index">
<xsl:with-param name="indextype" select="'location'"/>
</xsl:call-template>
</div>
</div>
</div>
</xsl:if>
<xsl:if test="//tei:body//tei:index[@indexName='person']">
<div class="tabs__content-item">
<div class="publications__index-name">
<div class="accordion">
<a class="accordion__showall" href="#">Show All</a>
<xsl:call-template name="create_index">
<xsl:with-param name="indextype" select="'person'"/>
</xsl:call-template>
</div>
</div>
</div>
</xsl:if>
<xsl:for-each select="$indices">
<xsl:call-template name="render_index">
<xsl:with-param name="indextype" select="@type"/>
</xsl:call-template>
</xsl:for-each>
</div>
</div>
</div>
Expand Down Expand Up @@ -504,50 +463,111 @@
</xsl:choose>
</xsl:template>

<xsl:template name="create_index">
<xsl:template name="render_index" as="element()*">
<xsl:param name="indextype"/>
<xsl:sequence select="eoa:info('creating index')"/>
<!-- all index elements starting with the same letter: -->
<xsl:for-each-group select="//tei:index[lower-case(@indexName) = $indextype]" group-by="substring(if (exists(./tei:term/@sortKey)) then ./tei:term/@sortKey else ./tei:term/text(),1,1)">
<xsl:sort select="current-grouping-key()"/>
<xsl:variable name="chapter" select="ancestor::tei:div[@type = 'chapter']"/>
<xsl:variable name="chapter_nr" select="count($chapter/preceding-sibling::*)"/>
<div class="accordion__item">
<a class="accordion__title" href="#">
<h2 class="border">
<xsl:value-of select="current-grouping-key()"/>
</h2>
</a>
<div class="accordion__content">
<!-- all index elements with the same "term": -->
<xsl:for-each-group select="current-group()" group-by="if (exists(tei:term/@sortKey)) then tei:term/@sortKey else tei:term/text()">
<xsl:sort select="current-grouping-key()"/>
<h4>
<xsl:value-of select="current-grouping-key()"/>
</h4>
<ul>
<xsl:for-each select="current-group()">
<xsl:variable name="paragraph_nr" select="index-of($chapter//tei:p/tei:index/generate-id(), generate-id(.))"/>
<xsl:variable name="local_uri" select="concat($series, '/', $publication_number, '/', $chapter_nr , '/index.html#', $paragraph_nr)"/>
<xsl:variable name="global_uri" select="concat($domain, '/', $local_uri)"/>
<xsl:sequence select="eoa:info(concat(current-grouping-key(), ': ', $global_uri))"/>
<li>
<a href="{$global_uri}"> <xsl:value-of select="position()"/></a>
</li>
</xsl:for-each>
</ul>
<!-- below that, ul/li for each jumping point -->
<div class="tabs__content-item">
<div class="publications__index-name">
<div class="accordion">
<a class="accordion__showall" href="#">Show All</a>
<xsl:for-each-group
select="eoa:term"
group-by="substring(@key,1,1)"
>
<div class="accordion__item">
<a class="accordion__title" href="#">
<h2 class="border">
<xsl:value-of select="current-grouping-key()"/>
</h2>
</a>
<div class="accordion__content">
<xsl:for-each
select="current-group()"
>
<h4>
<xsl:value-of select="@key"/>
</h4>
<ul>
<xsl:for-each select="eoa:entry">
<li>
<a href="{concat(string-join(($domain, eoa:link/eoa:entry[position() != last()]),'/'), '/index.html#', eoa:link/eoa:entry[last()])}"> <xsl:value-of select="position()"/></a>
</li>
</xsl:for-each>
</ul>
</xsl:for-each>
</div>
</div>
</xsl:for-each-group>
</div>
</div>
<!--
<xsl:message>
<xsl:value-of select="$sortkey"/>
<xsl:text>: </xsl:text>
<xsl:value-of select="./tei:term//text()"/>
</xsl:message>
-->
</xsl:for-each-group>
</div>
</div>
</div>
</xsl:template>

<xsl:template name="create_index" as="element(eoa:index)">
<xsl:param name="indextype"/>
<xsl:sequence select="eoa:info(concat('creating index ', $indextype))"/>
<!-- all index elements starting with the same letter: -->
<eoa:index type="{$indextype}">
<xsl:for-each-group
select="//tei:body//tei:index[lower-case(@indexName) = $indextype][not(ancestor::tei:index)]"
group-by="if (exists(tei:term/@sortKey)) then tei:term/@sortKey else tei:term/text()"
>
<xsl:sort select="current-grouping-key()"/>
<eoa:term key="{current-grouping-key()}">
<xsl:for-each select="current-group()">
<xsl:sequence select="eoa:info(concat('adding index element ', tei:term, '!'))"/>
<xsl:variable name="chapter" select="ancestor::tei:div[@type = 'chapter']"/>
<xsl:variable name="chapter_nr" select="count($chapter/preceding-sibling::*)"/>
<xsl:variable name="dest_id" as="xs:string?">
<xsl:variable name="candidates" as="xs:string*">
<xsl:for-each select="ancestor::tei:*">
<xsl:variable name="footnote_id" as="xs:string?">
<xsl:call-template name="footnote_id"/>
</xsl:variable>
<xsl:variable name="paragraph_id" as="xs:string?">
<xsl:call-template name="paragraph_id"/>
</xsl:variable>
<xsl:choose>
<xsl:when test="$footnote_id">
<xsl:value-of select="$footnote_id"/>
</xsl:when>
<xsl:when test="$paragraph_id">
<xsl:value-of select="$paragraph_id"/>
</xsl:when>
</xsl:choose>
</xsl:for-each>
</xsl:variable>
<xsl:value-of select="if( count($candidates) != 0) then $candidates[1] else ()"/>
</xsl:variable>
<xsl:choose>
<xsl:when test="not($dest_id)">
<xsl:sequence select="eoa:warning(concat('paragraph not found for index element ', tei:term, '!'))"/>
</xsl:when>
<xsl:otherwise>
<eoa:entry>
<eoa:tei-element>
<xsl:copy-of select="."/>
</eoa:tei-element>
<eoa:link>
<eoa:entry>
<xsl:value-of select="$series"/>
</eoa:entry>
<eoa:entry>
<xsl:value-of select="$publication_number"/>
</eoa:entry>
<eoa:entry>
<xsl:value-of select="$chapter_nr"/>
</eoa:entry>
<eoa:entry>
<xsl:value-of select="$dest_id"/>
</eoa:entry>
</eoa:link>
</eoa:entry>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</eoa:term>
</xsl:for-each-group>
</eoa:index>
<xsl:sequence select="eoa:info('finished creating index')"/>
</xsl:template>

Expand Down
75 changes: 55 additions & 20 deletions tei2html/utils/html_rules.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -182,23 +182,6 @@
<a class="accordion__pageup" href="#"></a>
</div>
</div>
<!--
<div id="{@xml:id}" class="accordion__item active">
<a class="accordion__title" href="#">
<h2>
<xsl:if test="../@n != 'nonumber'">
<xsl:value-of select="concat(../@n, '.', @n, ' ')"/>
</xsl:if>
<xsl:apply-templates select="tei:head" mode="text_structure"/>
</h2>
</a>
<div class="accordion__content">
<xsl:apply-templates select="*[not(self::tei:head)]" mode="text_structure"/>
- the link to close the accordion: -
<a class="accordion__pageup" href="#"/>
</div>
</div>
-->
</xsl:template>

<xsl:template mode="text_structure" match="tei:div[@type='subsection']">
Expand Down Expand Up @@ -230,6 +213,36 @@
<xsl:apply-templates mode="text_structure" select="*[not(self::tei:head)]"/>
</xsl:template>

<xsl:template mode="text_structure" match="tei:div[@type='letter']">
<xsl:sequence select="eoa:info('letter')"/>
<xsl:variable name="chapter" select="ancestor::tei:div[@type = 'chapter']"/>
<xsl:variable name="chapter_nr" select="count($chapter/preceding-sibling::*)"/>
<xsl:variable name="paragraph_id" as="xs:string"><xsl:call-template name="paragraph_id"/></xsl:variable>
<xsl:variable name="local_uri" select="concat($series, '/', $publication_number, '/', $chapter_nr , '/index.html#', $paragraph_id)"/>
<xsl:variable name="global_uri" select="concat($domain, '/', $local_uri)"/>
<xsl:call-template name="accordion_row">
<xsl:with-param name="link" as="xs:string" select="$global_uri"/>
<xsl:with-param name="content" as="element()*">
<xsl:if test="tei:head">
<h4>
<xsl:apply-templates mode="text_structure" select="tei:head"/>
</h4>
</xsl:if>
<p class="verse">
<xsl:for-each select="tei:p">
<xsl:apply-templates mode="html" select="node()"/>
<xsl:if test="position() != last()">
<br/>
</xsl:if>
</xsl:for-each>
</p>
<!--
<xsl:apply-templates mode="text_structure" select="*[not(self::tei:head)]"/>
-->
</xsl:with-param>
</xsl:call-template>
</xsl:template>

<!-- paragraph level elements: -->

<xsl:template mode="text_structure" match="tei:body//tei:head">
Expand Down Expand Up @@ -468,7 +481,10 @@
</xsl:template>

<xsl:template mode="html" match="tei:note[@place = 'bottom']">
<a href="#fn{@n}">
<xsl:variable name="footnote_id" as="xs:string?">
<xsl:call-template name="footnote_id"/>
</xsl:variable>
<a href="{concat('#', $footnote_id)}">
<sup>
<xsl:value-of select="@n"/>
</sup>
Expand Down Expand Up @@ -514,11 +530,30 @@
<!-- if the current element is a "paragraph level element", return its id in the document. Otherwise return the empty sequence -->
<xsl:template name="paragraph_id" as="xs:string?">
<xsl:choose>
<xsl:when test="(self::tei:p | self::tei:epigraph | self::tei:ab | self::tei:lg | self::tei:quote | self::tei:list | self::tei:table | self::tei:figure)[parent::tei:div[@type = ('chapter', 'section', 'subsection', 'subsubsection')]]">
<xsl:when test="(self::tei:p | self::tei:epigraph | self::tei:ab | self::tei:lg | self::tei:quote | self::tei:list | self::tei:table | self::tei:figure | self::tei:div[@type = 'letter'])[parent::tei:div[@type = ('chapter', 'section', 'subsection', 'subsubsection')] or parent::tei:div/parent::tei:div[@type = 'bilingual'] or parent::tei:div/parent::tei:div[@type = 'sidebyside']]">
<value-of>
<xsl:text>p</xsl:text>
<xsl:number
count="(tei:p | tei:epigraph | tei:ab | tei:lg | tei:quote | tei:list | tei:table | tei:figure)[parent::tei:div[@type = ('chapter', 'section', 'subsection', 'subsubsection')]]"
count="(tei:p | tei:epigraph | tei:ab | tei:lg | tei:quote | tei:list | tei:table | tei:figure | tei:div[@type = 'letter'])[parent::tei:div[@type = ('chapter', 'section', 'subsection', 'subsubsection')] or parent::tei:div/parent::tei:div[@type = 'bilingual'] or parent::tei:div/parent::tei:div[@type = 'sidebyside']]"
from="tei:div[@type = 'chapter']"
level="any"
/>
</value-of>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="()"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>

<!-- if the current element is a "paragraph level element", return its id in the document. Otherwise return the empty sequence -->
<xsl:template name="footnote_id" as="xs:string?">
<xsl:choose>
<xsl:when test="self::tei:note">
<value-of>
<xsl:text>fn</xsl:text>
<xsl:number
count="tei:note"
from="tei:div[@type = 'chapter']"
level="any"
/>
Expand Down

0 comments on commit 01cfd75

Please sign in to comment.