-
Notifications
You must be signed in to change notification settings - Fork 0
/
XML2LaTeX.xsl.xml
530 lines (482 loc) · 22.1 KB
/
XML2LaTeX.xsl.xml
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
523
524
525
526
527
528
529
530
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
<xsl:output method="text" encoding="utf-8"/>
<xsl:strip-space elements="*"/>
<!--========================================================================-->
<!--
Converts Tanach XML files to text files.
Modified: 12 Oct 2010 - For full Chapter:Verse, Layout and Content control.
Modified: 19 Aug 2010 - To include content, samachpenun, and notes formatting variables.
Modified: 14 Jul 2010 - To prevent multiple ketiv *'s within same <k>
tag output.
-->
<!--========================================================================-->
<xsl:param name="template" >Excerpt</xsl:param>
<!-- Variable xsldate is the date of this xsl file. -->
<xsl:variable name="xsldate">2 Jun 2011</xsl:variable>
<!-- Variable build is the build date of the complete site as set by ant. -->
<xsl:variable name="build">25.2</xsl:variable>
<!-- Parameter conversiondate is the date of text conversion. -->
<xsl:param name="conversiondate">1509.1942</xsl:param>
<!-- User settable variables. Set exactly to permissible values! -->
<xsl:variable name="labelprefix" select="'‪xxxx'"/>
<xsl:variable name="labelsuffix" select="'‬
'"/>
<xsl:variable name="rtlmarker" select="'‫'"/>
<xsl:variable name="noteprefix">‪[</xsl:variable>
<xsl:variable name="notesuffix">]‬</xsl:variable>
<!--
Very basic definitions of Unicode Hebrew blocks
-->
<!-- Blank character -->
<xsl:variable name="blank"> </xsl:variable>
<!-- Variable consonants contains consonants ONLY -->
<xsl:variable name="consonants">אבגדהוזחטיךכלםמןנסעףפץצקרשת</xsl:variable>
<!-- Variable maqafsofpasuq contains ONLY maqaf and the sof passuq. -->
<xsl:variable name="maqafsofpasuq">־׃</xsl:variable>
<!-- Variable vowels contains vowels and shin/sin dots. -->
<xsl:variable name="vowels">ְֱֲֳִֵֶַָֹֺֻּׁׂ</xsl:variable>
<!-- Variable trueaccents contains accents less maqaf and sof pasuq plus ZWJ but without blank. -->
<xsl:variable name="trueaccents">ֽֿ֑֖֛֣֤֥֦֧֪֚֭֮֒֓֔֕֗֘֙֜֝֞֟֠֡֨֩֫֬׀ׅׄ‍</xsl:variable>
<!-- Variable mdivider contains the morphogical divider, /. -->
<xsl:variable name="mdivider">/</xsl:variable>
<!--
Block definitions for book contents,
morphology, accents, vowels, consonants.
-->
<!-- Variable accents contains trueaccents plus blank. -->
<xsl:variable name="accents">ֽֿ֑֖֛֣֤֥֦֧֪֚֭֮֒֓֔֕֗֘֙֜֝֞֟֠֡֨֩֫֬׀ׅׄ‍ </xsl:variable>
<!-- Variable all contains all of the above. -->
<xsl:variable name="all"
select="concat($consonants, $maqafsofpasuq, $vowels, $accents, $mdivider)"/>
<!-- Variable no morphology eliminates the /. -->
<xsl:variable name="nomorphology"
select="concat($consonants, $maqafsofpasuq, $vowels, $accents)"/>
<!-- Variable noaccents eliminates the accents except for the sof passuq and maqaf. -->
<xsl:variable name="noaccents" select="concat($consonants, $maqafsofpasuq, $vowels)"/>
<!-- Variable novowels eliminates the vowels and replaces the maqaf with a blank. -->
<xsl:variable name="novowels" select="concat($consonants,' ')"/>
<!--========================================================================-->
<!-- Chapter:Verse specification parameters, set initially to show the whole book. -->
<xsl:param name="chapter" >1</xsl:param>
<xsl:param name="verse" >1</xsl:param>
<!-- LastChapter:LastVerse specification -->
<xsl:param name="lastchapter" >1000</xsl:param>
<xsl:param name="lastverse" >1000</xsl:param>
<!--========================================================================-->
<!--
Dispatching template.
-->
<xsl:template match="/Tanach">
<!--<html>
<body><xsl:value-of select="$template"/></body></html> -->
<!-- Template dispatcher -->
<xsl:choose>
<xsl:when test="$template='Excerpt'">
<xsl:call-template name="Excerpt"/>
</xsl:when>
<!-- Unimplemented template, error condition -->
<xsl:otherwise>
<xsl:call-template name="InvalidTemplate"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!--========================================================================-->
<xsl:template name="Excerpt">
<xsl:variable name="bookHeb" select="tanach/book/names/hebrewname"/>
<xsl:variable name="section">
<xsl:choose>
<xsl:when test="$chapter=$lastchapter">
<xsl:text>\section*{</xsl:text>
<xsl:value-of select="$bookHeb"/>
<xsl:text> \hebrewnumeral{</xsl:text>
<xsl:value-of select="$chapter"/>
<xsl:text>}:\hebrewnumeral{</xsl:text>
<xsl:value-of select="$verse"/>
<xsl:text>}--\hebrewnumeral{</xsl:text>
<xsl:value-of select="$lastverse"/>
<xsl:text>}}</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>\section*{</xsl:text>
<xsl:value-of select="$bookHeb"/>
<xsl:text> \hebrewnumeral{</xsl:text>
<xsl:value-of select="$chapter"/>
<xsl:text>}:\hebrewnumeral{</xsl:text>
<xsl:value-of select="$verse"/>
<xsl:text>}--\hebrewnumeral{</xsl:text>
<xsl:value-of select="$lastchapter"/>
<xsl:text>}:\hebrewnumeral{</xsl:text>
<xsl:value-of select="$lastverse"/>
<xsl:text>}}</xsl:text>
</xsl:otherwise>
</xsl:choose>
<xsl:text>
</xsl:text>
</xsl:variable>
<xsl:text>\documentclass[20pt]{tikkun}
</xsl:text>
<xsl:text>\begin{document}
</xsl:text>
<xsl:text>\setspacing
</xsl:text>
<xsl:text>\marginparright
</xsl:text>
<xsl:value-of select="$section"/>
<xsl:text>\begin{pointed}</xsl:text>
<xsl:call-template name="GetChapters">
<xsl:with-param name="format" select="'Full'" />
</xsl:call-template>
<xsl:text>\end{pointed}
</xsl:text>
<xsl:text>
\pagebreak
</xsl:text>
<xsl:value-of select="$section"/>
<xsl:text>\begin{torah}</xsl:text>
<xsl:call-template name="GetChapters">
<xsl:with-param name="format" select="'Consonants'" />
</xsl:call-template>
<xsl:text>\end{torah}
</xsl:text>
<xsl:text>\end{document}
</xsl:text>
</xsl:template>
<!--========================================================================-->
<xsl:template name="GetChapters">
<xsl:param name="format" />
<!--
Breaks the excerpt specification into 4 types of chapter.
-->
<!--========================================================================-->
<xsl:for-each select="tanach/book/c[@n >=$chapter and @n <= $lastchapter]">
<xsl:choose>
<!-- A first chapter with other chapters. Initial verse partial, all others full. -->
<xsl:when test="@n = $chapter and @n != $lastchapter">
<xsl:call-template name="GetVerses">
<xsl:with-param name="type" select="'first'"/>
<xsl:with-param name="format" select="$format"/>
</xsl:call-template>
</xsl:when>
<!-- A complete, entire chapter, a middle chapter. All verses full. -->
<xsl:when test="@n != $chapter and @n != $lastchapter">
<xsl:call-template name="GetVerses">
<xsl:with-param name="type" select="'entire'"/>
<xsl:with-param name="format" select="$format"/>
</xsl:call-template>
</xsl:when>
<!-- An end chapter. Final verse partial, all others full. -->
<xsl:when test="@n != $chapter and @n = $lastchapter">
<xsl:call-template name="GetVerses">
<xsl:with-param name="type" select="'last'"/>
<xsl:with-param name="format" select="$format"/>
</xsl:call-template>
</xsl:when>
<!-- A single chapter. Initial and final verses partial -->
<xsl:when test="@n = $chapter and @n = $lastchapter">
<xsl:call-template name="GetVerses">
<xsl:with-param name="type" select="'single'"/>
<xsl:with-param name="format" select="$format"/>
</xsl:call-template>
</xsl:when>
</xsl:choose>
</xsl:for-each>
</xsl:template>
<!--========================================================================-->
<!-- Breaks a chapter into 4 types of verse. -->
<!--========================================================================-->
<xsl:template name="GetVerses">
<xsl:param name="type" select ="'entire'"/>
<xsl:param name="format"/>
<xsl:choose>
<!-- A full chapter show all the verses -->
<xsl:when test="$type='entire'">
<xsl:for-each select="v[not(./@n=following-sibling::*[1]/@n)]">
<xsl:call-template name="ExcerptLayout" >
<xsl:with-param name="type" select="'full'"/>
<xsl:with-param name="format" select="$format"/>
</xsl:call-template>
</xsl:for-each>
</xsl:when>
<!-- A first chapter -->
<xsl:when test="$type='first'">
<xsl:for-each select="v[./@n >= $verse and not(./@n=following-sibling::*[1]/@n)]">
<xsl:call-template name="ExcerptLayout" >
<xsl:with-param name="type" select="'start'"/>
<xsl:with-param name="format" select="$format"/>
</xsl:call-template>
</xsl:for-each>
</xsl:when>
<!-- A last chapter -->
<xsl:when test="$type='last'">
<xsl:for-each select="v[./@n < $lastverse and not(./@n=following-sibling::*[1]/@n) ]">
<xsl:call-template name="ExcerptLayout" >
<xsl:with-param name="type" select="'full'"/>
<xsl:with-param name="format" select="$format"/>
</xsl:call-template>
</xsl:for-each>
<xsl:for-each select="v[./@n = $lastverse and not(./@n=following-sibling::*[1]/@n) ]">
<xsl:call-template name="ExcerptLayout" >
<xsl:with-param name="type" select="'last'"/>
<xsl:with-param name="format" select="$format"/>
</xsl:call-template>
</xsl:for-each>
</xsl:when>
<!-- A single chapter show all the verses -->
<xsl:when test="$type='single'">
<xsl:choose>
<!-- Single verse chapter is possible. -->
<xsl:when test="$verse = $lastverse">
<xsl:for-each select="v[@n=$verse and not(./@n=following-sibling::*[1]/@n) ]">
<xsl:call-template name="ExcerptLayout">
<xsl:with-param name="type" select="'single'"/>
<xsl:with-param name="format" select="$format"/>
</xsl:call-template>
</xsl:for-each>
</xsl:when>
<!-- Chapter has at least two verses -->
<xsl:otherwise>
<xsl:for-each select="v[@n=$verse and not(./@n=following-sibling::*[1]/@n)]">
<xsl:call-template name="ExcerptLayout">
<xsl:with-param name="type" select="'start'"/>
<xsl:with-param name="format" select="$format"/>
</xsl:call-template>
</xsl:for-each>
<xsl:for-each select="v[@n > $verse and @n < $lastverse and not(./@n=following-sibling::*[1]/@n)]">
<xsl:call-template name="ExcerptLayout" >
<xsl:with-param name="type" select="'full'"/>
<xsl:with-param name="format" select="$format"/>
</xsl:call-template>
</xsl:for-each>
<xsl:for-each select="v[@n=$lastverse and not(./@n=following-sibling::*[1]/@n)]">
<xsl:call-template name="ExcerptLayout" >
<xsl:with-param name="type" select="'last'"/>
<xsl:with-param name="format" select="$format"/>
</xsl:call-template>
</xsl:for-each>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
</xsl:choose>
</xsl:template>
<!--========================================================================-->
<!-- Shows an excerpt in the specified layout. -->
<!--========================================================================-->
<xsl:template name="ExcerptLayout">
<xsl:param name="format"/>
<xsl:variable name="verse" select="./@n"/>
<xsl:choose>
<xsl:when test="$format='Full'">
<xsl:call-template name="chapterverse" />
</xsl:when>
</xsl:choose>
<xsl:call-template name="ExcerptVerseDispatch">
<xsl:with-param name="format" select="$format"/>
</xsl:call-template>
<xsl:text>
</xsl:text>
</xsl:template>
<!--========================================================================-->
<!-- Dispatches all verses having the same number (split verses)
to appply SourceMarkings. -->
<!--========================================================================-->
<xsl:template name="ExcerptVerseDispatch">
<xsl:param name="format"/>
<xsl:variable name="verse" select="./@n"/>
<xsl:for-each select="../v[./@n=$verse]">
<xsl:call-template name="GOs">
<xsl:with-param name="format" select="$format"/>
</xsl:call-template>
</xsl:for-each>
</xsl:template>
<!-- ====================================================================== -->
<!--
Template to output graphical objects, GOs.
Enter with a verse context node containing v elements with same verse
number.
-->
<!--========================================================================-->
<xsl:template name="GOs">
<xsl:param name="format"/>
<xsl:variable name="verse" select="./@n"/>
<xsl:for-each select="child::node()">
<!-- Process a non-KW word (w) -->
<xsl:if test="self::w">
<xsl:call-template name="w">
<xsl:with-param name="format" select="$format"/>
</xsl:call-template>
</xsl:if>
<!-- Process a Ketib (k) -->
<xsl:if test="self::k">
<xsl:call-template name="k">
<xsl:with-param name="format" select="$format"/>
</xsl:call-template>
</xsl:if>
<!-- Process a Qere (q) -->
<xsl:if test="self::q">
<xsl:call-template name="q">
<xsl:with-param name="format" select="$format"/>
</xsl:call-template>
</xsl:if>
<!-- Process a pe, samekh, or reversednun -->
<xsl:if test="self::pe">
<xsl:call-template name="pe"/>
</xsl:if>
<xsl:if test="self::samekh">
<xsl:call-template name="samekh"/>
</xsl:if>
<xsl:if test="self::reversednun">
<xsl:call-template name="reversednun"/>
</xsl:if>
<!-- Process a note -->
<xsl:if test="self::x">
<xsl:call-template name="x"/>
</xsl:if>
<!-- Process a special text decoration . This shouldn't occur. -->
<xsl:if test="self::s">
<xsl:call-template name="s"/>
</xsl:if>
</xsl:for-each>
</xsl:template>
<!-- ====================================================================== -->
<!-- Template to display non-KQ words (w). -->
<!-- Enter with a child of a verse (v) context node known to be a 'w'. -->
<!--========================================================================-->
<xsl:template name="w">
<xsl:param name="format"/>
<xsl:for-each select="child::node()">
<xsl:choose>
<xsl:when test="self::x">
<xsl:call-template name="x"/>
</xsl:when>
<xsl:when test="self::s">
<xsl:call-template name="s"/>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="OutputContent">
<xsl:with-param name="format" select="$format"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
<xsl:variable name="lastchild" select="."/>
<xsl:variable name="lastchar" select="substring($lastchild, string-length($lastchild), 1)"/>
<xsl:if test="not( $lastchar = '־' or $lastchar = '.')">
<xsl:text> </xsl:text>
</xsl:if>
</xsl:template>
<!-- ====================================================================== -->
<!-- Template to display ketib words. -->
<!-- Enter with a child of a verse (v) context node known to be a 'k'. -->
<!--========================================================================-->
<xsl:template name="k">
<xsl:param name="format"/>
<xsl:for-each select="child::node()">
<xsl:choose>
<xsl:when test="self::x"><xsl:call-template name="x"/></xsl:when>
<xsl:when test="self::s"><xsl:call-template name="s"/></xsl:when>
<xsl:otherwise>
<xsl:if test="$format='Full'">
<xsl:text>*</xsl:text>
</xsl:if>
<xsl:call-template name="OutputContent">
<xsl:with-param name="format" select="$format"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
<!-- If the last character isn't a maqaf or a '.' , add in a blank. -->
<xsl:variable name="lastchild" select="child::node()[position()=last()]"/>
<xsl:variable name="lastchar" select="substring($lastchild, string-length($lastchild), 1)"/>
<xsl:if test="not( $lastchar = '־' or $lastchar = '.')"><xsl:text> </xsl:text></xsl:if>
</xsl:template>
<!-- ====================================================================== -->
<!-- Template to display qere words (q). -->
<!-- Enter with a child of a verse (v) context node known to be a 'q'. -->
<!--========================================================================-->
<xsl:template name="q">
<xsl:param name="format"/>
<xsl:choose>
<xsl:when test="$format='Full'">
<xsl:for-each select="child::node()">
<xsl:choose>
<xsl:when test="self::x"><xsl:call-template name="x"/></xsl:when>
<xsl:when test="self::s"><xsl:call-template name="s"/></xsl:when>
<xsl:otherwise>
<xsl:text>**</xsl:text>
<xsl:call-template name="OutputContent">
<xsl:with-param name="format" select="$format"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
<!-- If the last character isn't a maqaf or a '.' , add in a blank. -->
<xsl:variable name="lastchild" select="child::node()[position()=last()]"/>
<xsl:variable name="lastchar" select="substring($lastchild, string-length($lastchild), 1)"/>
<xsl:if test="not( $lastchar = '־' or $lastchar = '.')"><xsl:text> </xsl:text></xsl:if>
</xsl:when>
</xsl:choose>
</xsl:template>
<!-- ====================================================================== -->
<!--
Template to display notes (x).
-->
<!--========================================================================-->
<xsl:template name="x">
</xsl:template>
<!-- ====================================================================== -->
<!--
Template to display text decorations (s).
-->
<!--========================================================================-->
<xsl:template name="s">
</xsl:template>
<!-- ====================================================================== -->
<!-- Template to display pe markers (pe). -->
<!--========================================================================-->
<xsl:template name="pe">
<xsl:text>\pespace{}</xsl:text>
</xsl:template>
<!-- ====================================================================== -->
<!-- Template to display samekh markers (samekh). -->
<!--========================================================================-->
<xsl:template name="samekh">
<xsl:text>\samechspace{}</xsl:text>
</xsl:template>
<!-- ====================================================================== -->
<!-- Template to display reversednun markers. -->
<!--========================================================================-->
<xsl:template name="reversednun">
<xsl:text>׆</xsl:text>
</xsl:template>
<!-- ====================================================================== -->
<!-- Template to show characters after translation. -->
<!-- Enter with a child of a verse as a context node. -->
<!--========================================================================-->
<xsl:template name="OutputContent">
<xsl:param name="format"/>
<xsl:choose>
<xsl:when test="$format='Full'">
<xsl:value-of select="translate(., $all,$nomorphology)"/>
</xsl:when>
<xsl:when test="format='Vowels'">
<xsl:value-of select="translate(., $all,$noaccents)"/>
</xsl:when>
<xsl:when test="$format='Consonants'">
<xsl:value-of select="translate(., $all, $novowels)"/>
</xsl:when>
<xsl:when test="$format='Morphology'">
<xsl:value-of select="."/>
</xsl:when>
</xsl:choose>
</xsl:template>
<!--========================================================================-->
<xsl:template name="chapterverse">
<xsl:variable name="chapter" select="../@n" />
<xsl:variable name="verse" select="./@n" />
<xsl:text>\pnum{</xsl:text><xsl:value-of select="$verse"/><xsl:text>}</xsl:text>
</xsl:template>
<!--========================================================================-->
<xsl:template name="InvalidTemplate" >
<html>
<h1>Invalid template for ServerText.xml</h1>
<p/>
<h4><b>ServerText.xml</b> doesn't accept a template value
of <b>'<xsl:value-of select="$template"/>'</b>.
</h4>
<p/>
<hr/>
</html>
</xsl:template>
<!--========================================================================-->
</xsl:stylesheet>
<!--========================================================================-->
<!--========================================================================-->