Bug 20168: Update of the OPAC bootstrap template to bootstrap v4
[koha.git] / koha-tmpl / opac-tmpl / bootstrap / 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 str">
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="BiblioDefaultView"/>
90     <xsl:choose>
91         <xsl:when test="$BiblioDefaultView='normal'">
92             <xsl:text>/cgi-bin/koha/opac-detail.pl?biblionumber=</xsl:text>
93         </xsl:when>
94         <xsl:when test="$BiblioDefaultView='isbd'">
95             <xsl:text>/cgi-bin/koha/opac-ISBDdetail.pl?biblionumber=</xsl:text>
96         </xsl:when>
97         <xsl:when test="$BiblioDefaultView='marc'">
98             <xsl:text>/cgi-bin/koha/opac-MARCdetail.pl?biblionumber=</xsl:text>
99         </xsl:when>
100         <xsl:otherwise>
101             <xsl:text>/cgi-bin/koha/opac-detail.pl?biblionumber=</xsl:text>
102         </xsl:otherwise>
103     </xsl:choose>
104   </xsl:template>
105
106         <xsl:template name="chopPunctuation">
107                 <xsl:param name="chopString"/>
108                 <xsl:variable name="length" select="string-length($chopString)"/>
109                 <xsl:choose>
110                         <xsl:when test="$length=0"/>
111                         <xsl:when test="contains('.:,;/ ', substring($chopString,$length,1))">
112                                 <xsl:call-template name="chopPunctuation">
113                                         <xsl:with-param name="chopString" select="substring($chopString,1,$length - 1)"/>
114                                 </xsl:call-template>
115                         </xsl:when>
116                         <xsl:when test="not($chopString)"/>
117                         <xsl:otherwise><xsl:value-of select="$chopString"/></xsl:otherwise>
118                 </xsl:choose>
119         </xsl:template>
120
121         <!-- Function extractControlNumber is used to extract the control number (record number) from MARC tags 773/80/85 [etc.] subfield $w.
122              Parameter: control number string.
123              Assumes LOC convention: (OrgCode)recordNumber.
124              If OrgCode is not present, return full string.
125              Additionally, handle various brackets/parentheses. Chop leading and trailing spaces.
126          Returns the value URI-encoded.
127         -->
128         <xsl:template name="extractControlNumber">
129             <xsl:param name="subfieldW"/>
130             <xsl:variable name="tranW" select="translate($subfieldW,']})&gt;','))))')"/>
131             <xsl:choose>
132               <xsl:when test="contains($tranW,')')">
133                 <xsl:value-of select="str:encode-uri(normalize-space(translate(substring-after($tranW,')'),'[]{}()&lt;&gt;','')), true())"/>
134               </xsl:when>
135               <xsl:otherwise>
136                 <xsl:value-of select="str:encode-uri(normalize-space($subfieldW), true())"/>
137               </xsl:otherwise>
138             </xsl:choose>
139         </xsl:template>
140
141     <!-- Function m880Select:  Display Alternate Graphic Representation (MARC 880) for selected latin "base"tags
142         - should be called immediately before the corresonding latin tags are processed
143         - tags in right-to-left languages are displayed floating right
144         * Parameter:
145            + basetags: display these tags if found in linkage section ( subfield 6) of tag 880
146            + codes: display these subfields codes
147         * Options:
148             - class: wrap output in <span class="$class">...</span>
149             - label: prefix each(!) tag with label $label
150             - bibno: link to biblionumber $bibno
151             - 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.
152          * Limitations:
153             - displays every field on a separate line (to switch between rtl and ltr)
154          * Pitfalls:
155            (!) output might be empty
156     -->
157     <xsl:template name="m880Select">
158          <xsl:param name="basetags"/> <!-- e.g.  100,700,110,710 -->
159         <xsl:param name="codes"/> <!-- e.g. abc  -->
160         <xsl:param name="class"/> <!-- e.g. results_summary -->
161         <xsl:param name="label"/> <!-- e.g.  Edition -->
162         <xsl:param name="bibno"/>
163         <xsl:param name="index"/> <!-- e.g.  au -->
164
165         <xsl:for-each select="marc:datafield[@tag=880]">
166             <xsl:variable name="code6" select="marc:subfield[@code=6]"/>
167             <xsl:if test="contains(string($basetags), substring($code6,1,3))">
168                 <span>
169                     <xsl:choose>
170                     <xsl:when test="boolean($class) and substring($code6,string-length($code6)-1,2) ='/r'">
171                         <xsl:attribute name="class"><xsl:value-of select="$class"/> m880</xsl:attribute>
172                         <xsl:attribute name="dir">rtl</xsl:attribute>
173                     </xsl:when>
174                      <xsl:when test="boolean($class)">
175                         <xsl:attribute name="class"><xsl:value-of select="$class"/></xsl:attribute>
176                         <xsl:attribute name="style">display:block; </xsl:attribute>
177                     </xsl:when>
178                      <xsl:when test="substring($code6,string-length($code6)-1,2) ='/r'">
179                         <xsl:attribute name="class"><xsl:value-of select="$class"/> m880</xsl:attribute>
180                     </xsl:when>
181                     </xsl:choose>
182                     <xsl:if test="boolean($label)">
183                         <span class="label">
184                             <xsl:value-of select="$label"/>
185                         </span>
186                     </xsl:if>
187                     <xsl:variable name="str">
188                         <xsl:for-each select="marc:subfield">
189                             <xsl:if test="contains($codes, @code)">
190                                 <xsl:value-of select="text()"/>
191                                 <xsl:text> </xsl:text>
192                             </xsl:if>
193                         </xsl:for-each>
194                     </xsl:variable>
195                     <xsl:if test="string-length($str) &gt; 0">
196                         <xsl:choose>
197                             <xsl:when test="boolean($bibno)">
198                                 <a>
199                                     <xsl:attribute name="href">/cgi-bin/koha/opac-detail.pl?biblionumber=<xsl:value-of  select="str:encode-uri($bibno, true())"/></xsl:attribute>
200                                     <xsl:value-of select="$str"/>
201                                 </a>
202                             </xsl:when>
203                            <xsl:when test="boolean($index) and boolean(marc:subfield[@code=9])">
204                                 <a>
205                                     <xsl:attribute name="href">/cgi-bin/koha/opac-search.pl?q=an:<xsl:value-of  select="str:encode-uri(marc:subfield[@code=9], true())"/></xsl:attribute>
206                                     <xsl:value-of select="$str"/>
207                                 </a>
208                             </xsl:when>
209                             <xsl:when test="boolean($index)">
210                                 <a>
211                                     <xsl:attribute name="href">/cgi-bin/koha/opac-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>
212                                     <xsl:value-of select="$str"/>
213                                 </a>
214                             </xsl:when>
215                             <xsl:otherwise>
216                                 <xsl:value-of select="$str"/>
217                             </xsl:otherwise>
218                         </xsl:choose>
219                     </xsl:if>
220                 </span>
221             </xsl:if>
222         </xsl:for-each>
223     </xsl:template>
224
225     <xsl:template name="showRDAtag264">
226         <!-- Function showRDAtag264 shows selected information from tag 264
227          on the Publisher line (used by OPAC Detail and Results)
228          Depending on how many tags you have, we will pick by preference
229          Publisher-latest or Publisher or 'Other'-latest or 'Other'
230          The preferred tag is saved in the fav variable and passed to a
231          helper named-template -->
232         <!-- Amended  to show all 264 fields (filtered by ind1=3 if ind1=3 is present in the record)  -->
233         <xsl:param name="show_url"/>
234         <xsl:choose>
235             <xsl:when test="marc:datafield[@tag=264 and @ind1=3]">
236                 <xsl:for-each select="marc:datafield[@tag=264 and @ind1=3]">
237                     <xsl:call-template name="showRDAtag264helper">
238                         <xsl:with-param name="field" select="."/>
239                         <xsl:with-param name="url" select="$show_url"/>
240                     </xsl:call-template>
241                 </xsl:for-each>
242             </xsl:when>
243             <xsl:otherwise>
244                 <xsl:for-each select="marc:datafield[@tag=264]">
245                     <xsl:call-template name="showRDAtag264helper">
246                         <xsl:with-param name="field" select="."/>
247                         <xsl:with-param name="url" select="$show_url"/>
248                     </xsl:call-template>
249                 </xsl:for-each>
250             </xsl:otherwise>
251         </xsl:choose>
252     </xsl:template>
253     <xsl:template name="showRDAtag264helper">
254         <xsl:param name="field"/>
255         <xsl:param name="url"/>
256         <xsl:variable name="ind2" select="$field/@ind2"/>
257         <span class="results_summary rda264">
258             <xsl:choose>
259                 <xsl:when test="$ind2='0'">
260                     <span class="label">Producer: </span>
261                 </xsl:when>
262                 <xsl:when test="$ind2='1'">
263                     <span class="label">Publisher: </span>
264                 </xsl:when>
265                 <xsl:when test="$ind2='2'">
266                     <span class="label">Distributor: </span>
267                 </xsl:when>
268                 <xsl:when test="$ind2='3'">
269                     <span class="label">Manufacturer: </span>
270                 </xsl:when>
271                 <xsl:when test="$ind2='4'">
272                     <span class="label">Copyright date: </span>
273                 </xsl:when>
274             </xsl:choose>
275
276             <xsl:if test="$field/marc:subfield[@code='a']">
277                 <xsl:call-template name="subfieldSelect">
278                     <xsl:with-param name="codes">a</xsl:with-param>
279                 </xsl:call-template>
280             </xsl:if>
281             <xsl:text> </xsl:text>
282
283             <xsl:choose>
284                 <xsl:when test="$url='1'">
285                     <xsl:if test="$field/marc:subfield[@code='b']">
286                          <a>
287                          <xsl:attribute name="href">/cgi-bin/koha/opac-search.pl?q=Provider:<xsl:value-of select="str:encode-uri($field/marc:subfield[@code='b'], true())"/></xsl:attribute>
288                          <xsl:call-template name="subfieldSelect">
289                              <xsl:with-param name="codes">b</xsl:with-param>
290                          </xsl:call-template>
291                          </a>
292                     </xsl:if>
293                 </xsl:when>
294                 <xsl:otherwise>
295                     <xsl:if test="$field/marc:subfield[@code='b']">
296                         <xsl:call-template name="subfieldSelect">
297                             <xsl:with-param name="codes">b</xsl:with-param>
298                         </xsl:call-template>
299                     </xsl:if>
300                 </xsl:otherwise>
301             </xsl:choose>
302             <xsl:text> </xsl:text>
303             <xsl:call-template name="chopPunctuation">
304                 <xsl:with-param name="chopString">
305                     <xsl:call-template name="subfieldSelect">
306                         <xsl:with-param name="codes">c</xsl:with-param>
307                     </xsl:call-template>
308                 </xsl:with-param>
309             </xsl:call-template>
310         </span>
311     </xsl:template>
312
313     <xsl:template name="show-lang-041">
314       <xsl:if test="marc:datafield[@tag=041]">
315     <xsl:for-each select="marc:datafield[@tag=041]">
316         <span class="results_summary languages">
317         <xsl:call-template name="show-lang-node">
318             <xsl:with-param name="langNode" select="marc:subfield[@code='a']"/>
319             <xsl:with-param name="langLabel">Language: </xsl:with-param>
320         </xsl:call-template>
321         <xsl:call-template name="show-lang-node">
322             <xsl:with-param name="langNode" select="marc:subfield[@code='b']"/>
323             <xsl:with-param name="langLabel">Summary language: </xsl:with-param>
324         </xsl:call-template>
325         <xsl:call-template name="show-lang-node">
326             <xsl:with-param name="langNode" select="marc:subfield[@code='d']"/>
327             <xsl:with-param name="langLabel">Spoken language: </xsl:with-param>
328         </xsl:call-template>
329         <xsl:call-template name="show-lang-node">
330             <xsl:with-param name="langNode" select="marc:subfield[@code='h']"/>
331             <xsl:with-param name="langLabel">Original language: </xsl:with-param>
332         </xsl:call-template>
333         <xsl:call-template name="show-lang-node">
334             <xsl:with-param name="langNode" select="marc:subfield[@code='j']"/>
335             <xsl:with-param name="langLabel">Subtitle language: </xsl:with-param>
336         </xsl:call-template>
337         </span>
338     </xsl:for-each>
339       </xsl:if>
340     </xsl:template>
341
342     <xsl:template name="show-lang-node">
343       <xsl:param name="langNode"/>
344       <xsl:param name="langLabel"/>
345       <xsl:if test="$langNode">
346     <span class="language">
347         <span class="label"><xsl:value-of select="$langLabel"/></span>
348         <xsl:for-each select="$langNode">
349         <span>
350             <xsl:attribute name="class">lang_code-<xsl:value-of select="translate(., ' .-;|#', '_')"/></xsl:attribute>
351             <xsl:call-template name="languageCodeText">
352         <xsl:with-param name="code" select="."/>
353             </xsl:call-template>
354             <xsl:if test="position() != last()">
355             <span class="separator"><xsl:text>, </xsl:text></span>
356             </xsl:if>
357         </span>
358         </xsl:for-each>
359         <span class="separator"><xsl:text> </xsl:text></span>
360     </span>
361       </xsl:if>
362     </xsl:template>
363
364 </xsl:stylesheet>
365
366 <!-- Stylus Studio meta-information - (c)1998-2002 eXcelon Corp.
367 <metaInformation>
368 <scenarios/><MapperInfo srcSchemaPath="" srcSchemaRoot="" srcSchemaPathIsRelative="yes" srcSchemaInterpretAsXML="no" destSchemaPath="" destSchemaRoot="" destSchemaPathIsRelative="yes" destSchemaInterpretAsXML="no"/>
369 </metaInformation>
370 -->