-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEAD3_to_LUX.xsl
1363 lines (1228 loc) · 66.8 KB
/
EAD3_to_LUX.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"
xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:ead3="http://ead3.archivists.org/schema/"
xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:saxon="http://saxon.sf.net/"
xmlns:map="http://www.w3.org/2005/xpath-functions/map"
xmlns:mdc="http://mdc"
xmlns:j="http://www.w3.org/2005/xpath-functions" version="3.0">
<!-- author(s): Mark Custer... you? and you??? anyone else who wants to help! -->
<!-- requires XSLT 3.0 -->
<xsl:output method="text"/>
<xsl:strip-space elements="*"/>
<xsl:preserve-space elements="ead3:p"/>
<xsl:include href="ead3-to-html.xsl"/>
<xsl:include href="relators.xsl"/>
<xsl:include href="collections_in_repositories.xsl"/>
<xsl:key name="relator-code" match="relator" use="code"/>
<!-- to do:
review how languages are serialized once we upgrade.
can likely split out the notes better, if data is added to descriptiveNote moving forward.
fix how the HTML conversion is handled. no need to do silly text stuff.
finish usage rights
include acquisition dates ???
add onsite/offsite locations
e.g. physloc localtype="whatever"
(will also have a colleciton-level summary in a notestmt/controlnote in next round of exports)
etc.
-->
<!--
questions:
1) should everything aside from YCBA and Peabody get "Special Collections (YUL)" now? this was the generic General Collection before.
2)
-->
<!-- now that we add @altrenders, should we change this function? -->
<xsl:function name="mdc:find-the-ultimate-parent-id" as="xs:string">
<!-- given that there can be multiple parent/id pairings, this occasionally recursive function will find and select the top container ID attribute, which will be used to do the groupings, rather than depenidng on entirely document order -->
<xsl:param name="current-container" as="node()"/>
<xsl:variable name="parent" select="$current-container/@parent"/>
<xsl:choose>
<xsl:when test="not($parent)">
<xsl:value-of select="$current-container/@id"/>
</xsl:when>
<xsl:otherwise>
<xsl:sequence select="mdc:find-the-ultimate-parent-id($current-container/preceding-sibling::ead3:container[@id eq $parent])"/>
</xsl:otherwise>
</xsl:choose>
</xsl:function>
<xsl:function name="mdc:convert-to-date" as="xs:date">
<xsl:param name="standarddate" as="xs:string"/>
<xsl:variable name="date-numbers" select="for $num in tokenize($standarddate, '-') return number($num)"/>
<xsl:variable name="year">
<xsl:value-of select="format-number($date-numbers[1], '0001')"/>
</xsl:variable>
<xsl:variable name="month">
<xsl:value-of select="if ($date-numbers[2]) then format-number($date-numbers[2], '01') else '01'"/>
</xsl:variable>
<xsl:variable name="day">
<xsl:value-of select="if ($date-numbers[3]) then format-number($date-numbers[3], '01') else '01'"/>
</xsl:variable>
<xsl:variable name="date-string">
<xsl:value-of select="$year, $month, $day" separator="-"/>
</xsl:variable>
<xsl:value-of select="xs:date($date-string)"/>
</xsl:function>
<xsl:function name="mdc:convert-duration" as="xs:string">
<xsl:param name="duration" as="node()"/>
<!-- the label just specifies up to 3 milliseconds, so that's all we'll allow here, although there could certainly be more.
-->
<xsl:variable name="duration-statment" as="item()*">
<xsl:analyze-string select="normalize-space($duration)" regex="^(\d\d):(\d\d):(\d\d\.?\d{{0,3}}$)">
<xsl:matching-substring>
<xsl:variable name="hours" select="number(regex-group(1))"/>
<xsl:variable name="minutes" select="number(regex-group(2))"/>
<xsl:variable name="seconds" select="number(regex-group(3))"/>
<xsl:sequence select="(if ($hours eq 0) then ()
else $hours || ' hours', if ($minutes eq 0) then () else $minutes || ' minutes',
if ($seconds eq 0) then () else $seconds || ' seconds')"/>
</xsl:matching-substring>
</xsl:analyze-string>
</xsl:variable>
<xsl:value-of select="$duration-statment" separator=", "/>
</xsl:function>
<!-- 1) global parameters and variables -->
<!--
https://git.yale.edu/raw/LUX/json-schema-validation/master/schema.json
https://git.yale.edu/mc2343/json-schema-validation/raw/master/schema.json
/Users/markcuster/Documents/GitYale/json-schema-validation/schema.json
-->
<xsl:param name="json_schema_location" select="'https://git.yale.edu/raw/LUX/json-schema-validation/master/schema.json'"/>
<xsl:param name="output-directory">
<xsl:choose>
<xsl:when test="$split-files">
<xsl:value-of select="concat('../ArchivesSpace-JSON-Lines/', $repo-code, '/')"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="concat('../ArchivesSpace-JSON/', $repo-code, '/', $collection-ID-text, '/')"/>
</xsl:otherwise>
</xsl:choose>
</xsl:param>
<!-- change this to true to create one json file for each archival component, including the archdesc;
when set to false, each EAD file produces a single json file for the archdesc. not used when $split-files is set to true. -->
<xsl:param name="include-dsc-in-transformation" select="true()"/>
<!-- inherit container option. might want to change this and add an open list for inheritible elements. currently not used. -->
<xsl:param name="inherit-containers" select="true()"/>
<!-- can be combined with system-id to get public uri -->
<xsl:param name="base-url" select="'https://archives.yale.edu'"/>
<xsl:param name="isPartOf-URI-prefix"/>
<!-- don't have a good way to do this yet, but should include a switch for it. right now, we always include it. -->
<xsl:param name="includeHTML" select="true()"/>
<xsl:param name="newline" select="'
'"/>
<!-- this determines whether we go into JSON Lines mode or not. pass false during testing. -->
<xsl:param name="split-files" select="true()"/>
<!-- this number determines the max number of lines in a JSON lines file. we have a few collections with more than 10k, so we'll use that as a test case (we don't have any over 50k, though). -->
<!-- was requested to change this to 5k -->
<xsl:param name="split-at" as="xs:integer" select="5000"/>
<!-- parameter for the serilization map, below.
for jsonl, though, we'll always keep this set to false... so, just adding two different variables for that now.
for testing, we'll set to true()...-->
<xsl:param name="indent" select="true()"/>
<!-- note that saxon:property-order requires saxon pe or ee -->
<!-- also, update this later since the only change is whether we indent or not! should just update that one value when not using jsonlines -->
<xsl:variable name="serialization-map" select="map{
'method':'json',
'encoding': 'utf-8',
'indent': $indent,
QName('http://saxon.sf.net/', 'property-order'): '$schema record identifiers basic_descriptors titles measurements notes languages agents places dates subjects locations rights digital_assets hierarchies * subject_facets supertypes',
'use-character-maps': map{'/': '/'}}"/>
<xsl:variable name="jsonl-serialization-map" select="map{
'method':'json',
'encoding': 'utf-8',
'indent': false(),
QName('http://saxon.sf.net/', 'property-order'): '$schema record identifiers basic_descriptors titles measurements notes languages agents places dates subjects locations rights digital_assets hierarchies * subject_facets supertypes',
'use-character-maps': map{'/': '/'}}"/>
<xsl:variable name="collection-ID" select="ead3:ead/ead3:control/ead3:recordid"/>
<xsl:variable name="collection-ID-text" select="$collection-ID/normalize-space()"/>
<xsl:variable name="collection-URI" select="$collection-ID/@instanceurl/normalize-space()"/>
<xsl:variable name="repo-code" select="if (contains($collection-ID-text, '.')) then substring-before($collection-ID-text, '.') else null"/>
<xsl:variable name="collection-call-number" select="ead3:ead/ead3:archdesc/ead3:did/ead3:unitid[not(@audience='internal')][1]/normalize-space()"/>
<!-- also, YCBA-IA and OHAM (and Beinecke Ndy) use no separators. in those cases, it's just code+number, eg. S001 -->
<!-- could probably just grab the first character in those cases, but right now I still have no idea what they mean, if anything -->
<xsl:variable name="curatorial-code-separator" select="if ($repo-code eq 'ypm') then '.' else ' '"/>
<!-- need to change this logic for other edge cases, like Beinecke "NdyXXX" call numbers. for now, those just get added to Special Collections (YUL). -->
<xsl:variable name="curatorial-code" select="$collection-call-number => substring-before($curatorial-code-separator) => upper-case()"/>
<!-- consider changing to archdesc/did/repository, since the corpname element could actually have an @identifier attribute available there. the publisher element, on the other hand, could only have an id attribute.-->
<xsl:variable name="repository-name" select="ead3:ead/ead3:control/ead3:filedesc/ead3:publicationstmt/ead3:publisher[1]/normalize-space()"/>
<!-- only 1 for the entire collection right now, but could add the archival object timestamps if needed if we add to the EAD3 exports -->
<xsl:variable name="last-updated" select="ead3:ead/ead3:control/ead3:maintenancehistory/ead3:maintenanceevent[1]/ead3:eventdatetime[1]/replace(., '\+00:00', 'Z')"/>
<!-- should everything from ASpace get this now, aside from YCBA and Peabody??? -->
<xsl:variable name='default-general-collection-name' select="'Special Collections (YUL)'"/>
<xsl:variable name="local-access-restriction-types" select="map{
'RestrictedSpecColl': 'Donor/university imposed access restriction',
'RestrictedCurApprSpecColl': 'Repository imposed access restriction',
'RestrictedFragileSpecColl': 'Restricted fragile',
'InProcessSpecColl': 'Restricted in-process',
'UseSurrogate': 'Use surrogate'
}"/>
<xsl:variable name="did-note-type-label-backups" select="map{
'abstract': 'Abstract',
'dimensions': 'Dimensions',
'langmaterial': 'Language',
'materialspec': 'Material Details',
'physdesc': 'Physical Description',
'physfacet': 'Physical Facet',
'physlocal': 'Physical Location'
}"/>
<xsl:variable name="subject-facet-types" select="map{
'agent_corporate_entity': 'organization',
'agent_family': 'family',
'agent_person': 'person',
'cultural_context': 'culture',
'genre_form': 'genre',
'geographic': 'place',
'temporal': 'period',
'topical': 'topic',
'uniform_title': 'title'
}"/>
<!-- not a label, i don't think, but that's the example from the spreadsheet documentation, so i'm going with it for now... -->
<xsl:param name="default-metadata-rights-label" select="'CC0 1.0 Universal (CC0 1.0) Public Domain Dedication'"/>
<xsl:param name="default-metadata-rights-URI" select="'https://creativecommons.org/publicdomain/zero/1.0/'"/>
<xsl:param name="default-metadata-identifier-prefix" select="'aspace-'"/>
<xsl:variable name="repo-email" select="ead3:ead/ead3:control[1]/ead3:filedesc[1]/ead3:publicationstmt[1]/ead3:address[1]/ead3:addressline[@localtype='email']"/>
<!-- 2) primary template section -->
<xsl:template match="ead3:ead">
<xsl:if test="@audience='internal'">
<xsl:message terminate="yes">
<xsl:value-of select="$collection-ID-text"/>
<xsl:text> is unpublished, so we're skipping it.</xsl:text>
</xsl:message>
</xsl:if>
<xsl:if test="not($repo-code)">
<xsl:message terminate="yes">
<xsl:text>No recordid, so we're skipping this collection. Fix please!</xsl:text>
</xsl:message>
</xsl:if>
<xsl:choose>
<xsl:when test="$split-files eq true()">
<xsl:for-each-group select="ead3:archdesc, ead3:archdesc/ead3:dsc//ead3:c" group-adjacent="(position() - 1) idiv $split-at">
<xsl:variable name="filename" select="$output-directory || $collection-ID-text || '-' || format-number(current-grouping-key() + 1, '000') || '.jsonl'"/>
<xsl:result-document href="{$filename}">
<xsl:apply-templates select="current-group()" mode="split-files"/>
</xsl:result-document>
</xsl:for-each-group>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="ead3:archdesc[not(@audience='internal')]"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!-- all components, including the archdesc, start here -->
<!-- this process creates one file per level of description -->
<!-- using ead3:c, but if we had to deal with both, could use a match for c, c0, c1 essentially-->
<xsl:template match="ead3:archdesc | ead3:c">
<xsl:param name="archdesc-level" select="if (local-name() eq 'archdesc') then true() else false()"/>
<xsl:variable name="component-ID" select="if (@id)
then $collection-ID-text || '-' || @id => normalize-space() => replace('aspace_', '')
else $collection-ID-text || '-' || generate-id(.)"/>
<xsl:variable name="component-name">
<xsl:sequence select="ead3:did/ead3:unittitle[not(@audience='internal')]/string-join(normalize-space(.), '; ')"/>
</xsl:variable>
<xsl:variable name="filename">
<xsl:choose>
<xsl:when test="$archdesc-level eq true()">
<xsl:value-of select="$output-directory || $collection-ID-text || '.json'"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$output-directory || $component-ID || '.json'"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:result-document href="{$filename}">
<xsl:variable name="xml">
<xsl:call-template name="create-xml">
<xsl:with-param name="archdesc-level" select="$archdesc-level"/>
<xsl:with-param name="component-name" select="$component-name"/>
<xsl:with-param name="component-ID" select="$component-ID"/>
</xsl:call-template>
</xsl:variable>
<xsl:sequence select="$xml => xml-to-json() => parse-json() => serialize($serialization-map)"/>
</xsl:result-document>
<!-- when the include-dsc-in-transformation value is set to true, then all of the component templates will be processed by this same template recursively. -->
<xsl:if test="$include-dsc-in-transformation eq true()">
<xsl:apply-templates select="ead3:dsc/ead3:c[not(@audience='internal')] | ead3:c[not(@audience='internal')]"/>
</xsl:if>
</xsl:template>
<xsl:template match="ead3:archdesc | ead3:c" mode="split-files">
<xsl:param name="archdesc-level" select="if (local-name() eq 'archdesc') then true() else false()"/>
<xsl:variable name="component-ID" select="if (@id)
then $collection-ID-text || '-' || @id => normalize-space() => replace('aspace_', '')
else $collection-ID-text || '-' || generate-id(.)"/>
<xsl:variable name="component-name">
<xsl:sequence select="ead3:did/ead3:unittitle[not(@audience='internal')]/string-join(normalize-space(.), '; ')"/>
</xsl:variable>
<xsl:variable name="xml">
<xsl:call-template name="create-xml">
<xsl:with-param name="archdesc-level" select="$archdesc-level"/>
<xsl:with-param name="component-name" select="$component-name"/>
<xsl:with-param name="component-ID" select="$component-ID"/>
</xsl:call-template>
</xsl:variable>
<xsl:sequence select="$xml => xml-to-json() => parse-json() => serialize($jsonl-serialization-map)"/>
<!-- now that's what i call json lines, yeah -->
<xsl:value-of select="$newline"/>
</xsl:template>
<!-- here's where we create the XML document in order to convert it to JSON.
will eventually shorten this template by adding others, most likely.-->
<xsl:template name="create-xml">
<xsl:param name="component-name"/>
<xsl:param name="archdesc-level"/>
<xsl:param name="component-ID"/>
<xsl:variable name="level-of-description" select="@level => lower-case() => normalize-space()"/>
<!-- new, for Yale's updated EAD exporter in ASpace -->
<xsl:variable name="aspace-id" select="@altrender"/>
<!-- for us, we'll just have one of these. we'll also expand these to include series identifiers at lower levels.
e.g. OSB MSS 176, Series I -->
<!--
string-join(ancestor::*[@level=('collection', 'recordgrp', 'series')]/did/unitid, ', ')
plus add series id of current component.
-->
<xsl:variable name="EAD-unitid">
<xsl:value-of select="if ($archdesc-level) then '' else ead3:did/ead3:unitid[not(@audience='internal')][1]/normalize-space()"/>
</xsl:variable>
<xsl:variable name="Voyager-BIB-ID" select="../ead3:control/ead3:otherrecordid[@localtype='BIB'][1]/normalize-space()"/>
<xsl:variable name="container-groupings">
<xsl:for-each-group select="ead3:did/ead3:container" group-by="mdc:find-the-ultimate-parent-id(.)">
<container-group>
<xsl:copy-of select="current-group()"/>
</container-group>
</xsl:for-each-group>
</xsl:variable>
<j:map>
<!-- schema declarartion -->
<j:string key="$schema">
<xsl:value-of select="$json_schema_location"/>
</j:string>
<j:map key="record">
<!-- field has been changed to the timestamp of LUX ingestion.... so, we don't know that any more.
because of that, we won't vend anything here, but leaving in the "last-updated" / exported from ASpace value in as an example.
<j:string key="metadata_arrived_in_LUX">
<xsl:value-of select="$last-updated"/>
</j:string>
-->
<j:string key="metadata_identifier">
<xsl:value-of select="$default-metadata-identifier-prefix || replace($aspace-id, '^/repositories/\d*/', '') => replace('s/|_', '-')"/>
</j:string>
<j:string key="metadata_rights_label">
<xsl:value-of select="$default-metadata-rights-label"/>
</j:string>
<j:array key="metadata_rights_URI">
<j:string>
<xsl:value-of select="$default-metadata-rights-URI"/>
</j:string>
</j:array>
</j:map>
<!-- identifiers -->
<j:array key="identifiers">
<j:map>
<j:string key="identifier_value">
<xsl:choose>
<xsl:when test="$archdesc-level and $collection-ID">
<xsl:value-of select="$collection-ID"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$component-ID"/>
</xsl:otherwise>
</xsl:choose>
</j:string>
<j:string key="identifier_type">
<xsl:text>ead</xsl:text>
</j:string>
</j:map>
<j:map>
<j:string key="identifier_value">
<xsl:value-of select="$collection-call-number"/>
</j:string>
<j:string key="identifier_display">
<xsl:value-of select="$collection-call-number"/>
</j:string>
<j:string key="identifier_type">
<xsl:value-of select="'call number'"/>
</j:string>
<j:string key="identifier_label">
<xsl:text>Call Number</xsl:text>
</j:string>
</j:map>
<xsl:for-each select="ancestor::ead3:c[not(@audience='internal')][@level=('collection', 'fonds', 'recordgrp', 'series')][ead3:did/ead3:unitid/normalize-space()]">
<j:map>
<j:string key="identifier_value">
<xsl:value-of select="ead3:did/ead3:unitid/normalize-space()"/>
</j:string>
<j:string key="identifier_type">
<xsl:value-of select="@level || ' unitid'"/>
</j:string>
</j:map>
</xsl:for-each>
<xsl:if test="$EAD-unitid != '' and not($archdesc-level)">
<j:map>
<j:string key="identifier_value">
<xsl:value-of select="$EAD-unitid"/>
</j:string>
<j:string key="identifier_display">
<xsl:value-of select="$EAD-unitid"/>
</j:string>
<j:string key="identifier_type">
<xsl:text>unitid</xsl:text>
</j:string>
<j:string key="identifier_label">
<xsl:value-of select="if ($EAD-unitid) then 'Identifier' else ()"/>
</j:string>
</j:map>
</xsl:if>
<xsl:if test="$Voyager-BIB-ID">
<j:map>
<!-- adding "yul:" as per the YUL examples -->
<j:string key="identifier_value">
<xsl:value-of select="'yul:' || $Voyager-BIB-ID"/>
</j:string>
<j:string key="identifier_type">
<xsl:text>voyager bib id</xsl:text>
</j:string>
</j:map>
</xsl:if>
</j:array>
<!-- basic descriptors (not a grouping element) -->
<j:map key="basic_descriptors">
<xsl:call-template name="supertypes"/>
<!--
<j:string key="edition_display"/>
<j:string key="imprint_display"/>
-->
<!-- what could we map here???
<j:array key="materials_display"/>
-->
<!-- used to go to notes, now mapping here since these have been untangled from rights -->
<j:array key="provenance_display">
<xsl:apply-templates select="ead3:custodhist" mode="array-wrapped-notes"/>
</j:array>
<j:array key="acquisition_source_display">
<xsl:apply-templates select="ead3:acqinfo" mode="array-wrapped-notes"/>
</j:array>
</j:map>
<!-- titles -->
<j:array key="titles">
<!-- don't need all of this internal stuff since we already process the EAD, but what the hay -->
<xsl:call-template name="combine-title-and-date"/>
</j:array>
<!--measurements
what to map here?? -->
<!-- since this field is no longer required, i don't need to "values?" param anymore -->
<xsl:if test="ead3:did/ead3:physdescstructured">
<j:array key="measurements">
<xsl:apply-templates select="ead3:did/ead3:physdescstructured" mode="measurements"/>
</j:array>
</xsl:if>
<!-- notes (plus container info, for now) -->
<j:array key="notes">
<xsl:apply-templates select="$container-groupings/container-group"/>
<xsl:apply-templates select="
ead3:did/ead3:abstract |
ead3:did/ead3:dimensions (: add elsewhere? :) |
ead3:did/ead3:langmaterial[ead3:descriptivenote] | (: language codes/values are passed to the langauges array. here, we just grab any other notes. :)
ead3:did/ead3:materialspec |
ead3:did/ead3:physdesc[not(@localtype='container_summary')] (: definitely elsewhere :) |
ead3:did/ead3:physfacet |
ead3:did/ead3:physloc |
ead3:accruals |
ead3:altformavail |
ead3:appraisal |
ead3:arrangement |
ead3:bibliography |
ead3:bioghist |
ead3:fileplan |
ead3:index |
ead3:legalstatus |
ead3:odd |
ead3:originalsloc |
ead3:otherfindaid |
ead3:phystech |
ead3:prefercite |
ead3:processinfo |
ead3:relatedmaterial |
ead3:scopecontent |
ead3:separatedmaterial" mode="notes"/>
</j:array>
<!-- languages -->
<j:array key="languages">
<!-- either need a note note here, or just continue to pass the langmaterial/descriptivenote to the notes array -->
<xsl:apply-templates select="ead3:did/ead3:langmaterial/ead3:language" mode="languages"/>
</j:array>
<!-- agents -->
<j:array key="agents">
<xsl:apply-templates select="ead3:did/ead3:origination"/>
</j:array>
<!-- places -->
<!-- what to map here? probably can only map our geogrpahic headings as subjects... and
those could really be subjects and not "places", with specific roles, associated with the material
<j:array key="places">
<j:map>
<j:string key="place_display"/>
<j:array key="place_URI"/>
<j:string key="place_role_label"/>
<j:string key="place_role_code"/>
<j:array key="place_role_URI"/>
<j:string key="place_type_display"/>
<j:array key="place_type_URI"/>
<j:array key="place_coordinates_display"/>
<j:array key="place_coordinates_type"/>
</j:map>
</j:array>
-->
<!-- dates -->
<j:array key="dates">
<xsl:apply-templates select="ead3:did/ead3:unitdate | ead3:did/ead3:unitdatestructured"/>
</j:array>
<!-- subjects -->
<j:array key="subjects">
<!-- we don't need to worry about ead3:controlaccess/ead3:head or anything else like that.. just the subjects! -->
<!-- update this if we map the geognames to 'places' instead. maybe only geognames with a single part? -->
<xsl:apply-templates select="ead3:controlaccess/*" mode="subjects"/>
</j:array>
<!-- locations -->
<j:array key="locations">
<j:map>
<!-- hopefully we can change the names when the JSON schema is revised -->
<j:array key="campus_division">
<j:string>
<xsl:value-of select="if ($repo-code eq 'ypm') then 'Yale Peabody Museum of Natural History'
else if ($repo-code eq 'ycba') then 'Yale Center for British Art'
else 'Yale University Library'"/>
</j:string>
</j:array>
<!-- what about YCBA, Peabody? just leave out, right? -->
<j:array key="yul_holding_institution">
<xsl:if test="not($repo-code = ('ypm', 'ycba'))">
<j:string>
<xsl:value-of select="if (contains($repository-name, 'Arts Library')) then 'Haas Arts Library' else $repository-name"/>
</j:string>
</xsl:if>
</j:array>
<xsl:call-template name="collections"/>
<!-- could do something here about on-site vs. off-site, but need guidance on this. ditto for a lot of stuff here. -->
<j:array key="access_in_repository_display">
<j:map>
<j:string key="value">
<xsl:apply-templates select="ead3:did" mode="access_notes"/>
</j:string>
</j:map>
</j:array>
<j:array key="access_in_repository_URI">
<j:string>
<xsl:value-of select="$base-url || $aspace-id"/>
</j:string>
</j:array>
<!-- email or webpage -->
<j:string key="access_contact_in_repository">
<xsl:value-of select="$repo-email"/>
</j:string>
</j:map>
</j:array>
<j:array key="rights">
<xsl:call-template name="rights"/>
</j:array>
<!-- exclude this key if there are none??? -->
<!-- also, this data model doesn't work very well for ASpace. ASpace can have digital object sets, but LUX cannot.
i think the main use case here is digital object links, thumbnails, and outbound links to metadata (e.g. IIIF manifests).
propose a simplification for digital_assets in the next revision -->
<j:array key="digital_assets">
<xsl:apply-templates select="ead3:did/ead3:daoset/ead3:dao[@href]| ead3:did/ead3:dao[@href]"/>
</j:array>
<!-- hierarchies -->
<j:array key="hierarchies">
<xsl:variable name="level-of-description">
<xsl:choose>
<xsl:when test="$archdesc-level">
<xsl:text>Collection</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:sequence select="if ($level-of-description eq 'recordgrp') then 'Record Group'
else if ($level-of-description eq 'subgrp') then 'Subgroup'
else if ($level-of-description eq 'otherlevel') then concat(upper-case(substring(@otherlevel,1,1)),
substring(@otherlevel, 2),
' '[not(last())])
else concat(upper-case(substring($level-of-description,1,1)),
substring($level-of-description, 2),
' '[not(last())])"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<!-- might need to be a bit more robust here.... could add an option to inherit containers? -->
<!-- is that hacky test sufficient to work for peabody finding aids that don't have containers? -->
<xsl:variable name="deliverable-unit-test" select="if (ead3:did/ead3:container |
ead3:did/ead3:dao and not(ead3:c) or (not(ead3:c) and $repo-code eq 'ypm')) then '; Deliverable Unit' else ()"/>
<j:map>
<j:string key="hierarchy_type">
<xsl:value-of select="'EAD' || '; ' || $level-of-description || $deliverable-unit-test"/>
</j:string>
<j:string key="root_internal_identifier">
<xsl:value-of select="$base-url || (if (self::ead3:archdesc) then $aspace-id else ancestor-or-self::ead3:archdesc/@altrender)"/>
</j:string>
<j:number key="descendant_count">
<xsl:value-of select="count(descendant::ead3:c)"/>
</j:number>
<!-- what's the real definition of this? should it be max depth of the collection, or max depth of the context node? -->
<!-- let's go with context node. you can always get the max max depth from the collection/archdesc node -->
<j:number key="maximum_depth">
<xsl:variable name="current-max-depth" select="(max(descendant::ead3:c[not(ead3:c)]/count(ancestor::ead3:c)), 0)[1]" as="xs:integer"/>
<!-- only add archdesc to the ancestor count if there are any components -->
<xsl:value-of select="if (self::ead3:archdesc and $current-max-depth ne 0) then $current-max-depth + 1 else $current-max-depth"/>
</j:number>
<j:number key="sibling_count">
<xsl:value-of select="if (self::ead3:archdesc) then 0 else count(../ead3:c) - 1"/>
</j:number>
<!-- add the ASpace stuff here -->
<j:array key="ancestor_internal_identifiers">
<xsl:apply-templates select="ancestor::*[local-name() = ('archdesc', 'c')]/@altrender" mode="ancestor-array"/>
</j:array>
<!-- not used, but adding since it's required by the json schema -->
<j:array key="ancestor_URIs"/>
<j:array key="ancestor_display_names">
<xsl:apply-templates select="ancestor::*[local-name() = ('archdesc', 'c')]/ead3:did" mode="ancestor-array"/>
</j:array>
</j:map>
</j:array>
<!-- citations array would go here, but need to figure out how / if we can map this. for Papyrus, we should have something to map,
but not sure if / how to use ead3:bibliography here. need to evaluate data / ask staff -->
</j:map>
</xsl:template>
<!-- EAD mappings -->
<xsl:template match="@altrender" mode="ancestor-array">
<j:string>
<xsl:value-of select="$base-url || ."/>
</j:string>
</xsl:template>
<xsl:template match="ead3:did" mode="ancestor-array">
<j:string>
<xsl:if test="../@level = 'series' and ead3:unitid">
<xsl:value-of select="ead3:unitid/normalize-space() || '. '"/>
</xsl:if>
<xsl:choose>
<xsl:when test="ead3:unittitle">
<!-- we can only have one, but update if that ever changes in ASpace -->
<xsl:apply-templates select="ead3:unittitle" mode="#current"/>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="ead3:unitdate | ead3:unitdatestructured" mode="add-dates-to-title"/>
</xsl:otherwise>
</xsl:choose>
</j:string>
</xsl:template>
<!-- would it be better to create a variable with the notes?? -->
<xsl:template match="ead3:did" mode="access_notes">
<xsl:call-template name="access_notes">
<xsl:with-param name="repo-code" select="$repo-code"/>
<xsl:with-param name="collection-URI" select="$collection-URI"/>
</xsl:call-template>
</xsl:template>
<xsl:template name="combine-title-and-date">
<!-- also need to deal with inherited titles here. e.g. if not ead3:did/ead3:unittitle,
specify type = 'inherited'
and grab archival object or archdesc title -->
<xsl:variable name="inherited" select="if (not(ead3:did/ead3:unittitle[not(@audience='internal')])) then true() else false()" as="xs:boolean"/>
<j:map>
<j:array key="title_display">
<j:map>
<j:string key="value">
<xsl:apply-templates select="if ($inherited)
then ancestor::ead3:*[ead3:did/ead3:unittitle][1]/ead3:did/ead3:unittitle
else ead3:did/ead3:unittitle"/>
<!-- if no title, ASpace requires a date, but let's add a check regardless -->
<xsl:if test="ead3:did/ead3:unitdate | ead3:did/ead3:unitdatestructured">
<xsl:text>, </xsl:text>
</xsl:if>
<xsl:apply-templates select="ead3:did/ead3:unitdate | ead3:did/ead3:unitdatestructured" mode="add-dates-to-title"/>
</j:string>
</j:map>
</j:array>
<j:string key="title_type">
<xsl:value-of select="if ($inherited) then 'inherited' else 'primary'"/>
</j:string>
<j:string key="title_label">
<xsl:value-of select="'Primary'"/>
</j:string>
</j:map>
</xsl:template>
<xsl:template name="rights">
<xsl:apply-templates select="ead3:accessrestrict | ead3:userestrict"/>
</xsl:template>
<xsl:template name="sub-rights-fields">
<j:array key="original_rights_URI">
<j:string>
<xsl:value-of select="if ($repo-code = 'beinecke' and self::ead3:userestrict)
then 'https://beinecke.library.yale.edu/research-teaching/copyright-questions'
else ''"/>
<!-- follow up on this with all of the repos -->
</j:string>
</j:array>
</xsl:template>
<xsl:template name="supertypes">
<j:array key="supertypes">
<!-- default for everything described in ASpace, for now -->
<j:array>
<j:string>Archival and Manuscript Material</j:string>
</j:array>
<!-- DRY this up and move to a function or named template once we have the full set of mappings -->
<xsl:if test="some $t in ead3:did/ead3:physdescstructured/ead3:unittype satisfies matches($t, 'audio|phonograph', 'i')">
<j:array>
<j:string>Time-Based Media</j:string>
<j:string>Audio</j:string>
</j:array>
</xsl:if>
<xsl:if test="some $t in ead3:did/ead3:physdescstructured/ead3:unittype satisfies matches($t, 'video|film', 'i')">
<j:array>
<j:string>Time-Based Media</j:string>
<j:string>Moving Images</j:string>
</j:array>
</xsl:if>
<xsl:if test="some $t in ead3:did/ead3:physdescstructured/ead3:unittype satisfies matches($t, 'painting', 'i')">
<j:array>
<j:string>Two-Dimensional Objects</j:string>
<j:string>Paintings</j:string>
</j:array>
</xsl:if>
<xsl:if test="some $t in ead3:did/ead3:physdescstructured/ead3:unittype satisfies matches($t, 'photo', 'i')">
<j:array>
<j:string>Two-Dimensional Objects</j:string>
<j:string>Photographs</j:string>
</j:array>
</xsl:if>
</j:array>
</xsl:template>
<xsl:template match="ead3:accessrestrict | ead3:userestrict">
<j:map>
<j:string key="original_rights_status_display">
<!-- we can't really do anything with userestrict here, right? -->
<xsl:if test="self::ead3:accessrestrict">
<xsl:value-of select="for $t in tokenize(@localtype, ' ')
return map:get($local-access-restriction-types, $t)" separator="; "/>
</xsl:if>
</j:string>
<!-- woops. shouldn't have made this required in v9 of the JSON schema. -->
<j:array key="original_rights_copyright_credit_display">
<j:map>
<j:string key="value"/>
</j:map>
</j:array>
<!-- this is difficult to untangle, since we have access vs. use notes. will likely need to consult with staff and come up with mapping logic-->
<j:array key="original_rights_notes">
<j:string>
<xsl:apply-templates/>
</j:string>
</j:array>
<j:string key="original_rights_type">
<xsl:value-of select="if (self::ead3:accessrestrict) then 'access' else 'usage'"/>
</j:string>
<!-- more sighs -->
<j:string key="original_rights_type_label">
<xsl:value-of select="if (self::ead3:accessrestrict) then 'Access' else 'Usage'"/>
</j:string>
<xsl:call-template name="sub-rights-fields"/>
</j:map>
</xsl:template>
<!-- digital_assets stuff, but just for the daos that we're mapping currently -->
<xsl:template match="ead3:dao">
<xsl:variable name="primary" as="xs:boolean">
<xsl:value-of select="if (count(../preceding-sibling::ead3:daoset) eq 0) then true()
else if (parent::ead3:did and count(preceding-sibling::ead3:dao) eq 0) then true() else false()"/>
</xsl:variable>
<j:map>
<!--
optional properties: data not stored in ASpace, so not vending currently
asset_rights_status_display / string
asset_rights_notes / array string
asset_rights_type / string
asset_rights_type_label / string
asset_type / string (might be able to add this from ASpace, but folks currently don't record it)
-->
<j:array key="asset_URI">
<j:string>
<xsl:value-of select="@href"/>
</j:string>
</j:array>
<xsl:if test="@show eq 'embed' and $primary">
<j:string key="asset_flag">
<xsl:value-of select="'primary image'"/>
</j:string>
</xsl:if>
<xsl:if test="@linktitle">
<j:array key="asset_caption_display">
<j:map>
<j:string key="value">
<xsl:value-of select="@linktitle"/>
</j:string>
</j:map>
</j:array>
</xsl:if>
<j:string key="asset_type">
<xsl:value-of select="if (@show eq 'embed') then 'thumbnail' else if (starts-with(@href, 'https://soundcloud')) then 'soundcloud' else 'digital object link'"/>
</j:string>
</j:map>
</xsl:template>
<!-- add all the notes here, aside from the ones that are mapped elsewhere -->
<xsl:template match="ead3:*" mode="notes">
<j:map>
<j:array key="note_display">
<!-- don't have the ablity in ASpace to denote different languages and descriptions, aside from at the finding-level, so right now
leaving out those options and just providing the display "value".-->
<j:map>
<j:string key="value">
<!-- note that we are currently suppressing "ead3:head", but better to be more explicit here in the transformation.-->
<xsl:apply-templates select="if (local-name() = ('langmaterial')) then ead3:descriptivenote else (text() | * except ead3:head)"/>
</j:string>
</j:map>
</j:array>
<j:string key="note_type">
<xsl:value-of select="local-name()"/>
</j:string>
<j:string key="note_label">
<xsl:value-of select="if (ead3:head) then ead3:head[1]/normalize-space()
else if (@label) then normalize-space(@label)
else if (map:contains($did-note-type-label-backups, local-name())) then map:get($did-note-type-label-backups, local-name())
else ()"/>
</j:string>
</j:map>
</xsl:template>
<!-- just "acqinfo" and "custodhist" currently, both of which are mapped to "basic_descriptors" -->
<xsl:template match="ead3:*" mode="array-wrapped-notes">
<j:map>
<!-- don't have the ablity in ASpace to denote different languages and descriptions, aside from at the finding-level, so right now
leaving out those options and just providing the display "value".-->
<j:string key="value">
<xsl:apply-templates select="text() | * except ead3:head"/>
</j:string>
</j:map>
</xsl:template>
<xsl:template match="ead3:language" mode="languages">
<j:map>
<!-- prolly gotta do something for notes that have text -->
<j:string key="language_display">
<xsl:apply-templates/>
</j:string>
<j:string key="language_code">
<xsl:value-of select="normalize-space(@langcode)"/>
</j:string>
<j:array key="language_URI">
<j:string>
<xsl:value-of select="if (@langcode) then 'http://id.loc.gov/vocabulary/languages/' || normalize-space(@langcode) else ''"/>
</j:string>
</j:array>
<!-- advocate for scriptcodes, too, or agree to use IETF BCP 47 and add to language_code above? -->
</j:map>
</xsl:template>
<xsl:template match="ead3:origination">
<xsl:variable name="relator" select="*/normalize-space(@relator)"/>
<j:map>
<j:array key="agent_display">
<j:map>
<j:string key="value">
<xsl:apply-templates/>
</j:string>
</j:map>
</j:array>
<j:string key="agent_sortname">
<xsl:apply-templates/>
</j:string>
<j:array key="agent_URI">
<j:string>
<xsl:value-of select="*/normalize-space(@identifier)"/>
</j:string>
</j:array>
<j:string key="agent_role_label">
<xsl:choose>
<xsl:when test="$relator">
<xsl:value-of select="key('relator-code', $relator, $cached-list-of-relators)/label"/>
</xsl:when>
<!-- should parameratize the Creator/Contributor so that they are configuration options, but just adding them as is for now -->
<xsl:when test="lower-case(@label) eq 'source'">
<xsl:value-of select="'Source'"/>
</xsl:when>
<xsl:when test="(lower-case(@label) eq 'creator') and not(preceding-sibling::ead3:origination[lower-case(@label) eq 'creator'])">
<xsl:value-of select="'Creator'"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="'Contributor'"/>
</xsl:otherwise>
</xsl:choose>
</j:string>
<j:string key="agent_role_code">
<xsl:value-of select="$relator"/>
</j:string>
<j:array key="agent_role_URI">
<j:string>
<xsl:if test="$relator">
<xsl:value-of select="'http://id.loc.gov/vocabulary/relators/' || $relator"/>
</xsl:if>
</j:string>
</j:array>
<j:string key="agent_type_display">
<xsl:choose>
<xsl:when test="ead3:persname">
<xsl:text>person</xsl:text>
</xsl:when>
<xsl:when test="ead3:corpname">
<xsl:text>organization</xsl:text>
</xsl:when>
<xsl:when test="ead3:famname">
<xsl:text>family</xsl:text>
</xsl:when>
<xsl:otherwise>
<!-- in ASpace, it would default to Software, but let's say Unknown for now since it would likely be mistake if indicated as such -->
<xsl:text>unknown</xsl:text>
</xsl:otherwise>
</xsl:choose>
<!-- or just filter out sources from LUX? -->
</j:string>
<j:array key="agent_type_URI">
<j:string>
<xsl:choose>
<xsl:when test="ead3:persname">
<xsl:text>http://id.loc.gov/ontologies/bibframe/Person</xsl:text>
</xsl:when>
<xsl:when test="ead3:corpname">
<xsl:text>http://id.loc.gov/ontologies/bibframe/Organization</xsl:text>
</xsl:when>
<xsl:when test="ead3:famname">
<xsl:text>http://id.loc.gov/ontologies/bibframe/Family</xsl:text>
</xsl:when>
<!-- in ASpace, it would default to Software, but let's just keep this blank for now -->
<xsl:otherwise/>
</xsl:choose>
</j:string>
</j:array>
<!-- ask if this should be a number... and whether we start at 0, 1, or whatever -->