Skip to content

Commit

Permalink
Add JATS to TEI conversion with XSL
Browse files Browse the repository at this point in the history
  • Loading branch information
kthoden committed Aug 4, 2021
1 parent 25ecb0f commit 128889c
Showing 1 changed file with 260 additions and 0 deletions.
260 changes: 260 additions & 0 deletions src/stylesheets/jats2tei.xsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,260 @@
<?xml version="1.0"?>
<xsl:stylesheet version="2.0"
xmlns="http://www.tei-c.org/ns/1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:html="http://www.w3.org/1999/xhtml"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:eoa="http://www.edition-open-access.de/ns"
xmlns:xlink="http://www.w3.org/1999/xlink"
exclude-result-prefixes="xs html eoa xlink"
>
<xsl:output
method="xml"
encoding="UTF-8"
indent="yes"
version="1.0"
/>

<xsl:template
match="/"
>
<TEI xmlns="http://www.tei-c.org/ns/1.0">
<teiHeader>
<fileDesc>
<titleStmt>
<title>
<xsl:apply-templates select="//front/article-meta/title-group/article-title" />
</title>
</titleStmt>
<publicationStmt>
<p>Publication Information</p>
</publicationStmt>
<sourceDesc>
<p>Information about the source</p>
</sourceDesc>
</fileDesc>
</teiHeader>
<text>
<body>
<xsl:apply-templates select="//body" />
</body>
</text>
</TEI>
</xsl:template>

<xsl:template match="sec[@sec-type='chapter']">
<xsl:element name="div">
<xsl:attribute name="xml:id">
<xsl:value-of select="@id"/>
</xsl:attribute>
<xsl:attribute name="type">chapter</xsl:attribute>
<head><xsl:apply-templates select="./title"/></head>
<xsl:apply-templates select="*[not(self::title)]"/>
</xsl:element>
</xsl:template>

<xsl:template match="sec">
<xsl:element name="div">
<xsl:attribute name="xml:id">
<xsl:value-of select="@id"/>
</xsl:attribute>
<xsl:attribute name="type">section</xsl:attribute>

<head><xsl:apply-templates select="./title"/></head>
<xsl:apply-templates select="*[not(self::title)]"/>
</xsl:element>
</xsl:template>

<xsl:template match="sec[@sec-type='chapter']/sec/sec">
<xsl:element name="div">
<xsl:attribute name="xml:id">
<xsl:value-of select="@id"/>
</xsl:attribute>
<xsl:attribute name="type">subsection</xsl:attribute>
<head><xsl:apply-templates select="./title"/></head>
<xsl:apply-templates select="*[not(self::title)]"/>
</xsl:element>
</xsl:template>

<xsl:template match="sec[@sec-type='chapter']/sec/sec/sec">
<xsl:element name="div">
<xsl:attribute name="xml:id">
<xsl:value-of select="@id"/>
</xsl:attribute>
<xsl:attribute name="type">subsubsection</xsl:attribute>
<head><xsl:apply-templates select="./title"/></head>
<xsl:apply-templates select="*[not(self::title)]"/>
</xsl:element>
</xsl:template>

<xsl:template match="sec/p[not(descendant::disp-formula)]">
<p>
<xsl:apply-templates/>
</p>
</xsl:template>

<xsl:template match="xref[@ref-type='fn']">
<xsl:element name="note">
<xsl:attribute name="place">
<xsl:text>bottom</xsl:text>
</xsl:attribute>
<xsl:attribute name="xml:id">
<xsl:value-of select="@rid"/>
</xsl:attribute>
<p>
<xsl:apply-templates/>
</p>
</xsl:element>
</xsl:template>

<xsl:template match="xref[@ref-type='sec']">
<xsl:element name="ref">
<xsl:attribute name="target">
<xsl:value-of select="concat('#',@rid)"/>
</xsl:attribute>
<xsl:attribute name="type">number</xsl:attribute>
</xsl:element>
</xsl:template>

<xsl:template match="xref[@ref-type='bibr']">
<xsl:element name="ref">
<xsl:attribute name="target">
<xsl:value-of select="concat('#',@rid)"/>
</xsl:attribute>
<xsl:attribute name="type">year</xsl:attribute>
</xsl:element>
</xsl:template>

<xsl:template match="ext-link">
<xsl:element name="ref">
<xsl:attribute name="target">
<xsl:value-of select="@xlink:href"/>
</xsl:attribute>
<xsl:attribute name="type">url</xsl:attribute>
</xsl:element>
</xsl:template>

<xsl:template match="disp-quote/p">
<quote>
<xsl:apply-templates/>
</quote>
</xsl:template>

<xsl:template match="list">
<xsl:element name="list">
<xsl:attribute name="type">
<xsl:choose>
<xsl:when test="@list-type='order'">
<xsl:text>ordered</xsl:text>
</xsl:when>
<xsl:when test="@list-type='bullet'">
<xsl:text>unordered</xsl:text>
</xsl:when>
</xsl:choose>
</xsl:attribute>
<xsl:apply-templates select="list-item"/>
</xsl:element>
</xsl:template>

<xsl:template match="list-item/p">
<item><xsl:apply-templates/></item>
</xsl:template>

<xsl:template match="fig[@fig-type='content-image']">
<xsl:element name="figure">
<xsl:attribute name="xml:id">
<xsl:value-of select="@id"/>
</xsl:attribute>
<xsl:element name="graphic">
<xsl:attribute name="url">
<xsl:value-of select="graphic/@xlink:href"/>
</xsl:attribute>
</xsl:element>
<head>
<xsl:apply-templates select="caption/title"/>
</head>
</xsl:element>
</xsl:template>

<xsl:template match="italic">
<hi rend="italic">
<xsl:apply-templates/>
</hi>
</xsl:template>

<xsl:template match="bold">
<hi rend="bold">
<xsl:apply-templates/>
</hi>
</xsl:template>

<xsl:template match="sup">
<hi rend="superscript">
<xsl:apply-templates/>
</hi>
</xsl:template>

<xsl:template match="sub">
<hi rend="subscript">
<xsl:apply-templates/>
</hi>
</xsl:template>

<xsl:template match="table-wrap">
<xsl:element name="table">
<xsl:attribute name="xml:id">
<xsl:value-of select="@id"/>
</xsl:attribute>
<xsl:attribute name="cols">
<xsl:value-of select="count(./table/thead[1]/tr[1]/th)"/>
</xsl:attribute>
<xsl:attribute name="rows">
<xsl:value-of select="count(.//tr)"/>
</xsl:attribute>
<xsl:element name="head">
<xsl:apply-templates select="caption/title"/>
</xsl:element>
<xsl:apply-templates select="./table/thead"/>
<xsl:apply-templates select="./table/tbody"/>
</xsl:element>
</xsl:template>

<xsl:template match="thead/tr">
<row role="label">
<xsl:apply-templates select="th/p"/>
</row>
</xsl:template>

<xsl:template match="th/p">
<cell role="label"><xsl:apply-templates/></cell>
</xsl:template>

<xsl:template match="tbody/tr">
<row role="data">
<xsl:apply-templates select="td/p"/>
</row>
</xsl:template>

<xsl:template match="td/p">
<cell role="data"><xsl:apply-templates/></cell>
</xsl:template>

<xsl:template match="inline-formula">
<formula notation="tex" rend="inline">
<xsl:value-of select="tex-math"/>
</formula>
</xsl:template>

<xsl:template match="p/disp-formula">
<xsl:element name="ab">
<xsl:attribute name="xml:id">
<xsl:value-of select="@id"/>
</xsl:attribute>
<xsl:attribute name="type">equation</xsl:attribute>
<formula notation="tex">
<xsl:value-of select="tex-math"/>
</formula>
</xsl:element>
</xsl:template>

</xsl:stylesheet>

0 comments on commit 128889c

Please sign in to comment.