-
Notifications
You must be signed in to change notification settings - Fork 0
/
jTei2html5.xsl
307 lines (289 loc) · 8.46 KB
/
jTei2html5.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
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="3.0"
xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="xs"
xmlns="http://www.w3.org/1999/xhtml" xpath-default-namespace="http://www.tei-c.org/ns/1.0">
<!--
jTei2html5
@author emchateau
@since 2018-11-28
This transformation deal with articles encoded acording to the Journal of the Text-Encoding Initiative Article Schema
https://tei-c.org/release/doc/tei-p5-exemplars/html/tei_jtei.doc.html
@todo figure, graphic, cit, blockquote, notes, test eg and egXML
@rmq some legacy elements added compared to jTei schema for superscript, underscript, del, label
-->
<xsl:output method="xhtml" html-version="5.0" include-content-type="no" omit-xml-declaration="yes" exclude-result-prefixes="#all" encoding="UTF-8" indent="yes" />
<xsl:strip-space elements="*" />
<xsl:variable name="cssPath" select="'css/normalize.css', 'css/main.css'" />
<xsl:variable name="jsPath" select="'js/script.js'" />
<xsl:template match="/TEI">
<html lang="fr">
<xsl:apply-templates select="teiHeader" />
<body>
<xsl:apply-templates select="text" />
</body>
</html>
</xsl:template>
<xsl:template match="teiHeader">
<head>
<meta charset="utf-8" />
<meta http-equiv="content-type" content="text/html" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0" />
<title>
<xsl:for-each select="fileDesc/titleStmt/title">
<xsl:apply-templates />
<xsl:if test="position() != last()">
<xsl:text>, </xsl:text>
</xsl:if>
</xsl:for-each>
</title>
<xsl:for-each select="$cssPath">
<link href="{.}" rel="stylesheet" />
</xsl:for-each>
<xsl:for-each select="$jsPath">
<script src="{.}" />
</xsl:for-each>
</head>
</xsl:template>
<xsl:template match="text">
<main>
<xsl:apply-templates />
</main>
</xsl:template>
<xsl:template match="front | body | back">
<section class="{local-name(.)}">
<xsl:apply-templates />
</section>
</xsl:template>
<xsl:template match="front/div | front/body | front/back">
<article>
<xsl:apply-templates />
</article>
</xsl:template>
<xsl:template match="div">
<div>
<xsl:apply-templates />
</div>
</xsl:template>
<xsl:template match="p">
<p>
<xsl:apply-templates />
</p>
</xsl:template>
<xsl:template match="list">
<xsl:choose>
<xsl:when test="@type = 'ordered'">
<ol>
<xsl:apply-templates />
</ol>
</xsl:when>
<xsl:when test="@type = 'definition'">
<dl>
<xsl:apply-templates mode="definition" />
</dl>
</xsl:when>
<xsl:otherwise>
<ul>
<xsl:apply-templates />
</ul>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="item">
<li>
<xsl:apply-templates />
</li>
</xsl:template>
<xsl:template match="item" mode="definition">
<dt>
<xsl:apply-templates />
</dt>
</xsl:template>
<xsl:template match="head">
<xsl:variable name="level" select="count(ancestor::section | ancestor::div | ancestor::article)" />
<xsl:variable name="name" select="concat('h', $level)" />
<xsl:element name="{$name}">
<xsl:apply-templates select="@* | node()" />
</xsl:element>
</xsl:template>
<!-- cit et ref -->
<xsl:template match="quote">
<xsl:text>« </xsl:text>
<xsl:apply-templates />
<xsl:text> »</xsl:text>
</xsl:template>
<xsl:template match="note">
<div class="notes" id="{@xml:id}">
<a href="{concat('#bn', @xml:id)}">
<xsl:number count="note" level="any" />
<xsl:text>. </xsl:text>
</a>
<xsl:apply-templates/>
</div>
</xsl:template>
<xsl:template match="ref">
<a class="noteCall" href="{@target}" id="{concat('bn', substring-after(@target, '#'))}">
<xsl:number count="ref" level="any" />
</a>
</xsl:template>
<xsl:template match="cit">
<!-- @todo -->
</xsl:template>
<xsl:template match="figure">
<!-- @todo -->
</xsl:template>
<xsl:template match="graphic">
<!-- @todo -->
</xsl:template>
<xsl:template match="table">
<!-- @todo -->
</xsl:template>
<xsl:template match="lb">
<!-- @todo insert in schema -->
<br />
</xsl:template>
<xsl:template match="ptr">
<!-- @todo revoir -->
<a class="ptr" href="{@target}"><xsl:apply-templates/></a>
</xsl:template>
<!-- inline -->
<xsl:template match="abbr">
<abbr><xsl:apply-templates/></abbr>
</xsl:template>
<xsl:template match="att | gi | val | ident">
<pre class="{local-name(.)}"><xsl:apply-templates/></pre>
</xsl:template>
<xsl:template match="code">
<pre><xsl:apply-templates/></pre>
</xsl:template>
<xsl:template match="eg">
<code class="xml"><xsl:apply-templates/></code>
</xsl:template>
<xsl:template match="egXML">
<code><xsl:apply-templates/></code>
</xsl:template>
<xsl:template match="emph">
<emph><xsl:apply-templates/></emph>
</xsl:template>
<xsl:template match="foreign">
<mark class="lang"><xsl:apply-templates/></mark>
</xsl:template>
<xsl:template match="gap">
<gap>[...]</gap>
</xsl:template>
<xsl:template match="mentioned">
<em class="mentioned"><xsl:apply-templates/></em>
</xsl:template>
<xsl:template match="q">
<xsl:text>« </xsl:text>
<xsl:apply-templates/>
<xsl:text> »</xsl:text>
</xsl:template>
<xsl:template match="quote">
<xsl:text>« </xsl:text>
<xsl:apply-templates/>
<xsl:text> »</xsl:text>
</xsl:template>
<!--<xsl:template match="ref">
<a href="{@target}">
<xsl:apply-templates/>
</a>
</xsl:template>-->
<xsl:template match="soCalled">
<em class="soCalled">
<xsl:apply-templates />
</em>
</xsl:template>
<xsl:template match="supplied">
<xsl:text>[</xsl:text>
<xsl:apply-templates />
<xsl:text>]</xsl:text>
</xsl:template>
<xsl:template match="tag">
<pre>
<xsl:text><</xsl:text>
<xsl:apply-templates></xsl:apply-templates>
<xsl:text>></xsl:text>
</pre>
</xsl:template>
<xsl:template match="term">
<strong class="term"><xsl:apply-templates/></strong>
</xsl:template>
<xsl:template match="title">
<xsl:choose>
<xsl:when test="@level='a'">
<xsl:text>« </xsl:text>
<xsl:apply-templates/>
<xsl:text> »</xsl:text>
</xsl:when>
<xsl:when test="@level='j'">
<cite><xsl:apply-templates/></cite>
</xsl:when>
<xsl:otherwise><cite><xsl:apply-templates/></cite></xsl:otherwise>
</xsl:choose>
</xsl:template>
<!-- legacy -->
<xsl:template match="hi[@rend = 'italic']">
<em>
<xsl:apply-templates />
</em>
</xsl:template>
<xsl:template match="hi[@rend = 'bold']">
<strong>
<xsl:apply-templates />
</strong>
</xsl:template>
<xsl:template match="hi[@rend = 'superscript']">
<!-- @todo insert in schema -->
<sup>
<xsl:apply-templates />
</sup>
</xsl:template>
<xsl:template match="hi[@rend = 'underscript']">
<!-- @todo insert in schema -->
<sub>
<xsl:apply-templates />
</sub>
</xsl:template>
<xsl:template match="hi[@rend = 'smallcaps']">
<!-- @todo insert in schema -->
<sub>
<xsl:apply-templates />
</sub>
</xsl:template>
<xsl:template match="del">
<!-- @todo insert in schema -->
<del>
<xsl:apply-templates />
</del>
</xsl:template>
<xsl:template match="label">
<span class="label"><xsl:apply-templates/></span>
</xsl:template>
<xsl:template match="persName | placeName | orgName | date | docAuthor">
<span class="{local-name()}">
<xsl:apply-templates />
</span>
</xsl:template>
<!-- attributes -->
<!--<xsl:template match="*">
<xsl:element name="{local-name()}">
<xsl:apply-templates select="@*" />
<xsl:apply-templates select="node()" />
</xsl:element>
</xsl:template>-->
<xsl:template match="@xml:id">
<xsl:attribute name="id">
<xsl:value-of select="." />
</xsl:attribute>
</xsl:template>
<!--
<xsl:template match="@*">
<xsl:copy />
</xsl:template>-->
<!-- identity copy -->
<xsl:template match="node() | @*" mode="#all">
<xsl:copy>
<xsl:apply-templates select="node() | @*" mode="#current" />
</xsl:copy>
</xsl:template>
</xsl:stylesheet>