TEI stylesheet for making TEI files from
OpenOffice. Originally derived from the OpenOffice /Docbook
conversion, but largely rewritten
LicenseThis software is dual-licensed:
1. Distributed under a Creative Commons Attribution-ShareAlike 3.0
Unported License http://creativecommons.org/licenses/by-sa/3.0/
2. http://www.opensource.org/licenses/BSD-2-Clause
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
This software is provided by the copyright holders and contributors
"as is" and any express or implied warranties, including, but not
limited to, the implied warranties of merchantability and fitness for
a particular purpose are disclaimed. In no event shall the copyright
holder or contributors be liable for any direct, indirect, incidental,
special, exemplary, or consequential damages (including, but not
limited to, procurement of substitute goods or services; loss of use,
data, or profits; or business interruption) however caused and on any
theory of liability, whether in contract, strict liability, or tort
(including negligence or otherwise) arising in any way out of the use
of this software, even if advised of the possibility of such damage.
<xsl:template match="text:h[@text:outline-level]"><xsl:choose><xsl:when test="ancestor::text:note-body"><p><xsl:attribute name="rend"><xsl:choose><xsl:when test="@text:style-name"><xsl:value-of select="@text:style-name"/></xsl:when><xsl:otherwise>heading</xsl:otherwise></xsl:choose></xsl:attribute><xsl:apply-templates/></p></xsl:when><xsl:otherwise><HEAD level="{@text:outline-level}"><xsl:attribute name="style"><xsl:choose><xsl:when test="@text:style-name"><xsl:value-of select="@text:style-name"/></xsl:when><xsl:otherwise>nostyle</xsl:otherwise></xsl:choose></xsl:attribute><!--
We do not process hard page breaks here directly
but defer their output until the sections get created.
Therefore we add a dedicated attribute '@page-break-before'
for flagging this.
--><xsl:attribute name="page-break-before" select="exists(tei:pagebreak-before(.))"/><xsl:apply-templates/></HEAD></xsl:otherwise></xsl:choose></xsl:template>
<xsl:template name="applyStyle"><xsl:variable name="name"><xsl:value-of select="replace(@text:style-name,'tei_5f_','')"/></xsl:variable><xsl:variable name="style"><xsl:value-of select="@text:style-name"/></xsl:variable><xsl:choose><xsl:when test="string-length(.)=0 and not (text:s or draw:frame)"/><!-- if the style name is the same as that of a known TEI
element, make it that --><xsl:when test="doc-available('../names.xml') and doc('../names.xml')//tei:gi[.=$name]"><xsl:element name="{$name}"><xsl:call-template name="id.attribute"/><xsl:apply-templates/></xsl:element></xsl:when><xsl:otherwise><xsl:variable name="rendition" select="tei:inlineStyles($style,.)"/><xsl:choose><xsl:when test="self::text:p and count(parent::table:table-cell/text:p)=1"><xsl:if test="not($rendition='')"><xsl:attribute name="rend" select="$rendition"/></xsl:if><xsl:apply-templates/></xsl:when><xsl:when test="self::text:p"><p><xsl:call-template name="id.attribute"/><xsl:if test="not($rendition='')"><xsl:attribute name="rend" select="$rendition"/></xsl:if><xsl:apply-templates/></p></xsl:when><xsl:when test="$rendition=''"><xsl:apply-templates/></xsl:when><xsl:otherwise><hi rend="{$rendition}"><xsl:apply-templates/></hi></xsl:otherwise></xsl:choose></xsl:otherwise></xsl:choose></xsl:template>
Since soft page breaks are an optional and application specific feature, we disregard
them completely.
See the OpenDocument specification
for further information.
<xsl:template name="group-by-section"><xsl:variable name="ThisHeader" select="number(@level)"/><xsl:variable name="NextHeader" select="number(@level)+1"/><xsl:choose><xsl:when test="@magic"><xsl:for-each-group select="current-group() except ." group-starting-with="tei:HEAD[number(@level)=$NextHeader]"><xsl:choose><xsl:when test="self::tei:HEAD"><xsl:call-template name="group-by-section"/></xsl:when><xsl:otherwise><xsl:call-template name="inSection"/></xsl:otherwise></xsl:choose></xsl:for-each-group></xsl:when><xsl:otherwise><!--
hard page breaks before sections are passed on via the
@page-break-before attribute and need to get injected here
--><xsl:if test="@page-break-before='true'"><pb/></xsl:if><div><xsl:choose><xsl:when test="starts-with(@style,'Heading')"/><xsl:when test="@style"><xsl:attribute name="rend" select="@style"/></xsl:when></xsl:choose><xsl:if test="not(@interpolated='true')"><head><xsl:apply-templates mode="pass1"/></head></xsl:if><xsl:for-each-group select="current-group() except ." group-starting-with="tei:HEAD[number(@level)=$NextHeader]"><xsl:choose><xsl:when test="self::tei:HEAD"><xsl:call-template name="group-by-section"/></xsl:when><xsl:otherwise><xsl:call-template name="inSection"/></xsl:otherwise></xsl:choose></xsl:for-each-group></div></xsl:otherwise></xsl:choose></xsl:template>