Out defined DEBUG logging of sel_thread size
[pazpar2-moved-to-github.git] / test / tmarcxml.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:tmarc="http://www.indexdata.com/MARC21/turboxml" >
7   
8   <xsl:output indent="yes" method="xml" version="1.0" encoding="UTF-8"/>
9
10 <!-- 
11      Extract metadata from MARC21/USMARC from streamlined marcxml format
12       http://www.loc.gov/marc/bibliographic/ecbdhome.html
13 -->  
14   <xsl:template name="record-hook"/>
15
16
17   <xsl:template match="/">
18     <pz:collection>
19      <xsl:apply-templates/>
20     </pz:collection>
21   </xsl:template>
22
23   <xsl:template match="tmarc:r">
24     <xsl:variable name="title_medium" select="tmarc:d245/tmarc:sh"/>
25     <xsl:variable name="journal_title" select="tmarc:d773/tmarc:st"/>
26     <xsl:variable name="electronic_location_url" select="tmarc:d856/tmarc:su"/>
27     <xsl:variable name="fulltext_a" select="tmarc:d900/tmarc:sa"/>
28     <xsl:variable name="fulltext_b" select="tmarc:d900/tmarc:sb"/>
29         <!-- Does not always hit the right substring. The field is not always fixed-width? -->
30     <xsl:variable name="control_lang" select="substring(tmarc:c008, 36, 3)"/>
31     <xsl:variable name="contains110" select="tmarc:d110"/>
32     <xsl:variable name="hasAuthorFields" select="tmarc:d100 or tmarc:d111"/>
33     
34     <xsl:variable name="medium">
35         <xsl:choose>
36                 <xsl:when test="$title_medium">
37                         <xsl:value-of select="translate($title_medium, ' []/', '')" />
38                 </xsl:when>
39                 <xsl:when test="$fulltext_a">
40                         <xsl:text>electronic resource</xsl:text>
41                 </xsl:when>
42                 <xsl:when test="$fulltext_b">
43                         <xsl:text>electronic resource</xsl:text>
44                 </xsl:when>
45                 <xsl:when test="$journal_title">
46                         <xsl:text>article</xsl:text>
47                 </xsl:when>
48                 <xsl:otherwise>
49                         <xsl:text>book</xsl:text>
50                 </xsl:otherwise>
51         </xsl:choose>
52     </xsl:variable>
53
54     <pz:record>
55         <xsl:attribute name="mergekey">
56         <xsl:text>title </xsl:text>
57         <xsl:value-of select="tmarc:d245/tmarc:sa" />
58         <xsl:text> author </xsl:text>
59         <xsl:value-of select="tmarc:d100/tmarc:sa" />
60         <xsl:text> medium </xsl:text>
61         <xsl:value-of select="$medium" />
62       </xsl:attribute>
63
64       <xsl:for-each select="tmarc:c001">
65         <pz:metadata type="id">
66           <xsl:value-of select="."/>
67         </pz:metadata>
68       </xsl:for-each>
69
70       <xsl:for-each select="tmarc:d010">
71         <pz:metadata type="lccn">
72           <xsl:value-of select="tmarc:sa"/>
73         </pz:metadata>
74       </xsl:for-each>
75
76       <xsl:for-each select="tmarc:d020">
77         <pz:metadata type="isbn">
78           <xsl:value-of select="tmarc:sa"/>
79         </pz:metadata>
80       </xsl:for-each>
81
82       <xsl:for-each select="tmarc:d022">
83         <pz:metadata type="issn">
84           <xsl:value-of select="tmarc:sa"/>
85         </pz:metadata>
86       </xsl:for-each>
87
88       <xsl:for-each select="tmarc:d027">
89         <pz:metadata type="tech-rep-nr">
90           <xsl:value-of select="tmarc:sa"/>
91         </pz:metadata>
92       </xsl:for-each>
93
94       <xsl:for-each select="tmarc:d035">
95         <pz:metadata type="system-control-nr">
96           <xsl:value-of select="tmarc:sa"/>
97         </pz:metadata>
98       </xsl:for-each>
99
100       <xsl:for-each select="tmarc:d100">
101         <pz:metadata type="author">
102           <xsl:value-of select="tmarc:sa"/>
103         </pz:metadata>
104         <pz:metadata type="author-title">
105           <xsl:value-of select="tmarc:sc"/>
106         </pz:metadata>
107         <pz:metadata type="author-date">
108           <xsl:value-of select="tmarc:sd"/>
109         </pz:metadata>
110       </xsl:for-each>
111
112       <xsl:for-each select="tmarc:d110">
113         <pz:metadata type="corporate-name">
114             <xsl:value-of select="tmarc:sa"/>
115         </pz:metadata>
116         <pz:metadata type="corporate-location">
117             <xsl:value-of select="tmarc:sc"/>
118         </pz:metadata>
119         <pz:metadata type="corporate-date">
120             <xsl:value-of select="tmarc:sd"/>
121         </pz:metadata>
122       </xsl:for-each>
123
124       <xsl:for-each select="tmarc:d111">
125         <pz:metadata type="meeting-name">
126             <xsl:value-of select="tmarc:sa"/>
127         </pz:metadata>
128         <pz:metadata type="meeting-location">
129             <xsl:value-of select="tmarc:sc"/>
130         </pz:metadata>
131         <pz:metadata type="meeting-date">
132             <xsl:value-of select="tmarc:sd"/>
133         </pz:metadata>
134       </xsl:for-each>
135
136       <xsl:for-each select="tmarc:d260">
137         <pz:metadata type="date">
138             <xsl:value-of select="tmarc:sc"/>
139         </pz:metadata>
140       </xsl:for-each>
141
142       <xsl:for-each select="tmarc:d130">
143         <pz:metadata type="title-uniform">
144           <xsl:value-of select="tmarc:sa"/>
145         </pz:metadata>
146         <pz:metadata type="title-uniform-media">
147           <xsl:value-of select="tmarc:sm"/>
148         </pz:metadata>
149         <pz:metadata type="title-uniform-parts">
150           <xsl:value-of select="tmarc:sn"/>
151         </pz:metadata>
152         <pz:metadata type="title-uniform-partname">
153           <xsl:value-of select="tmarc:sp"/>
154         </pz:metadata>
155         <pz:metadata type="title-uniform-key">
156           <xsl:value-of select="tmarc:sr"/>
157         </pz:metadata>
158       </xsl:for-each>
159
160       <xsl:for-each select="tmarc:d245">
161         <pz:metadata type="title">
162           <xsl:value-of select="tmarc:sa"/>
163         </pz:metadata>
164         <pz:metadata type="title-remainder">
165           <xsl:value-of select="tmarc:sb"/>
166         </pz:metadata>
167         <pz:metadata type="title-responsibility">
168           <xsl:value-of select="tmarc:sc"/>
169         </pz:metadata>
170         <pz:metadata type="title-dates">
171           <xsl:value-of select="tmarc:sf"/>
172         </pz:metadata>
173         <pz:metadata type="title-medium">
174           <xsl:value-of select="tmarc:sh"/>
175         </pz:metadata>
176         <pz:metadata type="title-number-section">
177           <xsl:value-of select="tmarc:sn"/>
178         </pz:metadata>
179       </xsl:for-each>
180
181       <xsl:for-each select="tmarc:d250">
182         <pz:metadata type="edition">
183             <xsl:value-of select="tmarc:sa"/>
184         </pz:metadata>
185       </xsl:for-each>
186
187       <xsl:for-each select="tmarc:d260">
188         <pz:metadata type="publication-place">
189           <xsl:value-of select="tmarc:sa"/>
190         </pz:metadata>
191         <pz:metadata type="publication-name">
192           <xsl:value-of select="tmarc:sb"/>
193         </pz:metadata>
194         <pz:metadata type="publication-date">
195           <xsl:value-of select="tmarc:sc"/>
196         </pz:metadata>
197       </xsl:for-each>
198
199       <xsl:for-each select="tmarc:d300">
200         <pz:metadata type="physical-extent">
201           <xsl:value-of select="tmarc:sa"/>
202         </pz:metadata>
203         <pz:metadata type="physical-format">
204           <xsl:value-of select="tmarc:sb"/>
205         </pz:metadata>
206         <pz:metadata type="physical-dimensions">
207           <xsl:value-of select="tmarc:sc"/>
208         </pz:metadata>
209         <pz:metadata type="physical-accomp">
210           <xsl:value-of select="tmarc:se"/>
211         </pz:metadata>
212         <pz:metadata type="physical-unittype">
213           <xsl:value-of select="tmarc:sf"/>
214         </pz:metadata>
215         <pz:metadata type="physical-unitsize">
216           <xsl:value-of select="tmarc:sg"/>
217         </pz:metadata>
218         <pz:metadata type="physical-specified">
219           <xsl:value-of select="tmarc:s3"/>
220         </pz:metadata>
221       </xsl:for-each>
222
223       <xsl:for-each select="tmarc:d440">
224         <pz:metadata type="series-title">
225           <xsl:value-of select="tmarc:sa"/>
226         </pz:metadata>
227       </xsl:for-each>
228
229       <xsl:for-each select="tmarc:d500">
230         <pz:metadata type="description">
231           <xsl:value-of select="*/text()"/>
232         </pz:metadata>
233       </xsl:for-each>
234
235       <xsl:for-each select="tmarc:d505">
236         <pz:metadata type="description">
237           <xsl:value-of select="*/text()"/>
238         </pz:metadata>
239       </xsl:for-each>
240
241       <xsl:for-each select="tmarc:d518">
242         <pz:metadata type="description">
243           <xsl:value-of select="*/text()"/>
244         </pz:metadata>
245       </xsl:for-each>
246
247       <xsl:for-each select="tmarc:d520">
248         <pz:metadata type="description">
249           <xsl:value-of select="*/text()"/>
250         </pz:metadata>
251       </xsl:for-each>
252
253       <xsl:for-each select="tmarc:d522">
254         <pz:metadata type="description">
255           <xsl:value-of select="*/text()"/>
256         </pz:metadata>
257       </xsl:for-each>
258
259       <xsl:for-each select="tmarc:d600" > 
260         <pz:metadata type="subject">
261           <xsl:value-of select="tmarc:sa"/>
262         </pz:metadata>
263         <pz:metadata type="subject-long">
264           <xsl:for-each select="node()/text()">
265             <xsl:if test="position() > 1">
266               <xsl:text>, </xsl:text>
267             </xsl:if>
268             <xsl:value-of select="."/>
269           </xsl:for-each>
270         </pz:metadata>
271       </xsl:for-each>
272
273       <xsl:for-each select="tmarc:d610" > 
274         <pz:metadata type="subject">
275           <xsl:value-of select="tmarc:sa"/>
276         </pz:metadata>
277         <pz:metadata type="subject-long">
278           <xsl:for-each select="node()/text()">
279             <xsl:if test="position() > 1">
280               <xsl:text>, </xsl:text>
281             </xsl:if>
282             <xsl:value-of select="."/>
283           </xsl:for-each>
284         </pz:metadata>
285       </xsl:for-each>
286
287       <xsl:for-each select="tmarc:d611" > 
288         <pz:metadata type="subject">
289           <xsl:value-of select="tmarc:sa"/>
290         </pz:metadata>
291         <pz:metadata type="subject-long">
292           <xsl:for-each select="node()/text()">
293             <xsl:if test="position() > 1">
294               <xsl:text>, </xsl:text>
295             </xsl:if>
296             <xsl:value-of select="."/>
297           </xsl:for-each>
298         </pz:metadata>
299       </xsl:for-each>
300
301       <xsl:for-each select="tmarc:d630" > 
302         <pz:metadata type="subject">
303           <xsl:value-of select="tmarc:sa"/>
304         </pz:metadata>
305         <pz:metadata type="subject-long">
306           <xsl:for-each select="node()/text()">
307             <xsl:if test="position() > 1">
308               <xsl:text>, </xsl:text>
309             </xsl:if>
310             <xsl:value-of select="."/>
311           </xsl:for-each>
312         </pz:metadata>
313       </xsl:for-each>
314
315       <xsl:for-each select="tmarc:d648" > 
316         <pz:metadata type="subject">
317           <xsl:value-of select="tmarc:sa"/>
318         </pz:metadata>
319         <pz:metadata type="subject-long">
320           <xsl:for-each select="node()/text()">
321             <xsl:if test="position() > 1">
322               <xsl:text>, </xsl:text>
323             </xsl:if>
324             <xsl:value-of select="."/>
325           </xsl:for-each>
326         </pz:metadata>
327       </xsl:for-each>
328
329       <xsl:for-each select="tmarc:d650" > 
330         <pz:metadata type="subject">
331           <xsl:value-of select="tmarc:sa"/>
332         </pz:metadata>
333         <pz:metadata type="subject-long">
334           <xsl:for-each select="node()/text()">
335             <xsl:if test="position() > 1">
336               <xsl:text>, </xsl:text>
337             </xsl:if>
338             <xsl:value-of select="."/>
339           </xsl:for-each>
340         </pz:metadata>
341       </xsl:for-each>
342
343       <xsl:for-each select="tmarc:d651" > 
344         <pz:metadata type="subject">
345           <xsl:value-of select="tmarc:sa"/>
346         </pz:metadata>
347         <pz:metadata type="subject-long">
348           <xsl:for-each select="node()/text()">
349             <xsl:if test="position() > 1">
350               <xsl:text>, </xsl:text>
351             </xsl:if>
352             <xsl:value-of select="."/>
353           </xsl:for-each>
354         </pz:metadata>
355       </xsl:for-each>
356
357       <xsl:for-each select="tmarc:d653" > 
358         <pz:metadata type="subject">
359           <xsl:value-of select="tmarc:sa"/>
360         </pz:metadata>
361         <pz:metadata type="subject-long">
362           <xsl:for-each select="node()/text()">
363             <xsl:if test="position() > 1">
364               <xsl:text>, </xsl:text>
365             </xsl:if>
366             <xsl:value-of select="."/>
367           </xsl:for-each>
368         </pz:metadata>
369       </xsl:for-each>
370
371       <xsl:for-each select="tmarc:d654" > 
372         <pz:metadata type="subject">
373           <xsl:value-of select="tmarc:sa"/>
374         </pz:metadata>
375         <pz:metadata type="subject-long">
376           <xsl:for-each select="node()/text()">
377             <xsl:if test="position() > 1">
378               <xsl:text>, </xsl:text>
379             </xsl:if>
380             <xsl:value-of select="."/>
381           </xsl:for-each>
382         </pz:metadata>
383       </xsl:for-each>
384
385       <xsl:for-each select="tmarc:d655" > 
386         <pz:metadata type="subject">
387           <xsl:value-of select="tmarc:sa"/>
388         </pz:metadata>
389         <pz:metadata type="subject-long">
390           <xsl:for-each select="node()/text()">
391             <xsl:if test="position() > 1">
392               <xsl:text>, </xsl:text>
393             </xsl:if>
394             <xsl:value-of select="."/>
395           </xsl:for-each>
396         </pz:metadata>
397       </xsl:for-each>
398
399       <xsl:for-each select="tmarc:d656" > 
400         <pz:metadata type="subject">
401           <xsl:value-of select="tmarc:sa"/>
402         </pz:metadata>
403         <pz:metadata type="subject-long">
404           <xsl:for-each select="node()/text()">
405             <xsl:if test="position() > 1">
406               <xsl:text>, </xsl:text>
407             </xsl:if>
408             <xsl:value-of select="."/>
409           </xsl:for-each>
410         </pz:metadata>
411       </xsl:for-each>
412
413       <xsl:for-each select="tmarc:d657" > 
414         <pz:metadata type="subject">
415           <xsl:value-of select="tmarc:sa"/>
416         </pz:metadata>
417         <pz:metadata type="subject-long">
418           <xsl:for-each select="node()/text()">
419             <xsl:if test="position() > 1">
420               <xsl:text>, </xsl:text>
421             </xsl:if>
422             <xsl:value-of select="."/>
423           </xsl:for-each>
424         </pz:metadata>
425       </xsl:for-each>
426
427       <xsl:for-each select="tmarc:d658" > 
428         <pz:metadata type="subject">
429           <xsl:value-of select="tmarc:sa"/>
430         </pz:metadata>
431         <pz:metadata type="subject-long">
432           <xsl:for-each select="node()/text()">
433             <xsl:if test="position() > 1">
434               <xsl:text>, </xsl:text>
435             </xsl:if>
436             <xsl:value-of select="."/>
437           </xsl:for-each>
438         </pz:metadata>
439       </xsl:for-each>
440
441       <xsl:for-each select="tmarc:d662" > 
442         <pz:metadata type="subject">
443           <xsl:value-of select="tmarc:sa"/>
444         </pz:metadata>
445         <pz:metadata type="subject-long">
446           <xsl:for-each select="node()/text()">
447             <xsl:if test="position() > 1">
448               <xsl:text>, </xsl:text>
449             </xsl:if>
450             <xsl:value-of select="."/>
451           </xsl:for-each>
452         </pz:metadata>
453       </xsl:for-each>
454
455       <xsl:for-each select="tmarc:d69X" > 
456         <pz:metadata type="subject">
457           <xsl:value-of select="tmarc:sa"/>
458         </pz:metadata>
459         <pz:metadata type="subject-long">
460           <xsl:for-each select="node()/text()">
461             <xsl:if test="position() > 1">
462               <xsl:text>, </xsl:text>
463             </xsl:if>
464             <xsl:value-of select="."/>
465           </xsl:for-each>
466         </pz:metadata>
467       </xsl:for-each>
468
469 <!--
470      or tmarc:d651 or tmarc:d653 or tmarc:d654 or tmarc:d655 or tmarc:d656 or tmarc:d657 or tmarc:d658 or tmarc:d662 or tmarc:d69X">
471 -->
472
473 <!--
474       <xsl:for-each select="tmarc:d600" > 
475         <pz:metadata type="subject">
476           <xsl:value-of select="tmarc:sa"/>
477         </pz:metadata>
478         <pz:metadata type="subject-long">
479           <xsl:for-each select="tmarc:sa tmarc:sb tmarc:sc tmarc:sd ">
480             <xsl:if test="position() > 1">
481               <xsl:text>, </xsl:text>
482             </xsl:if>
483             <xsl:value-of select="."/>
484           </xsl:for-each>
485         </pz:metadata>
486       </xsl:for-each>
487 -->
488
489       <xsl:for-each select="tmarc:d856">
490         <pz:metadata type="electronic-url">
491           <xsl:value-of select="tmarc:su"/>
492         </pz:metadata>
493         <pz:metadata type="electronic-text">
494           <xsl:if test="tmarc:sy" >
495             <xsl:value-of select="tmarc:sy/text()" />
496           </xsl:if>
497           <xsl:if test="tmarc:s3">
498             <xsl:value-of select="tmarc:s3/text()" />
499           </xsl:if>
500         </pz:metadata>
501         <pz:metadata type="electronic-note">
502           <xsl:value-of select="tmarc:sz"/>
503         </pz:metadata>
504         <pz:metadata type="electronic-format-instruction">
505           <xsl:value-of select="tmarc:si"/>
506         </pz:metadata>
507         <pz:metadata type="electronic-format-type">
508           <xsl:value-of select="tmarc:sq"/>
509         </pz:metadata>
510       </xsl:for-each>
511
512       <xsl:for-each select="tmarc:d773">
513         <pz:metadata type="citation">
514           <xsl:for-each select="*">
515             <xsl:value-of select="normalize-space(.)"/>
516             <xsl:text> </xsl:text>
517           </xsl:for-each>
518         </pz:metadata>
519       </xsl:for-each>
520
521       <xsl:for-each select="tmarc:d852">
522         <xsl:if test="tmarc:sy">
523           <pz:metadata type="publicnote">
524             <xsl:value-of select="tmarc:sy"/>
525           </pz:metadata>
526         </xsl:if>
527         <xsl:if test="tmarc:sh">
528           <pz:metadata type="callnumber">
529             <xsl:value-of select="tmarc:sh"/>
530           </pz:metadata>
531         </xsl:if>
532       </xsl:for-each>
533
534       <pz:metadata type="medium">
535         <xsl:value-of select="$medium"/>
536       </pz:metadata>
537       
538       <xsl:for-each select="tmarc:d900/tmarc:sa">
539         <pz:metadata type="fulltext">
540           <xsl:value-of select="."/>
541         </pz:metadata>
542       </xsl:for-each>
543
544       <!-- <xsl:if test="$fulltext_a">
545         <pz:metadata type="fulltext">
546           <xsl:value-of select="$fulltext_a"/>
547         </pz:metadata>
548       </xsl:if>
549 -->
550
551       <xsl:for-each select="tmarc:d900/tmarc:sb">
552         <pz:metadata type="fulltext">
553           <xsl:value-of select="."/>
554         </pz:metadata>
555       </xsl:for-each>
556
557       <!-- <xsl:if test="$fulltext_b">
558         <pz:metadata type="fulltext">
559           <xsl:value-of select="$fulltext_b"/>
560         </pz:metadata>
561       </xsl:if>
562 -->
563
564       <xsl:for-each select="tmarc:d907">
565 <!--  or tmarc:d901"> -->
566         <pz:metadata type="iii-id">
567           <xsl:value-of select="tmarc:sa"/>
568         </pz:metadata>
569       </xsl:for-each>
570
571       <xsl:for-each select="tmarc:d926">
572         <pz:metadata type="holding">
573           <xsl:for-each select="tmarc:s">
574             <xsl:if test="position() > 1">
575               <xsl:text> </xsl:text>
576             </xsl:if>
577             <xsl:value-of select="."/>
578           </xsl:for-each>
579         </pz:metadata>
580       </xsl:for-each>
581
582       <xsl:for-each select="tmarc:d948">
583         <pz:metadata type="holding">
584           <xsl:for-each select="tmarc:s">
585             <xsl:if test="position() > 1">
586               <xsl:text> </xsl:text>
587             </xsl:if>
588             <xsl:value-of select="."/>
589           </xsl:for-each>
590         </pz:metadata>
591       </xsl:for-each>
592
593       <xsl:for-each select="tmarc:d991">
594         <pz:metadata type="holding">
595           <xsl:for-each select="tmarc:s">
596             <xsl:if test="position() > 1">
597               <xsl:text> </xsl:text>
598             </xsl:if>
599             <xsl:value-of select="."/>
600           </xsl:for-each>
601         </pz:metadata>
602       </xsl:for-each>
603
604       <!-- passthrough id data -->
605       <xsl:for-each select="pz:metadata">
606           <xsl:copy-of select="."/>
607       </xsl:for-each>
608
609       <!-- other stylesheets importing this might want to define this -->
610       <xsl:call-template name="record-hook"/>
611
612     </pz:record>    
613   </xsl:template>
614   
615   <xsl:template match="text()"/>
616
617   <xsl:template name="shortTitle">
618     <xsl:param name="tag" />
619     <xsl:for-each select="tmarc:d">
620       <xsl:value-of select="tmarc:sa" />
621       <xsl:value-of select="tmarc:sm" />
622       <xsl:value-of select="tmarc:sn" />
623       <xsl:value-of select="tmarc:sp" />
624       <xsl:value-of select="tmarc:sr" />
625     </xsl:for-each>
626   </xsl:template>
627
628
629   <xsl:template name="description">
630     <xsl:param name="element" />
631     <xsl:for-each select="$element">
632         <pz:metadata type="description">
633             <xsl:value-of select="*/text()"/>
634         </pz:metadata>
635     </xsl:for-each>
636     <xsl:apply-templates/>
637   </xsl:template>
638
639
640   <xsl:template name="subject">
641     <xsl:param name="element" />
642       <xsl:for-each select="$element" > 
643         <pz:metadata type="subject">
644           <xsl:value-of select="tmarc:sa"/>
645         </pz:metadata>
646         <pz:metadata type="subject-long">
647           <xsl:for-each select="node()/text()">
648             <xsl:if test="position() > 1">
649               <xsl:text>, </xsl:text>
650             </xsl:if>
651             <xsl:value-of select="."/>
652           </xsl:for-each>
653         </pz:metadata>
654       </xsl:for-each>
655   </xsl:template>
656
657
658 </xsl:stylesheet>