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