-
Notifications
You must be signed in to change notification settings - Fork 1
/
UNIMARC2MARC21.xsl
210 lines (195 loc) · 8.86 KB
/
UNIMARC2MARC21.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
<xsl:stylesheet version="1.0"
exclude-result-prefixes="msxml js"
xmlns="http://www.loc.gov/MARC21/slim"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxml="urn:schemas-microsoft-com:xslt"
xmlns:js="javascript:code"
>
<xsl:output encoding="UTF-8" indent="yes" method="xml"/>
<xsl:strip-space elements="*"/>
<!--
Transformation from UNIMARC XML representation to MARCXML.
Based upon http://www.loc.gov/marc/unimarctomarc21.html
-->
<xsl:template match="/">
<xsl:choose>
<xsl:when test="//collection">
<collection 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">
<xsl:for-each select="//collection/record">
<record>
<xsl:call-template name="record"/>
</record>
</xsl:for-each>
</collection>
</xsl:when>
<xsl:otherwise>
<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">
<xsl:for-each select="//record">
<xsl:call-template name="record"/>
</xsl:for-each>
</record>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="record">
<xsl:if test="@type">
<xsl:attribute name="type">
<xsl:value-of select="@type"/>
</xsl:attribute>
</xsl:if>
<xsl:call-template name="transform-leader"/>
<xsl:call-template name="copy-control">
<xsl:with-param name="tag">001</xsl:with-param>
</xsl:call-template>
<xsl:call-template name="copy-control">
<xsl:with-param name="tag">005</xsl:with-param>
</xsl:call-template>
<xsl:call-template name="transform-100"/>
<!-- 200->245 -->
<xsl:call-template name="transform-datafield">
<xsl:with-param name="srcTag">200</xsl:with-param>
<xsl:with-param name="dstTag">245</xsl:with-param>
<xsl:with-param name="srcCodes">aefb</xsl:with-param>
<xsl:with-param name="dstCodes">abch</xsl:with-param>
</xsl:call-template>
<!-- 210->260 -->
<xsl:call-template name="transform-datafield">
<xsl:with-param name="srcTag">210</xsl:with-param>
<xsl:with-param name="dstTag">260</xsl:with-param>
<xsl:with-param name="srcCodes">acd</xsl:with-param>
<xsl:with-param name="dstCodes">abc</xsl:with-param>
</xsl:call-template>
<!-- 215->300 -->
<xsl:call-template name="transform-datafield">
<xsl:with-param name="srcTag">215</xsl:with-param>
<xsl:with-param name="dstTag">300</xsl:with-param>
<xsl:with-param name="srcCodes">acde</xsl:with-param>
<xsl:with-param name="dstCodes">abce</xsl:with-param>
</xsl:call-template>
<!-- 610->653 -->
<xsl:call-template name="transform-datafield">
<xsl:with-param name="srcTag">610</xsl:with-param>
<xsl:with-param name="dstTag">653</xsl:with-param>
</xsl:call-template>
<!-- 615->650 -->
<xsl:call-template name="transform-datafield">
<xsl:with-param name="srcTag">615</xsl:with-param>
<xsl:with-param name="dstTag">650</xsl:with-param>
<xsl:with-param name="srcCodes">ax</xsl:with-param>
</xsl:call-template>
<!-- 615->072 -->
<xsl:call-template name="transform-datafield">
<xsl:with-param name="srcTag">615</xsl:with-param>
<xsl:with-param name="dstTag">072</xsl:with-param>
<xsl:with-param name="srcCodes">nm</xsl:with-param>
<xsl:with-param name="dstCodes">ax</xsl:with-param>
</xsl:call-template>
<!-- 700->100 -->
<xsl:call-template name="transform-personal-name">
<xsl:with-param name="srcTag">700</xsl:with-param>
<xsl:with-param name="dstTag">100</xsl:with-param>
</xsl:call-template>
<!-- 701->700 -->
<xsl:call-template name="transform-personal-name">
<xsl:with-param name="srcTag">701</xsl:with-param>
<xsl:with-param name="dstTag">700</xsl:with-param>
</xsl:call-template>
<!-- 702->700 -->
<xsl:call-template name="transform-personal-name">
<xsl:with-param name="srcTag">702</xsl:with-param>
<xsl:with-param name="dstTag">700</xsl:with-param>
</xsl:call-template>
</xsl:template>
<xsl:template name="transform-leader">
<xsl:variable name="leader" select="leader"/>
<xsl:variable name="leader05" select="translate(js:part($leader,05,05), 'o', 'c')"/>
<xsl:variable name="leader06" select="translate(js:part($leader,06,06), 'hmn', 'aor')"/>
<xsl:variable name="leader07" select="js:part($leader,07,07)"/>
<xsl:variable name="leader08-16" select="' 22 '"/>
<xsl:variable name="leader17" select="translate(js:part($leader,17,17), '23', '87')"/>
<xsl:variable name="leader18" select="translate(js:part($leader,18,18), ' n', 'i ')"/>
<xsl:variable name="leader19-23" select="' 4500'"/>
<leader>
<xsl:value-of select="concat(' ', $leader05, $leader06, $leader07, $leader08-16, $leader17, $leader18, $leader19-23)"/>
</leader>
</xsl:template>
<xsl:template name="copy-control">
<xsl:param name="tag"/>
<xsl:for-each select="controlfield[@tag=$tag]">
<controlfield tag="{$tag}">
<xsl:value-of select="text()"/>
</controlfield>
</xsl:for-each>
</xsl:template>
<xsl:template name="transform-100">
<xsl:variable name="source" select="datafield[@tag='100']/subfield[@code='a']"/>
<xsl:variable name="dest00-05" select="js:part($source,02,07)"/>
<xsl:variable name="dest06" select="translate(js:part($source,08,08), 'abcdefghij', 'cdusrqmtpe')"/>
<xsl:variable name="dest07-14" select="js:part($source,09,16)"/>
<xsl:variable name="dest15-21" select="' '"/>
<xsl:variable name="dest22" select="translate(js:part($source,17,17), 'bcadekmu', 'abjcdeg ')"/>
<xsl:variable name="dest23-27" select="' '"/>
<xsl:variable name="dest28" select="translate(js:part($source,20,20), 'abcdefghy', 'fsllcizo ')"/>
<xsl:variable name="dest29-32" select="' '"/>
<xsl:variable name="dest33" select="js:part($source,34,34)"/>
<xsl:variable name="dest34-37" select="' '"/>
<xsl:variable name="dest38" select="translate(js:part($source,21,21), '01', ' o')"/>
<xsl:variable name="dest39-40" select="' '"/>
<controlfield tag="008">
<xsl:value-of select="concat($dest00-05, $dest06, $dest07-14, $dest15-21, $dest22, $dest23-27, $dest28, $dest29-32, $dest33, $dest34-37, $dest38, $dest39-40)"/>
</controlfield>
</xsl:template>
<xsl:template name="transform-datafield">
<xsl:param name="srcTag"/>
<xsl:param name="dstTag" select="@srcTag"/>
<xsl:param name="srcCodes" select="$all-codes"/>
<xsl:param name="dstCodes" select="$srcCodes"/>
<xsl:if test="datafield[@tag=$srcTag]/subfield[contains($srcCodes, @code)]">
<xsl:for-each select="datafield[@tag=$srcTag]">
<datafield tag="{$dstTag}">
<xsl:call-template name="copy-indicators"/>
<xsl:call-template name="transform-subfields">
<xsl:with-param name="srcCodes" select="$srcCodes"/>
<xsl:with-param name="dstCodes" select="$dstCodes"/>
</xsl:call-template>
</datafield>
</xsl:for-each>
</xsl:if>
</xsl:template>
<xsl:template name="transform-personal-name">
<xsl:param name="srcTag"/>
<xsl:param name="dstTag"/>
<xsl:for-each select="datafield[@tag=$srcTag]">
<datafield tag="{$dstTag}" ind1="{@ind2}" ind2="">
<xsl:call-template name="transform-subfields">
<xsl:with-param name="srcCodes" select="'acdfgp4'"/>
<xsl:with-param name="dstCodes" select="'acbdqu4'"/>
</xsl:call-template>
</datafield>
</xsl:for-each>
</xsl:template>
<xsl:template name="copy-indicators">
<xsl:attribute name="ind1">
<xsl:value-of select="translate(@ind1, '#', '')"/>
</xsl:attribute>
<xsl:attribute name="ind2">
<xsl:value-of select="translate(@ind2, '#', '')"/>
</xsl:attribute>
</xsl:template>
<xsl:template name="transform-subfields">
<xsl:param name="srcCodes" select="$all-codes"/>
<xsl:param name="dstCodes" select="$srcCodes"/>
<xsl:for-each select="subfield[contains($srcCodes, @code)]">
<subfield code="{translate(@code, $srcCodes, $dstCodes)}">
<xsl:value-of select="text()"/>
</subfield>
</xsl:for-each>
</xsl:template>
<xsl:variable name="all-codes">abcdefghijklmnopqrstuvwxyz123456789</xsl:variable>
<msxml:script implements-prefix="js">
function part(source : String, from : int, to : int)
{
return source.substring(from, to + 1);
}
</msxml:script>
</xsl:stylesheet>