Skip to content

Commit

Permalink
tei->html: refactor: rename and restructure
Browse files Browse the repository at this point in the history
  • Loading branch information
EsGeh authored and EsGeh committed Nov 7, 2019
1 parent 868cc6e commit f9f67c1
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 65 deletions.
8 changes: 4 additions & 4 deletions tei2html/tei2html_chapter_utils.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -216,20 +216,20 @@ tex2jax: {inlineMath: [["$","$"],["\\(","\\)"]]}
<div class="publication-detail__footnotes">
<ol>
<xsl:for-each select="$chapter//tei:note[@place = 'bottom']">
<xsl:variable name="paragraph_id" as="xs:string?">
<xsl:variable name="container_id" as="xs:string?">
<xsl:for-each select="parent::tei:*">
<xsl:call-template name="paragraph_id"/>
<xsl:call-template name="container_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">
<xsl:if test="$container_id">
<li id="{$footnote_id}">
<xsl:for-each select="tei:p">
<p><xsl:apply-templates mode="html"/></p>
</xsl:for-each>
<a href="#{$paragraph_id}">to paragraph</a>
<a href="#{$container_id}">to paragraph</a>
</li>
</xsl:if>
</xsl:for-each>
Expand Down
8 changes: 4 additions & 4 deletions tei2html/tei2html_publ_frontpage_utils.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -523,15 +523,15 @@
<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 name="container_id" as="xs:string?">
<xsl:call-template name="container_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 test="$container_id">
<xsl:value-of select="$container_id"/>
</xsl:when>
</xsl:choose>
</xsl:for-each>
Expand Down
141 changes: 84 additions & 57 deletions tei2html/utils/html_rules.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,6 @@
</xsl:with-param>
</xsl:call-template>
<xsl:apply-templates mode="chapter_main_paragraphs" select="(if (tei:div[@type = 'section']) then (tei:div[@type = 'section'][1]/preceding-sibling::*) else (*))[not(self::tei:head)]"/>
<!--
<xsl:apply-templates mode="text_structure" select="tei:*[not(self::tei:head) and not(self::tei:div[@type = 'section']) and not(self::tei:div[@type = 'subsection']) and not(self::tei:div[@type = 'subsubsection'])]"/>
-->
</div>
<a class="accordion__showall show" href="#">Close All</a>
<!-- render chapter text -->
Expand Down Expand Up @@ -94,42 +91,13 @@
</xsl:call-template>
</xsl:template>

<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="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:sequence select="eoa:info(concat('chapter paragraph', $paragraph_id))"/>
<xsl:call-template name="accordion_row">
<xsl:with-param name="link" select="$global_uri"/>
<xsl:with-param name="content" as="element()*">
<p id="{$paragraph_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)"/>
<xsl:variable name="theorem_group" select="key('theorems', $id)"/>
<xsl:variable name="theorem_nr" select="index-of($theorem_group/generate-id(), generate-id(.))"/>

<xsl:sequence select="eoa:info(concat(' (theorem nr', $theorem_nr, ')'))"/>
<b>
<xsl:value-of select="concat( $theorem/text(), ' ', $theorem_nr, ': ')"/>
</b>
</xsl:if>
<xsl:apply-templates mode="html"/>
</p>
</xsl:with-param>
</xsl:call-template>
</xsl:template>

<xsl:template mode="chapter_main_paragraphs" match="tei:epigraph">
<xsl:variable name="paragraph_id"><xsl:call-template name="paragraph_id"/></xsl:variable>
<xsl:sequence select="eoa:info(concat('epigraph', $paragraph_id))"/>
<xsl:variable name="container_id"><xsl:call-template name="container_id"/></xsl:variable>
<xsl:sequence select="eoa:info(concat('epigraph', $container_id))"/>
<xsl:call-template name="accordion_row">
<xsl:with-param name="content" as="element()*">
<xsl:for-each select="tei:p">
<p id="{$paragraph_id}" class="epigraph">
<p id="{$container_id}" class="epigraph">
<em>
<xsl:apply-templates mode="html"/>
</em>
Expand All @@ -140,11 +108,11 @@
</xsl:template>

<xsl:template mode="chapter_main_paragraphs" match="tei:ab[@type = 'chapterabstract']">
<xsl:variable name="paragraph_id"><xsl:call-template name="paragraph_id"/></xsl:variable>
<xsl:sequence select="eoa:info(concat('chapterabstract', $paragraph_id))"/>
<xsl:variable name="container_id"><xsl:call-template name="container_id"/></xsl:variable>
<xsl:sequence select="eoa:info(concat('chapterabstract', $container_id))"/>
<xsl:call-template name="accordion_row">
<xsl:with-param name="content" as="element()*">
<p id="{$paragraph_id}" class="abstract">
<p id="{$container_id}" class="abstract">
<xsl:apply-templates mode="html"/>
</p>
</xsl:with-param>
Expand Down Expand Up @@ -217,8 +185,8 @@
<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="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:call-template name="accordion_row">
<xsl:with-param name="link" as="xs:string" select="$global_uri"/>
Expand Down Expand Up @@ -267,10 +235,10 @@

<xsl:template mode="text_structure" match="tei:ab[@type='subequations']">
<xsl:sequence select="eoa:info('equation array')"/>
<xsl:variable name="paragraph_id"><xsl:call-template name="paragraph_id"/></xsl:variable>
<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="{$paragraph_id}">
<tr id="{$container_id}">
<td>
<xsl:value-of select="concat('$', ., '$')"/>
</td>
Expand All @@ -281,10 +249,10 @@

<xsl:template mode="text_structure" match="tei:ab[@type='equationarray']">
<xsl:sequence select="eoa:info('equation array')"/>
<xsl:variable name="paragraph_id"><xsl:call-template name="paragraph_id"/></xsl:variable>
<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="{$paragraph_id}">
<tr id="{$container_id}">
<td>
<xsl:value-of select="concat('$', ., '$')"/>
</td>
Expand All @@ -299,8 +267,8 @@
<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="paragraph_id"><xsl:call-template name="paragraph_id"/></xsl:variable>
<p id="{$paragraph_id}">
<xsl:variable name="container_id"><xsl:call-template name="container_id"/></xsl:variable>
<p id="{$container_id}">
<xsl:for-each select="tei:l">
<xsl:apply-templates mode="html"/>
<xsl:if test="position() != last()">
Expand All @@ -313,15 +281,15 @@
<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="paragraph_id"><xsl:call-template name="paragraph_id"/></xsl:variable>
<p id="{$paragraph_id}">
<xsl:variable name="container_id"><xsl:call-template name="container_id"/></xsl:variable>
<p id="{$container_id}">
<xsl:apply-templates mode="html"/>
</p>
</xsl:template>

<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="paragraph_id"><xsl:call-template name="paragraph_id"/></xsl:variable>
<xsl:variable name="container_id"><xsl:call-template name="container_id"/></xsl:variable>
<xsl:variable name="element_name">
<xsl:choose>
<xsl:when test="@type = 'ordered'">ol</xsl:when>
Expand All @@ -333,7 +301,7 @@
</xsl:choose>
</xsl:variable>
<xsl:element name="{$element_name}">
<xsl:attribute name="id" select="$paragraph_id"/>
<xsl:attribute name="id" select="$container_id"/>
<xsl:for-each select="tei:item">
<li>
<xsl:if test="preceding-sibling::tei:label[1]">
Expand All @@ -348,8 +316,8 @@

<xsl:template mode="text_structure" match="tei:table">
<xsl:sequence select="eoa:info('table')"/>
<xsl:variable name="paragraph_id"><xsl:call-template name="paragraph_id"/></xsl:variable>
<figure id="{$paragraph_id}">
<xsl:variable name="container_id"><xsl:call-template name="container_id"/></xsl:variable>
<figure id="{$container_id}">
<xsl:element name="table">
<xsl:for-each select="tei:row">
<tr>
Expand All @@ -372,11 +340,11 @@
<xsl:template mode="text_structure" match="tei:figure">
<!-- TODO: check/fix path -->
<xsl:sequence select="eoa:info('figure')"/>
<xsl:variable name="paragraph_id"><xsl:call-template name="paragraph_id"/></xsl:variable>
<xsl:variable name="container_id"><xsl:call-template name="container_id"/></xsl:variable>
<xsl:variable name="caption">
<xsl:apply-templates mode="html" select="tei:head/node() | text()"/>
</xsl:variable>
<figure class="publication__image" id="{$paragraph_id}">
<figure class="publication__image" id="{$container_id}">
<a href="{@url}" data-lightbox="" title="$caption">
<img src="{@url}">image could not</img>
</a>
Expand Down Expand Up @@ -528,13 +496,44 @@
</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="paragraph_id" as="xs:string?">
<xsl:template name="container_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 | 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']]">
<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 | 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']]"
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"
/>
Expand All @@ -546,6 +545,34 @@
</xsl:choose>
</xsl:template>

<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:call-template name="accordion_row">
<xsl:with-param name="link" select="$global_uri"/>
<xsl:with-param name="content" as="element()*">
<p id="{$container_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)"/>
<xsl:variable name="theorem_group" select="key('theorems', $id)"/>
<xsl:variable name="theorem_nr" select="index-of($theorem_group/generate-id(), generate-id(.))"/>
<xsl:sequence select="eoa:info(concat(' (theorem nr', $theorem_nr, ')'))"/>
<b>
<xsl:value-of select="concat( $theorem/text(), ' ', $theorem_nr, ': ')"/>
</b>
</xsl:if>
<xsl:apply-templates mode="html"/>
</p>
</xsl:with-param>
</xsl:call-template>
</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 f9f67c1

Please sign in to comment.