-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathhelper-functions.xsl
More file actions
522 lines (505 loc) · 23.3 KB
/
helper-functions.xsl
File metadata and controls
522 lines (505 loc) · 23.3 KB
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
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
<xsl:stylesheet xmlns="http://www.w3.org/1999/xhtml" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:t="http://www.tei-c.org/ns/1.0" xmlns:x="http://www.w3.org/1999/xhtml" xmlns:saxon="http://saxon.sf.net/" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:local="http://syriaca.org/ns" exclude-result-prefixes="xs t x saxon local" version="2.0">
<!-- =================================================================== -->
<!-- Helper Functions -->
<!-- =================================================================== -->
<xsl:variable name="odd">
<xsl:if test="doc-available(concat('xmldb:exist://',$app-root,'/documentation/syriaca-tei-main.odd'))">
<xsl:sequence select="doc(concat('xmldb:exist://',$app-root,'/documentation/syriaca-tei-main.odd'))"/>
</xsl:if>
</xsl:variable>
<!-- Add a lang attribute to HTML elements -->
<xsl:function name="local:attributes">
<xsl:param name="node"/>
<!-- Add lang attribute and direction attributes -->
<xsl:if test="$node/@xml:lang">
<xsl:copy-of select="$node/@xml:lang"/>
<xsl:attribute name="lang">
<xsl:value-of select="$node/@xml:lang"/>
</xsl:attribute>
<xsl:choose>
<xsl:when test="$node/@xml:lang='en'">
<xsl:attribute name="dir">
<xsl:value-of select="'ltr'"/>
</xsl:attribute>
</xsl:when>
<xsl:when test="$node/@xml:lang = ('syr','ar','syc','syr-Syrj')">
<xsl:attribute name="dir">
<xsl:value-of select="'rtl'"/>
</xsl:attribute>
</xsl:when>
</xsl:choose>
</xsl:if>
<!-- Add id attributes as html attributes -->
<xsl:choose>
<xsl:when test="$node/@xml:id">
<xsl:attribute name="id">
<xsl:value-of select="$node/@xml:id"/>
</xsl:attribute>
</xsl:when>
<xsl:when test="$node/@id">
<xsl:attribute name="id">
<xsl:value-of select="$node/@xml:id"/>
</xsl:attribute>
</xsl:when>
</xsl:choose>
<!-- Handle n attributes as span elements -->
<xsl:if test="$node/@n">
<span class="tei-attr-n">
<xsl:value-of select="string($node/@n)"/>
</span>
</xsl:if>
</xsl:function>
<!-- Function for adding footnotes -->
<xsl:function name="local:add-footnotes">
<xsl:param name="refs"/>
<xsl:param name="lang"/>
<xsl:if test="$refs != ''">
<span class="tei-footnote-refs" dir="ltr">
<xsl:if test="$lang != 'en'">
<xsl:attribute name="lang">en</xsl:attribute>
<xsl:attribute name="xml:lang">en</xsl:attribute>
</xsl:if>
<xsl:for-each select="tokenize($refs,' ')">
<span class="tei-footnote-ref">
<a href="{.}">
<xsl:value-of select="substring-after(.,'-')"/>
</a>
<xsl:if test="position() != last()">,<xsl:text> </xsl:text>
</xsl:if>
</span>
</xsl:for-each>
<xsl:text> </xsl:text>
</span>
</xsl:if>
</xsl:function>
<!-- Process names editors/authors orint max in function call -->
<xsl:function name="local:emit-responsible-persons">
<!-- node passed by refering stylesheet -->
<xsl:param name="current-node"/>
<!-- mode, footnote or biblist -->
<xsl:param name="moded"/>
<!-- max number of authors -->
<xsl:param name="maxauthors"/>
<!-- count number of relevant persons -->
<xsl:variable name="ccount">
<xsl:value-of select="count($current-node)"/>
</xsl:variable>
<!-- process based on above parameters -->
<xsl:choose>
<xsl:when test="$ccount=1 and $moded='footnote'">
<xsl:apply-templates select="$current-node[1]" mode="footnote"/>
</xsl:when>
<xsl:when test="$ccount=1 and $moded='biblist'">
<xsl:apply-templates select="$current-node[1]" mode="lastname-first"/>
</xsl:when>
<xsl:when test="$ccount > $maxauthors and $moded='footnote'">
<xsl:apply-templates select="$current-node[1]" mode="footnote"/>
<xsl:text> et al.</xsl:text>
</xsl:when>
<xsl:when test="$ccount > $maxauthors and $moded='biblist'">
<xsl:apply-templates select="$current-node[1]" mode="lastname-first"/>
<xsl:text> et al.</xsl:text>
</xsl:when>
<xsl:when test="$ccount = 2 and $moded='footnote'">
<xsl:apply-templates select="$current-node[1]" mode="footnote"/>
<xsl:text> and </xsl:text>
<xsl:apply-templates select="$current-node[2]" mode="footnote"/>
</xsl:when>
<xsl:when test="$ccount = 2 and $moded='biblist'">
<xsl:apply-templates select="$current-node[1]" mode="lastname-first"/>
<xsl:text> and </xsl:text>
<xsl:apply-templates select="$current-node[2]" mode="biblist"/>
</xsl:when>
<xsl:otherwise>
<xsl:for-each select="$current-node[position() < $maxauthors+1]">
<xsl:choose>
<xsl:when test="position() = $maxauthors">
<xsl:text> and </xsl:text>
</xsl:when>
<xsl:when test="position() = last()">
<xsl:text> and </xsl:text>
</xsl:when>
<xsl:when test="position() > 1">
<xsl:text>, </xsl:text>
</xsl:when>
</xsl:choose>
<xsl:choose>
<xsl:when test="$moded='footnote'">
<xsl:apply-templates mode="footnote"/>
</xsl:when>
<xsl:when test="$moded='biblist'">
<xsl:apply-templates mode="biblist"/>
</xsl:when>
</xsl:choose>
</xsl:for-each>
</xsl:otherwise>
</xsl:choose>
</xsl:function>
<!-- Process names editors/authors print all -->
<xsl:function name="local:emit-responsible-persons-all">
<!-- node passed by refering stylesheet -->
<xsl:param name="current-node"/>
<!-- mode, footnote or biblist -->
<xsl:param name="moded"/>
<!-- count number of relevant persons -->
<xsl:variable name="ccount">
<xsl:value-of select="count($current-node)"/>
</xsl:variable>
<!-- process based on above parameters -->
<xsl:choose>
<xsl:when test="$ccount=1 and $moded='footnote'">
<xsl:apply-templates select="$current-node[1]" mode="footnote"/>
</xsl:when>
<xsl:when test="$ccount=1 and $moded='biblist'">
<xsl:apply-templates select="$current-node[1]" mode="lastname-first"/>
</xsl:when>
<xsl:when test="$ccount = 2 and $moded='footnote'">
<xsl:apply-templates select="$current-node[1]" mode="footnote"/>
<xsl:text> and </xsl:text>
<xsl:apply-templates select="$current-node[2]" mode="footnote"/>
</xsl:when>
<xsl:when test="$ccount = 2 and $moded='biblist'">
<xsl:apply-templates select="$current-node[1]" mode="lastname-first"/>
<xsl:text> and </xsl:text>
<xsl:apply-templates select="$current-node[2]" mode="biblist"/>
</xsl:when>
<xsl:otherwise>
<xsl:for-each select="$current-node">
<xsl:choose>
<xsl:when test="position() = $ccount">
<xsl:if test="$ccount > 2">
<xsl:text>,</xsl:text>
</xsl:if>
<xsl:text> and </xsl:text>
</xsl:when>
<xsl:when test="position() > 1">
<xsl:text>, </xsl:text>
</xsl:when>
</xsl:choose>
<xsl:choose>
<xsl:when test="$moded='footnote'">
<xsl:apply-templates mode="footnote"/>
</xsl:when>
<xsl:when test="$moded='biblist'">
<xsl:apply-templates mode="biblist"/>
</xsl:when>
</xsl:choose>
</xsl:for-each>
</xsl:otherwise>
</xsl:choose>
</xsl:function>
<!-- Function to add correct ordinal suffix to numbers used in citation creation. -->
<xsl:function name="local:ordinal">
<xsl:param name="num" as="xs:string"/>
<xsl:choose>
<xsl:when test="number($num) = number($num)">
<xsl:choose>
<xsl:when test="ends-with($num,'1') and not($num = '11')">
<xsl:value-of select="concat($num, 'st ed.')"/>
</xsl:when>
<xsl:when test="ends-with($num,'2') and not($num = '12')">
<xsl:value-of select="concat($num, 'nd ed.')"/>
</xsl:when>
<xsl:when test="ends-with($num,'3') and not($num = '13')">
<xsl:value-of select="concat($num, 'rd ed.')"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="concat($num, 'th ed.')"/>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$num"/>
</xsl:otherwise>
</xsl:choose>
</xsl:function>
<!--
Function to output dates in correct formats passes whole element to function,
function also uses trim-date to strip leading 0
-->
<xsl:function name="local:do-dates">
<xsl:param name="element" as="node()"/>
<xsl:if test="$element/@when or $element/@notBefore or $element/@notAfter or $element/@from or $element/@to">
<xsl:choose>
<!-- Formats to and from dates -->
<xsl:when test="$element/@from">
<xsl:choose>
<xsl:when test="$element/@to">
<xsl:value-of select="local:trim-date($element/@from)"/>-<xsl:value-of select="local:trim-date($element/@to)"/>
</xsl:when>
<xsl:otherwise>from <xsl:value-of select="local:trim-date($element/@from)"/>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:when test="$element/@to">to <xsl:value-of select="local:trim-date($element/@to)"/>
</xsl:when>
</xsl:choose>
<!-- Formats notBefore and notAfter dates -->
<xsl:if test="$element/@notBefore">
<!-- Adds comma if there are other dates -->
<xsl:if test="$element/@to or $element/@from">, </xsl:if>not before <xsl:value-of select="local:trim-date($element/@notBefore)"/>
</xsl:if>
<xsl:if test="$element/@notAfter">
<!-- Adds comma if there are other dates -->
<xsl:if test="$element/@to or $element/@from or $element/@notBefore">, </xsl:if>not after <xsl:value-of select="local:trim-date($element/@notAfter)"/>
</xsl:if>
<!-- Formats when, single date -->
<xsl:if test="$element/@when">
<!-- Adds comma if there are other dates -->
<xsl:if test="$element/@to or $element/@from or $element/@notBefore or $element/@notAfter">, </xsl:if>
<xsl:value-of select="local:trim-date($element/@when)"/>
</xsl:if>
</xsl:if>
</xsl:function>
<!-- Date function to remove leading 0s -->
<xsl:function name="local:trim-date">
<xsl:param name="date"/>
<xsl:choose>
<!-- NOTE: This can easily be changed to display BCE instead -->
<!-- removes leading 0 but leaves - -->
<xsl:when test="starts-with($date,'-0')">
<xsl:value-of select="concat(substring($date,3),' BCE')"/>
</xsl:when>
<!-- removes leading 0 -->
<xsl:when test="starts-with($date,'0')">
<xsl:value-of select="local:trim-date(substring($date,2))"/>
</xsl:when>
<!-- passes value through without changing it -->
<xsl:otherwise>
<xsl:value-of select="$date"/>
</xsl:otherwise>
</xsl:choose>
<!-- <xsl:value-of select="string(number($date))"/>-->
</xsl:function>
<!-- Function to tranlate xml:lang attributes to full lang label -->
<xsl:function name="local:expand-lang">
<xsl:param name="lang" as="xs:string"/>
<xsl:param name="type" as="xs:string"/>
<xsl:choose>
<xsl:when test="$lang='la'">
<xsl:text>Latin</xsl:text>
</xsl:when>
<xsl:when test="$lang='grc'">
<xsl:text>Greek</xsl:text>
</xsl:when>
<xsl:when test="$lang='ar'">
<xsl:text>Arabic</xsl:text>
</xsl:when>
<xsl:when test="$lang='hy'">
<xsl:text>Armenian</xsl:text>
</xsl:when>
<xsl:when test="$lang='ka'">
<xsl:text>Georgian</xsl:text>
</xsl:when>
<xsl:when test="$lang='sog'">
<xsl:text>Soghdian</xsl:text>
</xsl:when>
<xsl:when test="$lang='cu'">
<xsl:text>Slavic</xsl:text>
</xsl:when>
<xsl:when test="$lang='cop'">
<xsl:text>Coptic</xsl:text>
</xsl:when>
<xsl:when test="$lang='gez'">
<xsl:text>Ethiopic</xsl:text>
</xsl:when>
<xsl:when test="$lang='syr-pal'">
<xsl:text>Syro-Palestinian</xsl:text>
</xsl:when>
<xsl:when test="$lang='ar-syr'">
<xsl:text>Karshuni</xsl:text>
</xsl:when>
<xsl:when test="$lang='de'">
<xsl:text>German</xsl:text>
</xsl:when>
<xsl:when test="$lang='fr'">
<xsl:text>French</xsl:text>
</xsl:when>
<xsl:when test="$lang='en'">
<xsl:text>English</xsl:text>
</xsl:when>
<xsl:when test="$lang='it'">
<xsl:text>Italian</xsl:text>
</xsl:when>
<xsl:when test="$lang='pt'">
<xsl:text>Portugese</xsl:text>
</xsl:when>
<xsl:when test="$lang='ru'">
<xsl:text>Russian</xsl:text>
</xsl:when>
<xsl:when test="$lang='nl'">
<xsl:text>Dutch</xsl:text>
</xsl:when>
<xsl:when test="$lang='ar'">
<xsl:text>Arabic</xsl:text>
</xsl:when>
<xsl:when test="$lang='es'">
<xsl:text>Spanish</xsl:text>
</xsl:when>
<xsl:when test="$lang='tr'">
<xsl:text>Turkish</xsl:text>
</xsl:when>
<xsl:otherwise/>
</xsl:choose>
</xsl:function>
<!-- Translate labels to human readable labels via odd -->
<xsl:function name="local:translate-label">
<xsl:param name="label"/>
<xsl:param name="count"/>
<xsl:choose>
<xsl:when test="$odd/descendant::t:valItem[@ident=$label]/t:gloss">
<xsl:choose>
<xsl:when test="$count > 1 and $odd/descendant::t:valItem[@ident=$label]/t:gloss[@type='pl']">
<xsl:value-of select="$odd/descendant::t:valItem[@ident=$label]/t:gloss[@type='pl'][1]"/>
</xsl:when>
<xsl:otherwise>
<xsl:choose>
<xsl:when test="$odd/descendant::t:valItem[@ident=$label]/t:gloss[@type='sg']">
<xsl:value-of select="$odd/descendant::t:valItem[@ident=$label]/t:gloss[@type='sg'][1]"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$odd/descendant::t:valItem[@ident=$label]/t:gloss[1]"/>
</xsl:otherwise>
</xsl:choose>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="concat(upper-case(substring($label,1,1)),substring($label,2))"/>
</xsl:otherwise>
</xsl:choose>
</xsl:function>
<!-- Translate labels to human readable labels via odd, passes on element and label value -->
<xsl:function name="local:translate-label">
<xsl:param name="element"/>
<xsl:param name="label"/>
<xsl:param name="count"/>
<xsl:variable name="element" select="$odd/descendant::t:elementSpec[@ident = name($element)]"/>
<xsl:choose>
<xsl:when test="$element/descendant::t:valItem[@ident=$label]/t:gloss">
<xsl:choose>
<xsl:when test="$count > 1 and $element/descendant::t:valItem[@ident=$label]/t:gloss[@type='pl']">
<xsl:value-of select="$element/descendant::t:valItem[@ident=$label]/t:gloss[@type='pl'][1]"/>
</xsl:when>
<xsl:otherwise>
<xsl:choose>
<xsl:when test="$element/descendant::t:valItem[@ident=$label]/t:gloss[@type='sg']">
<xsl:value-of select="$element/descendant::t:valItem[@ident=$label]/t:gloss[@type='sg'][1]"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$element/descendant::t:valItem[@ident=$label]/t:gloss[1]"/>
</xsl:otherwise>
</xsl:choose>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="concat(upper-case(substring($label,1,1)),substring($label,2))"/>
</xsl:otherwise>
</xsl:choose>
</xsl:function>
<!-- Translate labels to human readable labels via specified xml file, passes on element and label value -->
<xsl:function name="local:translate-label">
<xsl:param name="ref"/>
<xsl:param name="element"/>
<xsl:param name="label"/>
<xsl:param name="count"/>
<xsl:variable name="file-name">
<xsl:choose>
<xsl:when test="contains($ref,'#')">
<xsl:value-of select="substring-before($ref,'#')"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$ref"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="file">
<xsl:choose>
<xsl:when test="contains($file-name,$base-uri)">
<xsl:value-of select="replace($file-name,$base-uri,concat('xmldb:exist://',$nav-base))"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="doc($ref)"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:choose>
<xsl:when test="$file/descendant::*[@xml:id=$label]/t:gloss">
<xsl:value-of select="$file/descendant::*[@xml:id=$label]/t:gloss[1]"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="concat(upper-case(substring($label,1,1)),substring($label,2))"/>
</xsl:otherwise>
</xsl:choose>
</xsl:function>
<xsl:function name="local:bibl-type-order">
<xsl:param name="label"/>
<xsl:choose>
<xsl:when test="$label = 'lawd:Edition'">a</xsl:when>
<xsl:when test="$label = 'syriaca:Apparatus'">b</xsl:when>
<xsl:when test="$label = 'syriaca:Manuscript'">c</xsl:when>
<xsl:when test="$label = 'syriaca:AncientVersion'">d</xsl:when>
<xsl:when test="$label = 'syriaca:ModernTranslation'">e</xsl:when>
<xsl:when test="$label = 'syriaca:DigitalCatalogue'">f</xsl:when>
<xsl:when test="$label = 'syriaca:PrintCatalogue'">g</xsl:when>
<xsl:when test="$label = 'syriaca:Glossary'">h</xsl:when>
<xsl:when test="$label = 'lawd:WrittenWork'">i</xsl:when>
</xsl:choose>
</xsl:function>
<!-- =================================================================== -->
<!-- Helper templates -->
<!-- =================================================================== -->
<!-- Wrap text with @rend in appropriate html elements or html classes -->
<xsl:template name="rend">
<xsl:choose>
<xsl:when test="@rend">
<xsl:choose>
<xsl:when test="@rend = 'bold'">
<b>
<xsl:call-template name="ref"/>
</b>
</xsl:when>
<xsl:when test="@rend = 'italic'">
<i>
<xsl:call-template name="ref"/>
</i>
</xsl:when>
<xsl:when test="@rend = ('superscript','sup')">
<sup>
<xsl:call-template name="ref"/>
</sup>
</xsl:when>
<xsl:when test="@rend = ('subscript','sub')">
<sub>
<xsl:call-template name="ref"/>
</sub>
</xsl:when>
<xsl:otherwise>
<span class="tei-rend-{string(@rend)}">
<xsl:call-template name="ref"/>
</span>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="ref"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="ref">
<xsl:choose>
<xsl:when test="parent::t:ref or parent::t:ptr or parent::*[1]/@ref">
<xsl:apply-templates/>
</xsl:when>
<xsl:when test="@ref">
<a href="{@ref}">
<xsl:apply-templates/>
</a>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>