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