Merge branch 'master' of ssh://git.indexdata.com/home/git/pub/pazpar2
[pazpar2-moved-to-github.git] / etc / marc22.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="substring-after(substring-before($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     <pz:record>
46
47       <pz:metadata type="medium">
48         <xsl:value-of select="$medium"/>
49       </pz:metadata>
50
51       <xsl:apply-templates/>
52
53       <!-- other stylesheets importing this might want to define this -->
54       <xsl:call-template name="record-hook"/>
55
56     </pz:record>    
57   </xsl:template>
58
59   <xsl:template match="marc:controlfield[@tag='001']">
60     <pz:metadata type="id">
61       <xsl:value-of select="."/>
62     </pz:metadata>
63   </xsl:template>
64
65   <xsl:template match="marc:datafield[@tag='010']">
66     <pz:metadata type="lccn">
67       <xsl:value-of select="marc:subfield[@code='a']"/>
68     </pz:metadata>
69   </xsl:template>
70
71   <xsl:template match="marc:datafield[@tag='020']">
72     <pz:metadata type="isbn">
73       <xsl:value-of select="marc:subfield[@code='a']"/>
74     </pz:metadata>
75   </xsl:template>
76   
77   <!-- does ANYONE need this?
78   <xsl:template match="marc:datafield[@tag='027']">
79     <pz:metadata type="tech-rep-nr">
80       <xsl:value-of select="marc:subfield[@code='a']"/>
81     </pz:metadata>
82   </xsl:template>
83   -->
84   
85   <xsl:template match="marc:datafield[@tag='035']">
86     <pz:metadata type="system-control-nr">
87       <xsl:value-of select="marc:subfield[@code='a']"/>
88     </pz:metadata>
89   </xsl:template>
90   
91   <xsl:template match="marc:datafield[@tag='100' or @tag='700']">
92     <pz:metadata type="author">
93       <xsl:value-of select="marc:subfield[@code='a']"/>
94     </pz:metadata>
95     <pz:metadata type="author-title">
96       <xsl:value-of select="marc:subfield[@code='c']"/>
97     </pz:metadata>
98     <pz:metadata type="author-date">
99       <xsl:value-of select="marc:subfield[@code='d']"/>
100     </pz:metadata>
101   </xsl:template>
102
103   <xsl:template match="marc:datafield[@tag='110']">
104     <pz:metadata type="corporate-name">
105       <xsl:value-of select="marc:subfield[@code='a']"/>
106     </pz:metadata>
107     <pz:metadata type="corporate-location">
108       <xsl:value-of select="marc:subfield[@code='c']"/>
109     </pz:metadata>
110     <pz:metadata type="corporate-date">
111       <xsl:value-of select="marc:subfield[@code='d']"/>
112     </pz:metadata>
113   </xsl:template>
114
115   <xsl:template match="marc:datafield[@tag='111']">
116     <pz:metadata type="meeting-name">
117       <xsl:value-of select="marc:subfield[@code='a']"/>
118     </pz:metadata>
119     <pz:metadata type="meeting-location">
120       <xsl:value-of select="marc:subfield[@code='c']"/>
121     </pz:metadata>
122     <pz:metadata type="meeting-date">
123       <xsl:value-of select="marc:subfield[@code='d']"/>
124     </pz:metadata>
125   </xsl:template>
126
127   <xsl:template match="marc:datafield[@tag='245']">
128     <pz:metadata type="title">
129       <xsl:value-of select="marc:subfield[@code='a']"/>
130     </pz:metadata>
131     <pz:metadata type="title-remainder">
132       <xsl:value-of select="marc:subfield[@code='b']"/>
133     </pz:metadata>
134     <pz:metadata type="title-responsibility">
135       <xsl:value-of select="marc:subfield[@code='c']"/>
136     </pz:metadata>
137     <pz:metadata type="title-dates">
138       <xsl:value-of select="marc:subfield[@code='f']"/>
139     </pz:metadata>
140     <pz:metadata type="title-medium">
141       <xsl:value-of select="marc:subfield[@code='h']"/>
142     </pz:metadata>
143     <pz:metadata type="title-number-section">
144       <xsl:value-of select="marc:subfield[@code='n']"/>
145     </pz:metadata>
146   </xsl:template>
147
148   <xsl:template match="marc:datafield[@tag='250']">
149     <pz:metadata type="edition">
150         <xsl:value-of select="marc:subfield[@code='a']"/>
151     </pz:metadata>
152   </xsl:template>
153
154   <xsl:template match="marc:datafield[@tag='260']">
155     <pz:metadata type="publication-place">
156       <xsl:value-of select="marc:subfield[@code='a']"/>
157     </pz:metadata>
158     <pz:metadata type="publication-name">
159       <xsl:value-of select="marc:subfield[@code='b']"/>
160     </pz:metadata>
161     <pz:metadata type="publication-date">
162       <xsl:value-of select="marc:subfield[@code='c']"/>
163     </pz:metadata>
164     <pz:metadata type="date">
165       <xsl:value-of select="marc:subfield[@code='c']"/>
166     </pz:metadata>
167   </xsl:template>
168
169   <xsl:template match="marc:datafield[@tag='300']">
170     <pz:metadata type="physical-extent">
171       <xsl:value-of select="marc:subfield[@code='a']"/>
172     </pz:metadata>
173     <pz:metadata type="physical-format">
174       <xsl:value-of select="marc:subfield[@code='b']"/>
175     </pz:metadata>
176     <pz:metadata type="physical-dimensions">
177       <xsl:value-of select="marc:subfield[@code='c']"/>
178     </pz:metadata>
179     <pz:metadata type="physical-accomp">
180       <xsl:value-of select="marc:subfield[@code='e']"/>
181     </pz:metadata>
182     <pz:metadata type="physical-unittype">
183       <xsl:value-of select="marc:subfield[@code='f']"/>
184     </pz:metadata>
185     <pz:metadata type="physical-unitsize">
186       <xsl:value-of select="marc:subfield[@code='g']"/>
187     </pz:metadata>
188     <pz:metadata type="physical-specified">
189       <xsl:value-of select="marc:subfield[@code='3']"/>
190     </pz:metadata>
191   </xsl:template>
192
193   <xsl:template match="marc:datafield[@tag='440']">
194     <pz:metadata type="series-title">
195       <xsl:value-of select="marc:subfield[@code='a']"/>
196     </pz:metadata>
197   </xsl:template>
198
199   <xsl:template match="marc:datafield[@tag = '500' or @tag = '505' or
200             @tag = '518' or @tag = '520' or @tag = '522']">
201     <pz:metadata type="description">
202         <xsl:value-of select="*/text()"/>
203     </pz:metadata>
204   </xsl:template>
205   
206   <xsl:template match="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']">
207     <pz:metadata type="subject">
208       <xsl:value-of select="marc:subfield[@code='a']"/>
209     </pz:metadata>
210     <pz:metadata type="subject-long">
211       <xsl:for-each select="marc:subfield">
212         <xsl:if test="position() > 1">
213           <xsl:text>, </xsl:text>
214         </xsl:if>
215         <xsl:value-of select="."/>
216       </xsl:for-each>
217     </pz:metadata>
218   </xsl:template>
219
220   <xsl:template match="marc:datafield[@tag='856']">
221     <pz:metadata type="electronic-url">
222       <xsl:value-of select="marc:subfield[@code='u']"/>
223     </pz:metadata>
224     <pz:metadata type="electronic-text">
225       <xsl:value-of select="marc:subfield[@code='y' or @code='3']"/>
226     </pz:metadata>
227     <pz:metadata type="electronic-note">
228       <xsl:value-of select="marc:subfield[@code='z']"/>
229     </pz:metadata>
230   </xsl:template>
231
232   <xsl:template match="marc:datafield[@tag='773']">
233     <pz:metadata type="citation">
234       <xsl:for-each select="*">
235         <xsl:value-of select="normalize-space(.)"/>
236         <xsl:text> </xsl:text>
237       </xsl:for-each>
238     </pz:metadata>
239   </xsl:template>
240
241   <xsl:template match="marc:datafield[@tag='852']">
242     <xsl:if test="marc:subfield[@code='y']">
243       <pz:metadata type="publicnote">
244         <xsl:value-of select="marc:subfield[@code='y']"/>
245       </pz:metadata>
246     </xsl:if>
247     <xsl:if test="marc:subfield[@code='h']">
248       <pz:metadata type="callnumber">
249         <xsl:value-of select="marc:subfield[@code='h']"/>
250       </pz:metadata>
251     </xsl:if>
252   </xsl:template>
253
254   <xsl:template match="marc:datafield[@tag='900']/marc:subfield[@code='a']">
255     <pz:metadata type="fulltext">
256       <xsl:value-of select="."/>
257     </pz:metadata>
258   </xsl:template>
259
260   <xsl:template match="marc:datafield[@tag='907' or @tag='901']">
261     <pz:metadata type="iii-id">
262       <xsl:value-of select="marc:subfield[@code='a']"/>
263     </pz:metadata>
264   </xsl:template>
265
266   <xsl:template match="marc:datafield[@tag='926']">
267     <pz:metadata type="holding">
268       <xsl:for-each select="marc:subfield">
269         <xsl:if test="position() > 1">
270           <xsl:text> </xsl:text>
271         </xsl:if>
272         <xsl:value-of select="."/>
273       </xsl:for-each>
274     </pz:metadata>
275   </xsl:template>
276
277   <xsl:template match="marc:datafield[@tag='948']">
278     <pz:metadata type="holding">
279       <xsl:for-each select="marc:subfield">
280         <xsl:if test="position() > 1">
281           <xsl:text> </xsl:text>
282         </xsl:if>
283         <xsl:value-of select="."/>
284       </xsl:for-each>
285     </pz:metadata>
286   </xsl:template>
287
288   <xsl:template match="marc:datafield[@tag='991']">
289     <pz:metadata type="holding">
290       <xsl:for-each select="marc:subfield">
291         <xsl:if test="position() > 1">
292           <xsl:text> </xsl:text>
293         </xsl:if>
294         <xsl:value-of select="."/>
295       </xsl:for-each>
296     </pz:metadata>
297   </xsl:template>
298
299   <xsl:template match="pz:metadata">
300       <xsl:copy-of select="."/>
301   </xsl:template>
302
303       <!-- other stylesheets importing this might want to define this -->
304   <xsl:template match="text()"/>
305
306 </xsl:stylesheet>