Bug 20364: Show languages from MARC21 field 041 in intranet
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / xslt / MARC21slimUtils.xsl
1 <?xml version='1.0'?>
2 <!DOCTYPE stylesheet [<!ENTITY nbsp "&#160;" >]>
3 <xsl:stylesheet version="1.0"
4   xmlns:marc="http://www.loc.gov/MARC21/slim"
5   xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
6   xmlns:str="http://exslt.org/strings"
7   exclude-result-prefixes="marc">
8   <xsl:include href="MARC21Languages.xsl"/>
9         <xsl:template name="datafield">
10                 <xsl:param name="tag"/>
11                 <xsl:param name="ind1"><xsl:text> </xsl:text></xsl:param>
12                 <xsl:param name="ind2"><xsl:text> </xsl:text></xsl:param>
13                 <xsl:param name="subfields"/>
14                 <xsl:element name="datafield">
15                         <xsl:attribute name="tag">
16                                 <xsl:value-of select="$tag"/>
17                         </xsl:attribute>
18                         <xsl:attribute name="ind1">
19                                 <xsl:value-of select="$ind1"/>
20                         </xsl:attribute>
21                         <xsl:attribute name="ind2">
22                                 <xsl:value-of select="$ind2"/>
23                         </xsl:attribute>
24                         <xsl:copy-of select="$subfields"/>
25                 </xsl:element>
26         </xsl:template>
27
28         <xsl:template name="subfieldSelect">
29                 <xsl:param name="codes"/>
30                 <xsl:param name="delimeter"><xsl:text> </xsl:text></xsl:param>
31                 <xsl:param name="subdivCodes"/>
32                 <xsl:param name="subdivDelimiter"/>
33         <xsl:param name="prefix"/>
34         <xsl:param name="suffix"/>
35         <xsl:param name="urlencode"/>
36                 <xsl:variable name="str">
37                         <xsl:for-each select="marc:subfield">
38                                 <xsl:if test="contains($codes, @code)">
39                     <xsl:if test="contains($subdivCodes, @code)">
40                         <xsl:value-of select="$subdivDelimiter"/>
41                     </xsl:if>
42                                         <xsl:value-of select="$prefix"/><xsl:value-of select="text()"/><xsl:value-of select="$suffix"/><xsl:value-of select="$delimeter"/>
43                                 </xsl:if>
44                         </xsl:for-each>
45                 </xsl:variable>
46         <xsl:choose>
47             <xsl:when test="$urlencode=1">
48                 <xsl:value-of select="str:encode-uri(substring($str,1,string-length($str)-string-length($delimeter)), true())"/>
49             </xsl:when>
50             <xsl:otherwise>
51                 <xsl:value-of select="substring($str,1,string-length($str)-string-length($delimeter))"/>
52             </xsl:otherwise>
53         </xsl:choose>
54         </xsl:template>
55
56     <xsl:template name="subfieldSelectSpan">
57         <xsl:param name="codes"/>
58         <xsl:param name="delimeter"><xsl:text> </xsl:text></xsl:param>
59         <xsl:param name="subdivCodes"/>
60         <xsl:param name="subdivDelimiter"/>
61         <xsl:param name="prefix"/>
62         <xsl:param name="suffix"/>
63             <xsl:for-each select="marc:subfield">
64                 <xsl:if test="contains($codes, @code)">
65                     <span>
66                         <xsl:attribute name="class"><xsl:value-of select="@code"/></xsl:attribute>
67                         <xsl:if test="contains($subdivCodes, @code)">
68                             <xsl:value-of select="$subdivDelimiter"/>
69                         </xsl:if>
70                         <xsl:value-of select="$prefix"/><xsl:value-of select="text()"/><xsl:value-of select="$suffix"/><xsl:if test="position()!=last()"><xsl:value-of select="$delimeter"/></xsl:if>
71                     </span>
72                 </xsl:if>
73             </xsl:for-each>
74     </xsl:template>
75
76         <xsl:template name="buildSpaces">
77                 <xsl:param name="spaces"/>
78                 <xsl:param name="char"><xsl:text> </xsl:text></xsl:param>
79                 <xsl:if test="$spaces>0">
80                         <xsl:value-of select="$char"/>
81                         <xsl:call-template name="buildSpaces">
82                                 <xsl:with-param name="spaces" select="$spaces - 1"/>
83                                 <xsl:with-param name="char" select="$char"/>
84                         </xsl:call-template>
85                 </xsl:if>
86         </xsl:template>
87
88     <xsl:template name="buildBiblioDefaultViewURL">
89         <xsl:param name="IntranetBiblioDefaultView"/>
90         <xsl:choose>
91             <xsl:when test="$IntranetBiblioDefaultView='normal'">
92                 <xsl:text>/cgi-bin/koha/catalogue/detail.pl?biblionumber=</xsl:text>
93             </xsl:when>
94             <xsl:when test="$IntranetBiblioDefaultView='isbd'">
95                 <xsl:text>/cgi-bin/koha/catalogue/ISBDdetail.pl?biblionumber=</xsl:text>
96             </xsl:when>
97             <xsl:when test="$IntranetBiblioDefaultView='labeled_marc'">
98                 <xsl:text>/cgi-bin/koha/catalogue/labeledMARCdetail.pl?biblionumber=</xsl:text>
99             </xsl:when>
100             <xsl:when test="$IntranetBiblioDefaultView='marc'">
101                 <xsl:text>/cgi-bin/koha/catalogue/MARCdetail.pl?biblionumber=</xsl:text>
102             </xsl:when>
103             <xsl:otherwise>
104                 <xsl:text>/cgi-bin/koha/catalogue/detail.pl?biblionumber=</xsl:text>
105             </xsl:otherwise>
106         </xsl:choose>
107     </xsl:template>
108
109         <xsl:template name="chopPunctuation">
110                 <xsl:param name="chopString"/>
111                 <xsl:variable name="length" select="string-length($chopString)"/>
112                 <xsl:choose>
113                         <xsl:when test="$length=0"/>
114                         <xsl:when test="contains('.:,;/ ', substring($chopString,$length,1))">
115                                 <xsl:call-template name="chopPunctuation">
116                                         <xsl:with-param name="chopString" select="substring($chopString,1,$length - 1)"/>
117                                 </xsl:call-template>
118                         </xsl:when>
119                         <xsl:when test="not($chopString)"/>
120                         <xsl:otherwise><xsl:value-of select="$chopString"/></xsl:otherwise>
121                 </xsl:choose>
122         </xsl:template>
123
124         <!-- Function extractControlNumber is used to extract the control number (record number) from MARC tags 773/80/85 [etc.] subfield $w.
125              Parameter: control number string.
126              Assumes LOC convention: (OrgCode)recordNumber.
127              If OrgCode is not present, return full string.
128              Additionally, handle various brackets/parentheses. Chop leading and trailing spaces.
129          Returns the value URI-encoded.
130         -->
131         <xsl:template name="extractControlNumber">
132             <xsl:param name="subfieldW"/>
133             <xsl:variable name="tranW" select="translate($subfieldW,']})&gt;','))))')"/>
134             <xsl:choose>
135               <xsl:when test="contains($tranW,')')">
136                 <xsl:value-of select="str:encode-uri(normalize-space(translate(substring-after($tranW,')'),'[]{}()&lt;&gt;','')), true())"/>
137               </xsl:when>
138               <xsl:otherwise>
139                 <xsl:value-of select="str:encode-uri(normalize-space($subfieldW), true())"/>
140               </xsl:otherwise>
141             </xsl:choose>
142         </xsl:template>
143
144     <!-- Function m880Select:  Display Alternate Graphic Representation (MARC 880) for selected latin "base"tags
145         - should be called immediately before the corresonding latin tags are processed 
146         - tags in right-to-left languages are displayed floating right
147         * Parameter:
148            + basetags: display these tags if found in linkage section ( subfield 6) of tag 880
149            + codes: display these subfields codes
150         * Options: 
151             - class: wrap output in <span class="$class">...</span>
152             - label: prefix each(!) tag with label $label
153             - bibno: link to biblionumber $bibno
154             - index: build a search link using index $index with subfield $a as key; if subfield $9 is present use index 'an' with key $9 instead.
155          * Limitations:
156             - displays every field on a separate line (to switch between rtl and ltr)
157          * Pitfalls:
158            (!) output might be empty
159     --> 
160     <xsl:template name="m880Select">
161          <xsl:param name="basetags"/> <!-- e.g.  100,700,110,710 -->
162         <xsl:param name="codes"/> <!-- e.g. abc  -->
163         <xsl:param name="class"/> <!-- e.g. results_summary -->
164         <xsl:param name="label"/> <!-- e.g.  Edition -->
165         <xsl:param name="bibno"/>
166         <xsl:param name="index"/> <!-- e.g.  au -->
167         <xsl:param name="UseAuthoritiesForTracings"/>
168
169         <xsl:for-each select="marc:datafield[@tag=880]">
170             <xsl:variable name="code6" select="marc:subfield[@code=6]"/>
171             <xsl:if test="contains(string($basetags), substring($code6,1,3))">
172                 <span>
173                     <xsl:choose>
174                     <xsl:when test="boolean($class) and substring($code6,string-length($code6)-1,2) ='/r'">
175                         <xsl:attribute name="class"><xsl:value-of select="$class"/> m880</xsl:attribute>
176                         <xsl:attribute name="dir">rtl</xsl:attribute>
177                     </xsl:when>
178                      <xsl:when test="boolean($class)">
179                         <xsl:attribute name="class"><xsl:value-of select="$class"/></xsl:attribute>
180                         <xsl:attribute name="style">display:block; </xsl:attribute>
181                     </xsl:when>    
182                      <xsl:when test="substring($code6,string-length($code6)-1,2) ='/r'">
183                         <xsl:attribute name="class"><xsl:value-of select="$class"/> m880</xsl:attribute>
184                     </xsl:when>                                    
185                     </xsl:choose>
186                     <xsl:if test="boolean($label)">
187                         <span class="label">
188                             <xsl:value-of select="$label"/>
189                         </span>
190                     </xsl:if>
191                     <xsl:variable name="str">
192                         <xsl:for-each select="marc:subfield">
193                             <xsl:if test="contains($codes, @code)">
194                                 <xsl:value-of select="text()"/>
195                                 <xsl:text> </xsl:text>
196                             </xsl:if>
197                         </xsl:for-each>
198                     </xsl:variable>
199                     <xsl:choose>
200                         <xsl:when test="boolean($bibno)">
201                             <a>
202                                 <xsl:attribute name="href">/cgi-bin/koha/catalogue/detail.pl?biblionumber=<xsl:value-of  select="str:encode-uri($bibno, true())"/></xsl:attribute>
203                                 <xsl:value-of select="$str"/>
204                             </a>
205                         </xsl:when>
206                        <xsl:when test="boolean($index) and boolean(marc:subfield[@code=9]) and $UseAuthoritiesForTracings='1'">
207                             <a>
208                                 <xsl:attribute name="href">/cgi-bin/koha/catalogue/search.pl?q=an:<xsl:value-of  select="str:encode-uri(marc:subfield[@code=9], true())"/></xsl:attribute>
209                                   <xsl:value-of select="$str"/>
210                             </a>
211                         </xsl:when>
212                         <xsl:when test="boolean($index)">
213                             <a>
214                                 <xsl:attribute name="href">/cgi-bin/koha/catalogue/search.pl?q=<xsl:value-of select="str:encode-uri($index, true())"/>:<xsl:value-of select="str:encode-uri(marc:subfield[@code='a'], true())"/></xsl:attribute>
215                                 <xsl:value-of select="$str"/>
216                             </a>
217                         </xsl:when>
218                         <xsl:otherwise>
219                             <xsl:value-of select="$str"/>
220                         </xsl:otherwise>
221                     </xsl:choose>
222                 </span>
223             </xsl:if>
224         </xsl:for-each>
225     </xsl:template>
226
227     <xsl:template name="showRDAtag264">
228     <!-- Function showRDAtag264 shows selected information from tag 264
229          on the Publisher line (used by OPAC Detail and Results)
230          Depending on how many tags you have, we will pick by preference
231          Publisher-latest or Publisher or 'Other'-latest or 'Other'
232          The preferred tag is saved in the fav variable and passed to a
233          helper named-template -->
234     <!-- Amended  to show all 264 fields (filtered by ind1=3 if ind1=3 is present in the record)  -->
235         <xsl:param name="show_url"/>
236         <xsl:choose>
237             <xsl:when test="marc:datafield[@tag=264 and @ind1=3]">
238                 <xsl:for-each select="marc:datafield[@tag=264 and @ind1=3]">
239                     <xsl:call-template name="showRDAtag264helper">
240                         <xsl:with-param name="field" select="."/>
241                         <xsl:with-param name="url" select="$show_url"/>
242                     </xsl:call-template>
243                 </xsl:for-each>
244             </xsl:when>
245             <xsl:otherwise>
246                 <xsl:for-each select="marc:datafield[@tag=264]">
247                     <xsl:call-template name="showRDAtag264helper">
248                         <xsl:with-param name="field" select="."/>
249                         <xsl:with-param name="url" select="$show_url"/>
250                     </xsl:call-template>
251                 </xsl:for-each>
252             </xsl:otherwise>
253         </xsl:choose>
254     </xsl:template>
255     <xsl:template name="showRDAtag264helper">
256         <xsl:param name="field"/>
257         <xsl:param name="url"/>
258         <xsl:variable name="ind2" select="$field/@ind2"/>
259         <span class="results_summary">
260             <xsl:choose>
261                 <xsl:when test="$ind2='0'">
262                     <span class="label">Producer: </span>
263                 </xsl:when>
264                 <xsl:when test="$ind2='1'">
265                     <span class="label">Publisher: </span>
266                 </xsl:when>
267                 <xsl:when test="$ind2='2'">
268                     <span class="label">Distributor: </span>
269                 </xsl:when>
270                 <xsl:when test="$ind2='3'">
271                     <span class="label">Manufacturer: </span>
272                 </xsl:when>
273                 <xsl:when test="$ind2='4'">
274                     <span class="label">Copyright date: </span>
275                 </xsl:when>
276             </xsl:choose>
277
278             <xsl:if test="$field/marc:subfield[@code='a']">
279                 <xsl:call-template name="subfieldSelect">
280                     <xsl:with-param name="codes">a</xsl:with-param>
281                 </xsl:call-template>
282             </xsl:if>
283             <xsl:text> </xsl:text>
284
285             <xsl:choose>
286                 <xsl:when test="$url='1'">
287                     <xsl:if test="$field/marc:subfield[@code='b']">
288                          <a>
289                          <xsl:attribute name="href">/cgi-bin/koha/catalogue/search.pl?q=Provider:<xsl:value-of select="str:encode-uri($field/marc:subfield[@code='b'], true())"/></xsl:attribute>
290                          <xsl:call-template name="subfieldSelect">
291                              <xsl:with-param name="codes">b</xsl:with-param>
292                          </xsl:call-template>
293                          </a>
294                     </xsl:if>
295                 </xsl:when>
296                 <xsl:otherwise>
297                     <xsl:if test="$field/marc:subfield[@code='b']">
298                         <xsl:call-template name="subfieldSelect">
299                             <xsl:with-param name="codes">b</xsl:with-param>
300                         </xsl:call-template>
301                     </xsl:if>
302                 </xsl:otherwise>
303             </xsl:choose>
304             <xsl:text> </xsl:text>
305             <xsl:call-template name="chopPunctuation">
306                 <xsl:with-param name="chopString">
307                     <xsl:call-template name="subfieldSelect">
308                         <xsl:with-param name="codes">c</xsl:with-param>
309                     </xsl:call-template>
310                 </xsl:with-param>
311             </xsl:call-template>
312
313         </span>
314     </xsl:template>
315
316     <xsl:template name="showISBNISSN">
317       <xsl:call-template name="showSingleSubfield">
318         <xsl:with-param name="tag">020</xsl:with-param>
319         <xsl:with-param name="code">a</xsl:with-param>
320         <xsl:with-param name="class">isbn</xsl:with-param>
321         <xsl:with-param name="label">ISBN: </xsl:with-param>
322       </xsl:call-template>
323       <xsl:call-template name="showSingleSubfield">
324         <xsl:with-param name="tag">022</xsl:with-param>
325         <xsl:with-param name="code">a</xsl:with-param>
326         <xsl:with-param name="class">issn</xsl:with-param>
327         <xsl:with-param name="label">ISSN: </xsl:with-param>
328       </xsl:call-template>
329     </xsl:template>
330
331     <xsl:template name="showSingleSubfield">
332       <xsl:param name="tag"/>
333       <xsl:param name="code"/>
334       <xsl:param name="class"/>
335       <xsl:param name="label"/>
336       <xsl:if test="marc:datafield[@tag=$tag]/marc:subfield[@code=$code]">
337         <span><xsl:attribute name="class"><xsl:value-of select="concat('results_summary ', $class)"/></xsl:attribute>
338         <span class="label"><xsl:value-of select="$label"/></span>
339             <xsl:for-each select="marc:datafield[@tag=$tag]/marc:subfield[@code=$code]">
340               <span><xsl:attribute name="property"><xsl:value-of select="$class"/></xsl:attribute>
341                 <xsl:value-of select="."/>
342                 <xsl:choose>
343                   <xsl:when test="position()=last()">
344                     <xsl:text>.</xsl:text>
345                   </xsl:when>
346                   <xsl:otherwise>
347                     <xsl:text>; </xsl:text>
348                   </xsl:otherwise>
349                 </xsl:choose>
350               </span>
351             </xsl:for-each>
352           </span>
353       </xsl:if>
354     </xsl:template>
355
356     <xsl:template name="show-lang-041">
357       <xsl:if test="marc:datafield[@tag=041]">
358         <xsl:for-each select="marc:datafield[@tag=041]">
359           <span class="results_summary languages">
360             <xsl:call-template name="show-lang-node">
361               <xsl:with-param name="langNode" select="marc:subfield[@code='a']"/>
362               <xsl:with-param name="langLabel">Language: </xsl:with-param>
363             </xsl:call-template>
364             <xsl:call-template name="show-lang-node">
365               <xsl:with-param name="langNode" select="marc:subfield[@code='b']"/>
366               <xsl:with-param name="langLabel">Summary language: </xsl:with-param>
367             </xsl:call-template>
368             <xsl:call-template name="show-lang-node">
369               <xsl:with-param name="langNode" select="marc:subfield[@code='d']"/>
370               <xsl:with-param name="langLabel">Spoken language: </xsl:with-param>
371             </xsl:call-template>
372             <xsl:call-template name="show-lang-node">
373               <xsl:with-param name="langNode" select="marc:subfield[@code='h']"/>
374               <xsl:with-param name="langLabel">Original language: </xsl:with-param>
375             </xsl:call-template>
376             <xsl:call-template name="show-lang-node">
377               <xsl:with-param name="langNode" select="marc:subfield[@code='j']"/>
378               <xsl:with-param name="langLabel">Subtitle language: </xsl:with-param>
379             </xsl:call-template>
380           </span>
381         </xsl:for-each>
382       </xsl:if>
383     </xsl:template>
384
385     <xsl:template name="show-lang-node">
386       <xsl:param name="langNode"/>
387       <xsl:param name="langLabel"/>
388       <xsl:if test="$langNode">
389         <span class="language">
390           <span class="label"><xsl:value-of select="$langLabel"/></span>
391           <xsl:for-each select="$langNode">
392             <span>
393               <xsl:attribute name="class">lang_code-<xsl:value-of select="substring(translate(., ' .-;|#', '_'),1,3)"/></xsl:attribute>
394               <xsl:call-template name="languageCodeText">
395                 <xsl:with-param name="code" select="substring(.,1,3)"/>
396               </xsl:call-template>
397               <xsl:if test="position() != last()">
398                 <span class="sep"><xsl:text>, </xsl:text></span>
399               </xsl:if>
400             </span>
401           </xsl:for-each>
402           <span class="sep"><xsl:text>. </xsl:text></span>
403         </span>
404       </xsl:if>
405     </xsl:template>
406
407 </xsl:stylesheet>
408
409 <!-- Stylus Studio meta-information - (c)1998-2002 eXcelon Corp.
410 <metaInformation>
411 <scenarios/><MapperInfo srcSchemaPath="" srcSchemaRoot="" srcSchemaPathIsRelative="yes" srcSchemaInterpretAsXML="no" destSchemaPath="" destSchemaRoot="" destSchemaPathIsRelative="yes" destSchemaInterpretAsXML="no"/>
412 </metaInformation>
413 -->