Skip to content

Commit

Permalink
tei->html: refactoring. also: almost all paragraph elems have links now
Browse files Browse the repository at this point in the history
  • Loading branch information
EsGeh authored and EsGeh committed Nov 7, 2019
1 parent 3311f16 commit fa97c34
Showing 1 changed file with 97 additions and 109 deletions.
206 changes: 97 additions & 109 deletions tei2html/utils/html_rules.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,11 @@
</xsl:template>

<xsl:template mode="chapter_main" match="tei:div[@type='chapter']">
<xsl:variable name="chapter" select="self::tei:div[@type = 'chapter']"/>
<xsl:variable name="chapter_nr" select="count($chapter/preceding-sibling::*)"/>
<xsl:variable name="local_uri" select="concat($series, '/', $publication_number, '/', $chapter_nr , '/index.html')"/>
<xsl:variable name="global_uri" select="concat($domain, '/', $local_uri)"/>
<xsl:variable name="uri"><xsl:call-template name="calc_uri"/></xsl:variable>
<div class="accordion">
<div class="accordion__main">
<xsl:call-template name="accordion_row">
<xsl:with-param name="link" as="xs:string" select="$global_uri"/>
<xsl:with-param name="link" as="xs:string" select="$uri/eoa:uri"/>
<xsl:with-param name="content" as="element()*">
<!-- print chapter heading -->
<h1 class="publication-detail__title">
Expand Down Expand Up @@ -141,17 +138,13 @@
</xsl:template>

<xsl:template mode="chapter_main_paragraphs" match="tei:epigraph">
<xsl:variable name="chapter" select="ancestor::tei:div[@type = 'chapter']"/>
<xsl:variable name="chapter_nr" select="count($chapter/preceding-sibling::*)"/>
<xsl:variable name="container_id" as="xs:string"><xsl:call-template name="container_id"/></xsl:variable>
<xsl:variable name="local_uri" select="concat($series, '/', $publication_number, '/', $chapter_nr , '/index.html#', $container_id)"/>
<xsl:variable name="global_uri" select="concat($domain, '/', $local_uri)"/>
<xsl:sequence select="eoa:info(concat('epigraph', $container_id))"/>
<xsl:variable name="uri"><xsl:call-template name="calc_uri"/></xsl:variable>
<xsl:sequence select="eoa:info(concat('epigraph', $uri/eoa:id))"/>
<xsl:call-template name="accordion_row">
<xsl:with-param name="link" select="$global_uri"/>
<xsl:with-param name="link" select="$uri/eoa:uri"/>
<xsl:with-param name="content" as="element()*">
<xsl:for-each select="tei:p">
<p id="{$container_id}" class="epigraph">
<p id="{$uri/eoa:id}" class="epigraph">
<em>
<xsl:apply-templates mode="html"/>
</em>
Expand All @@ -162,16 +155,12 @@
</xsl:template>

<xsl:template mode="chapter_main_paragraphs" match="tei:ab[@type = 'chapterabstract']">
<xsl:variable name="chapter" select="ancestor::tei:div[@type = 'chapter']"/>
<xsl:variable name="chapter_nr" select="count($chapter/preceding-sibling::*)"/>
<xsl:variable name="container_id" as="xs:string"><xsl:call-template name="container_id"/></xsl:variable>
<xsl:variable name="local_uri" select="concat($series, '/', $publication_number, '/', $chapter_nr , '/index.html#', $container_id)"/>
<xsl:variable name="global_uri" select="concat($domain, '/', $local_uri)"/>
<xsl:sequence select="eoa:info(concat('chapterabstract', $container_id))"/>
<xsl:variable name="uri"><xsl:call-template name="calc_uri"/></xsl:variable>
<xsl:sequence select="eoa:info(concat('chapterabstract', $uri/eoa:id))"/>
<xsl:call-template name="accordion_row">
<xsl:with-param name="link" select="$global_uri"/>
<xsl:with-param name="link" select="$uri/eoa:uri"/>
<xsl:with-param name="content" as="element()*">
<p id="{$container_id}" class="abstract">
<p id="{$uri/eoa:id}" class="abstract">
<xsl:apply-templates mode="html"/>
</p>
</xsl:with-param>
Expand All @@ -189,16 +178,12 @@
</xsl:template>

<xsl:template mode="text_structure" match="tei:div[@type='section']">
<xsl:variable name="chapter" select="ancestor::tei:div[@type = 'chapter']"/>
<xsl:variable name="chapter_nr" select="count($chapter/preceding-sibling::*)"/>
<xsl:variable name="container_id" as="xs:string"><xsl:call-template name="container_id"/></xsl:variable>
<xsl:variable name="local_uri" select="concat($series, '/', $publication_number, '/', $chapter_nr , '/index.html#', $container_id)"/>
<xsl:variable name="global_uri" select="concat($domain, '/', $local_uri)"/>
<xsl:variable name="uri"><xsl:call-template name="calc_uri"/></xsl:variable>
<xsl:sequence select="eoa:info('section')"/>
<div class="accordion__item active">
<a class="accordion__title" href="#">
<xsl:call-template name="accordion_row">
<xsl:with-param name="link" as="xs:string" select="$global_uri"/>
<xsl:with-param name="link" as="xs:string" select="$uri/eoa:uri"/>
<xsl:with-param name="content" as="element()*">
<h2>
<xsl:if test="../@n != 'nonumber'">
Expand All @@ -217,14 +202,10 @@
</xsl:template>

<xsl:template mode="text_structure" match="tei:div[@type='subsection']">
<xsl:variable name="chapter" select="ancestor::tei:div[@type = 'chapter']"/>
<xsl:variable name="chapter_nr" select="count($chapter/preceding-sibling::*)"/>
<xsl:variable name="container_id" as="xs:string"><xsl:call-template name="container_id"/></xsl:variable>
<xsl:variable name="local_uri" select="concat($series, '/', $publication_number, '/', $chapter_nr , '/index.html#', $container_id)"/>
<xsl:variable name="global_uri" select="concat($domain, '/', $local_uri)"/>
<xsl:variable name="uri"><xsl:call-template name="calc_uri"/></xsl:variable>
<xsl:sequence select="eoa:info('subsection')"/>
<xsl:call-template name="accordion_row">
<xsl:with-param name="link" as="xs:string" select="$global_uri"/>
<xsl:with-param name="link" as="xs:string" select="$uri/eoa:uri"/>
<xsl:with-param name="content" as="element()*">
<h4>
<xsl:if test="../../@n != 'nonumber'">
Expand All @@ -238,14 +219,10 @@
</xsl:template>

<xsl:template mode="text_structure" match="tei:div[@type='subsubsection']">
<xsl:variable name="chapter" select="ancestor::tei:div[@type = 'chapter']"/>
<xsl:variable name="chapter_nr" select="count($chapter/preceding-sibling::*)"/>
<xsl:variable name="container_id" as="xs:string"><xsl:call-template name="container_id"/></xsl:variable>
<xsl:variable name="local_uri" select="concat($series, '/', $publication_number, '/', $chapter_nr , '/index.html#', $container_id)"/>
<xsl:variable name="global_uri" select="concat($domain, '/', $local_uri)"/>
<xsl:variable name="uri"><xsl:call-template name="calc_uri"/></xsl:variable>
<xsl:sequence select="eoa:info('subsubsection')"/>
<xsl:call-template name="accordion_row">
<xsl:with-param name="link" as="xs:string" select="$global_uri"/>
<xsl:with-param name="link" as="xs:string" select="$uri/eoa:uri"/>
<xsl:with-param name="content" as="element()*">
<h4>
<xsl:apply-templates mode="text_structure" select="./tei:head"/>
Expand All @@ -257,13 +234,9 @@

<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="container_id" as="xs:string"><xsl:call-template name="container_id"/></xsl:variable>
<xsl:variable name="local_uri" select="concat($series, '/', $publication_number, '/', $chapter_nr , '/index.html#', $container_id)"/>
<xsl:variable name="global_uri" select="concat($domain, '/', $local_uri)"/>
<xsl:variable name="uri"><xsl:call-template name="calc_uri"/></xsl:variable>
<xsl:call-template name="accordion_row">
<xsl:with-param name="link" as="xs:string" select="$global_uri"/>
<xsl:with-param name="link" as="xs:string" select="$uri/eoa:uri"/>
<xsl:with-param name="content" as="element()*">
<xsl:if test="tei:head">
<h4>
Expand Down Expand Up @@ -304,35 +277,53 @@

<xsl:template mode="text_structure" match="tei:ab[@type='equation']">
<xsl:sequence select="eoa:info('block formula')"/>
<xsl:value-of select="concat('$', ., '$')"/>
<xsl:variable name="uri"><xsl:call-template name="calc_uri"/></xsl:variable>
<xsl:call-template name="accordion_row">
<xsl:with-param name="link" as="xs:string" select="$uri/eoa:uri"/>
<xsl:with-param name="content" as="element()*">
<p>
<xsl:value-of select="concat('$', ., '$')"/>
</p>
</xsl:with-param>
</xsl:call-template>
</xsl:template>

<xsl:template mode="text_structure" match="tei:ab[@type='subequations']">
<xsl:sequence select="eoa:info('equation array')"/>
<xsl:variable name="container_id"><xsl:call-template name="container_id"/></xsl:variable>
<xsl:element name="table">
<xsl:for-each select="tei:formula">
<tr id="{$container_id}">
<td>
<xsl:value-of select="concat('$', ., '$')"/>
</td>
</tr>
</xsl:for-each>
</xsl:element>
<xsl:variable name="uri"><xsl:call-template name="calc_uri"/></xsl:variable>
<xsl:call-template name="accordion_row">
<xsl:with-param name="link" as="xs:string" select="$uri/eoa:uri"/>
<xsl:with-param name="content" as="element()*">
<table>
<xsl:for-each select="tei:formula">
<tr id="{$uri/eoa:id}">
<td>
<xsl:value-of select="concat('$', ., '$')"/>
</td>
</tr>
</xsl:for-each>
</table>
</xsl:with-param>
</xsl:call-template>
</xsl:template>

<xsl:template mode="text_structure" match="tei:ab[@type='equationarray']">
<xsl:sequence select="eoa:info('equation array')"/>
<xsl:variable name="container_id"><xsl:call-template name="container_id"/></xsl:variable>
<xsl:element name="table">
<xsl:for-each select="tei:formula">
<tr id="{$container_id}">
<td>
<xsl:value-of select="concat('$', ., '$')"/>
</td>
</tr>
</xsl:for-each>
</xsl:element>
<xsl:variable name="uri"><xsl:call-template name="calc_uri"/></xsl:variable>
<xsl:call-template name="accordion_row">
<xsl:with-param name="link" as="xs:string" select="$uri/eoa:uri"/>
<xsl:with-param name="content" as="element()*">
<table>
<xsl:for-each select="tei:formula">
<tr id="{$uri/eoa:id}">
<td>
<xsl:value-of select="concat('$', ., '$')"/>
</td>
</tr>
</xsl:for-each>
</table>
</xsl:with-param>
</xsl:call-template>
</xsl:template>

<!-- the theorem DECLARATION is not supposed to appear in the text: -->
Expand All @@ -341,15 +332,11 @@
<xsl:template mode="text_structure" match="tei:lg[@type='verse']">
<!-- TODO: find a way to indent the poem -->
<xsl:sequence select="eoa:info('verse')"/>
<xsl:variable name="chapter" select="ancestor::tei:div[@type = 'chapter']"/>
<xsl:variable name="chapter_nr" select="count($chapter/preceding-sibling::*)"/>
<xsl:variable name="container_id" as="xs:string"><xsl:call-template name="container_id"/></xsl:variable>
<xsl:variable name="local_uri" select="concat($series, '/', $publication_number, '/', $chapter_nr , '/index.html#', $container_id)"/>
<xsl:variable name="global_uri" select="concat($domain, '/', $local_uri)"/>
<xsl:variable name="uri"><xsl:call-template name="calc_uri"/></xsl:variable>
<xsl:call-template name="accordion_row">
<xsl:with-param name="link" as="xs:string" select="$global_uri"/>
<xsl:with-param name="link" as="xs:string" select="$uri/eoa:uri"/>
<xsl:with-param name="content" as="element()*">
<p id="{$container_id}">
<p id="{$uri/eoa:id}">
<xsl:for-each select="tei:l">
<xsl:apply-templates mode="html"/>
<xsl:if test="position() != last()">
Expand All @@ -364,15 +351,11 @@
<xsl:template mode="text_structure" match="tei:quote">
<!-- TODO: find a way to indent the quote -->
<xsl:sequence select="eoa:info('quote')"/>
<xsl:variable name="chapter" select="ancestor::tei:div[@type = 'chapter']"/>
<xsl:variable name="chapter_nr" select="count($chapter/preceding-sibling::*)"/>
<xsl:variable name="container_id" as="xs:string"><xsl:call-template name="container_id"/></xsl:variable>
<xsl:variable name="local_uri" select="concat($series, '/', $publication_number, '/', $chapter_nr , '/index.html#', $container_id)"/>
<xsl:variable name="global_uri" select="concat($domain, '/', $local_uri)"/>
<xsl:variable name="uri"><xsl:call-template name="calc_uri"/></xsl:variable>
<xsl:call-template name="accordion_row">
<xsl:with-param name="link" as="xs:string" select="$global_uri"/>
<xsl:with-param name="link" as="xs:string" select="$uri/eoa:uri"/>
<xsl:with-param name="content" as="element()*">
<p id="{$container_id}">
<p id="{$uri/eoa:id}">
<xsl:apply-templates mode="html"/>
</p>
</xsl:with-param>
Expand All @@ -381,13 +364,9 @@

<xsl:template mode="text_structure" match="tei:list[@type='ordered' or @type='unordered' or @type='gloss']">
<xsl:sequence select="eoa:info('list')"/>
<xsl:variable name="chapter" select="ancestor::tei:div[@type = 'chapter']"/>
<xsl:variable name="chapter_nr" select="count($chapter/preceding-sibling::*)"/>
<xsl:variable name="container_id" as="xs:string"><xsl:call-template name="container_id"/></xsl:variable>
<xsl:variable name="local_uri" select="concat($series, '/', $publication_number, '/', $chapter_nr , '/index.html#', $container_id)"/>
<xsl:variable name="global_uri" select="concat($domain, '/', $local_uri)"/>
<xsl:variable name="uri"><xsl:call-template name="calc_uri"/></xsl:variable>
<xsl:call-template name="accordion_row">
<xsl:with-param name="link" as="xs:string" select="$global_uri"/>
<xsl:with-param name="link" as="xs:string" select="$uri/eoa:uri"/>
<xsl:with-param name="content" as="element()*">
<xsl:variable name="element_name">
<xsl:choose>
Expand All @@ -400,7 +379,7 @@
</xsl:choose>
</xsl:variable>
<xsl:element name="{$element_name}">
<xsl:attribute name="id" select="$container_id"/>
<xsl:attribute name="id" select="$uri/eoa:id"/>
<xsl:for-each select="tei:item">
<li>
<xsl:if test="preceding-sibling::tei:label[1]">
Expand All @@ -417,15 +396,11 @@

<xsl:template mode="text_structure" match="tei:table">
<xsl:sequence select="eoa:info('table')"/>
<xsl:variable name="chapter" select="ancestor::tei:div[@type = 'chapter']"/>
<xsl:variable name="chapter_nr" select="count($chapter/preceding-sibling::*)"/>
<xsl:variable name="container_id" as="xs:string"><xsl:call-template name="container_id"/></xsl:variable>
<xsl:variable name="local_uri" select="concat($series, '/', $publication_number, '/', $chapter_nr , '/index.html#', $container_id)"/>
<xsl:variable name="global_uri" select="concat($domain, '/', $local_uri)"/>
<xsl:variable name="uri"><xsl:call-template name="calc_uri"/></xsl:variable>
<xsl:call-template name="accordion_row">
<xsl:with-param name="link" as="xs:string" select="$global_uri"/>
<xsl:with-param name="link" as="xs:string" select="$uri/eoa:uri"/>
<xsl:with-param name="content" as="element()*">
<figure id="{$container_id}">
<figure id="{$uri/eoa:id}">
<xsl:element name="table">
<xsl:for-each select="tei:row">
<tr>
Expand All @@ -450,18 +425,14 @@
<xsl:template mode="text_structure" match="tei:figure">
<!-- TODO: check/fix path -->
<xsl:sequence select="eoa:info('figure')"/>
<xsl:variable name="chapter" select="ancestor::tei:div[@type = 'chapter']"/>
<xsl:variable name="chapter_nr" select="count($chapter/preceding-sibling::*)"/>
<xsl:variable name="container_id" as="xs:string"><xsl:call-template name="container_id"/></xsl:variable>
<xsl:variable name="local_uri" select="concat($series, '/', $publication_number, '/', $chapter_nr , '/index.html#', $container_id)"/>
<xsl:variable name="global_uri" select="concat($domain, '/', $local_uri)"/>
<xsl:variable name="uri"><xsl:call-template name="calc_uri"/></xsl:variable>
<xsl:call-template name="accordion_row">
<xsl:with-param name="link" as="xs:string" select="$global_uri"/>
<xsl:with-param name="link" as="xs:string" select="$uri/eoa:uri"/>
<xsl:with-param name="content" as="element()*">
<xsl:variable name="caption">
<xsl:apply-templates mode="html" select="tei:head/node() | text()"/>
</xsl:variable>
<figure class="publication__image" id="{$container_id}">
<figure class="publication__image" id="{$uri/eoa:id}">
<a href="{@url}" data-lightbox="" title="$caption">
<img src="{@url}">image could not</img>
</a>
Expand Down Expand Up @@ -615,16 +586,12 @@

<xsl:template name="render_paragraph" as="element(div)">
<xsl:param name="css_classes" as="xs:string" select="''"/>
<xsl:variable name="chapter" select="ancestor::tei:div[@type = 'chapter']"/>
<xsl:variable name="chapter_nr" select="count($chapter/preceding-sibling::*)"/>
<xsl:variable name="container_id" as="xs:string"><xsl:call-template name="container_id"/></xsl:variable>
<xsl:variable name="local_uri" select="concat($series, '/', $publication_number, '/', $chapter_nr , '/index.html#', $container_id)"/>
<xsl:variable name="global_uri" select="concat($domain, '/', $local_uri)"/>
<xsl:sequence select="eoa:info(concat('chapter paragraph', $container_id))"/>
<xsl:variable name="uri"><xsl:call-template name="calc_uri"/></xsl:variable>
<xsl:sequence select="eoa:info(concat('chapter paragraph', $uri/eoa:id))"/>
<xsl:call-template name="accordion_row">
<xsl:with-param name="link" select="$global_uri"/>
<xsl:with-param name="link" select="$uri/eoa:uri"/>
<xsl:with-param name="content" as="element()*">
<p id="{$container_id}" class="{$css_classes}">
<p id="{$uri/eoa:id}" class="{$css_classes}">
<xsl:if test="@corresp">
<xsl:variable name="id" as="xs:string" select="eoa:normalize_reference(@corresp)"/>
<xsl:variable name="theorem" select="key('theoremdecls', $id)"/>
Expand All @@ -641,6 +608,27 @@
</xsl:call-template>
</xsl:template>

<xsl:template name="calc_uri" as="element()*">
<xsl:variable name="chapter" select="ancestor-or-self::tei:div[@type = 'chapter']"/>
<xsl:variable name="chapter_nr" select="count($chapter/preceding-sibling::*)"/>
<xsl:variable name="container_id" as="xs:string"><xsl:call-template name="container_id"/></xsl:variable>
<xsl:variable name="local_uri" select="concat($series, '/', $publication_number, '/', $chapter_nr , '/index.html')"/>
<xsl:variable name="global_uri" select="concat($domain, '/', $local_uri)"/>
<eoa:id>
<xsl:value-of select="$container_id"/>
</eoa:id>
<eoa:uri>
<xsl:choose>
<xsl:when test="self::tei:div[@type ='chapter']">
<xsl:value-of select="$global_uri"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="concat($global_uri, '#', $container_id)"/>
</xsl:otherwise>
</xsl:choose>
</eoa:uri>
</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>
Expand Down

0 comments on commit fa97c34

Please sign in to comment.