Bug 2093: (follow-up) Add OPAC dashboard for logged-in users
[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" xmlns:marc="http://www.loc.gov/MARC21/slim" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" exclude-result-prefixes="marc">
4         <xsl:template name="datafield">
5                 <xsl:param name="tag"/>
6                 <xsl:param name="ind1"><xsl:text> </xsl:text></xsl:param>
7                 <xsl:param name="ind2"><xsl:text> </xsl:text></xsl:param>
8                 <xsl:param name="subfields"/>
9                 <xsl:element name="datafield">
10                         <xsl:attribute name="tag">
11                                 <xsl:value-of select="$tag"/>
12                         </xsl:attribute>
13                         <xsl:attribute name="ind1">
14                                 <xsl:value-of select="$ind1"/>
15                         </xsl:attribute>
16                         <xsl:attribute name="ind2">
17                                 <xsl:value-of select="$ind2"/>
18                         </xsl:attribute>
19                         <xsl:copy-of select="$subfields"/>
20                 </xsl:element>
21         </xsl:template>
22
23         <xsl:template name="subfieldSelect">
24                 <xsl:param name="codes"/>
25                 <xsl:param name="delimeter"><xsl:text> </xsl:text></xsl:param>
26                 <xsl:param name="subdivCodes"/>
27                 <xsl:param name="subdivDelimiter"/>
28         <xsl:param name="prefix"/>
29         <xsl:param name="suffix"/>
30                 <xsl:variable name="str">
31                         <xsl:for-each select="marc:subfield">
32                                 <xsl:if test="contains($codes, @code)">
33                     <xsl:if test="contains($subdivCodes, @code)">
34                         <xsl:value-of select="$subdivDelimiter"/>
35                     </xsl:if>
36                                         <xsl:value-of select="$prefix"/><xsl:value-of select="text()"/><xsl:value-of select="$suffix"/><xsl:value-of select="$delimeter"/>
37                                 </xsl:if>
38                         </xsl:for-each>
39                 </xsl:variable>
40                 <xsl:value-of select="substring($str,1,string-length($str)-string-length($delimeter))"/>
41         </xsl:template>
42
43     <xsl:template name="subfieldSelectSpan">
44         <xsl:param name="codes"/>
45         <xsl:param name="delimeter"><xsl:text> </xsl:text></xsl:param>
46         <xsl:param name="subdivCodes"/>
47         <xsl:param name="subdivDelimiter"/>
48         <xsl:param name="prefix"/>
49         <xsl:param name="suffix"/>
50             <xsl:for-each select="marc:subfield">
51                 <xsl:if test="contains($codes, @code)">
52                     <span>
53                         <xsl:attribute name="class"><xsl:value-of select="@code"/></xsl:attribute>
54                         <xsl:if test="contains($subdivCodes, @code)">
55                             <xsl:value-of select="$subdivDelimiter"/>
56                         </xsl:if>
57                         <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>
58                     </span>
59                 </xsl:if>
60             </xsl:for-each>
61     </xsl:template>
62
63         <xsl:template name="buildSpaces">
64                 <xsl:param name="spaces"/>
65                 <xsl:param name="char"><xsl:text> </xsl:text></xsl:param>
66                 <xsl:if test="$spaces>0">
67                         <xsl:value-of select="$char"/>
68                         <xsl:call-template name="buildSpaces">
69                                 <xsl:with-param name="spaces" select="$spaces - 1"/>
70                                 <xsl:with-param name="char" select="$char"/>
71                         </xsl:call-template>
72                 </xsl:if>
73         </xsl:template>
74
75   <xsl:template name="buildBiblioDefaultViewURL">
76     <xsl:param name="BiblioDefaultView"/>
77     <xsl:choose>
78         <xsl:when test="$BiblioDefaultView='normal'">
79             <xsl:text>/cgi-bin/koha/opac-detail.pl?biblionumber=</xsl:text>
80         </xsl:when>
81         <xsl:when test="$BiblioDefaultView='isbd'">
82             <xsl:text>/cgi-bin/koha/opac-ISBDdetail.pl?biblionumber=</xsl:text>
83         </xsl:when>
84         <xsl:when test="$BiblioDefaultView='marc'">
85             <xsl:text>/cgi-bin/koha/opac-MARCdetail.pl?biblionumber=</xsl:text>
86         </xsl:when>
87         <xsl:otherwise>
88             <xsl:text>/cgi-bin/koha/opac-detail.pl?biblionumber=</xsl:text>
89         </xsl:otherwise>
90     </xsl:choose>
91   </xsl:template>
92
93         <xsl:template name="chopPunctuation">
94                 <xsl:param name="chopString"/>
95                 <xsl:variable name="length" select="string-length($chopString)"/>
96                 <xsl:choose>
97                         <xsl:when test="$length=0"/>
98                         <xsl:when test="contains('.:,;/ ', substring($chopString,$length,1))">
99                                 <xsl:call-template name="chopPunctuation">
100                                         <xsl:with-param name="chopString" select="substring($chopString,1,$length - 1)"/>
101                                 </xsl:call-template>
102                         </xsl:when>
103                         <xsl:when test="not($chopString)"/>
104                         <xsl:otherwise><xsl:value-of select="$chopString"/></xsl:otherwise>
105                 </xsl:choose>
106         </xsl:template>
107
108         <!-- Function extractControlNumber is used to extract the control number (record number) from MARC tags 773/80/85 [etc.] subfield $w.
109              Parameter: control number string.
110              Assumes LOC convention: (OrgCode)recordNumber.
111              If OrgCode is not present, return full string.
112              Additionally, handle various brackets/parentheses. Chop leading and trailing spaces.
113         -->
114         <xsl:template name="extractControlNumber">
115             <xsl:param name="subfieldW"/>
116             <xsl:variable name="tranW" select="translate($subfieldW,']})&gt;','))))')"/>
117             <xsl:choose>
118               <xsl:when test="contains($tranW,')')">
119                 <xsl:value-of select="normalize-space(translate(substring-after($tranW,')'),'[]{}()&lt;&gt;',''))"/>
120               </xsl:when>
121               <xsl:otherwise>
122                 <xsl:value-of select="normalize-space($subfieldW)"/>
123               </xsl:otherwise>
124             </xsl:choose>
125         </xsl:template>
126
127     <!-- Function m880Select:  Display Alternate Graphic Representation (MARC 880) for selected latin "base"tags
128         - should be called immediately before the corresonding latin tags are processed
129         - tags in right-to-left languages are displayed floating right
130         * Parameter:
131            + basetags: display these tags if found in linkage section ( subfield 6) of tag 880
132            + codes: display these subfields codes
133         * Options:
134             - class: wrap output in <span class="$class">...</span>
135             - label: prefix each(!) tag with label $label
136             - bibno: link to biblionumber $bibno
137             - 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.
138          * Limitations:
139             - displays every field on a separate line (to switch between rtl and ltr)
140          * Pitfalls:
141            (!) output might be empty
142     -->
143     <xsl:template name="m880Select">
144          <xsl:param name="basetags"/> <!-- e.g.  100,700,110,710 -->
145         <xsl:param name="codes"/> <!-- e.g. abc  -->
146         <xsl:param name="class"/> <!-- e.g. results_summary -->
147         <xsl:param name="label"/> <!-- e.g.  Edition -->
148         <xsl:param name="bibno"/>
149         <xsl:param name="index"/> <!-- e.g.  au -->
150
151         <xsl:for-each select="marc:datafield[@tag=880]">
152             <xsl:variable name="code6" select="marc:subfield[@code=6]"/>
153             <xsl:if test="contains(string($basetags), substring($code6,1,3))">
154                 <span>
155                     <xsl:choose>
156                     <xsl:when test="boolean($class) and substring($code6,string-length($code6)-1,2) ='/r'">
157                         <xsl:attribute name="class"><xsl:value-of select="$class"/> m880</xsl:attribute>
158                         <xsl:attribute name="dir">rtl</xsl:attribute>
159                     </xsl:when>
160                      <xsl:when test="boolean($class)">
161                         <xsl:attribute name="class"><xsl:value-of select="$class"/></xsl:attribute>
162                         <xsl:attribute name="style">display:block; </xsl:attribute>
163                     </xsl:when>
164                      <xsl:when test="substring($code6,string-length($code6)-1,2) ='/r'">
165                         <xsl:attribute name="class"><xsl:value-of select="$class"/> m880</xsl:attribute>
166                     </xsl:when>
167                     </xsl:choose>
168                     <xsl:if test="boolean($label)">
169                         <span class="label">
170                             <xsl:value-of select="$label"/>
171                         </span>
172                     </xsl:if>
173                     <xsl:variable name="str">
174                         <xsl:for-each select="marc:subfield">
175                             <xsl:if test="contains($codes, @code)">
176                                 <xsl:value-of select="text()"/>
177                                 <xsl:text> </xsl:text>
178                             </xsl:if>
179                         </xsl:for-each>
180                     </xsl:variable>
181                     <xsl:if test="string-length($str) &gt; 0">
182                         <xsl:choose>
183                             <xsl:when test="boolean($bibno)">
184                                 <a>
185                                     <xsl:attribute name="href">/cgi-bin/koha/opac-detail.pl?biblionumber=<xsl:value-of  select="$bibno"/></xsl:attribute>
186                                     <xsl:value-of select="$str"/>
187                                 </a>
188                             </xsl:when>
189                            <xsl:when test="boolean($index) and boolean(marc:subfield[@code=9])">
190                                 <a>
191                                     <xsl:attribute name="href">/cgi-bin/koha/opac-search.pl?q=an:<xsl:value-of  select="marc:subfield[@code=9]"/></xsl:attribute>
192                                     <xsl:value-of select="$str"/>
193                                 </a>
194                             </xsl:when>
195                             <xsl:when test="boolean($index)">
196                                 <a>
197                                     <xsl:attribute name="href">/cgi-bin/koha/opac-search.pl?q=<xsl:value-of  select="$index"/>:<xsl:value-of  select="marc:subfield[@code='a']"/></xsl:attribute>
198                                     <xsl:value-of select="$str"/>
199                                 </a>
200                             </xsl:when>
201                             <xsl:otherwise>
202                                 <xsl:value-of select="$str"/>
203                             </xsl:otherwise>
204                         </xsl:choose>
205                     </xsl:if>
206                 </span>
207             </xsl:if>
208         </xsl:for-each>
209     </xsl:template>
210
211     <xsl:template name="showRDAtag264">
212         <!-- Function showRDAtag264 shows selected information from tag 264
213          on the Publisher line (used by OPAC Detail and Results)
214          Depending on how many tags you have, we will pick by preference
215          Publisher-latest or Publisher or 'Other'-latest or 'Other'
216          The preferred tag is saved in the fav variable and passed to a
217          helper named-template -->
218         <!-- Amended  to show all 264 fields (filtered by ind1=3 if ind1=3 is present in the record)  -->
219         <xsl:param name="show_url"/>
220         <xsl:choose>
221             <xsl:when test="marc:datafield[@tag=264 and @ind1=3]">
222                 <xsl:for-each select="marc:datafield[@tag=264 and @ind1=3]">
223                     <xsl:call-template name="showRDAtag264helper">
224                         <xsl:with-param name="field" select="."/>
225                         <xsl:with-param name="url" select="$show_url"/>
226                     </xsl:call-template>
227                 </xsl:for-each>
228             </xsl:when>
229             <xsl:otherwise>
230                 <xsl:for-each select="marc:datafield[@tag=264]">
231                     <xsl:call-template name="showRDAtag264helper">
232                         <xsl:with-param name="field" select="."/>
233                         <xsl:with-param name="url" select="$show_url"/>
234                     </xsl:call-template>
235                 </xsl:for-each>
236             </xsl:otherwise>
237         </xsl:choose>
238     </xsl:template>
239     <xsl:template name="showRDAtag264helper">
240         <xsl:param name="field"/>
241         <xsl:param name="url"/>
242         <xsl:variable name="ind2" select="$field/@ind2"/>
243         <span class="results_summary">
244             <xsl:choose>
245                 <xsl:when test="$ind2='0'">
246                     <span class="label">Producer: </span>
247                 </xsl:when>
248                 <xsl:when test="$ind2='1'">
249                     <span class="label">Publisher: </span>
250                 </xsl:when>
251                 <xsl:when test="$ind2='2'">
252                     <span class="label">Distributor: </span>
253                 </xsl:when>
254                 <xsl:when test="$ind2='3'">
255                     <span class="label">Manufacturer: </span>
256                 </xsl:when>
257                 <xsl:when test="$ind2='4'">
258                     <span class="label">Copyright date: </span>
259                 </xsl:when>
260             </xsl:choose>
261
262             <xsl:if test="$field/marc:subfield[@code='a']">
263                 <xsl:call-template name="subfieldSelect">
264                     <xsl:with-param name="codes">a</xsl:with-param>
265                 </xsl:call-template>
266             </xsl:if>
267             <xsl:text> </xsl:text>
268
269             <xsl:choose>
270                 <xsl:when test="$url='1'">
271                     <xsl:if test="$field/marc:subfield[@code='b']">
272                          <a href="/cgi-bin/koha/opac-search.pl?q=Provider:{$field/marc:subfield[@code='b']}">
273                          <xsl:call-template name="subfieldSelect">
274                              <xsl:with-param name="codes">b</xsl:with-param>
275                          </xsl:call-template>
276                          </a>
277                     </xsl:if>
278                 </xsl:when>
279                 <xsl:otherwise>
280                     <xsl:if test="$field/marc:subfield[@code='b']">
281                         <xsl:call-template name="subfieldSelect">
282                             <xsl:with-param name="codes">b</xsl:with-param>
283                         </xsl:call-template>
284                     </xsl:if>
285                 </xsl:otherwise>
286             </xsl:choose>
287             <xsl:text> </xsl:text>
288             <xsl:call-template name="chopPunctuation">
289                 <xsl:with-param name="chopString">
290                     <xsl:call-template name="subfieldSelect">
291                         <xsl:with-param name="codes">c</xsl:with-param>
292                     </xsl:call-template>
293                 </xsl:with-param>
294             </xsl:call-template>
295
296         </span>
297     </xsl:template>
298 </xsl:stylesheet>
299
300 <!-- Stylus Studio meta-information - (c)1998-2002 eXcelon Corp.
301 <metaInformation>
302 <scenarios/><MapperInfo srcSchemaPath="" srcSchemaRoot="" srcSchemaPathIsRelative="yes" srcSchemaInterpretAsXML="no" destSchemaPath="" destSchemaRoot="" destSchemaPathIsRelative="yes" destSchemaInterpretAsXML="no"/>
303 </metaInformation>
304 -->