-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathPDF.xql
3491 lines (3231 loc) · 163 KB
/
PDF.xql
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
xquery version "3.1";
(:~
: This module based on the one provided in the shakespare example app
: produces a xslfo temporary object and passes it to FOP to produce a PDF
: @author Pietro Liuzzo
:)
declare namespace http = "http://expath.org/ns/http-client";
declare namespace fo = "http://www.w3.org/1999/XSL/Format";
declare namespace xslfo = "http://exist-db.org/xquery/xslfo";
declare namespace tei = "http://www.tei-c.org/ns/1.0";
declare namespace functx = "http://www.functx.com";
declare namespace s = "local.print";
declare namespace map = "http://www.w3.org/2005/xpath-functions/map";
declare namespace d = "betmas.domlib";
declare variable $local:BMappUrl := 'https://betamasaheft.eu/';
declare variable $local:settings := doc('settings.xml')/s:settings;
declare variable $local:catalogue := doc('driver.xml')/tei:teiCorpus;
declare variable $local:entries := $local:catalogue//tei:TEI;
declare variable $local:prefix := $local:settings//s:localPrefix;
declare variable $local:listPrefixDef := $local:catalogue//tei:listPrefixDef;
declare variable $local:Z := if($local:settings/s:zotero/text()) then $local:settings/s:zotero/text() else 'https://api.zotero.org/groups/358366/items' ;
declare variable $local:zstyle := if($local:settings/s:zstyle/text()) then $local:settings/s:zstyle/text() else 'hiob-ludolf-centre-for-ethiopian-studies' ;
(:the basis of transformation is a series of strings for components:)
declare variable $local:values as element(value)+ := (
<value num="1" char="I" />,
<value num="4" char="IV"/>,
<value num="5" char="V" />,
<value num="9" char="IX"/>,
<value num="10" char="X" />,
<value num="40" char="XL"/>,
<value num="50" char="L" />,
<value num="90" char="XC"/>,
<value num="100" char="C" />,
<value num="400" char="CD"/>,
<value num="500" char="D" />,
<value num="900" char="CM"/>,
<value num="1000" char="M" />
);
declare variable $local:domlib := doc('https://raw.githubusercontent.com/BetaMasaheft/BetMas/master/db/apps/lists/domlib.xml');
declare variable $local:bmeditors := doc('https://raw.githubusercontent.com/BetaMasaheft/BetMas/master/db/apps/lists/editors.xml')//tei:list ;
declare variable $local:title := fo:tei2fo($local:catalogue/tei:teiHeader//tei:titleStmt/tei:title);
(:return the concatenation of strings by continuous reduction:)
declare function local:n2roman ( $num as xs:integer ) as xs:string
{
(:as long as we have a number, keep going:)
if ( $num ) then
(:reduce by the largest number that has a string value:)
for $val in $local:values[@num <= $num][fn:last()] return
(:using the highest value:)
fn:concat( $val/@char,local:n2roman( $num - xs:integer( $val/@num
) ) )
(:nothing left:)
else ""
};
(:~ helper functx function, returning the index at which a substring starts :)
declare function functx:index-of-string( $arg as xs:string?, $substring as xs:string ) as xs:integer* {
if (contains($arg, $substring))
then (string-length(substring-before($arg, $substring))+1,
for $other in
functx:index-of-string(substring-after($arg, $substring),
$substring)
return
$other +
string-length(substring-before($arg, $substring)) +
string-length($substring))
else ()
} ;
declare function functx:index-of-node( $nodes as node()* ,
$nodeToFind as node() ) as xs:integer* {
for $seq in (1 to count($nodes))
return $seq[$nodes[$seq] is $nodeToFind]
} ;
declare function functx:capitalize-first($arg as xs:string?) as xs:string? {
concat(upper-case(substring($arg, 1, 1)),
substring($arg, 2))
};
declare function fo:editorName($ref) {
if(string-length($ref) != 2 ) then () else (
if($local:bmeditors//tei:item[@xml:id = $ref])
then $local:bmeditors//tei:item[@xml:id = $ref]/text() else string($ref)
)
};
declare function fo:printTitleID($ref as xs:string?) as xs:string?{
let $r := if(starts-with($ref, $local:BMappUrl)) then substring-after($ref, $local:BMappUrl) else $ref
return
json-doc(replace(concat($local:BMappUrl,'api/', replace($r, ':', '_'),'/title/json'), '\s', ''))?title
};
declare function fo:getFile($id){
let $r := if(starts-with($id, $local:BMappUrl)) then $local:BMappUrl else ($local:BMappUrl || $id)
return
doc( concat($r,'.xml'))
};
declare function fo:lang($lang as xs:string) {
switch ($lang)
case 'ar'
return
(attribute baseline-shift {'2pt'}, attribute font-size {'14pt'}, attribute font-family {'Scheherazade'}, attribute writing-mode {'rl'})
case 'so'
return
(attribute font-family {'coranica'}, attribute writing-mode {'rl'})
case 'aa'
return
(attribute font-family {'coranica'}, attribute writing-mode {'rl'})
case 'x-oh'
return
(attribute font-family {'coranica'}, attribute writing-mode {'rl'})
case 'he'
return
(attribute font-family {'Titus'}, attribute writing-mode {'rl'})
case 'syr'
return
(attribute font-family {'Titus'}, attribute writing-mode {'rl'})
case 'grc'
return
attribute font-family {'Cardo'}
case 'cop'
return
attribute font-family {'Titus'}
case 'gez'
return
(attribute font-family {'Ludolfus'}, attribute letter-spacing {'0.5pt'}, attribute font-size {'0.9em'})
case 'ti'
return
(attribute font-family {'Ludolfus'}, attribute letter-spacing {'0.5pt'}, attribute font-size {'0.9em'})
case 'amh'
return
(attribute font-family {'Ludolfus'}, attribute letter-spacing {'0.5pt'}, attribute font-size {'0.9em'})
case 'sa'
return
attribute font-family {'NotoSansDevanagari'}
default return
attribute font-family {'Ludolfus'}
};
declare function fo:entitiesWithRef($node) {
let $n := substring-after($node/@target, '#')
let $attid := string(root($node)/tei:TEI/@xml:id) || generate-id($node) || string($node/@ref)
return
<fo:inline id="{$attid}">{
if ($node/@target and not($node/text())) then
if (starts-with($node/@target, '#')) then
<fo:basic-link
internal-destination="{$n}">{$n}</fo:basic-link>
else
<fo:basic-link
external-destination="{$node/@target}"></fo:basic-link>
else if ($node/@target and $node/text()) then
<fo:basic-link external-destination="{$node/@target}">{fo:tei2fo($node/text())}</fo:basic-link>
else if ($node/@ref and $node/text()) then
fo:tei2fo($node/node())
else if ($node/text() or $node/tei:*) then
(
let $lang := if ($node/@xml:lang) then
$node/@xml:lang
else
$node/following-sibling::tei:textLang/@mainLang
return
if ($lang) then
fo:lang($lang)
else
(),
fo:tei2fo($node/node()))
else
if ($node/@ref) then
let $r := if(starts-with($node/@ref, $local:BMappUrl)) then string($node/@ref) else $local:BMappUrl ||
'/' || string($node/@ref)
let $t := if($node/node()) then fo:tei2fo($node/node()) else fo:printTitleID($node/@ref)
return
<fo:basic-link
external-destination="{$r}">{$t}</fo:basic-link>
else
'no title provided'
}</fo:inline>
};
declare function fo:entitiesWithRefNoID($node) {
let $n := substring-after($node/@target, '#')
return
<fo:inline>{
if ($node/@target and not($node/text())) then
if (starts-with($node/@target, '#')) then
<fo:basic-link
internal-destination="{$n}">{$n}</fo:basic-link>
else
<fo:basic-link
external-destination="{$node/@target}"></fo:basic-link>
else if ($node/@target and $node/text()) then
<fo:basic-link external-destination="{$node/@target}">{fo:tei2fo($node/text())}</fo:basic-link>
else if ($node/@ref and $node/text()) then
fo:tei2fo($node/node())
else if ($node/text() or $node/tei:*) then
(
let $lang := if ($node/@xml:lang) then
$node/@xml:lang
else
$node/following-sibling::tei:textLang/@mainLang
return
if ($lang) then
fo:lang($lang)
else
(),
fo:tei2fo($node/node()))
else if ($node/@ref) then
let $r := if(starts-with($node/@ref, $local:BMappUrl)) then string($node/@ref) else $local:BMappUrl ||
'/' || string($node/@ref)
let $t := if($node/node()) then fo:tei2fo($node/node()) else fo:printTitleID($node/@ref)
return
<fo:basic-link
external-destination="{$r}">{$t}</fo:basic-link>
else
'no title provided'
}</fo:inline>
};
declare function fo:ContentsTitle ($title){
(:
if tei:title[@xml:lang="gez"][@xml:id="t1"]
then
if tei:title[@xml:lang='en'][@corresp='#t1'][@type='main']
then
2) äthiopischer titel ja, englischer Titel keine Übersetzung vom äthiopischen,
tei:title[@xml:lang='en'][@corresp='#t1'][@type='main'] + ( tei:title[@xml:lang="gez"][@xml:id="t1"] )
e.g. Psalter (ዳዊት፡)
else
1) englischer titel Übersetzung vom äthiopischen,
" tei:title[@xml:lang='en'][@corresp='#t1'] " + ( tei:title[@xml:lang="gez"][@xml:id="t1"] )
e.g. “The Canticles of the Prophets” (መሓልየ፡ ነቢያት)
else
3) kein äthiopischer Titel, nur descriptiver englischer Titel
tei:title[@xml:lang='en']
e.g. On the length of the day during the months of the
year, CAe 5886
:)
let $tref := $title/@ref
return
if($tref) then
let $fullref := string($title/@ref)
let $incomplete := if($title/@type='incomplete') then ', incomplete' else ()
let $tigrinya := if ($title/following-sibling::tei:textLang[@mainLang!="gez"]
or $title/following-sibling::tei:textLang[@otherLangs])
then
let $languages := $title/ancestor::tei:TEI//tei:langUsage
let $ml := string($title/following-sibling::tei:textLang/@mainLang)
let $mlL := $languages/tei:language[@ident=$ml]/text()
let $ol := string($title/following-sibling::tei:textLang/@otherLangs)
let $olL := $languages/tei:language[@ident=$ol]/text()
return
', in '||$mlL||(if($olL) then (' and ' || $olL) else ()) else ()
let $ref := if (contains($fullref, '#')) then substring-before($fullref, '#') else $fullref
let $record := fo:getFile($ref)//tei:TEI
let $geeztitle := $record//tei:titleStmt/tei:title[@xml:lang="gez"][@xml:id][not(@type)][1]
let $gezid := '#'||string($geeztitle/@xml:id)
let $maintitleENgez := $record//tei:titleStmt/tei:title[@xml:lang='en'][@type='main']
let $titleENgez:= $record//tei:titleStmt/tei:title[@xml:lang='en'][@corresp = $gezid]
let $titleENNOgez:= $record//tei:titleStmt/tei:title[@xml:lang='en']
let $TITSEL := if($geeztitle) then (
if($maintitleENgez) then
string-join($maintitleENgez/text(), ' ')||' ('||string-join($geeztitle/text(), ' ')||')'
else
'‘' || string-join($titleENgez/text(), ' ')||'’' ||' ('||string-join($geeztitle/text(), ' ')||')'
) else
string-join($titleENNOgez/text(), ' ')
return
$TITSEL||$incomplete ||', CAe ' || substring($ref, 4,4) || $tigrinya || '.'
else $title/text()
};
declare function fo:zoteroCit($ZoteroUniqueBMtag as xs:string){
let $url := concat($local:Z,'?tag=', $ZoteroUniqueBMtag, '&include=citation&locale=en-GB&style=', $local:zstyle)
let $parseedZoteroApiResponse :=json-doc($url)
let $string:= '<inline xmlns="http://www.w3.org/1999/XSL/Format">' || replace($parseedZoteroApiResponse?1?citation, '<span>', '') => replace('</span>', '') => replace('</i>', '</inline>') =>replace('<i>', '<inline font-style="italic">') || '</inline>'
return
parse-xml($string)
};
declare function fo:Zotero($ZoteroUniqueBMtag as xs:string) {
let $data := concat($local:Z,'?tag=', $ZoteroUniqueBMtag, '&format=bib&locale=en-GB&style=', $local:zstyle,'&linkwrap=1')
let $datawithlink := fo:tei2fo(doc($data)//*:div[@class = 'csl-entry'])
return
$datawithlink
};
declare function fo:titleSelector($fullref){
let $ref := if (contains($fullref, '#')) then substring-before($fullref, '#') else $fullref
let $record := fo:getFile($ref)//tei:TEI
let $geeztitle := $record//tei:titleStmt/tei:title[@xml:lang="gez"][@xml:id][not(@type)][1]
let $gezid := '#'||string($geeztitle/@xml:id)
let $maintitleENgez := $record//tei:titleStmt/tei:title[@xml:lang='en'][@type='main']
let $titleENgez:= $record//tei:titleStmt/tei:title[@xml:lang='en'][@corresp = $gezid]
let $titleENNOgez:= $record//tei:titleStmt/tei:title[@xml:lang='en']
let $TITSEL := if($geeztitle) then (
if($maintitleENgez) then
string-join($maintitleENgez/text(), ' ')||' ('||string-join($geeztitle/text(), ' ')||')'
else
'“' || string-join($titleENgez/text(), ' ')||'”'||' ('||string-join($geeztitle/text(), ' ')||')'
) else
string-join($titleENNOgez/text(), ' ')
return
$TITSEL ||', CAe ' || substring($ref, 4,4)};
declare function fo:figDesc2fo($nodes as node()*) {
for $node in $nodes
return
typeswitch ($node)
case element(tei:placeName)
return fo:entitiesWithRefNoID($node)
case element(tei:persName)
return fo:entitiesWithRefNoID($node)
case element()
return
fo:tei2fo($node)
default
return
$node
};
declare function fo:tei2foSinRef($nodes as node()*) {
for $node in $nodes
return
typeswitch ($node)
case element(span)
return
<fo:inline>{if($node/@style[.="font-style:normal;"]) then attribute font-style {'normal'} else ()}{$node/text()}</fo:inline>
case element(tei:gap)
return
switch ($node/@reason)
case 'lost'
return <fo:inline>[...]</fo:inline>
case 'illegible'
return
<fo:inline><...></fo:inline>
case 'omitted'
return
<fo:inline>...</fo:inline>
case 'ellipsis'
return
if($node/parent::tei:q) then () else <fo:inline>(...)</fo:inline>
default return
<fo:inline>[- ca. {(string($node/@quantity) || ' ' || string($node/@unit))}{
if (xs:integer($node/@quantity) gt 1) then
's'
else
()
} -]</fo:inline>
case element(tei:del)
return
<fo:inline>[...]</fo:inline>
case element(tei:choice)
return
<fo:inline>{$node/tei:sic/text()} (!)</fo:inline>
case element(tei:sic)
return
<fo:inline>{$node/text()} (!)</fo:inline>
case element(tei:add)
return fo:tei2fo($node/node())
case element(tei:space)
return <fo:inline>[////]</fo:inline>
case element(tei:subst)
return '{' || string-join(fo:tei2fo($node/tei:add)) || '}'
case element(tei:supplied)
return
<fo:inline>[{fo:tei2fo($node/node())}]</fo:inline>
case element(tei:add)
return
fo:tei2fo($node/node())
case element(tei:handShift)
return
fo:tei2fo($node/node())
case element(tei:hi)
return
if($node/@rend='rubric') then fo:tei2fo($node/node()) else
if ($node/@rendition) then
switch($node/@rendition)
case 'simple:italic' return
<fo:inline
font-style='italic'>{fo:tei2fo($node/text())}</fo:inline>
case 'simple:bold' return
<fo:inline
font-weight='bold'>{fo:tei2fo($node/text())}</fo:inline>
case 'simple:smallcaps' return
<fo:inline
font-size="0.75em">{upper-case(fo:tei2fo($node/text()))}</fo:inline>
default return
<fo:inline>{fo:tei2fo($node/node())}</fo:inline>
else fo:tei2fo($node/node())
case element(tei:certainty)
return
<fo:inline>(?)</fo:inline>
case element(tei:persName)
return fo:tei2foSinRef($node/node())
case element(tei:placeName)
return fo:tei2foSinRef($node/node())
case element(tei:title)
return fo:tei2foSinRef($node/node())
case element()
return
fo:tei2fo($node/node())
default
return
$node
};
declare function fo:tei2fo($nodes as node()*) {
for $node in $nodes
return
typeswitch ($node)
case element(a)
return
<fo:basic-link
external-destination="{string($node/@href)}">{fo:tei2fo($node/text())}</fo:basic-link>
case element(i)
return
<fo:inline
font-style="italic">{fo:tei2fo($node/node())}</fo:inline>
case element(span)
return
<fo:inline>{if($node/@style[.="font-style:normal;"]) then attribute font-style {'normal'} else ()}{$node/text()}</fo:inline>
case element(tei:gap)
return
switch ($node/@reason)
case 'lost'
return <fo:inline>[...]</fo:inline>
case 'illegible'
return
<fo:inline><...></fo:inline>
case 'omitted'
return
<fo:inline>...</fo:inline>
case 'ellipsis'
return
if($node/parent::tei:q) then () else <fo:inline>(...)</fo:inline>
default return
<fo:inline>[- ca. {(string($node/@quantity) || ' ' || string($node/@unit))}{
if (xs:integer($node/@quantity) gt 1) then
's'
else
()
} -]</fo:inline>
case element(tei:del)
return
<fo:inline>[...]</fo:inline>
case element(tei:choice)
return
<fo:inline>{$node/tei:sic/text()} (!)</fo:inline>
case element(tei:sic)
return
<fo:inline>{$node/text()} (!)</fo:inline>
case element(tei:add)
return fo:tei2fo($node/node())
case element(tei:space)
return <fo:inline>[////]</fo:inline>
case element(tei:subst)
return '{' || string-join(fo:tei2fo($node/tei:add)) || '}'
case element(tei:supplied)
return
(:switch ($node/@reason)
case 'omitted'
return
<fo:inline><{fo:tei2fo($node/node())}></fo:inline>
case 'undefined'
return
<fo:inline>[{fo:tei2fo($node/node())} (?)]</fo:inline>
default return:)
<fo:inline>[{fo:tei2fo($node/node())}]</fo:inline>
case element(tei:add)
return
fo:tei2fo($node/node())
case element(tei:handShift)
return
fo:tei2fo($node/node())
case element(tei:hi)
return
if($node/@rend='rubric') then fo:tei2fo($node/node()) else
if ($node/@rendition) then
switch($node/@rendition)
case 'simple:italic' return
<fo:inline
font-style='italic'>{fo:tei2fo($node/text())}</fo:inline>
case 'simple:bold' return
<fo:inline
font-weight='bold'>{fo:tei2fo($node/text())}</fo:inline>
case 'simple:smallcaps' return
<fo:inline
font-size="0.75em">{upper-case(fo:tei2fo($node/text()))}</fo:inline>
default return
<fo:inline>{fo:tei2fo($node/node())}</fo:inline>
else fo:tei2fo($node/node())
case element(tei:certainty)
return
<fo:inline>(?)</fo:inline>
case element(tei:foliation)
return
fo:tei2fo($node/node())
case element(tei:note)
return
let $root := root($node)
let $notes := $root//tei:note
let $n := count($node/preceding::tei:note) +1
return
<fo:footnote>
<fo:inline
font-size="7pt"
vertical-align="text-top">{$n}</fo:inline>
<fo:footnote-body text-align="justify" text-indent="0">
<fo:list-block>
<fo:list-item>
<fo:list-item-label>
<fo:block >
<fo:inline
vertical-align="text-top"
font-size="9pt"
>{$n}</fo:inline>
</fo:block>
</fo:list-item-label>
<fo:list-item-body>
<fo:block
hyphenate="true"
space-before="0.45cm"
font-size="9pt"
line-height="11pt"
margin-left="0.45cm"
>
{fo:tei2fo($node/node())}
</fo:block>
</fo:list-item-body>
</fo:list-item>
</fo:list-block>
</fo:footnote-body>
</fo:footnote>
case element(tei:p)
return
<fo:block
xml:lang="en"
hyphenate="true">{
if ($node/preceding-sibling::tei:p) then
(attribute text-indent {'0.43cm'})
else
()
}{fo:tei2fo($node/node())}</fo:block>
case element(tei:figure)
return
(: If your image is not dispalying well, remember to take a good screenshot and modify it to 300dpi.
if it does not fit to the page set the width attribute in the source file, as that is the one used to set the viewport size to which the image is adapted
:)
<fo:block
id="{string(root($node)/tei:TEI/@xml:id)}{$node/tei:graphic/@xml:id}{generate-id($node)}"
>
{for $g in $node/tei:graphic return
<fo:block-container height="85mm" >
<fo:block hyphenate="true" text-align="center" margin-top="3mm" margin-bottom="3mm" page-break-inside="avoid" page-break-after="avoid">
<fo:external-graphic
src="{if(starts-with($g/@url, 'http')) then
string($g/@url) else let $base := base-uri($node)
let $lastSlash := functx:index-of-string($base, '/')[last()]
return concat(substring($base, 1, $lastSlash), string($g/@url))}"
content-width="scale-down-to-fit"
width="90%"
scaling="uniform"
display-align="center"
/>
</fo:block>
<fo:block hyphenate="true" margin-bottom="0.3cm" font-size="smaller" margin-left="5mm" margin-right="5mm" page-break-before="avoid" text-align="center">
{
'Fig. ' || (count($g/preceding::tei:graphic) +1) || ' '}{fo:tei2fo($g/tei:desc)}
</fo:block>
</fo:block-container>
}
</fo:block>
case element(tei:signatures)
return
fo:tei2fo($node/node())
case element(tei:summary)
return
if($node/parent::tei:decoDesc) then fo:tei2fo($node/node())
else
()
case element(tei:seg)
return if($node/@part = 'I') then ('Incipit: ', fo:tei2fo($node/node()))
else if($node/@type='script') then fo:tei2fo($node/node())
else if($node/@type='supplication') then fo:tei2fo($node/node())
else ()
case element(tei:q)
return
if ($node/text()) then
<fo:inline>
{
if ($node/@xml:lang) then
fo:lang($node/@xml:lang)
else
()
}
{fo:tei2fo($node/node())}
</fo:inline>
else
let $nl := string($node/@xml:lang)
let $languages := root($node)//tei:langUsage
let $matchLang := $languages/tei:language[@ident = $nl]
return
<fo:block>Text in {$matchLang/text()}</fo:block>
case element(tei:place)
return
<fo:block
>({
for $pn in $node/tei:placeName
return
(<fo:inline>{fo:tei2fo($pn/text())}</fo:inline>,
<fo:inline
vertical-align="super"
font-size="8pt">{string($pn/@xml:lang)}</fo:inline>,
<fo:inline>
</fo:inline>)
};)
{fo:tei2fo($node/node()[not(name() = 'listBibl')][not(name() = 'placeName')][not(name() = 'location')])}
</fo:block>
case element(tei:person)
return
if (root($node)/tei:TEI/@type = 'pers') then
<fo:block
>( {
for $pn in $node/tei:persName
return
( <fo:inline>{fo:tei2fo($pn/node())}</fo:inline>,
<fo:inline
vertical-align="super"
font-size="8pt">{string($pn/@xml:lang)}
</fo:inline>)
} )
{fo:tei2fo($node/node()[not(name() = 'persName')])}
</fo:block>
else
fo:tei2fo($node/node())
case element(tei:list)
return
let $par := if($node/ancestor::tei:quote) then 1 else ()
return
<fo:list-block
provisional-distance-between-starts="6mm"
provisional-label-separation="6mm"
>
{attribute start-indent {((0.43 * (1 +count($node/ancestor::tei:list))) + $par) || "cm"}}
{fo:tei2fo($node/node())}
</fo:list-block>
case element(tei:item)
return
<fo:list-item>
<fo:list-item-label end-indent="label-end()">
<fo:block>
{<fo:inline>
{if($node/tei:label)
then fo:tei2fo($node/tei:label/node())
else
(let $upperalphabet := ('A', 'B', 'C', 'D', 'E', 'F', 'G', 'J', 'K', 'L')
let $loweralphabet := ('a', 'b', 'c', 'd', 'e', 'f', 'g', 'j', 'k', 'l')
let $romanUpper := ('I', 'II', 'III', 'IV', 'V', 'VI', 'VII', 'VIII', 'IX', 'X')
let $romanLower := ('i', 'ii', 'iii', 'iv', 'v', 'vi', 'vii', 'viii', 'ix', 'x')
let $position := count($node/preceding-sibling::tei:item) + 1
return
switch($node/parent::tei:list/@type)
case 'ordered:upperalpha' return $upperalphabet[$position]
case 'ordered:upperroman' return $romanUpper[$position]
case 'ordered:loweralpha' return $loweralphabet[$position]
case 'ordered:lowerroman' return $romanLower[$position]
default return $position
)
|| ')'}
</fo:inline>}
</fo:block>
</fo:list-item-label>
<fo:list-item-body start-indent="body-start()">
<fo:block hyphenate="true">{
fo:tei2fo($node/node())
}</fo:block>
</fo:list-item-body>
</fo:list-item>
case element(tei:listWit)
return
<fo:block margin-top="3mm"
>
<fo:block>{string($node/@rend)}</fo:block>
{fo:tei2fo($node/node())}
</fo:block>
case element(tei:witness)
return
<fo:block margin-bottom="2mm">{if($node/@xml:id) then <fo:inline font-weight="bold">{(string($node/@xml:id) || ': ')}</fo:inline> else ()} {if($node/@type = 'external') then <fo:basic-link
external-destination="{string($node/@facs)}" font-weight="bold">{string($node/@corresp)}</fo:basic-link> else fo:printTitleID(string($node/@corresp))}</fo:block>
case element(tei:titleStmt)
return
(<fo:block
id="{string(root($node)/tei:TEI/@xml:id)}{generate-id($node/tei:title)}"
font-size="12pt"
text-align="center"
font-weight='700'
margin-bottom="12.24pt"
margin-top="25.2pt">{fo:tei2fo($node/tei:title)}</fo:block>,
<fo:block
font-size="12pt"
text-align="center"
font-variant="small-caps"
margin-bottom="25pt">{string-join($node/tei:author/text(), ', ')}</fo:block>)
case element(tei:signed)
return
<fo:block text-align="right">{fo:tei2fo($node/text())}</fo:block>
case element(tei:date)
return
if ($node/text()) then fo:tei2fo($node/node())
else if ($node/@notBefore and $node/@notAfter) then
<fo:inline>{string($node/@notBefore) || '-' || string($node/@notAfter)}</fo:inline>
else if ($node/@when) then
<fo:inline>{string($node/@when)}</fo:inline>
else if ($node/@type = 'foundation')
then
<fo:inline>(Foundation: {fo:tei2fo($node/text())})</fo:inline>
else fo:tei2fo($node/node())
case element(tei:origDate)
return
if ($node/text()) then
<fo:inline> {if($node/@xml:lang) then fo:lang($node/@xml:lang) else ()}
{fo:tei2fo($node/node())}</fo:inline>
else if ($node/@notBefore and $node/@notAfter) then
<fo:inline> {if($node/@xml:lang) then fo:lang($node/@xml:lang) else ()}
{string($node/@notBefore) || '–' || string($node/@notAfter)}</fo:inline>
else if ($node/@when) then
<fo:inline>
{if($node/@xml:lang) then fo:lang($node/@xml:lang) else ()}
{string($node/@when)}</fo:inline>
else if ($node/@notBefore and not($node/@notAfter)) then
<fo:inline>
{if($node/@xml:lang) then fo:lang($node/@xml:lang) else ()}
{string($node/@notBefore)|| '–'}</fo:inline>
else if ($node/@notAfter and not($node/@notBefore)) then
<fo:inline>
{if($node/@xml:lang) then fo:lang($node/@xml:lang) else ()}
{'–'|| string($node/@notAfter)}</fo:inline>
else ()
case element(tei:label)
return
<fo:block>{fo:tei2fo($node/text())}</fo:block>
case element(tei:l)
return
(
<fo:inline
vertical-align="super"
font-size="8pt">{
if ($node/tei:ref) then
<fo:basic-link
external-destination="{string($node/tei:ref/@target)}">{string($node/@n)}</fo:basic-link>
else
string($node/@n)
}</fo:inline>,
fo:tei2fo($node/node())
)
case element(tei:listBibl)
return
<fo:block margin-top="5mm">
<fo:block margin-bottom="3mm" font-size="larger" font-weight="bold">{functx:capitalize-first(string($node/@type))} Bibliography</fo:block>
{if($node/tei:bibl) then
let $file := $node/ancestor::tei:TEI
for $b in $node/tei:bibl
let $z := fo:Zotero($b/tei:ptr/@target)
let $zt := substring(string-join($z),1,10)
order by $zt
return
if ($b/node()) then
<fo:block font-family="Titus"
start-indent="1cm"
text-indent="-1cm"> {$z}
{if($b/@corresp) then
let $corr := if (contains($b/@corresp, ' '))
then (for $x in tokenize($b/@corresp, ' ') return $x) else string($b/@corresp)
let $corresps := for $cor in $corr
return if (starts-with($cor, '#')) then substring-after($cor, '#') else $cor
let $correspsEl := for $c in $corresps
let $ref := $file//id($c)
return
(
(if($ref/text()) then fo:tei2fo($ref/text())
else if ($ref/name() = 'listWit') then
for $wit in $ref/tei:witness
let $i := string($wit/@corresp)
return
fo:printTitleID($i)
else if ($ref/name() = 'witness') then
let $i := string($ref/@corresp)
return
fo:printTitleID($i)
else concat($ref/name(), ' ', string($ref/@corresp)))
||
(if($ref/@xml:lang) then concat(' [', $file//tei:language[@ident = $ref/@xml:lang], ']') else ()))
return (' (about: ' ||
string-join($correspsEl, '; ')
|| ')'
) else ()}
</fo:block>
else
()
else fo:tei2fo($node/node())}
</fo:block>
case element(tei:bibl) return
let $rootid := string(root($node)/tei:TEI/@xml:id)
let $bibid := string($node/tei:ptr/@target)
return
<fo:basic-link internal-destination="{replace($bibid, ':', '_')}"><fo:inline id="{$rootid}{generate-id($node/tei:ptr)}{replace($bibid, ':', '_')}"> {
fo:zoteroCit($node/tei:ptr/@target)}
{if($node/tei:citedRange) then ', ' || (let $citRanges := for $cR in $node/tei:citedRange
let $unit := switch($cR/@unit)
case 'paragraph' return '§ '
case 'paragraphs' return '§§ '
case 'footnote' return 'n.'
case 'page' return ' '
default return (string($cR/@unit) || ' ')
return concat($unit, replace($cR/text(), '-', '–'))
return string-join($citRanges, ' '))
else ()}</fo:inline></fo:basic-link>
case element(tei:head)
return
<fo:block hyphenate="true" page-break-after="avoid"
id="{string(root($node)/tei:TEI/@xml:id)}{generate-id($node)}">
{
if ($node/parent::tei:div[@type = 'chapter']) then
(attribute font-weight {'700'},
attribute font-size {'12pt'},
attribute text-align {'center'},
attribute space-before {'25.2pt'},
attribute space-after {'12.24pt'})
else if ($node/parent::tei:div[@type = 'section']) then
(attribute font-weight {'700'},
attribute margin-top {'12.5pt'},
attribute margin-bottom {'6.25pt'})
else
if ($node/parent::tei:div[@type = 'subsection']) then
(attribute font-weight {'700'},
attribute margin-top {'12.5pt'},
attribute margin-bottom {'3.1pt'}
)
else
()
}
{
if ($node/parent::tei:div[@type = 'section'])
then
let $section := $node/parent::tei:div[@type = 'section'][tei:head]
let $parents := for $parent in $section/ancestor::tei:div
order by $parent/position() descending
return
count($parent/preceding-sibling::tei:div) + 1
return
concat(
string-join($parents, '.'),
'.',
count($section/preceding-sibling::tei:div[@type = 'section']) + 1
, ' ')
else
(: div type chapter:)
()
}
{$node/text()}
</fo:block>
case element(tei:div)
return
<fo:block hyphenate="true">{if($node/@xml:id) then attribute id {string(root($node)/tei:TEI/@xml:id)||'#'||string($node/@xml:id)} else ()}{fo:tei2fo($node/node())}</fo:block>
case element(tei:ab)
return
if ($node/@type = 'foundation') then
(<fo:block
font-size="1.2em"
space-before="2mm"
space-after="3mm">{functx:capitalize-first(string($node/@type))}</fo:block>,
<fo:block>{fo:tei2fo($node/node())}</fo:block>)
else
if ($node/@type = 'history') then
<fo:block>{fo:tei2fo($node/node())}</fo:block>
else
<fo:block linefeed-treatment="preserve">{fo:tei2fo($node/node()[not(name() = 'title')])}</fo:block>
case element(tei:lb)
return ()
case element(tei:desc)
return
<fo:inline>
{if($node/@xml:lang) then fo:lang($node/@xml:lang) else ()}
{fo:tei2fo($node/node())}
</fo:inline>
case element(tei:locus)
return
let $valandcomma :=
(
let $fF := if($node/preceding-sibling::text())
then
let $prevTextNode := $node/preceding-sibling::text()
let $clean := replace(string-join($prevTextNode), '\s', '')
return
if(matches($clean, '[^\.]$'))
then 'f'
else 'F'
else 'F'
let $fFornot := if(($node/preceding-sibling::element())[1]/name() = 'locus') then 'x'
else if(($node/following-sibling::element())[1]/name() = 'locus') then ( $fF || 'ols' )
else ( $fF || 'ol' )
let $value :=
( if ($node/@from and $node/@to)
then
(
if($fFornot = 'x') then () else
($fFornot ||
(if(ends-with($fFornot, 's')) then ' ' else 's ')
))
|| string($node/@from) || '–' || string($node/@to)
else
if ($node/@from) then
((if($fFornot = 'x') then () else ($fFornot||(if(ends-with($fFornot, 's')) then ' ' else 's ')))
|| string($node/@from || ' and following'))
else
if ($node/@target)
then
let $targets :=
if (contains($node/@target, ' '))
then
let $ts := for $t in tokenize($node/@target, ' ')
return substring-after($t, '#')
return
(if($fFornot = 'x') then () else ($fFornot||'s. '))
|| string-join($ts, ', ')
else