-
Notifications
You must be signed in to change notification settings - Fork 7
/
msdesc2html.xsl
2487 lines (2250 loc) · 100 KB
/
msdesc2html.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 xmlns="http://www.w3.org/1999/xhtml"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:tei="http://www.tei-c.org/ns/1.0"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xpath-default-namespace="http://www.tei-c.org/ns/1.0"
xmlns:jc="http://james.blushingbunny.net/ns.html"
xmlns:html="http://www.w3.org/1999/xhtml"
xmlns:bod="http://www.bodleian.ox.ac.uk/bdlss"
exclude-result-prefixes="tei jc html xs bod" version="2.0">
<!--
Created by Dr James Cummings james@blushingbunny.net
2017-05 for output of Bodley TEI msDescs as HTML to
be sucked into the frontend platform.
-->
<xsl:param name="collections-path" as="xs:string" select="''"/>
<xsl:param name="files" select="'*.xml'"/>
<xsl:param name="recurse" select="'yes'"/>
<xsl:param name="verbose" as="xs:boolean" select="false()"/>
<xsl:variable name="website-url" as="xs:string" select="''"/> <!-- This will be overriden by stylesheets that call this one -->
<xsl:variable name="output-full-html" as="xs:boolean" select="true()"/>
<xsl:output omit-xml-declaration="yes" method="xhtml" encoding="UTF-8" indent="yes"/>
<!-- Strip out all processing instructions in the source XML -->
<xsl:template match="processing-instruction()"/>
<!-- Functions -->
<xsl:function name="bod:logging" as="empty-sequence()">
<xsl:param name="level" as="xs:string"/>
<xsl:param name="msg" as="xs:string"/>
<xsl:param name="context" as="element()"/>
<xsl:param name="vals"/>
<xsl:choose>
<xsl:when test="lower-case($level) eq 'error'">
<xsl:message terminate="yes" select="concat(upper-case($level), '	', $msg, '	', ($context/ancestor-or-self::*/@xml:id)[position()=last()], ' ', string-join($vals, ' '))"/>
</xsl:when>
<xsl:otherwise>
<xsl:message select="concat(upper-case($level), '	', $msg, '	', ($context/ancestor-or-self::*/@xml:id)[position()=last()], ' ', string-join($vals, ' '))"/>
</xsl:otherwise>
</xsl:choose>
</xsl:function>
<xsl:function name="bod:logging" as="empty-sequence()">
<xsl:param name="level" as="xs:string"/>
<xsl:param name="msg" as="xs:string"/>
<xsl:param name="context" as="element()"/>
<xsl:choose>
<xsl:when test="lower-case($level) eq 'error'">
<xsl:message terminate="yes" select="concat(upper-case($level), '	', $msg, '	', ($context/ancestor-or-self::*/@xml:id)[position()=last()], ' ')"/>
</xsl:when>
<xsl:otherwise>
<xsl:message select="concat(upper-case($level), '	', $msg, '	', ($context/ancestor-or-self::*/@xml:id)[position()=last()], ' ')"/>
</xsl:otherwise>
</xsl:choose>
</xsl:function>
<xsl:function name="bod:languageCodeLookup" as="xs:string">
<xsl:param name="lang" as="xs:string"/>
<!-- textLang elements should really contain both codes and a full description, but this is for the few known cases where there is just a code -->
<xsl:choose>
<xsl:when test="$lang eq 'he'">Hebrew</xsl:when>
<xsl:when test="$lang eq 'yi'">Yiddish</xsl:when>
<xsl:when test="$lang eq 'arc'">Aramaic</xsl:when>
<xsl:when test="$lang eq 'ka'">Georgian</xsl:when>
<xsl:when test="$lang eq 'jrb'">Judeo-Arabic</xsl:when>
<xsl:when test="$lang eq 'ar'">Arabic</xsl:when>
<xsl:when test="$lang eq 'lad'">Ladino</xsl:when>
<xsl:when test="$lang eq 'jpr'">Judeo-Persian</xsl:when>
<xsl:when test="$lang eq 'jpt'">Judaeo-Portuguese</xsl:when>
<xsl:when test="$lang eq 'grc'">Greek</xsl:when>
<xsl:when test="$lang eq 'es'">Spanish</xsl:when>
<xsl:when test="$lang eq 'la'">Latin</xsl:when>
<xsl:when test="$lang eq 'lat'">Latin</xsl:when>
<xsl:when test="$lang eq 'en'">English</xsl:when>
<xsl:when test="$lang eq 'eng'">English</xsl:when>
<xsl:when test="$lang eq 'bo'">Tibetan</xsl:when>
<xsl:when test="$lang eq 'zxx'">No Linguistic Content</xsl:when>
<xsl:when test="$lang eq 'und'">Undetermined</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$lang"/>
</xsl:otherwise>
</xsl:choose>
</xsl:function>
<xsl:function name="bod:personRoleLookup" as="xs:string">
<xsl:param name="role" as="xs:string"/>
<!-- Lookup the values used in role attributes of people (or organizations) and map
those values to labels for display in facets on the web site -->
<xsl:variable name="rolelabels" as="xs:string*">
<xsl:for-each select="distinct-values(tokenize(normalize-space($role), ' '))">
<xsl:choose>
<xsl:when test="string-length(.) eq 3">
<xsl:value-of select="bod:roleLookupMarcCode(.)"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="bod:roleNormalizeLabel(.)"/>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:variable>
<xsl:variable name="label">
<xsl:for-each select="$rolelabels[string-length(.) gt 0]">
<xsl:value-of select="."/>
<xsl:choose>
<xsl:when test="position() eq last() - 1">
<xsl:text> and </xsl:text>
</xsl:when>
<xsl:when test="position() ne last()">
<xsl:text>, </xsl:text>
</xsl:when>
</xsl:choose>
</xsl:for-each>
</xsl:variable>
<xsl:value-of select="string-join($label, '')"/>
</xsl:function>
<xsl:function name="bod:roleNormalizeLabel" as="xs:string">
<xsl:param name="rolelabel" as="xs:string"/>
<xsl:variable name="lcrolelabel" as="xs:string" select="lower-case($rolelabel)"/>
<xsl:choose>
<xsl:when test="$lcrolelabel eq 'formerowner'">Former Owner</xsl:when>
<xsl:otherwise>
<!-- Anything else, just return with first letter capitalized -->
<xsl:value-of select="concat(upper-case(substring($rolelabel, 1, 1)), substring($rolelabel, 2))"/>
</xsl:otherwise>
</xsl:choose>
</xsl:function>
<xsl:function name="bod:roleLookupMarcCode" as="xs:string?">
<xsl:param name="rolecode" as="xs:string"/>
<!-- This is the MARC Code List for Relators standard, copy taken
on 2018-06-22 from http://id.loc.gov/vocabulary/relators.tsv -->
<xsl:variable name="rolesmapping" as="element()*">
<map code="abr">Abridger</map>
<map code="acp">Art copyist</map>
<map code="act">Actor</map>
<map code="adi">Art director</map>
<map code="adp">Adapter</map>
<map code="aft">Author of afterword, colophon, etc.</map>
<map code="anl">Analyst</map>
<map code="anm">Animator</map>
<map code="ann">Annotator</map>
<map code="ant">Bibliographic antecedent</map>
<map code="ape">Appellee</map>
<map code="apl">Appellant</map>
<map code="app">Applicant</map>
<map code="aqt">Author in quotations or text abstracts</map>
<map code="arc">Architect</map>
<map code="ard">Artistic director</map>
<map code="arr">Arranger</map>
<map code="art">Artist</map>
<map code="asg">Assignee</map>
<map code="asn">Associated name</map>
<map code="ato">Autographer</map>
<map code="att">Attributed name</map>
<map code="auc">Auctioneer</map>
<map code="aud">Author of dialog</map>
<map code="aui">Author of introduction, etc.</map>
<map code="aus">Screenwriter</map>
<map code="aut">Author</map>
<map code="bdd">Binding designer</map>
<map code="bjd">Bookjacket designer</map>
<map code="bkd">Book designer</map>
<map code="bkp">Book producer</map>
<map code="blw">Blurb writer</map>
<map code="bnd">Binder</map>
<map code="bpd">Bookplate designer</map>
<map code="brd">Broadcaster</map>
<map code="brl">Braille embosser</map>
<map code="bsl">Bookseller</map>
<map code="cas">Caster</map>
<map code="ccp">Conceptor</map>
<map code="chr">Choreographer</map>
<map code="cli">Client</map>
<map code="cll">Calligrapher</map>
<map code="clr">Colorist</map>
<map code="clt">Collotyper</map>
<map code="cmm">Commentator</map>
<map code="cmp">Composer</map>
<map code="cmt">Compositor</map>
<map code="cnd">Conductor</map>
<map code="cng">Cinematographer</map>
<map code="cns">Censor</map>
<map code="coe">Contestant-appellee</map>
<map code="col">Collector</map>
<map code="com">Compiler</map>
<map code="con">Conservator</map>
<map code="cor">Collection registrar</map>
<map code="cos">Contestant</map>
<map code="cot">Contestant-appellant</map>
<map code="cou">Court governed</map>
<map code="cov">Cover designer</map>
<map code="cpc">Copyright claimant</map>
<map code="cpe">Complainant-appellee</map>
<map code="cph">Copyright holder</map>
<map code="cpl">Complainant</map>
<map code="cpt">Complainant-appellant</map>
<map code="cre">Creator</map>
<map code="crp">Correspondent</map>
<map code="crr">Corrector</map>
<map code="crt">Court reporter</map>
<map code="csl">Consultant</map>
<map code="csp">Consultant to a project</map>
<map code="cst">Costume designer</map>
<map code="ctb">Contributor</map>
<map code="cte">Contestee-appellee</map>
<map code="ctg">Cartographer</map>
<map code="ctr">Contractor</map>
<map code="cts">Contestee</map>
<map code="ctt">Contestee-appellant</map>
<map code="cur">Curator</map>
<map code="cwt">Commentator for written text</map>
<map code="dbp">Distribution place</map>
<map code="dfd">Defendant</map>
<map code="dfe">Defendant-appellee</map>
<map code="dft">Defendant-appellant</map>
<map code="dgg">Degree granting institution</map>
<map code="dgs">Degree supervisor</map>
<map code="dis">Dissertant</map>
<map code="dln">Delineator</map>
<map code="dnc">Dancer</map>
<map code="dnr">Donor</map>
<map code="dpc">Depicted</map>
<map code="dpt">Depositor</map>
<map code="drm">Draftsman</map>
<map code="drt">Director</map>
<map code="dsr">Designer</map>
<map code="dst">Distributor</map>
<map code="dtc">Data contributor</map>
<map code="dte">Dedicatee</map>
<map code="dtm">Data manager</map>
<map code="dto">Dedicator</map>
<map code="dub">Dubious author</map>
<map code="edc">Editor of compilation</map>
<map code="edm">Editor of moving image work</map>
<map code="edt">Editor</map>
<map code="egr">Engraver</map>
<map code="elg">Electrician</map>
<map code="elt">Electrotyper</map>
<map code="eng">Engineer</map>
<map code="enj">Enacting jurisdiction</map>
<map code="etr">Etcher</map>
<map code="evp">Event place</map>
<map code="exp">Expert</map>
<map code="fac">Facsimilist</map>
<map code="fds">Film distributor</map>
<map code="fld">Field director</map>
<map code="flm">Film editor</map>
<map code="fmd">Film director</map>
<map code="fmk">Filmmaker</map>
<map code="fmo">Former owner</map>
<map code="fmp">Film producer</map>
<map code="fnd">Funder</map>
<map code="fpy">First party</map>
<map code="frg">Forger</map>
<map code="gis">Geographic information specialist</map>
<map code="his">Host institution</map>
<map code="hnr">Honoree</map>
<map code="hst">Host</map>
<map code="ill">Illustrator</map>
<map code="ilu">Illuminator</map>
<map code="ins">Inscriber</map>
<map code="inv">Inventor</map>
<map code="isb">Issuing body</map>
<map code="itr">Instrumentalist</map>
<map code="ive">Interviewee</map>
<map code="ivr">Interviewer</map>
<map code="jud">Judge</map>
<map code="jug">Jurisdiction governed</map>
<map code="lbr">Laboratory</map>
<map code="lbt">Librettist</map>
<map code="ldr">Laboratory director</map>
<map code="led">Lead</map>
<map code="lee">Libelee-appellee</map>
<map code="lel">Libelee</map>
<map code="len">Lender</map>
<map code="let">Libelee-appellant</map>
<map code="lgd">Lighting designer</map>
<map code="lie">Libelant-appellee</map>
<map code="lil">Libelant</map>
<map code="lit">Libelant-appellant</map>
<map code="lsa">Landscape architect</map>
<map code="lse">Licensee</map>
<map code="lso">Licensor</map>
<map code="ltg">Lithographer</map>
<map code="lyr">Lyricist</map>
<map code="mcp">Music copyist</map>
<map code="mdc">Metadata contact</map>
<map code="med">Medium</map>
<map code="mfp">Manufacture place</map>
<map code="mfr">Manufacturer</map>
<map code="mod">Moderator</map>
<map code="mon">Monitor</map>
<map code="mrb">Marbler</map>
<map code="mrk">Markup editor</map>
<map code="msd">Musical director</map>
<map code="mte">Metal-engraver</map>
<map code="mtk">Minute taker</map>
<map code="mus">Musician</map>
<map code="nrt">Narrator</map>
<map code="opn">Opponent</map>
<map code="org">Originator</map>
<map code="orm">Organizer</map>
<map code="osp">Onscreen presenter</map>
<map code="oth">Other</map>
<map code="own">Owner</map>
<map code="pan">Panelist</map>
<map code="pat">Patron</map>
<map code="pbd">Publishing director</map>
<map code="pbl">Publisher</map>
<map code="pdr">Project director</map>
<map code="pfr">Proofreader</map>
<map code="pht">Photographer</map>
<map code="plt">Platemaker</map>
<map code="pma">Permitting agency</map>
<map code="pmn">Production manager</map>
<map code="pop">Printer of plates</map>
<map code="ppm">Papermaker</map>
<map code="ppt">Puppeteer</map>
<map code="pra">Praeses</map>
<map code="prc">Process contact</map>
<map code="prd">Production personnel</map>
<map code="pre">Presenter</map>
<map code="prf">Performer</map>
<map code="prg">Programmer</map>
<map code="prm">Printmaker</map>
<map code="prn">Production company</map>
<map code="pro">Producer</map>
<map code="prp">Production place</map>
<map code="prs">Production designer</map>
<map code="prt">Printer</map>
<map code="prv">Provider</map>
<map code="pta">Patent applicant</map>
<map code="pte">Plaintiff-appellee</map>
<map code="ptf">Plaintiff</map>
<map code="pth">Patent holder</map>
<map code="ptt">Plaintiff-appellant</map>
<map code="pup">Publication place</map>
<map code="rbr">Rubricator</map>
<map code="rcd">Recordist</map>
<map code="rce">Recording engineer</map>
<map code="rcp">Addressee</map>
<map code="rdd">Radio director</map>
<map code="red">Redaktor</map>
<map code="ren">Renderer</map>
<map code="res">Researcher</map>
<map code="rev">Reviewer</map>
<map code="rpc">Radio producer</map>
<map code="rps">Repository</map>
<map code="rpt">Reporter</map>
<map code="rpy">Responsible party</map>
<map code="rse">Respondent-appellee</map>
<map code="rsg">Restager</map>
<map code="rsp">Respondent</map>
<map code="rsr">Restorationist</map>
<map code="rst">Respondent-appellant</map>
<map code="rth">Research team head</map>
<map code="rtm">Research team member</map>
<map code="sad">Scientific advisor</map>
<map code="sce">Scenarist</map>
<map code="scl">Sculptor</map>
<map code="scr">Scribe</map>
<map code="sds">Sound designer</map>
<map code="sec">Secretary</map>
<map code="sgd">Stage director</map>
<map code="sgn">Signer</map>
<map code="sht">Supporting host</map>
<map code="sll">Seller</map>
<map code="sng">Singer</map>
<map code="spk">Speaker</map>
<map code="spn">Sponsor</map>
<map code="spy">Second party</map>
<map code="srv">Surveyor</map>
<map code="std">Set designer</map>
<map code="stg">Setting</map>
<map code="stl">Storyteller</map>
<map code="stm">Stage manager</map>
<map code="stn">Standards body</map>
<map code="str">Stereotyper</map>
<map code="tcd">Technical director</map>
<map code="tch">Teacher</map>
<map code="ths">Thesis advisor</map>
<map code="tld">Television director</map>
<map code="tlp">Television producer</map>
<map code="trc">Transcriber</map>
<map code="trl">Translator</map>
<map code="tyd">Type designer</map>
<map code="tyg">Typographer</map>
<map code="uvp">University place</map>
<map code="vac">Voice actor</map>
<map code="vdg">Videographer</map>
<map code="wac">Writer of added commentary</map>
<map code="wal">Writer of added lyrics</map>
<map code="wam">Writer of accompanying material</map>
<map code="wat">Writer of added text</map>
<map code="wdc">Woodcutter</map>
<map code="wde">Wood engraver</map>
<map code="win">Writer of introduction</map>
<map code="wit">Witness</map>
<map code="wpr">Writer of preface</map>
<map code="wst">Writer of supplementary textual content</map>
</xsl:variable>
<xsl:variable name="matchinglabel" as="xs:string?" select="$rolesmapping//text()[../@code = lower-case($rolecode)]"/>
<xsl:if test="exists($matchinglabel)">
<xsl:value-of select="$matchinglabel"/>
</xsl:if>
</xsl:function>
<xsl:function name="bod:standardText">
<xsl:param name="textval" as="xs:string"/>
<xsl:choose>
<xsl:when test="$textval = (
'Physical Description',
'Contents',
'History',
'Record Sources',
'Language(s):',
'Support:',
'Origin:',
'Form:',
'Additional Information',
'Funding of Cataloguing'
)">
<xsl:processing-instruction name="ni"/>
<xsl:value-of select="$textval"/>
<xsl:processing-instruction name="ni"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$textval"/>
</xsl:otherwise>
</xsl:choose>
</xsl:function>
<xsl:function name="bod:shortenToNearestWord" as="xs:string">
<xsl:param name="stringval" as="xs:string"/>
<xsl:param name="tolength" as="xs:integer"/>
<xsl:variable name="cutoffat" as="xs:integer" select="$tolength - 1"/>
<xsl:choose>
<xsl:when test="string-length($stringval) le $tolength">
<!-- Already short enough, so return unmodified -->
<xsl:value-of select="$stringval"/>
</xsl:when>
<xsl:when test="substring($stringval, $cutoffat, 1) = (' ', '	', ' ')">
<!-- The cut-off is at the location of some whitespace, so won't be cutting off any words -->
<xsl:value-of select="concat(normalize-space(substring($stringval, 1, $cutoffat)), '…')"/>
</xsl:when>
<xsl:when test="substring($stringval, $tolength, 1) = (' ', '	', ' ')">
<!-- The cut-off is at the end of a word, so won't be cutting off any words -->
<xsl:value-of select="concat(substring($stringval, 1, $cutoffat), '…')"/>
</xsl:when>
<xsl:otherwise>
<!-- The cut-off is in the middle of a word, so return everything up to the preceding word -->
<xsl:value-of select="concat(replace(substring($stringval, 1, $cutoffat), '\s\S*$', ''), '…')"/>
</xsl:otherwise>
</xsl:choose>
</xsl:function>
<xsl:function name="bod:direction" as="attribute()?">
<xsl:param name="elem" as="element()?"/>
<!-- This funtion returns a HTML style attribute if the TEI element has a @xml:lang
specifying the script, as per BCP 47, is right-to-left (eg. "ar-Arab" or "per-Arab-x-lc"),
or if over half the characters within match a known right-to-left script, unless it contains
a foreign TEI element, indicating the contents are split between multiple scripts -->
<xsl:variable name="langcode" as="xs:string?" select="$elem/@xml:lang"/>
<xsl:variable name="stringval" as="xs:string" select="normalize-space($elem/string())"/>
<xsl:if test="not($elem//foreign or matches($langcode, '[^\-]+\-Latn', 'i')) and (
matches($langcode, '[^\-]+\-(Adlm|Arab|Aran|Armi|Avst|Cprt|Egyd|Egyh|Hatr|Hebr|Hung|Inds|Khar|Lydi|Mand|Mani|Mend|Merc|Mero|Narb|Nbat|Nkoo|Orkh|Palm|Phli|Phlp|Phlv|Phnx|Prti|Rohg|Samr|Sarb|Sogd|Sogo|Syrc|Syre|Syrj|Syrn|Thaa|Wole)', 'i')
or string-length(replace($stringval, '[؀-ۿﹰ-𐬀-𐬿֑-״܀-ݏࡠ-࡯]', '')) lt string-length($stringval) div 2
)">
<!-- NOTE: The match against the language code above uses a list of codes for right-to-left
scripts taken from: https://en.wikipedia.org/wiki/ISO_15924#List_of_codes -->
<!-- NOTE: If all the ranges for Arabic symbols then this would make anything with a number
display as right-to-left. The above should be sufficient to cover most cases. -->
<!-- TODO: Add more unicode ranges for non-Middle-Eastern R-T-L scripts? -->
<xsl:attribute name="style" select="'direction:rtl; display:inline-block;'"/>
</xsl:if>
</xsl:function>
<xsl:function name="bod:doDisplayItemNumber" as="xs:boolean">
<xsl:param name="msitem" as="element(msItem)"/>
<!-- Decide whether to display the numbering on an msItem, based on the presence of other msItems in the same record,
which (hopefully) form a sequence. When the msItems are split across multiple msPart, the numbering may or may not
restart for each part, but avoid every item being pointlessly numbered "1" (or "A" or "i") when there is one item per part. -->
<xsl:variable name="level" as="xs:integer" select="count($msitem/ancestor::*)"/>
<xsl:variable name="num" as="xs:string?" select="$msitem/@n"/>
<xsl:variable name="itemsatsamelevel" as="element(msItem)*" select="($msitem/preceding::msItem, $msitem/following::msItem)[count(ancestor::*) eq $level and string-length(@n) gt 0 and not(@n = 'toc')]"/>
<xsl:value-of select="boolean(
string-length($num) gt 0
and not($num = 'toc')
and (
count($msitem/parent::*/msItem[string-length(@n) gt 0 and not(@n = 'toc')]) gt 1
or (
count($itemsatsamelevel) gt 0
and not(every $otheritem in $itemsatsamelevel satisfies $otheritem/@n = $num)
)
)
)"/>
</xsl:function>
<!-- Named template which is called from command line
to batch convert all manuscript TEI files to HTML -->
<xsl:template name="batch">
<!-- Set up the collection of files to be converted. The path must be supplied in batch mode, and must be a full
path because this stylesheet is normally imported by convert2HTML.xsl via a URL. -->
<xsl:variable name="path">
<xsl:choose>
<xsl:when test="starts-with($collections-path, '/')">
<!-- UNIX-like systems -->
<xsl:value-of select="concat('file://', $collections-path, '/?select=', $files, ';on-error=warning;recurse=', $recurse)"/>
</xsl:when>
<xsl:when test="matches($collections-path, '[A-Z]:/')">
<!-- Git Bash on Windows -->
<xsl:value-of select="concat('file:///', $collections-path, '/?select=', $files, ';on-error=warning;recurse=', $recurse)"/>
</xsl:when>
<xsl:when test="matches($collections-path, '[A-Z]:\\')">
<!-- Windows -->
<xsl:value-of select="concat('file:///', replace($collections-path, '\\', '/'), '/?select=', $files, ';on-error=warning;recurse=', $recurse)"/>
</xsl:when>
<xsl:otherwise>
<xsl:copy-of select="bod:logging('error', 'A full path to the collections folder containing source TEI must be specified', .)"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<!-- For each item in the collection -->
<xsl:for-each select="collection($path)">
<xsl:choose>
<xsl:when test="string-length(/TEI/@xml:id/string()) eq 0">
<!-- Cannot do anything if there is no @xml:id on the root TEI element -->
<xsl:copy-of select="bod:logging('warn', 'Cannot process manuscript without @xml:id for root TEI element', /TEI, base-uri())"/>
</xsl:when>
<xsl:otherwise>
<!-- Build HTML in a variable so it can be post-processed to strip out undesirable HTML code -->
<xsl:variable name="outputdoc" as="element()">
<xsl:choose>
<xsl:when test="$output-full-html">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
<div class="content tei-body" id="{/TEI/@xml:id}">
<xsl:call-template name="Header"/>
<xsl:apply-templates select="/TEI/teiHeader/fileDesc/sourceDesc/msDesc"/>
<xsl:call-template name="Funding"/>
<xsl:call-template name="AbbreviationsKey"/>
<xsl:call-template name="Footer"/>
</div>
</body>
</html>
</xsl:when>
<xsl:otherwise>
<div>
<div class="content tei-body" id="{/TEI/@xml:id}">
<xsl:call-template name="Header"/>
<xsl:apply-templates select="/TEI/teiHeader/fileDesc/sourceDesc/msDesc"/>
<xsl:call-template name="Funding"/>
<xsl:call-template name="AbbreviationsKey"/>
<xsl:call-template name="Footer"/>
</div>
</div>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<!-- Create output HTML files -->
<xsl:variable name="subfolders" select="tokenize(substring-after(base-uri(.), $collections-path), '/')[position() ne last()]"/>
<xsl:variable name="outputpath" select="concat('./html/', string-join($subfolders, '/'), '/', /TEI/@xml:id/string(), '.html')"/>
<xsl:result-document href="{$outputpath}" method="xhtml" encoding="UTF-8" indent="yes">
<!-- Applying templates on the HTML already built, with a mode, to strip out undesirable HTML code -->
<xsl:apply-templates select="$outputdoc" mode="stripoutempty"/>
</xsl:result-document>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:template>
<!-- These next templates act on HTML already generated from the source TEI, as a post-processing phase to strip out
empty elements. These can confuse web browsers (whose parsers assume that, for example, an empty div element
was someone's handcoded mistake and ignores the closing div tag) causing display issues especially in IE/Edge -->
<xsl:template match="*" mode="stripoutempty">
<xsl:if test="child::* or text() or processing-instruction() or local-name() = ('img', 'br', 'hr', 'title')">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:apply-templates mode="stripoutempty"/>
</xsl:copy>
</xsl:if>
</xsl:template>
<xsl:template match="text()|processing-instruction()|comment()" mode="stripoutempty"><xsl:copy/></xsl:template>
<!-- These named templates are intentionally left empty. They can be overridden by
convert2HTML.xsl stylesheets to add a special footer for each TEI catalogue. The
hooks which call them are in other templates above and below in this stylesheet.-->
<xsl:template name="Header"></xsl:template>
<xsl:template name="Footer"></xsl:template>
<xsl:template name="AdditionalContent"></xsl:template>
<xsl:template name="MsItemFooter"></xsl:template>
<xsl:template name="AbbreviationsKey">
<xsl:variable name="abbrmapping" as="element()*">
<xsl:for-each select="//choice[abbr and expan]/abbr">
<map code="{ normalize-space(./string()) }">
<xsl:apply-templates select="parent::choice/expan[1]"/>
</map>
</xsl:for-each>
</xsl:variable>
<xsl:if test="count($abbrmapping) gt 0">
<h3>Key to Abbreviations</h3>
<ul>
<xsl:for-each select="distinct-values($abbrmapping/@code[string-length(.) gt 0])">
<xsl:sort select="."/>
<li>
<u>
<xsl:value-of select="."/>
</u>
<xsl:text>: </xsl:text>
<xsl:copy-of select="$abbrmapping[@code = current()][1]"/>
</li>
</xsl:for-each>
</ul>
</xsl:if>
</xsl:template>
<!-- Named template for displaying funders (of the cataloguing, funders of acquisition
are in history section) -->
<xsl:template name="Funding">
<xsl:if test="//teiHeader/fileDesc//funder">
<div class="funding">
<!-- Logos, if any, displayed floating on the right -->
<xsl:if test="//teiHeader/fileDesc//funder//orgName//graphic/@url">
<div style="float:right; padding-left:2em; padding-bottom:1em; max-width:50%; text-align:right;">
<xsl:for-each select="//teiHeader/fileDesc//funder//orgName[.//graphic/@url]">
<xsl:variable name="logourl" select="(.//graphic/@url)[1]"/>
<xsl:variable name="linkurl" select="(.//ref/@target)[1]"/>
<xsl:choose>
<xsl:when test="$linkurl">
<a href="{ $linkurl }" target="_blank">
<img src="{ $logourl }" width="200" style="display:inline-block; margin-right:1em; margin-bottom:1em; vertical-align:middle;"/>
</a>
</xsl:when>
<xsl:otherwise>
<img src="{ $logourl }" width="200" style="display:inline-block; margin-right:1em; margin-bottom:1em; vertical-align:middle;"/>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</div>
</xsl:if>
<!-- Display funder(s) text -->
<h3>
<xsl:copy-of select="bod:standardText('Funding of Cataloguing')"/>
</h3>
<xsl:for-each select="//teiHeader/fileDesc//funder">
<p>
<xsl:apply-templates/>
</p>
</xsl:for-each>
</div>
</xsl:if>
</xsl:template>
<!-- Actual TEI-to-HTML templates below -->
<xsl:template match="titleStmt/title">
<li class="title">
<span class="tei-label">
<xsl:copy-of select="bod:standardText('Title:')"/>
<xsl:text> </xsl:text>
</span>
<xsl:apply-templates/>
<xsl:if test="@type">(<xsl:value-of select="@type"/>)
</xsl:if>
</li>
</xsl:template>
<xsl:template match="title">
<span class="{name()} italic">
<xsl:apply-templates/>
</span>
</xsl:template>
<xsl:template match="series">
<span class="{name()}">
<xsl:apply-templates/>
</span>
</xsl:template>
<xsl:template match="citedRange">
<span class="{name()}">
<xsl:apply-templates/>
</span>
</xsl:template>
<xsl:template match="corr">
<span class="{name()}">
<xsl:apply-templates/>
</span>
</xsl:template>
<xsl:template match="date">
<span class="{name()}">
<xsl:if test="@when">
<xsl:attribute name="title">
<xsl:value-of select="@when"/>
</xsl:attribute>
</xsl:if>
<xsl:apply-templates/>
</span>
</xsl:template>
<xsl:template match="add">
<ins class="{@place}">
<xsl:choose>
<xsl:when test="@place = 'above'">
<xsl:text>^</xsl:text>
<xsl:apply-templates/>
<xsl:text>^</xsl:text>
</xsl:when>
<xsl:when test="@place = 'margin'">
<xsl:text>\</xsl:text>
<xsl:apply-templates/>
<xsl:text>/</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>\</xsl:text>
<xsl:apply-templates/>
<xsl:text>/</xsl:text>
</xsl:otherwise>
</xsl:choose>
</ins>
</xsl:template>
<xsl:template match="del">
<del>
<xsl:apply-templates/>
</del>
</xsl:template>
<xsl:template match="note">
<span class="{name()}">
<xsl:apply-templates/>
</span>
</xsl:template>
<xsl:template match="adminInfo/note">
<div class="{name()}" style="margin-top:1rem;">
<xsl:apply-templates/>
</div>
</xsl:template>
<xsl:template match="foreign">
<xsl:text> </xsl:text>
<span class="{name()} {@rend}">
<xsl:copy-of select="bod:direction(.)"/>
<xsl:apply-templates/>
</span>
<xsl:text> </xsl:text>
</xsl:template>
<xsl:template match="sic[parent::choice and (child::* or text())]">
<span class="{name()}">
<xsl:apply-templates/>
</span>
</xsl:template>
<xsl:template match="sic[not(parent::choice) and (child::* or text())]">
<span class="{name()}">
<xsl:apply-templates/>
<xsl:text>[</xsl:text>
<i>
<xsl:text>sic</xsl:text>
</i>
<xsl:text>]</xsl:text>
</span>
</xsl:template>
<xsl:template match="sic[not(child::* or text())]">
<!-- For self-closing sic tags just output a "[sic]" marker -->
<xsl:text>[</xsl:text>
<i>
<xsl:text>sic</xsl:text>
</i>
<xsl:text>]</xsl:text>
</xsl:template>
<xsl:template match="supplied">
<span class="supplied">
<xsl:text>⟨</xsl:text>
<xsl:apply-templates/>
<xsl:text>⟩</xsl:text>
</span>
</xsl:template>
<xsl:template match="choice[sic and corr]">
<span class="sicAndCorr">
<xsl:apply-templates select="sic"/>
<xsl:text> [</xsl:text>
<i>
<xsl:text>sic for </xsl:text>
</i>
<xsl:apply-templates select="corr"/>
<xsl:text>]</xsl:text>
</span>
</xsl:template>
<xsl:template match="choice[sic and not(corr)]">
<span class="sicAndNotCorr">
<xsl:apply-templates select="sic"/>
<xsl:text>[</xsl:text>
<i>sic</i>
<xsl:text>]</xsl:text>
</span>
</xsl:template>
<xsl:template match="choice[abbr and expan]">
<abbr title="{expan/string()}" style="cursor:default;">
<xsl:apply-templates select="*[not(self::expan)]"/>
</abbr>
</xsl:template>
<xsl:template match="choice[expan]/abbr">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="abbr[not(parent::choice)]">
<xsl:variable name="expansion" as="xs:string*" select="(//choice[abbr[normalize-space(string()) = normalize-space(string(current()))]]/expan/string())[1]"/>
<abbr style="cursor:default;">
<xsl:if test="$expansion">
<xsl:attribute name="title" select="$expansion"/>
</xsl:if>
<xsl:apply-templates/>
</abbr>
</xsl:template>
<!-- rendering for damage element; same as for supplied: is that OK? -->
<xsl:template match="damage">
<span class="damage">
<xsl:text>⟨</xsl:text>
<xsl:apply-templates/>
<xsl:text>⟩</xsl:text>
</span>
</xsl:template>
<xsl:template match="unclear">
<span class="unclear">
<xsl:apply-templates/>
<span class="unclearMarker">(?)</span>
</span>
</xsl:template>
<xsl:template match="gap">
<span class="gap">…</span>
</xsl:template>
<xsl:template match="gap[@reason='editorial']">
<span class="editorialgap"> […] </span>
</xsl:template>
<xsl:template match="gap[@reason='blank']">
<span class="blankgap"> [<i>left blank</i>] </span>
</xsl:template>
<xsl:template match="gap[@unit='char' and number(@quantity)]">
<xsl:variable name="possibleDots">
.....................................................................................................................
</xsl:variable>
<span class="gap">
<xsl:value-of select="substring(normalize-space($possibleDots), 1, number(@quantity))"/>
</span>
</xsl:template>
<xsl:template match="gap[@unit='char' and number(@extent)]">
<xsl:variable name="possibleDots">
.....................................................................................................................
</xsl:variable>
<span class="gap">
<xsl:value-of select="substring(normalize-space($possibleDots), 1, number(@extent))"/>
</span>
</xsl:template>
<xsl:template match="expan | ex">
<!-- was: class = expan, changed 6.11.17 to better match TEI guidelines. ex=parts of words. -->
<!-- TODO: Split this into two templates for expan used in contexts where it is not inline? -->
<span class="ex">(<xsl:apply-templates/>)</span>
</xsl:template>
<!-- editions -->
<xsl:template match="editionStmt/edition">
<li class="title">
<span class="tei-label">
<xsl:copy-of select="bod:standardText('Edition:')"/>
<xsl:text> </xsl:text>
</span>
<xsl:apply-templates/>
<xsl:if test="@type">(<xsl:value-of select="@type"/>)
</xsl:if>
</li>
</xsl:template>
<!-- responsibility and revisions -->
<xsl:template match="respStmt">
<li class="respStmt">
<xsl:apply-templates select="resp"/>
<xsl:if test="persName">(<xsl:value-of select="persName"/>)
</xsl:if>
</li>
</xsl:template>
<xsl:template match="resp">
<span class="{name()}">
<xsl:apply-templates/>
</span>
</xsl:template>
<xsl:template match="revisionDesc">
<li class="revisionDesc">
<ul class="revisionDesc">
<xsl:apply-templates/>
</ul>
</li>
</xsl:template>
<xsl:template match="revisionDesc//change">
<li class="change">
<span class="tei-label">
<xsl:copy-of select="bod:standardText('Change:')"/>
<xsl:text> </xsl:text>
</span>
<xsl:if test="@when">
<span class="date">
<xsl:value-of select="@when"/> --
</span>
</xsl:if>
<xsl:apply-templates/>
</li>
</xsl:template>
<xsl:template match="ref[@target]" priority="10">
<xsl:variable name="target" as="xs:string" select="normalize-space(@target)"/>
<xsl:choose>
<xsl:when test="starts-with($target, 'http') or starts-with($target, 'mailto') or starts-with($target, 'ftp')">
<!-- For valid-looking URLs create links to external resources -->
<a href="{$target}" target="_blank">
<xsl:apply-templates/>
</a>
</xsl:when>
<xsl:when test="starts-with($target, 'www')">
<!-- Assume if the protocol is missing that it is http (hopefully the destination server will redirect if https) -->
<a href="http://{$target}" target="_blank">
<xsl:apply-templates/>
</a>
</xsl:when>
<xsl:when test="contains(base-uri(.), 'hebrew-mss') or contains(base-uri(.), 'genizah-mss')">
<!-- In Hebrew and Genizah, anything that isn't a URL appears to be a classmark, sometimes with part numbers appended,
so as a TEMPORARY fix, convert them into links to search the catalogue -->
<a href="/?q={translate($target, '_#', ' ')}">
<xsl:apply-templates/>
<xsl:copy-of select="bod:logging('warn', 'Converting ref with unrecognized target into a search', ., $target)"/>
</a>
</xsl:when>
<xsl:when test="starts-with($target, '#')">