abaev-basex-htmx/xsl/abaev2html.xsl

364 lines
15 KiB
XML
Raw Normal View History

2025-03-21 14:14:03 +03:00
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xpath-default-namespace=""
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
2025-03-21 14:14:03 +03:00
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:tei="http://www.tei-c.org/ns/1.0"
xmlns:abv="http://ossetic-studies.org/ns/abaevdict"
exclude-result-prefixes="xs tei"
version="2.0">
<xsl:output method="xml"/>
<!-- Which language we are using for the final output -->
<xsl:param name="lang"/>
<!-- Function that recursively produces a sequence of languages -->
<xsl:function name="abv:getlangs" as="xs:string+">
<xsl:param name="node" as="node()"/>
<xsl:choose>
<xsl:when test="$node/@xml:lang">
<xsl:sequence select="($node/@xml:lang, tokenize($node/@extralang,','))"/>
<!-- <xsl:value-of select="($node/@xml:lang,$node/@extralang)"/> -->
</xsl:when>
<xsl:otherwise>
<xsl:sequence select="abv:getlangs($node/..)"/>
</xsl:otherwise>
</xsl:choose>
</xsl:function>
<xsl:template match="tei:mark">
2025-03-22 18:32:34 +03:00
<mark>
2025-03-22 23:43:48 +03:00
<xsl:apply-templates/>
2025-03-22 18:32:34 +03:00
</mark>
</xsl:template>
2025-03-21 14:14:03 +03:00
<xsl:template match="tei:entry">
<xsl:variable name="entry-id" select="@xml:id"/>
<xsl:element name="article">
<xsl:attribute name="id" select="$entry-id"/>
<xsl:attribute name="lang" select="$lang"/>
<xsl:attribute name="class">abv-entry</xsl:attribute>
<xsl:variable name="position">0</xsl:variable>
<!-- Split into two groups: the headword div and the rest -->
<xsl:for-each-group select="*" group-adjacent="self::tei:form or
(self::tei:pc and following-sibling::*[1][self::tei:form])">
<xsl:choose>
<xsl:when test="current-grouping-key()">
<h6 class="abv-headword">
<xsl:apply-templates select="current-group()"/>
<br/>
<a href="#{$entry-id}">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-hash" viewBox="0 0 16 16">
<path d="M8.39 12.648a1 1 0 0 0-.015.18c0 .305.21.508.5.508.266 0 .492-.172.555-.477l.554-2.703h1.204c.421 0 .617-.234.617-.547 0-.312-.188-.53-.617-.53h-.985l.516-2.524h1.265c.43 0 .618-.227.618-.547 0-.313-.188-.524-.618-.524h-1.046l.476-2.304a1 1 0 0 0 .016-.164.51.51 0 0 0-.516-.516.54.54 0 0 0-.539.43l-.523 2.554H7.617l.477-2.304c.008-.04.015-.118.015-.164a.51.51 0 0 0-.523-.516.54.54 0 0 0-.531.43L6.53 5.484H5.414c-.43 0-.617.22-.617.532s.187.539.617.539h.906l-.515 2.523H4.609c-.421 0-.609.219-.609.531s.188.547.61.547h.976l-.516 2.492c-.008.04-.015.125-.015.18 0 .305.21.508.5.508.265 0 .492-.172.554-.477l.555-2.703h2.242zm-1-6.109h2.266l-.515 2.563H6.859l.532-2.563z"/>
</svg>
</a>
2025-03-30 00:21:27 +03:00
<xsl:if test="//tei:mentioned[@xml:lang != 'os' and not(starts-with(@xml:lang,'os-'))]">
<a class="abv-map"
hx-get="./map"
hx-target="#modal_map"
hx-swap="innerHTML"
hx-vals='{"{"}"entry": "{$entry-id}"{"}"}'
hx-on-click='document.getElementById("modal_map").showModal()'
>
<img src="/static/map.png"></img>
2025-03-30 00:21:27 +03:00
</a>
</xsl:if>
2025-03-21 14:14:03 +03:00
</h6>
</xsl:when>
<xsl:otherwise>
<!-- Further split into usg 9i.e. dialect marking) and rest -->
<xsl:for-each-group select="current-group()"
group-adjacent="self::tei:usg or (self::tei:pc and following-sibling::*[1][self::tei:usg])" composite="yes">
<xsl:choose>
<xsl:when test="current-grouping-key()">
<div class="abv-usg">
<xsl:apply-templates select="current-group()"/>
</div>
</xsl:when>
<xsl:otherwise>
<!-- If there is no usg, create an empty div for correct
alignment -->
<xsl:if test="not(../tei:usg)">
<div class="abv-usg"></div>
</xsl:if>
<div class="abv-entrytxt">
<!-- Split main part into two paragraphs: examples and etym -->
<xsl:for-each-group select="current-group()"
group-adjacent="not(self::tei:etym)">
<xsl:choose>
<xsl:when test="current-grouping-key()">
2025-03-30 17:42:03 +03:00
<div class="abv-mainpart">
<p>
<xsl:apply-templates select="current-group()"/>
</p>
</div>
2025-03-21 14:14:03 +03:00
</xsl:when>
<xsl:otherwise>
2025-03-30 17:42:03 +03:00
<div class="abv-etym">
<xsl:for-each-group select="node()"
group-starting-with="tei:lb">
<p>
<xsl:apply-templates select="current-group()"/>
</p>
</xsl:for-each-group>
</div>
<div class="notes">
<xsl:apply-templates select="//tei:note[@type='footnote']" mode="footnote"/>
</div>
2025-03-21 14:14:03 +03:00
</xsl:otherwise>
</xsl:choose>
</xsl:for-each-group>
</div>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each-group>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each-group>
<!-- <div class="abv-usg">
<xsl:for-each select="tei:usg">
<xsl:apply-templates select="."/>
</xsl:for-each>
</div>
<div class="abv-entrytxt">
<p class="abv-mainpart">
<xsl:for-each select="*[not(self::tei:etym) and not(self::tei:form or self::tei:pc[following-sibling::*[1][self::tei:form]]) and not(self::tei:usg)]">
<xsl:apply-templates select="."/>
</xsl:for-each>
</p>
<xsl:apply-templates select="tei:etym"/>
</div> -->
</xsl:element>
</xsl:template>
<xsl:template match="tei:form/tei:orth">
<xsl:variable name="elem">
<xsl:choose>
<xsl:when test="ancestor::tei:cit[@type='formGrp'] or ancestor::tei:re">i</xsl:when>
2025-03-21 14:14:03 +03:00
<xsl:otherwise>b</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:element name="{$elem}">
<xsl:attribute name="class">abv-form</xsl:attribute>
<xsl:attribute name="lang" select="../@xml:lang"/>
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
<xsl:template match="tei:cit[@type='translationEquivalent']/tei:quote | tei:gloss/tei:q">
<xsl:element name="q">
<xsl:attribute name="class">abv-gloss</xsl:attribute>
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
<xsl:template match="tei:cit[@type='translation']/tei:quote">
<xsl:element name="q">
<xsl:attribute name="class">abv-tr</xsl:attribute>
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
2025-03-24 20:00:13 +03:00
<xsl:template match="tei:cit[@type='example']/tei:quote">
2025-03-21 14:14:03 +03:00
<xsl:element name="i">
<xsl:attribute name="class">abv-example</xsl:attribute>
<xsl:attribute name="lang" select="../@xml:lang"/>
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
<xsl:template match="tei:ref[@type='bibl']">
<xsl:element name="a">
<xsl:attribute name="class">abv-bibl</xsl:attribute>
<xsl:attribute name="href" select="@target"/>
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
<xsl:template match="tei:ref[@type='bibl']/tei:abbr">
<xsl:element name="abbr">
<xsl:attribute name="class">abv-bibl</xsl:attribute>
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
<xsl:template match="tei:ref[@type='xr' and not(tei:c | tei:m | tei:w | tei:phr | tei:s)]">
<xsl:element name="a">
<xsl:attribute name="href" select="@target"/>
<xsl:element name="i">
<xsl:choose>
<xsl:when test="../@xml:lang">
<xsl:attribute name="lang" select="../@xml:lang"/>
</xsl:when>
<xsl:otherwise>
<xsl:attribute name="lang">os</xsl:attribute>
</xsl:otherwise>
</xsl:choose>
<xsl:apply-templates/>
</xsl:element>
</xsl:element>
</xsl:template>
<xsl:template match="tei:ref[@type='xr']/tei:c | tei:ref[@type='xr']/tei:m | tei:ref[@type='xr']/tei:w | tei:ref[@type='xr']/tei:phr | tei:ref[@type='xr']/tei:s">
<xsl:element name="a">
<xsl:attribute name="href" select="../@target"/>
<xsl:element name="i">
<xsl:choose>
<xsl:when test="@xml:lang">
<xsl:attribute name="lang" select="@xml:lang"/>
</xsl:when>
<xsl:otherwise>
<xsl:attribute name="lang">os</xsl:attribute>
</xsl:otherwise>
</xsl:choose>
<xsl:apply-templates/>
</xsl:element>
</xsl:element>
</xsl:template>
<xsl:template match="tei:name | tei:author">
<xsl:element name="span">
<xsl:attribute name="class">abv-name</xsl:attribute>
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
<xsl:template match="tei:lang">
<xsl:element name="abbr">
<xsl:attribute name="class">abv-lang</xsl:attribute>
<xsl:attribute name="data-lang" select="string-join(abv:getlangs(.),',')"/>
<!-- <xsl:attribute name="title">#</xsl:attribute> TODO: Implement lookup table for full language names -->
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
<xsl:template name="make-word">
<xsl:element name="i">
<!-- If the element has its own language, or is part of a
mentioned, assign it a language. Otherwise, assign a special tag
that says that it is not really a linguistic object (e.g. an
abstract hypothetical form, phonetic sequence, etc.)-->
<xsl:choose>
<xsl:when test="../name() = 'mentioned' or @xml:lang">
<xsl:attribute name="lang" select="abv:getlangs(.)[1]"/>
</xsl:when>
<xsl:otherwise>
<xsl:attribute name="lang" select="'zxx'"/>
</xsl:otherwise>
</xsl:choose>
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
<xsl:template match="tei:c | tei:m | tei:w | tei:phr | tei:s">
<xsl:choose>
<xsl:when test="../name() = 'mentioned'">
<!-- <xsl:element name="a"> -->
<!-- <xsl:attribute name="href">#</xsl:attribute> -->
2025-03-21 14:14:03 +03:00
<xsl:call-template name="make-word"/>
<!-- </xsl:element> -->
2025-03-21 14:14:03 +03:00
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="make-word"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!-- If pc is empty, add one space -->
<xsl:template match="tei:pc[not(node())]">
<xsl:text> </xsl:text>
</xsl:template>
<!-- ETYMOLOGY -->
<xsl:template match="tei:etym">
2025-03-30 17:42:03 +03:00
<xsl:apply-templates />
2025-03-21 14:14:03 +03:00
</xsl:template>
<xsl:template match="tei:oRef">
<xsl:element name="i">
<!-- If oRef has a language, select it, otherwise
use the entry language -->
<xsl:attribute name="lang">
<xsl:choose>
<xsl:when test="@xml:lang">
<xsl:value-of select="@xml:lang"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="ancestor::tei:entry/@xml:lang"/>
</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
<xsl:template match="tei:lb">
</xsl:template>
<xsl:template match="tei:hi">
<xsl:choose>
<xsl:when test="@rendition='#rend_italic'">
<em><xsl:apply-templates/></em>
</xsl:when>
<xsl:when test="@rendition='#rend_bold'">
<strong><xsl:apply-templates/></strong>
</xsl:when>
<xsl:when test="@rendition='#rend_underline'">
<span class="abv-text-ul"><xsl:apply-templates/></span>
</xsl:when>
<xsl:when test="@rendition='#rend_subscript'">
<sub><xsl:apply-templates/></sub>
</xsl:when>
<xsl:when test="@rendition='#rend_superscript'">
<sup><xsl:apply-templates/></sup>
</xsl:when>
<xsl:when test="@rendition='#rend_smallcaps'">
<span class="abv-text-sc"><xsl:apply-templates/></span>
</xsl:when>
</xsl:choose>
</xsl:template>
<!-- tables -->
<xsl:template match="tei:table">
<table>
<xsl:apply-templates/>
</table>
</xsl:template>
<xsl:template match="tei:row">
<tr>
<xsl:apply-templates/>
</tr>
</xsl:template>
<xsl:template match="tei:cell">
<td>
<xsl:apply-templates/>
</td>
</xsl:template>
<!-- Footnotes -->
<xsl:template match="tei:note[@type='footnote']">
<xsl:variable name="no"><xsl:number level="single"/></xsl:variable>
<a id="fn_{/tei:entry/@xml:id}_{$no}" href="#fntxt_{/tei:entry/@xml:id}_{$no}"><sup><xsl:value-of select="$no"/></sup></a>
</xsl:template>
<xsl:template match="tei:note[@type='footnote']" mode='footnote'>
<xsl:variable name="no"><xsl:number level="single"/></xsl:variable>
<p>
<a id="fntxt_{/tei:entry/@xml:id}_{$no}" href="#fn_{/tei:entry/@xml:id}_{$no}"><sup><xsl:value-of select="$no"/></sup></a>
<xsl:apply-templates />
</p>
</xsl:template>
<!-- Remove internal notes -->
<xsl:template match="tei:note[@type='internal']">
</xsl:template>
<!-- get rid of new lines -->
<xsl:template match="text()">
2025-03-21 14:14:03 +03:00
<xsl:value-of select="replace(translate(., '&#xA;', ''), ' +', ' ')"/>
</xsl:template>
</xsl:stylesheet>