This repository has been archived by the owner on Jan 28, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ead-numbered-components_to_tsv.xsl
204 lines (183 loc) · 8.19 KB
/
ead-numbered-components_to_tsv.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
<?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:xd="http://www.oxygenxml.com/ns/doc/xsl"
xmlns:ead="urn:isbn:1-931666-22-9" exclude-result-prefixes="xs xd" version="2.0">
<xd:doc scope="stylesheet">
<xd:desc>
<xd:p><xd:b>Created on:</xd:b> Jul 21, 2017</xd:p>
<xd:p><xd:b>Author:</xd:b> Seth Shaw</xd:p>
<xd:p/>
</xd:desc>
</xd:doc>
<xsl:output method="text" omit-xml-declaration="yes" encoding="utf-8"/>
<!-- Tab variable for creating TSV file -->
<xsl:variable name="tab">
<xsl:text>	</xsl:text>
</xsl:variable>
<!-- New Line variable for creating new rows in TSV file -->
<xsl:variable name="newline">
<xsl:text>
</xsl:text>
</xsl:variable>
<xsl:template match="/">
<!-- header fields -->
<xsl:text>ref_id</xsl:text>
<xsl:value-of select="$tab"/>
<xsl:text>unitid</xsl:text>
<xsl:value-of select="$tab"/>
<xsl:text>c01</xsl:text>
<xsl:value-of select="$tab"/>
<xsl:text>c02</xsl:text>
<xsl:value-of select="$tab"/>
<xsl:text>c03</xsl:text>
<xsl:value-of select="$tab"/>
<xsl:text>c04</xsl:text>
<xsl:value-of select="$tab"/>
<xsl:text>c05</xsl:text>
<xsl:value-of select="$tab"/>
<xsl:text>type</xsl:text>
<xsl:value-of select="$tab"/>
<xsl:text>date</xsl:text>
<xsl:value-of select="$tab"/>
<xsl:text>extent</xsl:text>
<xsl:value-of select="$tab"/>
<xsl:text>odd</xsl:text>
<xsl:value-of select="$tab"/>
<xsl:text>container 1 type</xsl:text>
<xsl:value-of select="$tab"/>
<xsl:text>container 1 value</xsl:text>
<xsl:value-of select="$tab"/>
<xsl:text>container 2 type</xsl:text>
<xsl:value-of select="$tab"/>
<xsl:text>container 2 value</xsl:text>
<!-- <xsl:value-of select="$tab"/>
<xsl:text>scopecontent</xsl:text>
-->
<xsl:value-of select="$newline"/>
<xsl:apply-templates select="//ead:c01"/>
</xsl:template>
<xsl:template match="ead:c01 | ead:c02 | ead:c03 | ead:c04 | ead:c05">
<xsl:value-of select="normalize-space(@id)"/>
<xsl:value-of select="$tab"/>
<xsl:value-of select="normalize-space(ead:did/ead:unitid)"/>
<xsl:value-of select="$tab"/>
<!-- I would rather this be recursive, but it works. -->
<xsl:choose>
<xsl:when test="name() = 'c05'">
<xsl:value-of select="normalize-space(../../../../ead:did/ead:unittitle)"/>
<xsl:value-of select="$tab"/>
<xsl:value-of select="normalize-space(../../../ead:did/ead:unittitle)"/>
<xsl:value-of select="$tab"/>
<xsl:value-of select="normalize-space(../../ead:did/ead:unittitle)"/>
<xsl:value-of select="$tab"/>
<xsl:value-of select="normalize-space(../ead:did/ead:unittitle)"/>
<xsl:value-of select="$tab"/>
<xsl:value-of select="normalize-space(ead:did/ead:unittitle)"/>
<xsl:value-of select="$tab"/>
</xsl:when>
<xsl:when test="name() = 'c04'">
<xsl:value-of select="normalize-space(../../../ead:did/ead:unittitle)"/>
<xsl:value-of select="$tab"/>
<xsl:value-of select="normalize-space(../../ead:did/ead:unittitle)"/>
<xsl:value-of select="$tab"/>
<xsl:value-of select="normalize-space(../ead:did/ead:unittitle)"/>
<xsl:value-of select="$tab"/>
<xsl:value-of select="normalize-space(ead:did/ead:unittitle)"/>
<xsl:value-of select="$tab"/>
<xsl:value-of select="$tab"/>
</xsl:when>
<xsl:when test="name() = 'c03'">
<xsl:value-of select="normalize-space(../../ead:did/ead:unittitle)"/>
<xsl:value-of select="$tab"/>
<xsl:value-of select="normalize-space(../ead:did/ead:unittitle)"/>
<xsl:value-of select="$tab"/>
<xsl:value-of select="normalize-space(ead:did/ead:unittitle)"/>
<xsl:value-of select="$tab"/>
<xsl:value-of select="$tab"/>
<xsl:value-of select="$tab"/>
</xsl:when>
<xsl:when test="name() = 'c02'">
<xsl:value-of select="normalize-space(../ead:did/ead:unittitle)"/>
<xsl:value-of select="$tab"/>
<xsl:value-of select="normalize-space(ead:did/ead:unittitle)"/>
<xsl:value-of select="$tab"/>
<xsl:value-of select="$tab"/>
<xsl:value-of select="$tab"/>
<xsl:value-of select="$tab"/>
</xsl:when>
<xsl:when test="name() = 'c01'">
<xsl:value-of select="normalize-space(ead:did/ead:unittitle)"/>
<xsl:value-of select="$tab"/>
<xsl:value-of select="$tab"/>
<xsl:value-of select="$tab"/>
<xsl:value-of select="$tab"/>
<xsl:value-of select="$tab"/>
</xsl:when>
</xsl:choose>
<!-- level -->
<xsl:value-of select="@level"/>
<xsl:value-of select="$tab"/>
<!-- date -->
<xsl:for-each select="ead:did/ead:unitdate">
<xsl:if test="position() > 1">
<xsl:text>, </xsl:text>
</xsl:if>
<xsl:value-of select="normalize-space(.)"/>
</xsl:for-each>
<xsl:value-of select="$tab"/>
<!-- physdesc extent -->
<xsl:choose>
<xsl:when
test="count(ead:did/ead:physdesc/ead:extent[@altrender = 'materialtype spaceoccupied']) > 1">
<xsl:for-each
select="ead:did/ead:physdesc/ead:extent[@altrender = 'materialtype spaceoccupied']">
<xsl:value-of select="normalize-space(.)"/>
<xsl:text>;</xsl:text>
</xsl:for-each>
</xsl:when>
<xsl:otherwise>
<xsl:value-of
select="normalize-space(ead:did/ead:physdesc/ead:extent[@altrender = 'materialtype spaceoccupied'])"
/>
</xsl:otherwise>
</xsl:choose>
<xsl:text> </xsl:text>
<xsl:value-of
select="normalize-space(ead:did/ead:physdesc/ead:extent[@altrender = 'carrier'])"/>
<xsl:value-of select="$tab"/>
<!-- odd -->
<xsl:for-each select="ead:odd/ead:p">
<xsl:if test="position() > 1">
<xsl:text> </xsl:text>
</xsl:if>
<xsl:value-of select="normalize-space(.)"/>
</xsl:for-each>
<xsl:value-of select="$tab"/>
<!-- Top-level container ( box of flat files ) -->
<xsl:value-of select="normalize-space(ead:did/ead:container[1]/@type)"/>
<xsl:value-of select="$tab"/>
<xsl:value-of select="normalize-space(ead:did/ead:container[1])"/>
<xsl:value-of select="$tab"/>
<!-- Second container (folder) -->
<xsl:value-of select="normalize-space(ead:did/ead:container[2]/@type)"/>
<xsl:value-of select="$tab"/>
<xsl:value-of select="normalize-space(ead:did/ead:container[2])"/>
<!--
<xsl:value-of select="$tab"/>
<xsl:apply-templates select="ead:scopecontent"/>
-->
<xsl:value-of select="$newline"/>
<!-- If a level contains that next level, it will process it. Otherwise it will do nothing. -->
<xsl:apply-templates select="ead:c02"/>
<xsl:apply-templates select="ead:c03"/>
<xsl:apply-templates select="ead:c04"/>
<xsl:apply-templates select="ead:c05"/>
</xsl:template>
<xsl:template match="ead:scopecontent">
<!-- Keep the p tags but ditch tabs and line endings. Collateral loss of emph tags. -->
<xsl:for-each select="ead:p">
<xsl:text><p></xsl:text>
<xsl:value-of select="normalize-space(.)"/>
<xsl:text></p></xsl:text>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>