-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathcompile.xsl
1688 lines (1597 loc) · 78.8 KB
/
compile.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
<xslt:stylesheet version="1.0"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
xmlns:marc="http://www.loc.gov/MARC21/slim"
xmlns:bf="http://id.loc.gov/ontologies/bibframe/"
xmlns:bflc="http://id.loc.gov/ontologies/bflc/"
xmlns:madsrdf="http://www.loc.gov/mads/rdf/v1#"
xmlns:xslt="http://www.w3.org/1999/XSL/Transform"
xmlns:xsl="http://www.w3.org/1999/XSL/TransformAlias"
xmlns:bf2marc="http://www.loc.gov/bf2marc"
xmlns:local="http://example.org/local"
xmlns:exsl="http://exslt.org/common"
xmlns:xdmp="http://marklogic.com/xdmp"
exclude-result-prefixes="bf2marc">
<xslt:namespace-alias stylesheet-prefix="xsl" result-prefix="xslt"/>
<xslt:output encoding="UTF-8" method="xml" indent="yes"/>
<xslt:preserve-space elements="bf2marc:text"/>
<xslt:strip-space elements="*"/>
<xslt:template match="/">
<xsl:stylesheet version="1.0"
xmlns:exsl="http://exslt.org/common"
xmlns:date="http://exslt.org/dates-and-times"
xmlns:xdmp="http://marklogic.com/xdmp"
xmlns:fn="http://www.w3.org/2005/xpath-functions"
extension-element-prefixes="exsl date xdmp"
exclude-result-prefixes="fn rdf rdfs bf bflc madsrdf local">
<xsl:output encoding="UTF-8" method="xml" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:param name="pRecordId" select="'default'"/>
<xsl:param name="pCatScript" select="'Latn'"/>
<!-- parameters for 884 generation -->
<xsl:param name="pGenerationDatestamp">
<xsl:choose>
<xsl:when test="function-available('date:date-time')">
<xsl:value-of select="concat(translate(substring(date:date-time(),1,19),'-:T',''),'.0')"/>
</xsl:when>
<xsl:when test="function-available('fn:current-dateTime')">
<xsl:value-of select="concat(translate(substring(fn:current-dateTime(),1,19),'-:T',''),'.0')"/>
</xsl:when>
</xsl:choose>
</xsl:param>
<xsl:param name="pSourceRecordId"/>
<xsl:param name="pConversionAgency" select="'DLC'"/>
<xsl:param name="pGenerationUri" select="'https://github.com/lcnetdev/bibframe2marc'"/>
<xsl:param name="pSRULookup"/>
<!-- for upper- and lower-case translation (ASCII only) -->
<xsl:variable name="lower">abcdefghijklmnopqrstuvwxyz</xsl:variable>
<xsl:variable name="upper">ABCDEFGHIJKLMNOPQRSTUVWXYZ</xsl:variable>
<xsl:variable name="xslProcessor">
<!-- xsl:vendor, when compiled with xsltproc, works, meaning the output is xsl for elements and xsl:vendor and the tests pass. -->
<!-- xsl:vendor, when compiled with saxon, fails, meaning the output is xslt for elements and xsl for xsl:vendor and 'xsl' has not been defined. -->
<!-- xslt:vendor, when compiled with xsltproc, fails, meaning the output is xsl for elements and xslt for xslt:vendor. -->
<!-- xslt:vendor, when compiled with saxon, works, meaning he output is xslt for elements and xslt for xslt:vendor. Tests pass. -->
<xslt:choose>
<xslt:when test="system-property('xslt:vendor') = 'libxslt'">
<xsl:value-of select="system-property('xsl:vendor')" />
</xslt:when>
<xslt:otherwise>
<xsl:value-of select="system-property('xslt:vendor')" />
</xslt:otherwise>
</xslt:choose>
</xsl:variable>
<xslt:apply-templates/>
<!-- Conversion functions -->
<xsl:template name="tChopPunct">
<xsl:param name="pString"/>
<xsl:variable name="vNormString" select="normalize-space($pString)"/>
<xsl:variable name="vPunct" select="':;,/=–—'"/>
<xsl:variable name="vEndEnclose" select="')]}}"'"/>
<xsl:variable name="vLength" select="string-length($vNormString)"/>
<xsl:choose>
<xsl:when test="$vLength=0"/>
<xsl:when test="not($vNormString)"/>
<!-- remove enclosing characters -->
<xsl:when test="substring($vNormString,1,1) = '('">
<xsl:variable name="vCloseIndex">
<xsl:call-template name="tLastIndex">
<xsl:with-param name="pString" select="$vNormString"/>
<xsl:with-param name="pSearch" select="')'"/>
</xsl:call-template>
</xsl:variable>
<xsl:choose>
<xsl:when test="$vCloseIndex > 2">
<xsl:call-template name="tChopPunct">
<xsl:with-param name="pString" select="concat(substring($vNormString,2,$vCloseIndex - 2),substring($vNormString,$vCloseIndex+1))"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="tChopPunct">
<xsl:with-param name="pString" select="substring($vNormString,2)"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:when test="substring($vNormString,1,1) = '['">
<xsl:variable name="vCloseIndex">
<xsl:call-template name="tLastIndex">
<xsl:with-param name="pString" select="$vNormString"/>
<xsl:with-param name="pSearch" select="']'"/>
</xsl:call-template>
</xsl:variable>
<xsl:choose>
<xsl:when test="$vCloseIndex > 2">
<xsl:call-template name="tChopPunct">
<xsl:with-param name="pString" select="concat(substring($vNormString,2,$vCloseIndex - 2),substring($vNormString,$vCloseIndex+1))"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="tChopPunct">
<xsl:with-param name="pString" select="substring($vNormString,2)"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:when test="substring($vNormString,1,1) = '{{'">
<xsl:variable name="vCloseIndex">
<xsl:call-template name="tLastIndex">
<xsl:with-param name="pString" select="$vNormString"/>
<xsl:with-param name="pSearch" select="'}}'"/>
</xsl:call-template>
</xsl:variable>
<xsl:choose>
<xsl:when test="$vCloseIndex > 2">
<xsl:call-template name="tChopPunct">
<xsl:with-param name="pString" select="concat(substring($vNormString,2,$vCloseIndex - 2),substring($vNormString,$vCloseIndex+1))"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="tChopPunct">
<xsl:with-param name="pString" select="substring($vNormString,2)"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:when test="substring($vNormString,1,1) = '"'">
<xsl:variable name="vCloseIndex">
<xsl:call-template name="tLastIndex">
<xsl:with-param name="pString" select="$vNormString"/>
<xsl:with-param name="pSearch" select="'"'"/>
</xsl:call-template>
</xsl:variable>
<xsl:choose>
<xsl:when test="$vCloseIndex > 2">
<xsl:call-template name="tChopPunct">
<xsl:with-param name="pString" select="concat(substring($vNormString,2,$vCloseIndex - 2),substring($vNormString,$vCloseIndex+1))"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="tChopPunct">
<xsl:with-param name="pString" select="substring($vNormString,2)"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<!-- special handling for period -->
<!-- remove if there is other punctuation -->
<xsl:when test="substring($vNormString,$vLength,1) = '.'">
<xsl:choose>
<xsl:when test="contains(concat($vPunct,$vEndEnclose),substring($vNormString,$vLength - 1,1))">
<xsl:call-template name="tChopPunct">
<xsl:with-param name="pString" select="substring($vNormString,1,$vLength - 1)"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise><xsl:value-of select="$vNormString"/></xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:when test="contains($vPunct, substring($vNormString,$vLength,1))">
<xsl:call-template name="tChopPunct">
<xsl:with-param name="pString" select="substring($vNormString,1,$vLength - 1)"/>
</xsl:call-template>
</xsl:when>
<!-- remove end enclosing punctuation if start character is not in string -->
<xsl:when test="substring($vNormString,$vLength,1)=')' and not(contains($vNormString,'('))">
<xsl:call-template name="tChopPunct">
<xsl:with-param name="pString" select="substring($vNormString,1,$vLength - 1)"/>
</xsl:call-template>
</xsl:when>
<xsl:when test="substring($vNormString,$vLength,1)=']' and not(contains($vNormString,'['))">
<xsl:call-template name="tChopPunct">
<xsl:with-param name="pString" select="substring($vNormString,1,$vLength - 1)"/>
</xsl:call-template>
</xsl:when>
<xsl:when test="substring($vNormString,$vLength,1)='}}' and not(contains($vNormString,'{{'))">
<xsl:call-template name="tChopPunct">
<xsl:with-param name="pString" select="substring($vNormString,1,$vLength - 1)"/>
</xsl:call-template>
</xsl:when>
<xsl:when test="substring($vNormString,$vLength,1)='"' and not(contains($vNormString,'"'))">
<xsl:call-template name="tChopPunct">
<xsl:with-param name="pString" select="substring($vNormString,1,$vLength - 1)"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$vNormString"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="tLastIndex">
<xsl:param name="pString"/>
<xsl:param name="pSearch"/>
<xsl:choose>
<xsl:when test="$pSearch != '' and contains($pString,$pSearch)">
<xsl:variable name="vRevSearch">
<xsl:call-template name="tReverseString">
<xsl:with-param name="pString" select="$pSearch"/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="vRevString">
<xsl:call-template name="tReverseString">
<xsl:with-param name="pString" select="$pString"/>
</xsl:call-template>
</xsl:variable>
<xsl:value-of select="string-length($pString) - string-length(substring-before($vRevString,$vRevSearch))"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="tReverseString">
<xsl:param name="pString"/>
<xsl:variable name="vLength" select="string-length($pString)"/>
<xsl:choose>
<xsl:when test="$vLength < 2"><xsl:value-of select="$pString"/></xsl:when>
<xsl:when test="$vLength = 2">
<xsl:value-of select="concat(substring($pString,2,1),substring($pString,1,1))"/>
</xsl:when>
<xsl:otherwise>
<xsl:variable name="vMid" select="floor($vLength div 2)"/>
<xsl:variable name="vHalf1">
<xsl:call-template name="tReverseString">
<xsl:with-param name="pString" select="substring($pString,1,$vMid)"/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="vHalf2">
<xsl:call-template name="tReverseString">
<xsl:with-param name="pString" select="substring($pString,$vMid+1)"/>
</xsl:call-template>
</xsl:variable>
<xsl:value-of select="concat($vHalf2,$vHalf1)"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="tPadRight">
<xsl:param name="pInput"/>
<xsl:param name="pPadChar" select="' '"/>
<xsl:param name="pStringLength" />
<xsl:choose>
<xsl:when test="string-length($pInput) >= $pStringLength">
<xsl:value-of select="$pInput"/>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="tPadRight">
<xsl:with-param name="pInput" select="concat($pInput,$pPadChar)"/>
<xsl:with-param name="pPadChar" select="$pPadChar"/>
<xsl:with-param name="pStringLength" select="$pStringLength"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="tPadLeft">
<xsl:param name="pInput"/>
<xsl:param name="pPadChar" select="' '"/>
<xsl:param name="pStringLength" select="string-length($pInput)"/>
<xsl:choose>
<xsl:when test="string-length($pInput) >= $pStringLength">
<xsl:value-of select="$pInput"/>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="tPadLeft">
<xsl:with-param name="pInput" select="concat($pPadChar,$pInput)"/>
<xsl:with-param name="pPadChar" select="$pPadChar"/>
<xsl:with-param name="pStringLength" select="$pStringLength"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="tStringJoin">
<xsl:param name="pSeq" />
<xsl:param name="pJoinChar" select="', '" />
<xsl:for-each select="$pSeq">
<xsl:value-of select="." /><xsl:if test="position() != last()"><xsl:value-of select="$pJoinChar" /></xsl:if>
</xsl:for-each>
</xsl:template>
<xsl:template name="tEndsWith">
<xsl:param name="pStr" />
<xsl:param name="pEndChar" />
<xsl:choose>
<xsl:when test="substring($pStr, string-length($pStr)) = $pEndChar">1</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!-- EDTF functions -->
<!-- Extract first date from a range -->
<xsl:template name="EDTF-Date1">
<xsl:param name="pEDTFDate"/>
<xsl:choose>
<xsl:when test="contains($pEDTFDate,'/')">
<xsl:value-of select="substring-before($pEDTFDate,'/')"/>
</xsl:when>
<xsl:otherwise><xsl:value-of select="$pEDTFDate"/></xsl:otherwise>
</xsl:choose>
</xsl:template>
<!-- Extract second date from a range -->
<xsl:template name="EDTF-Date2">
<xsl:param name="pEDTFDate"/>
<xsl:value-of select="substring-after($pEDTFDate,'/')"/>
</xsl:template>
<!-- Extract date part from a single EDTF date -->
<!-- This will also work on ISO-8601 dates -->
<xsl:template name="EDTF-DatePart">
<xsl:param name="pEDTFDate"/>
<xsl:choose>
<xsl:when test="contains($pEDTFDate,'T')">
<xsl:value-of select="substring-before($pEDTFDate,'T')"/>
</xsl:when>
<xsl:otherwise><xsl:value-of select="$pEDTFDate"/></xsl:otherwise>
</xsl:choose>
</xsl:template>
<!-- Extract time part from a single EDTF date -->
<!-- This will also work on ISO-8601 dates -->
<xsl:template name="EDTF-TimePart">
<xsl:param name="pEDTFDate"/>
<xsl:choose>
<xsl:when test="contains(substring-after($pEDTFDate,'T'),'+')">
<xsl:value-of select="substring-before(substring-after($pEDTFDate,'T'),'+')"/>
</xsl:when>
<xsl:when test="contains(substring-after($pEDTFDate,'T'),'-')">
<xsl:value-of select="substring-before(substring-after($pEDTFDate,'T'),'-')"/>
</xsl:when>
<xsl:when test="contains(substring-after($pEDTFDate,'T'),'Z')">
<xsl:value-of select="substring-before(substring-after($pEDTFDate,'T'),'Z')"/>
</xsl:when>
<xsl:otherwise><xsl:value-of select="substring-after($pEDTFDate,'T')"/></xsl:otherwise>
</xsl:choose>
</xsl:template>
<!-- Extract time differential from a single EDTF date -->
<!-- This will also work on ISO-8601 dates -->
<xsl:template name="EDTF-TimeDiff">
<xsl:param name="pEDTFDate"/>
<xsl:choose>
<xsl:when test="contains(substring-after($pEDTFDate,'T'),'+')">
<xsl:value-of select="concat('+',substring-after(substring-after($pEDTFDate,'T'),'+'))"/>
</xsl:when>
<xsl:when test="contains(substring-after($pEDTFDate,'T'),'-')">
<xsl:value-of select="concat('-',substring-after(substring-after($pEDTFDate,'T'),'-'))"/>
</xsl:when>
<xsl:when test="contains(substring-after($pEDTFDate,'T'),'Z')">+00:00</xsl:when>
</xsl:choose>
</xsl:template>
<!-- Translate EDTF Level 1 date to 033/263 format -->
<!-- See https://www.loc.gov/standards/datetime/edtf.html -->
<!-- Template expects single dates, not ranges (the 033 expresses ranges as multiple single dates) -->
<xsl:template name="EDTF-to-033">
<xsl:param name="pEDTFDate"/>
<!-- Remove all qualifiers from EDTF date -->
<xsl:variable name="vEDTFDate" select="translate(translate(translate($pEDTFDate,'?',''),'~',''),'%','')"/>
<xsl:variable name="vDatePart">
<xsl:call-template name="EDTF-DatePart">
<xsl:with-param name="pEDTFDate" select="$vEDTFDate"/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="vTimePart">
<xsl:call-template name="EDTF-TimePart">
<xsl:with-param name="pEDTFDate" select="$vEDTFDate"/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="vTimeDiffPart">
<xsl:call-template name="EDTF-TimeDiff">
<xsl:with-param name="pEDTFDate" select="$vEDTFDate"/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="vYear">
<!-- Translate 'X' to '-' -->
<xsl:variable name="vYear033">
<xsl:choose>
<xsl:when test="contains($vDatePart,'-')">
<xsl:value-of select="translate(substring-before($vDatePart,'-'),'X','-')"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="translate($vDatePart,'X','-')"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:choose>
<!-- only support 4-digit, positive integer dates -->
<xsl:when test="starts-with($vYear033,'Y') or starts-with($vYear033,'-') or (string-length($vYear033) != 4)">
<xsl:text>----</xsl:text>
</xsl:when>
<xsl:otherwise><xsl:value-of select="$vYear033"/></xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="vMonth">
<!-- Translate 'X' to '-' -->
<xsl:variable name="vMonth033">
<xsl:choose>
<xsl:when test="substring-after(substring-after($vDatePart,'-'),'-') != ''">
<xsl:value-of select="translate(substring-before(substring-after($vDatePart,'-'),'-'),'X','-')"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="translate(substring-after($vDatePart,'-'),'X','-')"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:choose>
<!-- only support 2-digit months up to 12 (no seasons) -->
<xsl:when test="(string-length($vMonth033) != 2) or ($vMonth033 > 12)">
<xsl:text>--</xsl:text>
</xsl:when>
<xsl:otherwise><xsl:value-of select="$vMonth033"/></xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="vDay">
<!-- Translate 'X' to '-' -->
<xsl:variable name="vDay033" select="translate(substring-after(substring-after($vDatePart,'-'),'-'),'X','-')"/>
<xsl:choose>
<!-- only support 2-digit days up to 31 -->
<xsl:when test="(string-length($vDay033) != 2) or ($vDay033 > 31)">
<xsl:text>--</xsl:text>
</xsl:when>
<xsl:otherwise><xsl:value-of select="$vDay033"/></xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="vTime">
<xsl:if test="$vTimePart != ''">
<!-- Translate 'X' to '-', remove colons -->
<xsl:variable name="vTime033" select="translate(translate($vTimePart,'X','-'),':','')"/>
<xsl:choose>
<!-- only support 6-digits times (no other sanity check) -->
<xsl:when test="string-length($vTime033) = 6"><xsl:value-of select="$vTime033"/></xsl:when>
<xsl:otherwise>------</xsl:otherwise>
</xsl:choose>
</xsl:if>
</xsl:variable>
<xsl:variable name="vTimeDiff">
<xsl:if test="($vTimePart != '') and ($vTimeDiffPart != '')">
<!-- Translate 'X' to '-', remove colons -->
<xsl:variable name="vTimeDiff033" select="translate(translate($vTimeDiffPart,'X','-'),':','')"/>
<xsl:choose>
<!-- Needs to be 5 characters, pad with zeros on the right -->
<xsl:when test="string-length($vTimeDiff033) = 5"><xsl:value-of select="$vTimeDiff033"/></xsl:when>
<xsl:when test="string-length($vTimeDiff033) = 3">
<xsl:value-of select="concat($vTimeDiff033,'00')"/>
</xsl:when>
</xsl:choose>
</xsl:if>
</xsl:variable>
<xsl:value-of select="concat($vYear,$vMonth,$vDay,$vTime,$vTimeDiff)"/>
</xsl:template>
<!-- get the script code from an xml:lang attribute value -->
<xsl:template name="tScriptCode">
<xsl:param name="pXmlLang"/>
<xsl:if test="string-length($pXmlLang) >= 4">
<xsl:choose>
<xsl:when test="string-length($pXmlLang)=4 and translate(substring($pXmlLang,1,1),0123456789,'') != ''">
<xsl:value-of select="$pXmlLang"/>
</xsl:when>
<xsl:when test="string-length(substring-before($pXmlLang,'-'))=4 and translate(substring($pXmlLang,1,1),0123456789,'') != ''">
<xsl:value-of select="substring-before($pXmlLang,'-')"/>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="tScriptCode">
<xsl:with-param name="pXmlLang" select="substring-after($pXmlLang,'-')"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:if>
</xsl:template>
<!-- get the code (last element) from a URI -->
<xsl:template name="tUriCode">
<xsl:param name="pUri"/>
<xsl:choose>
<xsl:when test="contains($pUri,'://')">
<xsl:if test="contains(substring-after($pUri,'://'),'/')">
<xsl:call-template name="tUriCode">
<xsl:with-param name="pUri" select="substring-after($pUri,'://')"/>
</xsl:call-template>
</xsl:if>
</xsl:when>
<xsl:when test="contains($pUri,'/')">
<xsl:call-template name="tUriCode">
<xsl:with-param name="pUri" select="substring-after($pUri,'/')"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:choose>
<xsl:when test="contains($pUri,'?')">
<xsl:value-of select="substring-before($pUri,'?')"/>
</xsl:when>
<xsl:otherwise><xsl:value-of select="$pUri"/></xsl:otherwise>
</xsl:choose>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!-- generate marc:subfields by tokenizing a string -->
<xsl:template name="tToken2Subfields">
<xsl:param name="pString"/>
<xsl:param name="pSeparator" select="' '"/>
<xsl:param name="pSubfieldCode"/>
<xsl:choose>
<xsl:when test="contains($pString,$pSeparator)">
<marc:subfield>
<xsl:attribute name="code"><xsl:value-of select="$pSubfieldCode"/></xsl:attribute>
<xsl:value-of select="substring-before($pString,$pSeparator)"/>
</marc:subfield>
<xsl:call-template name="tToken2Subfields">
<xsl:with-param name="pString" select="substring-after($pString,$pSeparator)"/>
<xsl:with-param name="pSeparator" select="$pSeparator"/>
<xsl:with-param name="pSubfieldCode" select="$pSubfieldCode"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<marc:subfield>
<xsl:attribute name="code"><xsl:value-of select="$pSubfieldCode"/></xsl:attribute>
<xsl:value-of select="$pString"/>
</marc:subfield>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!-- get a MARC authority from a URI -->
<xsl:template name="tGetRelResource">
<xsl:param name="pRelUri"/>
<xsl:param name="pContext"/>
<xsl:choose>
<xsl:when test="$pContext/marc:record">
<xsl:copy-of select="$pContext/marc:record"/>
</xsl:when>
<xsl:when test="$pContext/bflc:marcKey">
<xsl:call-template name="tGetMiniMARCFromKey">
<xsl:with-param name="pFieldStr" select="$pContext/bflc:marcKey" />
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:variable name="vRelResourcePreNS">
<xsl:call-template name="tGetMARCAuth">
<xsl:with-param name="pUri" select="$pRelUri"/>
</xsl:call-template>
</xsl:variable>
<!--
In the interest of dashing future expectations, it is not possible
to call exsl:node-set() at this juncture. In XSLT 1.0 parlance,
templates return result tree fragments, which can only be used as
strings would be. They need to be converted to node-sets downstream
from here.
See https://www.w3.org/TR/xslt-10/#section-Result-Tree-Fragments
One might discover that Saxon and MarkLogic, and possibly other
processors, are forgiving of this rule, but then you will find out
that xsltproc is not.
-->
<xsl:copy-of select="$vRelResourcePreNS"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="tGetMiniMARCFromKey">
<xsl:param name="pFieldStr"/>
<xsl:variable name="tTag">
<xsl:choose>
<xsl:when test="substring($pFieldStr, 1, 3) = '880'">
<xsl:value-of select="substring( substring-after($pFieldStr, '$6'), 1, 3)" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="substring($pFieldStr, 1, 3)" />
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<marc:record>
<marc:datafield>
<xsl:attribute name="tag">
<xsl:choose>
<xsl:when test="substring($tTag, 2, 2) = '00'">100</xsl:when>
<xsl:when test="substring($tTag, 2, 2) = '10'">110</xsl:when>
<xsl:when test="substring($tTag, 2, 2) = '11'">111</xsl:when>
<xsl:when test="substring($tTag, 2, 2) = '30'">130</xsl:when>
<xsl:when test="substring($tTag, 2, 2) = '50'">150</xsl:when>
<xsl:when test="substring($tTag, 2, 2) = '51'">151</xsl:when>
<xsl:when test="substring($tTag, 2, 2) = '55'">155</xsl:when>
<xsl:when test="substring($tTag, 1, 3) = '440'">130</xsl:when>
<xsl:otherwise><xsl:value-of select="substring($tTag, 1, 3)" /></xsl:otherwise>
</xsl:choose>
</xsl:attribute>
<xsl:attribute name="ind1">
<xsl:choose>
<xsl:when test="$tTag = 630 or $tTag = 730">
<!-- flipping to a 130 so we need to get non filing info into the right place. -->
<xsl:value-of select="substring($pFieldStr, 5, 1)" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="substring($pFieldStr, 4, 1)" />
</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
<xsl:attribute name="ind2">
<xsl:choose>
<xsl:when test="$tTag = 630 or $tTag = 730">
<xsl:value-of select="substring($pFieldStr, 4, 1)" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="substring($pFieldStr, 5, 1)" />
</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
<xsl:call-template name="tParseMarcKey">
<xsl:with-param name="pString" select="substring($pFieldStr, 6)" />
</xsl:call-template>
</marc:datafield>
</marc:record>
</xsl:template>
<!--
special handling for id.loc.gov authorities:
Change the extension on the resource to .marcxml.xml UNLESS
global variable pSRULookup is "true" (string eq), THEN
convert id.loc.gov lookup to SRU search to get around
limitations of libxslt web client. Can also force SRU
lookup with template param pForceSRULookup (for testing)
-->
<xsl:template name="tGetMARCAuth">
<xsl:param name="pUri"/>
<xsl:param name="pForceSRULookup" select="false()"/>
<xsl:variable name="vUrl">
<xsl:choose>
<xsl:when test="(
contains($pUri,'id.loc.gov/authorities/') or
contains($pUri,'id.loc.gov/rwo/agents') or
contains($pUri,'id.loc.gov/resources/hubs') or
contains($pUri,'id.worldcat.org/fast/') or
contains($pUri,'d-nb.info/gnd/')
)
and not('.marcxml.xml' = substring($pUri, string-length($pUri) - 11))">
<xsl:choose>
<xsl:when test="($xslProcessor='libxslt' or $pSRULookup='true' or $pForceSRULookup=true())">
<xsl:variable name="vUriLccn">
<xsl:call-template name="tUriCode">
<xsl:with-param name="pUri" select="$pUri"/>
</xsl:call-template>
</xsl:variable>
<!-- need to distinguish between pre/post Y2K LCCNs -->
<xsl:variable name="vLccnSearch">
<xsl:variable name="vLccnNum">
<xsl:value-of select="translate($vUriLccn,translate($vUriLccn,'0123456789',''),'')"/>
</xsl:variable>
<xsl:variable name="vPrefix">
<xsl:value-of select="translate(substring($vUriLccn,1,3),'0123456789 ','')"/>
</xsl:variable>
<xsl:choose>
<!-- post Y2K -->
<xsl:when test="string-length($vLccnNum)=10">
<xsl:choose>
<xsl:when test="string-length($vPrefix) < 2">
<xsl:value-of select="concat($vPrefix,'%20',$vLccnNum)"/>
</xsl:when>
<xsl:otherwise><xsl:value-of select="$vUriLccn"/></xsl:otherwise>
</xsl:choose>
</xsl:when>
<!-- pre Y2K -->
<xsl:otherwise>
<xsl:choose>
<xsl:when test="string-length($vPrefix) < 3">
<xsl:value-of select="concat($vPrefix,'%20',$vLccnNum)"/>
</xsl:when>
<xsl:otherwise><xsl:value-of select="$vUriLccn"/></xsl:otherwise>
</xsl:choose>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:choose>
<xsl:when test="contains($pUri,'names') or contains($pUri,'agents')">
<xsl:value-of select="concat('http://lx2.loc.gov:210/NAF?query=bath.lccn%3d',$vLccnSearch,'&recordSchema=marcxml&maximumRecords=1')"/>
</xsl:when>
<xsl:when test="contains($pUri,'ubjects') or contains($pUri,'genreForm')">
<xsl:value-of select="concat('http://lx2.loc.gov:210/SAF?query=bath.lccn%3d',$vLccnSearch,'&recordSchema=marcxml&maximumRecords=1')"/>
</xsl:when>
<xsl:otherwise>
<xsl:message>Desire to look up <xsl:value-of select="$pUri"/> but using xsltproc. No lookup occurred.</xsl:message>
<xsl:value-of select="$pUri"/></xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:when test="contains($pUri, 'id.worldcat.org/fast/')">
<xsl:variable name="vPath">
<xsl:value-of select="substring-after($pUri,'://id.worldcat.org')"/>
</xsl:variable>
<xsl:value-of select="concat('https://id.worldcat.org',$vPath,'.mrc.xml')"/>
</xsl:when>
<xsl:when test="contains($pUri, 'd-nb.info/gnd/')">
<xsl:variable name="vPath">
<xsl:value-of select="substring-after($pUri,'://d-nb.info')"/>
</xsl:variable>
<xsl:value-of select="concat('https://d-nb.info',$vPath,'/about/marcxml')"/>
</xsl:when>
<xsl:otherwise>
<xsl:variable name="vLookupURI">
<xsl:choose>
<xsl:when test="contains($pUri, 'id.loc.gov/rwo/agents')">
<xsl:value-of select="concat(substring-before($pUri,'rwo/agents'), 'authorities/names/', substring-after($pUri,'rwo/agents/'))"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$pUri"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="vPath">
<xsl:value-of select="substring-after($vLookupURI,'://id.loc.gov')"/>
</xsl:variable>
<xsl:value-of select="concat('https://id.loc.gov',$vPath,'.marcxml.xml')"/>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise><xsl:value-of select="$pUri"/></xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:choose>
<xsl:when test="$vUrl != '' and not($xslProcessor='libxslt' and contains($vUrl, 'resources/hubs'))">
<xsl:variable name="vDoc">
<xsl:choose>
<xsl:when test="function-available('xdmp:document-get')">
<xsl:copy-of select="xdmp:document-get($vUrl)" />
</xsl:when>
<xsl:otherwise>
<xsl:copy-of select="document($vUrl)" />
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<!-- <xsl:message><xsl:value-of select="$vUrl"/></xsl:message> -->
<xsl:choose>
<xsl:when test="$vDoc">
<xsl:copy-of select="$vDoc"/>
</xsl:when>
<xsl:otherwise>
<!-- return empty collection so XSpec doesn't fail -->
<marc:collection/>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<!-- return empty collection so XSpec doesn't fail -->
<marc:collection/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!--
Special handling for label lookups at id.loc.gov
Might have to do something like system-property('xsl:vendor') if HTTPS gives problems.
-->
<xsl:template name="tGetLabel">
<xsl:param name="pUri"/>
<xsl:if test="$xslProcessor != 'libxslt'">
<xsl:variable name="vUrl">
<xsl:choose>
<xsl:when test="(
contains($pUri,'id.loc.gov/entities/') or
contains($pUri,'id.loc.gov/vocabulary/')
)
and not('.madsrdf_raw.rdf' = substring($pUri, string-length($pUri) - 16))">
<xsl:variable name="vPath">
<xsl:value-of select="substring-after($pUri,'://id.loc.gov')"/>
</xsl:variable>
<xsl:value-of select="concat('https://id.loc.gov',$vPath,'.madsrdf_raw.rdf')"/>
</xsl:when>
<xsl:otherwise><xsl:value-of select="$pUri"/></xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="vDoc">
<xsl:choose>
<xsl:when test="function-available('xdmp:document-get')">
<xsl:copy-of select="xdmp:document-get($vUrl)" />
</xsl:when>
<xsl:otherwise>
<xsl:copy-of select="document($vUrl)" />
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:choose>
<xsl:when test="$vDoc">
<xsl:value-of select="$vDoc/rdf:RDF/madsrdf:*/madsrdf:authoritativeLabel[1]" />
</xsl:when>
</xsl:choose>
</xsl:if>
</xsl:template>
<!-- generate marc:subfields by splitting a string with embedded subfields (i.e. bflc:readMarc382) -->
<xsl:template name="tParseMarcKey">
<xsl:param name="pString"/>
<xsl:param name="pSeparator" select="'$'"/>
<xsl:choose>
<xsl:when test="starts-with($pString,$pSeparator)">
<marc:subfield>
<xsl:attribute name="code"><xsl:value-of select="substring(substring-after($pString,$pSeparator),1,1)"/></xsl:attribute>
<xsl:choose>
<xsl:when test="substring(substring-after($pString,$pSeparator),1,1) = '6' and
contains(substring-after($pString,$pSeparator),$pSeparator) and
substring-before(substring(substring-after($pString,$pSeparator),2),'/$1$') != ''
">
<!-- We have something like this: $6700-09/$1$a李... -->
<xsl:value-of select="concat(substring-before(substring(substring-after($pString,$pSeparator),2),'/$1'),'/$1')"/>
</xsl:when>
<xsl:when test="contains(substring-after($pString,$pSeparator),$pSeparator)">
<xsl:value-of select="substring-before(substring(substring-after($pString,$pSeparator),2),$pSeparator)"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="substring(substring-after($pString,$pSeparator),2)"/>
</xsl:otherwise>
</xsl:choose>
</marc:subfield>
<xsl:choose>
<xsl:when test="substring(substring-after($pString,$pSeparator),1,1) = '6' and
substring-before(substring(substring-after($pString,$pSeparator),2),'/$1$') != '' and
contains(substring-after($pString,$pSeparator),$pSeparator)">
<xsl:call-template name="tParseMarcKey">
<xsl:with-param name="pString" select="concat($pSeparator,substring-after(substring-after($pString,$pSeparator),'/$1$'))"/>
<xsl:with-param name="pSeparator" select="$pSeparator"/>
</xsl:call-template>
</xsl:when>
<xsl:when test="contains(substring-after($pString,$pSeparator),$pSeparator)">
<xsl:call-template name="tParseMarcKey">
<xsl:with-param name="pString" select="concat($pSeparator,substring-after(substring-after($pString,$pSeparator),$pSeparator))"/>
<xsl:with-param name="pSeparator" select="$pSeparator"/>
</xsl:call-template>
</xsl:when>
</xsl:choose>
</xsl:when>
</xsl:choose>
</xsl:template>
<!-- generate marc:subfields by splitting a string with embedded subfields (i.e. bflc:readMarc382) -->
<xsl:template name="tReadMarc382">
<xsl:param name="pString"/>
<xsl:param name="pSeparator" select="'$'"/>
<xsl:choose>
<xsl:when test="starts-with($pString,$pSeparator)">
<!-- Do not generate $3, that should come from RDF -->
<xsl:if test="substring(substring-after($pString,$pSeparator),1,1) != '3'">
<marc:subfield>
<xsl:attribute name="code"><xsl:value-of select="substring(substring-after($pString,$pSeparator),1,1)"/></xsl:attribute>
<xsl:choose>
<xsl:when test="contains(substring-after($pString,$pSeparator),$pSeparator)">
<xsl:value-of select="substring-before(substring(substring-after($pString,$pSeparator),2),$pSeparator)"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="substring(substring-after($pString,$pSeparator),2)"/>
</xsl:otherwise>
</xsl:choose>
</marc:subfield>
</xsl:if>
<xsl:choose>
<xsl:when test="contains(substring-after($pString,$pSeparator),$pSeparator)">
<xsl:call-template name="tReadMarc382">
<xsl:with-param name="pString" select="concat($pSeparator,substring-after(substring-after($pString,$pSeparator),$pSeparator))"/>
<xsl:with-param name="pSeparator" select="$pSeparator"/>
</xsl:call-template>
</xsl:when>
</xsl:choose>
</xsl:when>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
</xslt:template>
<!-- top-level rules element -->
<xslt:template match="bf2marc:rules">
<xsl:variable name="vCurrentVersion"><xslt:value-of select="bf2marc:version"/></xsl:variable>
<xslt:apply-templates mode="map"/>
<xslt:apply-templates mode="key"/>
<xsl:template match="/">
<!-- rudimentary document validation -->
<!-- Document should consist of an rdf:RDF root element with one top-level bf:Instance element -->
<!-- There can be 0 or 1 top-level bf:Work element that is linked to the bf:Instance -->
<xsl:choose>
<xsl:when test="rdf:RDF">
<xsl:choose>
<xsl:when test="count(rdf:RDF/bf:Instance[not(rdf:type/@rdf:resource='http://id.loc.gov/ontologies/bflc/SecondaryInstance')]) = 1">
<xsl:choose>
<xsl:when test="count(rdf:RDF/bf:Work) = 0"/>
<xsl:when test="count(rdf:RDF/bf:Work) = 1">
<xsl:choose>
<xsl:when test="rdf:RDF/bf:Instance/bf:instanceOf/bf:*[@rdf:about=/rdf:RDF/bf:Work/@rdf:about]"/>
<xsl:when test="rdf:RDF/bf:Instance/bf:instanceOf[@rdf:resource=/rdf:RDF/bf:Work/@rdf:about]"/>
<xsl:when test="rdf:RDF/bf:Work/bf:hasInstance[@rdf:resource=/rdf:RDF/bf:Instance/@rdf:about]"/>
<xsl:otherwise>
<xsl:message terminate="yes">Invalid document: top-level Instance and Work are not linked</xsl:message>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<xsl:message terminate="yes">Invalid document: document can only have 0 or 1 top-level Work element</xsl:message>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<xsl:message terminate="yes">Invalid document: document must have exactly one top-level Instance element</xsl:message>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<xsl:message terminate="yes">Invalid document: no RDF root element</xsl:message>
</xsl:otherwise>
</xsl:choose>
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="rdf:RDF">
<xsl:variable name="vPrincipalInstance" select="bf:Instance[not(rdf:type/@rdf:resource='http://id.loc.gov/ontologies/bflc/SecondaryInstance')]"/>
<xsl:variable name="vAdminMetadata" select="$vPrincipalInstance/bf:adminMetadata/bf:AdminMetadata | bf:Work/bf:adminMetadata/bf:AdminMetadata[not(/rdf:RDF/bf:Instance/bf:adminMetadata/bf:AdminMetadata)]"/>
<xsl:variable name="vRecordId">
<xsl:choose>
<xsl:when test="$pRecordId = 'default'">
<xsl:choose>
<xsl:when test="$vAdminMetadata/bf:identifiedBy/bf:Local[not(bf:source) or bf:source/@rdf:resource='http://id.loc.gov/vocabulary/organizations/dlc' or bf:source/bf:Source/@rdf:about='http://id.loc.gov/vocabulary/organizations/dlc' or bf:source/bf:Source/rdfs:label='DLC']/rdf:value">
<xsl:value-of select="$vAdminMetadata/bf:identifiedBy/bf:Local[not(bf:source) or bf:source/@rdf:resource='http://id.loc.gov/vocabulary/organizations/dlc' or bf:source/bf:Source/@rdf:about='http://id.loc.gov/vocabulary/organizations/dlc' or bf:source/bf:Source/rdfs:label='DLC']/rdf:value"/>
</xsl:when>
<xsl:otherwise><xsl:value-of select="generate-id()"/></xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise><xsl:value-of select="$pRecordId"/></xsl:otherwise>
</xsl:choose>
</xsl:variable>
<marc:record>
<xslt:apply-templates mode="documentFrame"/>
</marc:record>
</xsl:template>
<xslt:apply-templates mode="generateTemplates"/>
<xsl:template match="text()"/>
</xslt:template>
<!-- templates for constructing map variables -->
<!-- compile maps from included files -->
<xslt:template match="bf2marc:file" mode="map">
<xslt:apply-templates select="document(.)/bf2marc:rules/bf2marc:file | document(.)/bf2marc:rules/bf2marc:map" mode="map"/>
</xslt:template>
<xslt:template match="bf2marc:map" mode="map">
<xsl:variable name="{@name}">
<xslt:for-each select="*">
<xslt:copy-of select="."/>
</xslt:for-each>
</xsl:variable>
<!--
The below works but is unused: 20240909.
In future, could replace a bunch of exsl:node-set calls in the main code with
this.
<xsl:variable name="{@name}NS" select="exsl:node-set(${@name})" />
-->
</xslt:template>
<!-- templates for constructing keys: simple pass-through -->
<!-- compile keys from included files -->
<xslt:template match="bf2marc:file" mode="key">
<xslt:apply-templates select="document(.)/bf2marc:rules/bf2marc:file | document(.)/bf2marc:rules/bf2marc:key" mode="key"/>
</xslt:template>