Merge branch 'master' of ssh://git.indexdata.com:222/home/git/pub/pazpar2
[pazpar2-moved-to-github.git] / etc / marc21.xsl
1 <?xml version="1.0" encoding="UTF-8"?>
2 <xsl:stylesheet
3     version="1.0"
4     xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
5     xmlns:pz="http://www.indexdata.com/pazpar2/1.0"
6     xmlns:marc="http://www.loc.gov/MARC21/slim">
7   
8   <xsl:output indent="yes" method="xml" version="1.0" encoding="UTF-8"/>
9
10 <!-- Extract metadata from MARC21/USMARC 
11       http://www.loc.gov/marc/bibliographic/ecbdhome.html
12 -->  
13   <xsl:template name="record-hook"/>
14
15   <xsl:template match="/">
16     <xsl:apply-templates/>
17   </xsl:template>
18
19   <xsl:template match="marc:record">
20     <xsl:variable name="title_medium" select="marc:datafield[@tag='245']/marc:subfield[@code='h']"/>
21     <xsl:variable name="journal_title" select="marc:datafield[@tag='773']/marc:subfield[@code='t']"/>
22     <xsl:variable name="electronic_location_url" select="marc:datafield[@tag='856']/marc:subfield[@code='u']"/>
23     <xsl:variable name="fulltext_a" select="marc:datafield[@tag='900']/marc:subfield[@code='a']"/>
24     <xsl:variable name="fulltext_b" select="marc:datafield[@tag='900']/marc:subfield[@code='b']"/>
25     <xsl:variable name="medium">
26       <xsl:choose>
27         <xsl:when test="$title_medium">
28           <xsl:value-of select="translate($title_medium, ' []/', '')"/>
29         </xsl:when>
30         <xsl:when test="$fulltext_a">
31           <xsl:text>electronic resource</xsl:text>
32         </xsl:when>
33         <xsl:when test="$fulltext_b">
34           <xsl:text>electronic resource</xsl:text>
35         </xsl:when>
36         <xsl:when test="$journal_title">
37           <xsl:text>article</xsl:text>
38         </xsl:when>
39         <xsl:otherwise>
40           <xsl:text>book</xsl:text>
41         </xsl:otherwise>
42       </xsl:choose>
43     </xsl:variable>
44
45     <xsl:variable name="has_fulltext">
46       <xsl:choose>
47         <xsl:when test="marc:datafield[@tag='856']/marc:subfield[@code='q']">
48           <xsl:text>yes</xsl:text>
49         </xsl:when>
50         <xsl:when test="marc:datafield[@tag='856']/marc:subfield[@code='i']='TEXT*'">
51           <xsl:text>yes</xsl:text>
52         </xsl:when>
53         <xsl:otherwise>
54           <xsl:text>no</xsl:text>
55         </xsl:otherwise>
56       </xsl:choose>
57     </xsl:variable>
58
59     <pz:record>
60       <xsl:for-each select="marc:controlfield[@tag='001']">
61         <pz:metadata type="id">
62           <xsl:value-of select="."/>
63         </pz:metadata>
64       </xsl:for-each>
65
66       <xsl:for-each select="marc:datafield[@tag='010']">
67         <pz:metadata type="lccn">
68           <xsl:value-of select="marc:subfield[@code='a']"/>
69         </pz:metadata>
70       </xsl:for-each>
71
72       <xsl:for-each select="marc:datafield[@tag='020']">
73         <pz:metadata type="isbn">
74           <xsl:value-of select="marc:subfield[@code='a']"/>
75         </pz:metadata>
76       </xsl:for-each>
77
78       <xsl:for-each select="marc:datafield[@tag='022']">
79         <pz:metadata type="issn">
80           <xsl:value-of select="marc:subfield[@code='a']"/>
81         </pz:metadata>
82       </xsl:for-each>
83
84       <xsl:for-each select="marc:datafield[@tag='027']">
85         <pz:metadata type="tech-rep-nr">
86           <xsl:value-of select="marc:subfield[@code='a']"/>
87         </pz:metadata>
88       </xsl:for-each>
89
90       <xsl:for-each select="marc:datafield[@tag='035']">
91         <pz:metadata type="system-control-nr">
92           <xsl:choose>
93             <xsl:when test="marc:subfield[@code='a']">
94               <xsl:value-of select="marc:subfield[@code='a']"/>
95             </xsl:when>
96             <xsl:otherwise>
97               <xsl:value-of select="marc:subfield[@code='b']"/>
98             </xsl:otherwise>
99           </xsl:choose>
100         </pz:metadata>
101       </xsl:for-each>
102
103       <xsl:for-each select="marc:datafield[@tag='100']">
104         <pz:metadata type="author">
105           <xsl:value-of select="marc:subfield[@code='a']"/>
106         </pz:metadata>
107         <pz:metadata type="author-title">
108           <xsl:value-of select="marc:subfield[@code='c']"/>
109         </pz:metadata>
110         <pz:metadata type="author-date">
111           <xsl:value-of select="marc:subfield[@code='d']"/>
112         </pz:metadata>
113       </xsl:for-each>
114
115       <xsl:for-each select="marc:datafield[@tag='110']">
116         <pz:metadata type="corporate-name">
117             <xsl:value-of select="marc:subfield[@code='a']"/>
118         </pz:metadata>
119         <pz:metadata type="corporate-location">
120             <xsl:value-of select="marc:subfield[@code='c']"/>
121         </pz:metadata>
122         <pz:metadata type="corporate-date">
123             <xsl:value-of select="marc:subfield[@code='d']"/>
124         </pz:metadata>
125       </xsl:for-each>
126
127       <xsl:for-each select="marc:datafield[@tag='111']">
128         <pz:metadata type="meeting-name">
129             <xsl:value-of select="marc:subfield[@code='a']"/>
130         </pz:metadata>
131         <pz:metadata type="meeting-location">
132             <xsl:value-of select="marc:subfield[@code='c']"/>
133         </pz:metadata>
134         <pz:metadata type="meeting-date">
135             <xsl:value-of select="marc:subfield[@code='d']"/>
136         </pz:metadata>
137       </xsl:for-each>
138
139       <xsl:for-each select="marc:datafield[@tag='260']">
140         <pz:metadata type="date">
141             <xsl:value-of select="marc:subfield[@code='c']"/>
142         </pz:metadata>
143       </xsl:for-each>
144
145       <xsl:for-each select="marc:datafield[@tag='245']">
146         <pz:metadata type="title">
147           <xsl:value-of select="marc:subfield[@code='a']"/>
148         </pz:metadata>
149         <pz:metadata type="title-remainder">
150           <xsl:value-of select="marc:subfield[@code='b']"/>
151         </pz:metadata>
152         <pz:metadata type="title-responsibility">
153           <xsl:value-of select="marc:subfield[@code='c']"/>
154         </pz:metadata>
155         <pz:metadata type="title-dates">
156           <xsl:value-of select="marc:subfield[@code='f']"/>
157         </pz:metadata>
158         <pz:metadata type="title-medium">
159           <xsl:value-of select="marc:subfield[@code='h']"/>
160         </pz:metadata>
161         <pz:metadata type="title-number-section">
162           <xsl:value-of select="marc:subfield[@code='n']"/>
163         </pz:metadata>
164       </xsl:for-each>
165
166       <xsl:for-each select="marc:datafield[@tag='250']">
167         <pz:metadata type="edition">
168             <xsl:value-of select="marc:subfield[@code='a']"/>
169         </pz:metadata>
170       </xsl:for-each>
171
172       <xsl:for-each select="marc:datafield[@tag='260']">
173         <pz:metadata type="publication-place">
174           <xsl:value-of select="marc:subfield[@code='a']"/>
175         </pz:metadata>
176         <pz:metadata type="publication-name">
177           <xsl:value-of select="marc:subfield[@code='b']"/>
178         </pz:metadata>
179         <pz:metadata type="publication-date">
180           <xsl:value-of select="marc:subfield[@code='c']"/>
181         </pz:metadata>
182       </xsl:for-each>
183
184       <xsl:for-each select="marc:datafield[@tag='300']">
185         <pz:metadata type="physical-extent">
186           <xsl:value-of select="marc:subfield[@code='a']"/>
187         </pz:metadata>
188         <pz:metadata type="physical-format">
189           <xsl:value-of select="marc:subfield[@code='b']"/>
190         </pz:metadata>
191         <pz:metadata type="physical-dimensions">
192           <xsl:value-of select="marc:subfield[@code='c']"/>
193         </pz:metadata>
194         <pz:metadata type="physical-accomp">
195           <xsl:value-of select="marc:subfield[@code='e']"/>
196         </pz:metadata>
197         <pz:metadata type="physical-unittype">
198           <xsl:value-of select="marc:subfield[@code='f']"/>
199         </pz:metadata>
200         <pz:metadata type="physical-unitsize">
201           <xsl:value-of select="marc:subfield[@code='g']"/>
202         </pz:metadata>
203         <pz:metadata type="physical-specified">
204           <xsl:value-of select="marc:subfield[@code='3']"/>
205         </pz:metadata>
206       </xsl:for-each>
207
208       <xsl:for-each select="marc:datafield[@tag='440']">
209         <pz:metadata type="series-title">
210           <xsl:value-of select="marc:subfield[@code='a']"/>
211         </pz:metadata>
212       </xsl:for-each>
213
214       <xsl:for-each select="marc:datafield[@tag = '500' or @tag = '505' or
215                 @tag = '518' or @tag = '520' or @tag = '522']">
216         <pz:metadata type="description">
217             <xsl:value-of select="*/text()"/>
218         </pz:metadata>
219       </xsl:for-each>
220       
221       <xsl:for-each select="marc:datafield[@tag='600' or @tag='610' or @tag='611' or @tag='630' or @tag='648' or @tag='650' or @tag='651' or @tag='653' or @tag='654' or @tag='655' or @tag='656' or @tag='657' or @tag='658' or @tag='662' or @tag='69X']">
222         <pz:metadata type="subject">
223           <xsl:value-of select="marc:subfield[@code='a']"/>
224         </pz:metadata>
225         <pz:metadata type="subject-long">
226           <xsl:for-each select="marc:subfield">
227             <xsl:if test="position() > 1">
228               <xsl:text>, </xsl:text>
229             </xsl:if>
230             <xsl:value-of select="."/>
231           </xsl:for-each>
232         </pz:metadata>
233       </xsl:for-each>
234
235       <xsl:for-each select="marc:datafield[@tag='856']">
236         <pz:metadata type="electronic-url">
237           <xsl:value-of select="marc:subfield[@code='u']"/>
238         </pz:metadata>
239         <pz:metadata type="electronic-text">
240           <xsl:value-of select="marc:subfield[@code='y' or @code='3']"/>
241         </pz:metadata>
242         <pz:metadata type="electronic-note">
243           <xsl:value-of select="marc:subfield[@code='z']"/>
244         </pz:metadata>
245         <pz:metadata type="electronic-format-instruction">
246           <xsl:value-of select="marc:subfield[@code='i']"/>
247         </pz:metadata>
248         <pz:metadata type="electronic-format-type">
249           <xsl:value-of select="marc:subfield[@code='q']"/>
250         </pz:metadata>
251       </xsl:for-each>
252
253       <pz:metadata type="has-fulltext">
254         <xsl:value-of select="$has_fulltext"/> 
255       </pz:metadata>
256
257       <xsl:for-each select="marc:datafield[@tag='773']">
258         <pz:metadata type="citation">
259               <xsl:for-each select="*">
260                 <xsl:value-of select="normalize-space(.)"/>
261                 <xsl:text> </xsl:text>
262           </xsl:for-each>
263         </pz:metadata>
264         <xsl:if test="marc:subfield[@code='t']">
265           <pz:metadata type="journal-title">
266                 <xsl:value-of select="marc:subfield[@code='t']"/>
267           </pz:metadata>          
268         </xsl:if>
269         <xsl:if test="marc:subfield[@code='g']">
270           <pz:metadata type="journal-subpart">
271                 <xsl:value-of select="marc:subfield[@code='g']"/>
272           </pz:metadata>          
273         </xsl:if>
274       </xsl:for-each>
275
276       <xsl:for-each select="marc:datafield[@tag='852']">
277         <xsl:if test="marc:subfield[@code='y']">
278           <pz:metadata type="publicnote">
279             <xsl:value-of select="marc:subfield[@code='y']"/>
280           </pz:metadata>
281         </xsl:if>
282         <xsl:if test="marc:subfield[@code='h']">
283           <pz:metadata type="callnumber">
284             <xsl:value-of select="marc:subfield[@code='h']"/>
285           </pz:metadata>
286         </xsl:if>
287       </xsl:for-each>
288
289       <pz:metadata type="medium">
290         <xsl:value-of select="$medium"/>
291       </pz:metadata>
292       
293       <xsl:for-each select="marc:datafield[@tag='900']/marc:subfield[@code='a']">
294         <pz:metadata type="fulltext">
295           <xsl:value-of select="."/>
296         </pz:metadata>
297       </xsl:for-each>
298
299       <!-- <xsl:if test="$fulltext_a">
300         <pz:metadata type="fulltext">
301           <xsl:value-of select="$fulltext_a"/>
302         </pz:metadata>
303       </xsl:if> -->
304
305       <xsl:for-each select="marc:datafield[@tag='900']/marc:subfield[@code='b']">
306         <pz:metadata type="fulltext">
307           <xsl:value-of select="."/>
308         </pz:metadata>
309       </xsl:for-each>
310
311       <!-- <xsl:if test="$fulltext_b">
312         <pz:metadata type="fulltext">
313           <xsl:value-of select="$fulltext_b"/>
314         </pz:metadata>
315       </xsl:if> -->
316
317       <xsl:for-each select="marc:datafield[@tag='907' or @tag='901']">
318         <pz:metadata type="iii-id">
319           <xsl:value-of select="marc:subfield[@code='a']"/>
320         </pz:metadata>
321       </xsl:for-each>
322
323       <xsl:for-each select="marc:datafield[@tag='926']">
324         <pz:metadata type="holding">
325           <xsl:for-each select="marc:subfield">
326             <xsl:if test="position() > 1">
327               <xsl:text> </xsl:text>
328             </xsl:if>
329             <xsl:value-of select="."/>
330           </xsl:for-each>
331         </pz:metadata>
332       </xsl:for-each>
333
334       <xsl:for-each select="marc:datafield[@tag='948']">
335         <pz:metadata type="holding">
336           <xsl:for-each select="marc:subfield">
337             <xsl:if test="position() > 1">
338               <xsl:text> </xsl:text>
339             </xsl:if>
340             <xsl:value-of select="."/>
341           </xsl:for-each>
342         </pz:metadata>
343       </xsl:for-each>
344
345       <xsl:for-each select="marc:datafield[@tag='991']">
346         <pz:metadata type="holding">
347           <xsl:for-each select="marc:subfield">
348             <xsl:if test="position() > 1">
349               <xsl:text> </xsl:text>
350             </xsl:if>
351             <xsl:value-of select="."/>
352           </xsl:for-each>
353         </pz:metadata>
354       </xsl:for-each>
355
356       <!-- passthrough id data -->
357       <xsl:for-each select="pz:metadata">
358           <xsl:copy-of select="."/>
359       </xsl:for-each>
360
361       <!-- other stylesheets importing this might want to define this -->
362       <xsl:call-template name="record-hook"/>
363
364     </pz:record>    
365   </xsl:template>
366   
367   <xsl:template match="text()"/>
368
369 </xsl:stylesheet>