abaev-basex/xsl/standardize.xsl

354 lines
13 KiB
XML
Raw Normal View History

2025-03-21 14:14:03 +03:00
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
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:param name="standardize-lang"/>
<!-- NAMED TEMPLATES-->
<xsl:template name="defaultlang">
<xsl:if test="not(@xml:lang)">
<xsl:variable name="entrylang" select="ancestor::tei:entry/@xml:lang"/>
<xsl:choose>
<xsl:when test="$entrylang = 'os'">
<xsl:attribute name="xml:lang">os-x-iron</xsl:attribute>
</xsl:when>
<xsl:otherwise>
<xsl:attribute name="xml:lang" select="$entrylang"/>
</xsl:otherwise>
</xsl:choose>
</xsl:if>
</xsl:template>
<!-- XSLT Template to copy anything -->
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<!-- Delete outdate elements-->
<xsl:template match="tei:encodingDesc|tei:tagsDecl">
</xsl:template>
<!-- The completeness attribute is to be used without namespace, to simplify styling.
For the purposes of conversion, delete it at present -->
<xsl:template match="@abv:completeness | @abv:status">
<!--<xsl:attribute name="completeness">
<xsl:value-of select="."/>
</xsl:attribute>-->
</xsl:template>
<!-- Replace these guys with placeholders, will fix later -->
<xsl:template match="tei:publicationStatement">
<xsl:element name="tei:publicationStatement">
<tei:p>PLACEHOLDER</tei:p>
</xsl:element>
</xsl:template>
<xsl:template match="tei:sourceDesc">
<xsl:element name="tei:sourceDesc">
<tei:p>PLACEHOLDER</tei:p>
</xsl:element>
</xsl:template>
<!-- Replace custom elements with TEI elements -->
<xsl:template match="abv:tr">
<xsl:choose>
<xsl:when test="preceding-sibling::*[1][self::tei:usg or self::tei:quote]">
<tei:pc><xsl:text> </xsl:text></tei:pc>
</xsl:when>
<xsl:when test="preceding-sibling::*[1][self::abv:tr]">
<tei:pc><xsl:text>, </xsl:text></tei:pc>
</xsl:when>
</xsl:choose>
<xsl:element name="tei:cit">
<xsl:attribute name="type">
<xsl:choose>
<xsl:when test="parent::tei:sense">translationEquivalent</xsl:when>
<xsl:when test="parent::abv:example">translation</xsl:when>
</xsl:choose>
</xsl:attribute>
<xsl:apply-templates select="@* | node()"/>
</xsl:element>
</xsl:template>
<xsl:template match="abv:tr/tei:q">
<xsl:if test="preceding-sibling::*[1][self::tei:q]">
<tei:pc><xsl:text>, </xsl:text></tei:pc>
</xsl:if>
<xsl:element name="tei:quote">
<xsl:apply-templates select="@* | node()"/>
</xsl:element>
</xsl:template>
<xsl:template match="abv:example">
<xsl:choose>
<xsl:when test="parent::abv:formGrp and preceding-sibling::*[1][self::tei:form]">
<tei:pc><xsl:text>: </xsl:text></tei:pc>
</xsl:when>
<xsl:when test="parent::tei:sense">
<xsl:choose>
<xsl:when test="preceding-sibling::*[1][self::abv:tr]">
<tei:pc><xsl:text>: </xsl:text></tei:pc>
</xsl:when>
<xsl:when test="preceding-sibling::*[1][self::tei:sense]">
<tei:pc><xsl:text>; </xsl:text></tei:pc>
</xsl:when>
</xsl:choose>
</xsl:when>
<xsl:when test="(parent::tei:sense or parent::abv:exampleGrp) and preceding-sibling::*[1][self::abv:example]">
<tei:pc><xsl:text>; </xsl:text></tei:pc>
</xsl:when>
</xsl:choose>
<xsl:element name="tei:cit">
<xsl:attribute name="type">example</xsl:attribute>
<xsl:call-template name="defaultlang"/>
<xsl:apply-templates select="@* | node()"/>
</xsl:element>
</xsl:template>
<xsl:template match="abv:exampleGrp">
<xsl:choose>
<xsl:when test="ancestor::tei:re[parent::tei:entry[child::tei:sense]]">
<tei:pc><xsl:text>: </xsl:text></tei:pc>
</xsl:when>
<xsl:otherwise><tei:pc>. — </tei:pc></xsl:otherwise>
</xsl:choose>
<xsl:element name="tei:dictScrap">
<xsl:apply-templates select="@*"/>
<xsl:if test="@n"><xsl:value-of select="@n"/><xsl:text>. </xsl:text></xsl:if>
<xsl:apply-templates select="node()"/>
</xsl:element>
</xsl:template>
<xsl:template match="tei:re[tei:re]">
<xsl:element name="tei:dictScrap">
<xsl:apply-templates select="@*|node()"/>
</xsl:element>
</xsl:template>
<!-- FORMS AND FORM GROUPS -->
<xsl:template match="abv:formGrp">
<xsl:choose>
<xsl:when test="preceding-sibling::*[1][self::tei:sense or self::tei:re]">
<tei:pc><xsl:text>; </xsl:text></tei:pc>
</xsl:when>
<xsl:when test="preceding-sibling::*[1][self::tei:form] or (parent::tei:entry and preceding-sibling::*[1][self::abv:formGrp])">
<tei:pc><xsl:text>, </xsl:text></tei:pc>
</xsl:when>
<xsl:when test="preceding-sibling::*[1][self::abv:exampleGrp]">
<tei:pc><xsl:text>. — </xsl:text></tei:pc>
</xsl:when>
</xsl:choose>
<xsl:element name="tei:cit">
<xsl:attribute name="type">formGrp</xsl:attribute>
<xsl:apply-templates select="@* | node()"/>
</xsl:element>
</xsl:template>
<xsl:template match="tei:form">
<xsl:choose>
<xsl:when test="preceding-sibling::*[1][self::tei:usg]">
<tei:pc><xsl:text> </xsl:text></tei:pc>
</xsl:when>
<xsl:when test="preceding-sibling::*[1][self::tei:form[@xml:lang='os-x-iron']] and @xml:lang='os-x-digor'">
<tei:pc><xsl:text> | </xsl:text></tei:pc>
</xsl:when>
<xsl:when test="(preceding-sibling::*[1][self::tei:orth] and (@type='variant' or @type='synonym')) or (preceding-sibling::*[1][self::tei:form] and parent::tei:form and @type = 'variant')">
<tei:pc><xsl:text>, </xsl:text></tei:pc>
</xsl:when>
<xsl:when test="preceding-sibling::*[1][self::tei:orth or self::tei:form[@type = 'variant']] and @type='participle'">
<tei:pc><xsl:text> : </xsl:text></tei:pc>
</xsl:when>
</xsl:choose>
<xsl:if test="@subtype='parens'"><xsl:text>(</xsl:text></xsl:if>
<xsl:copy>
<xsl:if test="not(@xml:lang)">
<xsl:attribute name="xml:lang" select="ancestor::tei:entry/@xml:lang"/>
</xsl:if>
<xsl:apply-templates select="@*"/>
<xsl:if test="@type='rec'"><xsl:text>*</xsl:text></xsl:if>
<xsl:apply-templates select="node()"/>
</xsl:copy>
<xsl:if test="@subtype='parens'"><xsl:text>)</xsl:text></xsl:if>
</xsl:template>
<!-- WORDS ETC. -->
<xsl:template match="tei:w | tei:m | tei:c | tei:phr | tei:oRef">
<xsl:if test="preceding-sibling::*[1][@xml:lang='os-x-iron'] and @xml:lang='os-x-digor'"> <!-- THIS IS A HACK. MAYBE I'LL HAVE TO LIST THE TAG NAMES AFTER ALL -->
<tei:pc><xsl:text> | </xsl:text></tei:pc>
</xsl:if>
<xsl:copy>
<xsl:apply-templates select="@*"/>
<xsl:if test="@type='rec'"><xsl:text>*</xsl:text></xsl:if>
<xsl:apply-templates select="node()"/>
</xsl:copy>
</xsl:template>
<!-- Orth after lang or gram -->
<xsl:template match="tei:form/tei:orth[preceding-sibling::*[1][self::tei:lang or self::tei:gram]]">
<tei:pc><xsl:text> </xsl:text></tei:pc>
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<!-- USAGE NOTES -->
<xsl:template match="tei:usg">
<xsl:variable name="is_afterForm"><xsl:value-of select="boolean(preceding-sibling::*[1][self::tei:form or self::abv:formGrp])"/></xsl:variable>
<xsl:if test="$is_afterForm">
<tei:pc><xsl:text> </xsl:text></tei:pc>
</xsl:if>
<xsl:copy>
<xsl:apply-templates select="@*"/>
<xsl:if test="$is_afterForm">
<tei:pc><xsl:text>(</xsl:text></tei:pc>
</xsl:if>
<xsl:apply-templates select="node()"/>
<xsl:if test="$is_afterForm">
<tei:pc><xsl:text>)</xsl:text></tei:pc>
</xsl:if>
</xsl:copy>
</xsl:template>
<!-- SENSES -->
<xsl:template match="tei:sense">
<xsl:choose>
<xsl:when test="preceding-sibling::*[1][self::abv:formGrp or self::tei:re or self::tei:usg or self::tei:note]">
<tei:pc><xsl:text> </xsl:text></tei:pc>
</xsl:when>
<xsl:when test="parent::tei:entry or parent::tei:re">
<xsl:choose>
<xsl:when test="preceding-sibling::*[1][self::tei:sense]">
<tei:pc><xsl:text>; </xsl:text></tei:pc>
</xsl:when>
<xsl:when test="preceding-sibling::*[1][self::tei:form]">
<tei:pc><xsl:text> </xsl:text></tei:pc>
</xsl:when>
</xsl:choose>
</xsl:when>
<xsl:when test="parent::tei:sense and preceding-sibling::*[1][self::tei:sense]">
<tei:pc><xsl:text>, </xsl:text></tei:pc>
</xsl:when>
</xsl:choose>
<xsl:copy>
<xsl:apply-templates select="@*"/>
<xsl:if test="@n"><xsl:value-of select="@n"/>. </xsl:if>
<xsl:apply-templates select="node()"/>
</xsl:copy>
</xsl:template>
<!-- RELATED ENTRIES -->
<xsl:template match="tei:re">
<xsl:choose>
<xsl:when test="preceding-sibling::*[1][self::abv:formGrp]">
<tei:pc><xsl:text> </xsl:text></tei:pc>
</xsl:when>
<xsl:when test="parent::tei:sense">
<xsl:choose>
<xsl:when test="preceding-sibling::*[1][self::tei:re] or preceding-sibling::*[1][self::tei:sense] or (preceding-sibling::*[1][self::abv:tr] and child::*[1][self::tei:form])">
<tei:pc><xsl:text>; </xsl:text></tei:pc>
</xsl:when>
<xsl:when test="preceding-sibling::*[1][self::abv:tr] and child::*[1][self::tei:form]">
<tei:pc><xsl:text>: </xsl:text></tei:pc>
</xsl:when>
<xsl:when test="parent::*[abv:tr] and preceding-sibling::*[1][self::tei:note]">
<tei:pc><xsl:text>; </xsl:text></tei:pc>
</xsl:when>
</xsl:choose>
</xsl:when>
<xsl:when test="parent::tei:entry">
<xsl:choose>
<xsl:when test="preceding-sibling::*[self::tei:re and child::abv:exampleGrp]"><tei:pc><xsl:text>. — </xsl:text></tei:pc></xsl:when>
<xsl:when test="(preceding-sibling::*[1][self::tei:note] and child::*[1][self::tei:form]) or preceding-sibling::*[1][self::tei:sense or self::tei:re]"><tei:pc><xsl:text>; </xsl:text></tei:pc></xsl:when>
</xsl:choose>
</xsl:when>
<xsl:when test="parent::tei:re">
<xsl:choose>
<xsl:when test="preceding-sibling::*[1][self::tei:re and child::abv:exampleGrp]">
<tei:pc><xsl:text>; </xsl:text></tei:pc>
</xsl:when>
<xsl:when test="preceding-sibling::*[1][self::tei:re]">
<tei:pc><xsl:text>, </xsl:text></tei:pc>
</xsl:when>
</xsl:choose>
</xsl:when>
<xsl:when test="preceding-sibling::*[1][self::abv:exampleGrp]">
<tei:pc><xsl:text>. — </xsl:text></tei:pc>
</xsl:when>
</xsl:choose>
<xsl:copy>
<xsl:call-template name="defaultlang"/>
<xsl:apply-templates select="@*"/>
<xsl:apply-templates select="node()"/>
</xsl:copy>
</xsl:template>
<!-- BIBLIO -->
<xsl:template match="abv:example/tei:bibl">
<xsl:choose>
<xsl:when test="preceding-sibling::*[self::tei:bibl]">
<tei:pc><xsl:text>; </xsl:text></tei:pc>
</xsl:when>
<xsl:otherwise>
<tei:pc><xsl:text> (</xsl:text></tei:pc>
</xsl:otherwise>
</xsl:choose>
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
<xsl:if test="last()">
<tei:pc><xsl:text>)</xsl:text></tei:pc>
</xsl:if>
</xsl:template>
<!-- ENTRY AND ETYM PUNCTUATION -->
<xsl:template match="tei:entry[not(tei:etym)]">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy><tei:pc>.</tei:pc>
</xsl:template>
<xsl:template match="tei:etym">
<tei:pc>.</tei:pc><tei:lb/><xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<!-- QUOTE -->
<xsl:template match="tei:quote[preceding-sibling::*[1][self::tei:usg]]">
<tei:pc> </tei:pc><xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<!-- CROSSREF PUNCTUATION -->
<xsl:template match="tei:entry/tei:ref[@type='xr']">
<xsl:if test="preceding-sibling::*[1][self::tei:sense]">
<tei:pc><xsl:text>; </xsl:text></tei:pc>
</xsl:if>
<xsl:copy>
<xsl:apply-templates select="@*"/>
<xsl:choose>
<xsl:when test="$standardize-lang = 'en'">
<xsl:text>see </xsl:text>
</xsl:when>
<xsl:when test="$standardize-lang = 'ru'">
<xsl:text>см. </xsl:text>
</xsl:when>
</xsl:choose>
<xsl:apply-templates select="node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>