-
Notifications
You must be signed in to change notification settings - Fork 1
/
univ_ead2cpf.xsl
2974 lines (2684 loc) · 165 KB
/
univ_ead2cpf.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:ead="urn:isbn:1-931666-22-9"
xmlns:functx="http://www.functx.com"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:eac="urn:isbn:1-931666-33-4"
xmlns:snac="http://socialarchive.iath.virginia.edu/"
xmlns:saxext="http://example.com/saxon-extension"
exclude-result-prefixes="#all"
version="2.0">
<!--
Mar 3 2015 This file is very similar to eadToCpf.xsl, but has somewhat more generalized paths to
required files. This is currently experimental.
Author: Tom Laudeman, Daniel Pitti
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://www.osedu.org/licenses/ECL-2.0
http://opensource.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.
Required steps:
0.1) symlink to session_lib.pm or copy into this dir
1) create file lists
2) create the ead urls aka "fix urls"
2.1) create the geonames xml file geo.xml. See geo.xsl.
3) run the cpf conversion
4) validate with jing
cd createFileLists
./run_all.pl > rax.log 2>&1 &
or you can run a single collection aka dir, in this case mhs:
../snac_transform.sh dummy.xml createList.xsl abbreviation=\"mhs\" >> ra.log 2>&1
QA and testing is a good idea. See qa.xml for comments about what each input file tests. Note that QA
cannot test URL substitution in CPF because the collection sourceCode is per-file not per-record. QA
can be run through fix_ur.xsl to generate URLs.
snac_transform.sh qa.xml eadToCpf.xsl > qa.log 2>&1 &
snac_transform.sh qa2.xml eadToCpf.xsl > qa.log 2>&1 &
# Run urls for just one collection
snac_transform.sh createFileLists/mhs_list.xml fix_url.xsl 2> tmp.log > url_xml/mhs_url.xml
# Run all the URLs aka "fixed urls"
./run_fix_all.pl > rfa.log 2>&1 &
An entire collection is run without regard to $start and $stop. Small batches for testing are handled by qa.xml and qa2.xml.
In the past, variables start and stop in eadToCpfVariables.xsl controled how much of the xml file is processed,
unless the xml file had force="1", but now we just run the entire input.
snac_transform.sh qa.xml eadToCpf.xsl cpfOutLocation="cpf_qa" > qa.log 2>&1 &
Use command line param inc_orig to get the original EAD in the CFP output objectXML.
snac_transform.sh qa2.xml eadToCpf.xsl cpfOutLocation="cpf_qa" inc_orig=1 > qa.log 2>&1 &
Examples of running single collections:
snac_transform.sh createFileLists/oac_list.xml eadToCpf.xsl > logs/oac.log 2>&1 &
snac_transform.sh createFileLists/aao_list.xml eadToCpf.xsl > logs/aao.log 2>&1 &
Use extract_all.pl to run everything. By default extract_all.pl is non-review, original not included.
./extract_all.pl > ext.log 2>&1 &
For rewview data, with original EAD included:
./extract_all.pl review=1 inc_orig=1 > rev.log 2>&1 &
The review feature works on separate data, and creates separate output, both to support fully
functional review data. (The review probably has URLs completed, which is an issue with the normal QA
which cannot complete URLs.) Review reads file lists from ./review_file_lists/ instead of
./createFielLists/. It logs to ./rlogs/ instead of ./logs/. And it writes results to ./cpf_review/
instead of ./cpf_extract/. See extract_all.pl.
Validate with jing. The old way with find -exec works well enough. stdout and stderr can both go to
the same file, so we only need one log file.
find ./cpf_extract/ -type f -exec java -jar /usr/share/jing/bin/jing.jar /projects/socialarchive/published/shared/cpf.rng {} + > jing.log 2>&1 &
The "parallel" utility will auto launch multiple processes which speeds up the validation.
Use two log files and the eta param, \-\-eta, that is dash dash eta
find cpf_extract/ -type f | parallel \-\-eta -X java -jar /usr/share/jing/bin/jing.jar /projects/socialarchive/published/shared/cpf.rng {} ::: > jing.log 2> jing_error.log &
For debugging, see variable processingType. A differnt command line is necessary.
-->
<xsl:import href="av.xsl"/>
<xsl:import href="functions.xsl"/>
<xsl:import href="variables.xsl"/>
<xsl:import href="templates.xsl"/>
<!--
Mar 3 2015 Need to make paths easier to configure, slightly more portable.
No trailing / as is the convention.
-->
<xsl:param name="data_path_stem" select="'./data/source'"/>
<!--
Mar 3 2015
Stop stem string. Used in a regex to trim off leading part of path for path-relative URL matching. see templates.xsl
This is the left-most part of the path to keep. (Yes, keep, not throw away).
If your files are in data/source/findindAids/repo then this is 'findingAids' and the final, matching
path will be findingAids/repo/1234.xml.
-->
<xsl:param name="trim_stop_string" select="'findingAids'"/>
<xsl:strip-space elements="*"/>
<xsl:output indent="yes" method="xml"/>
<xsl:key name="sourceCodeName" match="source" use="sourceCode"/>
<xsl:param name="cpfOutLocation">
<!-- this variable is used in building the path to the were cpf records will be serialized as files. -->
<xsl:text>cpf_extract/</xsl:text>
</xsl:param>
<!--
The deepest part of the original file name path that we'll remove. Everything deeper has path info
that we keep, and a file base name used to generate unique file names for output.
-->
<xsl:variable name="depth_path">
<xsl:text>findingAids</xsl:text>
</xsl:variable>
<xsl:variable name="this_year" select="year-from-date(current-date())"/>
<xsl:variable name="processingType">
<!--
Only CPFOut will produce CPF output. All the others are for debugging, and write XML to stdout,
creating no files.
When using one of the debug processing types, separate stdout and stderr to separate log files.
snac_transform.sh qa2.xml eadToCpf.xsl cpfOutLocation="cpf_qa" inc_orig=0 > qa.log 2> qa_err.log &
-->
<xsl:text>CPFOut</xsl:text>
<!-- <xsl:text>rawExtract</xsl:text> -->
<!-- <xsl:text>stepOne</xsl:text> -->
<!-- <xsl:text>stepTwo</xsl:text> -->
<!-- <xsl:text>stepFive</xsl:text> -->
<!-- rawExtract stepOne stepTwo stepThree stepFour stepFive testCPFOut CPFOut-->
</xsl:variable>
<!--
The expected, normal xml input file is something like: createFileLists/nmaia_list.xml which to base-uri() is:
file:/lv1/home/twl8n/ead2cpf_pack/createFileLists/nmaia_list.xml
-->
<xsl:variable name="file2url">
<xsl:choose>
<xsl:when test="matches(base-uri(), '_missing')">
<xsl:copy-of select="document(concat('url_xml/', replace(base-uri(), '.*/(.*?_missing).*', '$1'), '_url.xml'))"/>
</xsl:when>
<xsl:otherwise>
<xsl:copy-of select="document(concat('url_xml/', replace(base-uri(), '.*/(.*?)_.*', '$1'), '_url.xml'))"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<!--
Do not include original data unless specifically asked to.
-->
<xsl:param name="inc_orig" select="false()" as="xs:boolean"/>
<xsl:template name="tpt_process">
<xsl:param name="icount"/>
<!--
This was variable name="process". The two for-each loops (snac:list/snac:group, snac:i) have been
moved into template name="tpt_main" match="/" below.
This processes a single ead file.
-->
<xsl:message>
<xsl:value-of select="concat('first url file: ', $file2url/container/file[1])"/>
</xsl:message>
<!-- Mar 3 2015 change to ./ relative to current working directory. -->
<xsl:variable name="eadPath">
<!-- <xsl:value-of select="concat('./data/source/', .)"/> -->
<xsl:value-of select="concat($data_path_stem, '/', .)"/>
</xsl:variable>
<!-- Mar 3 2015 change to ./ relative to current working directory. -->
<xsl:variable name="fn">
<!-- <xsl:value-of select="concat('./data/source/', .)"/> -->
<xsl:value-of select="concat($data_path_stem, '/', .)"/>
</xsl:variable>
<xsl:message>
<xsl:text>fn: </xsl:text>
<xsl:value-of select="$fn"/>
</xsl:message>
<xsl:for-each select="document($fn)">
<!-- <xsl:variable name="original_ead" select="."/> -->
<!--
Raw extraction extracts all tagged names and origination, tagged or not. For the
latter it attemts to determine type, and if unable to do so, defaults to persname. It
also selects out, carefully, family names that have been mistagged as persname or
corpname. (Except for names found in controlaccess, unless that bug has been fixed.)
-->
<xsl:variable name="rawExtract_a">
<!--
Extraction origination which is creator of the collection, or author of the materials in
the collection.
Nov 11 2014 Add logging for multiple names in origination. Some finding aids may what we
consider .r names in origination instead of controlaccess.
-->
<xsl:if test="count(ead/archdesc/did/origination) > 1">
<xsl:message>
<xsl:value-of select="concat('Multi-orig: ', count(ead/archdesc/did/origination), $cr)"/>
</xsl:message>
</xsl:if>
<xsl:for-each select="ead/archdesc/did/origination">
<!-- <xsl:message> -->
<!-- <xsl:text>orig: </xsl:text> -->
<!-- <xsl:copy-of select="."/> -->
<!-- </xsl:message> -->
<xsl:choose>
<xsl:when test="persname | corpname | famname">
<xsl:for-each select="(persname | corpname | famname) [matches(.,'[\p{L}]')]">
<entity source="origination">
<xsl:choose>
<xsl:when test="snac:containsFamily(.)">
<rawExtract>
<xsl:element name="{name()}">
<xsl:copy-of select="@*"/>
<xsl:value-of select="normalize-space(.)"/>
</xsl:element>
</rawExtract>
<xsl:choose>
<xsl:when test="@normal">
<normal type="attributeNormal">
<famname>
<xsl:copy-of select="@*"/>
<xsl:value-of select="normalize-space(@normal)"/>
</famname>
</normal>
</xsl:when>
<xsl:otherwise>
<normal type="provisional">
<famname>
<xsl:copy-of select="@*"/>
<xsl:value-of select="normalize-space(.)"/>
</famname>
</normal>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<rawExtract>
<xsl:element name="{name()}">
<xsl:copy-of select="@*"/>
<xsl:value-of select="normalize-space(.)"/>
</xsl:element>
</rawExtract>
<xsl:variable name="an">
<!--
See "note 1" elsewhere in this file. This adds a new
<normal> with a copy of the name from rawExtract. This has
led to several bugs and some confusion.
-->
<xsl:call-template name="tpt_attributeNormal"/>
</xsl:variable>
<xsl:copy-of select="$an"/>
</xsl:otherwise>
</xsl:choose>
</entity>
</xsl:for-each>
</xsl:when>
<xsl:otherwise>
<!-- Odd looking syntax means "context not equal to the empty string". -->
<xsl:if test=". != ''">
<entity source="origination">
<rawExtract type="unknown">
<xsl:element name="{name()}">
<xsl:copy-of select="@*"/>
<xsl:value-of select="normalize-space(.)"/>
</xsl:element>
</rawExtract>
<xsl:choose>
<xsl:when test="contains(lower-case(.),'family')">
<normal type="tenuous">
<famname>
<xsl:value-of select="normalize-space(.)"/>
</famname>
</normal>
</xsl:when>
<xsl:when test="snac:containsCorporateWord(.)">
<normal type="tenuous">
<corpname>
<xsl:value-of select="normalize-space(.)"/>
</corpname>
</normal>
</xsl:when>
<xsl:when test="contains(.,',')">
<!--
This is simply a wager that personal names far outnumber
corporate and family names, thus ... more often right than
wrong. Perhaps.
-->
<normal type="tenuous">
<persname>
<xsl:value-of select="normalize-space(.)"/>
</persname>
</normal>
</xsl:when>
<xsl:otherwise>
<normal type="tenuous">
<persname>
<xsl:value-of select="normalize-space(.)"/>
</persname>
</normal>
</xsl:otherwise>
</xsl:choose>
</entity>
</xsl:if>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
<!--
extract control access aka controlaccess (this really is it, apparent cut/paste error gave
other entity elements have source = "controlaccess"
Note: controlaccess may be nested in controlaccess, thus the //controlaccess is necessary.
Due to processing the data before building the <entity> element, the data is in
$temp_entity_controlaccess, and the <entity> element is below.
-->
<!-- <xsl:for-each select="ead/archdesc//controlaccess/(persname | corpname | famname)"> -->
<!-- <xsl:message> -->
<!-- <xsl:text>ca-no: </xsl:text> -->
<!-- <xsl:copy-of select="."/> -->
<!-- </xsl:message> -->
<!-- </xsl:for-each> -->
<xsl:for-each select="ead/archdesc//controlaccess/(persname | corpname | famname)[matches(.,'[\p{L}]')]">
<!-- <xsl:message> -->
<!-- <xsl:text>ca-match: </xsl:text> -->
<!-- <xsl:copy-of select="."/> -->
<!-- </xsl:message> -->
<xsl:variable name="temp_entity_controlaccess">
<container>
<xsl:if
test="contains(lower-case(@role),'correspond') or
contains(lower-case(@role),'crp') or
lower-case(@role)='corr' or
contains(lower-case(.),'correspond')">
<xsl:attribute name="correspondent">
<xsl:text>yes</xsl:text>
</xsl:attribute>
</xsl:if>
<xsl:choose>
<xsl:when test="snac:containsFamily(.)">
<xsl:message>
</xsl:message>
<rawExtract>
<xsl:element name="{name()}">
<xsl:copy-of select="@*"/>
<xsl:value-of select="normalize-space(.)"/>
</xsl:element>
</rawExtract>
<xsl:choose>
<xsl:when test="@normal">
<normal type="attributeNormal">
<famname>
<xsl:copy-of select="@*"/>
<xsl:value-of select="normalize-space(@normal)"/>
</famname>
</normal>
</xsl:when>
<xsl:otherwise>
<normal type="provisional">
<famname>
<xsl:copy-of select="@*"/>
<xsl:value-of select="normalize-space(.)"/>
</famname>
</normal>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<!--
Create <persname> attributes @surname and @firstname that we can use to
compare to the name from <origination>. This isn't full on name parsing,
so it won't be perfect. The @firstname is only the first "word" of the
forename.
-->
<xsl:variable name="special_controlaccess_normal">
<xsl:element name="{name()}">
<xsl:copy-of select="@*"/>
<!--
If you change this you probably also need to change variable nice_name below.
(What is supposed to be at line 1314? Nothing interesting
there now.)
Build the name that we want. We will have to clean up extraneous dots (periods) and parenthesis.
Mackay, Alexander Murdoch, 1849-1890 Mechanical engineer, missionary
Stokes, Leonard Aloysius Scott . ( 1858-1925 ) architect
Has both 'dates' and 'y' (other records have a date in 'y')
/data/source/findingAids/ahub/gulsc/1071_2002.xml
<persname source="gb-0247" normal="marr, james, c1877-c1955"
encodinganalog="jisc-hub40" authfilenumber="p0419"> <emph
altrender="surname">Marr</emph> <emph
altrender="forename">James</emph> <emph altrender="dates">fl
1895</emph> <emph altrender="y">minister</emph> </persname>
However, BNF gives us simple persname values:
<persname>Kossyguine, Alexis (1904 - 1980)</persname>
-->
<xsl:variable name="nice_name">
<xsl:for-each select="*|node()">
<!--
New: Sep 21 2014, stop removing <emph> until we find the case(s) where it was a problem.
<controlaccess id="a12">
<persname rules="ncarules">
<emph altrender="surname">Mackay</emph>
<emph altrender="forename">Alexander Murdoch</emph>
<emph altrender="dates">1849-1890</emph>
<emph altrender="epithet">Mechanical engineer, missionary</emph>
</persname>
xlf /data/source/findingAids/ahub/birminghamspcoll/900_2002.xml
less cpf_qa/ahub/birminghamspcoll/900_2002.c01.xml
old: I couldn't figure out an xpath that didn't include
<emph> (perhaps because it it matching node()) so just
use an xsl:if to weed out the <emph> elements.
-->
<!-- <xsl:if test="name() != 'emph'"> -->
<xsl:value-of select="."/>
<xsl:value-of select="' '"/>
<!-- </xsl:if> -->
</xsl:for-each>
<!-- there are cases of multiple surname values "Lloyd" and "George", separate with a space -->
<xsl:value-of select="emph[@altrender='surname' or @altrender='a' ]" separator=" "/>
<!-- Comma after surname(s). Extra comma removed by a later cleaning step. -->
<xsl:value-of select="', '"/>
<!-- there are cases of multiple forenames, so separate with space -->
<xsl:value-of select="emph[@altrender='forename']" separator=" "/>
<!--
Does an xpath with contraints connected with 'or' return
the elements in order? This is a big pita because many
of these ostensibly single elements occur multiple
times. Like multiple forenames. y and epithet often occur
as multiples.
-->
<xsl:for-each select="emph[@altrender='dates' or
@altrender='y' or
@altrender='epithet']">
<xsl:value-of select="concat(', ', .)"/>
</xsl:for-each>
</xsl:variable>
<!--
"improved" in the sense that $nice_name is just cleaned up.
-->
<xsl:variable name="improved_name">
<xsl:value-of select="snac:removeLeadingComma(
snac:removeFinalComma(
snac:removeDoubleComma(
snac:fixDates($nice_name))))"/>
</xsl:variable>
<xsl:value-of select="$improved_name"/>
<!-- <xsl:message> -->
<!-- <xsl:text>pri: </xsl:text> -->
<!-- <xsl:value-of select="normalize-space($improved_name)"/> -->
<!-- <xsl:value-of select="$cr"/> -->
<!-- <xsl:text>context: </xsl:text> -->
<!-- <xsl:copy-of select="."/> -->
<!-- <xsl:value-of select="$cr"/> -->
<!-- <xsl:text>nice_name: (nice, not improved) </xsl:text> -->
<!-- <xsl:copy-of select="snac:fixDates($nice_name)"/> -->
<!-- <xsl:value-of select="$cr"/> -->
<!-- </xsl:message> -->
</xsl:element>
</xsl:variable> <!-- special_controlaccess_normal -->
<rawExtract>
<xsl:element name="{name()}">
<xsl:copy-of select="@*"/>
<xsl:value-of select="normalize-space(.)"/>
</xsl:element>
<!-- Stop using $special_controlaccess_normal, and go back the the original code. -->
<!-- <xsl:copy-of select="$special_controlaccess_normal"/> -->
</rawExtract>
<!-- Go back to calling tpt_attributeNormal -->
<!-- <normal type="attributeNormal"> -->
<!-- <xsl:copy-of select="$special_controlaccess_normal"/> -->
<!-- </normal> -->
<!--
In the old days we called tpt_attributNormal here, but that created
issues. (What issues?) The $special_controlaccess_normal is exactly
the same code as tpt_attributNormal runs for non-@normal names. We
want $special_controlaccess_normal , and it is wrong to run anything
else here.
Note 1.
Calling attributeNormal creates a second <persname> or whatever outside
<rawExtract> but using a separate code, with the undesireable effect that
the two can become different (as when fixing the emph surname bug). So,
anthing you fix/do with names above probably also has to be fixed in
attributeNormal.
-->
<xsl:call-template name="tpt_attributeNormal"/>
</xsl:otherwise>
</xsl:choose>
</container>
</xsl:variable> <!-- temp_entity_controlaccess -->
<!-- <xsl:message> -->
<!-- <xsl:text>tec: </xsl:text> -->
<!-- <xsl:copy-of select="$temp_entity_controlaccess"/> -->
<!-- <xsl:value-of select="$cr"/> -->
<!-- </xsl:message> -->
<!--
Test to make sure we have at least one persname|famname|corpname that isn't empty. Then at the bottom
when doing copy-of * use an exciting xpath constraint to only copy elements that
contain a non-empty persname|famname|corpname.
<entity source="controlaccess" ftwo="Leonard Stokes"><rawExtract><persname
rules="ncarules">Stokes, Leonard Aloysius Scott, 1858-1925,
architect</persname></rawExtract><normal type="provisional"><persname
rules="ncarules">Stokes, Leonard Aloysius Scott, 1858-1925,
architect</persname></normal></entity>
-->
<xsl:variable name="pn_value">
<xsl:value-of select="$temp_entity_controlaccess/container/rawExtract/(persname|famname|corpname)"/>
</xsl:variable>
<!-- <xsl:message> -->
<!-- <xsl:text>pnv: </xsl:text> -->
<!-- <xsl:copy-of select="$temp_entity_controlaccess"/> -->
<!-- </xsl:message> -->
<xsl:if test="string-length($pn_value)">
<entity source="controlaccess"
encodinganalog="{$temp_entity_controlaccess/container/rawExtract/(persname|famname|corpname)/@encodinganalog}">
<!--
New: all names get ftwo down in variable name rawExtract_b so we don't need
to create a normal-for-match name here.
As far as I know, we want everything in <container> so it is unclear why I
put in a string-length() test. That test makes no sense.
Breaking this code can make bad things happen, like persname is ok, but
famname disappears and then we end up with too few .rxxx files.
-->
<xsl:copy-of select="$temp_entity_controlaccess/container/@*"/>
<!-- <xsl:copy-of select="$temp_entity/container/*[string-length(persname) > 0]"/> -->
<xsl:copy-of select="$temp_entity_controlaccess/container/*"/>
</entity>
</xsl:if>
</xsl:for-each>
<!-- extract scope and content -->
<xsl:for-each select="ead/archdesc//scopecontent/(persname | corpname | famname)[matches(.,'[\p{L}]')]">
<!-- <xsl:message> -->
<!-- <xsl:text>scocon: </xsl:text> -->
<!-- <xsl:copy-of select="."/> -->
<!-- </xsl:message> -->
<entity source="scopecontent">
<xsl:choose>
<xsl:when test="snac:containsFamily(.)">
<rawExtract>
<xsl:element name="{name()}">
<xsl:copy-of select="@*"/>
<xsl:value-of select="normalize-space(.)"/>
</xsl:element>
</rawExtract>
<xsl:choose>
<xsl:when test="@normal">
<normal type="attributeNormal">
<famname>
<xsl:copy-of select="@*"/>
<xsl:value-of select="normalize-space(@normal)"/>
</famname>
</normal>
</xsl:when>
<xsl:otherwise>
<normal type="provisional">
<famname>
<xsl:copy-of select="@*"/>
<xsl:value-of select="normalize-space(.)"/>
</famname>
</normal>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<rawExtract>
<xsl:element name="{name()}">
<!-- <xsl:attribute name="debug" select="'two'"/> -->
<xsl:copy-of select="@*"/>
<xsl:value-of select="normalize-space(.)"/>
</xsl:element>
</rawExtract>
<!-- see "note 1" elsewhere in this file -->
<xsl:call-template name="tpt_attributeNormal"/>
</xsl:otherwise>
</xsl:choose>
</entity>
</xsl:for-each>
<!-- extract dsc -->
<xsl:for-each
select="ead/archdesc//dsc//(persname | corpname | famname) [matches(.,'[\p{L}]')] [not(parent::controlaccess)][not(parent::scopecontent)] ">
<!-- <xsl:message> -->
<!-- <xsl:text>nocon: </xsl:text> -->
<!-- <xsl:copy-of select="."/> -->
<!-- </xsl:message> -->
<!--
two variables: both preprocess using new routines,
but groups into Correspondence and not; for former,
process the group to add Correspondence to the end.
-->
<entity source="dsc">
<xsl:if
test="(ancestor::*[ancestor::dsc]/did[contains(lower-case(unittitle[1]),'correspond')] and .[parent::unittitle])
or
(ancestor::*[ancestor::dsc]/did[contains(lower-case(unittitle[1]),'letter')] and .[parent::unittitle]) or
contains(lower-case(@role),'correspond') or
contains(lower-case(@role),'crp') or
contains(lower-case(.),'correspond') or
lower-case(@role)='corr'
">
<xsl:attribute name="correspondent">
<xsl:text>yes</xsl:text>
</xsl:attribute>
</xsl:if>
<xsl:choose>
<xsl:when test="snac:containsFamily(.)">
<rawExtract>
<xsl:element name="{name()}">
<xsl:copy-of select="@*"/>
<xsl:value-of select="normalize-space(.)"/>
</xsl:element>
</rawExtract>
<xsl:choose>
<xsl:when test="@normal">
<normal type="attributeNormal">
<famname>
<xsl:copy-of select="@*"/>
<xsl:value-of select="normalize-space(@normal)"/>
</famname>
</normal>
</xsl:when>
<xsl:otherwise>
<normal type="provisional">
<famname>
<xsl:copy-of select="@*"/>
<xsl:value-of select="normalize-space(.)"/>
</famname>
</normal>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<rawExtract>
<xsl:element name="{name()}">
<xsl:copy-of select="@*"/>
<!-- <xsl:attribute name="debug" select="'three'"/> -->
<xsl:value-of select="normalize-space(.)"/>
</xsl:element>
</rawExtract>
<!-- see "note 1" elsewhere in this file -->
<xsl:call-template name="tpt_attributeNormal"/>
</xsl:otherwise>
</xsl:choose>
<xsl:if test="parent::*/parent::did/unittitle/unitdate">
<xsl:for-each select="parent::*/parent::did/unittitle/unitdate">
<xsl:for-each select="tokenize(snac:getDateFromUnitdate(.),'\s')">
<!-- looks only for tokens in the date that are NNNN, and thus ignores months and days entered as nunmbers -->
<xsl:if test="matches(.,'^[\d]{3,4}$')">
<activeDate>
<xsl:number value="." format="0001"/>
</activeDate>
</xsl:if>
</xsl:for-each>
</xsl:for-each>
</xsl:if>
<xsl:if test="parent::origination/parent::did/following-sibling::controlaccess/(occupation | function)"/>
<!--
This will be rare, I surmise. If it occurs with any frequency, then we can grab
them and associate with the specific entity.
-->
<xsl:if test="parent::origination/parent::did/following-sibling::controlaccess/(occupation | function)">
<xsl:message>
<xsl:text>has sibling occ/func: </xsl:text>
<xsl:copy-of
select="parent::origination/parent::did/following-sibling::controlaccess/(occupation | function)"/>
</xsl:message>
</xsl:if>
</entity>
</xsl:for-each>
</xsl:variable> <!-- rawExtract_a end -->
<!--
Check for 3 types of direct name, and convert to indirect.
John Smith
J Smith
JT Smith or J T Smith
Note 2: While we are looping over the data, add @ftwo to every name (normal first and last direct order name for matching).
Multiple names in this field have interesting consequences since the name is parsed, and then the first and last words are pulled out.
"Teddy Wedlock, Dora Wedlock, Helen M. Heynes" becomes direct order name "Dora Wedlock Teddy Wedlock" which becomes @ftwo "dora wedlock".
-->
<xsl:variable name="rawExtract_b">
<xsl:for-each select="$rawExtract_a/entity">
<xsl:variable name="norm_for_match">
<xsl:choose>
<xsl:when test="@ftwo">
<xsl:value-of select="@ftwo"/>
</xsl:when>
<xsl:when test="normal/persname">
<xsl:value-of
select="replace(lower-case(snac:directPersnameTwo(./normal/persname)), '^(\w+).*?(\w+)(\d+|$)', '$1 $2')"/>
<!--
See Note 2 above. Multiple names in persname are exciting.
-->
</xsl:when>
<!-- Otherwise nothing. I wonder how a missing @ftwo attribute effects code below? -->
</xsl:choose>
</xsl:variable>
<xsl:choose>
<xsl:when test="./normal[matches(persname, '^\w+\s+\w+$|^[A-Z]+\s+\w+$|^[A-Z]+\s*[A-Z]+\s+\w+$')]">
<entity ftwo="{$norm_for_match}">
<xsl:copy-of select="@*[name() != 'ftwo']"/>
<xsl:copy-of select="rawExtract"/>
<normal>
<xsl:copy-of select="./normal/@*"/>
<persname>
<xsl:value-of select="replace(./normal/persname, '^(\w+)\s+(\w+)$|^([A-Z]+)\s+(\w+)$|^([A-Z]+\s*[A-Z]+)\s+(\w+)$', '$2, $1')"/>
<!-- <xsl:value-of select="replace(./normal/persname, '^(\w+)\s+(\w+)$', '$2, $1')"/> -->
</persname>
</normal>
</entity>
</xsl:when>
<xsl:otherwise>
<entity ftwo="{$norm_for_match}">
<xsl:copy-of select="@*[name() != 'ftwo']"/>
<xsl:copy-of select="rawExtract"/>
<xsl:copy-of select="normal"/>
</entity>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:variable> <!-- rawExtract_b -->
<!--
Another intermediate step that tries to match origination and controlaccess names. And I think
it decides which name to use, and might use controlaccess rather than origination (if the
names match, and based on some other criteria).
-->
<xsl:variable name="rawExtract">
<xsl:for-each select="$rawExtract_b/entity">
<!-- <xsl:message> -->
<!-- <xsl:text>xent: </xsl:text> -->
<!-- <xsl:copy-of select="./normal/(persname|famname|corpname)"/> -->
<!-- <xsl:value-of select="concat(' ft: ', ./@ftwo)"/> -->
<!-- </xsl:message> -->
<xsl:variable name="orig">
<xsl:value-of select="normalize-space(.[@source='origination']/normal/persname)"/>
</xsl:variable>
<xsl:variable name="orig_nfm">
<xsl:value-of select="@ftwo"/>
</xsl:variable>
<!--
If someone enters two matching names in controlaccess, this xpath would return both
names. It turns out that ahub has at least one example of this. Only select [1].
/data/source/findingAids/ahub/soas/196.xml
-->
<xsl:variable name="matches_ca">
<xsl:copy-of select="$rawExtract_b/(entity[@source='controlaccess' and @ftwo=$orig_nfm and @ftwo != ''])[1]"/>
</xsl:variable>
<xsl:variable name="matches_orig">
<xsl:copy-of select="$rawExtract_b/entity[@source='origination' and @ftwo=$orig_nfm and @ftwo != '']"/>
</xsl:variable>
<xsl:choose>
<xsl:when test="./@source = 'origination' and string-length($matches_ca) > 0">
<entity source="origination" ftwo="{@ftwo}" true_source="controlaccess">
<xsl:copy-of select="$matches_ca/entity/*"/>
</entity>
<!-- <xsl:message> -->
<!-- <xsl:text>mc: </xsl:text> -->
<!-- <xsl:value-of select="count($matches_ca/entity)"/> -->
<!-- <xsl:text> cto: using: </xsl:text> -->
<!-- <xsl:value-of select="$matches_ca/entity/normal/persname"/> -->
<!-- <xsl:text> instead-of: </xsl:text> -->
<!-- <xsl:value-of select="./normal/persname"/> -->
<!-- </xsl:message> -->
</xsl:when>
<xsl:when test="./@source = 'origination' and string-length($matches_ca) = 0">
<xsl:copy-of select="."/>
</xsl:when>
<xsl:when test="./@source = 'controlaccess' and string-length($matches_orig) = 0">
<xsl:copy-of select="."/>
</xsl:when>
<xsl:when test="./@source = 'controlaccess' and string-length($matches_orig) > 0">
<!-- Do nothing. This controlaccess has been converted to an origination -->
</xsl:when>
<xsl:otherwise>
<xsl:copy-of select="."/>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
<!-- <xsl:copy-of select="$rawExtract_b"/> -->
</xsl:variable> <!-- rawExtract -->
<!-- <xsl:message> -->
<!-- <xsl:text>rexa: </xsl:text> -->
<!-- <xsl:copy-of select="$rawExtract_a"/> -->
<!-- <xsl:value-of select="$cr"/> -->
<!-- <xsl:text>rexb: </xsl:text> -->
<!-- <xsl:copy-of select="$rawExtract_b"/> -->
<!-- <xsl:value-of select="$cr"/> -->
<!-- <xsl:text>new rex: </xsl:text> -->
<!-- <xsl:copy-of select="$rawExtract"/> -->
<!-- <xsl:value-of select="$cr"/> -->
<!-- <xsl:for-each select="$rawExtract/entity[@source='origination']/normal/persname"> -->
<!-- <xsl:value-of select="concat('creator: ', ., $cr)"/> -->
<!-- </xsl:for-each> -->
<!-- </xsl:message> -->
<xsl:if test="string-length($rawExtract) = 0">
<!--
Historically, $rawExtract is empty when we failed to convert some xmlns to xmlns="". However,
some records do not have any CPF entities.
-->
<xsl:choose>
<xsl:when test="namespace-uri() != ''">
<xsl:message>
<xsl:text>Warning: rawExtract possible problem.</xsl:text>
<xsl:value-of select="$cr"/>
<xsl:text>Error: incompatible namespace: </xsl:text>
<xsl:value-of select="namespace-uri()"/>
</xsl:message>
</xsl:when>
<xsl:otherwise>
<xsl:message>
<xsl:text>Warning: var rawExtract is empty.</xsl:text>
</xsl:message>
</xsl:otherwise>
</xsl:choose>
</xsl:if>
<xsl:if test="$rawExtract/entity[count(rawExtract) > 1]">
<xsl:message>
<xsl:text>multi: </xsl:text>
<xsl:copy-of select="$rawExtract/entity[count(rawExtract) > 1]"/>
<xsl:for-each select="$rawExtract/entity[count(rawExtract) > 1]/rawExtract">
<xsl:value-of select="concat($cr, 'pos: ', position())"/>
<xsl:text> </xsl:text>
<xsl:copy-of select="."/>
</xsl:for-each>
</xsl:message>
</xsl:if>
<!--
NORMALIZE STEP ONE: Removes any entity with the words unknown or various, as these are
dubious or combine name and not name components. Normalizes entries that are not
based on @normal. Every outgoing entity has a normal, either attributeNormal or regEx.
-->
<xsl:variable name="normalizeStepOne">
<xsl:for-each select="$rawExtract/entity">
<xsl:choose>
<xsl:when test="contains(lower-case(rawExtract/*),'unknown') or contains(lower-case(rawExtract/*),'various')">
<!--
This removes entries that contain unknown and various, as in either
case, the entry is either not useful or difficult to sort out.
-->
<xsl:message>
<xsl:text>Removed: </xsl:text>
<xsl:value-of select="rawExtract"/>
</xsl:message>
</xsl:when>
<xsl:otherwise>
<xsl:choose>
<xsl:when test="normal/persname">
<entity>
<xsl:copy-of select="* | @*"/>
<xsl:if test="normal[not(@type='attributeNormal')]/persname">
<!--
If we have a normal that is not an attributeNormal, then do
additional normalization, and make the type regExed. Var
pers_normal is Daniel's original normalization.
Added normalize-space() to start things off because we
previously weren't dealing well with embedded newlines.
oct 27 2014 remove snac:removeApostropheLowercaseSSpace()
which we decided does more harm than good.
Note: this piece of code is only for person! (not
corporateBody or family).
Nov 11 2014 Add snac:removeColon() here and to normal/corpname below.
-->
<xsl:variable name="pers_normal">
<xsl:value-of
select="
snac:removeColon(
snac:stripStringAfterDateInPersname(
snac:removeBeforeHyphen2(
snac:fixSpacing(
snac:fixDatesReplaceActiveWithFl(
snac:fixDatesRemoveParens(
snac:fixCommaHyphen2(
snac:cleanCommaHyphenEarly(
snac:fixHypen2Paren(
snac:removeTrailingInappropriatePunctuation(
snac:removeInitialNonWord(
snac:removeInitialTrailingParen(
snac:removeBrackets(
snac:removeInitialHypen(
snac:removeQuotes(
snac:fixSpaceComma(
normalize-space(normal/persname)))))))))))))))))"
/>
</xsl:variable>
<normal type="regExed">
<persname>
<xsl:value-of select="snac:normalize_extra($pers_normal)"/>
</persname>
</normal>
</xsl:if>
<xsl:call-template name="extractOccupationOrFunction">
<xsl:with-param name="entry">
<xsl:copy-of select="./rawExtract/*"/>
</xsl:with-param>
</xsl:call-template>
</entity>
</xsl:when>
<xsl:when test="normal/famname">
<entity>
<xsl:copy-of select="* | @*"/>
<xsl:if test="normal[not(@type='attributeNormal')]/famname">
<normal type="regExed">
<famname>
<xsl:choose>
<xsl:when test="not(contains(snac:removeBeforeHyphen2(normal/famname),' '))">
<xsl:value-of select="snac:removePunctuation(snac:removeBeforeHyphen2(normal/famname))"/>
<xsl:text> [family]</xsl:text>
</xsl:when>
<xsl:otherwise>