Bug 13145 UNIMARC 610 tag isn't displayed in OPAC when there is no $9 subfield
[koha-equinox.git] / koha-tmpl / opac-tmpl / bootstrap / en / xslt / UNIMARCslimUtils.xsl
1 <?xml version='1.0'?>
2
3 <!DOCTYPE stylesheet [<!ENTITY nbsp "&#160;" >]>
4
5 <xsl:stylesheet version="1.0"
6   xmlns:marc="http://www.loc.gov/MARC21/slim"
7   xmlns:items="http://www.koha-community.org/items"
8   xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
9   exclude-result-prefixes="marc items">
10
11   <xsl:template name="datafield">
12     <xsl:param name="tag"/>
13     <xsl:param name="ind1"><xsl:text> </xsl:text></xsl:param>
14     <xsl:param name="ind2"><xsl:text> </xsl:text></xsl:param>
15     <xsl:param name="subfields"/>
16     <xsl:element name="datafield">
17       <xsl:attribute name="tag">
18         <xsl:value-of select="$tag"/>
19       </xsl:attribute>
20       <xsl:attribute name="ind1">
21         <xsl:value-of select="$ind1"/>
22       </xsl:attribute>
23       <xsl:attribute name="ind2">
24        <xsl:value-of select="$ind2"/>
25          </xsl:attribute>
26        <xsl:copy-of select="$subfields"/>
27     </xsl:element>
28   </xsl:template>
29
30   <xsl:template name="subfieldSelect">
31     <xsl:param name="codes"/>
32     <xsl:param name="delimeter"><xsl:text> </xsl:text></xsl:param>
33     <xsl:param name="subdivCodes"/>
34     <xsl:param name="subdivDelimiter"/>
35     <xsl:variable name="str">
36       <xsl:for-each select="marc:subfield">
37         <xsl:if test="contains($codes, @code)">
38           <xsl:if test="contains($subdivCodes, @code)">
39             <xsl:value-of select="$subdivDelimiter"/>
40           </xsl:if>
41           <xsl:value-of select="text()"/><xsl:value-of select="$delimeter"/>
42         </xsl:if>
43       </xsl:for-each>
44     </xsl:variable>
45     <xsl:value-of select="substring($str,1,string-length($str)-string-length($delimeter))"/>
46   </xsl:template>
47
48   <xsl:template name="buildSpaces">
49     <xsl:param name="spaces"/>
50     <xsl:param name="char"><xsl:text> </xsl:text></xsl:param>
51     <xsl:if test="$spaces>0">
52       <xsl:value-of select="$char"/>
53       <xsl:call-template name="buildSpaces">
54         <xsl:with-param name="spaces" select="$spaces - 1"/>
55         <xsl:with-param name="char" select="$char"/>
56       </xsl:call-template>
57     </xsl:if>
58   </xsl:template>
59
60   <xsl:template name="chopPunctuation">
61     <xsl:param name="chopString"/>
62     <xsl:variable name="length" select="string-length($chopString)"/>
63     <xsl:choose>
64       <xsl:when test="$length=0"/>
65       <xsl:when test="contains('.:,;/ ', substring($chopString,$length,1))">
66         <xsl:call-template name="chopPunctuation">
67           <xsl:with-param name="chopString" select="substring($chopString,1,$length - 1)"/>
68         </xsl:call-template>
69       </xsl:when>
70       <xsl:when test="not($chopString)"/>
71       <xsl:otherwise><xsl:value-of select="$chopString"/></xsl:otherwise>
72     </xsl:choose>
73     <xsl:text> </xsl:text>
74   </xsl:template>
75
76   <xsl:template name="addClassRtl">
77     <xsl:variable name="lang" select="marc:subfield[@code='7']" />
78     <xsl:if test="$lang = 'ha' or $lang = 'Hebrew' or $lang = 'fa' or $lang = 'Arabe'">
79       <xsl:attribute name="class">rtl</xsl:attribute>
80     </xsl:if>
81   </xsl:template>
82
83   <xsl:template name="tag_title">
84     <xsl:param name="tag" />
85     <xsl:param name="label" />
86     <xsl:param name="spanclass" />
87     <xsl:if test="marc:datafield[@tag=$tag]">
88       <span class="results_summary {$spanclass}">
89         <span class="label">
90         <xsl:value-of select="$label"/>: </span>
91         <xsl:for-each select="marc:datafield[@tag=$tag]">
92           <xsl:call-template name="addClassRtl" />
93           <xsl:for-each select="marc:subfield">
94             <xsl:choose>
95               <xsl:when test="@code='a'">
96                 <xsl:variable name="title" select="."/>
97                 <xsl:variable name="ntitle"
98                  select="translate($title, '&#x0088;&#x0089;&#x0098;&#x009C;','')"/>
99                 <xsl:value-of select="$ntitle" />
100               </xsl:when>
101               <xsl:when test="@code='b'">
102                 <xsl:text>[</xsl:text>
103                 <xsl:value-of select="."/>
104                 <xsl:text>]</xsl:text>
105               </xsl:when>
106               <xsl:when test="@code='d'">
107                 <xsl:text> = </xsl:text>
108                 <xsl:value-of select="."/>
109               </xsl:when>
110               <xsl:when test="@code='e'">
111                 <xsl:text> : </xsl:text>
112                 <xsl:value-of select="."/>
113               </xsl:when>
114               <xsl:when test="@code='f'">
115                 <xsl:text> / </xsl:text>
116                 <xsl:value-of select="."/>
117               </xsl:when>
118               <xsl:when test="@code='g'">
119                 <xsl:text> ; </xsl:text>
120                 <xsl:value-of select="."/>
121               </xsl:when>
122               <xsl:otherwise>
123                 <xsl:if test="position()>1">
124                   <xsl:text>, </xsl:text>
125                 </xsl:if>
126                 <xsl:value-of select="."/>
127               </xsl:otherwise>
128             </xsl:choose>
129           </xsl:for-each>
130           <xsl:if test="not (position() = last())">
131             <xsl:text> • </xsl:text>
132           </xsl:if>
133         </xsl:for-each>
134       </span>
135     </xsl:if>
136   </xsl:template>
137
138   <xsl:template name="tag_comma">
139     <xsl:param name="tag" />
140     <xsl:param name="label" />
141     <xsl:param name="spanclass" />
142     <xsl:if test="marc:datafield[@tag=$tag]">
143       <span class="results_summary {$spanclass}">
144         <span class="label">
145         <xsl:value-of select="$label"/>: </span>
146         <xsl:for-each select="marc:datafield[@tag=$tag]">
147           <xsl:call-template name="addClassRtl" />
148           <xsl:for-each select="marc:subfield">
149             <xsl:if test="position()>1">
150               <xsl:text>, </xsl:text>
151             </xsl:if>
152             <xsl:value-of select="."/>
153           </xsl:for-each>
154           <xsl:if test="not (position() = last())">
155             <xsl:text> • </xsl:text>
156           </xsl:if>
157         </xsl:for-each>
158       </span>
159     </xsl:if>
160   </xsl:template>
161
162   <xsl:template name="tag_210">
163     <span class="results_summary publication">
164       <span class="label">Publication: </span>
165       <xsl:for-each select="marc:datafield[@tag=210]">
166         <span>
167           <xsl:call-template name="addClassRtl" />
168           <xsl:for-each select="marc:subfield">
169             <xsl:choose>
170               <xsl:when test="@code='c' or @code='g'">
171                 <xsl:if test="position()>1">
172                   <xsl:text> : </xsl:text>
173                 </xsl:if>
174                 <xsl:value-of select="."/>
175               </xsl:when>
176               <xsl:otherwise>
177                 <xsl:if test="position()>1">
178                   <xsl:text>, </xsl:text>
179                 </xsl:if>
180                 <xsl:value-of select="."/>
181               </xsl:otherwise>
182             </xsl:choose>
183           </xsl:for-each>
184           <xsl:if test="not (position() = last())">
185             <xsl:text> • </xsl:text>
186           </xsl:if>
187         </span>
188       </xsl:for-each>
189     </span>
190   </xsl:template>
191
192   <xsl:template name="tag_215">
193     <xsl:for-each select="marc:datafield[@tag=215]">
194           <span class="results_summary description">
195         <span class="label">Description: </span>
196         <xsl:if test="marc:subfield[@code='a']">
197           <xsl:value-of select="marc:subfield[@code='a']"/>
198         </xsl:if>
199         <xsl:if test="marc:subfield[@code='c']"> :
200           <xsl:value-of select="marc:subfield[@code='c']"/>
201         </xsl:if>
202         <xsl:if test="marc:subfield[@code='d']"> ;
203           <xsl:value-of select="marc:subfield[@code='d']"/>
204         </xsl:if>
205         <xsl:if test="marc:subfield[@code='e']"> +
206           <xsl:value-of select="marc:subfield[@code='e']"/>
207         </xsl:if>
208       </span>
209     </xsl:for-each>
210   </xsl:template>
211
212   <xsl:template name="tag_onesubject">
213     <xsl:choose>
214       <xsl:when test="marc:subfield[@code=9]">
215         <xsl:for-each select="marc:subfield">
216           <xsl:if test="@code='9'">
217             <xsl:variable name="start" select="position()"/>
218             <xsl:variable name="ends">
219               <xsl:for-each select="../marc:subfield[position() &gt; $start]">
220                 <xsl:if test="@code=9">
221                   <xsl:variable name="end" select="position() + $start"/>
222                   <xsl:value-of select="$end"/>
223                   <xsl:text>,</xsl:text>
224                 </xsl:if>
225               </xsl:for-each>
226             </xsl:variable>
227             <xsl:variable name="end">
228               <xsl:choose>
229                 <xsl:when test="string-length($ends) > 0">
230                   <xsl:value-of select="substring-before($ends,',')"/>
231                 </xsl:when>
232                 <xsl:otherwise>
233                   <xsl:text>1000</xsl:text>
234                 </xsl:otherwise>
235               </xsl:choose>
236             </xsl:variable>
237             <xsl:variable name="display">
238               <xsl:for-each select="../marc:subfield[position() &gt; $start and position() &lt; $end and @code!=2 and @code!=3]">
239                 <xsl:value-of select="."/>
240                 <xsl:if test="not(position()=last())">
241                   <xsl:text>, </xsl:text>
242                 </xsl:if>
243               </xsl:for-each>
244             </xsl:variable>
245             <a>
246               <xsl:attribute name="href">
247                 <xsl:text>/cgi-bin/koha/opac-search.pl?q=an:</xsl:text>
248                 <xsl:value-of select="."/>
249               </xsl:attribute>
250               <xsl:choose>
251                 <xsl:when test="string-length($display) &gt; 0">
252                   <xsl:call-template name="chopPunctuation">
253                     <xsl:with-param name="chopString">
254                       <xsl:value-of select="$display"/>
255                     </xsl:with-param>
256                   </xsl:call-template>
257                 </xsl:when>
258                 <xsl:otherwise>
259                   <xsl:value-of select="."/>
260                 </xsl:otherwise>
261               </xsl:choose>
262             </a>
263             <xsl:variable name="ncommas"
264                  select="string-length($ends) - string-length(translate($ends, ',', ''))" />
265             <xsl:if test="$ncommas &gt; 1">
266               <xsl:text> -- </xsl:text>
267             </xsl:if>
268           </xsl:if>
269         </xsl:for-each>
270       </xsl:when>
271       <xsl:when test="marc:subfield[@code='a']">
272         <a>
273           <xsl:attribute name="href">
274             <xsl:text>/cgi-bin/koha/opac-search.pl?q=su:</xsl:text>
275             <xsl:value-of select="marc:subfield[@code='a']"/>
276           </xsl:attribute>
277           <xsl:call-template name="chopPunctuation">
278             <xsl:with-param name="chopString">
279               <xsl:call-template name="subfieldSelect">
280                 <xsl:with-param name="codes">abcdfijkmnpvxyz</xsl:with-param>
281                 <xsl:with-param name="subdivCodes">ijknpxyz</xsl:with-param>
282                 <xsl:with-param name="subdivDelimiter">-- </xsl:with-param>
283               </xsl:call-template>
284             </xsl:with-param>
285           </xsl:call-template>
286         </a>
287       </xsl:when>
288       <xsl:otherwise/>
289     </xsl:choose>
290     <xsl:if test="not(position()=last())">
291       <xsl:text> | </xsl:text>
292     </xsl:if>
293   </xsl:template>
294
295   <xsl:template name="tag_subject">
296     <xsl:param name="tag" />
297     <xsl:param name="label" />
298     <xsl:param name="spanclass" />
299     <xsl:if test="marc:datafield[@tag=$tag]">
300       <span class="results_summary subjects {$spanclass}">
301         <span class="label">
302           <xsl:value-of select="$label"/>
303           <xsl:text>: </xsl:text>
304         </span>
305         <span class="value">
306           <xsl:for-each select="marc:datafield[@tag=$tag]">
307             <xsl:call-template name="tag_onesubject">
308             </xsl:call-template>
309           </xsl:for-each>
310         </span>
311       </span>
312     </xsl:if>
313   </xsl:template>
314
315   <xsl:template name="tag_7xx">
316     <xsl:param name="tag" />
317     <xsl:param name="label" />
318     <xsl:param name="spanclass" />
319     <xsl:if test="marc:datafield[@tag=$tag]">
320       <span class="results_summary author {$spanclass}">
321         <span class="label">
322           <xsl:value-of select="$label" />
323           <xsl:text>: </xsl:text>
324         </span>
325         <span class="value">
326           <xsl:for-each select="marc:datafield[@tag=$tag]">
327             <a>
328               <xsl:choose>
329                 <xsl:when test="marc:subfield[@code=9]">
330                   <xsl:attribute name="href">
331                     <xsl:text>/cgi-bin/koha/opac-search.pl?q=an:</xsl:text>
332                     <xsl:value-of select="marc:subfield[@code=9]"/>
333                   </xsl:attribute>
334                 </xsl:when>
335                 <xsl:otherwise>
336                   <xsl:attribute name="href">
337                     <xsl:text>/cgi-bin/koha/opac-search.pl?q=au:</xsl:text>
338                     <xsl:value-of select="marc:subfield[@code='a']"/>
339                     <xsl:text> </xsl:text>
340                     <xsl:value-of select="marc:subfield[@code='b']"/>
341                   </xsl:attribute>
342                 </xsl:otherwise>
343               </xsl:choose>
344               <xsl:for-each select="marc:subfield[@code='a' or @code='b' or @code='4' or @code='c' or @code='d' or @code='f' or @code='g' or @code='p']">
345                 <xsl:choose>
346                   <xsl:when test="@code='9'">
347                   </xsl:when>
348                   <xsl:otherwise>
349                     <xsl:value-of select="."/>
350                   </xsl:otherwise>
351                 </xsl:choose>
352                 <xsl:if test="not(position() = last())">
353                   <xsl:text>, </xsl:text>
354                 </xsl:if>
355               </xsl:for-each>
356             </a>
357             <xsl:if test="not(position() = last())">
358               <span style="padding: 3px;">
359                 <xsl:text>;</xsl:text>
360               </span>
361             </xsl:if>
362           </xsl:for-each>
363         </span>
364       </span>
365     </xsl:if>
366   </xsl:template>
367
368 </xsl:stylesheet>