-
Notifications
You must be signed in to change notification settings - Fork 0
/
brbl.labels.folders-ASpace-NEW.xsl
417 lines (385 loc) · 21.7 KB
/
brbl.labels.folders-ASpace-NEW.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
<?xml version="1.0"?>
<!--
Beinecke XSLT: EAD to Tab Delimited Text file for Folder Labels Mail Merge
Created: 2017-07-01 (significantly revised; also updated to XSLT 3.0, just because i wanted to use format-integer)
Contact: [email protected]
Need to do:
test a lot!
Also need to fix/simplify how the ancestor sequence is created, tokenize, etc.
see about retaining italics and the like. do we want that?
-->
<xsl:stylesheet version="3.0" xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ead="urn:isbn:1-931666-22-9"
xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:mdc="http://mdc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" exclude-result-prefixes="#all">
<xsl:output method="text" encoding="UTF-8" indent="yes"/>
<!-- change to true() to inspect the XML output for each row,
and also change the output method from text to xml-->
<xsl:param name="debug-mode" select="false()"/>
<xsl:include href="sort-container-function.xsl"/>
<!-- put into a separate file later on -->
<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()" mode="copy">
<xsl:copy>
<xsl:apply-templates select="@* | node()" mode="#current"/>
</xsl:copy>
</xsl:template>
<xsl:param name="collection">
<xsl:value-of select="normalize-space(ead:ead/ead:archdesc/ead:did/ead:unittitle[1])"/>
</xsl:param>
<xsl:param name="callnum">
<xsl:value-of select="normalize-space(ead:ead/ead:archdesc/ead:did/ead:unitid[not(@audience='internal')][1])"/>
</xsl:param>
<xsl:variable name="resorted-container-groups">
<xsl:element name="flattened-list">
<xsl:for-each select="//ead:container[@id][not(@parent)][following-sibling::ead:container[lower-case(@type) = 'folder']]">
<xsl:sort select="mdc:container-to-number(.)" data-type="number" order="ascending"/>
<xsl:variable name="current-id" select="@id"/>
<xsl:variable name="immediate-ancestor" select="ancestor::ead:*[ead:did/ead:unittitle][ancestor::ead:dsc][1]"/>
<xsl:variable name="folder-title-plus-unitid">
<xsl:choose>
<!-- if there's just a unitid, use that in place of the title and don't inherit anything.
the "inherited" title will still appear as an ancestor title on the label due to the ancestor-sequence element -->
<xsl:when
test="not(../ead:unittitle[normalize-space()]) and ../ead:unitid[not(@audience = 'internal')][normalize-space()]">
<xsl:value-of select="../ead:unitid[not(@audience = 'internal')][1]"/>
</xsl:when>
<!-- if there's no unitid or unittitle, then grab an ancestor title and unitid.
if the ancestor unittitle is the same as the constructed title, we'll filter out the ancestor title when we create the ancestor-sequence-filtered variable.
we don't just use the unitdate here since the "folderDates" are added later.
-->
<xsl:when test="not(../ead:unittitle[normalize-space()])">
<xsl:if test="$immediate-ancestor[ead:did/ead:unitid][not(@audience = 'internal')][normalize-space()]">
<xsl:value-of
select="concat($immediate-ancestor/ead:did/ead:unitid[not(@audience = 'internal')][1], ' ')"
/>
</xsl:if>
<xsl:value-of
select="normalize-space($immediate-ancestor/ead:did/ead:unittitle[1])"
/>
</xsl:when>
<xsl:otherwise>
<xsl:if
test="normalize-space(../ead:unitid[not(@audience = 'internal')][1])">
<xsl:value-of
select="normalize-space(../ead:unitid[not(@audience = 'internal')][1])"/>
<xsl:text> </xsl:text>
</xsl:if>
<xsl:value-of select="normalize-space(../ead:unittitle[1])"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="ancestor-sequence">
<xsl:sequence select="
string-join(
for $ancestor in ../../ancestor::*[ead:did][ancestor::ead:dsc]
return
if (matches($ancestor/ead:did/ead:unitid[not(@audience = 'internal')][1], '^\d$')
and $ancestor/lower-case(@level) eq 'series')
then
concat('Series ', $ancestor/ead:did/ead:unitid[not(@audience = 'internal')][1]/format-integer(., 'I'), '. ', $ancestor/ead:did/ead:unittitle/normalize-space())
else
if (ends-with($ancestor/ead:did/ead:unitid[not(@audience = 'internal')][1]/normalize-space(), '.'))
then
concat($ancestor/ead:did/ead:unitid[not(@audience = 'internal')][1]/normalize-space(), ' ', $ancestor/ead:did/ead:unittitle/normalize-space())
else
if ($ancestor/ead:did/ead:unitid[not(@audience = 'internal')][1]/normalize-space()) then
concat($ancestor/ead:did/ead:unitid[not(@audience = 'internal')][1], ' ', $ancestor/ead:did/ead:unittitle/normalize-space())
else
$ancestor/ead:did/ead:unittitle/normalize-space()
, 'xx*****yz')"
/>
</xsl:variable>
<xsl:variable name="ancestor-sequence-tokenized"
select="
if (contains($ancestor-sequence, 'xx*****yz')) then
tokenize($ancestor-sequence, 'xx\*\*\*\*\*yz')
else $ancestor-sequence"/>
<xsl:variable name="ancestor-sequence-filtered">
<xsl:sequence select="
string-join(
remove($ancestor-sequence-tokenized, if (exists(index-of($ancestor-sequence-tokenized, $folder-title-plus-unitid)))
then index-of($ancestor-sequence-tokenized, $folder-title-plus-unitid)
else 0)
, 'xx*****yz')"/>
</xsl:variable>
<xsl:element name="container-grouping">
<!-- copies the origination, unitdate, current container, and following related containers-->
<xsl:apply-templates
select="
../ead:origination
, ../ead:unitdate
, .
, ../ead:container[@parent = $current-id]"
mode="copy"/>
<xsl:element name="ancestor-sequence">
<xsl:sequence select="$ancestor-sequence-filtered"/>
</xsl:element>
<xsl:element name="constructed-title">
<xsl:value-of select="$folder-title-plus-unitid"/>
</xsl:element>
</xsl:element>
</xsl:for-each>
</xsl:element>
</xsl:variable>
<!-- Matches the root of the document, outputs the first tab delimited line, then applies templates to each EAD component with a folder value. -->
<xsl:template match="/">
<xsl:choose>
<xsl:when test="$debug-mode eq true()">
<xsl:element name="root">
<xsl:for-each
select="$resorted-container-groups/flattened-list/container-grouping">
<xsl:copy-of select="."/>
</xsl:for-each>
</xsl:element>
</xsl:when>
<xsl:otherwise>
<xsl:text>COLLECTION	CALL NO.	BOX	FOLDER	C01 ANCESTOR	C02 ANCESTOR	C03 ANCESTOR	C04 ANCESTOR	C05 ANCESTOR	FOLDER ORIGINATION	FOLDER TITLE	FOLDER DATES
</xsl:text>
<xsl:for-each select="$resorted-container-groups/flattened-list/container-grouping">
<xsl:variable name="folderString"
select="normalize-space(ead:container[lower-case(@type) = 'folder'][1])"/>
<xsl:variable name="folderStringNormal"
select="translate($folderString, '–—', '-')"/>
<xsl:choose>
<xsl:when test="contains($folderStringNormal, '-')">
<xsl:choose>
<xsl:when
test="matches(replace($folderStringNormal, '-', ''), '\D')">
<xsl:message>Component with @id="<xsl:value-of select="@id"/>"
includes a folder span with an alphabetic value:
"<xsl:value-of select="$folderStringNormal"/>". Span not
broken up into discrete lines for each folder</xsl:message>
<xsl:call-template name="folderRowOutput">
<xsl:with-param name="folderSpanSumToOutput">
<xsl:value-of select="1"/>
</xsl:with-param>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:variable name="folderSpanFirstValue"
select="xs:integer(substring-before($folderStringNormal, '-'))"/>
<xsl:variable name="folderSpanSecondValue"
select="xs:integer(substring-after($folderStringNormal, '-'))"/>
<xsl:variable name="folderSpanSum"
select="$folderSpanSecondValue - $folderSpanFirstValue + 1"/>
<xsl:choose>
<xsl:when
test="$folderSpanSecondValue lt $folderSpanFirstValue">
<xsl:message>Component with @id="<xsl:value-of
select="@id"/>" includes a folder span where the
second folder value is smaller than the first folder
value: "<xsl:value-of select="$folderStringNormal"
/>". Span not broken up into discrete lines for each
folder</xsl:message>
<xsl:call-template name="folderRowOutput">
<xsl:with-param name="folderSpanSumToOutput">
<xsl:value-of select="1"/>
</xsl:with-param>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="folderRowOutput">
<xsl:with-param name="folderSpanSumToOutput">
<xsl:value-of select="$folderSpanSum"/>
</xsl:with-param>
<xsl:with-param name="folderSpanFirstFolder">
<xsl:value-of select="$folderSpanFirstValue"/>
</xsl:with-param>
<xsl:with-param name="folderSpanInstance">
<xsl:value-of select="1"/>
</xsl:with-param>
<xsl:with-param name="folderSpanInstanceTotal">
<xsl:value-of select="$folderSpanSum"/>
</xsl:with-param>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="folderRowOutput">
<xsl:with-param name="folderSpanSumToOutput">
<xsl:value-of select="1"/>
</xsl:with-param>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!-- Template for each EAD component with a folder value. Then calls template for each DL column, followed by tabs and a line break on the end. -->
<xsl:template name="folderRowOutput">
<xsl:param name="folderSpanSumToOutput"/>
<xsl:param name="folderSpanFirstFolder"/>
<xsl:param name="folderSpanInstance"/>
<xsl:param name="folderSpanInstanceTotal"/>
<xsl:value-of select="$collection"/>
<xsl:text>	</xsl:text>
<xsl:value-of select="$callnum"/>
<xsl:text>	</xsl:text>
<xsl:call-template name="box"/>
<xsl:text>	</xsl:text>
<xsl:call-template name="folder">
<xsl:with-param name="folderSpanFirstFolder">
<xsl:value-of select="$folderSpanFirstFolder"/>
</xsl:with-param>
</xsl:call-template>
<xsl:text>	</xsl:text>
<xsl:variable name="series-of-series" select="
if (contains(ancestor-sequence, 'xx*****yz')) then
tokenize(ancestor-sequence, 'xx\*\*\*\*\*yz')
else ancestor-sequence"/>
<xsl:sequence select="$series-of-series[1]"/>
<xsl:text>	</xsl:text>
<xsl:sequence select="$series-of-series[2]"/>
<xsl:text>	</xsl:text>
<xsl:sequence select="$series-of-series[3]"/>
<xsl:text>	</xsl:text>
<xsl:sequence select="$series-of-series[4]"/>
<xsl:text>	</xsl:text>
<xsl:sequence select="$series-of-series[5]"/>
<xsl:text>	</xsl:text>
<xsl:call-template name="folderOrigination"/>
<xsl:text>	</xsl:text>
<xsl:call-template name="folderTitle">
<xsl:with-param name="folderSpanInstance">
<xsl:value-of select="$folderSpanInstance"/>
</xsl:with-param>
<xsl:with-param name="folderSpanInstanceTotal">
<xsl:value-of select="$folderSpanInstanceTotal"/>
</xsl:with-param>
</xsl:call-template>
<xsl:text>	</xsl:text>
<xsl:call-template name="folderDates"/>
<!--make sure to only add a new line if there's another folder row to add.
this is a bit more complicated than just checking for the last position, because the last group could be a folder span.
e.g. folder 1000-1004, so we need to make sure that the folderSpanInstance is still less than the folderSpanInstanceTotal in that case.
-->
<xsl:if
test="
position() lt last()
or (last() and $folderSpanInstance lt $folderSpanInstanceTotal)">
<xsl:text>
</xsl:text>
</xsl:if>
<xsl:if test="$folderSpanSumToOutput != 1">
<xsl:call-template name="folderRowOutput">
<xsl:with-param name="folderSpanSumToOutput">
<xsl:value-of select="$folderSpanSumToOutput - 1"/>
</xsl:with-param>
<xsl:with-param name="folderSpanFirstFolder">
<xsl:value-of select="$folderSpanFirstFolder + 1"/>
</xsl:with-param>
<xsl:with-param name="folderSpanInstance">
<xsl:value-of select="$folderSpanInstance + 1"/>
</xsl:with-param>
<xsl:with-param name="folderSpanInstanceTotal">
<xsl:value-of select="$folderSpanInstanceTotal"/>
</xsl:with-param>
</xsl:call-template>
</xsl:if>
</xsl:template>
<!-- Template for the box number.
ASpace versions 2.x will export type="" if the container type is left blank, so we now test for 'box' or ''
-->
<xsl:template name="box">
<xsl:if test="ead:container[lower-case(@type) = ('box', '')][normalize-space()]">
<xsl:text>Box </xsl:text>
<xsl:value-of select="normalize-space(ead:container[lower-case(@type) = ('box', '')])"/>
</xsl:if>
</xsl:template>
<!-- Template for folder numbers -->
<xsl:template name="folder">
<xsl:param name="folderSpanFirstFolder"/>
<xsl:if test="normalize-space(ead:container[lower-case(@type) = 'folder'])">
<xsl:text>Folder </xsl:text>
<xsl:choose>
<xsl:when test="normalize-space($folderSpanFirstFolder)">
<xsl:value-of select="$folderSpanFirstFolder"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of
select="normalize-space(ead:container[lower-case(@type) = 'folder'])"/>
</xsl:otherwise>
</xsl:choose>
</xsl:if>
</xsl:template>
<!-- Template for folder originations -->
<xsl:template name="folderOrigination">
<xsl:value-of select="normalize-space(ead:origination[1])"/>
</xsl:template>
<!-- Template for folder unittitles -->
<xsl:template name="folderTitle">
<xsl:param name="folderSpanInstance"/>
<xsl:param name="folderSpanInstanceTotal"/>
<xsl:value-of select="constructed-title"/>
<xsl:if test="normalize-space($folderSpanInstance)">
<xsl:text> [</xsl:text>
<xsl:value-of select="$folderSpanInstance"/>
<xsl:text> of </xsl:text>
<xsl:value-of select="$folderSpanInstanceTotal"/>
<xsl:text> folders]</xsl:text>
</xsl:if>
</xsl:template>
<!-- Template for folder unitdates -->
<xsl:template name="folderDates">
<xsl:for-each select="ead:unitdate[not(parent::ead:unittitle)]">
<xsl:choose>
<xsl:when test="not(@normal) or matches(replace(., '/|-', ''), '[\D]')">
<xsl:value-of select="normalize-space()"/>
</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:if test="following-sibling::ead:unitdate">
<xsl:text>, </xsl:text>
</xsl:if>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>