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