-
Notifications
You must be signed in to change notification settings - Fork 4
/
EAD_prep-for-pdf-preview.xsl
337 lines (318 loc) · 15.3 KB
/
EAD_prep-for-pdf-preview.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
<?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:mdc="http://www.local-functions/mdc"
xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:ead="urn:isbn:1-931666-22-9"
exclude-result-prefixes="xs mdc xlink ead" version="2.0">
<xsl:include href="EAD2002_id_head_values.xsl"/>
<xsl:output method="xml" encoding="UTF-8"/>
<xsl:function name="mdc:iso-date-2-display-form" as="xs:string*">
<xsl:param name="date" as="xs:string"/>
<xsl:variable name="months"
select="
('January',
'February',
'March',
'April',
'May',
'June',
'July',
'August',
'September',
'October',
'November',
'December')"/>
<xsl:analyze-string select="$date" flags="x" regex="(\d{{4}})(\d{{2}})?(\d{{2}})?">
<xsl:matching-substring>
<!-- year -->
<xsl:value-of select="regex-group(1)"/>
<!-- month (can't add an if,then,else '' statement here without getting an extra space at the end of the result-->
<xsl:if test="regex-group(2)">
<xsl:value-of select="subsequence($months, number(regex-group(2)), 1)"/>
</xsl:if>
<!-- day -->
<xsl:if test="regex-group(3)">
<xsl:number value="regex-group(3)" format="1"/>
</xsl:if>
<!-- still need to handle time... but if that's there, then I can just use xs:dateTime !!!! -->
</xsl:matching-substring>
</xsl:analyze-string>
</xsl:function>
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="ead:eadheader[not(ead:eadid/text())]">
<ead:eadheader audience="internal" countryencoding="iso3166-1" dateencoding="iso8601" findaidstatus="edited-full-draft" langencoding="iso639-2b" repositoryencoding="iso15511" scriptencoding="iso15924">
<ead:eadid>...</ead:eadid>
<ead:filedesc>
<ead:titlestmt>
<ead:titleproper type="formal">Guide to the ...</ead:titleproper>
<ead:titleproper audience="internal" type="filing">...</ead:titleproper>
<ead:author>by... you!</ead:author>
</ead:titlestmt>
<ead:publicationstmt>
<ead:publisher>Yale University Special Collections</ead:publisher>
<ead:address>
<ead:addressline>New Haven, Connecticut</ead:addressline>
</ead:address>
</ead:publicationstmt>
<ead:notestmt>
<ead:note type="bpg">
<ead:p>This encoded finding aid is compliant with the Yale EAD Best Practice Guidelines,
Version 1.0.</ead:p>
</ead:note>
</ead:notestmt>
</ead:filedesc>
<ead:profiledesc>
<ead:langusage>Finding aid written in
<ead:language langcode="eng" scriptcode="Latn">English</ead:language>.</ead:langusage>
<ead:descrules>Describing Archives: A Content Standard</ead:descrules>
</ead:profiledesc>
</ead:eadheader>
</xsl:template>
<xsl:template
match="ead:archdesc/ead:did[starts-with(ead:unitid, 'temp')][ead:physdesc/ead:extent eq '0 linear_feet']">
<xsl:copy>
<ead:head>Overview</ead:head>
<xsl:copy-of select="ead:unitid"/>
<ead:unittitle label="Title:">TTK</ead:unittitle>
<ead:unitdate calendar="gregorian" datechar="creation" era="ce" label="Dates:" type="inclusive">...</ead:unitdate>
<ead:physdesc label="Physical Description:">
<ead:extent>...</ead:extent>
</ead:physdesc>
<ead:repository label="Repository:">
<ead:corpname>Yale University Special Collections</ead:corpname>
</ead:repository>
</xsl:copy>
<ead:descgrp id="ai" type="admininfo">
<ead:head>Administrative Information</ead:head>
<ead:descgrp id="prov" type="provenance">
<ead:head>Provenance</ead:head>
<ead:acqinfo id="acq">
<ead:head>
<xsl:value-of select="$acqinfo_head"/>
</ead:head>
<ead:p>....</ead:p>
</ead:acqinfo>
</ead:descgrp>
<ead:accessrestrict id="acc">
<ead:head>Information about Access</ead:head>
<ead:p>...</ead:p>
</ead:accessrestrict>
<ead:userestrict id="use">
<ead:head>Ownership & Copyright</ead:head>
<ead:p>...</ead:p>
</ead:userestrict>
<ead:prefercite id="pre">
<ead:head>Cite As</ead:head>
<ead:p>...</ead:p>
</ead:prefercite>
<ead:processinfo id="pro">
<ead:head>Processing Notes</ead:head>
<ead:p>...</ead:p>
</ead:processinfo>
</ead:descgrp>
</xsl:template>
<xsl:template
match="
ead:c[not(@id)] |
ead:*[matches(local-name(), '^c0|c1')][not(@id)]">
<xsl:copy>
<xsl:attribute name="id" select="generate-id()"/>
<xsl:apply-templates select="@*"/>
<xsl:apply-templates select="node()"/>
</xsl:copy>
</xsl:template>
<!-- MDC: new additions for new data-entry rules in ArchivesSpace !!! -->
<xsl:template match="ead:*[@level = 'series']/ead:did/ead:unitid[matches(., '^\d+$')]">
<xsl:variable name="roman-numeral">
<xsl:number value="." format="I"/>
</xsl:variable>
<xsl:copy>
<xsl:if test="not(@id)">
<xsl:attribute name="id" select="generate-id()"/>
</xsl:if>
<xsl:apply-templates select="@*"/>
<xsl:value-of select="concat('Series ', $roman-numeral)"/>
</xsl:copy>
</xsl:template>
<xsl:template match="ead:unitdate[@type ne 'bulk'] | ead:unitdate[not(@type)]">
<xsl:copy>
<xsl:copy-of select="@* except @label"/>
<xsl:attribute name="label">
<xsl:value-of select="$unitdate_label_inclusive"/>
</xsl:attribute>
<xsl:if test="not(@calendar)">
<xsl:attribute name="calendar">
<xsl:text>gregorian</xsl:text>
</xsl:attribute>
</xsl:if>
<xsl:if test="not(@era)">
<xsl:attribute name="era">
<xsl:text>ce</xsl:text>
</xsl:attribute>
</xsl:if>
<xsl:if test="not(@datechar)">
<xsl:attribute name="datechar">
<xsl:text>creation</xsl:text>
</xsl:attribute>
</xsl:if>
<!-- example to deal with:
<unitdate normal="1901-02/1951-04-28" type="inclusive">1901-02-1951-04-28</unitdate>
<unitdate normal="2015-05-05/2015-05-05" type="inclusive">2015-05-05</unitdate>
i'd like to use xs:date, but i can't use that on values like 2015-05, so I'll have to roll my own function for this?
i also shouldn't create a new date string if the current text field contains any characters aside from spaces, hyphens, or numbers.
-->
<xsl:choose>
<xsl:when test="not(@normal) or matches(replace(., '/|-', ''), '[\D]')">
<xsl:apply-templates/>
</xsl:when>
<xsl:otherwise>
<xsl:variable name="first-date"
select="
if (contains(@normal, '/')) then
replace(substring-before(@normal, '/'), '\D', '')
else
replace(@normal, '\D', '')"/>
<xsl:variable name="second-date"
select="replace(substring-after(@normal, '/'), '\D', '')"/>
<!-- just adding the next line until i write a date conversion function-->
<xsl:value-of select="mdc:iso-date-2-display-form($first-date)"/>
<xsl:if test="$second-date ne '' and ($first-date ne $second-date)">
<xsl:text>–</xsl:text>
<xsl:value-of select="mdc:iso-date-2-display-form($second-date)"/>
</xsl:if>
</xsl:otherwise>
</xsl:choose>
</xsl:copy>
</xsl:template>
<xsl:template match="ead:unitdate[@type = 'bulk']">
<xsl:copy>
<xsl:copy-of select="@* except @label"/>
<xsl:attribute name="label">
<xsl:value-of select="$unitdate_label_bulk"/>
</xsl:attribute>
<xsl:if test="not(@calendar)">
<xsl:attribute name="calendar">
<xsl:text>gregorian</xsl:text>
</xsl:attribute>
</xsl:if>
<xsl:if test="not(@era)">
<xsl:attribute name="era">
<xsl:text>ce</xsl:text>
</xsl:attribute>
</xsl:if>
<xsl:if test="not(@datechar)">
<xsl:attribute name="datechar">
<xsl:text>creation</xsl:text>
</xsl:attribute>
</xsl:if>
<xsl:choose>
<!-- need to convert these to human readable form if more granular than just a 4-digit year-->
<xsl:when test="not(@normal) or matches(replace(., '/|-|bulk', ''), '[\D]')">
<xsl:apply-templates/>
</xsl:when>
<xsl:otherwise>
<xsl:text>Bulk, </xsl:text>
<xsl:variable name="first-date"
select="
if (contains(@normal, '/')) then
replace(substring-before(@normal, '/'), '\D', '')
else
replace(@normal, '\D', '')"/>
<xsl:variable name="second-date"
select="replace(substring-after(@normal, '/'), '\D', '')"/>
<xsl:value-of select="mdc:iso-date-2-display-form($first-date)"/>
<xsl:if test="$second-date ne '' and ($first-date ne $second-date)">
<xsl:text>–</xsl:text>
<xsl:value-of select="mdc:iso-date-2-display-form($second-date)"/>
</xsl:if>
</xsl:otherwise>
</xsl:choose>
</xsl:copy>
</xsl:template>
<!--optimized for what ASpace can output (up to 2 extents only). If these templates are not used with AS-produced EAD, they
will definitely need to change!-->
<xsl:template match="ead:extent[1][matches(., '^\d')]">
<xsl:copy>
<xsl:apply-templates select="@*"/>
<!--ASpace doesn't force the extent number to be a number, so we'll need to validate and test this on our own-->
<xsl:variable name="extent-number"
select="number(substring-before(normalize-space(.), ' '))"/>
<xsl:variable name="extent-type"
select="lower-case(substring-after(normalize-space(.), ' '))"/>
<xsl:value-of select="format-number($extent-number, '#,##0.##')"/>
<xsl:text> </xsl:text>
<xsl:choose>
<!--changes feet to foot for singular extents-->
<xsl:when test="$extent-number eq 1 and contains($extent-type, ' feet')">
<xsl:value-of select="replace($extent-type, ' feet', ' foot')"/>
</xsl:when>
<!--changes boxes to box for singular extents-->
<xsl:when test="$extent-number eq 1 and contains($extent-type, ' Boxes')">
<xsl:value-of select="replace($extent-type, ' Boxes', ' Box')"/>
</xsl:when>
<!--changes works to work for the "Works of art" extent type, if this is used-->
<xsl:when test="$extent-number eq 1 and contains($extent-type, ' Works of art')">
<xsl:value-of select="replace($extent-type, ' Works', ' Work')"/>
</xsl:when>
<!--chops off the trailing 's' for singular extents-->
<xsl:when test="$extent-number eq 1 and ends-with($extent-type, 's')">
<xsl:variable name="sl" select="string-length($extent-type)"/>
<xsl:value-of select="substring($extent-type, 1, $sl - 1)"/>
</xsl:when>
<!--chops off the trailing 's' for singular extents that are in AAT form, with a paranthetical qualifer-->
<xsl:when test="$extent-number eq 1 and ends-with($extent-type, ')')">
<xsl:value-of select="replace($extent-type, 's \(', ' (')"/>
</xsl:when>
<!--any other irregular singluar/plural extent type names???-->
<!--otherwise, just print out the childless text node as is-->
<xsl:otherwise>
<xsl:value-of select="$extent-type"/>
</xsl:otherwise>
</xsl:choose>
<!--provide a separator before the next extent value, if present-->
<xsl:choose>
<!-- if there's a second extent, and that value starts with an open parentheis character, then add a space-->
<xsl:when test="starts-with(following-sibling::ead:extent[1], '(')">
<xsl:text> </xsl:text>
</xsl:when>
<!--otherwise, if there's a second extent value, add a comma and a space-->
<xsl:when test="following-sibling::ead:extent[1]">
<xsl:text>, </xsl:text>
</xsl:when>
</xsl:choose>
</xsl:copy>
</xsl:template>
<!-- this stuff won't work for all of the hand-encoded YCBA files, so those should probably be updated in ASpace.
Or, just remove these templates for YCBA by adding a repository-based filter-->
<xsl:template match="ead:physfacet">
<xsl:copy>
<xsl:apply-templates select="@*"/>
<xsl:choose>
<xsl:when test="preceding-sibling::ead:extent">
<xsl:text> : </xsl:text>
<xsl:apply-templates/>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates/>
</xsl:otherwise>
</xsl:choose>
</xsl:copy>
</xsl:template>
<xsl:template match="ead:dimensions">
<xsl:copy>
<xsl:apply-templates select="@*"/>
<xsl:choose>
<xsl:when test="preceding-sibling::ead:extent | preceding-sibling::ead:physfacet">
<xsl:text> ; </xsl:text>
<xsl:apply-templates/>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates/>
</xsl:otherwise>
</xsl:choose>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>