Bug 34020: Add spans to subfields
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / xslt / MARC21slimUtils.xsl
1 <?xml version='1.0'?>
2 <!DOCTYPE stylesheet>
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:param name="newline"/>
64             <xsl:for-each select="marc:subfield">
65                 <xsl:if test="contains($codes, @code)">
66                     <span>
67                         <xsl:attribute name="class">
68                             <xsl:value-of select="@code"/>
69                             <xsl:if test="$newline = 1 and contains(text(), '--')">
70                                 <xsl:text> newline</xsl:text>
71                             </xsl:if>
72                         </xsl:attribute>
73                         <xsl:if test="contains($subdivCodes, @code)">
74                             <xsl:value-of select="$subdivDelimiter"/>
75                         </xsl:if>
76                         <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>
77                     </span>
78                 </xsl:if>
79             </xsl:for-each>
80     </xsl:template>
81
82         <xsl:template name="buildSpaces">
83                 <xsl:param name="spaces"/>
84                 <xsl:param name="char"><xsl:text> </xsl:text></xsl:param>
85                 <xsl:if test="$spaces>0">
86                         <xsl:value-of select="$char"/>
87                         <xsl:call-template name="buildSpaces">
88                                 <xsl:with-param name="spaces" select="$spaces - 1"/>
89                                 <xsl:with-param name="char" select="$char"/>
90                         </xsl:call-template>
91                 </xsl:if>
92         </xsl:template>
93
94     <xsl:template name="buildBiblioDefaultViewURL">
95         <xsl:param name="IntranetBiblioDefaultView"/>
96         <xsl:choose>
97             <xsl:when test="$IntranetBiblioDefaultView='normal'">
98                 <xsl:text>/cgi-bin/koha/catalogue/detail.pl?biblionumber=</xsl:text>
99             </xsl:when>
100             <xsl:when test="$IntranetBiblioDefaultView='isbd'">
101                 <xsl:text>/cgi-bin/koha/catalogue/ISBDdetail.pl?biblionumber=</xsl:text>
102             </xsl:when>
103             <xsl:when test="$IntranetBiblioDefaultView='labeled_marc'">
104                 <xsl:text>/cgi-bin/koha/catalogue/labeledMARCdetail.pl?biblionumber=</xsl:text>
105             </xsl:when>
106             <xsl:when test="$IntranetBiblioDefaultView='marc'">
107                 <xsl:text>/cgi-bin/koha/catalogue/MARCdetail.pl?biblionumber=</xsl:text>
108             </xsl:when>
109             <xsl:otherwise>
110                 <xsl:text>/cgi-bin/koha/catalogue/detail.pl?biblionumber=</xsl:text>
111             </xsl:otherwise>
112         </xsl:choose>
113     </xsl:template>
114
115         <xsl:template name="chopPunctuation">
116                 <xsl:param name="chopString"/>
117                 <xsl:variable name="length" select="string-length($chopString)"/>
118                 <xsl:choose>
119                         <xsl:when test="$length=0"/>
120                         <xsl:when test="contains('.:,;/ ', substring($chopString,$length,1))">
121                                 <xsl:call-template name="chopPunctuation">
122                                         <xsl:with-param name="chopString" select="substring($chopString,1,$length - 1)"/>
123                                 </xsl:call-template>
124                         </xsl:when>
125                         <xsl:when test="not($chopString)"/>
126                         <xsl:otherwise><xsl:value-of select="$chopString"/></xsl:otherwise>
127                 </xsl:choose>
128         </xsl:template>
129
130         <!-- Function extractControlNumber is used to extract the control number (record number) from MARC tags 773/80/85 [etc.] subfield $w.
131              Parameter: control number string.
132              Assumes LOC convention: (OrgCode)recordNumber.
133              If OrgCode is not present, return full string.
134              Additionally, handle various brackets/parentheses. Chop leading and trailing spaces.
135          Returns the value URI-encoded.
136         -->
137         <xsl:template name="extractControlNumber">
138             <xsl:param name="subfieldW"/>
139             <xsl:variable name="tranW" select="translate($subfieldW,']})&gt;','))))')"/>
140             <xsl:choose>
141               <xsl:when test="contains($tranW,')')">
142                 <xsl:value-of select="str:encode-uri(normalize-space(translate(substring-after($tranW,')'),'[]{}()&lt;&gt;','')), true())"/>
143               </xsl:when>
144               <xsl:otherwise>
145                 <xsl:value-of select="str:encode-uri(normalize-space($subfieldW), true())"/>
146               </xsl:otherwise>
147             </xsl:choose>
148         </xsl:template>
149
150     <!-- Function m880Select:  Display Alternate Graphic Representation (MARC 880) for selected latin "base"tags
151         - should be called immediately before the corresonding latin tags are processed 
152         - tags in right-to-left languages are displayed floating right
153         * Parameter:
154            + basetags: display these tags if found in linkage section ( subfield 6) of tag 880
155            + codes: display these subfields codes
156         * Options: 
157             - class: wrap output in <span class="$class">...</span>
158             - label: prefix each(!) tag with label $label
159             - bibno: link to biblionumber $bibno
160             - 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.
161          * Limitations:
162             - displays every field on a separate line (to switch between rtl and ltr)
163          * Pitfalls:
164            (!) output might be empty
165     --> 
166     <xsl:template name="m880Select">
167          <xsl:param name="basetags"/> <!-- e.g.  100,700,110,710 -->
168         <xsl:param name="codes"/> <!-- e.g. abc  -->
169         <xsl:param name="class"/> <!-- e.g. results_summary -->
170         <xsl:param name="label"/> <!-- e.g.  Edition -->
171         <xsl:param name="bibno"/>
172         <xsl:param name="index"/> <!-- e.g.  au -->
173         <xsl:param name="UseAuthoritiesForTracings"/>
174
175         <xsl:for-each select="marc:datafield[@tag=880]">
176             <xsl:variable name="code6" select="marc:subfield[@code=6]"/>
177             <xsl:if test="contains(string($basetags), substring($code6,1,3))">
178                 <span>
179                     <xsl:choose>
180                     <xsl:when test="boolean($class) and substring($code6,string-length($code6)-1,2) ='/r'">
181                         <xsl:attribute name="class"><xsl:value-of select="$class"/> m880</xsl:attribute>
182                         <xsl:attribute name="dir">rtl</xsl:attribute>
183                     </xsl:when>
184                      <xsl:when test="boolean($class)">
185                         <xsl:attribute name="class"><xsl:value-of select="$class"/></xsl:attribute>
186                         <xsl:attribute name="style">display:block; </xsl:attribute>
187                     </xsl:when>    
188                      <xsl:when test="substring($code6,string-length($code6)-1,2) ='/r'">
189                         <xsl:attribute name="class"><xsl:value-of select="$class"/> m880</xsl:attribute>
190                     </xsl:when>                                    
191                     </xsl:choose>
192                     <xsl:if test="boolean($label)">
193                         <span class="label">
194                             <xsl:value-of select="$label"/>
195                         </span>
196                     </xsl:if>
197                     <xsl:variable name="str">
198                         <xsl:for-each select="marc:subfield">
199                             <xsl:if test="contains($codes, @code)">
200                                 <xsl:value-of select="text()"/>
201                                 <xsl:text> </xsl:text>
202                             </xsl:if>
203                         </xsl:for-each>
204                     </xsl:variable>
205                     <xsl:choose>
206                         <xsl:when test="boolean($bibno)">
207                             <a>
208                                 <xsl:attribute name="href">/cgi-bin/koha/catalogue/detail.pl?biblionumber=<xsl:value-of  select="str:encode-uri($bibno, true())"/></xsl:attribute>
209                                 <xsl:value-of select="$str"/>
210                             </a>
211                         </xsl:when>
212                        <xsl:when test="boolean($index) and boolean(marc:subfield[@code=9]) and $UseAuthoritiesForTracings='1'">
213                             <a>
214                                 <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>
215                                   <xsl:value-of select="$str"/>
216                             </a>
217                         </xsl:when>
218                         <xsl:when test="boolean($index)">
219                             <a>
220                                 <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>
221                                 <xsl:value-of select="$str"/>
222                             </a>
223                         </xsl:when>
224                         <xsl:otherwise>
225                             <xsl:value-of select="$str"/>
226                         </xsl:otherwise>
227                     </xsl:choose>
228                 </span>
229             </xsl:if>
230         </xsl:for-each>
231     </xsl:template>
232
233     <xsl:template name="showRDAtag264">
234     <!-- Function showRDAtag264 shows selected information from tag 264
235          on the Publisher line (used by OPAC Detail and Results)
236          Depending on how many tags you have, we will pick by preference
237          Publisher-latest or Publisher or 'Other'-latest or 'Other'
238          The preferred tag is saved in the fav variable and passed to a
239          helper named-template -->
240     <!-- Amended  to show all 264 fields (filtered by ind1=3 if ind1=3 is present in the record)  -->
241         <xsl:param name="show_url"/>
242         <xsl:choose>
243             <xsl:when test="marc:datafield[@tag=264 and @ind1=3]">
244                 <xsl:for-each select="marc:datafield[@tag=264 and @ind1=3]">
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:when>
251             <xsl:otherwise>
252                 <xsl:for-each select="marc:datafield[@tag=264]">
253                     <xsl:call-template name="showRDAtag264helper">
254                         <xsl:with-param name="field" select="."/>
255                         <xsl:with-param name="url" select="$show_url"/>
256                     </xsl:call-template>
257                 </xsl:for-each>
258             </xsl:otherwise>
259         </xsl:choose>
260     </xsl:template>
261     <xsl:template name="showRDAtag264helper">
262         <xsl:param name="field"/>
263         <xsl:param name="url"/>
264         <xsl:variable name="ind2" select="$field/@ind2"/>
265         <span class="results_summary rda264">
266             <xsl:choose>
267                 <xsl:when test="$ind2='0'">
268                     <span class="label">Producer: </span>
269                 </xsl:when>
270                 <xsl:when test="$ind2='1'">
271                     <span class="label">Publisher: </span>
272                 </xsl:when>
273                 <xsl:when test="$ind2='2'">
274                     <span class="label">Distributor: </span>
275                 </xsl:when>
276                 <xsl:when test="$ind2='3'">
277                     <span class="label">Manufacturer: </span>
278                 </xsl:when>
279                 <xsl:when test="$ind2='4'">
280                     <span class="label">Copyright date: </span>
281                 </xsl:when>
282             </xsl:choose>
283
284             <xsl:for-each select="marc:subfield">
285                 <xsl:if test="@code='a'">
286                     <span class="rda264_place" property="location">
287                         <xsl:value-of select="current()"/>
288                     </span>
289                 </xsl:if>
290                     <xsl:if test="@code='b'">
291                          <span property="rda264_name" typeof="Organization">
292                              <span property="name" class="rda264_name">
293                                 <xsl:choose>
294                                     <xsl:when test="$url='1'">
295                                              <a>
296                                              <xsl:attribute name="href">/cgi-bin/koha/catalogue/search.pl?q=Provider:<xsl:value-of select="str:encode-uri(current(), true())"/></xsl:attribute>
297                                              <xsl:value-of select="current()"/>
298                                              </a>
299                                     </xsl:when>
300                                     <xsl:otherwise>
301                                             <xsl:value-of select="current()"/>
302                                     </xsl:otherwise>
303                                 </xsl:choose>
304                              </span>
305                          </span>
306                     </xsl:if>
307                 <xsl:if test="@code='c'">
308                     <span property="date" class="rda264_date">
309                         <xsl:call-template name="chopPunctuation">
310                             <xsl:with-param name="chopString">
311                                 <xsl:value-of select="current()"/>
312                             </xsl:with-param>
313                         </xsl:call-template>
314                     </span>
315                 </xsl:if>
316                 <xsl:if test="position() != last()">
317                     <xsl:text> </xsl:text>
318                 </xsl:if>
319             </xsl:for-each>
320         </span>
321     </xsl:template>
322
323     <xsl:template name="showISBNISSN">
324       <xsl:call-template name="showSingleSubfield">
325         <xsl:with-param name="tag">020</xsl:with-param>
326         <xsl:with-param name="code">a</xsl:with-param>
327         <xsl:with-param name="class">isbn</xsl:with-param>
328         <xsl:with-param name="label">ISBN: </xsl:with-param>
329       </xsl:call-template>
330       <xsl:call-template name="showSingleSubfield">
331         <xsl:with-param name="tag">022</xsl:with-param>
332         <xsl:with-param name="code">a</xsl:with-param>
333         <xsl:with-param name="class">issn</xsl:with-param>
334         <xsl:with-param name="label">ISSN: </xsl:with-param>
335       </xsl:call-template>
336     </xsl:template>
337
338     <xsl:template name="showSingleSubfield">
339       <xsl:param name="tag"/>
340       <xsl:param name="code"/>
341       <xsl:param name="class"/>
342       <xsl:param name="label"/>
343       <xsl:if test="marc:datafield[@tag=$tag]/marc:subfield[@code=$code]">
344         <span><xsl:attribute name="class"><xsl:value-of select="concat('results_summary ', $class)"/></xsl:attribute>
345         <span class="label"><xsl:value-of select="$label"/></span>
346             <xsl:for-each select="marc:datafield[@tag=$tag]/marc:subfield[@code=$code]">
347               <span><xsl:attribute name="property"><xsl:value-of select="$class"/></xsl:attribute>
348                 <xsl:value-of select="."/>
349                 <xsl:choose><xsl:when test="position()=last()"><xsl:text></xsl:text></xsl:when><xsl:otherwise><xsl:text>; </xsl:text></xsl:otherwise></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="translate(., ' .-;|#', '_')"/></xsl:attribute>
394               <xsl:call-template name="languageCodeText">
395                 <xsl:with-param name="code" select="."/>
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:template name="show-series">
408         <xsl:param name="searchurl"/>
409         <xsl:param name="UseControlNumber"/>
410         <xsl:param name="UseAuthoritiesForTracings"/>
411         <!-- Series -->
412         <xsl:if test="marc:datafield[@tag=440 or @tag=490 or @tag=800 or @tag=801 or @tag=811 or @tag=830]">
413         <span class="results_summary series"><span class="label">Series: </span>
414         <!-- 440 -->
415         <xsl:for-each select="marc:datafield[@tag=440 and @ind1!='z']">
416             <a><xsl:attribute name="href"><xsl:value-of select="$searchurl"/>?q=se,phr:"<xsl:value-of select="str:encode-uri(marc:subfield[@code='a'], true())"/>"</xsl:attribute>
417             <xsl:call-template name="chopPunctuation">
418                             <xsl:with-param name="chopString">
419                                 <xsl:call-template name="subfieldSelect">
420                                     <xsl:with-param name="codes">a</xsl:with-param>
421                                 </xsl:call-template>
422                             </xsl:with-param>
423                         </xsl:call-template>
424             </a>
425             <xsl:call-template name="part"/>
426             <xsl:if test="marc:subfield[@code='v']">
427                 <xsl:text> ; </xsl:text><xsl:value-of select="marc:subfield[@code='v']" />
428             </xsl:if>
429             <xsl:choose>
430                 <xsl:when test="position()=last()">
431                     <xsl:if test="../marc:datafield[@tag=490][@ind1!=1] or ../marc:datafield[(@tag=800 or @tag=810 or @tag=811) and @ind1!='z'] or ../marc:datafield[@tag=830 and @ind1!='z']">
432                         <span class="separator"> | </span>
433                     </xsl:if>
434                 </xsl:when>
435                 <xsl:otherwise><span class="separator"> | </span></xsl:otherwise>
436             </xsl:choose>
437         </xsl:for-each>
438
439         <!-- 490 Series not traced, Ind1 = 0 -->
440         <xsl:for-each select="marc:datafield[@tag=490][@ind1!=1]">
441             <a><xsl:attribute name="href"><xsl:value-of select="$searchurl"/>?q=se,phr:"<xsl:value-of select="str:encode-uri(marc:subfield[@code='a'], true())"/>"</xsl:attribute>
442                         <xsl:call-template name="chopPunctuation">
443                             <xsl:with-param name="chopString">
444                                 <xsl:call-template name="subfieldSelect">
445                                     <xsl:with-param name="codes">a</xsl:with-param>
446                                 </xsl:call-template>
447                             </xsl:with-param>
448                         </xsl:call-template>
449             </a>
450             <xsl:call-template name="part"/>
451             <xsl:if test="marc:subfield[@code='v']">
452                 <xsl:text> ; </xsl:text><xsl:value-of select="marc:subfield[@code='v']" />
453             </xsl:if>
454             <xsl:choose>
455                 <xsl:when test="position()=last()">
456                     <xsl:if test="../marc:datafield[(@tag=800 or @tag=810 or @tag=811) and @ind1!='z'] or ../marc:datafield[@tag=830 and @ind1!='z']">
457                         <span class="separator"> | </span>
458                     </xsl:if>
459                 </xsl:when>
460                 <xsl:otherwise><span class="separator"> | </span></xsl:otherwise>
461             </xsl:choose>
462         </xsl:for-each>
463         <!-- 800,810,811,830 always display. -->
464
465         <xsl:for-each select="marc:datafield[(@tag=800 or @tag=810 or @tag=811) and @ind1!='z']">
466             <xsl:choose>
467                 <xsl:when test="$UseControlNumber = '1' and marc:subfield[@code='w']">
468                     <a><xsl:attribute name="href"><xsl:value-of select="$searchurl"/>?q=rcn:<xsl:value-of select="str:encode-uri(marc:subfield[@code='w'], true())"/></xsl:attribute>
469                         <xsl:call-template name="chopPunctuation">
470                             <xsl:with-param name="chopString">
471                                 <xsl:call-template name="subfieldSelect">
472                                     <xsl:with-param name="codes">a_t</xsl:with-param>
473                                 </xsl:call-template>
474                             </xsl:with-param>
475                         </xsl:call-template>
476                     </a>
477                 </xsl:when>
478                 <xsl:when test="marc:subfield[@code=9] and $UseAuthoritiesForTracings='1'">
479                     <a><xsl:attribute name="href"><xsl:value-of select="$searchurl"/>?q=an:<xsl:value-of select="str:encode-uri(marc:subfield[@code=9], true())"/></xsl:attribute>
480                         <xsl:call-template name="chopPunctuation">
481                             <xsl:with-param name="chopString">
482                                 <xsl:call-template name="subfieldSelect">
483                                     <xsl:with-param name="codes">a_t</xsl:with-param>
484                                 </xsl:call-template>
485                             </xsl:with-param>
486                         </xsl:call-template>
487                     </a>
488                 </xsl:when>
489                 <xsl:otherwise>
490                     <a><xsl:attribute name="href"><xsl:value-of select="$searchurl"/>?q=se,phr:"<xsl:value-of select="str:encode-uri(marc:subfield[@code='t'], true())"/>"&amp;q=au:"<xsl:value-of select="str:encode-uri(marc:subfield[@code='a'], true())"/>"</xsl:attribute>
491                         <xsl:call-template name="chopPunctuation">
492                             <xsl:with-param name="chopString">
493                                 <xsl:call-template name="subfieldSelect">
494                                     <xsl:with-param name="codes">a_t</xsl:with-param>
495                                 </xsl:call-template>
496                             </xsl:with-param>
497                         </xsl:call-template>
498                     </a>
499                 </xsl:otherwise>
500             </xsl:choose>
501             <xsl:call-template name="part"/>
502             <xsl:text> ; </xsl:text>
503             <xsl:value-of  select="marc:subfield[@code='v']" />
504         <xsl:choose>
505             <xsl:when test="position()=last()">
506                 <xsl:if test="../marc:datafield[@tag=830 and @ind1!='z']">
507                     <span class="separator"> | </span>
508                 </xsl:if>
509             </xsl:when>
510             <xsl:otherwise>
511                 <span class="separator"> | </span>
512             </xsl:otherwise>
513         </xsl:choose>
514         </xsl:for-each>
515
516         <xsl:for-each select="marc:datafield[@tag=830 and @ind1!='z']">
517             <xsl:choose>
518                 <xsl:when test="$UseControlNumber = '1' and marc:subfield[@code='w']">
519                     <a><xsl:attribute name="href"><xsl:value-of select="$searchurl"/>?q=rcn:<xsl:value-of select="marc:subfield[@code='w']"/></xsl:attribute>
520                         <xsl:call-template name="chopPunctuation">
521                             <xsl:with-param name="chopString">
522                                 <xsl:call-template name="subfieldSelect">
523                                     <xsl:with-param name="codes">a_t</xsl:with-param>
524                                 </xsl:call-template>
525                             </xsl:with-param>
526                         </xsl:call-template>
527                     </a>
528                 </xsl:when>
529                 <xsl:when test="marc:subfield[@code=9] and $UseAuthoritiesForTracings='1'">
530                     <a><xsl:attribute name="href"><xsl:value-of select="$searchurl"/>?q=an:<xsl:value-of select="str:encode-uri(marc:subfield[@code=9], true())"/></xsl:attribute>
531                         <xsl:call-template name="chopPunctuation">
532                             <xsl:with-param name="chopString">
533                                 <xsl:call-template name="subfieldSelect">
534                                     <xsl:with-param name="codes">a_t</xsl:with-param>
535                                 </xsl:call-template>
536                             </xsl:with-param>
537                         </xsl:call-template>
538                     </a>
539                 </xsl:when>
540                 <xsl:otherwise>
541                     <a><xsl:attribute name="href"><xsl:value-of select="$searchurl"/>?q=se,phr:"<xsl:value-of select="str:encode-uri(marc:subfield[@code='a'], true())"/>"</xsl:attribute>
542                         <xsl:call-template name="chopPunctuation">
543                             <xsl:with-param name="chopString">
544                                 <xsl:call-template name="subfieldSelect">
545                                     <xsl:with-param name="codes">a_t</xsl:with-param>
546                                 </xsl:call-template>
547                             </xsl:with-param>
548                         </xsl:call-template>
549                     </a>
550                 </xsl:otherwise>
551             </xsl:choose>
552             <xsl:call-template name="part"/>
553             <xsl:if test="marc:subfield[@code='v']">
554                 <xsl:text> ; </xsl:text><xsl:value-of select="marc:subfield[@code='v']" />
555             </xsl:if>
556         <xsl:choose><xsl:when test="position()=last()"><xsl:text></xsl:text></xsl:when><xsl:otherwise><span class="separator"> | </span></xsl:otherwise></xsl:choose>
557         </xsl:for-each>
558
559         </span>
560         </xsl:if>
561     </xsl:template>
562
563     <xsl:template name="part">
564         <xsl:variable name="partNumber">
565             <xsl:call-template name="specialSubfieldSelect">
566                 <xsl:with-param name="axis">n</xsl:with-param>
567                 <xsl:with-param name="anyCodes">n</xsl:with-param>
568                 <xsl:with-param name="afterCodes">fghkdlmor</xsl:with-param>
569             </xsl:call-template>
570         </xsl:variable>
571         <xsl:variable name="partName">
572             <xsl:call-template name="specialSubfieldSelect">
573                 <xsl:with-param name="axis">p</xsl:with-param>
574                 <xsl:with-param name="anyCodes">p</xsl:with-param>
575                 <xsl:with-param name="afterCodes">fghkdlmor</xsl:with-param>
576             </xsl:call-template>
577         </xsl:variable>
578         <xsl:if test="string-length(normalize-space($partNumber)) or string-length(normalize-space($partName))" >
579             <xsl:text>. </xsl:text>
580         </xsl:if>
581         <xsl:if test="string-length(normalize-space($partNumber))">
582             <xsl:value-of select="$partNumber" />
583         </xsl:if>
584         <xsl:if test="string-length(normalize-space($partNumber))"><xsl:text> </xsl:text></xsl:if>
585         <xsl:if test="string-length(normalize-space($partName))">
586             <xsl:value-of select="$partName" />
587         </xsl:if>
588     </xsl:template>
589
590     <xsl:template name="quote_search_term">
591         <xsl:param name="term" />
592         <xsl:text>"</xsl:text>
593         <xsl:call-template name="escape_quotes">
594             <xsl:with-param name="text">
595                 <xsl:value-of select="$term"/>
596             </xsl:with-param>
597         </xsl:call-template>
598         <xsl:text>"</xsl:text>
599     </xsl:template>
600
601     <xsl:template name="escape_quotes">
602         <xsl:param name="text"/>
603         <xsl:choose>
604             <xsl:when test="contains($text, '&quot;')">
605                 <xsl:variable name="before" select="substring-before($text,'&quot;')"/>
606                 <xsl:variable name="next" select="substring-after($text,'&quot;')"/>
607                 <xsl:value-of select="$before"/>
608                 <xsl:text>\&quot;</xsl:text>
609                 <xsl:call-template name="escape_quotes">
610                     <xsl:with-param name="text" select="$next"/>
611                 </xsl:call-template>
612             </xsl:when>
613             <xsl:otherwise>
614                 <xsl:value-of select="$text"/>
615             </xsl:otherwise>
616         </xsl:choose>
617     </xsl:template>
618
619     <xsl:template name="host-item-entries">
620         <xsl:param name="UseControlNumber"/>
621         <!-- 773 -->
622         <xsl:if test="marc:datafield[@tag=773]">
623             <xsl:for-each select="marc:datafield[@tag=773]">
624                 <xsl:if test="@ind1 !=1">
625                     <span class="results_summary in"><span class="label">
626                     <xsl:choose>
627                         <xsl:when test="@ind2=' '">
628                             In:
629                         </xsl:when>
630                         <xsl:when test="@ind2=8 and marc:subfield[@code='i']">
631                             <xsl:call-template name="subfieldSelect">
632                                 <xsl:with-param name="codes">i</xsl:with-param>
633                             </xsl:call-template>
634                             <xsl:text> </xsl:text>
635                         </xsl:when>
636                     </xsl:choose>
637                     </span>
638                     <xsl:variable name="f773">
639                         <xsl:call-template name="chopPunctuation">
640                             <xsl:with-param name="chopString">
641                                 <xsl:call-template name="subfieldSelect">
642                                     <xsl:with-param name="codes">a_t</xsl:with-param>
643                                 </xsl:call-template>
644                             </xsl:with-param>
645                         </xsl:call-template>
646                     </xsl:variable>
647                     <xsl:choose>
648                         <xsl:when test="$UseControlNumber = '1' and marc:subfield[@code='w']">
649                             <a><xsl:attribute name="href">/cgi-bin/koha/catalogue/search.pl?q=Control-number:<xsl:call-template name="extractControlNumber"><xsl:with-param name="subfieldW" select="marc:subfield[@code='w']"/></xsl:call-template></xsl:attribute>
650                             <xsl:value-of select="translate($f773, '()', '')"/>
651                             </a>
652                         </xsl:when>
653                         <xsl:when test="marc:subfield[@code='0']">
654                             <a><xsl:attribute name="href">/cgi-bin/koha/catalogue/detail.pl?biblionumber=<xsl:value-of select="str:encode-uri(marc:subfield[@code='0'], true())"/></xsl:attribute>
655                             <xsl:value-of select="$f773"/>
656                             </a>
657                         </xsl:when>
658                         <xsl:otherwise>
659                             <xsl:variable name="host_query">
660                                 <xsl:text>ti,phr:(</xsl:text>
661                                 <xsl:call-template name="quote_search_term">
662                                     <xsl:with-param name="term"><xsl:value-of select="marc:subfield[@code='t']"/></xsl:with-param>
663                                 </xsl:call-template>
664                                 <xsl:text>)</xsl:text>
665                                 <xsl:if test="marc:subfield[@code='a']">
666                                     <xsl:text> AND au:(</xsl:text>
667                                     <xsl:call-template name="quote_search_term">
668                                         <xsl:with-param name="term">
669                                             <xsl:value-of select="marc:subfield[@code='a']"/>
670                                         </xsl:with-param>
671                                     </xsl:call-template>
672                                     <xsl:text>)</xsl:text>
673                                 </xsl:if>
674                             </xsl:variable>
675                             <a>
676                             <xsl:attribute name="href">/cgi-bin/koha/catalogue/search.pl?q=<xsl:value-of select="str:encode-uri($host_query, true())" />
677                             </xsl:attribute>
678                                 <xsl:value-of select="$f773"/>
679                             </a>
680                         </xsl:otherwise>
681                     </xsl:choose>
682                     <xsl:if test="marc:subfield[@code='g']">
683                         <xsl:text> </xsl:text><xsl:value-of select="marc:subfield[@code='g']"/>
684                     </xsl:if>
685                     </span>
686                     <xsl:if test="marc:subfield[@code='n']">
687                         <span class="results_summary in_note"><xsl:value-of select="marc:subfield[@code='n']"/></span>
688                     </xsl:if>
689                 </xsl:if>
690             </xsl:for-each>
691         </xsl:if>
692     </xsl:template>
693
694     <xsl:template name="AddMissingProtocol">
695         <xsl:param name="resourceLocation"/>
696         <xsl:param name="indicator1"/>
697         <xsl:param name="accessMethod"/>
698         <xsl:param name="delimiter" select="':'"/>
699         <xsl:if test="not(contains($resourceLocation, $delimiter))">
700             <xsl:choose>
701                 <xsl:when test="$indicator1=7 and ( $accessMethod='mailto' or $accessMethod='tel' )">
702                     <xsl:value-of select="$accessMethod"/><xsl:text>:</xsl:text>
703                 </xsl:when>
704                 <xsl:when test="$indicator1=7">
705                     <xsl:value-of select="$accessMethod"/><xsl:text>://</xsl:text>
706                 </xsl:when>
707                 <xsl:when test="$indicator1=0">
708                     <xsl:text>mailto:</xsl:text>
709                 </xsl:when>
710                 <xsl:when test="$indicator1=1">
711                     <xsl:text>ftp://</xsl:text>
712                 </xsl:when>
713                 <xsl:when test="$indicator1=2">
714                     <xsl:text>telnet://</xsl:text>
715                 </xsl:when>
716                 <xsl:when test="$indicator1=3">
717                     <xsl:text>tel:</xsl:text>
718                 </xsl:when>
719                 <xsl:otherwise>
720                     <xsl:text>http://</xsl:text>
721                 </xsl:otherwise>
722             </xsl:choose>
723         </xsl:if>
724     </xsl:template>
725
726     <xsl:template name="GetCnumSearchURL">
727         <xsl:param name="title_subfield" select="'t'"/>
728         <xsl:param name="cnum_subfield" select="'w'"/>
729         <xsl:param name="opac_url" select="1"/>
730         <xsl:param name="UseControlNumber"/>
731
732         <xsl:variable name="orgcode">
733             <xsl:choose>
734                 <xsl:when test="$UseControlNumber!='1'"/>
735                 <xsl:when test="substring-before(marc:subfield[@code=$cnum_subfield],')')">
736                     <!-- substring before closing parenthesis, remove parentheses and spaces -->
737                     <xsl:value-of select="normalize-space(translate(substring-before(marc:subfield[@code=$cnum_subfield],')'),'()',''))"/>
738                 </xsl:when>
739             </xsl:choose>
740         </xsl:variable>
741         <xsl:variable name="controlnumber">
742             <xsl:choose>
743                 <xsl:when test="$UseControlNumber!='1'"/>
744                 <xsl:when test="substring-after(marc:subfield[@code=$cnum_subfield],')')">
745                     <!-- substring after closing parenthesis, remove spaces -->
746                     <xsl:value-of select="normalize-space(substring-after(marc:subfield[@code=$cnum_subfield],')'))"/>
747                 </xsl:when>
748                 <xsl:otherwise>
749                     <!-- consider whole subfield now as controlnumber -->
750                     <xsl:value-of select="normalize-space(marc:subfield[@code=$cnum_subfield])"/>
751                 </xsl:otherwise>
752             </xsl:choose>
753         </xsl:variable>
754         <xsl:variable name="scriptname">
755             <xsl:choose>
756                 <xsl:when test="$opac_url=1"><xsl:text>/cgi-bin/koha/opac-search.pl</xsl:text></xsl:when>
757                 <xsl:otherwise><xsl:text>/cgi-bin/koha/catalogue/search.pl</xsl:text></xsl:otherwise>
758             </xsl:choose>
759         </xsl:variable>
760         <xsl:choose>
761             <!-- search for (1) controlnumber AND orgcode, or (2) only controlnumber, or (3) title -->
762             <xsl:when test="$controlnumber!='' and $orgcode!=''">
763                 <xsl:value-of select="str:encode-uri(concat($scriptname,'?q=Control-number:',$controlnumber,' AND Control-number-identifier:',$orgcode),false())"/>
764             </xsl:when>
765             <xsl:when test="$controlnumber!=''">
766                 <xsl:value-of select="str:encode-uri(concat($scriptname,'?q=Control-number:',$controlnumber),false())"/>
767             </xsl:when>
768             <xsl:otherwise>
769                 <xsl:variable name="quoted_title">
770                     <xsl:call-template name="quote_search_term">
771                         <xsl:with-param name="term"><xsl:value-of select="marc:subfield[@code=$title_subfield]"/></xsl:with-param>
772                     </xsl:call-template>
773                 </xsl:variable>
774                 <xsl:value-of select="str:encode-uri(concat($scriptname,'?q=ti,phr:',translate($quoted_title, '()', '')),false())"/>
775             </xsl:otherwise>
776         </xsl:choose>
777     </xsl:template>
778
779 </xsl:stylesheet>
780
781 <!-- Stylus Studio meta-information - (c)1998-2002 eXcelon Corp.
782 <metaInformation>
783 <scenarios/><MapperInfo srcSchemaPath="" srcSchemaRoot="" srcSchemaPathIsRelative="yes" srcSchemaInterpretAsXML="no" destSchemaPath="" destSchemaRoot="" destSchemaPathIsRelative="yes" destSchemaInterpretAsXML="no"/>
784 </metaInformation>
785 -->