Skip to content
Permalink
8fcfc0aaf5
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
292 lines (267 sloc) 12.6 KB
<?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:param name="frontmatter" as="xs:boolean" required="no" select="false()"/>
<xsl:param name="frontmattermanual" as="xs:boolean" required="no" select="false()"/>
<xsl:param name="contributors" as="xs:boolean" required="no" select="false()"/>
<xsl:param name="strictfloats" as="xs:boolean" required="no" select="false()"/>
<xsl:param name="indentfloats" as="xs:boolean" required="no" select="false()"/>
<xsl:param name="extranewpage" as="xs:boolean" required="no" select="false()"/>
<xsl:param name="manualpreambel" as="xs:boolean" required="no" select="false()"/>
<xsl:param name="hyphenation" as="xs:boolean" required="no" select="false()"/>
<xsl:param name="verbosity" as="xs:integer" required="no" select="0"/>
<xsl:include href="tei2eoatex/eoatex_contributors.xsl"/>
<xsl:include href="tei2eoatex/eoatex_frontmatter.xsl"/>
<xsl:include href="tei2eoatex/eoatex_functions.xsl"/>
<xsl:include href="tei2eoatex/eoatex_persons.xsl"/>
<xsl:include href="tei2eoatex/eoatex_processinginstructions.xsl"/>
<xsl:include href="tei2eoatex/eoatex_textparts.xsl"/>
<xsl:variable name="langid" select="//tei:langUsage/tei:language/@ident"/>
<xsl:variable name="transl" select="document('../../data/aux/translations.xml')"/>
<xsl:key name="en" match="translations/entry" use="@en"/>
<xsl:key name="de" match="translations/entry" use="@de"/>
<xsl:key name="fr" match="translations/entry" use="@fr"/>
<xsl:key name="it" match="translations/entry" use="@it"/>
<xsl:output method="text" encoding="UTF-8" use-character-maps="texreplacements"/>
<xsl:character-map name="texreplacements">
<!--
the character map replaces characters
In the stylesheet below, a sign (&#x2E0E;) is used to denote a
comment in LaTeX. The sign itself is unlikely to occur in the
text. The LaTeX comment sign is originally a percent sign, but
since this the percent sign needs to be escaped in other
contexts, a double replacement is performed.
-->
<xsl:output-character character="&#x23;" string="\#"/>
<xsl:output-character character="&#x26;" string="\&amp;"/>
<xsl:output-character character="&#x25;" string="\%"/>
<xsl:output-character character="&#x2E0E;" string="%"/>
<xsl:output-character character="&#x00A0;" string="~"/>
<xsl:output-character character="&#x2E0F;" string="&amp;"/>
</xsl:character-map>
<xsl:template match="*">
<!--
catchall template
https://stackoverflow.com/questions/3360017/why-does-xslt-output-all-text-by-default
-->
<xsl:variable name="current_el" as="xs:string"><xsl:call-template name="print_el_with_ctxt"/></xsl:variable>
<xsl:value-of select="eoa:debug(2, 'Unmatched element: ', $current_el)"/>
<xsl:apply-templates/>
</xsl:template>
<!-- default template: print warning -->
<xsl:template mode="header" match="*">
<xsl:value-of select="eoa:debug(2, 'Unmatched header element: ', name())"/>
<xsl:apply-templates/>
</xsl:template>
<xsl:template mode="header" match="tei:teiHeader//tei:seriesStmt/tei:title">
<xsl:value-of select="."/>
</xsl:template>
<xsl:template match="/">
<xsl:value-of select="eoa:texcomment(concat('LaTeX output, generated by script tei2eoatex.xsl on ', current-dateTime()))" />
<xsl:value-of select="eoa:texcomment(concat('Using ', system-property('xsl:product-name'), system-property('xsl:product-version'), ' by ', system-property('xsl:vendor'), ' (', system-property('xsl:vendor-url'), ')'))" />
<xsl:text>&#x000a;</xsl:text>
<xsl:choose>
<xsl:when test="$manualpreambel">
<xsl:text>\input{preambel/pre_eoa}&#x000a;</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="eoa:texcomment('Preambel is to be attached by eoatex2pdf script')"/>
</xsl:otherwise>
</xsl:choose>
<xsl:text>\EOAbibliographytype{</xsl:text>
<xsl:value-of select="//tei:sourceDesc/tei:ab[@type='bibdatabase']/tei:ref/@type"/>
<xsl:text>}&#x000a;</xsl:text>
<xsl:text>\EOAbibliographydatabase{</xsl:text>
<xsl:value-of select="substring-before(//tei:sourceDesc/tei:ab[@type='bibdatabase']/tei:ref/@target, '.bib')"/>
<xsl:text>}&#x000a;</xsl:text>
<xsl:text>\EOAseries{</xsl:text>
<xsl:apply-templates mode="header" select="//tei:seriesStmt/tei:title"/>
<xsl:text>}&#x000a;</xsl:text>
<xsl:choose>
<xsl:when test="$hyphenation">
<xsl:text>\input{texfiles/hyphenation}&#x000a;</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="eoa:texcomment('No hyphenation rules added.')"/>
</xsl:otherwise>
</xsl:choose>
<xsl:text>&#x000a;\begin{document}&#x000a;</xsl:text>
<xsl:choose>
<xsl:when test="$frontmatter">
<xsl:choose>
<xsl:when test="$frontmattermanual">
<xsl:text>\input{texfiles/frontmatter-manual.tex}&#x000a;</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>\input{texfiles/frontmatter.tex}&#x000a;</xsl:text>
<xsl:call-template name="writefrontmatter"/>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="eoa:debug(1, 'Not writing the frontmatter.', '')" />
<xsl:text>&#x000a;</xsl:text>
<xsl:value-of select="eoa:texcomment('No frontmatter created yet. Insert it like so:')" />
<xsl:value-of select="eoa:texcomment('\input{texfiles/frontmatter.tex}')" />
<xsl:text>&#x000a;</xsl:text>
</xsl:otherwise>
</xsl:choose>
<xsl:text>\pagenumbering{arabic}&#x000a;\setcounter{page}{1}&#x000a;\EOAtoc&#x000a; <!--\EOAnewpage&#x000a;-->
</xsl:text>
<xsl:choose>
<xsl:when test="$contributors">
<xsl:text>&#x000a;\EOAchapternonumber{List of Contributors}{List of Contributors}&#x000a;</xsl:text>
<xsl:text>\input{texfiles/contributors.tex}&#x000a;&#x000a;</xsl:text>
<xsl:call-template name="writecontributors"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="eoa:debug(1, 'Not writing list of contributors.', '')" />
<xsl:text>&#x000a;</xsl:text>
</xsl:otherwise>
</xsl:choose>
<xsl:choose>
<xsl:when test="//tei:body//tei:div[@type='part']">
<xsl:value-of select="eoa:debug(1, 'Book has parts. ', name())"/>
<xsl:call-template name="hasparts"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="eoa:debug(1, 'Book has no parts, the highest level is chapter. ', name())"/>
<xsl:call-template name="hasnoparts"/>
</xsl:otherwise>
</xsl:choose>
<xsl:text>\end{document}&#x000a;</xsl:text>
<xsl:sequence select="eoa:debug(1, 'DONE!', '')"/>
</xsl:template>
<!-- <xsl:template match="/"> ends here -->
<xsl:template name="hasparts">
<!-- render chapters which are not inside parts: -->
<xsl:for-each select="//tei:body/tei:div[@type='chapter']">
<xsl:variable name="filename" select="concat('texfiles/beforepart-chapter', format-number(position(), '00'), '.tex')"/>
<xsl:result-document method="text" include-content-type="no" href="{$filename}">
<xsl:apply-templates select="."/>
</xsl:result-document>
<xsl:call-template name="include_chapter">
<xsl:with-param name="file" select="$filename"/>
</xsl:call-template>
</xsl:for-each>
<!-- render parts: -->
<xsl:for-each select="//tei:div[@type='part']">
<xsl:variable name="partposition" select="position()"/>
<xsl:value-of select="eoa:debug(0, concat('printing part ', $partposition ), '')" />
<xsl:call-template name="start_part"/>
<!-- include chapters: -->
<xsl:for-each select="tei:div[ @type = ('chapter', 'chapteroriginal', 'chaptertranslation', 'indexchapter')]">
<xsl:sequence select="eoa:debug(1, concat('including chapter ', position() ), '')" />
<xsl:call-template name="include_chapter">
<xsl:with-param name="file" select="concat('texfiles/part', $partposition, '-chapter', format-number(position(), '00'), '.tex')"/>
</xsl:call-template>
</xsl:for-each>
<!-- write chapters: -->
<xsl:for-each select="tei:div[@type='chapter' or @type='chapteroriginal' or @type='chaptertranslation']">
<xsl:sequence select="eoa:debug(1, concat('printing chapter ', position() ), '')" />
<xsl:result-document method="text" include-content-type="no" href="{concat('texfiles/part', $partposition, '-chapter', format-number(position(), '00'), '.tex')}">
<xsl:apply-templates select="."/>
</xsl:result-document>
</xsl:for-each>
</xsl:for-each>
</xsl:template>
<!-- <xsl:template name="hasparts"> ends here -->
<xsl:template name="hasnoparts">
<xsl:for-each select="//tei:body/tei:div[@type='chapter' or @type='chapteroriginal' or @type='chaptertranslation' or @type='indexchapter']">
<xsl:sequence select="eoa:debug(1, concat('including chapter ', position() ), '')" />
<xsl:call-template name="include_chapter">
<xsl:with-param name="file" select="concat('texfiles/chapter', format-number(position(), '00'), '.tex')"/>
</xsl:call-template>
</xsl:for-each>
<xsl:for-each select="//tei:div[@type='chapter']">
<xsl:sequence select="eoa:debug(1, concat('printing chapter ', position() ), '')" />
<xsl:result-document method="text" include-content-type="no" href="{concat('texfiles/chapter', format-number(position(), '00'), '.tex')}">
<xsl:apply-templates select="."/>
</xsl:result-document>
</xsl:for-each>
</xsl:template>
<xsl:template name="start_part">
<xsl:variable name="partposition" select="position()"/>
<xsl:if test="not(tei:head)">
<xsl:sequence select="eoa:debug(3, 'part has no tei:head!', $partposition)" />
</xsl:if>
<xsl:text>\EOApart{</xsl:text>
<xsl:apply-templates select="tei:head"/>
<xsl:choose>
<xsl:when test="not(@xml:id)">
<xsl:value-of select="eoa:debug(1, 'No ID for part', node())" />
<xsl:text>}&#x000a;</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>}\EOAlabel{</xsl:text>
<xsl:value-of select="@xml:id"/>
<xsl:text>}&#x000a;</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="include_chapter">
<xsl:param name="file" as="xs:string"/>
<xsl:choose>
<xsl:when test="@type='indexchapter'">
<xsl:text>\EOAtocentry{</xsl:text>
<xsl:apply-templates select="tei:head"/>
<xsl:text>}</xsl:text>
<xsl:apply-templates select="tei:p"/>
<xsl:text>&#x000a;&#x000a;</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="tei:head"/>
<xsl:text>&#x000a;</xsl:text>
<xsl:choose>
<xsl:when test="not(@xml:id)">
<xsl:value-of select="eoa:debug(1, concat('Chapter has no ID: ', @n), '')" />
</xsl:when>
<xsl:otherwise>
<xsl:text>\EOAlabel{</xsl:text>
<xsl:value-of select="@xml:id"/>
<xsl:text>}&#x000a;</xsl:text>
</xsl:otherwise>
</xsl:choose>
<!-- <xsl:call-template name="chapterauthor"/> -->
<xsl:text>&#x000a;\input{</xsl:text>
<xsl:value-of select="$file"/>
<xsl:text>}&#x000a;&#x000a;</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!-- https://stackoverflow.com/questions/5035501/how-do-i-replace-sequences-of-whitespaces-by-one-space-but-dont-trim-in-xslt -->
<xsl:template match="text()">
<xsl:value-of select="translate(normalize-space(concat('&#x7F;',.,'&#x7F;')),'&#x7F;','')"/>
</xsl:template>
<!-- utils -->
<!-- print -->
<xsl:template name="print_el_with_ctxt" as="xs:string">
<xsl:value-of>
<xsl:for-each select="parent::*">
<xsl:call-template name="print_el"/>
</xsl:for-each>
<xsl:text>/</xsl:text>
<xsl:call-template name="print_el"/>
</xsl:value-of>
</xsl:template>
<xsl:template name="print_el" as="xs:string">
<xsl:value-of>
<xsl:value-of select="name()"/>
<xsl:if test="attribute::*">
<xsl:text>[</xsl:text>
<xsl:for-each select="attribute::*">
<xsl:value-of select="concat('@', name(), '=', .)"/>
<xsl:if test="position() != last()">
<xsl:text> and </xsl:text>
</xsl:if>
</xsl:for-each>
<xsl:text>]</xsl:text>
</xsl:if>
</xsl:value-of>
</xsl:template>
</xsl:stylesheet>