-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtei2latex.xsl
1650 lines (1544 loc) · 70.8 KB
/
tei2latex.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
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
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:tei="http://www.tei-c.org/ns/1.0" xmlns:tex="placeholder.uri" exclude-result-prefixes="tex">
<xsl:output method="text"/>
<!--<xsl:strip-space elements="tei:p tei:s tei:q tei:w" />-->
<xsl:strip-space elements="tei:*" />
<!-- This xslt script converts TEI xml to LaTeX -->
<!-- First version created by Marjorie Burghart for the TEI Critical Apparatus Toolbox - 2017 -->
<!-- downloaded from GitHub by Todd Hanneken 23 November 2022 -->
<xsl:param name="pdfAuthor">Todd R. Hanneken</xsl:param>
<!-- options for the apparatus variants footnotes -->
<!-- Should we shorten the lemma in the footnote if the lemma has more than X words? 0 for no, other number for the max length of lemma in the note (in words) -->
<xsl:param name="shortenLem">15</xsl:param>
<!-- What word or phrase do you want to use in the critical notes to indicate that a variant is an omission? -->
<xsl:param name="varOm">om.</xsl:param>
<!-- What word or phrase do you want to use in the critical notes to indicate that a variant is an addition? -->
<xsl:param name="varAdd">add.</xsl:param>
<!-- Possivility to change the default lemma separator -->
<xsl:param name="lemSep"/>
<!-- Should we display the contents of tei:quote in italics? 0 for no, 1 for yes-->
<xsl:param name="italQuote">0</xsl:param>
<!-- Should we display le sigla of witnesses in italics in the critical notes? -->
<xsl:param name="italWit">1</xsl:param>
<!-- Page size? Accepted values:
a0paper, a1paper, a2paper, a3paper, a4paper, a5paper, a6paper, b0paper, b1paper, b2paper, b3paper, b4paper, b5paper, b6paper, c0paper, c1paper, c2paper, c3paper, c4paper, c5paper, c6paper, b0j, b1j, b2j, b3j, b4j, b5j, b6j, ansiapaper, ansibpaper, ansicpaper, ansidpaper, ansiepaper, letterpaper, executivepaper, legalpaper -->
<xsl:param name="pageSize">letterpaper</xsl:param>
<!-- Use layout for facing pages? Accepted values = 0 (single pages), 1 (facing pages) -->
<xsl:param name="facingLayout">1</xsl:param>
<!-- Setting the size of the margins, in inches -->
<xsl:param name="marginInner">1.8</xsl:param>
<xsl:param name="marginOuter">2</xsl:param>
<xsl:param name="marginTop">1.5</xsl:param>
<xsl:param name="marginBottom">1.5</xsl:param>
<xsl:param name="marginBinding">0</xsl:param>
<!-- Set main language (useful for hyphenation rules) -->
<xsl:param name="lang1">latin</xsl:param>
<!-- Set other language (useful for hyphenation rules) -->
<xsl:param name="lang2">english</xsl:param>
<!-- Running titles for odd and even pages; note that you can include LaTeX instructions in the text, for instance if you want your running title text displayed in small capitals, use the value: "\textsc{Your Text}" instead of just "Your Text" -->
<xsl:param name="rTitleEven">\textsc{Gura, Gallo, and Hanneken}</xsl:param>
<xsl:param name="rTitleOdd">\textsc{Latin Moses}</xsl:param>
<!-- Running titles position for odd and even pages; accepted values: L, C, R -->
<xsl:param name="rTitleOddPos">C</xsl:param>
<xsl:param name="rTitleEvenPos">C</xsl:param>
<!-- Running titles size for odd and even pages. Accepted values are relative: nothing (default), then from smallest to largest: tiny, scriptsize, footnotesize, normalsize, large, Large, LARGE, huge, Huge -->
<xsl:param name="rTitleOddSize"/>
<xsl:param name="rTitleEvenSize"/>
<!-- Should we wrap the contents of tei:quote in quotation marks? Accepted values = 0 (No), 1 (Yes) -->
<xsl:param name="qmQuote">0</xsl:param>
<!-- If so, which style of quotation marks should we use? Indicate the left and right marks, separated by a | sign -->
<xsl:param name="qmQuoteStyle">«|»</xsl:param>
<!-- Should we put a non-breaking space between the quotation mark and the quoted text? Accepted values = 0 (No), 1 (Yes) -->
<xsl:param name="qmQuoteNoBr">1</xsl:param>
<!-- start number of pagination; used only if different from 0; The value must always be an arabic numeral, even if you are using a different numbering style. -->
<xsl:param name="fromPage">49</xsl:param>
<!-- Is there a page number on the first page? Accepted values: 0 = No, 1 = Yes -->
<xsl:param name="pageNumFirstPage">1</xsl:param>
<!-- Page numbering style: accepted values are
arabic: arabic numerals; roman: lowercase roman numerals; Roman: uppercase roman numerals; alph: lowercase letters; Alph: uppercase letters -->
<xsl:param name="pageNumberingStyle">arabic</xsl:param>
<!-- Should the page num be placed in the header, or footer? Accepted values: head, foot. -->
<xsl:param name="pageNumPlace">head</xsl:param>
<!-- Where should the page number be positioned in the header or footer? Accepted values: L (left), R (right), C (center), LE,RO (left on even pages, right on odd pages, i.e. outer margin of each page), RE,LO (inner margin) -->
<xsl:param name="pageNumPosition">LE,RO</xsl:param>
<!-- Size of the footer text? Accepted values are relative: nothing (default), then from smallest to largest: tiny, scriptsize, footnotesize, normalsize, large, Large, LARGE, huge, Huge -->
<xsl:param name="pageNumSize"/>
<!-- to number the lines; options can be: page, pstart or section -->
<xsl:param name="lineationStyle">section</xsl:param>
<!-- lineation start value (default = 0) -->
<xsl:param name="lineationStart">0</xsl:param>
<!-- lineation step (default = 5) -->
<xsl:param name="lineationStep">999</xsl:param>
<!-- base font size of the document: 8pt, 9pt, 10pt, 11pt, 12pt, 14pt, 17pt, and 20pt. -->
<xsl:param name="baseFontSize">12</xsl:param>
<!-- do you want to print the document title? Yes if value is different from 0 -->
<xsl:param name="printTitle">0</xsl:param>
<!-- How big should we print the title? Accepted values are large, Large, LARGE, huge, Huge. Those sizes are relative to the normal font size in the document. For more information see: http://jacques-andre.fr/fontex/taille.pdf -->
<xsl:param name="printTitleSize"></xsl:param>
<!-- Should we print the title in small caps or caps? Accepted values: smallcaps and caps -->
<xsl:param name="printTitleStyle"></xsl:param>
<!-- do you want to print the list of witnesses? Yes if value is different from 0 -->
<xsl:param name="printListWit">1</xsl:param>
<!-- separator between apparatus entries on the same line; leave empty if you don't want to add one -->
<xsl:param name="separatorAppEntries"/>
<!-- Size of the blank space before each series of notes (in pt) -->
<xsl:param name="spaceBeforeNotesA">18</xsl:param>
<xsl:param name="spaceBeforeNotesB">18</xsl:param>
<!-- How to display the contents of tei:head ? -->
<!-- Should it be in bold? Accepted values: 1 for italic, 2 for bold, 3 for small caps -->
<xsl:param name="headStyle">1</xsl:param>
<!-- vSpace before and after each tei:head, in cm -->
<xsl:param name="headStylevSpaceBefore">0.5</xsl:param>
<xsl:param name="headStylevSpaceAfter">0.3</xsl:param>
<!-- How big should we print the tei:head elements ? Accepted values are 0 (no specification), large, Large, LARGE, huge, Huge. Those sizes are relative to the normal font size in the document. -->
<xsl:param name="headSize">large</xsl:param>
<!-- How should we align the tei:head? Accepted values: center (to be continued) -->
<xsl:param name="headAlign"/>
<!-- vSpace after each tei:p, in cm -->
<xsl:param name="parStylevSpace">0</xsl:param>
<!-- TRH: adapt side notes from folios to chapter milestone -->
<!-- Side notes for folios -->
<!-- Write the folio numbers in the margins? 1 = Yes, 0 = No-->
<xsl:param name="folioNotes">1</xsl:param>
<!-- Location of side notes? Accepted values: left, right, inner, or outer -->
<xsl:param name="sideNoteLocation">outer</xsl:param>
<!-- Optional separator materialising the folio limit in the text -->
<xsl:param name="folioInTextMarker"> ||</xsl:param>
<!-- Should we print the ms. siglum before the folio number? 1 = Yes, 0 = No -->
<xsl:param name="folioNotesMs">0</xsl:param>
<!-- Should we print all teipb? 1 = Yes, 0 = No, only tei:pb related to a particular witness -->
<xsl:param name="folioNotesAll">0</xsl:param>
<!-- If we must print only tei:pb related to a particular witness, tell us in which attribute of tei:pb is stored the value linking to this witness... -->
<xsl:param name="folioNoteAttribute">ed</xsl:param>
<!-- ...and the value we're looking for in this attribute -->
<xsl:param name="folioNoteAttributeValue">T1</xsl:param>
<!-- Do you want to add an index nominum? 0 = no, 1 = yes-->
<xsl:param name="idxNom">o</xsl:param>
<!-- Do you want to add a prologue to the index nominum? -->
<xsl:param name="idxNomPrologue"/>
<!-- Which title do you want for the index nominum? -->
<xsl:param name="idxNomTitle">Index Nominum</xsl:param>
<!-- Do you want to add an index locorum? 0 = no, 1 = yes-->
<xsl:param name="idxLoc">o</xsl:param>
<!-- Do you want to add a prologue to the index nominum? -->
<xsl:param name="idxLocPrologue"/>
<!-- Which title do you want for the index locorum? -->
<xsl:param name="idxLocTitle">Index locorum</xsl:param>
<xsl:template match="/">
<xsl:text>\documentclass[</xsl:text><xsl:value-of select="$pageSize"/><xsl:if test="$facingLayout = '1'"><xsl:text>,twoside</xsl:text></xsl:if><xsl:text>]{extbook} </xsl:text>
<xsl:text>\usepackage[oldstyle,proportional]{libertine} </xsl:text>
<xsl:text>\usepackage{fontspec} </xsl:text>
<xsl:text>\usepackage{microtype} </xsl:text>
<xsl:text>\usepackage{polyglossia} </xsl:text>
<xsl:text>\usepackage{bookmark} </xsl:text>
<xsl:text>\hypersetup{pdftitle={</xsl:text>
<xsl:value-of select="//tei:teiHeader/tei:fileDesc/tei:titleStmt/tei:title"/>
<xsl:text>},pdfauthor={</xsl:text>
<xsl:value-of select="$pdfAuthor"/>
<xsl:text>},pdfborder={0 0 0}} </xsl:text>
<xsl:if test="$parStylevSpace != '0'">
<xsl:text>\setlength{\parskip}{</xsl:text>
<xsl:value-of select="$parStylevSpace"/>
<xsl:text>cm}</xsl:text>
</xsl:if>
<xsl:if test="$idxNom = '1' or $idxLoc = '1'">
<xsl:text>\usepackage[innote]{indextools}
</xsl:text>
<!-- \indexsetup{} -->
<xsl:if test="$idxNom = '1'">
<xsl:text>\makeindex[title={</xsl:text>
<xsl:value-of select="$idxNomTitle"/>
<xsl:text>},name=nominum]</xsl:text>
</xsl:if>
<xsl:if test="$idxLoc = '1'">
<xsl:text>\makeindex[title={</xsl:text><xsl:value-of select="$idxLocTitle"/>
<xsl:text>},name=locorum]</xsl:text>
</xsl:if>
</xsl:if>
<xsl:text>\usepackage[</xsl:text><xsl:value-of select="$baseFontSize"/><xsl:text>pt]{extsizes} </xsl:text>
<!-- Set margins -->
<xsl:if test="$marginBinding != '' or $marginInner != '' or $marginOuter != '' or $marginTop != '' or $marginBottom != ''">
<xsl:text>\usepackage[</xsl:text>
<xsl:if test="$marginBinding != ''">
<xsl:text>bindingoffset=</xsl:text>
<xsl:value-of select="$marginBinding"/>
<xsl:text>in,</xsl:text>
</xsl:if>
<xsl:if test="$marginBinding != ''">
<xsl:text>inner=</xsl:text>
<xsl:value-of select="$marginInner"/>
<xsl:text>in,</xsl:text>
</xsl:if>
<xsl:if test="$marginOuter != ''">
<xsl:text>outer=</xsl:text>
<xsl:value-of select="$marginOuter"/>
<xsl:text>in,</xsl:text>
</xsl:if>
<xsl:if test="$marginTop != ''">
<xsl:text>top=</xsl:text>
<xsl:value-of select="$marginTop"/>
<xsl:text>in,</xsl:text>
</xsl:if>
<xsl:if test="$marginBottom != ''">
<xsl:text>bottom=</xsl:text>
<xsl:value-of select="$marginBottom"/>
<xsl:text>in</xsl:text>
</xsl:if>
<xsl:text>]{geometry} </xsl:text>
</xsl:if>
<!-- Fancy headers and footers -->
<xsl:text>\usepackage{fancyhdr} </xsl:text>
<xsl:text>\fancyfoot{} </xsl:text>
<xsl:text>\renewcommand{\headrulewidth}{0pt} % remove the header </xsl:text>
<xsl:text>\pagestyle{fancy} </xsl:text>
<xsl:choose>
<xsl:when test="$pageNumPlace = 'head'">
<xsl:text>\fancyhead[</xsl:text>
<xsl:value-of select="$pageNumPosition"/>
<xsl:text>]{</xsl:text>
<xsl:value-of select="$pageNumSize"/>
<xsl:text>\thepage} </xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>\fancyfoot[</xsl:text>
<xsl:value-of select="$pageNumPosition"/>
<xsl:text>]{</xsl:text>
<xsl:value-of select="$pageNumSize"/>
<xsl:text>\thepage} </xsl:text>
</xsl:otherwise>
</xsl:choose>
<xsl:if test="$rTitleEven">
<xsl:text>\fancyhead[</xsl:text>
<xsl:value-of select="$rTitleEvenPos"/>
<xsl:text>E]{</xsl:text>
<xsl:value-of select="$rTitleEvenSize"/>
<xsl:value-of select="$rTitleEven"/>
<xsl:text>} </xsl:text>
</xsl:if>
<xsl:if test="$rTitleOdd != ''">
<xsl:text>\fancyhead[</xsl:text>
<xsl:value-of select="$rTitleOddPos"/>
<xsl:text>O]{</xsl:text>
<xsl:value-of select="$rTitleOddSize"/>
<xsl:value-of select="$rTitleOdd"/>
<xsl:text>} </xsl:text>
</xsl:if>
<!-- Set accordingly -->
<xsl:choose>
<xsl:when test="$lang1 = 'ancientGreek'">
<xsl:text>\setmainlanguage[variant=ancient]{greek} </xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>\setmainlanguage{</xsl:text>
<xsl:value-of select="$lang1"/>
<xsl:text>} </xsl:text>
</xsl:otherwise>
</xsl:choose>
<xsl:choose>
<xsl:when test="$lang2 = 'ancientGreek'">
<xsl:text>\setmainlanguage[variant=ancient]{greek} </xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>\setotherlanguage{</xsl:text>
<xsl:value-of select="$lang2"/>
<xsl:text>} </xsl:text>
</xsl:otherwise>
</xsl:choose>
<!--<xsl:text>\usepackage[series={A,B},noend,nofamiliar,noeledsec,noledgroup]{reledmac} </xsl:text>-->
<xsl:text>\usepackage[series={A,B},noend,noeledsec]{reledmac} </xsl:text>
<xsl:text>\usepackage[shiftedpstarts]{reledpar} </xsl:text>
<xsl:text>\Xarrangement[A]{paragraph} </xsl:text>
<xsl:text>\Xarrangement[B]{paragraph} </xsl:text>
<!-- set the space before each series of notes -->
<xsl:text>% set the space before each series of notes </xsl:text>
<xsl:text>\Xbeforenotes[A]{</xsl:text><xsl:value-of select="$spaceBeforeNotesA"/><xsl:text>pt} </xsl:text>
<xsl:text>\Xbeforenotes[B]{</xsl:text><xsl:value-of select="$spaceBeforeNotesB"/><xsl:text>pt} </xsl:text>
<!-- Prevents the lemma from having the same characteristics as in the text (bold, italics, etc.) -->
<xsl:text>\Xlemmadisablefontselection[A] % Prevents the lemma from having the same characteristics as in the text (bold, italics, etc.) </xsl:text>
<!-- To print the line number in bold in the apparatus... -->
<xsl:text>\Xnotenumfont{\normalfont\bfseries} % To print the line number in bold in the apparatus... </xsl:text>
<xsl:if test="$lemSep != ''">
<xsl:text>\Xlemmaseparator[]{\,</xsl:text><xsl:value-of select="$lemSep"/><xsl:text>} </xsl:text>
</xsl:if>
<!-- to number the lines; options can be: page, pstart or section -->
<xsl:text>\lineation{</xsl:text><xsl:value-of select="$lineationStyle"/><xsl:text>} </xsl:text> <!-- setting lineation start, and step. -->
<xsl:text>\setlength{\stanzaindentbase}{20pt} \setstanzaindents{1,1} \setcounter{stanzaindentsrepetition}{1} </xsl:text>
<xsl:text>\firstlinenum{</xsl:text><xsl:value-of select="$lineationStart"/><xsl:text>} </xsl:text>
<xsl:text>\linenumincrement{</xsl:text><xsl:value-of select="$lineationStep"/><xsl:text>} </xsl:text>
<!-- choose in which margin the line numbers will appear -->
<xsl:text>\linenummargin{outer} \Xnumberonlyfirstinline[] \Xnumberonlyfirstintwolines[] </xsl:text>
<!-- separator between entries on the same line -->
<xsl:text>\Xsymlinenum{</xsl:text><xsl:value-of select="$separatorAppEntries"/><xsl:text>} </xsl:text>
<!-- order of the critical and familiar footnotes -->
<xsl:text>\fnpos{critical-familiar} </xsl:text>
<xsl:text>\renewcommand*{\thefootnoteA}{\alph{footnoteA}} </xsl:text>
<xsl:text>\title{</xsl:text><xsl:value-of select="//tei:teiHeader/tei:fileDesc/tei:titleStmt/tei:title"/><xsl:text>} </xsl:text>
<xsl:text>\author{</xsl:text><xsl:value-of select="/tei:TEI/tei:teiHeader/tei:fileDesc/tei:titleStmt/tei:author"/><xsl:text>} </xsl:text>
<xsl:text>\date{</xsl:text><xsl:value-of select="/tei:TEI/tei:teiHeader/tei:fileDesc/tei:publicationStmt/tei:date"/><xsl:text>} </xsl:text>
<!-- Title styling -->
<xsl:if test="$printTitleStyle != '' or $printTitleSize != ''">
<xsl:text>\usepackage{titling} \pretitle{\begin{center}</xsl:text>
<xsl:choose>
<xsl:when test="$printTitleSize != ''">
<xsl:text>\</xsl:text>
<xsl:value-of select="$printTitleSize"/>
</xsl:when>
<xsl:otherwise>
<xsl:text>\Large</xsl:text>
</xsl:otherwise>
</xsl:choose>
<xsl:choose>
<xsl:when test="$printTitleStyle = 'smallcaps'"><xsl:text>\scshape</xsl:text></xsl:when>
<xsl:when test="$printTitleStyle = 'caps'"><xsl:text>\MakeUppercase</xsl:text></xsl:when>
</xsl:choose>
<xsl:text>} </xsl:text>
</xsl:if>
<!-- % Basic workaround for broken \section functionality in reledmac-->
<xsl:text>\makeatletter \newcommand{\TEIsection}[1]{\vspace{</xsl:text>
<xsl:value-of select="$headStylevSpaceBefore"/>
<xsl:text>cm}\noindent</xsl:text>
<xsl:if test="$headAlign = 'center'">
<xsl:text>\centering</xsl:text>
</xsl:if>
<xsl:if test="$headSize != '0'">
<xsl:text>\</xsl:text>
<xsl:value-of select="$headSize"/>
</xsl:if>
<xsl:text>\text</xsl:text>
<xsl:if test="$headStyle = '1'">
<xsl:text>it</xsl:text>
</xsl:if>
<xsl:if test="$headStyle = '2'">
<xsl:text>bf</xsl:text>
</xsl:if>
<xsl:if test="$headStyle = '3'">
<xsl:text>sc</xsl:text>
</xsl:if>
<xsl:text>{#1}\vspace{</xsl:text>
<xsl:value-of select="$headStylevSpaceAfter"/>
<xsl:text>cm}}\par\nobreak\vspace{-\parskip}\@afterheading\noindent \makeatother \begin{document} \parindentX \raggedbottom </xsl:text>
<xsl:text>\sidenotemargin{</xsl:text><xsl:value-of select="$sideNoteLocation"/><xsl:text>} </xsl:text>
<xsl:text>\pagenumbering{</xsl:text><xsl:value-of select="$pageNumberingStyle"/><xsl:text>} </xsl:text>
<xsl:if test="$fromPage != '0'">
<xsl:text>\setcounter{page}{</xsl:text><xsl:value-of select="$fromPage"/><xsl:text>} </xsl:text>
</xsl:if>
<!-- Printing (or not) the document title -->
<xsl:if test="$printTitle != '0'">
<xsl:text>\maketitle </xsl:text>
</xsl:if>
<xsl:if test="$pageNumFirstPage = '0'">
<xsl:text>\thispagestyle{empty} </xsl:text>
</xsl:if>
<xsl:if test="$printListWit != '0'">
<xsl:if test="//tei:listWit">
<xsl:apply-templates select="//tei:listWit"/>
</xsl:if>
</xsl:if>
<xsl:for-each select="/tei:TEI/tei:text/tei:body/tei:div">
<xsl:variable name="divNumber">
<xsl:number level="single" from="/tei:TEI/tei:text/tei:body" count="tei:div" format="1"/>
</xsl:variable>
<xsl:text>\fancyhead[CE]{\textsc{</xsl:text><xsl:value-of select="tei:head"/><xsl:text>}} </xsl:text>
<xsl:text>\fancyhead[CO]{\textsc{</xsl:text><xsl:value-of select="/tei:TEI/tei:text/tei:back/tei:div[@xml:id='translation']/tei:div[0+$divNumber]/tei:head"/><xsl:text>}} </xsl:text>
<xsl:text>\begin{pages} </xsl:text>
<xsl:text>\begin{Leftside} </xsl:text>
<xsl:text>\beginnumbering \startlock </xsl:text>
<!--<xsl:text>\memorydump </xsl:text> -->
<xsl:apply-templates select="."/>
<xsl:text>\endlock \endnumbering </xsl:text>
<xsl:text>\end{Leftside} </xsl:text>
<xsl:text>\begin{Rightside} </xsl:text>
<xsl:text>\beginnumbering </xsl:text>
<!--<xsl:text>\memorydump </xsl:text> -->
<xsl:text>\firstlinenumR{1000000000} </xsl:text>
<xsl:apply-templates select="/tei:TEI/tei:text/tei:back/tei:div[@xml:id='translation']/tei:div[0+$divNumber]"/>
<xsl:text>\endnumbering </xsl:text>
<xsl:text>\end{Rightside} </xsl:text>
<xsl:text>\end{pages} </xsl:text>
<xsl:text>\Pages </xsl:text>
</xsl:for-each>
<xsl:if test="$idxNom = '1'">
<xsl:if test="$idxNomPrologue != ''">
<xsl:text>\indexprologue{\small </xsl:text><xsl:value-of select="$idxNomPrologue"/><xsl:text>} </xsl:text>
</xsl:if>
<xsl:text>\printindex[nominum] </xsl:text>
</xsl:if>
<xsl:if test="$idxLoc = '1'">
<xsl:if test="$idxLocPrologue != ''">
<xsl:text>\indexprologue{\small </xsl:text><xsl:value-of select="$idxLocPrologue"/><xsl:text>} </xsl:text>
</xsl:if>
<xsl:text>\printindex[locorum] </xsl:text>
</xsl:if>
<xsl:text>\end{document} </xsl:text>
</xsl:template>
<!-- Prints div heads as a Chapter -->
<xsl:template match="tei:div">
<xsl:apply-templates/>
</xsl:template>
<!-- Prints div heads -->
<xsl:template match="tei:head[parent::tei:div or parent::tei:body]">
<xsl:choose>
<xsl:when test="not(ancestor::tei:rdg)">
<xsl:text>\pstart \TEIsection{</xsl:text>
</xsl:when>
<xsl:otherwise>
<!-- If this is the descendant of a tei:rdg, it will only appear in the critical footnotes, so paragraphs are not allowed here, and we don't want fancy markup either; just a space to separate paragraphs. -->
<xsl:text> </xsl:text>
</xsl:otherwise>
</xsl:choose>
<!-- several lemmata can end or begin at the same paragraph-like element; we're going to count the number of tei:lem ancestors, and check for all of them is the current element is a first or last descendant -->
<xsl:variable name="depthOfLem" select="count(ancestor::tei:lem)"/>
<xsl:call-template name="whileStartLem">
<xsl:with-param name="depth">
<xsl:value-of select="$depthOfLem"/>
</xsl:with-param>
</xsl:call-template>
<xsl:apply-templates/>
<!-- several lemmata can end or begin at the same paragraph-like element; we're going to count the number of tei:lem ancestors, and check for all of them is the current element is a first or last descendant -->
<xsl:call-template name="whileEndLem">
<xsl:with-param name="depth">
<xsl:value-of select="$depthOfLem"/>
</xsl:with-param>
</xsl:call-template>
<xsl:if test="not(ancestor::tei:rdg)">
<!-- no paragraphs in the footnotes -->
<xsl:text>} \pend </xsl:text>
</xsl:if>
</xsl:template>
<!-- Prints out paragraphs -->
<xsl:template match="tei:p|tei:ab">
<!--
<xsl:choose>
<xsl:when test="ancestor::tei:rdg">
<xsl:text> </xsl:text>
</xsl:when>
<xsl:when test="@rend">
<xsl:text> </xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text> \pstart </xsl:text>
</xsl:otherwise>
</xsl:choose>
-->
<!--
<xsl:choose>
<xsl:when test="not(ancestor::tei:rdg)">
<xsl:text>\pstart </xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text> </xsl:text>
</xsl:otherwise>
</xsl:choose>
-->
<xsl:choose>
<xsl:when test="ancestor::tei:rdg">
<xsl:text> </xsl:text>
</xsl:when>
<xsl:when test="ancestor::tei:note"/>
<xsl:otherwise>
<xsl:text>\pstart </xsl:text>
</xsl:otherwise>
</xsl:choose>
<!-- several lemmata can end or begin at the same paragramh-like element; we're going to count the number of tei:lem ancestors, and check for all of them is the current element is a first or last descendant -->
<xsl:variable name="depthOfLem" select="count(ancestor::tei:lem)"/>
<xsl:call-template name="whileStartLem">
<xsl:with-param name="depth">
<xsl:value-of select="$depthOfLem"/>
</xsl:with-param>
</xsl:call-template>
<xsl:apply-templates/>
<!-- several lemmata can end or begin at the same paragramh-like element; we're going to count the number of tei:lem ancestors, and check for all of them is the current element is a first or last descendant -->
<xsl:call-template name="whileEndLem">
<xsl:with-param name="depth">
<xsl:value-of select="$depthOfLem"/>
</xsl:with-param>
</xsl:call-template>
<!--
<xsl:choose>
<xsl:when test="ancestor::tei:rdg">
<xsl:text> </xsl:text>
</xsl:when>
<xsl:when test="@rend">
<xsl:text> </xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text> \pend </xsl:text>
</xsl:otherwise>
</xsl:choose>
-->
<!--
<xsl:if test="not(ancestor::tei:rdg)">
<xsl:text> \pend </xsl:text>
</xsl:if>
-->
<xsl:choose>
<xsl:when test="ancestor::tei:rdg">
<xsl:text> </xsl:text>
</xsl:when>
<xsl:when test="ancestor::tei:note"/>
<xsl:otherwise>
<xsl:text> \pend</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="whileStartLem">
<xsl:param name="depth"/>
<xsl:if test="$depth > 0">
<xsl:if test="ancestor::tei:lem[position() = $depth]/descendant::node()[name() = 'p' or name() = 'head' or name() = 'lg' or name() = 'list'][position() = 1] = self::node()">
<xsl:text>\edlabel{lem_</xsl:text>
<xsl:number select="ancestor::tei:lem[position() = $depth]" level="any"/>
<xsl:text>_start} </xsl:text>
</xsl:if>
<xsl:call-template name="whileStartLem">
<xsl:with-param name="depth" select="$depth - 1"/>
</xsl:call-template>
</xsl:if>
</xsl:template>
<xsl:template name="whileEndLem">
<xsl:param name="depth"/>
<xsl:if test="$depth > 0">
<xsl:if test="ancestor::tei:lem[position() = $depth]/descendant::node()[name() = 'p' or name() = 'head' or name() = 'lg' or name() = 'list'][last()] = self::node()">
<xsl:text>\edtext{</xsl:text>
<xsl:text>\edlabel{lem_</xsl:text>
<xsl:number select="ancestor::tei:lem[position() = $depth]" level="any"/>
<xsl:text>_end}}</xsl:text>
<xsl:text>{\xxref{lem_</xsl:text>
<xsl:number select="ancestor::tei:lem[position() = $depth]" level="any"/>
<xsl:text>_start}{lem_</xsl:text>
<xsl:number select="ancestor::tei:lem[position() = $depth]" level="any"/>
<xsl:text>_end}</xsl:text>
<xsl:call-template name="noteForLemmaWithParagraphs">
<xsl:with-param name="depth">
<xsl:value-of select="$depth"/>
</xsl:with-param>
</xsl:call-template>
<xsl:text>} </xsl:text>
</xsl:if>
<xsl:call-template name="whileEndLem">
<xsl:with-param name="depth" select="$depth - 1"/>
</xsl:call-template>
</xsl:if>
</xsl:template>
<xsl:template name="noteForLemmaWithParagraphs">
<xsl:param name="depth"/>
<xsl:choose>
<!-- default case -->
<!-- It is common practice to write the apparatus text in lower case, so I use the \MakeLowercase{} command -->
<!-- Common case: there is a <lem> -->
<xsl:when
test="ancestor::tei:app[position() = number($depth)]/tei:lem/descendant-or-self::text() != ''">
<xsl:choose>
<!-- If there is a tei:note[@type='altLem'], then we use its contents for the lemma, without changing the case -->
<xsl:when test="ancestor::tei:app[position() = number($depth)]/tei:note[@type='altLem']">
<xsl:text>{\lemma{</xsl:text>
<xsl:apply-templates
select="ancestor::tei:app[position() = number($depth)]/tei:note[@type='altLem']"/>
<xsl:text>} </xsl:text>
<xsl:choose>
<xsl:when test="ancestor::tei:app[position() = number($depth)]/tei:rdg">
<xsl:text>\Afootnote{</xsl:text>
<xsl:for-each select="ancestor::tei:app[position() = number($depth)]/tei:rdg">
<xsl:variable name="currentRdg">
<xsl:apply-templates select="."/>
</xsl:variable>
<xsl:choose>
<xsl:when test="text() != ''">
<!-- doing this because of a bug in reledmac when a footnote starts with plus or minus-->
<xsl:if
test="starts-with($currentRdg, 'plus') or starts-with($currentRdg, 'minus')">
<xsl:text>\,</xsl:text>
</xsl:if>
<xsl:value-of select="lower-case($currentRdg)"/>
<xsl:choose>
<xsl:when test="$italWit = '1'">
<xsl:text> \emph{</xsl:text>
</xsl:when>
<xsl:otherwise><xsl:text> </xsl:text></xsl:otherwise>
</xsl:choose>
<xsl:value-of select="translate(@wit, '#', '')"/>
<xsl:if test="$italWit = '1'">
<xsl:text>}</xsl:text>
</xsl:if>
</xsl:when>
<xsl:otherwise>
<xsl:text>\emph{</xsl:text>
<xsl:value-of select="$varOm"/>
<xsl:text>} </xsl:text>
<xsl:choose>
<xsl:when test="$italWit = '1'">
<xsl:text> \emph{</xsl:text>
</xsl:when>
<xsl:otherwise><xsl:text> </xsl:text></xsl:otherwise>
</xsl:choose>
<xsl:value-of select="translate(@wit, '#', '')"/>
<xsl:if test="$italWit = '1'">
<xsl:text>}</xsl:text>
</xsl:if>
</xsl:otherwise>
</xsl:choose>
<xsl:if test="following-sibling::node()/name() = 'rdg'">
<xsl:text>, </xsl:text>
</xsl:if>
</xsl:for-each>
<xsl:text>}}</xsl:text>
</xsl:when>
<xsl:otherwise>
<!-- Eh?? -->
<xsl:text>\Afootnote{</xsl:text>
<xsl:apply-templates/>
<xsl:text>}}</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<!-- If there is not, we use the contents of the <lem> -->
<xsl:otherwise>
<xsl:text>{\lemma{</xsl:text>
<xsl:variable name="currentLemmaNote"
select="ancestor::tei:app[position() = number($depth)]/tei:lem/tokenize(normalize-space(string-join(descendant-or-self::text()[not(parent::tei:rdg)][not(ancestor::tei:note)][not(ancestor::tei:bibl)],'')),' ')"/>
<xsl:choose>
<xsl:when test="$shortenLem != '0' and count($currentLemmaNote) > $shortenLem">
<xsl:value-of
select="translate(lower-case($currentLemmaNote[position() = 1]), ',.!?:;)', '')"/>
<xsl:text> </xsl:text>
<xsl:value-of
select="translate(lower-case($currentLemmaNote[position() = 2]), ',.!?:;)', '')"/>
<xsl:text> </xsl:text>
<xsl:value-of
select="translate(lower-case($currentLemmaNote[position() = 3]), ',.!?:;)', '')"/>
<xsl:text> \ldots{} </xsl:text>
<xsl:value-of
select="translate(lower-case($currentLemmaNote[last() - 2]), ',.!?:;)', '')"/>
<xsl:text> </xsl:text>
<xsl:value-of
select="translate(lower-case($currentLemmaNote[last() - 1]), ',.!?:;)', '')"/>
<xsl:text> </xsl:text>
<xsl:value-of
select="translate(lower-case($currentLemmaNote[last()]), ',.!?:;)', '')"/>
<!-- <xsl:value-of select="translate(lower-case(./tei:lem/tokenize(normalize-space(string-join(descendant-or-self::text()[not(ancestor::tei:rdg)][not(ancestor::tei:note)][not(ancestor::tei:bibl)],'')),' ')[last()]), ',.!?:;)', '')"/> -->
</xsl:when>
<!-- we must not use $currentLemma here; it's for the edtext and has plenty of unnecessary tex markup (especially if the apps are nested)
==> write a clean version of the lemma, text only (could be optimised) -->
<xsl:otherwise>
<xsl:value-of
select="translate(lower-case(ancestor::tei:app[position() = number($depth)]/tei:lem/normalize-space(string-join(descendant-or-self::text()[not(parent::tei:rdg)][not(ancestor::tei:note)][not(ancestor::tei:bibl)],''))), ',.!?:;)', '')"
/>
</xsl:otherwise>
</xsl:choose>
<xsl:text>} </xsl:text>
<xsl:choose>
<xsl:when test="ancestor::tei:app[position() = number($depth)]/tei:rdg">
<xsl:text>\Afootnote{</xsl:text>
<xsl:for-each select="ancestor::tei:app[position() = number($depth)]/tei:rdg">
<xsl:variable name="currentRdg">
<xsl:apply-templates select="."/>
</xsl:variable>
<xsl:choose>
<xsl:when test="descendant-or-self::text() != ''">
<xsl:if
test="starts-with($currentRdg, 'plus') or starts-with($currentRdg, 'minus')">
<xsl:text>\,</xsl:text>
</xsl:if>
<xsl:value-of select="lower-case($currentRdg)"/>
<xsl:choose>
<xsl:when test="$italWit = '1'">
<xsl:text> \emph{</xsl:text>
</xsl:when>
<xsl:otherwise><xsl:text> </xsl:text></xsl:otherwise>
</xsl:choose>
<xsl:value-of select="translate(@wit, '#', '')"/>
<xsl:if test="$italWit = '1'">
<xsl:text>}</xsl:text>
</xsl:if>
</xsl:when>
<xsl:otherwise>
<!-- it is an omission by this witness -->
<xsl:text>\emph{</xsl:text>
<xsl:value-of select="$varOm"/>
<xsl:text>} </xsl:text>
<xsl:choose>
<xsl:when test="$italWit = '1'">
<xsl:text> \emph{</xsl:text>
</xsl:when>
<xsl:otherwise><xsl:text> </xsl:text></xsl:otherwise>
</xsl:choose>
<xsl:value-of select="translate(@wit, '#', '')"/>
<xsl:if test="$italWit = '1'">
<xsl:text>}</xsl:text>
</xsl:if>
</xsl:otherwise>
</xsl:choose>
<xsl:if test="following-sibling::node()/name() = 'rdg'">
<xsl:text>, </xsl:text>
</xsl:if>
</xsl:for-each>
<xsl:text>}}</xsl:text>
</xsl:when>
<xsl:otherwise>
<!-- Eh?? -->
<xsl:text>\Afootnote{</xsl:text>
<xsl:apply-templates/>
<xsl:text>}}</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<!-- addition; the lemma is empty, so short of a better thing we need to put in the footnote's lemma the last word preceding this <app> -->
<xsl:otherwise>
<xsl:choose>
<xsl:when test="ancestor::tei:app[position() = number($depth)]/tei:note[@type='altLem']">
<xsl:text>{\lemma{</xsl:text>
<xsl:apply-templates
select="ancestor::tei:app[position() = number($depth)]/tei:note[@type='altLem']"/>
<xsl:text>} </xsl:text>
<xsl:choose>
<xsl:when test="ancestor::tei:app[position() = number($depth)]/tei:rdg">
<xsl:text>\Afootnote{</xsl:text>
<xsl:for-each select="ancestor::tei:app[position() = number($depth)]/tei:rdg">
<xsl:variable name="currentRdg">
<xsl:apply-templates select="."/>
</xsl:variable>
<xsl:if test="descendant-or-self::text() != ''">
<xsl:if
test="starts-with($currentRdg, 'plus') or starts-with($currentRdg, 'minus')">
<xsl:text>\,</xsl:text>
</xsl:if>
<xsl:value-of select="lower-case($currentRdg)"/>
<xsl:text>\emph{</xsl:text>
<xsl:value-of select="$varAdd"/>
<xsl:text>} </xsl:text>
<xsl:choose>
<xsl:when test="$italWit = '1'">
<xsl:text> \emph{</xsl:text>
</xsl:when>
<xsl:otherwise><xsl:text> </xsl:text></xsl:otherwise>
</xsl:choose>
<xsl:value-of select="translate(@wit, '#', '')"/>
<xsl:if test="$italWit = '1'">
<xsl:text>}</xsl:text>
</xsl:if>
<xsl:if
test="following-sibling::node()/name() = 'rdg' and following-sibling::node()/text() != ''">
<xsl:text>, </xsl:text>
</xsl:if>
</xsl:if>
</xsl:for-each>
<xsl:text>}}</xsl:text>
</xsl:when>
<xsl:otherwise>
<!-- Eh?? -->
<xsl:text>\Afootnote{</xsl:text>
<xsl:apply-templates/>
<xsl:text>}}</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<xsl:text>\edtext{}{\lemma{</xsl:text>
<xsl:variable name="currenttPreviousWord">
<xsl:value-of
select="tokenize(normalize-space(string-join(ancestor::tei:app[position() = number($depth)]/preceding::text()[not(ancestor::tei:rdg)][not(ancestor::tei:note)][not(ancestor::tei:bibl)],'')),' ')[last()]"
/>
</xsl:variable>
<!-- If the "word" immediately preceding the addition is a punctuation mark, then we're going to select the "word" before this one;
TODO: ideally, this should be recursive -->
<xsl:choose>
<xsl:when
test="$currenttPreviousWord = '.' or $currenttPreviousWord = '!' or $currenttPreviousWord = '?' or $currenttPreviousWord = ';' or $currenttPreviousWord = ':' or $currenttPreviousWord = ','">
<xsl:value-of
select="translate(lower-case(tokenize(normalize-space(string-join(preceding::text()[not(parent::tei:rdg)][not(ancestor::tei:note)][not(ancestor::tei:bibl)],'')),' ')[last()-1]), ',.!?:;)', '')"
/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of
select="translate(lower-case(tokenize(normalize-space(string-join(ancestor::tei:app[position() = number($depth)]/preceding::text()[not(parent::tei:rdg)][not(ancestor::tei:note)][not(ancestor::tei:bibl)],'')),' ')[last()]), ',.!?:;)', '')"
/>
</xsl:otherwise>
</xsl:choose>
<xsl:text>} </xsl:text>
<xsl:choose>
<xsl:when test="ancestor::tei:app[position() = number($depth)]/tei:rdg">
<xsl:text>\Afootnote{</xsl:text>
<xsl:for-each select="ancestor::tei:app[position() = number($depth)]/tei:rdg">
<xsl:variable name="currentRdg">
<xsl:apply-templates select="."/>
</xsl:variable>
<xsl:if test="descendant-or-self::text() != ''">
<xsl:if
test="starts-with($currentRdg, 'plus') or starts-with($currentRdg, 'minus')">
<xsl:text>\,</xsl:text>
</xsl:if>
<xsl:value-of select="lower-case($currentRdg)"/>
<xsl:text> \emph{</xsl:text>
<xsl:value-of select="$varAdd"/>
<xsl:text>} </xsl:text>
<xsl:if test="$italWit = '1'">
<xsl:text>\emph{</xsl:text>
</xsl:if>
<xsl:value-of select="translate(@wit, '#', '')"/>
<xsl:if test="$italWit = '1'">
<xsl:text>}</xsl:text>
</xsl:if>
<xsl:if
test="following-sibling::node()/name() = 'rdg' and following-sibling::node()/descendant-or-self::text() != ''">
<xsl:text>, </xsl:text>
</xsl:if>
</xsl:if>
</xsl:for-each>
<xsl:text>}}</xsl:text>
</xsl:when>
<xsl:otherwise>
<!-- Eh?? -->
<xsl:text>\Afootnote{</xsl:text>
<xsl:apply-templates/>
<xsl:text>}}</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:otherwise>
</xsl:choose>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!-- Add index entries for person names -->
<xsl:template match="tei:persName">
<xsl:choose>
<xsl:when test="$idxNom = '1'">
<xsl:choose>
<xsl:when test="@key">
<xsl:apply-templates/>
<xsl:text>\index[nominum]{</xsl:text>
<xsl:value-of select="@key"/>
<xsl:text>} </xsl:text>
</xsl:when>
<xsl:when test="@ref">
<xsl:variable name="nameRef">
<xsl:value-of select="translate(@ref, '#', '')"/>
</xsl:variable>
<xsl:apply-templates/>
<xsl:text>\index[nominum]{</xsl:text>
<xsl:value-of select="//tei:person[@xml:id = $nameRef]/tei:persName"/>
<xsl:text>} </xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates/>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!-- Add index entries for place names -->
<xsl:template match="tei:placeName">
<xsl:choose>
<xsl:when test="$idxLoc = '1'">
<xsl:choose>
<xsl:when test="@key">
<xsl:apply-templates/>\index[locorum]{<xsl:value-of select="@key"/>} </xsl:when>
<xsl:when test="@ref">
<xsl:variable name="nameRef"><xsl:value-of select="translate(@ref, '#', '')"
/></xsl:variable>
<xsl:apply-templates/>\index[locorum]{<xsl:value-of
select="//tei:place[@xml:id = $nameRef]/tei:placeName"/>} </xsl:when>
<xsl:otherwise>
<xsl:apply-templates/>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!--Adds linebreaks into document-->
<!--
<xsl:template match="tei:lb">
<xsl:if test="not(parent::tei:w)">
<xsl:text> </xsl:text>
</xsl:if>
</xsl:template>
-->
<xsl:template match="tei:lb"/>
<xsl:template match="tei:anchor"/><!--TRH-->
<!-- adds page breaks into document -->
<xsl:template match="tei:pb">
<xsl:if test="$folioNotes = '1'">
<xsl:choose>
<xsl:when test="$folioNotesAll = '1'">
<!-- Printing all tei:pb -->
<xsl:value-of select="$folioInTextMarker"/>\ledsidenote{<xsl:if test="$folioNotesMs = '1'"
><xsl:if test="@ed|@edRef">\emph{<xsl:choose>
<xsl:when test="@ed and @edRef"><xsl:value-of select="translate(@edRef, '#', '')"
/></xsl:when>
<xsl:when test="@ed and not(@edRef)"><xsl:value-of select="translate(@ed, '#', '')"
/></xsl:when>
<xsl:when test="@edRef and not(@ed)"><xsl:value-of
select="translate(@edRef, '#', '')"/></xsl:when>
</xsl:choose><xsl:text> </xsl:text>}</xsl:if></xsl:if><xsl:value-of select="@n"/>} </xsl:when>
<xsl:when test="$folioNotesAll = '0'">
<!-- Printing only one ms. -->
<xsl:choose>
<xsl:when test="$folioNoteAttribute = 'ed'">
<xsl:if test="translate(@ed, '#', '') = $folioNoteAttributeValue">
<xsl:value-of select="$folioInTextMarker"/>\ledsidenote{<xsl:if
test="$folioNotesMs = '1'"><xsl:if test="@ed|@edRef">\emph{<xsl:choose>
<xsl:when test="@ed and @edRef"><xsl:value-of
select="translate(@edRef, '#', '')"/></xsl:when>
<xsl:when test="@ed and not(@edRef)"><xsl:value-of
select="translate(@ed, '#', '')"/></xsl:when>
<xsl:when test="@edRef and not(@ed)"><xsl:value-of
select="translate(@edRef, '#', '')"/></xsl:when>
</xsl:choose><xsl:text> </xsl:text>}</xsl:if></xsl:if><xsl:value-of select="@n"
/>} </xsl:if>
</xsl:when>
<xsl:when test="$folioNoteAttribute = 'edRef'">
<xsl:if test="translate(@edRef, '#', '') = $folioNoteAttributeValue">
<xsl:value-of select="$folioInTextMarker"/>\ledsidenote{<xsl:if
test="$folioNotesMs = '1'"><xsl:if test="@ed|@edRef">\emph{<xsl:choose>
<xsl:when test="@ed and @edRef"><xsl:value-of
select="translate(@edRef, '#', '')"/></xsl:when>
<xsl:when test="@ed and not(@edRef)"><xsl:value-of
select="translate(@ed, '#', '')"/></xsl:when>
<xsl:when test="@edRef and not(@ed)"><xsl:value-of
select="translate(@edRef, '#', '')"/></xsl:when>
</xsl:choose><xsl:text> </xsl:text>}</xsl:if></xsl:if><xsl:value-of select="@n"
/>} </xsl:if>
</xsl:when>
</xsl:choose>
</xsl:when>
</xsl:choose>
</xsl:if>
</xsl:template>
<!-- inserts linegroup into document-->
<xsl:template match="tei:lg">
<!-- lg is a pain because it can occur in p (or not), but in tex it generates a stanza structure which must never be inside a paragraph
I've tried closing the parent paragraph and re-opening one, but it's not enough.
If the lg are inside a quotation, for instance, we need to have some more complicated handling.
-->
<xsl:choose>
<xsl:when test="not(ancestor::tei:rdg)">
<xsl:if test="ancestor::tei:p and not(preceding-sibling::tei:lg)">
<!-- In TEI an lg can occur within a p, while in LaTeX a stanza cannot occur within a pstart. The only solution I came up with was to close then re-open the current paragraph.
Warning: this can create a problem in the .tex file when the lg occurs at the very beginning or end of the paragraph. -->
<xsl:text> \pend </xsl:text>
</xsl:if>
<xsl:text>
\stanza[ ] </xsl:text>
<!-- this is not good; TODO: do better. -->
<xsl:if test="ancestor::tei:cit">
<xsl:if
test="ancestor::tei:quote[position() = 1]/descendant::node()[name() = 'lg'][position() = 1] = self::node()">
<xsl:text>\edlabel{cit_</xsl:text>
<xsl:number select="ancestor::tei:quote[position() = 1]" level="any"/>
<xsl:text>_start}</xsl:text>
</xsl:if>
</xsl:if>
</xsl:when>
<xsl:otherwise>
<xsl:text> </xsl:text>
</xsl:otherwise>
</xsl:choose>