Bug 11401: QA followup
[koha.git] / etc / pazpar2 / pz2-ourl-base.xsl
1 <?xml version="1.0" encoding="UTF-8"?>
2 <xsl:stylesheet
3     version="1.0"
4     xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
5     xmlns:pz="http://www.indexdata.com/pazpar2/1.0"
6     xmlns:marc="http://www.loc.gov/MARC21/slim"
7     xmlns:str="http://exslt.org/strings"
8     extension-element-prefixes="str">
9
10   <xsl:param name="open_url_resolver"/>
11   <!--<xsl:variable name="resolver">http://zeus.lib.uoc.gr:3210/sfxtst3</xsl:variable>-->
12  
13   <xsl:template name="insert-md-openurl">
14   
15     <xsl:value-of select="$open_url_resolver" /><xsl:text>?generatedby=pz2</xsl:text>
16     <xsl:call-template name="ou-parse-author" />
17     <xsl:call-template name="ou-parse-date" />
18     <xsl:call-template name="ou-parse-volume" />
19     <xsl:call-template name="ou-parse-any">
20       <xsl:with-param name="field_name" select="string('isbn')" />
21     </xsl:call-template>
22     <xsl:call-template name="ou-parse-any">
23       <xsl:with-param name="field_name" select="string('issn')" />
24     </xsl:call-template>
25     <xsl:call-template name="ou-parse-any">
26       <xsl:with-param name="field_name" select="string('title')" />
27     </xsl:call-template>
28     <xsl:call-template name="ou-parse-any">
29       <xsl:with-param name="field_name" select="string('atitle')" />
30     </xsl:call-template>
31
32   </xsl:template>
33  
34   <!-- parsing raw string data -->
35   
36   <xsl:template name="ou-parse-author" >
37     <xsl:variable name="author">
38       <xsl:call-template name="ou-author" />
39     </xsl:variable>
40     
41     <xsl:variable name="aulast" select="normalize-space(substring-before($author, ','))"/>
42
43     <xsl:variable name="aufirst" 
44       select="substring-before( normalize-space(substring-after($author, ',')), ' ')"/>
45
46     <xsl:if test="$aulast != ''">
47       <xsl:text>&amp;aulast=</xsl:text>
48       <xsl:value-of select="$aulast" />
49     </xsl:if>
50
51     <xsl:if test="string-length( translate($aufirst, '.', '') ) &gt; 1" >
52       <xsl:text>&amp;aufirst=</xsl:text>
53       <xsl:value-of select="$aufirst" />
54     </xsl:if>
55
56   </xsl:template>
57
58   <xsl:template name="ou-parse-volume">
59     <xsl:variable name="volume">
60       <xsl:call-template name="ou-volume" />
61     </xsl:variable>
62
63     <xsl:variable name="vol" select="substring-after($volume, 'Vol')"/>
64     <xsl:variable name="issue" select="false()" />
65     <xsl:variable name="spage" select="false()" />
66
67     <xsl:if test="$vol">
68       <xsl:text>&amp;volume=</xsl:text>
69       <xsl:value-of select="$vol" />
70     </xsl:if>
71
72     <xsl:if test="$issue">
73       <xsl:text>&amp;issue=</xsl:text>
74       <xsl:value-of select="$issue" />
75     </xsl:if>
76     
77     <xsl:if test="$spage">
78       <xsl:text>&amp;spage=</xsl:text>
79       <xsl:value-of select="$vol" />
80     </xsl:if>
81
82   </xsl:template>
83
84
85   <xsl:template name="ou-parse-date">
86     <xsl:variable name="date">
87       <xsl:call-template name="ou-date" />
88     </xsl:variable>
89
90     <xsl:variable name="parsed_date" select="translate($date, '.[]c;', '')"/>
91
92     <xsl:if test="$parsed_date">
93       <xsl:text>&amp;date=</xsl:text>
94       <xsl:value-of select="$parsed_date" />
95     </xsl:if>
96
97   </xsl:template>
98
99   
100   <xsl:template name="ou-parse-any">
101     <xsl:param name="field_name" />
102
103     <xsl:variable name="field_value">
104       <xsl:choose>
105
106       <xsl:when test="$field_name = 'isbn'">
107         <xsl:call-template name="ou-isbn"/>
108       </xsl:when>
109
110       <xsl:when test="$field_name = 'issn'">
111         <xsl:call-template name="ou-issn"/>
112       </xsl:when>
113       
114       <xsl:when test="$field_name = 'atitle'">
115         <xsl:call-template name="ou-atitle"/>
116       </xsl:when>
117      
118       <xsl:when test="$field_name = 'title'">
119         <xsl:call-template name="ou-title"/>
120       </xsl:when>
121
122       </xsl:choose>
123     </xsl:variable>
124
125     <xsl:variable name="digits" select="1234567890"/>
126
127     <xsl:variable name="parsed_value">
128       <xsl:choose>
129
130       <xsl:when test="$field_name = 'isbn'">
131         <xsl:value-of select="translate($field_value, translate($field_value, concat($digits, 'X'), ''), '')"/>
132       </xsl:when>
133
134       <xsl:when test="$field_name = 'issn'">
135         <xsl:value-of select="translate($field_value, translate($field_value, concat($digits, '-', 'X'), ''), '')"/>
136       </xsl:when>
137       
138       <xsl:when test="$field_name = 'atitle'">
139         <xsl:value-of select="translate(normalize-space($field_value), '.', '')"/>
140       </xsl:when>
141      
142       <xsl:when test="$field_name = 'title'">
143         <xsl:value-of select="translate(normalize-space($field_value), '.', '')"/>
144       </xsl:when>
145
146       </xsl:choose>
147     </xsl:variable>
148
149
150     <xsl:if test="$parsed_value != ''">
151       <xsl:text>&amp;</xsl:text>
152       <xsl:value-of select="$field_name" />
153       <xsl:text>=</xsl:text>
154       <xsl:value-of select="$parsed_value" />
155     </xsl:if>
156
157   </xsl:template>
158
159
160 </xsl:stylesheet>
161 <!--
162 /*
163  * Local variables:
164  * c-basic-offset: 2
165  * indent-tabs-mode: nil
166  * End:
167  * vim: shiftwidth=2 tabstop=4 expandtab
168  */
169 -->