Merge branch 'master' of git.evergreen-ils.org:Evergreen into template-toolkit-opac
[working/Evergreen.git] / Open-ILS / xsl / MARC21slim2RIS.xsl
1 <?xml version="1.0" encoding="UTF-8"?>
2 <xsl:stylesheet version="1.0" xmlns:marc="http://www.loc.gov/MARC21/slim" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" exclude-result-prefixes="marc">
3     <xsl:include href="MARC21slimUtils.xsl"/>
4     <xsl:output method="text"/>
5
6     <xsl:template match="marc:record">
7         <xsl:variable name="leader" select="marc:leader" />
8         <xsl:variable name="leader6" select="substring($leader,7,1)" />
9         <xsl:variable name="leader7" select="substring($leader,8,1)" />
10
11         <xsl:text>&#10;TY  - </xsl:text>
12
13         <xsl:variable name="field008" select="marc:controlfield[@tag=008]"/>
14
15         <xsl:choose>
16             <xsl:when test="$leader6='a' or $leader6='t'">
17                 <xsl:choose>
18                     <xsl:when test="$leader6='a' and $leader7='b' or $leader7='i' or $leader7='s'">
19                         <!-- Continuing Resource -->
20                         <xsl:variable name="field008-21" select="substring($field008,22,1)"/>
21                         <xsl:choose>
22                             <xsl:when test="$field008-21='p'">JOUR</xsl:when>
23                             <xsl:when test="$field008-21='n'">NEWS</xsl:when>
24                             <xsl:when test="$field008-21='m'">SER</xsl:when>
25
26                             <!-- Default to Journal -->
27                             <xsl:otherwise>JOUR</xsl:otherwise>
28                         </xsl:choose>
29                     </xsl:when>
30                     <xsl:otherwise>
31                         <!-- If not a CR, then a book (or book-type) item -->
32                         <xsl:variable name="field008-24-27" select="substring($field008,25,4)"/>
33                         <xsl:variable name="field008-29" select="substring($field008,30,1)"/>
34
35                         <xsl:choose>
36                             <xsl:when test="$leader6='a' and $leader7='m'">BOOK</xsl:when> 
37                             <xsl:when test="$leader6='a' and $leader7='a'">CHAP</xsl:when> 
38                             <xsl:when test="$field008-29='1'">CONF</xsl:when> 
39                             <xsl:when test="$field008-24-27='m'">THES</xsl:when> 
40                             <xsl:when test="$field008-24-27='a'">ABST</xsl:when> 
41                             <xsl:when test="$field008-24-27='j'">PAT</xsl:when> 
42                             <xsl:when test="$field008-24-27='v'">CASE</xsl:when> 
43                             <xsl:when test="$field008-24-27='l'">STAT</xsl:when> 
44                             <xsl:when test="$field008-24-27='t'">RPRT</xsl:when> 
45                             <xsl:when test="$field008-24-27='c'">CTLG</xsl:when> 
46
47                             <!-- Default to BOOK -->
48                             <xsl:otherwise>BOOK</xsl:otherwise>
49                         </xsl:choose>
50                     </xsl:otherwise>
51                 </xsl:choose>
52             </xsl:when>
53
54             <xsl:when test="$leader6='e' or $leader6='f'">MAP</xsl:when>
55             <xsl:when test="$leader6='i' or $leader6='j'">SOUND</xsl:when>
56             <xsl:when test="$leader6='c' or $leader6='d'">MUSIC</xsl:when>
57
58             <xsl:when test="$leader6='g'">
59                 <xsl:variable name="field008-33" select="substring($field008,34,1)"/>
60                 <xsl:choose>
61                     <xsl:when test="$field008-33='m' or $field008-33='f'">MPCT</xsl:when>
62                     <xsl:when test="$field008-33='v'">VIDEO</xsl:when>
63                     <xsl:when test="$field008-33='s'">SLIDE</xsl:when>
64
65                     <!-- Default to Motion Picture -->
66                     <xsl:otherwise>MPCT</xsl:otherwise>
67                 </xsl:choose>
68             </xsl:when>
69             <xsl:when test="$leader6='k' or $leader6='r'">
70                 <xsl:variable name="field008-33" select="substring($field008,34,1)"/>
71                 <xsl:choose>
72                     <xsl:when test="$field008-33='a' or $field008-33='c' or $field008-33='i' or $field008-33='k'">ART</xsl:when>
73
74                     <!-- Default to Generic -->
75                     <xsl:otherwise>GEN</xsl:otherwise>
76                 </xsl:choose>
77             </xsl:when>
78
79             <xsl:when test="$leader6='m'">
80                 <xsl:variable name="field008-26" select="substring($field008,27,1)"/>
81                 <xsl:choose>
82                     <xsl:when test="$field008-26='b'">COMP</xsl:when>
83                     <xsl:when test="$field008-26='e'">ELEC</xsl:when>
84                     <xsl:when test="$field008-26='a' or $field008-26='c' or $field008-26='d'">DATA</xsl:when>
85
86                     <!-- Default to Computer File -->
87                     <xsl:otherwise>COMP</xsl:otherwise>
88                 </xsl:choose>
89             </xsl:when>
90
91             <xsl:otherwise>GEN</xsl:otherwise>
92
93         </xsl:choose> <!-- End TY -->
94
95
96         <xsl:for-each select="marc:datafield[@tag=100]|marc:datafield[@tag=110]|marc:datafield[@tag=111]">
97             <xsl:text>&#10;A1  - </xsl:text>
98             <xsl:for-each select="marc:subfield[@code='a']">
99                 <xsl:call-template name="chopPunctuation">
100                     <xsl:with-param name="punctuation">
101                         <xsl:text>,; </xsl:text>
102                     </xsl:with-param>
103                     <xsl:with-param name="chopString">
104                         <xsl:value-of select="."/>
105                     </xsl:with-param>
106                 </xsl:call-template>
107             </xsl:for-each>
108             <xsl:if test="@tag = '110'">
109                 <xsl:for-each select="marc:subfield[@code='b']">
110                     <xsl:value-of select="."/>
111                 </xsl:for-each>
112             </xsl:if>
113             <xsl:if test="@tag = '111'">
114                 <xsl:for-each select="marc:subfield[@code='q']">
115                     <xsl:value-of select="."/>
116                 </xsl:for-each>
117                 <xsl:for-each select="marc:subfield[@code='e']">
118                     <xsl:value-of select="."/>
119                 </xsl:for-each>
120             </xsl:if>
121         </xsl:for-each>
122         
123         <xsl:for-each select="marc:datafield[@tag=245]">
124             <xsl:text>&#10;T1  - </xsl:text>
125             <xsl:for-each select="marc:subfield[@code='a']">
126                 <xsl:call-template name="chopPunctuation">
127                     <xsl:with-param name="punctuation">
128                         <xsl:text>:/ </xsl:text>
129                     </xsl:with-param>
130                     <xsl:with-param name="chopString">
131                         <xsl:value-of select="."/>
132                     </xsl:with-param>
133                 </xsl:call-template>
134             </xsl:for-each>
135             <xsl:for-each select="marc:subfield[@code='b']">
136                 <xsl:text>: </xsl:text>
137                 <xsl:call-template name="chopPunctuation">
138                     <xsl:with-param name="punctuation">
139                         <xsl:text>/ </xsl:text>
140                     </xsl:with-param>
141                     <xsl:with-param name="chopString">
142                         <xsl:value-of select="."/>
143                     </xsl:with-param>
144                 </xsl:call-template>
145             </xsl:for-each>
146         </xsl:for-each>
147
148         <xsl:variable name="respStmt" select="marc:datafield[@tag=245]/marc:subfield[@code='c']"/>
149
150         <xsl:for-each select="marc:datafield[@tag=700]">
151             <xsl:for-each select="marc:subfield[@code='a']">
152                 <xsl:variable name="addedAuthor" select="."/>
153                 <xsl:choose>
154                     <xsl:when test="contains($respStmt, substring-before($addedAuthor, ', '))">
155                         <xsl:text>&#10;A1  - </xsl:text>
156                         <xsl:call-template name="chopPunctuation">
157                             <xsl:with-param name="punctuation">
158                                 <xsl:text>,; </xsl:text>
159                             </xsl:with-param>
160                             <xsl:with-param name="chopString">
161                                 <xsl:value-of select="$addedAuthor"/>
162                             </xsl:with-param>
163                         </xsl:call-template>
164                     </xsl:when>
165                     <xsl:otherwise>
166                         <xsl:text>&#10;A2  - </xsl:text>
167                         <xsl:call-template name="chopPunctuation">
168                             <xsl:with-param name="punctuation">
169                                 <xsl:text>,; </xsl:text>
170                             </xsl:with-param>
171                             <xsl:with-param name="chopString">
172                                 <xsl:value-of select="$addedAuthor"/>
173                             </xsl:with-param>
174                         </xsl:call-template>
175                     </xsl:otherwise>
176                 </xsl:choose>
177             </xsl:for-each>
178         </xsl:for-each>
179
180         <xsl:for-each select="marc:datafield[@tag=710]">
181             <xsl:text>&#10;A2  - </xsl:text>
182             <xsl:for-each select="marc:subfield[@code='a']|marc:subfield[@code='b']">
183                 <xsl:value-of select="."/>
184             </xsl:for-each>
185         </xsl:for-each>
186
187         <xsl:for-each select="marc:datafield[@tag=490]|marc:datafield[@tag=711]">
188             <xsl:for-each select="marc:subfield[@code='a']">
189                 <xsl:text>&#10;T3  - </xsl:text>
190                 <xsl:value-of select="."/>
191             </xsl:for-each>
192             <xsl:if test="@tag = '711'">
193                 <xsl:for-each select="marc:subfield[@code='q']">
194                     <xsl:value-of select="."/>
195                 </xsl:for-each>
196                 <xsl:for-each select="marc:subfield[@code='e']">
197                     <xsl:value-of select="."/>
198                 </xsl:for-each>
199             </xsl:if>
200         </xsl:for-each>
201
202         <xsl:for-each select="marc:datafield[@tag=210]">
203             <xsl:text>&#10;JO  - </xsl:text>
204             <xsl:for-each select="marc:subfield[@code='a']">
205                 <xsl:value-of select="."/>
206             </xsl:for-each>
207         </xsl:for-each>
208
209         <xsl:for-each select="marc:datafield[@tag=222]">
210             <xsl:text>&#10;JF  - </xsl:text>
211             <xsl:for-each select="marc:subfield[@code='a']">
212                 <xsl:value-of select="."/>
213             </xsl:for-each>
214         </xsl:for-each>
215
216         <xsl:for-each select="marc:datafield[@tag=260]">
217             <xsl:for-each select="marc:subfield[@code='a']">
218                 <xsl:text>&#10;CY  - </xsl:text>
219                 <xsl:call-template name="chopPunctuation">
220                     <xsl:with-param name="punctuation">
221                         <xsl:text> :</xsl:text>
222                     </xsl:with-param>
223                     <xsl:with-param name="chopString">
224                         <xsl:value-of select="."/>
225                     </xsl:with-param>
226                 </xsl:call-template>
227             </xsl:for-each>
228             <xsl:for-each select="marc:subfield[@code='b']">
229                 <xsl:text>&#10;PB  - </xsl:text>
230                 <xsl:call-template name="chopPunctuation">
231                     <xsl:with-param name="punctuation">
232                         <xsl:text> ,</xsl:text>
233                     </xsl:with-param>
234                     <xsl:with-param name="chopString">
235                         <xsl:value-of select="."/>
236                     </xsl:with-param>
237                 </xsl:call-template>
238             </xsl:for-each>
239             <xsl:for-each select="marc:subfield[@code='c']">
240                 <xsl:text>&#10;PY  - </xsl:text>
241                 <xsl:call-template name="chopPunctuation">
242                     <xsl:with-param name="punctuation">
243                         <xsl:text> .</xsl:text>
244                     </xsl:with-param>
245                     <xsl:with-param name="chopString">
246                         <xsl:value-of select="."/>
247                     </xsl:with-param>
248                 </xsl:call-template>
249                 <xsl:text>///</xsl:text>
250             </xsl:for-each>
251         </xsl:for-each>
252
253         <xsl:for-each select="marc:datafield[@tag=520]">
254             <xsl:for-each select="marc:subfield[@code='a']">
255                 <xsl:text>&#10;N2  - </xsl:text>
256                 <xsl:value-of select="."/>
257             </xsl:for-each>
258         </xsl:for-each>
259
260         <xsl:for-each select="marc:datafield[@tag=650]|marc:datafield[@tag=651]">
261             <xsl:for-each select="marc:subfield">
262                 <xsl:text>&#10;KW  - </xsl:text>
263                 <xsl:value-of select="."/>
264             </xsl:for-each>
265         </xsl:for-each>
266
267         <xsl:for-each select="marc:datafield[@tag=856]">
268             <xsl:for-each select="marc:subfield[@code='u']">
269                 <xsl:text>&#10;UR  - </xsl:text>
270                 <xsl:value-of select="."/>
271             </xsl:for-each>
272         </xsl:for-each>
273
274         <xsl:for-each select="marc:datafield[@tag=020]|marc:datafield[@tag=022]">
275             <xsl:text>&#10;SN  - </xsl:text>
276             <xsl:for-each select="marc:subfield[@code='a']">
277                 <xsl:value-of select="."/>
278             </xsl:for-each>
279         </xsl:for-each>
280
281         <xsl:text>&#10;ER  -&#10;</xsl:text>
282         </xsl:template>
283 </xsl:stylesheet>
284