f06ee8130e33aaeefbb1d947a204c0ee3ec12fa9
[koha.git] / koha-tmpl / opac-tmpl / bootstrap / en / xslt / NORMARCslimUtils.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="str">
8         <xsl:template name="datafield">
9                 <xsl:param name="tag"/>
10                 <xsl:param name="ind1"><xsl:text> </xsl:text></xsl:param>
11                 <xsl:param name="ind2"><xsl:text> </xsl:text></xsl:param>
12                 <xsl:param name="subfields"/>
13                 <xsl:element name="datafield">
14                         <xsl:attribute name="tag">
15                                 <xsl:value-of select="$tag"/>
16                         </xsl:attribute>
17                         <xsl:attribute name="ind1">
18                                 <xsl:value-of select="$ind1"/>
19                         </xsl:attribute>
20                         <xsl:attribute name="ind2">
21                                 <xsl:value-of select="$ind2"/>
22                         </xsl:attribute>
23                         <xsl:copy-of select="$subfields"/>
24                 </xsl:element>
25         </xsl:template>
26
27         <xsl:template name="subfieldSelect">
28                 <xsl:param name="codes"/>
29                 <xsl:param name="delimeter"><xsl:text> </xsl:text></xsl:param>
30                 <xsl:param name="subdivCodes"/>
31                 <xsl:param name="subdivDelimiter"/>
32         <xsl:param name="prefix"/>
33         <xsl:param name="suffix"/>
34         <xsl:param name="urlencode"/>
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="$prefix"/><xsl:value-of select="text()"/><xsl:value-of select="$suffix"/><xsl:value-of select="$delimeter"/>
42                                 </xsl:if>
43                         </xsl:for-each>
44                 </xsl:variable>
45         <xsl:choose>
46             <xsl:when test="$urlencode=1">
47                 <xsl:value-of select="str:encode-uri(substring($str,1,string-length($str)-string-length($delimeter)), true())"/>
48             </xsl:when>
49             <xsl:otherwise>
50                 <xsl:value-of select="substring($str,1,string-length($str)-string-length($delimeter))"/>
51             </xsl:otherwise>
52         </xsl:choose>
53         </xsl:template>
54
55         <xsl:template name="buildSpaces">
56                 <xsl:param name="spaces"/>
57                 <xsl:param name="char"><xsl:text> </xsl:text></xsl:param>
58                 <xsl:if test="$spaces>0">
59                         <xsl:value-of select="$char"/>
60                         <xsl:call-template name="buildSpaces">
61                                 <xsl:with-param name="spaces" select="$spaces - 1"/>
62                                 <xsl:with-param name="char" select="$char"/>
63                         </xsl:call-template>
64                 </xsl:if>
65         </xsl:template>
66
67   <xsl:template name="buildBiblioDefaultViewURL">
68     <xsl:param name="BiblioDefaultView"/>
69     <xsl:choose>
70         <xsl:when test="$BiblioDefaultView='normal'">
71             <xsl:text>/cgi-bin/koha/opac-detail.pl?biblionumber=</xsl:text>
72         </xsl:when>
73         <xsl:when test="$BiblioDefaultView='isbd'">
74             <xsl:text>/cgi-bin/koha/opac-ISBDdetail.pl?biblionumber=</xsl:text>
75         </xsl:when>
76         <xsl:when test="$BiblioDefaultView='marc'">
77             <xsl:text>/cgi-bin/koha/opac-MARCdetail.pl?biblionumber=</xsl:text>
78         </xsl:when>
79         <xsl:otherwise>
80             <xsl:text>/cgi-bin/koha/opac-detail.pl?biblionumber=</xsl:text>
81         </xsl:otherwise>
82     </xsl:choose>
83   </xsl:template>
84
85         <xsl:template name="chopPunctuation">
86                 <xsl:param name="chopString"/>
87                 <xsl:variable name="length" select="string-length($chopString)"/>
88                 <xsl:choose>
89                         <xsl:when test="$length=0"/>
90                         <xsl:when test="contains('.:,;/ ', substring($chopString,$length,1))">
91                                 <xsl:call-template name="chopPunctuation">
92                                         <xsl:with-param name="chopString" select="substring($chopString,1,$length - 1)"/>
93                                 </xsl:call-template>
94                         </xsl:when>
95                         <xsl:when test="not($chopString)"/>
96                         <xsl:otherwise><xsl:value-of select="$chopString"/></xsl:otherwise>
97                 </xsl:choose>
98 <xsl:text> </xsl:text>
99         </xsl:template>
100
101         <!-- Function extractControlNumber is used to extract the control number (record number) from MARC tags 773/80/85 [etc.] subfield $w.
102              Parameter: control number string.
103              Assumes LOC convention: (OrgCode)recordNumber.
104              If OrgCode is not present, return full string.
105              Additionally, handle various brackets/parentheses. Chop leading and trailing spaces.
106          Returns the value URI-encoded.
107         -->
108         <xsl:template name="extractControlNumber">
109             <xsl:param name="subfieldW"/>
110             <xsl:variable name="tranW" select="translate($subfieldW,']})&gt;','))))')"/>
111             <xsl:choose>
112               <xsl:when test="contains($tranW,')')">
113                 <xsl:value-of select="str:encode-uri(normalize-space(translate(substring-after($tranW,')'),'[]{}()&lt;&gt;','')), true())"/>
114               </xsl:when>
115               <xsl:otherwise>
116                 <xsl:value-of select="str:encode-uri(normalize-space($subfieldW), true())"/>
117               </xsl:otherwise>
118             </xsl:choose>
119         </xsl:template>
120
121 <xsl:template name="nameABCDQ">
122 <xsl:call-template name="chopPunctuation">
123 <xsl:with-param name="chopString">
124 <xsl:call-template name="subfieldSelect">
125 <xsl:with-param name="codes">aq</xsl:with-param>
126 </xsl:call-template>
127 </xsl:with-param>
128 <xsl:with-param name="punctuation">
129 <xsl:text>:,;/ </xsl:text>
130 </xsl:with-param>
131 </xsl:call-template>
132 <xsl:call-template name="termsOfAddress"/>
133 </xsl:template>
134
135 <xsl:template name="nameABCDN">
136 <xsl:for-each select="marc:subfield[@code='a']">
137 <xsl:call-template name="chopPunctuation">
138 <xsl:with-param name="chopString" select="."/>
139 </xsl:call-template>
140 </xsl:for-each>
141 <xsl:for-each select="marc:subfield[@code='b']">
142 <xsl:value-of select="."/>
143 </xsl:for-each>
144 <xsl:if test="marc:subfield[@code='c'] or marc:subfield[@code='d'] or marc:subfield[@code='n']">
145 <xsl:call-template name="subfieldSelect">
146 <xsl:with-param name="codes">cdn</xsl:with-param>
147 </xsl:call-template>
148 </xsl:if>
149 </xsl:template>
150
151 <xsl:template name="nameACDEQ">
152 <xsl:call-template name="subfieldSelect">
153 <xsl:with-param name="codes">acdeq</xsl:with-param>
154 </xsl:call-template>
155 </xsl:template>
156
157 <xsl:template name="termsOfAddress">
158 <xsl:if test="marc:subfield[@code='b' or @code='c']">
159 <xsl:call-template name="chopPunctuation">
160 <xsl:with-param name="chopString">
161 <xsl:call-template name="subfieldSelect">
162 <xsl:with-param name="codes">bc</xsl:with-param>
163 </xsl:call-template>
164 </xsl:with-param>
165 </xsl:call-template>
166 </xsl:if>
167 </xsl:template>
168
169     <!-- Function m880Select:  Display Alternate Graphic Representation (MARC 880) for selected latin "base"tags
170         - should be called immediately before the corresonding latin tags are processed
171         - tags in right-to-left languages are displayed floating right
172         * Parameter:
173            + basetags: display these tags if found in linkage section ( subfield 6) of tag 880
174            + codes: display these subfields codes
175         * Options:
176             - class: wrap output in <span class="$class">...</span>
177             - label: prefix each(!) tag with label $label
178             - bibno: link to biblionumber $bibno
179             - 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.
180          * Limitations:
181             - displays every field on a separate line (to switch between rtl and ltr)
182          * Pitfalls:
183            (!) output might be empty
184     -->
185     <xsl:template name="m880Select">
186          <xsl:param name="basetags"/> <!-- e.g.  100,700,110,710 -->
187         <xsl:param name="codes"/> <!-- e.g. abc  -->
188         <xsl:param name="class"/> <!-- e.g. results_summary -->
189         <xsl:param name="label"/> <!-- e.g.  Edition -->
190         <xsl:param name="bibno"/>
191         <xsl:param name="index"/> <!-- e.g.  au -->
192
193         <xsl:for-each select="marc:datafield[@tag=880]">
194             <xsl:variable name="code6" select="marc:subfield[@code=6]"/>
195             <xsl:if test="contains(string($basetags), substring($code6,1,3))">
196                 <span>
197                     <xsl:if test="boolean($class)">
198                         <xsl:attribute name="class"><xsl:value-of select="$class"/></xsl:attribute>
199                     </xsl:if>
200                     <xsl:choose>
201                         <!-- display right-to-left tags floating right of their left-to-right counterparts -->
202                         <xsl:when test="substring($code6,10,2) ='/r'">
203                             <xsl:attribute name="style">display:block; text-align:right; float:right; width:50%; padding-left:20px</xsl:attribute>
204                             <xsl:attribute name="dir">rtl</xsl:attribute>
205                         </xsl:when>
206                         <xsl:otherwise>
207                             <xsl:attribute name="style">display:block; </xsl:attribute>
208                         </xsl:otherwise>
209                     </xsl:choose>
210                     <xsl:if test="boolean($label)">
211                         <span class="label">
212                             <xsl:value-of select="$label"/>
213                         </span>
214                     </xsl:if>
215                     <xsl:variable name="str">
216                         <xsl:for-each select="marc:subfield">
217                             <xsl:if test="contains($codes, @code)">
218                                 <xsl:value-of select="text()"/>
219                                 <xsl:text> </xsl:text>
220                             </xsl:if>
221                         </xsl:for-each>
222                     </xsl:variable>
223                     <xsl:if test="string-length($str) &gt; 0">
224                         <xsl:choose>
225                             <xsl:when test="boolean($bibno)">
226                                 <a>
227                                     <xsl:attribute name="href">/cgi-bin/koha/opac-detail.pl?biblionumber=<xsl:value-of  select="str:encode-uri($bibno, true())"/></xsl:attribute>
228                                     <xsl:value-of select="$str"/>
229                                 </a>
230                             </xsl:when>
231                            <xsl:when test="boolean($index) and boolean(marc:subfield[@code=9])">
232                                 <a>
233                                     <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>
234                                     <xsl:value-of select="$str"/>
235                                 </a>
236                             </xsl:when>
237                             <xsl:when test="boolean($index)">
238                                 <a>
239                                     <xsl:attribute name="href">/cgi-bin/koha/opac-search.pl?q=<xsl:value-of  select="$index"/>:<xsl:value-of  select="str:encode-uri(marc:subfield[@code='a'], true())"/></xsl:attribute>
240                                     <xsl:value-of select="$str"/>
241                                 </a>
242                             </xsl:when>
243                             <xsl:otherwise>
244                                 <xsl:value-of select="$str"/>
245                             </xsl:otherwise>
246                         </xsl:choose>
247                     </xsl:if>
248                 </span>
249             </xsl:if>
250         </xsl:for-each>
251
252     </xsl:template>
253
254 </xsl:stylesheet>
255
256 <!-- Stylus Studio meta-information - (c)1998-2002 eXcelon Corp.
257 <metaInformation>
258 <scenarios/><MapperInfo srcSchemaPath="" srcSchemaRoot="" srcSchemaPathIsRelative="yes" srcSchemaInterpretAsXML="no" destSchemaPath="" destSchemaRoot="" destSchemaPathIsRelative="yes" destSchemaInterpretAsXML="no"/>
259 </metaInformation>
260 -->