Skip to content

Commit

Permalink
Add tei2xelatex code
Browse files Browse the repository at this point in the history
kthoden committed Dec 8, 2020
1 parent cfed49d commit b3bff8a
Showing 7 changed files with 2,046 additions and 0 deletions.
459 changes: 459 additions & 0 deletions xxe/eoa/xsl/tei2xelatex.xsl

Large diffs are not rendered by default.

44 changes: 44 additions & 0 deletions xxe/eoa/xsl/tei2xelatex/contributors.xsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?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:template name="writecontributors">
<xsl:result-document method="text" include-content-type="no" href="{'texfiles/contributors.tex'}">
<xsl:value-of select="eoa:texcomment('List of contributors')" />
<xsl:for-each select="//tei:titleStmt/tei:respStmt">
<!-- sorting by lang="de" incorporates diacritics into the alphabet -->
<xsl:sort lang="de" select="tei:persName/tei:surname"/>
<xsl:sort lang="de" select="tei:persName/tei:forename"/>
<xsl:for-each select=".">
<xsl:if test="contains(tei:resp, 'chapter author')">
<xsl:text>\noindent\textbf{</xsl:text>
<xsl:variable name="people" select="@xml:id"/>
<xsl:call-template name="format_persons">
<xsl:with-param name="people" select="$people"/>
</xsl:call-template>
<xsl:text>}\par&#x000a;</xsl:text>
<xsl:for-each select="tei:persName/tei:affiliation">
<xsl:text>\noindent </xsl:text>
<xsl:value-of select="tei:roleName"/>
<xsl:text>\\&#x000a;</xsl:text>
<xsl:for-each select="tei:orgName">
<xsl:text>\noindent </xsl:text>
<xsl:value-of select="."/>
<xsl:text>\\&#x000a;</xsl:text>
</xsl:for-each>
</xsl:for-each>
<xsl:text>\noindent </xsl:text>
<xsl:value-of select="tei:persName/tei:email"/>
<xsl:text>\\&#x000a;</xsl:text>
<xsl:text>&#x000a;</xsl:text>
</xsl:if>
</xsl:for-each>
</xsl:for-each>
</xsl:result-document>
</xsl:template>
</xsl:stylesheet>
362 changes: 362 additions & 0 deletions xxe/eoa/xsl/tei2xelatex/frontmatter.xsl

Large diffs are not rendered by default.

37 changes: 37 additions & 0 deletions xxe/eoa/xsl/tei2xelatex/functions.xsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?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:function name="eoa:texcomment">
<xsl:param name="message" as="xs:string"/>
<xsl:text>&#x2E0E;&#x2E0E; </xsl:text>
<xsl:value-of select="$message"/>
<xsl:text>&#x000a;</xsl:text>
</xsl:function>

<xsl:function name="eoa:debug">
<xsl:param name="level" as="xs:integer"/>
<xsl:param name="message" as="xs:string"/>
<xsl:param name="node" />
<xsl:choose>
<xsl:when test="$level = 0 and $verbosity >= 3">
<xsl:message>[DEBUG]: <xsl:value-of select="$message"/> <xsl:value-of select="$node"/></xsl:message>
</xsl:when>
<xsl:when test="$level = 1 and $verbosity >= 2">
<xsl:message>[INFO]: <xsl:value-of select="$message"/> <xsl:value-of select="$node"/></xsl:message>
</xsl:when>
<xsl:when test="$level = 2 and $verbosity >= 1">
<xsl:message>[WARNING]: <xsl:value-of select="$message"/> <xsl:value-of select="$node"/></xsl:message>
</xsl:when>
<xsl:when test="$level = 3">
<xsl:message terminate="yes">[ERROR]: <xsl:value-of select="$message"/> <xsl:value-of select="$node"/>. Exiting.</xsl:message>
</xsl:when>
</xsl:choose>
</xsl:function>

</xsl:stylesheet>
107 changes: 107 additions & 0 deletions xxe/eoa/xsl/tei2xelatex/persons.xsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
<?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:template name="combine_names">
<xsl:choose>
<xsl:when test="./tei:persName/@xml:lang='zh'">
<xsl:variable name="formatted_author" select="concat(./tei:persName/tei:surname, ' ', ./tei:persName/tei:forename)"/>
<xsl:value-of select="$formatted_author"/>
</xsl:when>
<xsl:otherwise>
<xsl:variable name="formatted_author" select="concat(./tei:persName/tei:forename, ' ', ./tei:persName/tei:surname)"/>
<xsl:value-of select="$formatted_author"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>

<xsl:template name="format_persons">
<xsl:param name="people"/>
<xsl:variable name="joined_people" select="string-join($people, '')"/>
<xsl:variable name="num_people" select="count($people)"/>
<xsl:choose>
<xsl:when test="$num_people = 1">
<xsl:for-each select="//tei:teiHeader/tei:fileDesc/tei:titleStmt/tei:respStmt[contains($joined_people, @xml:id)]">
<xsl:call-template name="combine_names"/>
</xsl:for-each>
</xsl:when>
<xsl:when test="$num_people = 2">
<xsl:for-each select="//tei:teiHeader/tei:fileDesc/tei:titleStmt/tei:respStmt[contains($joined_people, @xml:id)]">
<xsl:call-template name="combine_names"/>
<xsl:if test="position()!=last()">
<xsl:text> and </xsl:text>
</xsl:if>
</xsl:for-each>
</xsl:when>
<xsl:when test="$num_people > 2">
<xsl:for-each select="//tei:teiHeader/tei:fileDesc/tei:titleStmt/tei:respStmt[contains($joined_people, @xml:id)]">
<xsl:call-template name="combine_names"/>
<!-- <xsl:value-of select="concat(./tei:persName/tei:forename, ' ', ./tei:persName/tei:surname)"/> -->
<xsl:choose>
<xsl:when test="position() &lt; $num_people - 1">
<xsl:text>, </xsl:text>
</xsl:when>
<xsl:when test="position()=$num_people - 1">
<xsl:text>, and </xsl:text>
</xsl:when>
</xsl:choose>
</xsl:for-each>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="eoa:debug(3, 'No book author. Exiting.', '')" />
</xsl:otherwise>
</xsl:choose>
</xsl:template>

<!-- next with thanks to https://www.oxygenxml.com/forum/topic712.html -->
<!-- expected ctxt: div[@type = 'chapter'] -->
<xsl:template name="eoaauthor">
<xsl:variable name="authors" select="@resp"/>
<xsl:variable name="num_authors" select="count(//tei:teiHeader/tei:fileDesc/tei:titleStmt/tei:respStmt[contains($authors, @xml:id)])"/>
<xsl:choose>
<xsl:when test="$num_authors = 0">
<xsl:value-of select="eoa:debug(1, 'No authors found in this chapter.', '')" />
</xsl:when>
<xsl:otherwise>
<xsl:text>\\ \textnormal{\textit{</xsl:text>
<xsl:choose>
<xsl:when test="$num_authors = 1">
<xsl:for-each select="//tei:teiHeader/tei:fileDesc/tei:titleStmt/tei:respStmt[contains($authors, @xml:id)]">
<xsl:call-template name="combine_names"/>
</xsl:for-each>
</xsl:when>
<xsl:when test="$num_authors = 2">
<xsl:for-each select="//tei:teiHeader/tei:fileDesc/tei:titleStmt/tei:respStmt[contains($authors, @xml:id)]">
<xsl:call-template name="combine_names"/>
<xsl:if test="position()!=last()">
<xsl:text> and </xsl:text>
</xsl:if>
</xsl:for-each>
</xsl:when>
<xsl:when test="$num_authors > 2">
<xsl:for-each select="//tei:teiHeader/tei:fileDesc/tei:titleStmt/tei:respStmt[contains($authors, @xml:id)]">
<xsl:call-template name="combine_names"/>
<xsl:choose>
<xsl:when test="position() &lt; $num_authors - 1">
<xsl:text>, </xsl:text>
</xsl:when>
<xsl:when test="position()=$num_authors - 1">
<xsl:text>, and </xsl:text>
</xsl:when>
</xsl:choose>
</xsl:for-each>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="eoa:debug(1, 'No chapter author: ', '')" />
</xsl:otherwise>
</xsl:choose>
<xsl:text>}}</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
44 changes: 44 additions & 0 deletions xxe/eoa/xsl/tei2xelatex/processinginstructions.xsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?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:template match="//processing-instruction()[name()='latex']">
<xsl:sequence select="eoa:debug(0, 'found processing instruction. type latex', '')"/>
<xsl:value-of select="."/>
</xsl:template>

<xsl:template match="processing-instruction('eoa')">
<xsl:sequence select="eoa:debug(0, 'found processing instruction. type: eoa', '')"/>
<xsl:choose>
<xsl:when test="contains(., 'printbibliography')">
<xsl:choose>
<xsl:when test="substring-after(., ' ')">
<xsl:text>\printbibliography[</xsl:text>
<xsl:value-of select="substring-after(., ' ')"/>
<xsl:text>]&#x000a;&#x000a;</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>\printbibliography&#x000a;&#x000a;</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:when test="contains(., 'printindex')">
<xsl:text>\printindex[keywords]&#x000a;&#x000a;</xsl:text>
</xsl:when>
<xsl:when test="contains(., 'printpersonindex')">
<xsl:text>\printindex[persons]&#x000a;&#x000a;</xsl:text>
</xsl:when>
<xsl:when test="contains(., 'printlocationindex')">
<xsl:text>\printindex[locations]&#x000a;&#x000a;</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="eoa:debug(2, 'Unrecognized processing instruction: ', current())" />
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
Loading

0 comments on commit b3bff8a

Please sign in to comment.