forked from snac-cooperative/snac_eac_cpf_utils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bl2cpf.xsl
2068 lines (1847 loc) · 105 KB
/
bl2cpf.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:xsl="http://www.w3.org/1999/XSL/Transform"
version="2.0"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:lib="http://example.com/"
xmlns:rel="http://example.com/relator"
xmlns:bl="http://example.com/bl"
xmlns:eac="urn:isbn:1-931666-33-4"
xmlns="urn:isbn:1-931666-33-4"
xmlns:xlink="http://www.w3.org/1999/xlink"
exclude-result-prefixes="#all"
>
<!--
Author: Tom Laudeman
The Institute for Advanced Technology in the Humanities
Copyright 2013 University of Virginia. Licensed under the Educational Community License, Version 2.0 (the
"License"); you may not use this file except in compliance with the License. You may obtain a copy of the
License at
http://opensource.org/licenses/ECL-2.0
http://www.osedu.org/licenses/ECL-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is
distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See
the License for the specific language governing permissions and limitations under the License.
Reads a list of British Library Names xml records and writes out EAC-CFP XML.
Run the small QA test data, do not include original data:
saxon.sh british_library/qa_file_target.xml bl2cpf.xsl inc_orig=0 > bl.log 2>&1 &
saxon.sh british_library/qa_file_target.xml bl2cpf.xsl inc_orig=0 output_dir=qa_cpf > bl.log 2>&1 &
saxon.sh british_library/file_target.xml bl2cpf.xsl > bl.log 2>&1 &
Older, historical command line:
saxon british_library/name_target.xml bl2cpf.xsl limit=100
See readme.md for details.
There is no point in doing omit-xml-declaration="yes" with Saxon, because it won't omit it for xml
output to stdout. However, if set to "yes" it will omit the declaration for result-document() output
to a file, which could be bad.
Templates in this file:
tpt_main match="/" This the xslt equivalent of main().
tpt_match_record
tpt_container match="marc:collection"
not_1xx match="//marc:record[not(marc:datafield[@tag='100' or @tag='110' or @tag='111'])]"
catch_all match="*"
match_subfield
top_record match="marc:record"
match_snac match="snac"
mode "copy-no-ns" match="*"
See also lib.xsl, eac_cpf.xsl.
What does this do in the XSL header?
extension-element-prefixes="date"
Exclude all instead of this list:
exclude-result-prefixes="xsl xs lib eac xlink rel bl"
-->
<!-- zero is all records -->
<xsl:param name="limit" select="0"/>
<xsl:param name="debug" select="false()"/>
<xsl:param name="output_dir" select="'./britlib'"/>
<xsl:param name="fallback_default" select="'UK-BL'"/>
<xsl:param name="auth_form" select="'BL'"/>
<xsl:param name="inc_orig" select="true()" as="xs:boolean"/>
<xsl:param name="archive_name" select="'BLArchive'"/>
<!--
Enable BL alternate format names nameEntry via use_bl_alt_name=1 on the command line.
Note that enabling the BL alt format will break XTF indexing.
-->
<xsl:param name="use_bl_alt_name" select="false()" as="xs:boolean"/>
<!-- These three params (variables) are passed to the cpf template eac_cpf.xsl via params to tpt_body. -->
<xsl:param name="ev_desc" select="'Derived from British Library'"/> <!-- eventDescription -->
<!-- xlink:role The $av_ variables are in lib.xsl. -->
<xsl:param name="xlink_role" select="$av_archivalResource"/>
<xsl:param name="xlink_href" select="'http://www.bl.uk/place_holder'"/> <!-- Not / terminated. Add the / in eac_cpf.xsl. xlink:href -->
<!--
When we find the tag <Corporation> we set the locn to 'CorporateBody'. Person and Family are ok.
$pers_val, $fami_val, $corp_val come from lib.xsl.
-->
<!--
This is the full list of all types of files and target values. This var exists for lookup so we can
quickly find the file associated with a given target.
-->
<xsl:variable name="file_target" select="document('british_library/file_target.xml')/*"/>
<!--
Create a key that we'll use on $file_target to look up the <file> based on file/@target.
-->
<xsl:key name="ft_key" match="file" use="@target" />
<xsl:include href="eac_cpf.xsl"/>
<xsl:include href="lib.xsl"/>
<!--
name="xml" method="xml" is for the result-document() output of CPF.
The unnamed output is just normal, default xml output.
-->
<xsl:output name="xml" method="xml" indent="yes" omit-xml-declaration="no"/>
<xsl:output indent="yes" omit-xml-declaration="no"/>
<xsl:strip-space elements="*"/>
<xsl:preserve-space elements="layout"/>
<!--
Chunking related. The prefix does not include _ or /.
-->
<xsl:param name="chunk_size" select="100"/>
<xsl:param name="chunk_prefix" select="'zzz'"/>
<xsl:param name="offset" select="1"/>
<xsl:param name="use_chunks" as="xs:boolean">
<xsl:choose>
<xsl:when test="not($chunk_prefix='zzz')">
<xsl:value-of select="true()"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="false()"/>
</xsl:otherwise>
</xsl:choose>
</xsl:param>
<xsl:variable name="xslt_script" select="'bl2cpf.xsl'"/>
<xsl:variable name="xslt_version" select="system-property('xsl:version')" />
<xsl:variable name="xslt_vendor" select="system-property('xsl:vendor')" />
<xsl:variable name="xslt_vendor_url" select="system-property('xsl:vendor-url')" />
<!-- a key-value node set, somewhat akin to a hash -->
<xsl:variable name="fn_suffix">
<key value="c">
<xsl:copy-of select="true()"/>
</key>
<key value="r">
<xsl:copy-of select="false()"/>
</key>
</xsl:variable>
<!--
Main root template start here.
-->
<xsl:template name="tpt_main" match="/" xmlns="urn:isbn:1-931666-33-4">
<xsl:message>
<xsl:value-of select="concat(' Date today: ', current-dateTime(), '
')"/>
<xsl:value-of select="concat('Number of geonames places read in: ', count($places/*), '
')"/>
<xsl:value-of select="concat(' Writing output to: ', $output_dir, '
')"/>
<xsl:value-of select="concat(' Default authorizedForm: ', $auth_form, '
')"/>
<xsl:value-of select="concat(' Fallback (default) agency code: ', $fallback_default, '
')"/>
<xsl:value-of select="concat(' Default eventDescription: ', $ev_desc, '
')"/>
<xsl:value-of select="concat(' Default xlink href: ', $xlink_href, '
')"/>
<xsl:value-of select="concat(' Default xlink role: ', $xlink_role, '
')"/>
<xsl:value-of select="concat(' limit: ', $limit, '
')"/>
<xsl:value-of select="concat(' use_bl_alt_name: ', $use_bl_alt_name, '
')"/>
<xsl:choose>
<xsl:when test="$inc_orig">
<xsl:value-of
select="concat(' Include original record: yes', '
')"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of
select="concat(' Include original record: no', '
')"/>
</xsl:otherwise>
</xsl:choose>
<xsl:choose>
<xsl:when test="$use_chunks">
<xsl:value-of select="concat(' Using chunks: yes', '
')"/>
<xsl:value-of select="concat(' Chunk size XSLT: ', $chunk_size, '
')"/>
<xsl:value-of select="concat(' Chunk dir prefix: ', $chunk_prefix, '
')"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="concat(' Using chunks: no', '
')"/>
</xsl:otherwise>
</xsl:choose>
</xsl:message>
<!--
Read each Names* file into a var, make that var the context, and call a template to process the
data.
Save the file name, and pass that into tpt_match_record. We'll create our cpf output using the
same name as the input, and we get chunking for free.
-->
<xsl:for-each select="container/file[($limit = 0 or (position() < $limit)) and matches(., 'Names')]">
<xsl:variable name="ofile" select="text()"/>
<xsl:variable name="name" select="document(concat('british_library/', text()))/*"/>
<xsl:for-each select="$name">
<xsl:call-template name="tpt_match_record">
<xsl:with-param name="ofile" select="$ofile"/>
</xsl:call-template>
</xsl:for-each>
</xsl:for-each>
</xsl:template>
<xsl:template name="tpt_match_record" xmlns="urn:isbn:1-931666-33-4">
<xsl:param name="ofile"/>
<xsl:variable name="orig_record">
<xsl:copy-of select="."/>
</xsl:variable>
<xsl:variable
name="chunk_count"
select="(position() + $offset) div $chunk_size"/>
<!--
Using format-number() with picture string '0' seems to convince it
to save the number as a string of the real number and not to switch
to scientific notation.
-->
<xsl:variable
name="record_position"
select="format-number(position()+$offset, '0')"/>
<xsl:variable
name="chunk_suffix"
select="floor((position() + $offset - 1) div $chunk_size) + 1"/>
<xsl:variable name="controlfield_001">
<!--
Some data may have missing/duplicate 001. Using position() should be sufficient to make a
unique 001 value. I'm unclear how well the 010 or 035 would perform as record id values.
-->
<xsl:choose>
<xsl:when test="string-length(normalize-space(.//@RecordID))>0">
<xsl:value-of select="normalize-space(.//@RecordID)"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="concat('missing001_', position())"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<!--
agency_info is not <maintenanceAgency><agencyName>. The SNAC project is the maintainer of the CPF
data, not the agency where the data originated. The two concepts (current maintainer, mainttainer
of the original) are now separate variables.
-->
<xsl:variable name="agency_info">
<agencyCode>
<xsl:value-of select="$fallback_default"/>
</agencyCode>
<agencyName>
<xsl:value-of select=".//Repository"/>
</agencyName>
</xsl:variable>
<xsl:variable name="record_id"
select="concat($agency_info/eac:agencyCode, '-', $controlfield_001)"/>
<!-- <xsl:message> -->
<!-- <xsl:text>rid: </xsl:text> -->
<!-- <xsl:copy-of select="$record_id"/> -->
<!-- </xsl:message> -->
<xsl:variable name="date"
select="current-dateTime()"/>
<xsl:variable name="chunk_dir">
<xsl:choose>
<xsl:when test="$use_chunks">
<xsl:value-of select="concat($output_dir, '/', $chunk_prefix, '_', $chunk_suffix)"/>
</xsl:when>
<xsl:otherwise>
<!-- Allow the use of an output dir even when not using chunks -->
<xsl:value-of select="$output_dir"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<!--
Similar to $all_xx or $exp_data, $final_per, $final_org and so on. A list of CPF entities
we've discovered.
-->
<xsl:variable name="all_cpf">
<!-- Why was variable "citation" here? Made no sense. -->
<!--
First handle the main cpf entity described in the current Names*/ file. Create a var for name
info, to normalize cpf name info regardless whether it is from c, p, or f.
-->
<xsl:variable name="ninfo">
<xsl:call-template name="tpt_name_info">
<xsl:with-param name="is_c_flag" select="true()"/>
<xsl:with-param name="is_r_flag" select="false()"/>
<xsl:with-param name="record_id" select="$record_id"/>
<xsl:with-param name="cf" select="concat('ninfo ', $record_id)"/>
</xsl:call-template>
</xsl:variable>
<container>
<xsl:copy-of select="$ninfo"/>
</container>
<!--
key() only works with the context, and we have to use for-each to set the context, so we
have to create a new var for the file name we're looking up with key().
<NameAuthorityRelationships>
<RelatedNamedAuthority RelationshipNumber="047-001686191">
<NatureRelationshipTargetDescription>Member</NatureRelationshipTargetDescription>
<NatureRelationshipSourceDescription>Member</NatureRelationshipSourceDescription>
<TargetRecordId>047-001686191</TargetRecordId>
<CategoryOfRelationship>Family</CategoryOfRelationship>
<DateRange/>
</RelatedNamedAuthority>
...
</NameAuthorityRelationships>
-->
<xsl:for-each select=".//NameAuthorityRelationships/RelatedNamedAuthority/TargetRecordId">
<xsl:variable name="tid" select="text()"/>
<xsl:variable name="nar_file">
<xsl:for-each select="$file_target">
<xsl:value-of select="key('ft_key', $tid)"/>
</xsl:for-each>
</xsl:variable>
<xsl:variable name="nar_info">
<xsl:choose>
<xsl:when test="string-length($nar_file) > 0">
<xsl:copy-of select="document(concat('british_library/', $nar_file))/*"/>
</xsl:when>
<xsl:otherwise>
<!-- <xsl:message> -->
<!-- <xsl:text>Missing Names tid: </xsl:text> -->
<!-- <xsl:value-of select="$tid"/> -->
<!-- <xsl:text> rid: </xsl:text> -->
<!-- <xsl:value-of select="$record_id"/> -->
<!-- <xsl:text> Called from: tpt_match</xsl:text> -->
<!-- </xsl:message> -->
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<!--
Use for-each to set $nar_info as the context. There better only be one name or cpf in
$nar_info.
-->
<xsl:for-each select="$nar_info/*">
<xsl:variable name="is_c_flag" select="false()" as="xs:boolean" />
<xsl:variable name="is_r_flag" select="true()" as="xs:boolean" />
<xsl:variable name="ninfo">
<xsl:call-template name="tpt_name_info">
<xsl:with-param name="is_c_flag" select="false()"/>
<xsl:with-param name="is_r_flag" select="true()"/>
<xsl:with-param name="record_id" select="concat('UK-BL-', $tid)"/>
<xsl:with-param name="cf" select="concat('nar ', $tid)"/>
</xsl:call-template>
</xsl:variable>
<container>
<xsl:copy-of select="$ninfo"/>
</container>
</xsl:for-each>
</xsl:for-each>
</xsl:variable>
<!--
For the BL data we only create a file for the "main" entry, and we only need to build cpfRelation
data for the "main" entity. We assume that all other cpfs will have their own file, and will be
processed accordingly. In BL data, is_c_flag means "is the main cpf entity".
Note: the context is a <container> node set. <container><e_name>...</e_name><existDates>...</existDates></container>
-->
<xsl:for-each select="$all_cpf/eac:container[eac:e_name/@is_c_flag = 'true']">
<!--
Create a set of cpfRelation elements for the current node. We are inside a for-each, so the
current node should be the context.
-->
<xsl:variable name="cpf_relation">
<xsl:call-template name="tpt_cpf_relation">
<xsl:with-param name="all_xx" select="$all_cpf"/>
</xsl:call-template>
</xsl:variable>
<!--
Originally, we only had a single resourceRelation, but NYSA can have multiples, so since
that time, we now use a rrel element to hold one or more node sets for
resourceRelation. This replaces individual elements of the same name out in param_data.
radna is RelatedArchiveDescriptionNamedAuthority.
The radna is for the related descs. We need to pass in our target id.
Only call tpt_snac_info for WorldCat
-->
<xsl:variable name="param_data" xmlns="urn:isbn:1-931666-33-4">
<xsl:copy-of select="eac:descriptiveNote"/>
<use_rrel as="xs:boolean">
<xsl:value-of select="true()"/>
</use_rrel>
<rules>
<xsl:value-of select="$auth_form"/>
</rules>
<inc_orig>
<xsl:copy-of select="$inc_orig" />
</inc_orig>
<snac_info>
<xsl:call-template name="tpt_snac_info"/>
</snac_info>
<!--
As far as I know, this is not normally used, but there is a branch for it in
eac_cpf.xsl, and the other rrel code keeps a copy of the default xlink_role here. It is
possible (and likely) that some sets of data will put values in each rrel node. That's
fine, and in that case this outer xlink_role will be ignored.
-->
<xlink_role>
<xsl:value-of select="$xlink_role"/>
</xlink_role>
<!--
Calling capitalize() doesn't hurt, but we shouldn't need to capitalized @entity_type
because the values are from $pers_val etc. from lib.xsl.
-->
<citation>
<xsl:text>British Library Archives and Manuscripts Catalogue : </xsl:text>
<xsl:value-of select="lib:capitalize(eac:e_name/@entity_type)"/>
<xsl:text> : Description : </xsl:text>
<xsl:value-of select="eac:ark"/>
</citation>
<!--
tpt_radna creates the necessary rrel elements (resourceRelation) for this CPF entry.
Create a couple of vars because the outer context is not available to the inner context
of the for-each.
-->
<xsl:variable name="entity_tid" select="eac:e_name/@enid"/>
<xsl:variable name="entity_type" select="string(eac:e_name/@entity_type)"/>
<xsl:for-each select="eac:dinfo/*">
<!-- <xsl:message> -->
<!-- <xsl:text>calling radna et: </xsl:text> -->
<!-- <xsl:copy-of select="."/> -->
<!-- <xsl:text>
</xsl:text> -->
<!-- </xsl:message> -->
<xsl:call-template name="tpt_radna">
<xsl:with-param name="entity_tid" select="$entity_tid"/>
<xsl:with-param name="controlfield_001" select="$controlfield_001"/>
<xsl:with-param name="rid" select="$record_id"/>
<xsl:with-param name="entity_type" select="$entity_type"/>
</xsl:call-template>
</xsl:for-each>
<en_lang>
<!-- entry language, applies only to the first (main) name if there are multiple names. -->
<xsl:value-of select="eac:e_name/@en_lang"/>
</en_lang>
<cpf_record_id>
<!-- Used in the eac_cpf template control/recordId element. -->
<xsl:value-of select="$record_id"/>
</cpf_record_id>
<!-- authorized and alternative names are all together now -->
<xsl:copy-of select="eac:e_name"/>
<!--
This sends over the current eac:container wrapper element, which has all kinds of info
about the current entity. It is used for occupation and function.
-->
<xsl:copy-of select="."/>
</xsl:variable>
<xsl:variable name="file_name" select="concat($output_dir, '/', $ofile)"/>
<xsl:result-document href="{$file_name}" format="xml" >
<xsl:call-template name="tpt_body">
<xsl:with-param name="param_data" select="$param_data" />
<xsl:with-param name="exist_dates" select="./eac:existDates" as="node()*" />
<xsl:with-param name="entity_type" select="eac:e_name/@entity_type_cpf" />
<!-- Do not use. Superceded by $param_data/e_name for records with multi or alternative names. -->
<!-- <xsl:with-param name="entity_name" select="eac:e_name"/> -->
<xsl:with-param name="controlfield_001" select="$controlfield_001"/>
<xsl:with-param name="is_c_flag" select="eac:e_name/@is_c_flag"/>
<xsl:with-param name="is_r_flag" select="eac:e_name/@is_r_flag"/>
<xsl:with-param name="fn_suffix" select="eac:e_name/@fn_suffix" />
<xsl:with-param name="cpf_relation" select="$cpf_relation" />
<xsl:with-param name="record_id" select="$record_id" />
<xsl:with-param name="date" select="$date" />
<xsl:with-param name="xslt_vendor" select="$xslt_vendor"/>
<xsl:with-param name="xslt_version" select="$xslt_version"/>
<xsl:with-param name="xslt_vendor_url" select="$xslt_vendor_url"/>
<xsl:with-param name="tag_545" select="eac:tag_545/*"/>
<xsl:with-param name="xslt_script" select="$xslt_script"/>
<!-- The original must be a node set, not text. -->
<xsl:with-param name="original">
<original><xsl:copy-of select="$orig_record"/></original>
</xsl:with-param>
<xsl:with-param name="geographic_subject" select="eac:geo_subj/*"/>
<xsl:with-param name="topical_subject" select="eac:topical_subj/*"/>
<!-- Lots of stuff that doesn't apply to the BL data. -->
<!-- <xsl:with-param name="leader06" select="$leader06"/> -->
<!-- <xsl:with-param name="leader07" select="$leader07"/> -->
<!-- <xsl:with-param name="leader08" select="$leader08"/> -->
<!-- <xsl:with-param name="mods" select="$mods"/> -->
<!-- <xsl:with-param name="rel_entry" select="$rel_entry"/> -->
<!-- <xsl:with-param name="arc_role" select="$arc_role"/> -->
<!-- <xsl:with-param name="tag_245" select="normalize-space($tag_245)"/> -->
<!-- <xsl:with-param name="lang_decl" select="$lang_decl"/> -->
<!-- <xsl:with-param name="topical_subject" select="$topical_subject"/> -->
<!-- <xsl:with-param name="language" select="$language"/> -->
</xsl:call-template>
</xsl:result-document>
</xsl:for-each>
<!-- <xsl:message> -->
<!-- <xsl:text>
</xsl:text> -->
<!-- </xsl:message> -->
</xsl:template> <!-- end tpt_match_record -->
<xsl:template name="tpt_bl_arc_role" xmlns="urn:isbn:1-931666-33-4">
<xsl:param name="rel_type"/>
<!--
Only "subject" is subject. All others are creatorOf. Discussed Aug 8 2013.
Daniel says: BL's manuscript collections. We will call every last one of these "archival," and
almost every name will either be the creator or referencedIn a resource. (Almost?)
Use value-of to turn one or more nodes (or a sequence) into a single string that we can test with
a regex matches().
-->
<xsl:variable name="denorm_role">
<xsl:value-of select="$rel_type"/>
</xsl:variable>
<xsl:choose>
<xsl:when test="matches($denorm_role, 'subject', 'i')">
<xsl:value-of select="$av_referencedIn"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$av_creatorOf"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="tpt_name_info">
<xsl:param name="is_c_flag"/>
<xsl:param name="is_r_flag"/>
<xsl:param name="record_id"/>
<xsl:param name="cf"/>
<!--
We have to be consistent in how record id values are determined. Other data has .c records that
refer to .r records which are contained internally in the original MARC record. BL has
independent CPF entities, some of which refer to each other.
-->
<xsl:variable name="locn">
<xsl:choose>
<xsl:when test="./local-name() = 'Corporation'">
<xsl:value-of select="$corp_val"/>
</xsl:when>
<xsl:when test="./local-name() = 'Family'">
<xsl:value-of select="$fami_val"/>
</xsl:when>
<xsl:when test="./local-name() = 'Person'">
<xsl:value-of select="$pers_val"/>
</xsl:when>
<xsl:otherwise>
<xsl:message terminate="yes">
<xsl:text>Bad input root element: </xsl:text>
<xsl:value-of select="./local-name()"/>
<xsl:text>
RecordID: 
</xsl:text>
<xsl:value-of select="./@RecordID"/>
<xsl:text>
Exiting.
</xsl:text>
</xsl:message>
<!-- <xsl:value-of select="./local-name()"/> -->
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="entity_tid" select="./@RecordID"/>
<!--
This xpath seems to be the same for all CPFs.
.//ArchiveDescriptionNameAuthorityRelationships/RelatedArchiveDescriptionNamedAuthority/TargetRecordId
radna is Related Archive Description Named Authority
-->
<xsl:variable name="radna">
<xsl:for-each select=".//ArchiveDescriptionNameAuthorityRelationships/RelatedArchiveDescriptionNamedAuthority/TargetRecordId">
<radna>
<xsl:value-of select="."/>
</radna>
</xsl:for-each>
</xsl:variable>
<xsl:variable name="descs_info">
<xsl:for-each select="$radna/*">
<!--
Context in this loop is the tid of the descs file. Get the file name here, and put it in
an attribute of the descs_container so we can easily get it later on.
-->
<xsl:variable name="tid" select="."/>
<xsl:variable name="descs_file">
<xsl:for-each select="$file_target">
<xsl:value-of select="key('ft_key', $tid)"/>
</xsl:for-each>
</xsl:variable>
<descs_container tid="{.}" descs_file="{$descs_file}">
<!--
Var names: tid is target id, rid is record id, cf is called from.
-->
<xsl:call-template name="tpt_descs_info">
<xsl:with-param name="tid" select="."/>
<xsl:with-param name="rid" select="$record_id"/>
<xsl:with-param name="cf" select="'tpt_name_info'"/>
<xsl:with-param name="descs_file" select="$descs_file"/>
</xsl:call-template>
</descs_container>
</xsl:for-each>
</xsl:variable>
<!--
The <radna> node set here is accessed later as eac:radna in order to create <rrel> elements that
become resourceRelation elements in the CPF output.
-->
<dinfo>
<xsl:copy-of select="$descs_info"/>
</dinfo>
<xsl:copy-of select="$radna"/>
<geo_subj>
<xsl:copy-of select="$descs_info/*/eac:place"/>
</geo_subj>
<topical_subj>
<xsl:copy-of select="$descs_info/*/eac:localDescription[@localType = $av_associatedSubject]"/>
</topical_subj>
<!--
Note1: The name values are create by concat()'ing all the fields together along with their
separators as though every field always had a value. lib:name-cleanse() will remove extraneous
separators due to empty fields. So, the code here is simple and clean, but lib:name-cleanse() has
many small regular expressions.
Note2: Important to use .// and not // because // is global using the document, ignores the context, and
returns RelatedArchiveDescriptionNamedAuthority in all of the current "document". Only get the
first matching record. There are duplicates, and that makes a mess of tot_ocfu_e which expects a
single value.
-->
<xsl:variable name="tag_545">
<!--
aka biogHist
If you need to change this then you probably also need to fix the same code for ScopeContent.
-->
<tag_545>
<xsl:choose>
<xsl:when test=".//History/text()">
<!-- <xsl:message> -->
<!-- <xsl:text>hist-text: </xsl:text> -->
<!-- <xsl:copy-of select=".//History"/> -->
<!-- </xsl:message> -->
<p>
<xsl:apply-templates select=".//History/node()"/>
</p>
</xsl:when>
<xsl:otherwise>
<!-- <xsl:message> -->
<!-- <xsl:text>hist-other: </xsl:text> -->
<!-- <xsl:copy-of select=".//History"/> -->
<!-- </xsl:message> -->
<!--
Can't nest apply-templates, and we need both the normal apply-templates and
mode_lc so we have to use a variable.
-->
<xsl:variable name="p1">
<xsl:apply-templates select=".//History/node()"/>
</xsl:variable>
<xsl:apply-templates select="$p1" mode="mode_lc"/>
</xsl:otherwise>
</xsl:choose>
<xsl:call-template name="tpt_name_extras">
<xsl:with-param name="record_id" select="$record_id"/>
</xsl:call-template>
</tag_545>
</xsl:variable>
<xsl:variable name="descriptive_note">
<!--
We are putting the name extras in biogHist aka tag_545. We briefly considered putting the
extra BL name fields in descriptiveNote, so this var was created and is supported in the
output template, but is not currently used.
-->
<!-- <descriptiveNote> -->
<!-- <xsl:call-template name="tpt_name_extras"> -->
<!-- <xsl:with-param name="record_id" select="$record_id"/> -->
<!-- </xsl:call-template> -->
<!-- </descriptiveNote> -->
</xsl:variable>
<xsl:variable name="all_occ">
<xsl:for-each select="$descs_info/eac:descs_container//RelatedArchiveDescriptionNamedAuthority[@TargetNumber = $entity_tid]/RelationshipType/text()">
<xsl:variable name="rt" select="."/>
<xsl:for-each select="bl:split-reltype(.)">
<xsl:variable name="occ_element_name">
<xsl:choose>
<xsl:when test="$locn = $corp_val or $locn = $fami_val">
<xsl:value-of select="'function'"/>
</xsl:when>
<xsl:otherwise>
<xsl:text>occupation</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<!--
tpt_ocfu_4 checks occupation name (or relator code) against the relators file.
-->
<occ>
<xsl:call-template name="tpt_ocfu_4">
<xsl:with-param name="sfield" select="."/>
<xsl:with-param name="cname" select="$occ_element_name"/>
</xsl:call-template>
</occ>
</xsl:for-each>
</xsl:for-each>
</xsl:variable>
<!--
De-duping in 6 lines. This is explained in a long comment near the end of template tpt_geo in
lib.xsl. Note that the child element of eac:occ might be eac:occupation or eac:function.
-->
<occ>
<xsl:for-each select="$all_occ/eac:occ/*[string-length(eac:term) > 0]">
<xsl:variable name="curr" select="."/>
<xsl:if test="not(preceding::eac:term[lib:pname-match(text(), $curr/eac:term)])">
<xsl:copy-of select="$curr" />
</xsl:if>
</xsl:for-each>
</occ>
<xsl:choose>
<xsl:when test="$locn = $corp_val"> <!-- Corporation -->
<!-- <CorporationNames> -->
<!-- <CorporationName> -->
<!-- <CorporateName>Chapel of St Andrew on the new bridge</CorporateName> -->
<!-- <Jurisdiction/> -->
<!-- <AdditionalQualifiers>Elvet Hall</AdditionalQualifiers> -->
<!-- <StartDate>-9999</StartDate> -->
<!-- <DateRange>Unspecified</DateRange> -->
<!-- <EndDate>-9999</EndDate> -->
<!-- <NameType>Authorised</NameType> -->
<!-- <NameLanguage>English</NameLanguage> -->
<!-- <NameScript>Latin</NameScript> -->
<!-- </CorporationName> -->
<!-- </CorporationNames> -->
<xsl:variable name="all_names">
<xsl:copy-of select="/Corporation/CorporationNames"/>
</xsl:variable>
<xsl:variable name="auth_name">
<xsl:copy-of select="/Corporation/CorporationNames/CorporationName[NameType = 'Authorised']"/>
</xsl:variable>
<xsl:variable name="parsed_date">
<xsl:call-template name="tpt_normalized_date">
<xsl:with-param name="date_range" select="$auth_name/CorporationName/DateRange"/>
<xsl:with-param name="descs_info" select="$descs_info"/>
<xsl:with-param name="locn" select="$locn"/>
<xsl:with-param name="auth_name" select="$auth_name"/>
<xsl:with-param name="is_active" select="true()"/>
</xsl:call-template>
</xsl:variable>
<e_name enid="{$entity_tid}"
record_id="{$record_id}"
fn_suffix="{$fn_suffix/eac:key[text() = $is_c_flag]/@value}"
is_c_flag="{$is_c_flag}"
is_r_flag="{$is_r_flag}"
entity_type="{$corp_val}"
entity_type_cpf="{$cpf_corp_val}"
en_lang="{lib:get-lang($auth_name/*/NameLanguage)}">
<!--
corpname
Use for-each to set context. See lib.xsl for lib:name-cleanse. See
british_library/qa_file_target.xml comments. Var name_entry eventually becomes
nameEntry in eac_cpf.xsl.
-->
<xsl:for-each select="$all_names/*/*">
<xsl:variable name="a_form">
<xsl:call-template name="tpt_a_form">
<xsl:with-param name="type" select="NameType"/>
</xsl:call-template>
</xsl:variable>
<name_entry en_lang="{lib:get-lang(NameLanguage)}"
a_form="{$a_form}">
<part>
<!-- See Note1 above. -->
<xsl:value-of select="lib:name-cleanse(
concat(
Jurisdiction, '. ',
CorporateName, ' (',
AdditionalQualifiers, ' : ',
$parsed_date/eac:parsed_date_range, ')')
)"/>
</part>
</name_entry>
<xsl:if test="$use_bl_alt_name">
<name_entry en_lang="{lib:get-lang(NameLanguage)}"
localType="http://socialarchive.iath.virginia.edu/control/term#BLName"
a_form="{$a_form}">
<xsl:for-each select="./*">
<part localType="{concat('http://socialarchive.iath.virginia.edu/control/term#BL', local-name())}">
<xsl:value-of select="."/>
</part>
</xsl:for-each>
</name_entry>
</xsl:if>
</xsl:for-each>
</e_name>
<ark>
<xsl:value-of select=".//MDARK"/>
</ark>
<xsl:copy-of select="$parsed_date/eac:existDates"/>
<xsl:copy-of select="$tag_545"/>
<xsl:copy-of select="$descriptive_note"/>
</xsl:when>
<xsl:when test="$locn = $pers_val"> <!-- Person -->
<!-- <PersonNames> -->
<!-- <PersonName> -->
<!-- <Surname>le Bretun</Surname> -->
<!-- <FirstName>Robert</FirstName> -->
<!-- <PreTitle/> -->
<!-- <Title/> -->
<!-- <Epithet>of Walton, Dominus/Sir</Epithet> -->
<!-- <AdditionalInformation/> -->
<!-- <Gender>Unspecified</Gender> -->
<xsl:variable name="all_names">
<xsl:copy-of select="/Person/PersonNames"/>
</xsl:variable>
<xsl:variable name="auth_name">
<xsl:copy-of select="/Person/PersonNames/PersonName[NameType = 'Authorised']"/>
</xsl:variable>
<xsl:variable name="parsed_date">
<xsl:call-template name="tpt_normalized_date">
<xsl:with-param name="date_range" select="$auth_name/PersonName/DateRange"/>
<xsl:with-param name="descs_info" select="$descs_info"/>
<xsl:with-param name="locn" select="$locn"/>
<xsl:with-param name="auth_name" select="$auth_name"/>
<xsl:with-param name="is_active" select="false()"/>
</xsl:call-template>
</xsl:variable>
<e_name enid="{$entity_tid}"
record_id="{$record_id}"
fn_suffix="{$fn_suffix/eac:key[text() = $is_c_flag]/@value}"
is_c_flag="{$is_c_flag}"
is_r_flag="{$is_r_flag}"
entity_type="{$pers_val}"
entity_type_cpf="{$cpf_pers_val}"
en_lang="{lib:get-lang($auth_name/*/NameLanguage)}">
<!--
persname
Use for-each to set context. See lib.xsl for lib:name-cleanse. See british_library/qa_file_target.xml comments.
Note the extra concat() to add a trailing dot to person names.
-->
<xsl:for-each select="$all_names/*/*">
<xsl:variable name="a_form">
<xsl:call-template name="tpt_a_form">
<xsl:with-param name="type" select="NameType"/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="tmp_name">
<!--
persname
See Note1 above. This went throught several iterations. We now use the fields
(below) in the authorizedForm, and an CPF merge pipeline compatible name in
alternativeForm. name-cleanse() cleans up extra field separator punctuation
when one or more fields are empty or missing.
-->
<xsl:value-of select="lib:name-cleanse(
concat(
lib:capitalize(AdditionalInformation), ' ',
Surname, ', ',
FirstName, ', ',
PreTitle, ', ',
$parsed_date/eac:parsed_date_range, ', ',
Title, ', ',
Epithet)
,1)"/>
</xsl:variable>
<name_entry en_lang="{lib:get-lang(NameLanguage)}"
a_form="{$a_form}">
<part>
<xsl:value-of select="normalize-space($tmp_name)"/>
</part>
</name_entry>
<!--
Add alt form for matching pipeline, for internal use only. Apr 11, 2014. Revert to
an older style date also. Only do this on the authorizedForm name.
-->
<xsl:if test="$a_form = 'authorizedForm'">
<xsl:variable name="revdate">
<xsl:value-of select="replace(
replace($parsed_date/eac:parsed_date_range, 'active', 'fl.')
, 'approximately', 'ca.')"/>
</xsl:variable>
<name_entry en_lang="{lib:get-lang(NameLanguage)}"
a_form="alternativeForm"
localType="{$av_match}">
<part>
<xsl:value-of select="lib:name-cleanse(
concat(
lib:capitalize(AdditionalInformation), ' ',
Surname, ', ',
FirstName, ', ',
$revdate)
,1)"/>
</part>
</name_entry>
</xsl:if>
<xsl:if test="$use_bl_alt_name">
<name_entry en_lang="{lib:get-lang(NameLanguage)}"
localType="http://socialarchive.iath.virginia.edu/control/term#BLName"
a_form="{$a_form}">
<xsl:for-each select="./*">
<part localType="{concat('http://socialarchive.iath.virginia.edu/control/term#BL', local-name())}">
<xsl:value-of select="."/>
</part>
</xsl:for-each>
</name_entry>
</xsl:if>
</xsl:for-each>
</e_name>
<ark>
<xsl:value-of select=".//MDARK"/>
</ark>
<xsl:copy-of select="$parsed_date/eac:existDates"/>
<xsl:copy-of select="$tag_545"/>
<xsl:copy-of select="$descriptive_note"/>
</xsl:when>
<xsl:when test="$locn = $fami_val"> <!-- Family -->
<!-- <FamilyNames> -->
<!-- <FamilyName> -->
<!-- <AdditionalInformation/> -->
<!-- <FamilySurname>Wood</FamilySurname> -->
<!-- <FamilyEpithet>Family</FamilyEpithet> -->
<!-- <TitleOccupation/> -->
<!-- <TerritorialDesignation>Subject of Mss Eur F553</TerritorialDesignation> -->
<!-- <StartDate>-9999</StartDate> -->
<!-- <DateRange>Unspecified</DateRange> -->
<!-- <EndDate>-9999</EndDate> -->
<!-- <NameType>Authorised</NameType> -->
<!-- <NameLanguage>English</NameLanguage> -->
<!-- <NameScript>Latin</NameScript> -->
<!-- </FamilyName> -->
<!-- </FamilyNames> -->
<xsl:variable name="all_names">
<xsl:copy-of select="/Family/FamilyNames"/>
</xsl:variable>
<xsl:variable name="auth_name">
<xsl:copy-of select="/Family/FamilyNames/FamilyName[NameType = 'Authorised']"/>
</xsl:variable>
<xsl:variable name="parsed_date">
<xsl:call-template name="tpt_normalized_date">
<xsl:with-param name="date_range" select="$auth_name/FamilyName/DateRange"/>
<xsl:with-param name="descs_info" select="$descs_info"/>
<xsl:with-param name="locn" select="$locn"/>
<xsl:with-param name="auth_name" select="$auth_name"/>
<xsl:with-param name="is_active" select="true()"/>
</xsl:call-template>
</xsl:variable>
<!-- <xsl:message> -->