-
Notifications
You must be signed in to change notification settings - Fork 0
/
brbl.labels.boxes-ASpace-NEW.xsl
153 lines (133 loc) · 6.9 KB
/
brbl.labels.boxes-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
<?xml version="1.0"?>
<!--
Beinecke XSLT: EAD to Tab Delimited Text file for Box Labels Mail Merge
Created: 2017-06-30 (significantly revised to ensure one box label per box; also updated to XSLT 2.0)
Contact: [email protected]
to fix / look into:
- test, test, test with staff. ask for feedback in July/August.
-->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ead="urn:isbn:1-931666-22-9"
xmlns:mdc="http://mdc" xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" exclude-result-prefixes="#all"
version="3.0">
<xsl:output method="text" encoding="UTF-8"/>
<xsl:include href="sort-container-function.xsl"/>
<xsl:param name="repository">
<xsl:value-of
select="normalize-space(ead:ead/ead:archdesc/ead:did/ead:repository/ead:corpname)"/>
</xsl:param>
<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[1])"/>
</xsl:param>
<xsl:template match="@* | node()" mode="copy">
<xsl:copy>
<xsl:apply-templates select="@* | node()" mode="#current"/>
</xsl:copy>
</xsl:template>
<xsl:variable name="resorted-container-groups">
<xsl:element name="flattened-list">
<xsl:for-each select="//ead:container[@id][not(@parent)]">
<xsl:sort select="mdc:container-to-number(.)" data-type="number" order="ascending"/>
<xsl:variable name="current-id" select="@id"/>
<xsl:variable name="series-unitid"
select="ancestor::ead:*[lower-case(@level) = 'series'][ead:did/ead:unitid][last()]/ead:did/ead:unitid[not(@audience='internal')]"/>
<xsl:variable name="separator"
select="
if (ends-with($series-unitid, '.')) then
' '
else
'. '"/>
<xsl:element name="container-grouping">
<xsl:apply-templates select="." mode="copy"/>
<xsl:apply-templates select="../ead:container[@parent = $current-id]"
mode="copy"/>
<xsl:if test="$series-unitid">
<xsl:element name="series-info">
<xsl:element name="title">
<xsl:value-of
select="
concat('Series ',
if ($series-unitid/matches(., '^\d$')) then
$series-unitid/format-integer(., 'I')
else
if ($series-unitid/starts-with(., 'Series')) then
$series-unitid/substring-after(., 'Series ')
else
$series-unitid,
$separator, $series-unitid/../ead:unittitle[1])"
/>
</xsl:element>
</xsl:element>
</xsl:if>
</xsl:element>
</xsl:for-each>
</xsl:element>
</xsl:variable>
<xsl:template match="ead:ead">
<!-- add column headers with tabs and a newline -->
<xsl:text>REPOSITORY	COLLECTION	CALL NO.	BOX	FIRST FOLDER	LAST FOLDER	FIRST C01 SERIES	SECOND C01 SERIES	THIRD C01 SERIES	FOURTH C01 SERIES	FIFTH C01 SERIES
</xsl:text>
<xsl:apply-templates select="$resorted-container-groups"/>
</xsl:template>
<xsl:template match="flattened-list">
<xsl:for-each-group select="container-grouping"
group-by="ead:container[lower-case(@type) = ('box', '')]">
<xsl:for-each-group select="current-group()" group-by="current-grouping-key()">
<xsl:variable name="firstFolderString" select="translate((current-group()/ead:container[lower-case(@type)='folder']/normalize-space())[1], '–—','-')"/>
<xsl:variable name="lastFolderString" select="translate((current-group()/ead:container[lower-case(@type)='folder']/normalize-space())[last()], '–—','-')"/>
<xsl:variable name="first-folder"
select="if (contains($firstFolderString, '-'))
then substring-before($firstFolderString, '-')
else $firstFolderString"/>
<xsl:variable name="last-folder"
select="if (contains($lastFolderString, '-'))
then substring-after($lastFolderString, '-')
else $lastFolderString"/>
<xsl:variable name="sequence-of-series"
select="distinct-values(current-group()/series-info/title)"/>
<!-- REPOSITORY -->
<xsl:value-of select="$repository"/>
<xsl:text>	</xsl:text>
<!-- COLLECTION -->
<xsl:value-of select="$collection"/>
<xsl:text>	</xsl:text>
<!-- CALL NO. -->
<xsl:value-of select="$callnum"/>
<xsl:text>	</xsl:text>
<!-- BOX -->
<xsl:value-of select="current-grouping-key()"/>
<xsl:text>	</xsl:text>
<!-- FIRST FOLDER -->
<xsl:value-of select="$first-folder"/>
<xsl:text>	</xsl:text>
<!-- LAST FOLDER -->
<xsl:value-of
select="
if ($first-folder eq $last-folder) then
''
else
$last-folder"/>
<xsl:text>	</xsl:text>
<!-- FIRST C01 SERIES -->
<xsl:value-of select="$sequence-of-series[1]"/>
<xsl:text>	</xsl:text>
<!-- SECOND C01 SERIES -->
<xsl:value-of select="$sequence-of-series[2]"/>
<xsl:text>	</xsl:text>
<!-- THIRD C01 SERIES -->
<xsl:value-of select="$sequence-of-series[3]"/>
<xsl:text>	</xsl:text>
<!-- FOURTH C01 SERIES -->
<xsl:value-of select="$sequence-of-series[4]"/>
<xsl:text>	</xsl:text>
<!-- FIFTH C01 SERIES -->
<xsl:value-of select="$sequence-of-series[5]"/>
</xsl:for-each-group>
<xsl:if test="position() lt last()">
<xsl:text>
</xsl:text>
</xsl:if>
</xsl:for-each-group>
</xsl:template>
</xsl:stylesheet>