-
Notifications
You must be signed in to change notification settings - Fork 1
/
ASPACE-METS-MARC.xsl
1435 lines (1255 loc) · 47.7 KB
/
ASPACE-METS-MARC.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 version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:marc="http://www.loc.gov/MARC21/slim" xmlns:mets="http://www.loc.gov/METS/"
xsi:schemaLocation="http://www.loc.gov/METS/ http://www.loc.gov/standards/mets/mets.xsd"
xmlns:mods="http://www.loc.gov/mods/v3" xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ead="urn:isbn:1-931666-22-9">
<!--
ASpace METS-MARC Stylesheet
Originally Created by LC
Re-factored to convert METS files exported from ArchivesSpace to MARC for ALMA
Requirements:
-Designed to work with one or more METS files from a *single* resource.
-Due to deficiences in ASPACE MARC export, the stylesheet must pull information from
the resources xml file, which should named 'ead.xml' and be in the same directory
as the stylesheet
-Concatenate all the individual METS files into a single file
-Remove extraneous xml declarations: <?xml version="1.0" encoding="UTF-8"?>
-Correct mets schema location output by ASpace so xslt will work:
Output: xsi:schemaLocation="http://www.loc.gov/standards/mets/mets.xsd"
Corrected: xsi:schemaLocation="http://www.loc.gov/METS/ http://www.loc.gov/standards/mets/mets.xsd"
-Put a wrapper element <daos> around the file
Transformation:
-Use an xlst 2.0 processor (e.g. use saxon)
Quality Control
- Use MarcEdit to convert the file from .xml to .mrc to .mrk
- Use Reports->MARCValidator to ensure the MARC is valid
- Use Reports->Field Count to make sure the expected number of required fields appeared (based on count of input daos)
- Use Ctrl+F to find and eyeball the following
- all 024 fields (=024)
- all 856 fields =856 40$3
- all 991 files (=991)
-->
<xsl:include href="MARC21slimUtils.xsl"/>
<xsl:variable name="ead" select="document('ead.xml')"/>
<xsl:variable name="relator" select="document('marc-relator-terms.xml')"/>
<xsl:output method="xml" indent="yes" encoding="UTF-8" omit-xml-declaration="yes"/>
<xsl:variable name="standalone">
<xsl:if test="$ead//ead:eadid/@url">
<xsl:text>FALSE</xsl:text>
</xsl:if>
<xsl:if test="not($ead//ead:eadid/@url)">
<xsl:text>TRUE</xsl:text>
</xsl:if>
</xsl:variable>
<xsl:template match="/daos">
<marc:collection>
<xsl:apply-templates/>
</marc:collection>
</xsl:template>
<xsl:template match="mets:metsHdr"/>
<xsl:template match="mets:dmdSec"/>
<xsl:template match="mets:dmdSec[1]">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="mets:amdSec"/>
<xsl:template match="mets:fileSec"/>
<xsl:template match="mets:structMap"/>
<!-- ead templates-->
<!--<xsl:template match="ead:c[descendant::ead:unitid=$unitid]">-->
<xsl:template match="ead:c">
<xsl:param name="unitid"/>
<xsl:if test="descendant::ead:unitid=$unitid">
<xsl:if test="ead:c[not(child::unitid=$unitid)]">
<marc:subfield code="g">
<xsl:value-of select="ead:did/ead:unittitle"/>
<xsl:text>, </xsl:text>
</marc:subfield>
</xsl:if>
</xsl:if>
<xsl:apply-templates select="ead:c">
<xsl:with-param name="unitid">
<xsl:value-of select="$unitid"/>
</xsl:with-param>
</xsl:apply-templates>
</xsl:template>
<!--mods templates-->
<xsl:template match="mods:mods">
<xsl:variable name="unitid">
<xsl:value-of
select="substring-before(/mets:mets/mets:fileSec/mets:fileGrp[1]/mets:file[1]/mets:FLocat/@xlink:href, '_000')"
/>
</xsl:variable>
<marc:record xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.loc.gov/MARC21/slim http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd">
<marc:leader>
<!-- 00-04 -->
<xsl:text> </xsl:text>
<!-- 05 -->
<xsl:text>n</xsl:text>
<!-- 06 -->
<xsl:apply-templates mode="leader" select="mods:typeOfResource[1]"/>
<!-- 07 -->
<xsl:choose>
<xsl:when test="$standalone='TRUE'">
<xsl:text>m</xsl:text>
</xsl:when>
<xsl:otherwise>
<!--archival subunit-->
<xsl:text>d</xsl:text>
</xsl:otherwise>
</xsl:choose>
<!-- 08 -->
<!--Default will be archival control for BC custom -->
<xsl:text>a</xsl:text>
<!-- 09 -->
<xsl:text>a</xsl:text>
<!-- 10 -->
<xsl:text>2</xsl:text>
<!-- 11 -->
<xsl:text>2</xsl:text>
<!-- 12-16 -->
<xsl:text> </xsl:text>
<!-- 17 -->
<xsl:text>7</xsl:text>
<!-- 18 -->
<xsl:text>i</xsl:text>
<!-- 19 -->
<xsl:text>#</xsl:text>
<!-- 20-23 -->
<xsl:text>4500</xsl:text>
</marc:leader>
<xsl:call-template name="controlRecordInfo"/>
<marc:controlfield tag="008">
<xsl:variable name="typeOf008">
<xsl:apply-templates mode="ctrl008" select="mods:typeOfResource"/>
</xsl:variable>
<!-- 00-05 -->
<xsl:choose>
<xsl:when test="ancestor::mets:mets/mets:metsHdr">
<xsl:value-of
select="translate(substring(ancestor::mets:mets/mets:metsHdr/@CREATEDATE,3,8),'-','')"
/>
</xsl:when>
<xsl:otherwise>
<xsl:text> </xsl:text>
</xsl:otherwise>
</xsl:choose>
<!-- 06 - 14 -->
<xsl:variable name="unitid">
<xsl:value-of
select="substring-before(ancestor::mets:mets/mets:fileSec/mets:fileGrp[1]/mets:file[1]/mets:FLocat/@xlink:href, '_000')"
/>
</xsl:variable>
<xsl:choose>
<xsl:when
test="substring-before($ead//ead:did[child::ead:unitid=$unitid]/ead:unitdate/@normal, '/')=substring-after($ead//ead:did[child::ead:unitid=$unitid]/ead:unitdate/@normal , '/')">
<xsl:text>s</xsl:text>
<xsl:value-of
select="substring($ead//ead:did[child::ead:unitid=$unitid]/ead:unitdate/@normal,1,4)"/>
<xsl:text>||||</xsl:text>
</xsl:when>
<xsl:otherwise>
<!--From Kathryn, for an item published somewhere in a probable range of years, the 008 06
code would be q (Questionable: Exact date for a single date item is not known but a range of
years for the date can be specified (e.g., between 1824 and 1846). m is more for multiple
items published over a span of years, or for a single item executed over a range of years,
like a painting.
If you can get close enough to guess at a single year, you would use s, even though it's a guess.-->
<xsl:choose>
<xsl:when test="$ead//ead:did[child::ead:unitid=$unitid]/ead:unitdate/@certainty='questionable'">
<xsl:text>q</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>m</xsl:text>
</xsl:otherwise>
</xsl:choose>
<xsl:value-of
select="substring($ead//ead:did[child::ead:unitid=$unitid]/ead:unitdate/@normal,1,4)"/>
<xsl:value-of
select="substring(substring-after($ead//ead:did[child::ead:unitid=$unitid]/ead:unitdate/@normal, '/'),1,4)"
/>
</xsl:otherwise>
</xsl:choose>
<!-- 15-17 -->
<xsl:choose>
<!-- v3 place -->
<xsl:when
test="mods:originInfo/mods:place/mods:placeTerm[@type='code'][@authority='marccountry']">
<!-- v3 fixed marc:code reference and authority change-->
<xsl:value-of
select="mods:originInfo/mods:place/mods:placeTerm[@type='code'][@authority='marccountry']"/>
<!-- 1/04 fix -->
<xsl:if
test="string-length(mods:originInfo/mods:place/mods:placeTerm[@type='code'][@authority='marccountry'])=2">
<xsl:text> </xsl:text>
</xsl:if>
</xsl:when>
<xsl:otherwise>
<xsl:text>mau</xsl:text>
</xsl:otherwise>
</xsl:choose>
<!-- 18-21 - MU -->
<xsl:if test="$typeOf008='MU'">
<xsl:text>||||</xsl:text>
</xsl:if>
<!-- 18-22 - MM -->
<xsl:if test="$typeOf008='MM'">
<xsl:text>#####</xsl:text>
</xsl:if>
<!-- 18-20 - VM -->
<xsl:if test="$typeOf008='VM'">
<xsl:text>nnn</xsl:text>
</xsl:if>
<!-- 18-21 - BK -->
<xsl:if test="$typeOf008='BK'">
<xsl:choose>
<xsl:when
test="mods:relatedItem/mods:part/mods:detail[1]/mods:title[text()='Anansi Stories']">
<xsl:text>ag||</xsl:text>
</xsl:when>
<xsl:otherwise>||||</xsl:otherwise>
</xsl:choose>
</xsl:if>
<!-- 21 -->
<xsl:choose>
<xsl:when test="$typeOf008='SE'">
<xsl:choose>
<xsl:when test="mods:genre[@authority='marc']='database'">d</xsl:when>
<xsl:when test="mods:genre[@authority='marc']='loose-leaf'">l</xsl:when>
<xsl:when test="mods:genre[@authority='marc']='newspaper'">n</xsl:when>
<xsl:when test="mods:genre[@authority='marc']='periodical'">p</xsl:when>
<xsl:when test="mods:genre[@authority='marc']='series'">m</xsl:when>
<xsl:when test="mods:genre[@authority='marc']='web site'">w</xsl:when>
<xsl:otherwise>|</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:when test="$typeOf008='VM'">
<xsl:text>#</xsl:text>
</xsl:when>
<xsl:otherwise/>
</xsl:choose>
<!-- 22 -->
<!-- 1/04 fix -->
<xsl:if
test="$typeOf008='BK' or $typeOf008='CF' or $typeOf008='MU' or $typeOf008='VM' ">
<xsl:choose>
<xsl:when test="mods:targetAudience[@authority='marctarget']">
<xsl:apply-templates mode="ctrl008"
select="mods:targetAudience[@authority='marctarget']"/>
</xsl:when>
<xsl:otherwise>|</xsl:otherwise>
</xsl:choose>
</xsl:if>
<!-- 23 -->
<xsl:choose>
<xsl:when
test="$typeOf008='BK' or $typeOf008='MU' or $typeOf008='SE' or $typeOf008='MM'"
>o</xsl:when>
</xsl:choose>
<!-- 24-27 -->
<xsl:choose>
<xsl:when test="$typeOf008='BK'">
<xsl:call-template name="controlField008-24-27"/>
</xsl:when>
<xsl:when test="$typeOf008='MP'">
<xsl:text>|</xsl:text>
<xsl:choose>
<xsl:when test="mods:genre[@authority='marc']='atlas'">e</xsl:when>
<xsl:when test="mods:genre[@authority='marc']='globe'">d</xsl:when>
<xsl:otherwise>|</xsl:otherwise>
</xsl:choose>
<xsl:text>||</xsl:text>
</xsl:when>
<xsl:when test="$typeOf008='CF'">
<xsl:text>||</xsl:text>
<xsl:choose>
<xsl:when test="mods:genre[@authority='marc']='database'">e</xsl:when>
<xsl:when test="mods:genre[@authority='marc']='font'">f</xsl:when>
<xsl:when test="mods:genre[@authority='marc']='game'">g</xsl:when>
<xsl:when test="mods:genre[@authority='marc']='numerical data'"
>a</xsl:when>
<xsl:when test="mods:genre[@authority='marc']='sound'">h</xsl:when>
<xsl:otherwise>|</xsl:otherwise>
</xsl:choose>
<xsl:text>|</xsl:text>
</xsl:when>
<xsl:when test="$typeOf008='VM'">
<xsl:text>#####</xsl:text>
</xsl:when>
<xsl:when test="$typeOf008='MU'">
<xsl:text>||||</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>####</xsl:text>
</xsl:otherwise>
</xsl:choose>
<!-- 28 -->
<xsl:choose>
<xsl:when test="$typeOf008='MU'">
<xsl:text>|</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>#</xsl:text>
</xsl:otherwise>
</xsl:choose>
<!-- 29 -->
<xsl:choose>
<xsl:when test="$typeOf008='BK' or $typeOf008='SE'">
<xsl:choose>
<xsl:when test="mods:genre[@authority='marc']='conference publication'"
>1</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:when test="$typeOf008='MP' or $typeOf008='VM'">
<xsl:text>0</xsl:text>
</xsl:when>
<xsl:when test="$typeOf008='MU'">
<xsl:text>|</xsl:text>
</xsl:when>
</xsl:choose>
<!-- 30-31 -->
<xsl:choose>
<xsl:when test="$typeOf008='BK'">
<xsl:choose>
<xsl:when test="mods:genre[@authority='marc']='festschrift'"
>1</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
<xsl:text>0</xsl:text>
</xsl:when>
<xsl:when test="$typeOf008='MU'">
<xsl:text>||</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>##</xsl:text>
</xsl:otherwise>
</xsl:choose>
<!-- 32 -->
<xsl:text>#</xsl:text>
<!-- 33 -->
<xsl:choose>
<xsl:when test="$typeOf008='VM'">
<xsl:choose>
<xsl:when test="mods:subject[@authority='gmgpc']/mods:topic='Prints'"
>c</xsl:when>
<xsl:otherwise>i</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:when test="$typeOf008='BK'">
<xsl:choose>
<xsl:when test="mods:genre[@authority='marc']='comic strip'"
>c</xsl:when>
<xsl:when test="mods:genre[@authority='marc']='fiction'">1</xsl:when>
<xsl:when test="mods:genre[@authority='marc']='essay'">e</xsl:when>
<xsl:when test="mods:genre[@authority='marc']='drama'">d</xsl:when>
<xsl:when test="mods:genre[@authority='marc']='humor, satire'"
>h</xsl:when>
<xsl:when test="mods:genre[@authority='marc']='letter'">i</xsl:when>
<xsl:when test="mods:genre[@authority='marc']='novel'">f</xsl:when>
<xsl:when test="mods:genre[@authority='marc']='short story'"
>j</xsl:when>
<xsl:when test="mods:genre[@authority='marc']='speech'">s</xsl:when>
<xsl:when
test="mods:relatedItem/mods:part/mods:detail[1]/mods:title[text()='Anansi Stories']"
>j</xsl:when>
<xsl:otherwise>|</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>|</xsl:otherwise>
</xsl:choose>
<!-- 34 -->
<xsl:choose>
<xsl:when test="$typeOf008='BK'">
<xsl:choose>
<xsl:when test="mods:genre[@authority='marc']='biography'">d</xsl:when>
</xsl:choose>
<xsl:choose>
<xsl:when
test="contains(mods:titleInfo[@usage='primary']/mods:title, 'Diary')"
>d</xsl:when>
<xsl:otherwise>|</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:when test="$typeOf008='VM'">
<xsl:text>n</xsl:text>
</xsl:when>
<xsl:when test="$typeOf008='MU'">
<xsl:text>#</xsl:text>
</xsl:when>
<xsl:otherwise>|</xsl:otherwise>
</xsl:choose>
<!-- 35-37 -->
<xsl:choose>
<!-- v3 language -->
<!-- BC Custom fixes LC bug, only language code, not text, should go to 008-->
<!-- handle bad data in athletics-->
<xsl:when
test="mods:relatedItem[@*]/mods:identifier[@type='accession number']='BC.1986.019'">
<xsl:text>zxx</xsl:text>
</xsl:when>
<xsl:when test="mods:language/mods:languageTerm[@type='code']">
<xsl:value-of select="mods:language/mods:languageTerm[@type='code']"/>
</xsl:when>
<xsl:otherwise>
<xsl:text>|||</xsl:text>
</xsl:otherwise>
</xsl:choose>
<!-- 38-39 -->
<xsl:text>#d</xsl:text>
</marc:controlfield>
<xsl:call-template name="marc024"/>
<xsl:call-template name="source"/>
<xsl:apply-templates/>
<!--temp Anansi data fix-->
<xsl:if test="not(mods:subject)">
<xsl:call-template name="datafield">
<xsl:with-param name="tag">655</xsl:with-param>
<xsl:with-param name="ind1"> </xsl:with-param>
<xsl:with-param name="ind2">7</xsl:with-param>
<xsl:with-param name="subfields">
<marc:subfield code="a">Manuscripts.</marc:subfield>
<marc:subfield code="2">gmgpc</marc:subfield>
</xsl:with-param>
</xsl:call-template>
</xsl:if>
<xsl:call-template name="burns-owner"/>
<xsl:if test="$standalone='FALSE'">
<xsl:call-template name="marc773"/>
</xsl:if>
<xsl:call-template name="marc856-FindingAid"/>
<xsl:call-template name="marc856-0bject"/>
<xsl:if test="$standalone = 'TRUE'">
<xsl:call-template name="standalone"/>
</xsl:if>
<xsl:call-template name="marc940"/>
<xsl:call-template name="marc991"/>
</marc:record>
</xsl:template>
<xsl:template match="mods:typeOfResource" mode="leader">
<xsl:choose>
<xsl:when test="text()='text'">t</xsl:when>
<!-- assumption all ASpace stuff is manuscript; made because ASpace METS export has no manuscript attribute-->
<xsl:when test="text()='cartographic' and @manuscript='yes'">f</xsl:when>
<xsl:when test="text()='cartographic'">e</xsl:when>
<xsl:when test="text()='notated music'">d</xsl:when>
<!-- v3 musical/non -->
<xsl:when test="text()='sound recording-nonmusical'">i</xsl:when>
<xsl:when test="text()='sound recording'">j</xsl:when>
<xsl:when test="text()='sound recording-musical'">j</xsl:when>
<xsl:when test="text()='still image'">k</xsl:when>
<xsl:when test="text()='moving image'">g</xsl:when>
<xsl:when test="text()='three dimensional object'">r</xsl:when>
<xsl:when test="text()='software, multimedia'">m</xsl:when>
<xsl:when test="text()='mixed material'">p</xsl:when>
</xsl:choose>
</xsl:template>
<xsl:template name="controlRecordInfo">
<!--<xsl:template match="mods:recordInfo">-->
<marc:controlfield tag="001">
<xsl:text>dao</xsl:text>
<xsl:value-of select="format-number(ancestor::mets:dmdSec/@ID, '0000000000')"/>
</marc:controlfield>
<marc:controlfield tag="003">ArchivesSpace</marc:controlfield>
<xsl:choose>
<xsl:when test="mods:typeOfResource='text'">
<marc:controlfield tag="006">m####|o##d########</marc:controlfield>
</xsl:when>
<xsl:when test="mods:typeOfResource='still image'">
<marc:controlfield tag="006">m####|o##c########</marc:controlfield>
</xsl:when>
<xsl:when test="mods:typeOfResource='mixed material'">
<marc:controlfield tag="006">m####|o##m########</marc:controlfield>
</xsl:when>
<xsl:when test="mods:typeOfResource='notated music'">
<marc:controlfield tag="006">m####|o##c########</marc:controlfield>
</xsl:when>
</xsl:choose>
<xsl:choose>
<xsl:when test="mods:physicalDescription/mods:digitalOrigin='born digital'">
<marc:controlfield tag="007">cr#cz#||||||||</marc:controlfield>
<!--useless test-->
</xsl:when>
<xsl:otherwise>
<marc:controlfield tag="007">cr#cz#|||||a||</marc:controlfield>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="mods:typeOfResource" mode="ctrl008">
<xsl:choose>
<xsl:when test="text()='text' and @manuscript='yes'">BK</xsl:when>
<xsl:when test="text()='text'">
<xsl:choose>
<xsl:when test="../mods:originInfo/mods:issuance='monographic'">BK</xsl:when>
<xsl:when test="../mods:originInfo/mods:issuance='continuing'">SE</xsl:when>
<xsl:otherwise>BK</xsl:otherwise>
<!-- ASPACE does not have mods:issuance-->
</xsl:choose>
</xsl:when>
<xsl:when test="text()='cartographic' and @manuscript='yes'">MP</xsl:when>
<xsl:when test="text()='cartographic'">MP</xsl:when>
<xsl:when test="text()='notated music' and @manuscript='yes'">MU</xsl:when>
<xsl:when test="text()='notated music'">MU</xsl:when>
<xsl:when test="text()='sound recording'">MU</xsl:when>
<!-- v3 musical/non -->
<xsl:when test="text()='sound recording-nonmusical'">MU</xsl:when>
<xsl:when test="text()='sound recording-musical'">MU</xsl:when>
<xsl:when test="text()='still image'">VM</xsl:when>
<xsl:when test="text()='still image' and @manuscript='yes'">VM</xsl:when>
<xsl:when test="text()='moving image'">VM</xsl:when>
<xsl:when test="text()='three dimensional object'">VM</xsl:when>
<xsl:when test="text()='software, multimedia'">CF</xsl:when>
<xsl:when test="text()='mixed material'">MM</xsl:when>
</xsl:choose>
</xsl:template>
<xsl:template name="controlField008-24-27">
<xsl:variable name="chars">
<xsl:for-each select="mods:genre[@authority='marc']">
<xsl:choose>
<xsl:when test=".='abstract of summary'">a</xsl:when>
<xsl:when test=".='bibliography'">b</xsl:when>
<xsl:when test=".='catalog'">c</xsl:when>
<xsl:when test=".='dictionary'">d</xsl:when>
<xsl:when test=".='directory'">r</xsl:when>
<xsl:when test=".='discography'">k</xsl:when>
<xsl:when test=".='encyclopedia'">e</xsl:when>
<xsl:when test=".='filmography'">q</xsl:when>
<xsl:when test=".='handbook'">f</xsl:when>
<xsl:when test=".='index'">i</xsl:when>
<xsl:when test=".='law report or digest'">w</xsl:when>
<xsl:when test=".='legal article'">g</xsl:when>
<xsl:when test=".='legal case and case notes'">v</xsl:when>
<xsl:when test=".='legislation'">l</xsl:when>
<xsl:when test=".='patent'">j</xsl:when>
<xsl:when test=".='programmed text'">p</xsl:when>
<xsl:when test=".='review'">o</xsl:when>
<xsl:when test=".='statistics'">s</xsl:when>
<xsl:when test=".='survey of literature'">n</xsl:when>
<xsl:when test=".='technical report'">t</xsl:when>
<xsl:when test=".='theses'">m</xsl:when>
<xsl:when test=".='treaty'">z</xsl:when>
</xsl:choose>
</xsl:for-each>
</xsl:variable>
<xsl:call-template name="makeSize">
<xsl:with-param name="string" select="$chars"/>
<xsl:with-param name="length" select="4"/>
</xsl:call-template>
</xsl:template>
<xsl:template name="makeSize">
<xsl:param name="string"/>
<xsl:param name="length"/>
<xsl:variable name="nstring" select="normalize-space($string)"/>
<xsl:variable name="nstringlength" select="string-length($nstring)"/>
<xsl:choose>
<xsl:when test="$nstringlength>$length">
<xsl:value-of select="substring($nstring,1,$length)"/>
</xsl:when>
<xsl:when test="$nstringlength<$length">
<xsl:value-of select="$nstring"/>
<xsl:call-template name="buildSpaces">
<xsl:with-param name="spaces" select="$length - $nstringlength"/>
<xsl:with-param name="char">|</xsl:with-param>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$nstring"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="source">
<xsl:call-template name="datafield">
<xsl:with-param name="tag">040</xsl:with-param>
<xsl:with-param name="subfields">
<marc:subfield code="a">MChB-B</marc:subfield>
<marc:subfield code="b">eng</marc:subfield>
<marc:subfield code="c">MChB-B</marc:subfield>
<marc:subfield code="e">dacs</marc:subfield>
</xsl:with-param>
</xsl:call-template>
</xsl:template>
<xsl:template name="marc024">
<xsl:call-template name="datafield">
<xsl:with-param name="tag">024</xsl:with-param>
<xsl:with-param name="ind1">7</xsl:with-param>
<xsl:with-param name="subfields">
<marc:subfield code="a">
<xsl:text>2345.2/</xsl:text>
<xsl:value-of
select="substring-before(ancestor::mets:mets/mets:fileSec/mets:fileGrp[1]/mets:file[1]/mets:FLocat/@xlink:href, '_000')"
/>
</marc:subfield>
<marc:subfield code="2">hdl</marc:subfield>
</xsl:with-param>
</xsl:call-template>
</xsl:template>
<xsl:template match="mods:dateCreated"/>
<!--personal name-->
<xsl:template match="mods:name[@type='personal']">
<xsl:choose>
<!-- <xsl:when test="self::node()[1] and ancestor::mods:mods/descendant::mods:roleTerm[text()='pht' or text()='cre' or text()='aut' or text()='crp']/@type='code'">-->
<xsl:when
test="self::node()[1] and self::node()/descendant::mods:roleTerm[text()='creator']/@type='text'">
<xsl:call-template name="datafield">
<xsl:with-param name="tag">100</xsl:with-param>
<xsl:with-param name="ind1">1</xsl:with-param>
<xsl:with-param name="subfields">
<marc:subfield code="a">
<xsl:value-of select="mods:namePart[@type='family']"/>
<xsl:text>, </xsl:text>
<xsl:value-of select="mods:namePart[@type='given'][1]"/>
<xsl:choose>
<xsl:when
test="mods:namePart[@type='date'] or (mods:namePart[@type='termsOfAddress'] != '')">
<xsl:text>, </xsl:text>
</xsl:when>
<xsl:when test="mods:namePart[@type='given'][2]">
<marc:subfield code="q">
<xsl:text>(</xsl:text>
<xsl:value-of select="mods:namePart[@type='given'][2]"/>
<xsl:text>)</xsl:text>
</marc:subfield>
</xsl:when>
<xsl:when test="mods:role">,</xsl:when>
<xsl:otherwise>.</xsl:otherwise>
</xsl:choose>
</marc:subfield>
<!-- v3 termsOfAddress -->
<xsl:for-each select="mods:namePart[@type='termsOfAddress']">
<xsl:if test="mods:namePart[@type='termsOfAddress'] != ''">
<marc:subfield code="c">
<xsl:value-of
select="string-length(mods:namePart[@type='termsOfAddress'])"/>
<!--<xsl:if
test="mods:namePart[@type='date'] or following-sibling::mods:role">
<xsl:text>,</xsl:text>
</xsl:if>-->
</marc:subfield>
</xsl:if>
</xsl:for-each>
<xsl:variable name="unitid">
<xsl:value-of
select="substring-before(/mets:mets/mets:fileSec/mets:fileGrp[1]/mets:file[1]/mets:FLocat/@xlink:href, '_000')"
/>
</xsl:variable>
<xsl:if
test="$ead//ead:did[child::ead:unitid=$unitid]/ead:origination[@label='creator']/ead:persname">
<xsl:variable name="date">
<xsl:value-of
select="substring-after(substring-after($ead//ead:did[child::ead:unitid=$unitid]/ead:origination[@label='creator']/ead:persname, ','),',')"
/>
</xsl:variable>
<xsl:if test="string-length($date) > 3">
<marc:subfield code="d">
<xsl:value-of select="normalize-space($date)"/>
<xsl:text>,</xsl:text>
</marc:subfield>
</xsl:if>
</xsl:if>
<!-- v3 role -->
<xsl:variable name="code">
<xsl:value-of
select="$ead//ead:did[child::ead:unitid=$unitid]/ead:origination[@label='creator']/ead:persname/@role"
/>
</xsl:variable>
<marc:subfield code="e">
<xsl:value-of
select="$relator//marc-relator-terms/relator[child::code=$code]/term"/>
<xsl:text>.</xsl:text>
</marc:subfield>
<marc:subfield code="4">
<xsl:value-of
select="$ead//ead:did[child::ead:unitid=$unitid]/ead:origination[@label='creator']/ead:persname/@role"
/>
</marc:subfield>
<xsl:for-each select="mods:affiliation">
<marc:subfield code="u">
<xsl:value-of select="."/>
</marc:subfield>
</xsl:for-each>
<xsl:for-each select="mods:description">
<marc:subfield code="g">
<xsl:value-of select="."/>
</marc:subfield>
</xsl:for-each>
</xsl:with-param>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="datafield">
<xsl:with-param name="tag">700</xsl:with-param>
<xsl:with-param name="ind1">1</xsl:with-param>
<xsl:with-param name="subfields">
<marc:subfield code="a">
<xsl:value-of select="mods:namePart[@type='family']"/>
<xsl:if
test="mods:namePart[@type='family']and mods:namePart[@type='given']"
>, </xsl:if>
<xsl:value-of select="mods:namePart[@type='given']"/>
<xsl:choose>
<xsl:when
test="not(mods:namePart[@type='termsofAddress'] or mods:namePart[@type='date'] or mods:role)"
>.</xsl:when>
<xsl:otherwise>,</xsl:otherwise>
</xsl:choose>
</marc:subfield>
<xsl:for-each select="mods:namePart[@type='termsOfAddress']">
<marc:subfield code="c">
<xsl:value-of select="."/>
<xsl:text>,</xsl:text>
</marc:subfield>
</xsl:for-each>
<xsl:for-each select="mods:namePart[@type='date']">
<marc:subfield code="d">
<xsl:value-of select="."/>
<xsl:text>,</xsl:text>
</marc:subfield>
</xsl:for-each>
<xsl:for-each select="mods:role/mods:roleTerm[@type='text']">
<marc:subfield code="e">
<xsl:value-of select="lower-case(.)"/>
<xsl:text>.</xsl:text>
</marc:subfield>
</xsl:for-each>
<xsl:for-each select="mods:role/mods:roleTerm[@type='code']">
<marc:subfield code="4">
<xsl:value-of select="."/>
</marc:subfield>
</xsl:for-each>
<xsl:for-each select="mods:affiliation">
<marc:subfield code="u">
<xsl:value-of select="."/>
</marc:subfield>
</xsl:for-each>
</xsl:with-param>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!-- Title Info elements -->
<xsl:template match="mods:titleInfo[not(ancestor-or-self::mods:subject)][not(@type)][1]">
<xsl:param name="ind1-245">
<!-- determine if title main entry-->
<xsl:choose>
<xsl:when
test="ancestor::mods:mods/descendant::mods:roleTerm[text()='creator']/@type='text'">
<xsl:text>1</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>0</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:param>
<xsl:call-template name="datafield">
<xsl:with-param name="tag">245</xsl:with-param>
<xsl:with-param name="ind1" select="$ind1-245"/>
<xsl:with-param name="ind2" select="string-length(mods:nonSort)"/>
<xsl:with-param name="subfields">
<xsl:call-template name="titleInfo"/>
</xsl:with-param>
</xsl:call-template>
</xsl:template>
<xsl:template name="titleInfo">
<xsl:choose>
<xsl:when test="$standalone='TRUE' and mods:title !=$ead//ead:archdesc[@level='collection']/ead:did/ead:unittitle">
<marc:subfield code="a">
<xsl:value-of select="normalize-space($ead//ead:archdesc[@level='collection']/ead:did/ead:unittitle)"/>
<xsl:text>.</xsl:text>
</marc:subfield>
</xsl:when>
<xsl:otherwise>
<xsl:for-each select="mods:title">
<marc:subfield code="a">
<xsl:value-of select="../mods:nonSort"/>
<xsl:value-of select="normalize-space(.)"/>
<xsl:text>.</xsl:text>
</marc:subfield>
</xsl:for-each>
</xsl:otherwise>
</xsl:choose>
<!-- 1/04 fix -->
<xsl:for-each select="mods:subTitle">
<marc:subfield code="b">
<xsl:value-of select="."/>
</marc:subfield>
</xsl:for-each>
<xsl:for-each select="mods:partNumber">
<marc:subfield code="n">
<xsl:value-of select="."/>
</marc:subfield>
</xsl:for-each>
<xsl:for-each select="mods:partName">
<marc:subfield code="p">
<xsl:value-of select="."/>
</marc:subfield>
</xsl:for-each>
</xsl:template>
<xsl:template name="marc264">
<xsl:variable name="unitid">
<xsl:value-of
select="substring-before(ancestor::mets:mets/mets:fileSec/mets:fileGrp[1]/mets:file[1]/mets:FLocat/@xlink:href, '_000')"
/>
</xsl:variable>
<xsl:call-template name="datafield">
<xsl:with-param name="tag">264</xsl:with-param>
<xsl:with-param name="ind2">0</xsl:with-param>
<xsl:with-param name="subfields">
<marc:subfield code="c">
<xsl:value-of select="$ead//ead:did[child::ead:unitid=$unitid]/ead:unitdate"/>
<xsl:if test="not(substring($ead//ead:did[child::ead:unitid=$unitid]/ead:unitdate, string-length($ead//ead:did[child::ead:unitid=$unitid]/ead:unitdate),1)='?')">
<xsl:text>.</xsl:text>
</xsl:if>
</marc:subfield>
</xsl:with-param>
</xsl:call-template>
</xsl:template>
<xsl:template name="marc300">
<xsl:call-template name="datafield">
<xsl:with-param name="tag">300</xsl:with-param>
<xsl:with-param name="subfields">
<marc:subfield code="a">
<xsl:text>1 online resource (</xsl:text>
<xsl:choose>
<xsl:when test="contains(ancestor::mets:mets/mets:fileSec/mets:fileGrp[1]/mets:file[position()=last], 'target')">
<xsl:value-of
select="count(ancestor::mets:mets/mets:fileSec/mets:fileGrp[1]/mets:file) - 1"/>
<xsl:text> image</xsl:text>
<xsl:if
test="count(ancestor::mets:mets/mets:fileSec/mets:fileGrp[1]/mets:file) > 2">
<xsl:text>s</xsl:text>
</xsl:if>
</xsl:when>
<xsl:otherwise>
<xsl:value-of
select="count(ancestor::mets:mets/mets:fileSec/mets:fileGrp[1]/mets:file)"/>
<xsl:text> image</xsl:text>
<xsl:if
test="count(ancestor::mets:mets/mets:fileSec/mets:fileGrp[1]/mets:file) > 1">
<xsl:text>s</xsl:text>
</xsl:if>
</xsl:otherwise>
</xsl:choose>
<xsl:text>)</xsl:text>
</marc:subfield>
</xsl:with-param>
</xsl:call-template>
</xsl:template>
<xsl:template match="mods:typeOfResource">
<xsl:call-template name="marc264"/>
<xsl:call-template name="marc300"/>
<xsl:choose>
<xsl:when test="text()='still image'">
<xsl:call-template name="datafield">
<xsl:with-param name="tag">336</xsl:with-param>
<xsl:with-param name="subfields">
<marc:subfield code="a">still image</marc:subfield>
<marc:subfield code="b">
<xsl:value-of select="substring(. , 1, 3)"/>
</marc:subfield>
<marc:subfield code="2">
<xsl:text>rdacontent</xsl:text>
</marc:subfield>
</xsl:with-param>
</xsl:call-template>
</xsl:when>
<xsl:when test="text()='text'">
<xsl:call-template name="datafield">
<xsl:with-param name="tag">336</xsl:with-param>
<xsl:with-param name="subfields">
<marc:subfield code="a">
<xsl:value-of select="."/>
</marc:subfield>
<marc:subfield code="b">
<xsl:text>txt</xsl:text>
</marc:subfield>
<marc:subfield code="2">
<xsl:text>rdacontent</xsl:text>
</marc:subfield>
</xsl:with-param>
</xsl:call-template>
</xsl:when>
<xsl:when test="text()='notated music'">
<xsl:call-template name="datafield">
<xsl:with-param name="tag">336</xsl:with-param>
<xsl:with-param name="subfields">
<marc:subfield code="a">
<xsl:value-of select="."/>
</marc:subfield>
<marc:subfield code="b">
<xsl:text>ntm</xsl:text>
</marc:subfield>
<marc:subfield code="2">
<xsl:text>rdacontent</xsl:text>
</marc:subfield>
</xsl:with-param>
</xsl:call-template>