Bug 9303 [QA Followup] - Restore ability for patron to control setting
[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:choose>
220             <xsl:when test="marc:datafield[@tag=264 and @ind1=3]">
221                 <xsl:for-each select="marc:datafield[@tag=264 and @ind1=3]">
222                     <xsl:call-template name="showRDAtag264helper">
223                         <xsl:with-param name="field" select="."/>
224                     </xsl:call-template>
225                 </xsl:for-each>
226             </xsl:when>
227             <xsl:otherwise>
228                 <xsl:for-each select="marc:datafield[@tag=264]">
229                     <xsl:call-template name="showRDAtag264helper">
230                         <xsl:with-param name="field" select="."/>
231                     </xsl:call-template>
232                 </xsl:for-each>
233             </xsl:otherwise>
234         </xsl:choose>
235     </xsl:template>
236     <xsl:template name="showRDAtag264helper">
237         <xsl:param name="field"/>
238         <xsl:variable name="ind2" select="$field/@ind2"/>
239         <span class="results_summary">
240             <xsl:choose>
241                 <xsl:when test="$ind2='0'">
242                     <span class="label">Producer: </span>
243                 </xsl:when>
244                 <xsl:when test="$ind2='1'">
245                     <span class="label">Publisher: </span>
246                 </xsl:when>
247                 <xsl:when test="$ind2='2'">
248                     <span class="label">Distributor: </span>
249                 </xsl:when>
250                 <xsl:when test="$ind2='3'">
251                     <span class="label">Manufacturer: </span>
252                 </xsl:when>
253                 <xsl:when test="$ind2='4'">
254                     <span class="label">Copyright date: </span>
255                 </xsl:when>
256             </xsl:choose>
257             <xsl:call-template name="subfieldSelect">
258                 <xsl:with-param name="codes">abc</xsl:with-param>
259             </xsl:call-template>
260         </span>
261     </xsl:template>
262 </xsl:stylesheet>
263
264 <!-- Stylus Studio meta-information - (c)1998-2002 eXcelon Corp.
265 <metaInformation>
266 <scenarios/><MapperInfo srcSchemaPath="" srcSchemaRoot="" srcSchemaPathIsRelative="yes" srcSchemaInterpretAsXML="no" destSchemaPath="" destSchemaRoot="" destSchemaPathIsRelative="yes" destSchemaInterpretAsXML="no"/>
267 </metaInformation>
268 -->