Skip to content

Commit

Permalink
improved code for dealing with TEI/XML from the journal ZfDG
Browse files Browse the repository at this point in the history
  • Loading branch information
tillgrallert committed Nov 21, 2024
1 parent 8a86bd7 commit e6db9f0
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 28 deletions.
76 changes: 49 additions & 27 deletions xslt/convert_tei-to-biblstruct_functions.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,19 @@
<xsl:template match="tei:biblScope" mode="m_simple">
<xsl:copy>
<xsl:choose>
<!-- normalise funky attribute values -->
<xsl:when test="@unit != ('chapter', 'column', 'issue', 'line', 'page', 'part', 'volume')">
<xsl:message>
<xsl:text>The value of @unit (</xsl:text>
<xsl:value-of select="@unit"/>
<xsl:text>) is not part of the canonical list</xsl:text>
</xsl:message>
<!-- this is ZfDG -->
<xsl:if test="@unit = 'year'">
<xsl:attribute name="unit" select="'volume'"/>
<xsl:apply-templates mode="m_simple" select="node()"/>
</xsl:if>
</xsl:when>
<xsl:when test="@unit and @from and @to">
<xsl:apply-templates mode="m_simple" select="@*"/>
</xsl:when>
Expand All @@ -383,7 +396,7 @@
<xsl:apply-templates mode="m_simple" select="tei:textLang"/>
<xsl:apply-templates mode="m_simple" select="tei:editor"/>
<xsl:apply-templates mode="m_simple" select="tei:imprint"/>
<xsl:apply-templates mode="m_simple" select="tei:biblScope"/>
<xsl:apply-templates mode="m_simple" select="descendant::tei:biblScope"/>
</xsl:copy>
</xsl:template>
<xsl:template match="tei:imprint" mode="m_simple">
Expand Down Expand Up @@ -520,9 +533,10 @@
</biblStruct>
</xsl:when>
<xsl:when test="tei:publicationStmt[descendant::tei:bibl]"/>
<!-- this is the weird encoding used by ZfDG -->
<xsl:when test="tei:titleStmt/tei:title/tei:biblStruct">
<biblStruct>
<xsl:apply-templates mode="m_identity-transform" select="tei:titleStmt/tei:title/tei:biblStruct/node()"/>
<xsl:apply-templates mode="m_simple" select="tei:titleStmt/tei:title/tei:biblStruct/node()"/>
<!-- add keywords from profileDesc -->
<xsl:apply-templates mode="m_fileDesc-to-biblStruct" select="following-sibling::tei:profileDesc/tei:textClass"/>
</biblStruct>
Expand Down Expand Up @@ -635,8 +649,8 @@
<xsl:text> </xsl:text>
<xsl:apply-templates mode="m_dhq-to-biblStruct" select="dhq:author_name/dhq:family"/>
</persName>
<xsl:apply-templates mode="m_identity-transform" select="tei:idno"/>
<xsl:apply-templates mode="m_dhq-to-biblStruct" select=".//tei:ref[matches(@target,'https*://orcid.org')]"/>
<xsl:apply-templates mode="m_fileDesc-to-biblStruct" select="tei:idno"/>
<xsl:apply-templates mode="m_dhq-to-biblStruct" select=".//tei:ref[matches(@target, 'https*://orcid.org')]"/>
<xsl:apply-templates mode="m_dhq-to-biblStruct" select="dhq:affiliation"/>
</author>
</xsl:template>
Expand All @@ -656,38 +670,46 @@
<xsl:value-of select="normalize-space($v_name)"/>
</surname>
</xsl:template>
<xsl:template match="dhq:authorInfo//tei:ref[matches(@target,'https*://orcid.org')]" mode="m_dhq-to-biblStruct">
<xsl:template match="dhq:authorInfo//tei:ref[matches(@target, 'https*://orcid.org')]" mode="m_dhq-to-biblStruct">
<idno type="ORCID">
<xsl:value-of select="replace(@target, 'https*://orcid.org/(.+)$', '$1')"/>
</idno>
</xsl:template>
<xsl:template match="tei:title[ancestor::tei:titleStmt]" mode="m_fileDesc-to-biblStruct">
<xsl:choose>
<xsl:when test="tei:title">
<xsl:template match="tei:title[parent::tei:titleStmt]" mode="m_fileDesc-to-biblStruct">
<!-- <xsl:choose>-->
<!-- some titles nest. for instance, in the case of reviews -->
<!--<xsl:when test="tei:title">
<xsl:apply-templates mode="m_fileDesc-to-biblStruct" select="tei:title"/>
</xsl:when>
<xsl:otherwise>
<xsl:copy>
<xsl:apply-templates mode="m_identity-transform" select="@*"/>
<xsl:attribute name="level" select="'a'"/>
<xsl:attribute name="xml:lang">
<xsl:choose>
<xsl:when test="@xml:lang">
<xsl:value-of select="@xml:lang"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="ancestor::tei:TEI/tei:text/@xml:lang"/>
</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
<xsl:apply-templates mode="m_plain-text" select="."/>
</xsl:copy>
</xsl:otherwise>
</xsl:choose>
</xsl:when>-->
<!-- <xsl:otherwise>-->
<xsl:copy>
<xsl:apply-templates mode="m_identity-transform" select="@*"/>
<xsl:attribute name="level" select="'a'"/>
<xsl:attribute name="xml:lang">
<xsl:choose>
<xsl:when test="@xml:lang">
<xsl:value-of select="@xml:lang"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="ancestor::tei:TEI/tei:text/@xml:lang"/>
</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
<xsl:apply-templates mode="m_plain-text" select="."/>
</xsl:copy>
<!--</xsl:otherwise>-->
<!--</xsl:choose>-->
</xsl:template>
<xsl:template match="tei:author | tei:date | tei:idno | tei:publisher | tei:title" mode="m_fileDesc-to-biblStruct">
<xsl:apply-templates mode="m_identity-transform" select="."/>
</xsl:template>
<!-- clean ORCID -->
<xsl:template match="tei:idno[matches(@type, 'orcid', 'i')]" mode="m_fileDesc-to-biblStruct m_simple" priority="2">
<xsl:copy>
<xsl:apply-templates mode="m_identity-transform" select="@*"/>
<xsl:value-of select="replace(., 'https*://orcid.org/(.+)$', '$1')"/>
</xsl:copy>
</xsl:template>
<xsl:template match="text()[. = 'NA'] | tei:title/@ref | tei:title/@resp" mode="m_simple"/>
<!-- the following two templates are based on authority control and can be safely removed if this isn't needed -->
<!--<xsl:template match="tei:pubPlace[tei:placeName[@ref][@ref != 'NA']]" mode="m_simple">
Expand Down
2 changes: 1 addition & 1 deletion xslt/convert_tei-to-mods_filedesc.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<xsl:output method="xml" encoding="UTF-8" indent="yes" omit-xml-declaration="no" version="1.0"/>
<xsl:preserve-space elements="tei:head tei:bibl"/>

<xsl:import href="convert_tei-to-biblstruct_functions.xsl"/>
<!-- <xsl:import href="convert_tei-to-biblstruct_functions.xsl"/>-->
<xsl:import href="convert_tei-to-mods_functions.xsl"/>

<xsl:template match="/">
Expand Down
4 changes: 4 additions & 0 deletions xslt/convert_tei-to-mods_functions.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,10 @@
<xsl:when test="@n">
<xsl:value-of select="@n"/>
</xsl:when>
<!-- fallback: no information in attributes -->
<xsl:otherwise>
<xsl:value-of select="."/>
</xsl:otherwise>
</xsl:choose>
</number>
</detail>
Expand Down

0 comments on commit e6db9f0

Please sign in to comment.