-
Notifications
You must be signed in to change notification settings - Fork 0
/
ead3ToOR.xsl
2220 lines (2026 loc) · 78.6 KB
/
ead3ToOR.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="http://ead3.archivists.org/schema/" xmlns:functx="http://www.functx.com" xmlns:snac="snac"
xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xpath-default-namespace="http://ead3.archivists.org/schema/"
version="3.0">
<!--
@author Daniel Pitti
@license https://opensource.org/licenses/BSD-3-Clause BSD 3-Clause
@copyright 2020 the Rector and Visitors of the University of Virginia
-->
<!-- To convert from EAD2002 to EAD3, or vice-versa
1. xmlns:ead="http://ead3.archivists.org/schema/" to/from xmlns:ead="urn:isbn:1-931666-22-9"
2. xpath-default-namespace="http://ead3.archivists.org/schema/" to/from
xpath-default-namespace="urn:isbn:1-931666-22-9"
3. Search for namespace string and replace with appropriate string.
4. change variable tempSourceId to empty string in both versions
No changes to included stylesheets
-->
<!-- SAXON test command line for running this XSLT:
java -cp /usr/local/Cellar/saxon/9.9.1.7/libexec/saxon9he.jar net.sf.saxon.Query -t -qs:"current-date()"
Output is current date plus additional meta-information on process.
Documentation is here: https://www.saxonica.com/html/documentation9.7/using-xsl/commandline/
The following command works locally:
java -cp /usr/local/Cellar/saxon/9.9.1.7/libexec/saxon9he.jar net.sf.saxon.Transform -s:/Users/dvp4c/Work/SNACIII/OpenRefine/EAD/Driver/driver.xml -xsl:/Users/dvp4c/Work/SNACIII/OpenRefine/EAD/XSLT/EADtoOR/eadToORxsl.xsl -o:/Users/dvp4c/Work/SNACIII/OpenRefine/EAD/Extract/output.xml sourceFolderPath=../../SourceFiles/nypl2019 outputFolderPath=../extract/
passing two parameters:
param sourceFolderPath
param outputFolderPath
optional param: start [number] stop[number] can also be added for test purposes when you want to, let us say, process
only 10 out of a 100 files.
parsing the command line:
-s:/Users/dvp4c/Work/SNACIII/OpenRefine/EAD/Driver/driver.xml This xml file actually exists, but it only serves as an
xml file to pass in the command line as -s seems to be required. The content of driver.xml is:
<?xml version="1.0" encoding="UTF-8"?>
<driver>Used as the "driver" xml for eadToORxsl</driver>
Similarly, -o works in a similar fashion, though the path and folder exist, the results of running the XSLT does not
result in a file named output.xml. A complete existing path is necessary though; I suspect because I am using a relative path in the parameters;
if absolute paths were used I suspect the would overwrite -s and -o. But not sure.
-->
<!-- This is the primary XSLT and it imports two additional XSLT files, one with custom developed functions used in the
processing, and the other has various global variables used in the processing. Local variable are situated as
appropriate in the primary XSLT file, which is to say, this file. There are also additional local variables in the
functions XSLT. relatorList.xml is also used by the XSTL. -->
<xsl:import href="eadToORFunctions.xsl"/>
<xsl:import href="eadToORVariables.xsl"/>
<xsl:param name="sourceFolderPath">
<xsl:text>../../SourceFiles/</xsl:text>
<xsl:value-of select="$tempSourceID"/>
<!-- URL for the remote folder in which there are ead encoded xml files; alternatively, if the files are "pre-fetched"
to a SNAC server, then the URL to the folder on the SNAC server will be the sourceFolder-->
</xsl:param>
<xsl:param name="outputFolderPath">
<xsl:text>../extract/</xsl:text>
<!-- URL for the three tsv files created. -->
</xsl:param>
<xsl:variable name="tempSourceID">
<xsl:text></xsl:text>
<!-- nypl2019 amnh-1 -->
<!-- reduce to empty string for production -->
</xsl:variable>
<!-- ******************************************** -->
<!-- The following two parameters are by default set to process all uri-collection files. But command
line can be used to process just a portion for testing purposes -->
<xsl:param name="start" as="xs:integer">
<xsl:text>1</xsl:text>
</xsl:param>
<xsl:param name="stop" as="xs:integer">
<xsl:value-of select="$fileCount"/>
</xsl:param>
<!-- ******************************************** -->
<xsl:variable name="incomingChars">
<xsl:text>“”’</xsl:text>
</xsl:variable>
<xsl:variable name="outgoingChars">
<xsl:text>""'</xsl:text>
</xsl:variable>
<xsl:variable name="findingAids" select="uri-collection(concat($sourceFolderPath, '?select=*.xml;recurse=yes'))">
<!-- This pulls in the URI whereas collection() pulls in the document -->
</xsl:variable>
<xsl:variable name="fileCount">
<xsl:value-of select="count($findingAids)"/>
</xsl:variable>
<xsl:variable name="colSeperator">
<xsl:text>^%%^</xsl:text>
</xsl:variable>
<xsl:variable name="cellSeperator">
<xsl:text>#%%#</xsl:text>
</xsl:variable>
<xsl:strip-space elements="*"/>
<xsl:key name="sourceCodeName" match="source" use="sourceCode"/>
<!-- ************************************************************************************************** -->
<!-- ************************************************************************************************** -->
<xsl:variable name="processingType">
<xsl:text>allOR</xsl:text>
<!-- rawExtract stepOne stepTwo stepThree stepFour stepFive testRD
testCPF testJoin allOR -->
</xsl:variable>
<!-- for testing purposes method is xml; this is overridden in result-document for tsv tables -->
<xsl:output indent="yes" method="xml"/>
<!-- ************************************************************************************************** -->
<!-- OpenRefine Column Labels -->
<!-- ************************************************************************************************** -->
<xsl:variable name="Abstract">Abstract</xsl:variable>
<xsl:variable name="BiogHist">BiogHist</xsl:variable>
<xsl:variable name="Citation">Citation</xsl:variable>
<xsl:variable name="Citation-URL">Citation-URL</xsl:variable>
<xsl:variable name="Citation-FoundData">Citation-FoundData</xsl:variable>
<xsl:variable name="CPF-Relation-Type">CPF-Relation-Type</xsl:variable>
<xsl:variable name="CPF-Source-ID">CPF-Source-ID</xsl:variable>
<xsl:variable name="CPF-Source-ID-Anchor">CPF-Source-ID-Anchor</xsl:variable>
<xsl:variable name="CPF-Source-ID-Target">CPF-Source-ID-Target</xsl:variable>
<xsl:variable name="CPF-Type">CPF-Type</xsl:variable>
<xsl:variable name="Date">Date</xsl:variable>
<xsl:variable name="Extent">Extent</xsl:variable>
<xsl:variable name="Activity">Activity</xsl:variable>
<xsl:variable name="Language">Language</xsl:variable>
<xsl:variable name="LanguageCode">LangCode</xsl:variable>
<xsl:variable name="NameEntry">NameEntry</xsl:variable>
<xsl:variable name="Occupation">Occupation</xsl:variable>
<xsl:variable name="Place">Place</xsl:variable>
<xsl:variable name="RD-Relation-Type">RD-Relation-Type</xsl:variable>
<xsl:variable name="RD-Source-ID">RD-Source-ID</xsl:variable>
<xsl:variable name="RD-Type">RD-Type</xsl:variable>
<xsl:variable name="RD-URL">RD-URL</xsl:variable>
<xsl:variable name="Repository">Repository</xsl:variable>
<xsl:variable name="Related-ID">Related-ID</xsl:variable>
<xsl:variable name="Subject">Subject</xsl:variable>
<xsl:variable name="Title">Title</xsl:variable>
<!-- ************************************************************************************************** -->
<!-- ************************************************************************************************** -->
<!-- ************************************************************************************************** -->
<xsl:variable name="process">
<xsl:for-each select="$findingAids[position() >= $start and position() <= $stop]">
<!-- this loop processes each ead file. -->
<xsl:variable name="eadPath">
<xsl:value-of select="."/>
</xsl:variable>
<xsl:for-each select="document(.)">
<!-- 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. -->
<xsl:variable name="rawExtract">
<!-- Extraction origination -->
<xsl:for-each select="ead/archdesc/did/origination">
<xsl:choose>
<xsl:when test="persname | corpname | famname">
<xsl:for-each select="(persname | corpname | famname)[matches(., '[\p{L}]')]">
<snac:entity source="origination">
<xsl:choose>
<xsl:when test="snac:containsFamily(.)">
<snac:rawExtract>
<xsl:element name="snac:{name()}">
<xsl:copy-of select="@*"/>
<xsl:value-of select="normalize-space(.)"/>
</xsl:element>
</snac:rawExtract>
<xsl:choose>
<xsl:when test="@normal">
<snac:normal type="attributeNormal">
<snac:famname>
<xsl:copy-of select="@*"/>
<xsl:value-of select="normalize-space(@normal)"/>
</snac:famname>
</snac:normal>
</xsl:when>
<xsl:otherwise>
<snac:normal type="provisional">
<snac:famname>
<xsl:copy-of select="@*"/>
<xsl:value-of select="normalize-space(.)"/>
</snac:famname>
</snac:normal>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<snac:rawExtract>
<xsl:element name="snac:{name()}">
<xsl:copy-of select="@*"/>
<xsl:value-of select="normalize-space(.)"/>
</xsl:element>
</snac:rawExtract>
<xsl:call-template name="attributeNormal"/>
</xsl:otherwise>
</xsl:choose>
</snac:entity>
</xsl:for-each>
</xsl:when>
<xsl:otherwise>
<xsl:if test=". != ''">
<snac:entity source="origination">
<snac:rawExtract type="unknown">
<xsl:element name="snac:{name()}">
<xsl:copy-of select="@*"/>
<xsl:value-of select="normalize-space(.)"/>
</xsl:element>
</snac:rawExtract>
<xsl:choose>
<xsl:when test="contains(lower-case(.), 'family')">
<snac:normal type="tenuous">
<snac:famname>
<xsl:value-of select="."/>
</snac:famname>
</snac:normal>
</xsl:when>
<xsl:when test="snac:containsCorporateWord(.)">
<snac:normal type="tenuous">
<snac:corpname>
<xsl:value-of select="."/>
</snac:corpname>
</snac: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. -->
<snac:normal type="tenuous">
<snac:persname>
<xsl:value-of select="."/>
</snac:persname>
</snac:normal>
</xsl:when>
<xsl:otherwise>
<snac:normal type="tenuous">
<snac:persname>
<xsl:value-of select="."/>
</snac:persname>
</snac:normal>
</xsl:otherwise>
</xsl:choose>
</snac:entity>
</xsl:if>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
<!-- extract control access -->
<xsl:for-each select="ead/archdesc//controlaccess/(persname | corpname | famname)[matches(., '[\p{L}]')]">
<snac:entity source="controlaccess">
<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(.)">
<snac:rawExtract>
<xsl:element name="snac:{name()}">
<xsl:copy-of select="@*"/>
<xsl:value-of select="normalize-space(.)"/>
</xsl:element>
</snac:rawExtract>
<xsl:choose>
<xsl:when test="@normal">
<snac:normal type="attributeNormal">
<snac:famname>
<xsl:copy-of select="@*"/>
<xsl:value-of select="normalize-space(@normal)"/>
</snac:famname>
</snac:normal>
</xsl:when>
<xsl:otherwise>
<snac:normal type="provisional">
<snac:famname>
<xsl:copy-of select="@*"/>
<xsl:value-of select="normalize-space(.)"/>
</snac:famname>
</snac:normal>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<snac:rawExtract>
<xsl:element name="snac:{name()}">
<xsl:copy-of select="@*"/>
<xsl:value-of select="normalize-space(.)"/>
</xsl:element>
</snac:rawExtract>
<xsl:call-template name="attributeNormal"/>
</xsl:otherwise>
</xsl:choose>
</snac:entity>
</xsl:for-each>
<!-- extract scope and content -->
<xsl:for-each select="ead/archdesc//scopecontent/(persname | corpname | famname)[matches(., '[\p{L}]')]">
<snac:entity source="controlaccess">
<xsl:choose>
<xsl:when test="snac:containsFamily(.)">
<snac:rawExtract>
<xsl:element name="snac:{name()}">
<xsl:copy-of select="@*"/>
<xsl:value-of select="normalize-space(.)"/>
</xsl:element>
</snac:rawExtract>
<xsl:choose>
<xsl:when test="@normal">
<snac:normal type="attributeNormal">
<snac:famname>
<xsl:copy-of select="@*"/>
<xsl:value-of select="normalize-space(@normal)"/>
</snac:famname>
</snac:normal>
</xsl:when>
<xsl:otherwise>
<snac:normal type="provisional">
<snac:famname>
<xsl:copy-of select="@*"/>
<xsl:value-of select="normalize-space(.)"/>
</snac:famname>
</snac:normal>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<snac:rawExtract>
<xsl:element name="snac:{name()}">
<xsl:copy-of select="@*"/>
<xsl:value-of select="normalize-space(.)"/>
</xsl:element>
</snac:rawExtract>
<xsl:call-template name="attributeNormal"/>
</xsl:otherwise>
</xsl:choose>
</snac: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)]">
<!-- two variables: both preprocess using new routines,
but groups into Correspondence and not; for former,
process the group to add Correspondence to the end-->
<snac: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(.)">
<snac:rawExtract>
<xsl:element name="snac:{name()}">
<xsl:copy-of select="@*"/>
<xsl:value-of select="normalize-space(.)"/>
</xsl:element>
</snac:rawExtract>
<xsl:choose>
<xsl:when test="@normal">
<snac:normal type="attributeNormal">
<snac:famname>
<xsl:copy-of select="@*"/>
<xsl:value-of select="normalize-space(@normal)"/>
</snac:famname>
</snac:normal>
</xsl:when>
<xsl:otherwise>
<snac:normal type="provisional">
<snac:famname>
<xsl:copy-of select="@*"/>
<xsl:value-of select="normalize-space(.)"/>
</snac:famname>
</snac:normal>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<snac:rawExtract>
<xsl:element name="snac:{name()}">
<xsl:copy-of select="@*"/>
<xsl:value-of select="normalize-space(.)"/>
</xsl:element>
</snac:rawExtract>
<xsl:call-template name="attributeNormal"/>
</xsl:otherwise>
</xsl:choose>
<!--context>
<xsl:copy-of select="parent::*"/>
</context-->
<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}$')">
<snac:activeDate>
<xsl:number value="." format="0001"/>
</snac:activeDate>
</xsl:if>
</xsl:for-each>
</xsl:for-each>
</xsl:if>
</snac:entity>
</xsl:for-each>
</xsl:variable>
<!-- 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/snac:entity">
<xsl:choose>
<xsl:when
test="contains(lower-case(snac:rawExtract/*), 'unknown') or contains(lower-case(snac: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="snac:normal/snac:persname">
<snac:entity>
<xsl:copy-of select="* | @*"/>
<xsl:if test="snac:normal[not(@type = 'attributeNormal')]/snac:persname">
<!-- This on normalizes those that do not have a @normal in rawExtract -->
<snac:normal type="regExed">
<snac:persname>
<xsl:copy-of select="snac:normal/snac:persname/@*"/>
<xsl:value-of
select="
normalize-space(
snac:stripStringAfterDateInPersname(
snac:removeApostropheLowercaseSSpace(
snac:removeBeforeHyphen2(
snac:fixSpacing(
snac:fixDatesReplaceActiveWithFl(
snac:fixDatesRemoveParens(
snac:fixCommaHyphen2(
snac:fixHypen2Paren(
snac:removeTrailingInappropriatePunctuation(
snac:removeInitialNonWord(
snac:removeInitialTrailingParen(
snac:removeBrackets(
snac:removeInitialHypen(
snac:removeQuotes(
snac:fixSpaceComma(
snac:stripTrailingPerformer(snac:normal/snac:persname))))))))))))))))
)"
/>
</snac:persname>
</snac:normal>
</xsl:if>
<xsl:call-template name="extractOccupationOrFunction">
<xsl:with-param name="entry">
<xsl:copy-of select="./snac:rawExtract/*"/>
</xsl:with-param>
</xsl:call-template>
</snac:entity>
</xsl:when>
<xsl:when test="snac:normal/snac:famname">
<snac:entity>
<xsl:copy-of select="* | @*"/>
<xsl:if test="snac:normal[not(@type = 'attributeNormal')]/snac:famname">
<snac:normal type="regExed">
<snac:famname>
<xsl:choose>
<xsl:when test="not(contains(snac:removeBeforeHyphen2(snac:normal/snac:famname), ' '))">
<xsl:value-of select="snac:removePunctuation(snac:removeBeforeHyphen2(snac:normal/snac:famname))"/>
<xsl:text> [family]</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="snac:removeBeforeHyphen2(snac:normal/snac:famname)"/>
</xsl:otherwise>
</xsl:choose>
</snac:famname>
</snac:normal>
</xsl:if>
<xsl:call-template name="extractOccupationOrFunction">
<xsl:with-param name="entry">
<xsl:copy-of select="./snac:rawExtract/*"/>
</xsl:with-param>
</xsl:call-template>
</snac:entity>
</xsl:when>
<xsl:when test="snac:normal/snac:corpname">
<snac:entity>
<xsl:copy-of select="* | @*"/>
<xsl:if test="snac:normal[not(@type = 'attributeNormal')]/snac:corpname">
<snac:normal type="regExed">
<snac:corpname>
<xsl:value-of
select="
normalize-space(
snac:removeBeforeHyphen2(
snac:fixDatesRemoveParens(
snac:fixCommaHyphen2(
snac:fixHypen2Paren(
snac:removeTrailingInappropriatePunctuation(
snac:removeInitialTrailingParen(
snac:removeBrackets(
snac:removeInitialHypen(
snac:removeQuotes(
snac:stripTrailingPerformer(snac:normal/snac:corpname))))))))))
)"
/>
</snac:corpname>
</snac:normal>
</xsl:if>
<xsl:call-template name="extractOccupationOrFunction">
<xsl:with-param name="entry">
<xsl:copy-of select="./snac:rawExtract/*"/>
</xsl:with-param>
</xsl:call-template>
</snac:entity>
</xsl:when>
</xsl:choose>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:variable>
<!-- NORMALIZE STEP TWO: Adds <normalForMatch> to <entity> and exist dates -->
<xsl:variable name="normalizeStepTwo">
<xsl:for-each select="$normalizeStepOne/snac:entity">
<snac:entity>
<xsl:copy-of select="@* | *"/>
<snac:normalForMatch>
<xsl:choose>
<xsl:when test="snac:normal[@type = 'attributeNormal']">
<xsl:value-of select="snac:normalizeString(snac:normal[@type = 'attributeNormal'])"/>
</xsl:when>
<xsl:when test="snac:normal[@type = 'regExed']">
<xsl:value-of select="snac:normalizeString(snac:normal[@type = 'regExed'])"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="snac:normalizeString(snac:normal[@type = 'provisional'])"/>
</xsl:otherwise>
</xsl:choose>
</snac:normalForMatch>
<!-- Make existDate for persname with dates in name -->
<xsl:choose>
<xsl:when test="snac:normal[@type = 'attributeNormal']/snac:persname">
<xsl:call-template name="existDateFromPersname">
<xsl:with-param name="tempString">
<xsl:value-of select="snac:normal[@type = 'attributeNormal']/snac:persname"/>
</xsl:with-param>
</xsl:call-template>
</xsl:when>
<xsl:when test="snac:normal[@type = 'regExed']/snac:persname">
<xsl:call-template name="existDateFromPersname">
<xsl:with-param name="tempString">
<xsl:value-of select="snac:normal[@type = 'regExed']/snac:persname"/>
</xsl:with-param>
</xsl:call-template>
</xsl:when>
<xsl:when test="snac:normal[@type = 'provisional']/snac:persname">
<xsl:call-template name="existDateFromPersname">
<xsl:with-param name="tempString">
<xsl:value-of select="snac:normal[@type = 'provisional']/snac:persname"/>
</xsl:with-param>
</xsl:call-template>
</xsl:when>
</xsl:choose>
</snac:entity>
</xsl:for-each>
</xsl:variable>
<!-- NORMALIZE STEP THREE: Eliminates exact (after punctuation and spelling normaizing) duplicates. -->
<xsl:variable name="normalizeStepThree">
<xsl:for-each select="$normalizeStepTwo">
<xsl:variable name="group">
<xsl:for-each-group select="snac:entity" group-by="snac:normalForMatch">
<snac:group>
<xsl:for-each select="current-group()">
<snac:entity>
<xsl:copy-of select="@* | *[not(self::snac:occupation)]"/>
</snac:entity>
</xsl:for-each>
<xsl:for-each select="current-group()">
<xsl:copy-of select="snac:occupation"/>
</xsl:for-each>
</snac:group>
</xsl:for-each-group>
</xsl:variable>
<xsl:for-each select="$group/snac:group">
<xsl:variable name="count">
<xsl:value-of select="count(snac:entity)"/>
</xsl:variable>
<xsl:variable name="correspondent">
<xsl:if test="snac:entity/@correspondent = 'yes'">
<xsl:text>yes</xsl:text>
</xsl:if>
</xsl:variable>
<xsl:variable name="activeDates">
<xsl:for-each-group select="snac:entity/snac:activeDate" group-by=".">
<xsl:sort/>
<xsl:for-each select="current-grouping-key()">
<snac:activeDate>
<xsl:value-of select="."/>
</snac:activeDate>
</xsl:for-each>
</xsl:for-each-group>
</xsl:variable>
<xsl:variable name="countActiveDates">
<xsl:value-of select="count($activeDates/*)"/>
</xsl:variable>
<xsl:variable name="occupations">
<xsl:for-each-group select="snac:occupation" group-by=".">
<xsl:sort/>
<xsl:for-each select="current-grouping-key()">
<snac:occupation>
<xsl:value-of select="."/>
</snac:occupation>
</xsl:for-each>
</xsl:for-each-group>
</xsl:variable>
<xsl:choose>
<!-- add correspondent to selection. -->
<xsl:when test="snac:entity[@source = 'origination']">
<xsl:for-each select="snac:entity[@source = 'origination'][1]">
<snac:entity>
<xsl:copy-of select="@*"/>
<xsl:attribute name="count">
<xsl:value-of select="$count"/>
</xsl:attribute>
<xsl:if test="$correspondent = 'yes'">
<xsl:attribute name="correspondent">
<xsl:text>yes</xsl:text>
</xsl:attribute>
</xsl:if>
<xsl:copy-of select="*[not(self::snac:activeDate)]"/>
<xsl:choose>
<xsl:when test="$countActiveDates = 0"/>
<xsl:when test="$countActiveDates = 1">
<xsl:copy-of select="$activeDates/snac:activeDate"/>
</xsl:when>
<xsl:when test="$countActiveDates > 1">
<xsl:copy-of select="$activeDates/snac:activeDate[1]"/>
<xsl:copy-of select="$activeDates/snac:activeDate[position() = $countActiveDates]"/>
</xsl:when>
</xsl:choose>
<xsl:for-each select="$occupations/snac:occupation">
<xsl:copy-of select="."/>
</xsl:for-each>
</snac:entity>
</xsl:for-each>
</xsl:when>
<xsl:when test="snac:entity[@source = 'controlaccess']">
<xsl:for-each select="snac:entity[@source = 'controlaccess'][1]">
<snac:entity>
<xsl:copy-of select="@*"/>
<xsl:attribute name="count">
<xsl:value-of select="$count"/>
</xsl:attribute>
<xsl:if test="$correspondent = 'yes'">
<xsl:attribute name="correspondent">
<xsl:text>yes</xsl:text>
</xsl:attribute>
</xsl:if>
<xsl:copy-of select="*[not(self::snac:activeDate)]"/>
<xsl:choose>
<xsl:when test="$countActiveDates = 0"/>
<xsl:when test="$countActiveDates = 1">
<xsl:copy-of select="$activeDates/snac:activeDate"/>
</xsl:when>
<xsl:when test="$countActiveDates > 1">
<xsl:copy-of select="$activeDates/snac:activeDate[1]"/>
<xsl:copy-of select="$activeDates/snac:activeDate[position() = $countActiveDates]"/>
</xsl:when>
</xsl:choose>
<xsl:for-each select="$occupations/snac:occupation">
<xsl:copy-of select="."/>
</xsl:for-each>
</snac:entity>
</xsl:for-each>
</xsl:when>
<xsl:when test="snac:entity[@source = 'dsc']">
<xsl:for-each select="snac:entity[@source = 'dsc'][1]">
<snac:entity>
<xsl:copy-of select="@*"/>
<xsl:attribute name="count">
<xsl:value-of select="$count"/>
</xsl:attribute>
<xsl:if test="$correspondent = 'yes'">
<xsl:attribute name="correspondent">
<xsl:text>yes</xsl:text>
</xsl:attribute>
</xsl:if>
<xsl:copy-of select="*[not(self::snac:activeDate)]"/>
<xsl:choose>
<xsl:when test="$countActiveDates = 0"/>
<xsl:when test="$countActiveDates = 1">
<xsl:copy-of select="$activeDates/snac:activeDate"/>
</xsl:when>
<xsl:when test="$countActiveDates > 1">
<xsl:copy-of select="$activeDates/snac:activeDate[1]"/>
<xsl:copy-of select="$activeDates/snac:activeDate[position() = $countActiveDates]"/>
</xsl:when>
</xsl:choose>
<xsl:for-each select="$occupations/snac:occupation">
<xsl:copy-of select="."/>
</xsl:for-each>
</snac:entity>
</xsl:for-each>
</xsl:when>
<xsl:otherwise>
<error>Something went wrong in selecting the entity!</error>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:for-each>
</xsl:variable>
<!-- NORMALIZE STEP FOUR: Flags for discard all entries consisting of one name component when the component is
found in a name string with two or more components. -->
<xsl:variable name="normalizeStepFour">
<xsl:for-each select="$normalizeStepThree">
<xsl:variable name="singleTokenSet">
<xsl:for-each select="snac:entity[snac:normal/snac:persname]">
<xsl:if test="snac:countTokens(snac:normalForMatch) = 1">
<xsl:copy-of select="."/>
</xsl:if>
</xsl:for-each>
</xsl:variable>
<xsl:variable name="multipleTokenSet">
<xsl:for-each select="snac:entity[snac:normal/snac:persname]">
<xsl:if test="snac:countTokens(snac:normalForMatch) > 1">
<xsl:copy-of select="."/>
</xsl:if>
</xsl:for-each>
</xsl:variable>
<xsl:variable name="multipleTokenString">
<xsl:for-each select="snac:entity[snac:normal/snac:persname]">
<xsl:if test="snac:countTokens(snac:normalForMatch) > 1">
<xsl:value-of select="snac:normalForMatch"/>
<xsl:text> </xsl:text>
</xsl:if>
</xsl:for-each>
</xsl:variable>
<!-- check for each enitity/normalized for match -->
<xsl:for-each select="$singleTokenSet/snac:entity">
<xsl:variable name="tempString" as="xs:string">
<xsl:value-of select="snac:normalForMatch"/>
</xsl:variable>
<xsl:choose>
<xsl:when test="exists(index-of(tokenize($multipleTokenString, '\s'), snac:normalForMatch))">
<snac:entity discard="yes">
<xsl:copy-of select="@* | *"/>
</snac:entity>
</xsl:when>
<xsl:otherwise>
<xsl:copy-of select="."/>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
<xsl:for-each select="$multipleTokenSet/snac:entity">
<xsl:copy-of select="."/>
</xsl:for-each>
<xsl:for-each select="*[not(snac:normal/snac:persname)]">
<xsl:copy-of select="."/>
</xsl:for-each>
</xsl:for-each>
</xsl:variable>
<!-- NORMALIZE STEP FIVE: Adds the identifier component for each entity, c or r, and number -->
<!-- Is this the final step? -->
<xsl:variable name="normalizeStepFive">
<xsl:variable name="selectBioghist">
<xsl:call-template name="selectBioghist"/>
</xsl:variable>
<xsl:for-each select="$normalizeStepFour">
<xsl:variable name="originationCount">
<xsl:value-of select="count(snac:entity[@source = 'origination'])"/>
</xsl:variable>
<xsl:variable name="controlaccessCount">
<xsl:value-of select="count(snac:entity[@source = 'controlaccess'])"/>
</xsl:variable>
<xsl:for-each select="snac:entity[not(@discard = 'yes')]">
<snac:entity>
<xsl:copy-of select="@*"/>
<xsl:attribute name="recordId">
<xsl:value-of select="snac:getBaseIdName(snac:getFileName($eadPath))"/>
<xsl:choose>
<xsl:when test=".[@source = 'origination' and not(@discard = 'yes')]">
<xsl:text>.c</xsl:text>
<xsl:number count="snac:entity[@source = 'origination' and not(@discard = 'yes')]" format="01"/>
</xsl:when>
<xsl:otherwise>
<xsl:text>.r</xsl:text>
<xsl:number count="snac:entity[not(@source = 'origination') and not(@discard = 'yes')]" format="001"/>
</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
<xsl:attribute name="originationCount">
<xsl:value-of select="$originationCount"/>
</xsl:attribute>
<xsl:attribute name="controlaccessCount">
<xsl:value-of select="$controlaccessCount"/>
</xsl:attribute>
<snac:normalFinal>
<xsl:choose>
<xsl:when test="snac:normal[@type = 'attributeNormal']">
<xsl:copy-of select="snac:normal[@type = 'attributeNormal']"/>
</xsl:when>
<xsl:otherwise>
<xsl:copy-of select="snac:normal[@type = 'regExed']/*"/>
</xsl:otherwise>
</xsl:choose>
</snac:normalFinal>
<xsl:copy-of select="*"/>
</snac:entity>
</xsl:for-each>
</xsl:for-each>
<xsl:call-template name="aboutOriginationEntity">
<xsl:with-param name="eadPath" select="$eadPath"/>
</xsl:call-template>
</xsl:variable>
<!-- ****************************************************************** -->
<!-- ****************************************************************** -->
<!-- ****************************************************************** -->
<xsl:choose>
<xsl:when test="$processingType = 'rawExtract'">
<snac:oneFindingAid source="{$eadPath}">
<xsl:for-each select="$rawExtract">
<xsl:for-each select="*">
<xsl:copy-of select="."/>
</xsl:for-each>
</xsl:for-each>
</snac:oneFindingAid>
</xsl:when>
<xsl:when test="$processingType = 'stepOne'">
<snac:oneFindingAid source="{$eadPath}">
<xsl:for-each select="$normalizeStepOne">
<xsl:for-each select="*">
<xsl:copy-of select="."/>
</xsl:for-each>
</xsl:for-each>
</snac:oneFindingAid>
</xsl:when>
<xsl:when test="$processingType = 'stepTwo'">
<snac:oneFindingAid source="{$eadPath}">
<xsl:for-each select="$normalizeStepTwo">
<xsl:for-each select="*">
<xsl:copy-of select="."/>
</xsl:for-each>
</xsl:for-each>
</snac:oneFindingAid>
</xsl:when>
<xsl:when test="$processingType = 'stepThree'">
<snac:oneFindingAid source="{$eadPath}">
<xsl:for-each select="$normalizeStepThree">
<xsl:for-each select="*">
<xsl:copy-of select="."/>
</xsl:for-each>
</xsl:for-each>
</snac:oneFindingAid>
</xsl:when>
<xsl:when test="$processingType = 'stepFour'">
<snac:oneFindingAid source="{$eadPath}">
<xsl:for-each select="$normalizeStepFour">
<xsl:for-each select="*">
<xsl:copy-of select="."/>
</xsl:for-each>
</xsl:for-each>
</snac:oneFindingAid>
</xsl:when>
<xsl:when
test="
$processingType = 'stepFive' or $processingType = 'testCPF' or $processingType = 'testRD'
or $processingType = 'testJoin' or $processingType = 'allOR'">
<snac:oneFindingAid source="{$eadPath}">
<xsl:for-each select="$normalizeStepFive">
<xsl:for-each select="*">
<xsl:copy-of select="."/>
</xsl:for-each>
</xsl:for-each>
</snac:oneFindingAid>
</xsl:when>
</xsl:choose>
<!-- ****************************************************************** -->
<!-- ****************************************************************** -->
<!-- ****************************************************************** -->
<!-- end of for each document(.) -->
</xsl:for-each>
<!-- end of snac:i -->
</xsl:for-each>
<!-- end of each fileList batch -->
</xsl:variable>
<xsl:template match="/">
<xsl:choose>
<xsl:when test="$processingType = 'CPFOut'">
<xsl:for-each select="$process/*">
<xsl:variable name="recordId" select="./control/recordId"
xpath-default-namespace="http://ead3.archivists.org/schema/"/>
<xsl:result-document href="{$outputFolderPath}{$tempSourceID}/{$recordId}.xml" indent="yes">
<xsl:processing-instruction name="oxygen">
<xsl:text>RNGSchema="http://socialarchive.iath.virginia.edu/shared/cpf.rng" type="xml"</xsl:text>
</xsl:processing-instruction>
<xsl:text>
</xsl:text>
<xsl:copy-of select="."/>
</xsl:result-document>
</xsl:for-each>
</xsl:when>
<xsl:when test="$processingType = 'testRD'">
<xsl:call-template name="RD-OR"/>
</xsl:when>
<xsl:when test="$processingType = 'testCPF'">
<xsl:call-template name="CPF-OR"/>
</xsl:when>
<xsl:when test="$processingType = 'testJoin'">