Skip to content
Permalink
a38cbb2921
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
427 lines (386 sloc) 13.4 KB
<?xml version="1.0"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:tei="http://www.tei-c.org/ns/1.0"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:eoa="http://www.edition-open-access.de/ns"
exclude-result-prefixes="xs tei"
version="2.0">
<xsl:output method="html" encoding="UTF-8"/>
<xsl:key name="theoremdecls" match="tei:ab[@type = 'theoremdeclaration']" use="@xml:id"/>
<xsl:key name="theorems" match="tei:p[@corresp]" use="eoa:normalize_reference(@corresp)"/>
<!-- TODO: restrict values by using a datatype -->
<xsl:param name="domain" select="'http://mprl-series.mpg.de'"/>
<xsl:variable name="series" select="lower-case(/tei:TEI/tei:teiHeader/tei:fileDesc/tei:seriesStmt/tei:title)"/>
<xsl:variable name="publication_number" select="/tei:TEI/tei:teiHeader/tei:fileDesc/tei:seriesStmt/tei:idno[@type = 'number']"/>
<!-- no mode: just render as text -->
<!--
<xsl:template match="tei:*" priority="-100">
<xsl:message>
<xsl:text>INFO: text mode for </xsl:text>
<xsl:value-of select="concat('', name(), ': ') "/>
<xsl:value-of select="./text()"/>
</xsl:message>
<xsl:apply-templates/>
</xsl:template>
-->
<!-- default rules with a warning -->
<!-- mode="html": convert inline elements to html -->
<xsl:template match="tei:*" mode="html" priority="-100">
<xsl:message>
<xsl:text>WARNING: unhandled inline element </xsl:text>
<xsl:value-of select="concat('', name(), ': ') "/>
<xsl:value-of select="./text()"/>
</xsl:message>
<!--
<xsl:apply-templates/>
-->
</xsl:template>
<!-- mode="body": structural element (div, p, ...) -->
<xsl:template match="tei:*" mode="body" priority="-100">
<xsl:message>WARNING: unhandled paragraph level element
<xsl:value-of select="concat('', name(), ': ') "/>
<xsl:value-of select="./text()"/>
</xsl:message>
<!--
<xsl:apply-templates/>
-->
</xsl:template>
<!-- section hierarchy -->
<xsl:template match="tei:div[@type='section']" mode="body">
<xsl:message>section</xsl:message>
<div 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="body"/>
</h2>
</a>
<div class="accordion__content">
<xsl:apply-templates select="*[name() != 'head']" mode="body"/>
<!-- the link to close the accordeon: -->
<a class="accordion__pageup" href="#"/>
</div>
</div>
</xsl:template>
<xsl:template match="tei:div[@type='subsection']" mode="body">
<xsl:message>subsection</xsl:message>
<h4>
<xsl:if test="../../@n != 'nonumber'">
<xsl:value-of select="concat(../../@n, '.', ../@n, '.', @n, ' ')"/>
</xsl:if>
<xsl:apply-templates select="./tei:head" mode="body"/>
</h4>
<xsl:apply-templates select="*[name() != 'head']" mode="body"/>
</xsl:template>
<xsl:template match="tei:div[@type='subsubsection']" mode="body">
<xsl:message>subsubsection</xsl:message>
<h4>
<xsl:apply-templates select="./tei:head" mode="body"/>
</h4>
<xsl:apply-templates select="*[name() != 'head']" mode="body"/>
</xsl:template>
<!-- paragraph level elements: -->
<xsl:variable name="paragraph_elements" as="xs:string*" select="('p', 'epigraph', 'ab', 'lg', 'quote', 'list', 'table', 'figure')"/>
<xsl:template match="tei:body//tei:head" mode="body">
<xsl:choose>
<xsl:when test="tei:choice/tei:expan">
<xsl:apply-templates select="tei:choice/tei:expan/node() | tei:choice/tei:expan/text()" mode="html"/>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates mode="html"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="paragraph_nr">
<xsl:number
count="tei:*[name() = $paragraph_elements]"
from="tei:div[@type = 'chapter']"
level="any"
/>
</xsl:template>
<xsl:template match="tei:body//tei:p" mode="body">
<xsl:variable name="chapter" select="ancestor::tei:div[@type = 'chapter']"/>
<xsl:variable name="chapter_nr" select="count($chapter/preceding-sibling::*)"/>
<xsl:variable name="paragraph_nr"><xsl:call-template name="paragraph_nr"/></xsl:variable>
<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:message>paragraph <xsl:value-of select="$paragraph_nr"/></xsl:message>
<p id="p{$paragraph_nr}">
<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:message>( theorem nr <xsl:value-of select="$theorem_nr"/> )</xsl:message>
<b>
<xsl:value-of select="concat( $theorem/text(), ' ', $theorem_nr, ': ')"/>
</b>
</xsl:if>
<xsl:apply-templates mode="html"/>
</p>
<!-- the infobox link: -->
<a class="accordion__popap" href="#"></a>
<div class="infobox infobox- -arrow-left">
<h4 class="infobox__title">Permanent Link</h4>
<p class="infobox__description">If you want to directly link to this paragraph in the text, you can use the following URL:</p>
<a title="Permanent Link" href="{concat('/', $local_uri)}">
<xsl:value-of select="$global_uri"/>
</a>
</div>
</xsl:template>
<xsl:template match="tei:epigraph" mode="body">
<!-- TODO: a single grouping element is needed, to carry the paragraph id -->
<xsl:message>epigraph</xsl:message>
<xsl:variable name="paragraph_nr"><xsl:call-template name="paragraph_nr"/></xsl:variable>
<!--
<div id="p{$paragraph_nr}">
-->
<xsl:for-each select="tei:p">
<p>
<em>
<xsl:apply-templates mode="html"/>
</em>
</p>
</xsl:for-each>
<!--
</div>
-->
</xsl:template>
<xsl:template match="tei:ab[@type = 'chapterabstract']" mode="body">
<xsl:message>chapter abstract</xsl:message>
<xsl:variable name="paragraph_nr"><xsl:call-template name="paragraph_nr"/></xsl:variable>
<p id="p{$paragraph_nr}">
<xsl:apply-templates mode="html"/>
</p>
</xsl:template>
<xsl:template match="tei:ab[@type='equation']" mode="body">
<xsl:message>block formula</xsl:message>
<xsl:value-of select="concat('$', ., '$')"/>
</xsl:template>
<xsl:template match="tei:ab[@type='subequations']" mode="body">
<xsl:message>equation array</xsl:message>
<xsl:variable name="paragraph_nr"><xsl:call-template name="paragraph_nr"/></xsl:variable>
<xsl:element name="table">
<xsl:for-each select="tei:formula">
<tr id="p{$paragraph_nr}">
<td>
<xsl:value-of select="concat('$', ., '$')"/>
</td>
</tr>
</xsl:for-each>
</xsl:element>
</xsl:template>
<xsl:template match="tei:ab[@type='equationarray']" mode="body">
<xsl:message>equation array</xsl:message>
<xsl:variable name="paragraph_nr"><xsl:call-template name="paragraph_nr"/></xsl:variable>
<xsl:element name="table">
<xsl:for-each select="tei:formula">
<tr id="p{$paragraph_nr}">
<td>
<xsl:value-of select="concat('$', ., '$')"/>
</td>
</tr>
</xsl:for-each>
</xsl:element>
</xsl:template>
<!-- the theorem DECLARATION is not supposed to appear in the text: -->
<xsl:template match="tei:ab[@type='theoremdeclaration']" mode="body"/>
<xsl:template match="tei:lg[@type='verse']" mode="body">
<!-- TODO: find a way to indent the poem -->
<xsl:message>verse</xsl:message>
<xsl:variable name="paragraph_nr"><xsl:call-template name="paragraph_nr"/></xsl:variable>
<p id="p{$paragraph_nr}">
<xsl:for-each select="tei:l">
<xsl:apply-templates mode="html"/>
<xsl:if test="position() != last()">
<br/>
</xsl:if>
</xsl:for-each>
</p>
</xsl:template>
<xsl:template match="tei:quote" mode="body">
<!-- TODO: find a way to indent the quote -->
<xsl:message>quote</xsl:message>
<xsl:variable name="paragraph_nr"><xsl:call-template name="paragraph_nr"/></xsl:variable>
<p id="p{$paragraph_nr}">
<xsl:apply-templates mode="html"/>
</p>
</xsl:template>
<xsl:template match="tei:list[@type='ordered' or @type='unordered' or @type='gloss']" mode="body">
<xsl:message>list</xsl:message>
<xsl:variable name="paragraph_nr"><xsl:call-template name="paragraph_nr"/></xsl:variable>
<xsl:variable name="element_name">
<xsl:choose>
<xsl:when test="@type = 'ordered'">ol</xsl:when>
<xsl:when test="@type = 'unordered'">ul</xsl:when>
<xsl:when test="@type = 'gloss'">ul</xsl:when>
<xsl:otherwise>
<xsl:message>ERROR: unknown list type!!</xsl:message>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:element name="{$element_name}">
<xsl:attribute name="id" select="$paragraph_nr"/>
<xsl:for-each select="tei:item">
<li>
<xsl:if test="preceding-sibling::tei:label[1]">
<xsl:apply-templates select="preceding-sibling::tei:label[1]"/>
<xsl:text>: </xsl:text>
</xsl:if>
<xsl:apply-templates mode="html"/>
</li>
</xsl:for-each>
</xsl:element>
</xsl:template>
<xsl:template match="tei:table" mode="body">
<xsl:message>table</xsl:message>
<xsl:variable name="paragraph_nr"><xsl:call-template name="paragraph_nr"/></xsl:variable>
<figure id="p{$paragraph_nr}">
<xsl:element name="table">
<xsl:for-each select="tei:row">
<tr>
<xsl:for-each select="tei:cell">
<xsl:element name="{if( @role = 'label') then 'th' else 'td'}">
<xsl:apply-templates mode="html"/>
</xsl:element>
</xsl:for-each>
</tr>
</xsl:for-each>
</xsl:element>
<xsl:if test="tei:head">
<figcaption>
<xsl:apply-templates select="tei:head/node() | text()" mode="html"/>
</figcaption>
</xsl:if>
</figure>
</xsl:template>
<xsl:template match="tei:figure" mode="body">
<!-- TODO: check/fix path -->
<xsl:message>figure</xsl:message>
<xsl:variable name="paragraph_nr"><xsl:call-template name="paragraph_nr"/></xsl:variable>
<xsl:variable name="caption">
<xsl:apply-templates select="tei:head/node() | text()" mode="html"/>
</xsl:variable>
<figure class="publication__image" id="p{$paragraph_nr}">
<a href="{@url}" data-lightbox="" title="$caption">
<img src="{@url}">image could not</img>
</a>
<xsl:if test="tei:head">
<figcaption>
<xsl:value-of select="$caption"/>
</figcaption>
</xsl:if>
</figure>
</xsl:template>
<!--
<xsl:template match="tei:formula">
<xsl:message>formula</xsl:message>
<xsl:choose>
<xsl:when test="@rend='inline'">
<xsl:message>inline</xsl:message>
<xsl:value-of select="concat('$', ., '$')"/>
</xsl:when>
<xsl:when test="../tei:ab[@type='equation']">
<xsl:message>
jo
<xsl:value-of select="."/>
</xsl:message>
<p>
<xsl:value-of select="."/>
</p>
</xsl:when>
<xsl:otherwise>
<xsl:message>nothing</xsl:message>
<xsl:value-of select="."/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
-->
<!-- text inline elements: -->
<xsl:template match="tei:hi" mode="html">
<xsl:message>markup</xsl:message>
<xsl:choose>
<xsl:when test="@rend='italic'">
<em>
<xsl:apply-templates/>
</em>
</xsl:when>
<xsl:when test="@rend='bold'">
<b>
<xsl:apply-templates/>
</b>
</xsl:when>
<xsl:when test="@rend='superscript'">
<sup>
<xsl:apply-templates/>
</sup>
</xsl:when>
<xsl:when test="@rend='subscript'">
<sub>
<xsl:apply-templates/>
</sub>
</xsl:when>
<xsl:when test="@rend='smallcaps'">
<sc>
<xsl:apply-templates/>
</sc>
</xsl:when>
<xsl:when test="@rend='math'">
<i>
<xsl:apply-templates/>
</i>
</xsl:when>
</xsl:choose>
</xsl:template>
<xsl:template match="tei:lb" mode="html">
<br/>
</xsl:template>
<xsl:template match="tei:body//tei:foreign" mode="html">
<span lang="{@xml:lang}">
<xsl:apply-templates/>
</span>
</xsl:template>
<xsl:template match="tei:formula[@rend='inline']" mode="html">
<xsl:message>inline formula</xsl:message>
<xsl:value-of select="concat('$', ., '$')"/>
</xsl:template>
<!--
<xsl:template match="//tei:div[not(@type='chapter' or @type='part')]/tei:head" mode="document-structure">
<xsl:choose>
<xsl:when test="../@type='section'">
<h2>
<xsl:if test="../../@n != 'nonumber'">
<xsl:value-of select="concat(../../@n, '.', ../@n, ' ')"/>
</xsl:if>
<xsl:apply-templates select="."/>
</h2>
</xsl:when>
<xsl:when test="../@type='subsection'">
<h4>
<xsl:if test="../../../@n != 'nonumber'">
<xsl:value-of select="concat(../../../@n, '.', ../../@n, '.', ../@n, ' ')"/>
</xsl:if>
<xsl:apply-templates select="."/>
</h4>
</xsl:when>
<xsl:when test="../@type='subsubsection'">
<h5>
<xsl:apply-templates select="."/>
</h5>
</xsl:when>
</xsl:choose>
</xsl:template>
-->
<xsl:function name="eoa:normalize_reference">
<xsl:param name="reference"/>
<xsl:analyze-string select="$reference" regex="#{{0,1}}(.+)">
<xsl:matching-substring>
<xsl:value-of select="regex-group(1)"/>
</xsl:matching-substring>
</xsl:analyze-string>
</xsl:function>
</xsl:stylesheet>