Move declaration to avoid warning when compiling wo Libxml2
[yaz-moved-to-github.git] / etc / marc21_to_endnote.xsl
1 <?xml version="1.0" encoding="UTF-8"?>
2 <xsl:stylesheet version="1.0"
3   xmlns:marc="http://www.loc.gov/MARC21/slim"
4   xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
5   >
6   <xsl:output method="text"/>
7   <xsl:strip-space elements="*"/>
8   
9   <xsl:template name="printfield">
10      <xsl:param name="name"/>
11      <xsl:param name="value"/>
12      <xsl:if test="string-length($value) &gt; 0">
13        <xsl:text>%</xsl:text><xsl:value-of select="$name"/>
14        <xsl:text> </xsl:text><xsl:value-of select="$value"/>
15 <xsl:text>
16 </xsl:text>
17      </xsl:if>
18   </xsl:template>
19
20   <xsl:template match="marc:record">
21     <xsl:variable name="title_medium" select="marc:datafield[@tag='245']/marc:subfield[@code='h']"/>
22     <xsl:variable name="journal_title" select="marc:datafield[@tag='773']/marc:subfield[@code='t']"/>
23     <xsl:variable name="electronic_location_url" select="marc:datafield[@tag='85
24 6']/marc:subfield[@code='u']"/>
25     <xsl:variable name="fulltext_a" select="marc:datafield[@tag='900']/marc:subfield[@code='a']"/>
26     <xsl:variable name="fulltext_b" select="marc:datafield[@tag='900']/marc:subfield[@code='b']"/>
27     <xsl:variable name="medium">
28       <xsl:choose>
29         <xsl:when test="$title_medium">
30           <xsl:value-of select="translate($title_medium, ':[]/', '')"/>
31         </xsl:when>
32         <xsl:when test="$fulltext_a">
33           <xsl:text>Electronic Resource</xsl:text>
34         </xsl:when>
35         <xsl:when test="$fulltext_b">
36           <xsl:text>Electronic Resource</xsl:text>
37         </xsl:when>
38         <xsl:when test="$journal_title">
39           <xsl:text>article</xsl:text>
40         </xsl:when>
41         <xsl:otherwise>
42           <xsl:text>Book</xsl:text>
43         </xsl:otherwise>
44       </xsl:choose>
45     </xsl:variable>
46
47     <!-- Medium -->
48     <xsl:call-template name="printfield">
49       <xsl:with-param name="name">0</xsl:with-param>
50       <xsl:with-param name="value"><xsl:value-of select="$medium"/>
51       </xsl:with-param>
52     </xsl:call-template>
53
54     <!-- Author -->
55     <xsl:choose>
56       <xsl:when test="marc:datafield[@tag='100' and @ind1='1']">
57         <xsl:for-each select="marc:datafield[@tag='100']">
58           <xsl:call-template name="printfield">
59             <xsl:with-param name="name">A</xsl:with-param>
60             <xsl:with-param name="value">
61               <xsl:value-of select="marc:subfield[@code='a']"/>
62             </xsl:with-param>
63           </xsl:call-template>
64         </xsl:for-each>
65       </xsl:when>
66       <xsl:when test="marc:datafield[@tag='700' and @ind1='1']">
67         <xsl:for-each select="marc:datafield[@tag='700']">
68           <xsl:call-template name="printfield">
69             <xsl:with-param name="name">A</xsl:with-param>
70             <xsl:with-param name="value">
71               <xsl:value-of select="marc:subfield[@code='a']"/>
72             </xsl:with-param>
73           </xsl:call-template>
74         </xsl:for-each>
75       </xsl:when>
76       <xsl:otherwise>
77       </xsl:otherwise>
78     </xsl:choose>
79       
80     <xsl:for-each select="marc:datafield[@tag='245']">
81       <!-- Title -->
82       <xsl:call-template name="printfield">
83         <xsl:with-param name="name">T</xsl:with-param>
84         <xsl:with-param name="value">
85           <xsl:value-of select="marc:subfield[@code='a']"/>
86         </xsl:with-param>
87       </xsl:call-template>
88
89       <!-- Secondary title -->
90       <xsl:call-template name="printfield">
91         <xsl:with-param name="name">B</xsl:with-param>
92         <xsl:with-param name="value">
93           <xsl:value-of select="marc:subfield[@code='b']"/>
94         </xsl:with-param>
95       </xsl:call-template>
96     </xsl:for-each>
97     
98     <xsl:for-each select="marc:datafield[@tag='260']">
99       <!-- Place Published -->
100       <xsl:call-template name="printfield">
101         <xsl:with-param name="name">C</xsl:with-param>
102         <xsl:with-param name="value">
103           <xsl:value-of select="marc:subfield[@code='a']"/>
104         </xsl:with-param>
105       </xsl:call-template>
106       <!-- Publisher -->
107       <xsl:call-template name="printfield">
108         <xsl:with-param name="name">I</xsl:with-param>
109         <xsl:with-param name="value">
110           <xsl:value-of select="marc:subfield[@code='b']"/>
111         </xsl:with-param>
112       </xsl:call-template>
113       <!-- Year -->
114       <xsl:call-template name="printfield">
115         <xsl:with-param name="name">D</xsl:with-param>
116         <xsl:with-param name="value">
117           <xsl:value-of select="marc:subfield[@code='c']"/>
118         </xsl:with-param>
119       </xsl:call-template>
120     </xsl:for-each>
121   
122     <!-- Keywords -->
123     <xsl:for-each select="marc:datafield[@tag='650']">
124       <xsl:call-template name="printfield">
125         <xsl:with-param name="name">K</xsl:with-param>
126         <xsl:with-param name="value">
127           <xsl:value-of select="marc:subfield[@code='a']"/>
128         </xsl:with-param>
129       </xsl:call-template>
130     </xsl:for-each>
131   
132     <!-- Callnumber -->
133     <xsl:for-each select="marc:datafield[@tag='852']">
134       <xsl:call-template name="printfield">
135         <xsl:with-param name="name">L</xsl:with-param>
136         <xsl:with-param name="value">
137           <xsl:value-of select="marc:subfield[@code='h']"/>
138         </xsl:with-param>
139       </xsl:call-template>
140     </xsl:for-each>
141   
142     <!-- Pages -->
143     <xsl:for-each select="marc:datafield[@tag='300']">
144       <xsl:call-template name="printfield">
145         <xsl:with-param name="name">P</xsl:with-param>
146         <xsl:with-param name="value">
147           <xsl:value-of select="marc:subfield[@code='a']"/>
148         </xsl:with-param>
149       </xsl:call-template>
150     </xsl:for-each>
151   
152     <!-- URL -->
153     <xsl:for-each select="marc:datafield[@tag='856']">
154       <xsl:call-template name="printfield">
155         <xsl:with-param name="name">U</xsl:with-param>
156         <xsl:with-param name="value">
157           <xsl:value-of select="marc:subfield[@code='u']"/>
158         </xsl:with-param>
159       </xsl:call-template>
160     </xsl:for-each>
161   
162     <!-- Volume -->
163     <xsl:for-each select="marc:datafield[@tag='245']">
164       <xsl:call-template name="printfield">
165         <xsl:with-param name="name">V</xsl:with-param>
166         <xsl:with-param name="value">
167           <xsl:value-of select="marc:subfield[@code='n']"/>
168         </xsl:with-param>
169       </xsl:call-template>
170     </xsl:for-each>
171   
172     <!-- Abstract -->
173     <xsl:for-each select="marc:datafield[@tag='520']">
174       <xsl:call-template name="printfield">
175         <xsl:with-param name="name">X</xsl:with-param>
176         <xsl:with-param name="value">
177           <xsl:value-of select="marc:subfield[@code='a']"/>
178         </xsl:with-param>
179       </xsl:call-template>
180     </xsl:for-each>
181   
182     <!-- ISBN -->
183     <xsl:for-each select="marc:datafield[@tag='020']">
184       <xsl:call-template name="printfield">
185         <xsl:with-param name="name">@</xsl:with-param>
186         <xsl:with-param name="value">
187           <xsl:value-of select="marc:subfield[@code='a']"/>
188         </xsl:with-param>
189       </xsl:call-template>
190     </xsl:for-each>
191   
192     <!-- ISSN -->
193     <xsl:for-each select="marc:datafield[@tag='022']">
194       <xsl:call-template name="printfield">
195         <xsl:with-param name="name">@</xsl:with-param>
196         <xsl:with-param name="value">
197           <xsl:value-of select="marc:subfield[@code='a']"/>
198         </xsl:with-param>
199       </xsl:call-template>
200     </xsl:for-each>
201   </xsl:template>
202   <xsl:template match="text()"/>
203 </xsl:stylesheet>