Merge branch 'bug_8117' into 3.12-master
[koha.git] / koha-tmpl / opac-tmpl / prog / 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="chopPunctuation">
56                 <xsl:param name="chopString"/>
57                 <xsl:variable name="length" select="string-length($chopString)"/>
58                 <xsl:choose>
59                         <xsl:when test="$length=0"/>
60                         <xsl:when test="contains('.:,;/ ', substring($chopString,$length,1))">
61                                 <xsl:call-template name="chopPunctuation">
62                                         <xsl:with-param name="chopString" select="substring($chopString,1,$length - 1)"/>
63                                 </xsl:call-template>
64                         </xsl:when>
65                         <xsl:when test="not($chopString)"/>
66                         <xsl:otherwise><xsl:value-of select="$chopString"/></xsl:otherwise>
67                 </xsl:choose>
68 <xsl:text> </xsl:text>
69         </xsl:template>
70
71 <xsl:template name="nameABCDQ">
72 <xsl:call-template name="chopPunctuation">
73 <xsl:with-param name="chopString">
74 <xsl:call-template name="subfieldSelect">
75 <xsl:with-param name="codes">aq</xsl:with-param>
76 </xsl:call-template>
77 </xsl:with-param>
78 <xsl:with-param name="punctuation">
79 <xsl:text>:,;/ </xsl:text>
80 </xsl:with-param>
81 </xsl:call-template>
82 <xsl:call-template name="termsOfAddress"/>
83 </xsl:template>
84
85 <xsl:template name="nameABCDN">
86 <xsl:for-each select="marc:subfield[@code='a']">
87 <xsl:call-template name="chopPunctuation">
88 <xsl:with-param name="chopString" select="."/>
89 </xsl:call-template>
90 </xsl:for-each>
91 <xsl:for-each select="marc:subfield[@code='b']">
92 <xsl:value-of select="."/>
93 </xsl:for-each>
94 <xsl:if test="marc:subfield[@code='c'] or marc:subfield[@code='d'] or marc:subfield[@code='n']">
95 <xsl:call-template name="subfieldSelect">
96 <xsl:with-param name="codes">cdn</xsl:with-param>
97 </xsl:call-template>
98 </xsl:if>
99 </xsl:template>
100
101 <xsl:template name="nameACDEQ">
102 <xsl:call-template name="subfieldSelect">
103 <xsl:with-param name="codes">acdeq</xsl:with-param>
104 </xsl:call-template>
105 </xsl:template>
106
107 <xsl:template name="termsOfAddress">
108 <xsl:if test="marc:subfield[@code='b' or @code='c']">
109 <xsl:call-template name="chopPunctuation">
110 <xsl:with-param name="chopString">
111 <xsl:call-template name="subfieldSelect">
112 <xsl:with-param name="codes">bc</xsl:with-param>
113 </xsl:call-template>
114 </xsl:with-param>
115 </xsl:call-template>
116 </xsl:if>
117 </xsl:template>
118
119     <!-- Function m880Select:  Display Alternate Graphic Representation (MARC 880) for selected latin "base"tags
120         - should be called immediately before the corresonding latin tags are processed 
121         - tags in right-to-left languages are displayed floating right
122         * Parameter:
123            + basetags: display these tags if found in linkage section ( subfield 6) of tag 880
124            + codes: display these subfields codes
125         * Options: 
126             - class: wrap output in <span class="$class">...</span>
127             - label: prefix each(!) tag with label $label
128             - bibno: link to biblionumber $bibno
129             - 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.
130          * Limitations:
131             - displays every field on a separate line (to switch between rtl and ltr)
132          * Pitfalls:
133            (!) output might be empty
134     -->
135     <xsl:template name="m880Select">
136          <xsl:param name="basetags"/> <!-- e.g.  100,700,110,710 -->
137         <xsl:param name="codes"/> <!-- e.g. abc  -->
138         <xsl:param name="class"/> <!-- e.g. results_summary -->
139         <xsl:param name="label"/> <!-- e.g.  Edition -->
140         <xsl:param name="bibno"/>
141         <xsl:param name="index"/> <!-- e.g.  au -->
142
143         <xsl:for-each select="marc:datafield[@tag=880]">
144             <xsl:variable name="code6" select="marc:subfield[@code=6]"/>
145             <xsl:if test="contains(string($basetags), substring($code6,1,3))">
146                 <span>
147                     <xsl:if test="boolean($class)">
148                         <xsl:attribute name="class"><xsl:value-of select="$class"/></xsl:attribute>
149                     </xsl:if>
150                     <xsl:choose>
151                         <!-- display right-to-left tags floating right of their left-to-right counterparts -->
152                         <xsl:when test="substring($code6,10,2) ='/r'">
153                             <xsl:attribute name="style">display:block; text-align:right; float:right; width:50%; padding-left:20px</xsl:attribute>
154                             <xsl:attribute name="dir">rtl</xsl:attribute>
155                         </xsl:when>
156                         <xsl:otherwise>
157                             <xsl:attribute name="style">display:block; </xsl:attribute>
158                         </xsl:otherwise>
159                     </xsl:choose>
160                     <xsl:if test="boolean($label)">
161                         <span class="label">
162                             <xsl:value-of select="$label"/>
163                         </span>
164                     </xsl:if>
165                     <xsl:variable name="str">
166                         <xsl:for-each select="marc:subfield">
167                             <xsl:if test="contains($codes, @code)">
168                                 <xsl:value-of select="text()"/>
169                                 <xsl:text> </xsl:text>
170                             </xsl:if>
171                         </xsl:for-each>
172                     </xsl:variable>
173                     <xsl:if test="string-length($str) &gt; 0">
174                         <xsl:choose>
175                             <xsl:when test="boolean($bibno)">
176                                 <a>
177                                     <xsl:attribute name="href">/cgi-bin/koha/opac-detail.pl?biblionumber=<xsl:value-of  select="$bibno"/></xsl:attribute>
178                                     <xsl:value-of select="$str"/>
179                                 </a>
180                             </xsl:when>
181                            <xsl:when test="boolean($index) and boolean(marc:subfield[@code=9])">
182                                 <a>
183                                     <xsl:attribute name="href">/cgi-bin/koha/opac-search.pl?q=an:<xsl:value-of  select="marc:subfield[@code=9]"/></xsl:attribute>
184                                     <xsl:value-of select="$str"/>
185                                 </a>
186                             </xsl:when>
187                             <xsl:when test="boolean($index)">
188                                 <a>
189                                     <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>
190                                     <xsl:value-of select="$str"/>
191                                 </a>
192                             </xsl:when>
193                             <xsl:otherwise>
194                                 <xsl:value-of select="$str"/>
195                             </xsl:otherwise>
196                         </xsl:choose>
197                     </xsl:if>
198                 </span>
199             </xsl:if>
200         </xsl:for-each>
201
202     </xsl:template>
203
204 </xsl:stylesheet>
205
206 <!-- Stylus Studio meta-information - (c)1998-2002 eXcelon Corp.
207 <metaInformation>
208 <scenarios/><MapperInfo srcSchemaPath="" srcSchemaRoot="" srcSchemaPathIsRelative="yes" srcSchemaInterpretAsXML="no" destSchemaPath="" destSchemaRoot="" destSchemaPathIsRelative="yes" destSchemaInterpretAsXML="no"/>
209 </metaInformation>
210 -->