Typo in the 'bytarget' fix
[pazpar2-moved-to-github.git] / etc / tmarc.xsl
1 <?xml version="1.0" encoding="UTF-8"?>
2 <xsl:stylesheet version="1.0"
3   xmlns="http://www.indexdata.com/turbomarc"
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/turbomarc">
7
8   <xsl:output indent="yes" method="xml" version="1.0"
9     encoding="UTF-8" />
10   <xsl:param name="medium"/>
11
12   <!-- Extract metadata from MARC21/USMARC from streamlined marcxml format 
13     http://www.loc.gov/marc/bibliographic/ecbdhome.html -->
14   <xsl:template name="record-hook" />
15
16
17   <xsl:template match="/">
18       <xsl:apply-templates />
19   </xsl:template>
20
21   <xsl:template match="tmarc:collection">
22     <collection>
23       <xsl:apply-templates />
24     </collection>
25   </xsl:template>
26
27   <xsl:template match="tmarc:r">
28     <xsl:variable name="title_medium" select="tmarc:d245/tmarc:sh" />
29     <xsl:variable name="journal_title" select="tmarc:d773/tmarc:st" />
30     <xsl:variable name="electronic_location_url" select="tmarc:d856/tmarc:su" />
31     <xsl:variable name="fulltext_a" select="tmarc:d900/tmarc:sa" />
32     <xsl:variable name="fulltext_b" select="tmarc:d900/tmarc:sb" />
33     <!-- Does not always hit the right substring. The field is not always fixed-width? -->
34     <xsl:variable name="control_lang" select="substring(tmarc:c008, 36, 3)" />
35     <xsl:variable name="contains110" select="tmarc:d110" />
36     <xsl:variable name="hasAuthorFields" select="tmarc:d100 or tmarc:d111" />
37     <xsl:variable name="typeofrec" select="substring(tmarc:l, 7, 1)"/>
38     <xsl:variable name="typeofvm" select="substring(tmarc:c008, 34, 1)"/>
39     <xsl:variable name="biblevel" select="substring(tmarc:l, 8, 1)"/>
40     <xsl:variable name="physdes" select="substring(tmarc:c007, 1, 1)"/>
41     <xsl:variable name="form1" select="substring(tmarc:c008, 24, 1)"/>
42     <xsl:variable name="form2" select="substring(tmarc:c008, 30, 1)"/>
43     <xsl:variable name="oclca" select="substring(tmarc:c007, 1, 1)"/>
44     <xsl:variable name="oclcb" select="substring(tmarc:c007, 2, 1)"/>
45     <xsl:variable name="oclcd" select="substring(tmarc:c007, 4, 1)"/>
46     <xsl:variable name="oclce" select="substring(tmarc:c007, 5, 1)"/>
47     <xsl:variable name="typeofserial" select="substring(tmarc:c008, 22, 1)"/>
48
49     <xsl:variable name="electronic">
50       <xsl:choose>
51         <xsl:when test="$form1='s' or $form1='q' or $form1='o' or
52            $form2='s' or $form2='q' or $form2='o'">
53            <xsl:text>yes</xsl:text>
54         </xsl:when>
55         <xsl:otherwise/>
56       </xsl:choose>
57     </xsl:variable>
58
59     <xsl:variable name="vmedium">
60       <xsl:choose>
61         <xsl:when test="string-length($medium)"><xsl:value-of select="$medium" /></xsl:when>
62         <xsl:when test="($typeofrec='a' or $typeofrec='t') and $biblevel='m'">book</xsl:when>
63         <xsl:when test="$typeofrec='j' or $typeofrec='i'">
64           <xsl:text>recording</xsl:text>
65           <xsl:choose>
66             <xsl:when test="$oclcb='d' and $oclcd='f'">-cd</xsl:when>
67             <xsl:when test="$oclcb='s'">-cassette</xsl:when>
68             <xsl:when test="$oclcb='d' and $oclcd='a' or $oclcd='b' or
69               $oclcd='c' or $oclcd='d' or $oclcd='e'">-vinyl</xsl:when>
70           </xsl:choose>
71         </xsl:when>
72         <xsl:when test="$typeofrec='g'">
73           <xsl:choose>
74             <xsl:when test="$typeofvm='m' or $typeofvm='v'">
75               <xsl:text>video</xsl:text>
76               <xsl:choose>
77                 <xsl:when test="$oclca='v' and $oclcb='d' and $oclce='v'">-dvd</xsl:when>
78                 <xsl:when test="$oclca='v' and $oclcb='d' and $oclce='s'">-blu-ray</xsl:when>
79                 <xsl:when test="$oclca='v' and $oclcb='f' and $oclce='b'">-vhs</xsl:when>
80               </xsl:choose>
81             </xsl:when>
82             <xsl:otherwise>audio-visual</xsl:otherwise>
83           </xsl:choose>
84         </xsl:when>
85         <xsl:when test="$typeofrec='a' and $biblevel='s'">
86           <xsl:choose>
87             <xsl:when test="$typeofserial='n'">newspaper</xsl:when>
88             <xsl:otherwise>journal</xsl:otherwise>
89           </xsl:choose>
90         </xsl:when>
91         <xsl:when test="$typeofrec='e' or $typeofrec='f'">map</xsl:when>
92         <xsl:when test="$typeofrec='c' or $typeofrec='d'">music-score</xsl:when>
93         <xsl:when test="$form1='a' or $form1='b' or $form1='c'">microform</xsl:when>
94         <xsl:when test="$typeofrec='t'">thesis</xsl:when>
95         <!-- <xsl:when test="$journal_title">article</xsl:when> -->
96         <xsl:when test="$typeofrec='a' or $typeofrec='i' and
97             ($typeofserial='d' or $typeofserial='w')">web</xsl:when>
98         <xsl:when test="$typeofrec='a' and $biblevel='b'">article</xsl:when>
99         <xsl:when test="$typeofrec='m'">electronic</xsl:when>
100         <xsl:when test="$title_medium">
101           <xsl:value-of select="translate($title_medium, ' []/:', '')" />
102         </xsl:when>
103         <xsl:otherwise>
104           <xsl:text>other</xsl:text>
105         </xsl:otherwise>
106       </xsl:choose>
107     </xsl:variable>
108
109     <xsl:variable name="has_fulltext">
110       <xsl:choose>
111         <xsl:when test="tmarc:d856/tmarc:sq">
112           <xsl:text>yes</xsl:text>
113         </xsl:when>
114         <xsl:when test="tmarc:d856/tmarc:si='TEXT*'">
115           <xsl:text>yes</xsl:text>
116         </xsl:when>
117         <xsl:otherwise>
118           <xsl:text>no</xsl:text>
119         </xsl:otherwise>
120       </xsl:choose>
121     </xsl:variable>
122
123     <xsl:variable name="oclc_number">
124       <xsl:choose>
125         <xsl:when test='contains(tmarc:c001,"ocn") or
126                         contains(tmarc:c001,"ocm") or
127                         contains(tmarc:c001,"OCoLC") '>
128          <xsl:value-of select="tmarc:c001"/>
129         </xsl:when>
130         <xsl:when test='contains(tmarc:d035/tmarc:sa,"ocn") or
131                         contains(tmarc:d035/tmarc:sa,"ocm") or
132                         contains(tmarc:d035/tmarc:sa,"OCoLC") '>
133          <xsl:value-of select="tmarc:d035/tmarc:sa"/>
134         </xsl:when>
135       </xsl:choose>
136     </xsl:variable>
137
138     <xsl:variable name="date_008">
139       <xsl:choose>
140         <xsl:when test="contains('cestpudikmr', substring(tmarc:c008, 7, 1))">
141           <xsl:value-of select="substring(tmarc:c008, 8, 4)" />
142         </xsl:when>
143       </xsl:choose>
144     </xsl:variable>
145
146     <xsl:variable name="date_end_008">
147       <xsl:choose>
148         <xsl:when test="contains('dikmr', substring(tmarc:c008, 7, 1))">
149           <xsl:value-of select="substring(tmarc:c008, 12, 4)" />
150         </xsl:when>
151       </xsl:choose>
152     </xsl:variable>
153
154     <pz:record>
155 <!--
156       <xsl:attribute name="mergekey">
157     <xsl:text>title </xsl:text>
158   <xsl:value-of select="tmarc:d245/tmarc:sa" />
159   <xsl:text> author </xsl:text>
160   <xsl:value-of select="tmarc:d100/tmarc:sa" />
161   <xsl:text> medium </xsl:text>
162   <xsl:value-of select="$medium" />
163     </xsl:attribute>
164   -->
165
166       <xsl:for-each select="tmarc:c001">
167         <pz:metadata type="id">
168           <xsl:value-of select="." />
169         </pz:metadata>
170       </xsl:for-each>
171
172       <pz:metadata type="oclc-number">
173         <xsl:value-of select="$oclc_number" />
174       </pz:metadata>
175
176       <xsl:for-each select="tmarc:d010">
177         <pz:metadata type="lccn">
178           <xsl:value-of select="tmarc:sa" />
179         </pz:metadata>
180       </xsl:for-each>
181
182       <xsl:for-each select="tmarc:d020">
183         <pz:metadata type="isbn">
184           <xsl:value-of select="tmarc:sa" />
185         </pz:metadata>
186       </xsl:for-each>
187
188       <xsl:for-each select="tmarc:d022">
189         <pz:metadata type="issn">
190           <xsl:value-of select="tmarc:sa" />
191         </pz:metadata>
192       </xsl:for-each>
193
194       <xsl:for-each select="tmarc:d027">
195         <pz:metadata type="tech-rep-nr">
196           <xsl:value-of select="tmarc:sa" />
197         </pz:metadata>
198       </xsl:for-each>
199
200       <xsl:for-each select="tmarc:d035"> 
201         <pz:metadata type="system-control-nr">
202           <xsl:choose>
203             <xsl:when test="tmarc:sa">
204               <xsl:value-of select="tmarc:sa"/>
205             </xsl:when>
206             <xsl:otherwise>
207               <xsl:value-of select="tmarc:sb"/>
208             </xsl:otherwise>
209           </xsl:choose>
210         </pz:metadata>
211       </xsl:for-each>
212
213       <xsl:for-each select="tmarc:d100">
214         <pz:metadata type="author">
215           <xsl:value-of select="tmarc:sa" />
216         </pz:metadata>
217         <pz:metadata type="author-title">
218           <xsl:value-of select="tmarc:sc" />
219         </pz:metadata>
220         <pz:metadata type="author-date">
221           <xsl:value-of select="tmarc:sd" />
222         </pz:metadata>
223       </xsl:for-each>
224
225       <xsl:for-each select="tmarc:d110">
226         <pz:metadata type="corporate-name">
227           <xsl:value-of select="tmarc:sa" />
228         </pz:metadata>
229         <pz:metadata type="corporate-location">
230           <xsl:value-of select="tmarc:sc" />
231         </pz:metadata>
232         <pz:metadata type="corporate-date">
233           <xsl:value-of select="tmarc:sd" />
234         </pz:metadata>
235       </xsl:for-each>
236
237       <xsl:for-each select="tmarc:d111">
238         <pz:metadata type="meeting-name">
239           <xsl:value-of select="tmarc:sa" />
240         </pz:metadata>
241         <pz:metadata type="meeting-location">
242           <xsl:value-of select="tmarc:sc" />
243         </pz:metadata>
244         <pz:metadata type="meeting-date">
245           <xsl:value-of select="tmarc:sd" />
246         </pz:metadata>
247       </xsl:for-each>
248
249       <xsl:for-each select="tmarc:d260">
250         <pz:metadata type="date">
251           <xsl:value-of select="translate(tmarc:sc, 'cp[].', '')" />
252         </pz:metadata>
253       </xsl:for-each>
254
255       <xsl:if test="$date_008 and not(tmarc:d260)">
256         <pz:metadata type="date">
257           <xsl:choose>
258             <xsl:when test="$date_end_008">
259               <xsl:value-of select="concat($date_008,'-',$date_end_008)" />
260             </xsl:when>
261             <xsl:otherwise> 
262               <xsl:value-of select="$date_008" />
263             </xsl:otherwise>
264           </xsl:choose>
265         </pz:metadata>
266       </xsl:if>
267
268
269       <xsl:for-each select="tmarc:d130">
270         <pz:metadata type="title-uniform">
271           <xsl:value-of select="tmarc:sa" />
272         </pz:metadata>
273         <pz:metadata type="title-uniform-media">
274           <xsl:value-of select="tmarc:sm" />
275         </pz:metadata>
276         <pz:metadata type="title-uniform-parts">
277           <xsl:value-of select="tmarc:sn" />
278         </pz:metadata>
279         <pz:metadata type="title-uniform-partname">
280           <xsl:value-of select="tmarc:sp" />
281         </pz:metadata>
282         <pz:metadata type="title-uniform-key">
283           <xsl:value-of select="tmarc:sr" />
284         </pz:metadata>
285       </xsl:for-each>
286
287       <xsl:for-each select="tmarc:d245">
288         <pz:metadata type="title">
289           <xsl:value-of select="tmarc:sa" />
290         </pz:metadata>
291         <pz:metadata type="title-remainder">
292           <xsl:value-of select="tmarc:sb" />
293         </pz:metadata>
294         <pz:metadata type="title-responsibility">
295           <xsl:value-of select="tmarc:sc" />
296         </pz:metadata>
297         <pz:metadata type="title-dates">
298           <xsl:value-of select="tmarc:sf" />
299         </pz:metadata>
300         <pz:metadata type="title-medium">
301           <xsl:value-of select="tmarc:sh" />
302         </pz:metadata>
303         <pz:metadata type="title-number-section">
304           <xsl:value-of select="tmarc:sn" />
305         </pz:metadata>
306         <pz:metadata type="title-complete">
307           <xsl:value-of select="tmarc:sa" />
308           <xsl:if test="tmarc:sb" ><xsl:value-of select="concat(' ', tmarc:sb)" /></xsl:if>
309         </pz:metadata>
310       </xsl:for-each>
311
312       <xsl:for-each select="tmarc:d250">
313         <pz:metadata type="edition">
314           <xsl:value-of select="tmarc:sa" />
315         </pz:metadata>
316       </xsl:for-each>
317
318       <xsl:for-each select="tmarc:d260">
319         <pz:metadata type="publication-place">
320           <xsl:value-of select="tmarc:sa" />
321         </pz:metadata>
322         <pz:metadata type="publication-name">
323           <xsl:value-of select="tmarc:sb" />
324         </pz:metadata>
325         <pz:metadata type="publication-date">
326           <xsl:value-of select="tmarc:sc" />
327         </pz:metadata>
328       </xsl:for-each>
329
330       <xsl:for-each select="tmarc:d300">
331         <pz:metadata type="physical-extent">
332           <xsl:value-of select="tmarc:sa" />
333         </pz:metadata>
334         <pz:metadata type="physical-format">
335           <xsl:value-of select="tmarc:sb" />
336         </pz:metadata>
337         <pz:metadata type="physical-dimensions">
338           <xsl:value-of select="tmarc:sc" />
339         </pz:metadata>
340         <pz:metadata type="physical-accomp">
341           <xsl:value-of select="tmarc:se" />
342         </pz:metadata>
343         <pz:metadata type="physical-unittype">
344           <xsl:value-of select="tmarc:sf" />
345         </pz:metadata>
346         <pz:metadata type="physical-unitsize">
347           <xsl:value-of select="tmarc:sg" />
348         </pz:metadata>
349         <pz:metadata type="physical-specified">
350           <xsl:value-of select="tmarc:s3" />
351         </pz:metadata>
352       </xsl:for-each>
353
354       <xsl:for-each select="tmarc:d440">
355         <pz:metadata type="series-title">
356           <xsl:value-of select="tmarc:sa" />
357         </pz:metadata>
358       </xsl:for-each>
359
360       <xsl:for-each select="tmarc:d500">
361         <pz:metadata type="description">
362           <xsl:for-each select="node()">
363             <xsl:value-of select="text()" />
364           </xsl:for-each>
365         </pz:metadata>
366       </xsl:for-each>
367
368       <xsl:for-each select="tmarc:d505">
369         <pz:metadata type="description">
370           <xsl:for-each select="node()">
371             <xsl:value-of select="text()" />
372           </xsl:for-each>
373         </pz:metadata>
374       </xsl:for-each>
375
376       <xsl:for-each select="tmarc:d518">
377         <pz:metadata type="description">
378           <xsl:for-each select="node()">
379             <xsl:value-of select="text()" />
380           </xsl:for-each>
381         </pz:metadata>
382       </xsl:for-each>
383
384       <xsl:for-each select="tmarc:d520">
385         <pz:metadata type="description">
386           <xsl:for-each select="node()">
387             <xsl:value-of select="text()" />
388           </xsl:for-each>
389         </pz:metadata>
390       </xsl:for-each>
391
392       <xsl:for-each select="tmarc:d522">
393         <pz:metadata type="description">
394           <xsl:for-each select="node()">
395             <xsl:value-of select="text()" />
396           </xsl:for-each>
397         </pz:metadata>
398       </xsl:for-each>
399
400       <xsl:for-each select="tmarc:d911">
401         <pz:metadata type="description">
402           <xsl:for-each select="node()">
403             <xsl:value-of select="text()" />
404           </xsl:for-each>
405         </pz:metadata>
406       </xsl:for-each>
407
408         <xsl:for-each select="tmarc:d600">
409                 <pz:metadata type="subject">
410                         <xsl:value-of select="tmarc:sa" />
411                 </pz:metadata>
412                 <pz:metadata type="subject-long">
413                         <xsl:for-each select="node()/text()">
414                                 <xsl:if test="position() > 1">
415                                         <xsl:text>, </xsl:text>
416                                 </xsl:if>
417                                 <xsl:variable name='value'>
418                                         <xsl:value-of select='normalize-space(.)' />
419                                 </xsl:variable>
420                                 <xsl:choose>
421                                         <xsl:when test="substring($value,string-length($value)) = ','">
422                                                 <xsl:value-of select="substring($value,0,string-length($value))" />
423                                         </xsl:when>
424                                         <xsl:otherwise>
425                                                 <xsl:value-of select="$value" />
426                                         </xsl:otherwise>
427                                 </xsl:choose>
428                         </xsl:for-each>
429                 </pz:metadata>
430         </xsl:for-each>
431
432       <xsl:for-each select="tmarc:d610">
433         <pz:metadata type="subject">
434           <xsl:value-of select="tmarc:sa" />
435         </pz:metadata>
436         <pz:metadata type="subject-long">
437           <xsl:for-each select="node()/text()">
438             <xsl:if test="position() > 1">
439               <xsl:text>, </xsl:text>
440             </xsl:if>
441                 <xsl:variable name='value'>
442                     <xsl:value-of select='normalize-space(.)' />
443                 </xsl:variable>
444                 <xsl:choose>
445                     <xsl:when test="substring($value,string-length($value)) = ','">
446                         <xsl:value-of select="substring($value,0,string-length($value))" />
447                     </xsl:when>
448                     <xsl:otherwise>
449                         <xsl:value-of select="$value" />
450                     </xsl:otherwise>
451                 </xsl:choose>
452           </xsl:for-each>
453         </pz:metadata>
454       </xsl:for-each>
455
456       <xsl:for-each select="tmarc:d611">
457         <pz:metadata type="subject">
458           <xsl:value-of select="tmarc:sa" />
459         </pz:metadata>
460         <pz:metadata type="subject-long">
461           <xsl:for-each select="node()/text()">
462             <xsl:if test="position() > 1">
463               <xsl:text>, </xsl:text>
464             </xsl:if>
465                 <xsl:variable name='value'>
466                     <xsl:value-of select='normalize-space(.)' />
467                 </xsl:variable>
468                 <xsl:choose>
469                     <xsl:when test="substring($value,string-length($value)) = ','">
470                         <xsl:value-of select="substring($value,0,string-length($value))" />
471                     </xsl:when>
472                     <xsl:otherwise>
473                         <xsl:value-of select="$value" />
474                     </xsl:otherwise>
475                 </xsl:choose>
476           </xsl:for-each>
477         </pz:metadata>
478       </xsl:for-each>
479
480       <xsl:for-each select="tmarc:d630">
481         <pz:metadata type="subject">
482           <xsl:value-of select="tmarc:sa" />
483         </pz:metadata>
484         <pz:metadata type="subject-long">
485           <xsl:for-each select="node()/text()">
486             <xsl:if test="position() > 1">
487               <xsl:text>, </xsl:text>
488             </xsl:if>
489                 <xsl:variable name='value'>
490                     <xsl:value-of select='normalize-space(.)' />
491                 </xsl:variable>
492                 <xsl:choose>
493                     <xsl:when test="substring($value,string-length($value)) = ','">
494                         <xsl:value-of select="substring($value,0,string-length($value))" />
495                     </xsl:when>
496                     <xsl:otherwise>
497                         <xsl:value-of select="$value" />
498                     </xsl:otherwise>
499                 </xsl:choose>
500           </xsl:for-each>
501         </pz:metadata>
502       </xsl:for-each>
503
504       <xsl:for-each select="tmarc:d648">
505         <pz:metadata type="subject">
506           <xsl:value-of select="tmarc:sa" />
507         </pz:metadata>
508         <pz:metadata type="subject-long">
509           <xsl:for-each select="node()/text()">
510             <xsl:if test="position() > 1">
511               <xsl:text>, </xsl:text>
512             </xsl:if>
513                 <xsl:variable name='value'>
514                     <xsl:value-of select='normalize-space(.)' />
515                 </xsl:variable>
516                 <xsl:choose>
517                     <xsl:when test="substring($value,string-length($value)) = ','">
518                         <xsl:value-of select="substring($value,0,string-length($value))" />
519                     </xsl:when>
520                     <xsl:otherwise>
521                         <xsl:value-of select="$value" />
522                     </xsl:otherwise>
523                 </xsl:choose>
524           </xsl:for-each>
525         </pz:metadata>
526       </xsl:for-each>
527
528       <xsl:for-each select="tmarc:d650">
529         <pz:metadata type="subject">
530           <xsl:value-of select="tmarc:sa" />
531         </pz:metadata>
532         <pz:metadata type="subject-long">
533           <xsl:for-each select="node()/text()">
534             <xsl:if test="position() > 1">
535               <xsl:text>, </xsl:text>
536             </xsl:if>
537                 <xsl:variable name='value'>
538                     <xsl:value-of select='normalize-space(.)' />
539                 </xsl:variable>
540                 <xsl:choose>
541                     <xsl:when test="substring($value,string-length($value)) = ','">
542                         <xsl:value-of select="substring($value,0,string-length($value))" />
543                     </xsl:when>
544                     <xsl:otherwise>
545                         <xsl:value-of select="$value" />
546                     </xsl:otherwise>
547                 </xsl:choose>
548           </xsl:for-each>
549         </pz:metadata>
550       </xsl:for-each>
551
552       <xsl:for-each select="tmarc:d651">
553         <pz:metadata type="subject">
554           <xsl:value-of select="tmarc:sa" />
555         </pz:metadata>
556         <pz:metadata type="subject-long">
557           <xsl:for-each select="node()/text()">
558             <xsl:if test="position() > 1">
559               <xsl:text>, </xsl:text>
560             </xsl:if>
561                 <xsl:variable name='value'>
562                     <xsl:value-of select='normalize-space(.)' />
563                 </xsl:variable>
564                 <xsl:choose>
565                     <xsl:when test="substring($value,string-length($value)) = ','">
566                         <xsl:value-of select="substring($value,0,string-length($value))" />
567                     </xsl:when>
568                     <xsl:otherwise>
569                         <xsl:value-of select="$value" />
570                     </xsl:otherwise>
571                 </xsl:choose>
572           </xsl:for-each>
573         </pz:metadata>
574       </xsl:for-each>
575
576       <xsl:for-each select="tmarc:d653">
577         <pz:metadata type="subject">
578           <xsl:value-of select="tmarc:sa" />
579         </pz:metadata>
580         <pz:metadata type="subject-long">
581           <xsl:for-each select="node()/text()">
582             <xsl:if test="position() > 1">
583               <xsl:text>, </xsl:text>
584             </xsl:if>
585                 <xsl:variable name='value'>
586                     <xsl:value-of select='normalize-space(.)' />
587                 </xsl:variable>
588                 <xsl:choose>
589                     <xsl:when test="substring($value,string-length($value)) = ','">
590                         <xsl:value-of select="substring($value,0,string-length($value))" />
591                     </xsl:when>
592                     <xsl:otherwise>
593                         <xsl:value-of select="$value" />
594                     </xsl:otherwise>
595                 </xsl:choose>
596           </xsl:for-each>
597         </pz:metadata>
598       </xsl:for-each>
599
600       <xsl:for-each select="tmarc:d654">
601         <pz:metadata type="subject">
602           <xsl:value-of select="tmarc:sa" />
603         </pz:metadata>
604         <pz:metadata type="subject-long">
605           <xsl:for-each select="node()/text()">
606             <xsl:if test="position() > 1">
607               <xsl:text>, </xsl:text>
608             </xsl:if>
609                 <xsl:variable name='value'>
610                     <xsl:value-of select='normalize-space(.)' />
611                 </xsl:variable>
612                 <xsl:choose>
613                     <xsl:when test="substring($value,string-length($value)) = ','">
614                         <xsl:value-of select="substring($value,0,string-length($value))" />
615                     </xsl:when>
616                     <xsl:otherwise>
617                         <xsl:value-of select="$value" />
618                     </xsl:otherwise>
619                 </xsl:choose>
620           </xsl:for-each>
621         </pz:metadata>
622       </xsl:for-each>
623
624       <xsl:for-each select="tmarc:d655">
625         <pz:metadata type="subject">
626           <xsl:value-of select="tmarc:sa" />
627         </pz:metadata>
628         <pz:metadata type="subject-long">
629           <xsl:for-each select="node()/text()">
630             <xsl:if test="position() > 1">
631               <xsl:text>, </xsl:text>
632             </xsl:if>
633             <xsl:value-of select="." />
634           </xsl:for-each>
635         </pz:metadata>
636       </xsl:for-each>
637
638       <xsl:for-each select="tmarc:d656">
639         <pz:metadata type="subject">
640           <xsl:value-of select="tmarc:sa" />
641         </pz:metadata>
642         <pz:metadata type="subject-long">
643           <xsl:for-each select="node()/text()">
644             <xsl:if test="position() > 1">
645               <xsl:text>, </xsl:text>
646             </xsl:if>
647                 <xsl:variable name='value'>
648                     <xsl:value-of select='normalize-space(.)' />
649                 </xsl:variable>
650                 <xsl:choose>
651                     <xsl:when test="substring($value,string-length($value)) = ','">
652                         <xsl:value-of select="substring($value,0,string-length($value))" />
653                     </xsl:when>
654                     <xsl:otherwise>
655                         <xsl:value-of select="$value" />
656                     </xsl:otherwise>
657                 </xsl:choose>
658           </xsl:for-each>
659         </pz:metadata>
660       </xsl:for-each>
661
662       <xsl:for-each select="tmarc:d657">
663         <pz:metadata type="subject">
664           <xsl:value-of select="tmarc:sa" />
665         </pz:metadata>
666         <pz:metadata type="subject-long">
667           <xsl:for-each select="node()/text()">
668             <xsl:if test="position() > 1">
669               <xsl:text>, </xsl:text>
670             </xsl:if>
671             <xsl:value-of select="." />
672           </xsl:for-each>
673         </pz:metadata>
674       </xsl:for-each>
675
676       <xsl:for-each select="tmarc:d658">
677         <pz:metadata type="subject">
678           <xsl:value-of select="tmarc:sa" />
679         </pz:metadata>
680         <pz:metadata type="subject-long">
681           <xsl:for-each select="node()/text()">
682             <xsl:if test="position() > 1">
683               <xsl:text>, </xsl:text>
684             </xsl:if>
685                 <xsl:variable name='value'>
686                     <xsl:value-of select='normalize-space(.)' />
687                 </xsl:variable>
688                 <xsl:choose>
689                     <xsl:when test="substring($value,string-length($value)) = ','">
690                         <xsl:value-of select="substring($value,0,string-length($value))" />
691                     </xsl:when>
692                     <xsl:otherwise>
693                         <xsl:value-of select="$value" />
694                     </xsl:otherwise>
695                 </xsl:choose>
696           </xsl:for-each>
697         </pz:metadata>
698       </xsl:for-each>
699
700       <xsl:for-each select="tmarc:d662">
701         <pz:metadata type="subject">
702           <xsl:value-of select="tmarc:sa" />
703         </pz:metadata>
704         <pz:metadata type="subject-long">
705           <xsl:for-each select="node()/text()">
706             <xsl:if test="position() > 1">
707               <xsl:text>, </xsl:text>
708             </xsl:if>
709                 <xsl:variable name='value'>
710                     <xsl:value-of select='normalize-space(.)' />
711                 </xsl:variable>
712                 <xsl:choose>
713                     <xsl:when test="substring($value,string-length($value)) = ','">
714                         <xsl:value-of select="substring($value,0,string-length($value))" />
715                     </xsl:when>
716                     <xsl:otherwise>
717                         <xsl:value-of select="$value" />
718                     </xsl:otherwise>
719                 </xsl:choose>
720           </xsl:for-each>
721         </pz:metadata>
722       </xsl:for-each>
723
724       <xsl:for-each select="tmarc:d69X">
725         <pz:metadata type="subject">
726           <xsl:value-of select="tmarc:sa" />
727         </pz:metadata>
728         <pz:metadata type="subject-long">
729           <xsl:for-each select="node()/text()">
730             <xsl:if test="position() > 1">
731               <xsl:text>, </xsl:text>
732             </xsl:if>
733                 <xsl:variable name='value'>
734                     <xsl:value-of select='normalize-space(.)' />
735                 </xsl:variable>
736                 <xsl:choose>
737                     <xsl:when test="substring($value,string-length($value)) = ','">
738                         <xsl:value-of select="substring($value,0,string-length($value))" />
739                     </xsl:when>
740                     <xsl:otherwise>
741                         <xsl:value-of select="$value" />
742                     </xsl:otherwise>
743                 </xsl:choose>
744           </xsl:for-each>
745         </pz:metadata>
746       </xsl:for-each>
747
748       <!-- or tmarc:d651 or tmarc:d653 or tmarc:d654 or tmarc:d655 or tmarc:d656 
749         or tmarc:d657 or tmarc:d658 or tmarc:d662 or tmarc:d69X"> -->
750
751       <!-- <xsl:for-each select="tmarc:d600" > <pz:metadata type="subject"> 
752         <xsl:value-of select="tmarc:sa"/> </pz:metadata> <pz:metadata type="subject-long"> 
753         <xsl:for-each select="tmarc:sa tmarc:sb tmarc:sc tmarc:sd "> <xsl:if test="position() 
754         > 1"> <xsl:text>, </xsl:text> </xsl:if> <xsl:value-of select="."/> </xsl:for-each> 
755         </pz:metadata> </xsl:for-each> -->
756
757       <xsl:for-each select="tmarc:d856">
758         <pz:metadata type="electronic-url">
759           <xsl:value-of select="tmarc:su" />
760         </pz:metadata>
761         <pz:metadata type="electronic-text">
762          <xsl:choose>
763               <xsl:when test="tmarc:sy">
764                    <xsl:value-of select="tmarc:sy/text()" />
765               </xsl:when>
766               <xsl:when test="tmarc:s3">
767                    <xsl:value-of select="tmarc:s3/text()" />
768               </xsl:when>
769               <xsl:otherwise>Get resource</xsl:otherwise>
770              </xsl:choose>
771         </pz:metadata>
772         <pz:metadata type="electronic-note">
773           <xsl:value-of select="tmarc:sz" />
774         </pz:metadata>
775         <pz:metadata type="electronic-format-instruction">
776           <xsl:value-of select="tmarc:si" />
777         </pz:metadata>
778         <pz:metadata type="electronic-format-type">
779           <xsl:value-of select="tmarc:sq" />
780         </pz:metadata>
781       </xsl:for-each>
782
783       <xsl:for-each select="tmarc:d773">
784         <pz:metadata type="citation">
785           <xsl:for-each select="*">
786             <xsl:value-of select="normalize-space(.)" />
787             <xsl:text> </xsl:text>
788           </xsl:for-each>
789         </pz:metadata>
790         <xsl:if test="tmarc:st">
791           <pz:metadata type="journal-title">
792             <xsl:value-of select="tmarc:st"/>
793           </pz:metadata>
794         </xsl:if>
795         <xsl:if test="tmarc:sg">
796           <xsl:variable name="value">
797             <xsl:for-each select="tmarc:sg">
798               <xsl:value-of select="."/>
799             </xsl:for-each>
800           </xsl:variable>
801           <pz:metadata type="journal-subpart">
802             <xsl:value-of select="$value"/>
803           </pz:metadata>
804           <xsl:variable name="l">
805             <xsl:value-of select="translate($value,
806                                   'ABCDEFGHIJKLMNOPQRSTUVWXYZ.',
807                                   'abcdefghijklmnopqrstuvwxyz ') "/>
808           </xsl:variable>
809           <xsl:variable name="volume">
810             <xsl:choose>
811               <xsl:when test="string-length(substring-after($l,'vol ')) &gt; 0">
812                 <xsl:value-of select="substring-before(normalize-space(substring-after($l,'vol ')),' ')"/>
813               </xsl:when>
814               <xsl:when test="string-length(substring-after($l,'v ')) &gt; 0">
815                 <xsl:value-of select="substring-before(normalize-space(substring-after($l,'v ')),' ')"/>
816               </xsl:when>
817             </xsl:choose>
818           </xsl:variable>
819           <xsl:variable name="issue">
820             <xsl:value-of select="substring-before(translate(normalize-space(substring-after($l,'issue')), ',', ' '),' ')"/>
821           </xsl:variable>
822           <xsl:variable name="pages">
823             <xsl:choose>
824               <xsl:when test="string-length(substring-after($l,' p ')) &gt; 0">
825                 <xsl:value-of select="normalize-space(substring-after($l,' p '))"/>
826               </xsl:when>
827               <xsl:when test="string-length(substring-after($l,',p')) &gt; 0">
828                 <xsl:value-of select="normalize-space(substring-after($l,',p'))"/>
829               </xsl:when>
830               <xsl:when test="string-length(substring-after($l,' p')) &gt; 0">
831                 <xsl:value-of select="normalize-space(substring-after($l,' p'))"/>
832               </xsl:when>
833             </xsl:choose>
834           </xsl:variable>
835
836           <!-- volume -->
837           <xsl:if test="string-length($volume) &gt; 0">
838             <pz:metadata type="volume-number">
839               <xsl:value-of select="$volume"/>
840             </pz:metadata>
841           </xsl:if>
842           <!-- issue -->
843           <xsl:if test="string-length($issue) &gt; 0">
844             <pz:metadata type="issue-number">
845               <xsl:value-of select="$issue"/>
846             </pz:metadata>
847           </xsl:if>
848           <!-- pages -->
849           <xsl:if test="string-length($pages) &gt; 0">
850             <pz:metadata type="pages-number">
851               <xsl:value-of select="$pages"/>
852             </pz:metadata>
853           </xsl:if>
854           
855           <!-- season -->
856         </xsl:if>
857         <xsl:if test="tmarc:sp">
858           <pz:metadata type="journal-title-abbrev">
859             <xsl:value-of select="tmarc:sp"/>
860           </pz:metadata>
861         </xsl:if>
862       </xsl:for-each>
863
864       <xsl:for-each select="tmarc:d852">
865         <xsl:if test="tmarc:sy">
866           <pz:metadata type="publicnote">
867             <xsl:value-of select="tmarc:sy" />
868           </pz:metadata>
869         </xsl:if>
870         <xsl:if test="tmarc:sh">
871           <pz:metadata type="callnumber">
872             <xsl:value-of select="tmarc:sh" />
873           </pz:metadata>
874         </xsl:if>
875       </xsl:for-each>
876
877       <xsl:for-each select="tmarc:d876">
878         <xsl:if test="tmarc:sf">
879           <pz:metadata type="loan-period">
880             <xsl:value-of select="concat(tmarc:s5,':',tmarc:sf)" />
881           </pz:metadata>
882         </xsl:if>
883       </xsl:for-each>
884
885       <pz:metadata type="medium">
886         <xsl:value-of select="$vmedium" />
887         <xsl:if test="string-length($electronic) and $vmedium != 'electronic'">
888           <xsl:text> (electronic)</xsl:text>
889         </xsl:if>
890       </pz:metadata>
891
892       <xsl:for-each select="tmarc:d900/tmarc:sa">
893         <pz:metadata type="fulltext">
894           <xsl:value-of select="." />
895         </pz:metadata>
896       </xsl:for-each>
897
898       <!-- <xsl:if test="$fulltext_a"> <pz:metadata type="fulltext"> <xsl:value-of 
899         select="$fulltext_a"/> </pz:metadata> </xsl:if> -->
900
901       <xsl:for-each select="tmarc:d900/tmarc:sb">
902         <pz:metadata type="fulltext">
903           <xsl:value-of select="." />
904         </pz:metadata>
905       </xsl:for-each>
906
907       <xsl:for-each select="tmarc:d900/tmarc:se">
908         <pz:metadata type="fulltext">
909           <xsl:value-of select="." />
910         </pz:metadata>
911       </xsl:for-each>
912
913       <xsl:for-each select="tmarc:d900/tmarc:sf">
914         <pz:metadata type="fulltext">
915           <xsl:value-of select="." />
916         </pz:metadata>
917       </xsl:for-each>
918
919       <xsl:for-each select="tmarc:d900/tmarc:si">
920         <pz:metadata type="fulltext">
921           <xsl:value-of select="." />
922         </pz:metadata>
923       </xsl:for-each>
924
925       <xsl:for-each select="tmarc:d900/tmarc:sk">
926         <pz:metadata type="fulltext">
927           <xsl:value-of select="." />
928         </pz:metadata>
929       </xsl:for-each>
930
931       <xsl:for-each select="tmarc:d900/tmarc:sq">
932         <pz:metadata type="fulltext">
933           <xsl:value-of select="." />
934         </pz:metadata>
935       </xsl:for-each>
936
937       <xsl:for-each select="tmarc:d900/tmarc:ss">
938         <pz:metadata type="fulltext">
939           <xsl:value-of select="." />
940         </pz:metadata>
941       </xsl:for-each>
942
943       <xsl:for-each select="tmarc:d900/tmarc:su">
944         <pz:metadata type="fulltext">
945           <xsl:value-of select="." />
946         </pz:metadata>
947       </xsl:for-each>
948
949       <xsl:for-each select="tmarc:d900/tmarc:sy">
950         <pz:metadata type="fulltext">
951           <xsl:value-of select="." />
952         </pz:metadata>
953       </xsl:for-each>
954
955
956       <!-- <xsl:if test="$fulltext_b"> <pz:metadata type="fulltext"> <xsl:value-of 
957         select="$fulltext_b"/> </pz:metadata> </xsl:if> -->
958
959       <pz:metadata type="has-fulltext">
960         <xsl:value-of select="$has_fulltext"/>
961       </pz:metadata>
962
963       <xsl:for-each select="tmarc:d907 | tmarc:d901">
964         <pz:metadata type="iii-id">
965           <xsl:value-of select="tmarc:sa" />
966         </pz:metadata>
967       </xsl:for-each>
968
969       <xsl:for-each select="tmarc:d926">
970         <pz:metadata type="locallocation">
971           <xsl:choose><xsl:when test="tmarc:sa">
972             <xsl:value-of select="tmarc:sa"/>
973           </xsl:when><xsl:otherwise>
974             <xsl:text>PAZPAR2_NULL_VALUE</xsl:text>
975           </xsl:otherwise></xsl:choose>
976         </pz:metadata>
977         <pz:metadata type="callnumber">
978           <xsl:choose><xsl:when test="tmarc:sc">
979             <xsl:value-of select="tmarc:sc"/>
980           </xsl:when><xsl:otherwise>
981             <xsl:text>PAZPAR2_NULL_VALUE</xsl:text>
982           </xsl:otherwise></xsl:choose>
983         </pz:metadata>
984         <pz:metadata type="available">
985           <xsl:choose><xsl:when test="tmarc:se">
986             <xsl:value-of select="tmarc:se"/>
987           </xsl:when><xsl:otherwise>
988             <xsl:text>PAZPAR2_NULL_VALUE</xsl:text>
989           </xsl:otherwise></xsl:choose>
990         </pz:metadata>
991       </xsl:for-each>
992
993       <!-- OhioLINK holdings -->
994       <xsl:for-each select="tmarc:d945">
995         <pz:metadata type="locallocation">
996           <xsl:choose>
997             <xsl:when test="tmarc:sa">
998               <xsl:value-of select="tmarc:sa"/>
999             </xsl:when>
1000             <xsl:otherwise>PAZPAR2_NULL_VALUE</xsl:otherwise>
1001           </xsl:choose>
1002         </pz:metadata>
1003         <pz:metadata type="callnumber">
1004           <xsl:choose>
1005             <xsl:when test="tmarc:sb">
1006               <xsl:value-of select="tmarc:sb"/>
1007             </xsl:when>
1008             <xsl:otherwise>PAZPAR2_NULL_VALUE</xsl:otherwise>
1009           </xsl:choose>
1010         </pz:metadata>
1011         <pz:metadata type="publicnote">
1012           <xsl:choose>
1013             <xsl:when test="tmarc:sc">
1014               <xsl:value-of select="tmarc:sc"/>
1015             </xsl:when>
1016             <xsl:otherwise>PAZPAR2_NULL_VALUE</xsl:otherwise>
1017           </xsl:choose>
1018         </pz:metadata>
1019         <pz:metadata type="available">
1020           <xsl:choose>
1021             <xsl:when test="tmarc:ss = 'N'">Available</xsl:when>
1022             <xsl:when test="tmarc:ss != 'N'">
1023               <xsl:choose>
1024                 <xsl:when test="tmarc:sd">
1025                   <xsl:value-of select="tmarc:sd"/>
1026                 </xsl:when>
1027                 <xsl:otherwise>PAZPAR2_NULL_VALUE</xsl:otherwise>
1028               </xsl:choose>
1029             </xsl:when>
1030             <xsl:otherwise>PAZPAR2_NULL_VALUE</xsl:otherwise>
1031           </xsl:choose>
1032         </pz:metadata>      
1033       </xsl:for-each>
1034
1035       <xsl:for-each select="tmarc:d948">
1036         <pz:metadata type="holding">
1037           <xsl:for-each select="tmarc:s">
1038             <xsl:if test="position() > 1">
1039               <xsl:text> </xsl:text>
1040             </xsl:if>
1041             <xsl:value-of select="." />
1042           </xsl:for-each>
1043         </pz:metadata>
1044       </xsl:for-each>
1045
1046       <xsl:for-each select="tmarc:d991">
1047         <pz:metadata type="holding">
1048           <xsl:for-each select="tmarc:s">
1049             <xsl:if test="position() > 1">
1050               <xsl:text> </xsl:text>
1051             </xsl:if>
1052             <xsl:value-of select="." />
1053           </xsl:for-each>
1054         </pz:metadata>
1055       </xsl:for-each>
1056
1057       <xsl:for-each select="tmarc:d999">
1058         <pz:metadata type="localid">
1059           <xsl:choose>
1060             <xsl:when test="tmarc:sa">
1061               <xsl:value-of select="tmarc:sa"/>
1062             </xsl:when>
1063             <xsl:when test="tmarc:sc">
1064               <xsl:value-of select="tmarc:sc"/>
1065             </xsl:when> 
1066             <xsl:otherwise>
1067               <xsl:value-of select="tmarc:sd"/>
1068             </xsl:otherwise>
1069           </xsl:choose>
1070         </pz:metadata>
1071       </xsl:for-each>
1072
1073
1074       <!-- passthrough id data -->
1075       <xsl:for-each select="pz:metadata">
1076         <xsl:copy-of select="." />
1077       </xsl:for-each>
1078
1079       <!-- other stylesheets importing this might want to define this -->
1080         <xsl:call-template name="record-hook" />
1081
1082     </pz:record>
1083   </xsl:template>
1084
1085   <xsl:template match="text()" />
1086
1087 </xsl:stylesheet>