Allow predictable sessions PAZ-1030
[pazpar2-moved-to-github.git] / test / dads-pz2.xsl
1 <?xml version="1.0" encoding="UTF-8"?>
2 <xsl:stylesheet version="1.0"
3   xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
4   xmlns:pz="http://www.indexdata.com/pazpar2/1.0"
5   xmlns:zs="http://www.loc.gov/zing/srw/"
6   xmlns:tmarc="http://www.indexdata.com/turbomarc">
7
8   <xsl:output indent="yes" method="xml" version="1.0"
9     encoding="UTF-8" />
10   <xsl:param name="medium"/>
11
12   <!-- Extract metadata from MARC21/USMARC from streamlined marcxml format 
13     http://www.loc.gov/marc/bibliographic/ecbdhome.html -->
14   <xsl:template name="record-hook" />
15
16
17   <xsl:template match="/">
18       <xsl:apply-templates />
19   </xsl:template>
20
21   <xsl:template match="zs:searchRetrieveResponse">
22       <xsl:apply-templates />
23   </xsl:template>
24
25   <xsl:template match="zs:records">
26     <collection>
27       <xsl:apply-templates />
28     </collection>
29   </xsl:template>
30
31   <xsl:template match="zs:record">
32       <xsl:apply-templates />
33   </xsl:template>  
34
35   <xsl:template match="zs:recordData">
36       <xsl:apply-templates />
37   </xsl:template>
38
39   <xsl:template match="doc">
40     <collection>
41       <xsl:apply-templates />
42     </collection>
43   </xsl:template>
44
45   <xsl:template match="art">
46     <xsl:variable name="journal_title" select="journal/title" />
47     <xsl:variable name="journal_issn" select="journal/issn" />
48     <xsl:variable name="date" select="journal/year" />
49     <xsl:variable name="month" select="journal/month" />
50     <xsl:variable name="description" select="abstract/abstract" />
51
52     <xsl:variable name="has_fulltext" select="article/fulltext"/>
53     <xsl:variable name="has_title" select="article/title"/>
54
55     <xsl:variable name="vmedium">
56       <xsl:choose>
57         <xsl:when  test="$has_title and $has_fulltext">
58           <xsl:text>e-article</xsl:text>
59         </xsl:when>
60         <xsl:when  test="$has_title and not($has_fulltext)">
61           <xsl:text>article</xsl:text>
62         </xsl:when>
63         <xsl:otherwise>
64           <xsl:text>other</xsl:text>
65         </xsl:otherwise>
66       </xsl:choose>
67     </xsl:variable>
68     
69     <pz:record>
70
71       <xsl:for-each select="localInfo/systemno"> 
72         <pz:metadata type="id">
73           <xsl:value-of select="."/>
74         </pz:metadata>
75       </xsl:for-each>
76
77       <xsl:for-each select="author/name">
78         <pz:metadata type="author">
79           <xsl:value-of select="." />
80         </pz:metadata>
81       </xsl:for-each>
82       
83       <xsl:for-each select="article/title">
84         <pz:metadata type="title">
85           <xsl:value-of select="." />
86         </pz:metadata>
87       </xsl:for-each>
88
89       <xsl:for-each select="journal/issn">
90         <pz:metadata type="issn">
91           <xsl:value-of select="." />
92         </pz:metadata>
93       </xsl:for-each>
94
95       <xsl:for-each select="journal/title">
96         <pz:metadata type="journal-title">
97           <xsl:value-of select="." />
98         </pz:metadata>
99       </xsl:for-each>
100
101       <xsl:for-each select="journal/vol">
102         <pz:metadata type="journal-number">
103           <xsl:value-of select="." />
104         </pz:metadata>
105       </xsl:for-each>
106
107       <xsl:for-each select="journal/issue">
108         <pz:metadata type="issue-number">
109           <xsl:value-of select="." />
110         </pz:metadata>
111       </xsl:for-each>
112
113       <xsl:for-each select="journal"> 
114         <pz:metadata type="journal-subpart">
115           <xsl:if test="vol">
116             <xsl:text>Vol. </xsl:text><xsl:value-of select="vol" /><xsl:text>,</xsl:text>
117           </xsl:if>
118           <xsl:if test="issue">
119             <xsl:if test="vol">
120               <xsl:text> no. </xsl:text>
121             </xsl:if>
122             <xsl:if test="not(vol)">
123               <xsl:text>No. </xsl:text>
124             </xsl:if>
125             <xsl:value-of select="issue" />
126           </xsl:if>
127           <xsl:text> (</xsl:text>
128           <xsl:if test="month">
129             <xsl:choose>
130               <xsl:when test="$month='01'">
131                 <xsl:text>Jan. </xsl:text>
132               </xsl:when>
133               <xsl:when test="$month='02'">
134                 <xsl:text>Feb. </xsl:text>
135               </xsl:when>
136               <xsl:when test="$month='03'">
137                 <xsl:text>Mar. </xsl:text>
138               </xsl:when>
139               <xsl:when test="$month='04'">
140                 <xsl:text>Apr. </xsl:text>
141               </xsl:when>
142               <xsl:when test="$month='05'">
143                 <xsl:text>May </xsl:text>
144               </xsl:when>
145               <xsl:when test="$month='06'">
146                 <xsl:text>June </xsl:text>
147               </xsl:when>
148               <xsl:when test="$month='07'">
149                 <xsl:text>July </xsl:text>
150               </xsl:when>
151               <xsl:when test="$month='08'">
152                 <xsl:text>Aug. </xsl:text>
153               </xsl:when>
154               <xsl:when test="$month='09'">
155                 <xsl:text>Sept. </xsl:text>
156               </xsl:when>
157               <xsl:when test="$month='10'">
158                 <xsl:text>Oct. </xsl:text>
159               </xsl:when>
160               <xsl:when test="$month='11'">
161                 <xsl:text>Nov. </xsl:text>
162               </xsl:when>
163               <xsl:when test="$month='12'">
164                 <xsl:text>Dec. </xsl:text>
165               </xsl:when>
166               <xsl:otherwise>
167                 <xsl:value-of select="$month"/><xsl:text> </xsl:text>
168               </xsl:otherwise>
169             </xsl:choose>
170           </xsl:if>
171           <xsl:value-of select="year" /><xsl:text>)</xsl:text>
172           <xsl:if test="page"> 
173             <xsl:text>, p. </xsl:text><xsl:value-of select="page" />
174           </xsl:if>
175         </pz:metadata>
176       </xsl:for-each>      
177
178       <pz:metadata type="description">
179         <xsl:value-of select="$description" />
180       </pz:metadata>
181       
182       <xsl:for-each select="ctrlT/term">
183         <pz:metadata type="subject">
184           <xsl:value-of select="." />
185         </pz:metadata>
186       </xsl:for-each>
187
188       <xsl:for-each select="article/fulltext">
189         <pz:metadata type="fulltext">
190           <xsl:value-of select="." />
191         </pz:metadata>
192       </xsl:for-each>
193
194       <pz:metadata type="medium">
195         <xsl:value-of select="$vmedium" />
196 <!--
197         <xsl:if test="string-length($electronic) and $vmedium != 'electronic'">
198           <xsl:text> (electronic)</xsl:text>
199         </xsl:if>
200 -->
201       </pz:metadata>
202
203
204       <!-- passthrough id data -->
205       <xsl:for-each select="pz:metadata">
206         <xsl:copy-of select="." />
207       </xsl:for-each>
208
209       <!-- other stylesheets importing this might want to define this -->
210       <xsl:call-template name="record-hook" />
211         
212     </pz:record>
213
214   </xsl:template>
215
216   <xsl:template match="text()" />
217
218 </xsl:stylesheet>