tei to md xsl

Created Diff never expires
2 removals
Lines
Total
Removed
Words
Total
Removed
To continue using this feature, upgrade to
Diffchecker logo
Diffchecker Pro
216 lines
26 additions
Lines
Total
Added
Words
Total
Added
To continue using this feature, upgrade to
Diffchecker logo
Diffchecker Pro
240 lines
<xsl:stylesheet
<xsl:stylesheet
version="2.0"
version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:tei="http://www.tei-c.org/ns/1.0"
xmlns:tei="http://www.tei-c.org/ns/1.0"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xpath-default-namespace="http://www.tei-c.org/ns/1.0">
xpath-default-namespace="http://www.tei-c.org/ns/1.0">


<xsl:import href="../common/common.xsl"/>
<xsl:import href="../common/common.xsl"/>


<xsl:strip-space elements="additional address adminInfo
<xsl:strip-space elements="additional address adminInfo
altGrp altIdentifier analytic
altGrp altIdentifier analytic
app appInfo application
app appInfo application
arc argument attDef
arc argument attDef
@@ -84,173 +84,197 @@
@@ -84,173 +84,197 @@
vMerge vNot vRange valItem
vMerge vNot vRange valItem
valList vocal"/>
valList vocal"/>


<doc xmlns="http://www.oxygenxml.com/ns/doc/xsl" scope="stylesheet" type="stylesheet">
<doc xmlns="http://www.oxygenxml.com/ns/doc/xsl" scope="stylesheet" type="stylesheet">
<desc>
<desc>


<p>This software is dual-licensed:
<p>This software is dual-licensed:


1. Distributed under a Creative Commons Attribution-ShareAlike 3.0
1. Distributed under a Creative Commons Attribution-ShareAlike 3.0
Unported License http://creativecommons.org/licenses/by-sa/3.0/
Unported License http://creativecommons.org/licenses/by-sa/3.0/


2. http://www.opensource.org/licenses/BSD-2-Clause
2. http://www.opensource.org/licenses/BSD-2-Clause




Redistribution and use in source and binary forms, with or without
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
modification, are permitted provided that the following conditions are
met:
met:


* Redistributions of source code must retain the above copyright
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
notice, this list of conditions and the following disclaimer.


* Redistributions in binary form must reproduce the above copyright
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
documentation and/or other materials provided with the distribution.


This software is provided by the copyright holders and contributors
This software is provided by the copyright holders and contributors
"as is" and any express or implied warranties, including, but not
"as is" and any express or implied warranties, including, but not
limited to, the implied warranties of merchantability and fitness for
limited to, the implied warranties of merchantability and fitness for
a particular purpose are disclaimed. In no event shall the copyright
a particular purpose are disclaimed. In no event shall the copyright
holder or contributors be liable for any direct, indirect, incidental,
holder or contributors be liable for any direct, indirect, incidental,
special, exemplary, or consequential damages (including, but not
special, exemplary, or consequential damages (including, but not
limited to, procurement of substitute goods or services; loss of use,
limited to, procurement of substitute goods or services; loss of use,
data, or profits; or business interruption) however caused and on any
data, or profits; or business interruption) however caused and on any
theory of liability, whether in contract, strict liability, or tort
theory of liability, whether in contract, strict liability, or tort
(including negligence or otherwise) arising in any way out of the use
(including negligence or otherwise) arising in any way out of the use
of this software, even if advised of the possibility of such damage.
of this software, even if advised of the possibility of such damage.
</p>
</p>
<p>Author: See AUTHORS</p>
<p>Author: See AUTHORS</p>


<p>Copyright: 2013, TEI Consortium</p>
<p>Copyright: 2013, TEI Consortium</p>
</desc>
</desc>
</doc>
</doc>


<xsl:output method="text"/>
<xsl:output method="text"/>


<xsl:template match="teiHeader"/>
<xsl:template match="teiHeader"/>
<xsl:template match="figDesc"/>
<xsl:template match="figDesc"/>
<xsl:template match="gap/desc"/>
<xsl:template match="gap/desc"/>
<xsl:template match="choice">
<xsl:template match="choice">
<xsl:apply-templates select="*[1]"/>
<xsl:apply-templates select="*[1]"/>
</xsl:template>
</xsl:template>
<xsl:template match="speaker"/>
<xsl:template match="speaker"/>
<xsl:template match="facsimile"/>
<xsl:template match="facsimile"/>


<xsl:template name="appReading">
<xsl:template name="appReading">
<xsl:param name="lemma"/>
<xsl:param name="lemma"/>
<xsl:param name="lemmawitness"/>
<xsl:param name="lemmawitness"/>
<xsl:param name="readings"/>
<xsl:param name="readings"/>
</xsl:template>
</xsl:template>


<xsl:template name="emphasize">
<xsl:template name="emphasize">
<xsl:param name="class"/>
<xsl:param name="class"/>
<xsl:param name="content"/>
<xsl:param name="content"/>
<xsl:choose>
<xsl:choose>
<xsl:when test="$class='titlem'">
<xsl:when test="$class='titlem'">
<xsl:text>_</xsl:text>
<xsl:text>_</xsl:text>
<xsl:copy-of select="$content"/>
<xsl:copy-of select="$content"/>
<xsl:text>_</xsl:text>
<xsl:text>_</xsl:text>
</xsl:when>
</xsl:when>
<xsl:when test="$class='titlej'">
<xsl:when test="$class='titlej'">
<xsl:text>_</xsl:text>
<xsl:text>_</xsl:text>
<xsl:copy-of select="$content"/>
<xsl:copy-of select="$content"/>
<xsl:text>_</xsl:text>
<xsl:text>_</xsl:text>
</xsl:when>
</xsl:when>
<xsl:when test="$class='titlea'">
<xsl:when test="$class='titlea'">
<xsl:text>‘</xsl:text>
<xsl:text>‘</xsl:text>
<xsl:copy-of select="$content"/>
<xsl:copy-of select="$content"/>
<xsl:text>’</xsl:text>
<xsl:text>’</xsl:text>
</xsl:when>
</xsl:when>
<xsl:otherwise>
<xsl:otherwise>
<xsl:copy-of select="$content"/>
<xsl:copy-of select="$content"/>
</xsl:otherwise>
</xsl:otherwise>
</xsl:choose>
</xsl:choose>
</xsl:template>
</xsl:template>


<xsl:template name="generateEndLink">
<xsl:template name="generateEndLink">
<xsl:param name="where"/>
<xsl:param name="where"/>
</xsl:template>
</xsl:template>


<xsl:template name="horizontalRule">
<xsl:template name="horizontalRule">
<xsl:text>&#10;---&#10;</xsl:text>
<xsl:text>&#10;---&#10;</xsl:text>
</xsl:template>
</xsl:template>


<xsl:template name="makeBlock">
<xsl:template name="makeBlock">
<xsl:param name="style"/>
<xsl:param name="style"/>
<xsl:apply-templates/>
<xsl:apply-templates/>
<xsl:call-template name="newline"/>
<xsl:call-template name="newline"/>
</xsl:template>
</xsl:template>


<xsl:template name="makeInline">
<xsl:template name="makeInline">
<xsl:param name="before"/>
<xsl:param name="before"/>
<xsl:param name="style"/>
<xsl:param name="style"/>
<xsl:param name="after"/>
<xsl:param name="after"/>
</xsl:template>
</xsl:template>


<xsl:template name="makeSpan">
<xsl:template name="makeSpan">
<xsl:apply-templates/>
<xsl:apply-templates/>
</xsl:template>
</xsl:template>


<xsl:template match="p">
<xsl:template match="q">
<xsl:text>“</xsl:text>
<xsl:apply-templates/>
<xsl:text>”</xsl:text>
</xsl:template>

<xsl:template match="hi[@rend = 'bold']">
<xsl:text>**</xsl:text>
<xsl:apply-templates/>
<xsl:text>**</xsl:text>
</xsl:template>

<xsl:template match="l">
<xsl:apply-templates/>
<xsl:text> </xsl:text>
<xsl:call-template name="newline"/>
</xsl:template>

<xsl:template match="p|trailer|lg">
<xsl:call-template name="newline"/>
<xsl:call-template name="newline"/>
<xsl:apply-templates/>
<xsl:apply-templates/>
<xsl:call-template name="newline"/>
<xsl:call-template name="newline"/>
</xsl:template>
</xsl:template>


<xsl:template match="note/p|ref">
<xsl:text> \[</xsl:text>
<xsl:apply-templates/>
<xsl:text>\] </xsl:text>
</xsl:template>

<xsl:template match="head">
<xsl:template match="head">
<xsl:choose>
<xsl:choose>
<xsl:when test="parent::castList"/>
<xsl:when test="parent::castList"/>
<xsl:when test="parent::figure"/>
<xsl:when test="parent::figure"/>
<xsl:when test="parent::list"/>
<xsl:when test="parent::list"/>
<xsl:when test="parent::front or parent::body or
<xsl:when test="parent::front or parent::body or
parent::back or parent::lg">&#10;*<xsl:apply-templates/>&#10;
parent::back or parent::lg">&#10;*<xsl:apply-templates/>&#10;
</xsl:when>
</xsl:when>
<xsl:when test="parent::table"/>
<xsl:when test="parent::table"/>
<xsl:otherwise>
<xsl:otherwise>
<xsl:variable name="depth">
<xsl:variable name="depth">
<xsl:apply-templates mode="depth" select=".."/>
<xsl:apply-templates mode="depth" select=".."/>
</xsl:variable>
</xsl:variable>
<xsl:call-template name="newline"/>
<xsl:call-template name="newline"/>
<xsl:choose>
<xsl:choose>
<xsl:when test="$depth=0">#</xsl:when>
<xsl:when test="$depth=0">#</xsl:when>
<xsl:when test="$depth=1">##</xsl:when>
<xsl:when test="$depth=1">##</xsl:when>
<xsl:when test="$depth=2">###</xsl:when>
<xsl:when test="$depth=2">###</xsl:when>
<xsl:when test="$depth=3">####</xsl:when>
<xsl:when test="$depth=3">####</xsl:when>
<xsl:when test="$depth=4">#####</xsl:when>
<xsl:when test="$depth=4">#####</xsl:when>
<xsl:otherwise>#</xsl:otherwise>
<xsl:otherwise>#</xsl:otherwise>
</xsl:choose>
</xsl:choose>
<xsl:text> </xsl:text>
<xsl:text> </xsl:text>
<xsl:apply-templates/>
<xsl:apply-templates/>
<xsl:call-template name="newline"/>
<xsl:call-template name="newline"/>
</xsl:otherwise>
</xsl:otherwise>
</xsl:choose>
</xsl:choose>
</xsl:template>
</xsl:template>


<!-- TEI graphic elements convert to a simple structure, but it's
<!-- TEI graphic elements convert to a simple structure, but it's
complicated figuring out where best to get the alt and title
complicated figuring out where best to get the alt and title
text from. Thanks @sydb for more elegant XPath. -->
text from. Thanks @sydb for more elegant XPath. -->
<xsl:template match="tei:graphic[@url]">
<xsl:template match="tei:graphic[@url]">
<xsl:variable name="altText" as="xs:string" select="xs:string((
<xsl:variable name="altText" as="xs:string" select="xs:string((
parent::tei:figure/tei:figDesc[1],
parent::tei:figure/tei:figDesc[1],
parent::tei:figure/tei:head[1],
parent::tei:figure/tei:head[1],
child::tei:desc[1],
child::tei:desc[1],
'graphic'
'graphic'
)[1])"/>
)[1])"/>
<xsl:variable name="titleText" as="xs:string" select="xs:string((
<xsl:variable name="titleText" as="xs:string" select="xs:string((
parent::tei:figure/tei:head[1],
parent::tei:figure/tei:head[1],
parent::tei:figure/figDesc[1],
parent::tei:figure/figDesc[1],
child::tei:desc[1],
child::tei:desc[1],
'graphic'
'graphic'
)[1])"/>
)[1])"/>
<xsl:variable name="dim" as="xs:string*">
<xsl:variable name="dim" as="xs:string*">
<xsl:if test="@width or @height">
<xsl:if test="@width or @height">
<xsl:text>{:</xsl:text>
<xsl:text>{:</xsl:text>
<xsl:for-each select="@width | @height">
<xsl:for-each select="@width | @height">
<xsl:value-of select="' ' || local-name(.) || '=&quot;' || . || '&quot;'"/>
<xsl:value-of select="' ' || local-name(.) || '=&quot;' || . || '&quot;'"/>
</xsl:for-each>
</xsl:for-each>
<xsl:text>}</xsl:text>
<xsl:text>}</xsl:text>
</xsl:if>
</xsl:if>
</xsl:variable>
</xsl:variable>
<xsl:sequence select="
<xsl:sequence select="
'!['
'!['
||$altText
||$altText
||']('
||']('
@@ -260,26 +284,28 @@ of this software, even if advised of the possibility of such damage.
@@ -260,26 +284,28 @@ of this software, even if advised of the possibility of such damage.
||'&quot;)'
||'&quot;)'
||string-join( $dim, '')
||string-join( $dim, '')
"/>
"/>
</xsl:template>
</xsl:template>


<!-- Suppress all attributes on graphic element. -->
<!-- Suppress all attributes on graphic element. -->
<xsl:template match="tei:graphic/@*"/>
<xsl:template match="tei:graphic/@*"/>




<xsl:template match="tei:item|tei:biblStruct">
<xsl:template match="tei:item|tei:biblStruct">
<xsl:call-template name="newline"/>
<xsl:call-template name="newline"/>
<xsl:choose>
<xsl:choose>
<xsl:when test="tei:isOrderedList(..)">1.</xsl:when>
<xsl:when test="tei:isOrderedList(..)">1.</xsl:when>
<xsl:otherwise>*</xsl:otherwise>
<xsl:otherwise>*</xsl:otherwise>
</xsl:choose>
</xsl:choose>
<xsl:apply-templates/>
<xsl:apply-templates/>
<xsl:call-template name="newline"/>
<xsl:call-template name="newline"/>
</xsl:template>
</xsl:template>


<xsl:template name="newline">
<xsl:template name="newline">
<xsl:text>&#10;</xsl:text>
<xsl:text>&#10;</xsl:text>
</xsl:template>
</xsl:template>


<xsl:template match="*">
<xsl:template match="*">
<xsl:apply-templates/>
<xsl:apply-templates/>
</xsl:template>
</xsl:template>


</xsl:stylesheet>
</xsl:stylesheet>