-
Notifications
You must be signed in to change notification settings - Fork 0
/
tei-to-markdown.xsl
367 lines (317 loc) · 13.1 KB
/
tei-to-markdown.xsl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
<xsl:stylesheet
version="2.0"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:tei="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="../Stylesheets/common/common.xsl"/>
<xsl:strip-space elements="additional address adminInfo
altGrp altIdentifier analytic
app appInfo application
arc argument attDef
attList availability back bibl
biblFull biblStruct bicond
binding bindingDesc body
broadcast cRefPattern calendar
calendarDesc castGroup
castList category cell certainty
char charDecl charProp
choice cit classDecl
classSpec classes climate
cond constraintSpec correction
custodialHist decoDesc
dimensions div div1 div2
div3 div4 div5 div6
div7 divGen docTitle eLeaf
eTree editionStmt
editorialDecl elementSpec
encodingDesc entry epigraph
epilogue equipment event
exemplum fDecl fLib
facsimile figure fileDesc
floatingText forest front
fs fsConstraints fsDecl
fsdDecl fvLib gap glyph
graph graphic group
handDesc handNotes history
hom hyphenation iNode if
imprint incident index
interpGrp interpretation join
joinGrp keywords kinesic
langKnowledge langUsage
layoutDesc leaf lg linkGrp
list listBibl listChange
listEvent listForest listNym
listOrg listPerson listPlace
listRef listRelation
listTranspose listWit location
locusGrp macroSpec metDecl
moduleRef moduleSpec monogr
msContents msDesc msIdentifier
msItem msItemStruct msPart
namespace node normalization
notatedMusic notesStmt nym
objectDesc org p particDesc
performance person personGrp
physDesc place population
postscript precision
profileDesc projectDesc
prologue publicationStmt
quotation rdgGrp recordHist
recording recordingStmt
refsDecl relatedItem relation
relationGrp remarks respStmt
respons revisionDesc root
row samplingDecl schemaSpec
scriptDesc scriptStmt seal
sealDesc segmentation
seriesStmt set setting
settingDesc sourceDesc
sourceDoc sp spGrp space
spanGrp specGrp specList
state stdVals subst
substJoin superEntry
supportDesc surface surfaceGrp
table tagsDecl taxonomy
teiCorpus teiHeader terrain
text textClass textDesc
timeline titlePage titleStmt
trait transpose tree
triangle typeDesc vAlt
vColl vDefault vLabel
vMerge vNot vRange valItem
valList vocal"/>
<doc xmlns="http://www.oxygenxml.com/ns/doc/xsl" scope="stylesheet" type="stylesheet">
<desc>
<p>This 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.
</p>
<p>Author: See AUTHORS</p>
<p>Copyright: 2013, TEI Consortium</p>
</desc>
</doc>
<xsl:output method="text"/>
<xsl:template match="teiHeader"/>
<xsl:template match="figDesc"/>
<xsl:template match="gap/desc"/>
<xsl:template match="choice">
<xsl:apply-templates select="*[1]"/>
</xsl:template>
<xsl:template match="speaker"/>
<xsl:template match="facsimile"/>
<xsl:template name="appReading">
<xsl:param name="lemma"/>
<xsl:param name="lemmawitness"/>
<xsl:param name="readings"/>
</xsl:template>
<xsl:template name="emphasize">
<xsl:param name="class"/>
<xsl:param name="content"/>
<xsl:choose>
<xsl:when test="$class='titlem'">
<xsl:text>_</xsl:text>
<xsl:copy-of select="$content"/>
<xsl:text>_</xsl:text>
</xsl:when>
<xsl:when test="$class='titlej'">
<xsl:text>_</xsl:text>
<xsl:copy-of select="$content"/>
<xsl:text>_</xsl:text>
</xsl:when>
<xsl:when test="$class='titlea'">
<xsl:text>‘</xsl:text>
<xsl:copy-of select="$content"/>
<xsl:text>’</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:copy-of select="$content"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="generateEndLink">
<xsl:param name="where"/>
</xsl:template>
<xsl:template name="horizontalRule">
<xsl:text> --- </xsl:text>
</xsl:template>
<xsl:template name="makeBlock">
<xsl:param name="style"/>
<xsl:apply-templates/>
<xsl:call-template name="newline"/>
</xsl:template>
<xsl:template name="makeInline">
<xsl:param name="before"/>
<xsl:param name="style"/>
<xsl:param name="after"/>
</xsl:template>
<xsl:template match="eg[@xml:space='preserve']">
<xsl:text>```
</xsl:text><xsl:value-of select="."/><xsl:text>
```</xsl:text>
</xsl:template>
<xsl:template match="eg"><xsl:value-of disable-output-escaping="no" select="concat('`',normalize-space(.),'`')"/></xsl:template>
<xsl:template name="makeSpan">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="p|front">
<xsl:call-template name="newline"/>
<xsl:apply-templates/>
<xsl:call-template name="newline"/>
</xsl:template>
<xsl:template match="docTitle">
<xsl:call-template name="newline"/>
<xsl:for-each select=".//title[@type='main']"># <xsl:apply-templates select="."/> </xsl:for-each> <xsl:for-each select=".//title[@type='sub']"> <br> <xsl:apply-templates select="."/> </xsl:for-each>
<xsl:call-template name="newline"/>
</xsl:template>
<xsl:template match="docAuthor">
<xsl:for-each select=".//name|.//addrLine">
> <xsl:apply-templates select="."/> <xsl:value-of select="'<br>'"/>
</xsl:for-each>
</xsl:template>
<xsl:template match="div[@type='abstract']">
<xsl:call-template name="newline"/>
## Abstract
<xsl:call-template name="newline"/>
<xsl:apply-templates/>
<xsl:call-template name="newline"/>
</xsl:template>
<xsl:template match="head">
<xsl:choose>
<xsl:when test="parent::castList"/>
<xsl:when test="parent::listBibl"/>
<xsl:when test="parent::figure"/>
<xsl:when test="parent::list"/>
<xsl:when test="parent::front or parent::body or
parent::back or parent::lg"> *<xsl:apply-templates/> </xsl:when>
<xsl:when test="parent::table"/>
<xsl:otherwise>
<xsl:variable name="depth">
<xsl:apply-templates mode="depth" select=".."/>
</xsl:variable>
<xsl:call-template name="newline"/>
<xsl:choose>
<xsl:when test="$depth=0">##</xsl:when>
<xsl:when test="$depth=1">###</xsl:when>
<xsl:when test="$depth=2">####</xsl:when>
<xsl:when test="$depth=3">#####</xsl:when>
<xsl:when test="$depth=4">######</xsl:when>
<xsl:otherwise>##</xsl:otherwise>
</xsl:choose>
<xsl:text> </xsl:text>
<xsl:apply-templates/>
<xsl:call-template name="newline"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="tei:item|tei:biblStruct">
<xsl:call-template name="newline"/>
<xsl:choose>
<xsl:when test="tei:isOrderedList(..)">1. </xsl:when>
<xsl:otherwise>* </xsl:otherwise>
</xsl:choose>
<xsl:apply-templates/>
<xsl:call-template name="newline"/>
</xsl:template>
<xsl:template name="newline">
<xsl:text> </xsl:text>
</xsl:template>
<xsl:template match="listBibl">
<xsl:apply-templates select="head"/>
<xsl:apply-templates select="bibl">
<xsl:sort select="concat(author[1],title[1])" data-type="text"/>
</xsl:apply-templates>
</xsl:template>
<xsl:template match="ref"><xsl:apply-templates/></xsl:template>
<xsl:template match="bibl">
<xsl:call-template name="newline"/>
<xsl:for-each select="author|editor"><xsl:if test="position() > 1 and position()=last()"><xsl:text> and </xsl:text></xsl:if><xsl:apply-templates/><xsl:if test="position() >= 1 and not(position() = last())"><xsl:text>, </xsl:text></xsl:if></xsl:for-each><xsl:if test="date"><xsl:text>,
</xsl:text><xsl:apply-templates select="date"/><xsl:text>. </xsl:text></xsl:if><xsl:if test="title">
<xsl:if test="title[@level = 'a']">
<xsl:apply-templates select="title[@level = 'a']"/><xsl:text>. </xsl:text><xsl:if test="title[@level = 'j']|title[@level = 'm']"><xsl:text> In:
</xsl:text></xsl:if>
</xsl:if>
<xsl:if test="title[@level = 'j']|title[@level = 'm']">_<xsl:apply-templates select="title[@level = 'j']|title[@level = 'm']"/>_<xsl:text> </xsl:text>
</xsl:if>
</xsl:if>
<xsl:if test="biblScope[@type='volume']">
<xsl:text>Vol. </xsl:text><xsl:apply-templates select="biblScope[@type='volume']"/><xsl:if test="biblScope[@type='number']">(<xsl:apply-templates select="biblScope[@type='number']"/>)<xsl:choose><xsl:when test="biblScope[@type='pp']"><xsl:text>, </xsl:text></xsl:when><xsl:otherwise><xsl:text>. </xsl:text></xsl:otherwise></xsl:choose></xsl:if></xsl:if> <xsl:if test="biblScope[@type='pp']"> <xsl:text>pp. </xsl:text><xsl:apply-templates select="biblScope[@type='pp']"/><xsl:text>. </xsl:text></xsl:if>
<xsl:if test="note">
<xsl:apply-templates select="note/node()"/>
</xsl:if>
<xsl:if test="ref"><xsl:text>
<kbd></xsl:text>[<xsl:apply-templates select="ref/@target"/>](<xsl:apply-templates select="ref/@target"/>)</kbd>
</xsl:if>
<xsl:call-template name="newline"/>
</xsl:template>
<xsl:template match="table">
<xsl:for-each select="row[@role='label']"><xsl:for-each select="cell[@role='label']"><xsl:if test="position() = 1">| </xsl:if> <xsl:apply-templates/> | <xsl:if test="position() = last()"><xsl:call-template name="newline"/></xsl:if></xsl:for-each></xsl:for-each>
<xsl:for-each select="row[@role='label']"><xsl:for-each select="cell[@role='label']"><xsl:if test="position() = 1">| </xsl:if> :-------- | <xsl:if test="position() = last()"><xsl:call-template name="newline"/></xsl:if></xsl:for-each>
</xsl:for-each>
<xsl:for-each select="row[@role='data']"><xsl:for-each select="cell"><xsl:if test="position() = 1">| </xsl:if> <xsl:apply-templates/> | <xsl:if test="position() = last()"><xsl:call-template name="newline"/></xsl:if></xsl:for-each>
</xsl:for-each>
</xsl:template>
<xsl:template match="*"><xsl:apply-templates/></xsl:template>
<xsl:function name="tei:isOrderedList" as="xs:boolean">
<xsl:param name="context"/>
<xsl:for-each select="$context">
<xsl:choose>
<xsl:when test="tei:match(@rend,'numbered')">true</xsl:when>
<xsl:when test="tei:match(@rend,'ordered')">true</xsl:when>
<xsl:when test="@type='ordered'">true</xsl:when>
<xsl:otherwise>false</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:function>
<xsl:function name="tei:match" as="xs:boolean">
<xsl:param name="att"/>
<xsl:param name="value"/>
<xsl:sequence select="if (tokenize($att,' ')=($value)) then true()
else false()"/>
</xsl:function>
<xsl:template match="tei:text" mode="depth">
<xsl:value-of select="count(ancestor::tei:text)-1"/>
</xsl:template>
<xsl:template match="tei:div|tei:div1|tei:div2|tei:div3|tei:div4|tei:div5|tei:div6"
mode="depth">
<xsl:choose>
<xsl:when test="ancestor::tei:text/parent::tei:group and
self::tei:div">
<xsl:value-of select="count(ancestor::tei:div) + 1"/>
</xsl:when>
<xsl:when test="local-name(.) = 'div'">
<xsl:value-of select="count(ancestor::tei:div)"/>
</xsl:when>
<xsl:when test="ancestor::tei:text/parent::tei:group">
<xsl:value-of select="number(substring-after(local-name(.),'div')) "/>
</xsl:when>
<xsl:when test="ancestor::tei:text/parent::tei:group">
<xsl:value-of select="number(substring-after(local-name(.),'div'))"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="number(substring-after(local-name(.),'div')) - 1"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>