added description of example
[idzebra-moved-to-github.git] / examples / marcxml / MARC21slim2INDEX.xsl
1 <?xml version="1.0" encoding="UTF-8"?>
2 <xsl:stylesheet 
3     xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
4     xmlns:z="http://indexdata.dk/zebra/xslt/1" 
5     xmlns:marc="http://www.loc.gov/MARC21/slim" 
6     version="1.0">
7
8   <!-- <xsl:include href="http://www.loc.gov/marcxml/xslt/MARC21slimUtils.xsl"/>-->
9   <!-- <xsl:include href="MARC21slimUtils.xsl"/> -->
10   <xsl:output indent="yes" method="xml" version="1.0" encoding="UTF-8"/>
11
12   <!-- disable all default text node output -->
13   <xsl:template match="text()"/>
14
15   <xsl:template match="/">
16     <xsl:if test="marc:collection">
17       <collection>
18          <xsl:apply-templates select="marc:collection/marc:record"/>
19        </collection>
20     </xsl:if>
21     <xsl:if test="marc:record">
22        <xsl:apply-templates select="marc:record"/>
23     </xsl:if>
24   </xsl:template>
25
26
27   <!-- match on marcxml record -->
28   <xsl:template match="marc:record">                
29     <xsl:variable name="leader" select="marc:leader"/>
30     <xsl:variable name="leader6" select="substring($leader,7,1)"/>
31     <xsl:variable name="leader7" select="substring($leader,8,1)"/>
32     <xsl:variable name="controlField001" select="marc:controlfield[@tag=001]"/>
33     <xsl:variable name="controlField008" select="marc:controlfield[@tag=008]"/>
34
35     <xsl:variable name="typeOf008">
36       <xsl:choose>
37         <xsl:when test="$leader6='a'">
38           <xsl:choose>
39             <xsl:when test="$leader7='a' or $leader7='c' or $leader7='d'
40                             or $leader7='m'">BK</xsl:when>
41             <xsl:when test="$leader7='b' or $leader7='i' 
42                             or $leader7='s'">SE</xsl:when>
43           </xsl:choose>
44         </xsl:when>
45         <xsl:when test="$leader6='t'">BK</xsl:when>
46         <xsl:when test="$leader6='p'">MM</xsl:when>
47         <xsl:when test="$leader6='m'">CF</xsl:when>
48         <xsl:when test="$leader6='e' or $leader6='f'">MP</xsl:when>
49         <xsl:when test="$leader6='g' or $leader6='k' or $leader6='o' 
50                         or $leader6='r'">VM</xsl:when>
51         <xsl:when test="$leader6='c' or $leader6='d' or $leader6='i' 
52                         or $leader6='j'">MU</xsl:when>
53       </xsl:choose>
54     </xsl:variable>
55
56     <z:record id="{$controlField001}" type="update">
57       <!-- <xsl:attribute name="id"></xsl:attribute> -->
58       <!-- <xsl:attribute name="type">update</xsl:attribute> -->
59       <!-- <xsl:attribute name="rank"></xsl:attribute> -->
60
61       <!-- calling simple templates working only on one field at a time -->
62       <!-- <xsl:apply-templates select="marc:controlfield"/> -->
63       <!-- <xsl:apply-templates select="marc:datafield"/> -->
64
65       <xsl:call-template name="bib1_rules"/>
66
67     </z:record>
68   </xsl:template>
69
70   <xsl:template name="bib1_rules">
71       <!-- att 1               Personal-name -->
72       <!-- att 2               Corporate-name -->
73       <!-- att 3               Conference-name -->
74       <!-- att 4               Title -->
75       <xsl:call-template name="Title"/>
76       <!-- att 5               Title-series -->
77       <!-- att 6               Title-uniform -->
78       <!-- att 7               ISBN -->
79       <!-- att 8               ISSN -->
80       <!-- att 9               LC-card-number -->
81       <!-- att 10              BNB-card-number -->
82       <!-- att 11              BGF-number -->
83       <!-- att 12              Local-number -->
84       <!-- att 13              Dewey-classification -->
85       <!-- att 14              UDC-classification -->
86       <!-- att 15              Bliss-classification -->
87       <!-- att 16              LC-call-number -->
88       <!-- att 17              NLM-call-number -->
89       <!-- att 18              NAL-call-number -->
90       <!-- att 19              MOS-call-number -->
91       <!-- att 20              Local-classification -->
92       <!-- att 21              Subject-heading -->
93       <xsl:call-template name="Subject-heading"/>
94       <!-- att 22              Subject-Rameau -->
95       <!-- att 23              BDI-index-subject -->
96       <!-- att 24              INSPEC-subject -->
97       <!-- att 25              MESH-subject -->
98       <!-- att 26              PA-subject -->
99       <!-- att 27              LC-subject-heading -->
100       <!-- att 28              RVM-subject-heading -->
101       <!-- att 29              Local-subject-index -->
102       <!-- att 30              Date -->
103       <!-- att 31              Date-of-publication -->
104       <!-- att 32              Date-of-acquisition -->
105       <!-- att 33              Title-key -->
106       <!-- att 34              Title-collective -->
107       <!-- att 35              Title-parallel -->
108       <!-- att 36              Title-cover -->
109       <!-- att 37              Title-added-title-page -->
110       <!-- att 38              Title-caption -->
111       <!-- att 39              Title-running -->
112       <!-- att 40              Title-spine -->
113       <!-- att 41              Title-other-variant -->
114       <!-- att 42              Title-former -->
115       <!-- att 43              Title-abbreviated -->
116       <!-- att 44              Title-expanded -->
117       <!-- att 45              Subject-precis -->
118       <!-- att 46              Subject-rswk -->
119       <!-- att 47              Subject-subdivision -->
120       <!-- att 48              Number-natl-biblio -->
121       <!-- att 49              Number-legal-deposit -->
122       <!-- att 50              Number-govt-pub -->
123       <!-- att 51              Number-music-publisher -->
124       <!-- att 52              Number-db -->
125       <!-- att 53              Number-local-call -->
126       <!-- att 54              Code-language -->
127       <!-- att 55              Code-geographic -->
128       <!-- att 56              Code-institution -->
129       <!-- att 57              Name-and-title -->      
130       <!-- att 58              Name-geographic -->
131       <!-- att 59              Place-publication -->
132       <!-- att 60              CODEN -->
133       <!-- att 61              Microform-generation -->
134       <!-- att 62              Abstract -->
135       <xsl:call-template name="Abstract"/>
136       <!-- att 63              Note -->
137       <!-- att 1000            Author-title -->
138       <xsl:call-template name="Author-title"/>
139       <!-- att 1001            Record-type -->
140       <!-- att 1002            Name -->
141       <!-- att 1003            Author -->
142       <xsl:call-template name="Author"/>
143       <!-- att 1004            Author-name-personal -->
144       <xsl:call-template name="Author-name-personal"/>
145       <!-- att 1005            Author-name-corporate -->
146       <xsl:call-template name="Author-name-corporate"/>
147       <!-- att 1006            Author-name-conference -->
148       <xsl:call-template name="Author-name-conference"/>
149       <!-- att 1007            Identifier-standard -->
150       <!-- att 1008            Subject-LC-childrens -->
151       <!-- att 1009            Subject-name-personal -->
152       <!-- att 1010            Body-of-text -->
153       <!-- att 1011            Date/time-added-to-db -->
154       <!-- att 1012            Date/time-last-modified -->
155       <!-- att 1013            Authority/format-id -->
156       <!-- att 1014            Concept-text -->
157       <!-- att 1015            Concept-reference -->
158       <!-- att 1016            Any -->
159       <!-- att 1017            Server-choice -->
160       <!-- att 1018            Publisher -->
161       <!-- att 1019            Record-source -->
162       <!-- att 1020            Editor -->
163       <!-- att 1021            Bib-level -->
164       <!-- att 1022            Geographic-class -->
165       <!-- att 1023            Indexed-by -->
166       <!-- att 1024            Map-scale -->
167       <!-- att 1025            Music-key -->
168       <!-- att 1026            Related-periodical -->
169       <!-- att 1027            Report-number -->
170       <!-- att 1028            Stock-number -->
171       <!-- att 1030            Thematic-number -->
172       <!-- att 1031            Material-type -->
173       <!-- att 1032            Doc-id -->
174       <!-- att 1033            Host-item -->
175       <!-- att 1034            Content-type -->
176       <!-- att 1035            Anywhere -->
177       <!-- att 1036            Author-Title-Subject -->
178   </xsl:template>
179
180
181   <xsl:template name="Abstract">
182     <xsl:for-each select="marc:datafield[@tag='520']">
183       <z:index name="Abstract" type="w">
184         <xsl:value-of select="."/>
185       </z:index>
186     </xsl:for-each>
187   </xsl:template>
188
189   <xsl:template name="Author">
190     <xsl:for-each select="marc:datafield[@tag='100']/marc:subfield[@code='a']
191                           | marc:datafield[@tag='110']
192                           | marc:datafield[@tag='111']">
193       <z:index name="Author" type="w">
194         <xsl:value-of select="."/>
195       </z:index>
196     </xsl:for-each>
197     <xsl:for-each select="marc:datafield[@tag='100']">
198       <z:index name="Author" type="p">
199         <xsl:value-of select="marc:subfield[@code='a']"/>
200         <xsl:text> </xsl:text>
201         <xsl:value-of select="marc:subfield[@code='d']"/>
202       </z:index>
203     </xsl:for-each>
204   </xsl:template>
205
206   <!-- collection info from different data fields -->
207   <xsl:template name="Author-title">
208     <xsl:if test="marc:datafield[@tag='100']
209                   and marc:datafield[@tag='245']">
210       <z:index name="Author-title" type="p">
211         <xsl:value-of 
212             select="marc:datafield[@tag='100']/marc:subfield[@code='a']"/>
213         <xsl:text> </xsl:text>
214         <xsl:value-of 
215             select="marc:datafield[@tag='100']/marc:subfield[@code='d']"/>
216         <xsl:text> </xsl:text>
217         <xsl:value-of 
218             select="marc:datafield[@tag='245']/marc:subfield[@code='a']"/>
219       </z:index>
220     </xsl:if>
221   </xsl:template>
222
223   <xsl:template name="Author-name-personal">
224     <xsl:for-each select="marc:datafield[@tag='100']">
225       <xsl:for-each select="marc:subfield[@code='a']">
226         <z:index name="Author-name-personal" type="w">
227           <xsl:value-of select="."/>
228         </z:index>
229       </xsl:for-each>
230     </xsl:for-each>
231     <xsl:for-each select="marc:datafield[@tag='100']">
232       <z:index name="Author-name-personal" type="p">
233         <xsl:value-of select="marc:subfield[@code='a']"/>
234         <xsl:text> </xsl:text>
235         <xsl:value-of select="marc:subfield[@code='d']"/>
236       </z:index>
237     </xsl:for-each>
238   </xsl:template>
239
240   <xsl:template name="Author-name-corporate">
241     <xsl:for-each select="marc:datafield[@tag='110']">
242       <z:index name="Author-name-corporate" type="w">
243         <xsl:value-of select="."/>
244       </z:index>
245     </xsl:for-each>
246   </xsl:template>
247
248   <xsl:template name="Author-name-conference">
249     <xsl:for-each select="marc:datafield[@tag='111']">
250       <z:index name="Author-name-conference" type="w">
251         <xsl:value-of select="."/>
252       </z:index>
253     </xsl:for-each>
254   </xsl:template>
255
256
257   <xsl:template name="Subject-heading">
258     <xsl:for-each select="marc:datafield[@tag='600']
259                           |marc:datafield[@tag='610']
260                           |marc:datafield[@tag='611']
261                           |marc:datafield[@tag='630']
262                           |marc:datafield[@tag='650']
263                           |marc:datafield[@tag='651']
264                           |marc:datafield[@tag='653']
265                           |marc:datafield[@tag='654']
266                           |marc:datafield[@tag='655']
267                           |marc:datafield[@tag='656']
268                           |marc:datafield[@tag='657']">
269       <z:index name="Subject-heading" type="w">
270         <xsl:value-of select="."/>
271       </z:index>
272     </xsl:for-each>
273     <xsl:for-each select="marc:datafield[@tag='600']
274                           |marc:datafield[@tag='650']
275                           |marc:datafield[@tag='651']
276                           |marc:datafield[@tag='653']">
277       <z:index name="Subject-heading" type="w">
278         <xsl:value-of select="."/>
279       </z:index>
280     </xsl:for-each>
281   </xsl:template>
282
283   <xsl:template name="Title">
284     <xsl:for-each select="marc:datafield[@tag='245']/marc:subfield[@code='a']">
285       <z:index name="Title" type="w">
286         <xsl:value-of select="."/>
287       </z:index>
288     </xsl:for-each>
289   </xsl:template>
290
291
292
293   <!--
294   <xsl:template match="marc:controlfield[@tag=005]">
295     <recordChangeDate encoding="iso8601">
296       <xsl:value-of select="."/>
297     </recordChangeDate>
298   </xsl:template>
299
300   <xsl:template match="marc:controlfield[@tag=008]">
301     <recordCreationDate encoding="marc">
302       <xsl:value-of select="substring(.,1,6)"/>
303     </recordCreationDate>
304   </xsl:template>
305
306   <xsl:template match="marc:datafield[@tag=010]">
307     <identifier>
308       <xsl:value-of select="marc:subfield[@code='a']"/>
309     </identifier>
310   </xsl:template>
311
312
313   <xsl:template match="marc:datafield[@tag=024]">
314     <identifier>
315       <xsl:value-of select="marc:subfield[@code='a']"/>
316     </identifier>
317   </xsl:template>
318
319
320   <xsl:template match="marc:datafield[@tag=040]/marc:subfield[@code='a']">
321     <recordContentSource authority="marcorg">
322       <xsl:value-of select="."/>
323     </recordContentSource>
324   </xsl:template>
325
326   <xsl:template match="marc:datafield[@tag=040]/marc:subfield[@code='b']">
327     <languageOfCataloging>
328       <languageTerm authority="iso639-2b" type="code">
329         <xsl:value-of select="."/>
330       </languageTerm>
331     </languageOfCataloging>
332   </xsl:template>
333   
334   <xsl:template match="marc:datafield[@tag=400]">
335     <variant>
336       <xsl:call-template name="variantTypeAttribute"/>
337       <name type="personal">
338         <xsl:call-template name="nameABCDQ"/>
339         <xsl:call-template name="role"/>
340       </name>
341       <xsl:apply-templates/>
342       <xsl:call-template name="title"/>
343     </variant>
344   </xsl:template>
345
346   <xsl:template match="marc:datafield[@tag=410]">
347     <variant>
348       <xsl:call-template name="variantTypeAttribute"/>
349       <name type="corporate">
350         <xsl:call-template name="nameABCDN"/>
351         <xsl:call-template name="role"/>                                
352       </name>
353       <xsl:apply-templates/>
354     </variant>
355   </xsl:template>
356
357   <xsl:template match="marc:datafield[@tag=411]">
358     <variant>
359       <xsl:call-template name="variantTypeAttribute"/>
360       <name type="conference">
361         <xsl:call-template name="nameACDENQ"/>
362       </name>
363       <xsl:apply-templates/>
364     </variant>
365   </xsl:template>
366
367   <xsl:template match="marc:datafield[@tag=500]|marc:datafield[@tag=700]">
368     <related>
369       <xsl:call-template name="relatedTypeAttribute"/>
370       <name type="personal">
371         <xsl:call-template name="setAuthority"/>                                                        
372         
373         <xsl:call-template name="nameABCDQ"/>
374         <xsl:call-template name="role"/>                                
375       </name>
376       <xsl:call-template name="title"/>
377       <xsl:apply-templates/>
378     </related>
379   </xsl:template>
380
381   <xsl:template match="marc:datafield[@tag=510]|marc:datafield[@tag=710]">
382     <related>
383       <xsl:call-template name="relatedTypeAttribute"/>
384       <name type="corporate">
385         <xsl:call-template name="setAuthority"/>
386         <xsl:call-template name="nameABCDN"/>
387         <xsl:call-template name="role"/>
388       </name>
389       <xsl:apply-templates/>
390     </related>
391   </xsl:template>
392
393   <xsl:template match="marc:datafield[@tag=511]|marc:datafield[@tag=711]">
394     <related>
395       <xsl:call-template name="relatedTypeAttribute"/>
396       <name type="conference">
397         <xsl:call-template name="setAuthority"/>
398         <xsl:call-template name="nameACDENQ"/>
399       </name>
400       <xsl:apply-templates/>
401     </related>
402   </xsl:template>
403   -->
404  
405    <!-- title processing -->
406
407   <!--
408   <xsl:template name="title">
409     <titleInfo>
410       <xsl:call-template name="setAuthority"/>
411       <title>
412         <xsl:variable name="str">
413           <xsl:for-each select="marc:subfield">
414             <xsl:if test="(contains('tfghklmors',@code) )">
415               <xsl:value-of select="text()"/>
416               <xsl:text> </xsl:text>
417             </xsl:if>
418           </xsl:for-each>
419         </xsl:variable>
420
421         <xsl:call-template name="chopPunctuation">
422           <xsl:with-param name="chopString">
423             <xsl:value-of select="substring($str,1,string-length($str)-1)"/>
424           </xsl:with-param>
425         </xsl:call-template>
426       </title>
427       <xsl:call-template name="part"/>
428     </titleInfo>
429   </xsl:template>
430    -->
431
432
433
434 </xsl:stylesheet>