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