Change to handle current primo simpleserver format
[pazpar2-moved-to-github.git] / etc / primo-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:tmarc="http://www.indexdata.com/turbomarc"
6   xmlns:prim="http://www.exlibrisgroup.com/xsd/primo/primo_nm_bib" 
7   xmlns:sear="http://www.exlibrisgroup.com/xsd/jaguar/search"
8
9 >
10
11   <xsl:output indent="yes" method="xml" version="1.0"
12     encoding="UTF-8" />
13
14   <xsl:variable name="type" select="/opt/prim:PrimoNMBib/prim:display/@prim:type"/>
15   <xsl:variable name="is_article" select="$type = 'article'" />
16   <xsl:variable name="fulltext" select="/opt/prim:PrimoNMBib/prim:delivery/@prim:fulltext"/>
17   <xsl:variable name="has_fulltext">
18     <xsl:choose>
19       <xsl:when test="$fulltext = 'no_fulltext' ">
20         <xsl:text>no</xsl:text>
21       </xsl:when>
22       <xsl:when test="$fulltext = 'fulltext'">
23         <xsl:text>yes</xsl:text>
24       </xsl:when>
25       <xsl:otherwise>
26         <xsl:text>no</xsl:text>
27       </xsl:otherwise>
28     </xsl:choose>
29   </xsl:variable>
30
31     
32
33   <xsl:template name="record-hook" />
34
35   <xsl:template match="/">
36     <xsl:apply-templates />
37   </xsl:template>
38
39   <xsl:template match="opt">
40     <pz:record>
41       <xsl:apply-templates />
42     </pz:record>
43   </xsl:template>
44
45   <xsl:template match="prim:PrimoNMBib">
46     <xsl:apply-templates />
47   </xsl:template>
48   
49   <xsl:template match="prim:record[@name='control']"> 
50     <xsl:if test="@recordid">
51       <pz:metadata type="id">
52         <xsl:value-of select="@recordid"/>
53       </pz:metadata>
54     </xsl:if>
55     <xsl:apply-templates />
56   </xsl:template>
57
58   <xsl:template match="prim:record[@name='addata']">
59     <xsl:if test="@date">
60       <pz:metadata type="date">
61         <xsl:value-of select="substring(@date,1,4)" />
62       </pz:metadata>
63       <pz:metadata type="fulldate">
64         <xsl:value-of select="@date" />
65       </pz:metadata>
66       <pz:metadata type="journal-month">
67         <xsl:value-of select="substring(@date,5,2)" />
68       </pz:metadata>
69     </xsl:if>
70
71     <xsl:if test="@volume">
72       <pz:metadata type="journal-number">
73         <xsl:value-of select="@volume" />
74       </pz:metadata>
75     </xsl:if>
76
77     <xsl:if test="@issue">
78       <pz:metadata type="issue-number">
79         <xsl:value-of select="@issue" />
80       </pz:metadata>
81     </xsl:if>
82
83     <xsl:if test="@issn">
84       <pz:metadata type="issn">
85         <xsl:value-of select="@issn" />
86       </pz:metadata>
87     </xsl:if>
88
89     <xsl:if test="@jtitle">
90       <pz:metadata type="journal-title">
91         <xsl:value-of select="@jtitle" />
92       </pz:metadata>
93     </xsl:if>
94     
95     <xsl:apply-templates />
96   </xsl:template>
97
98   <xsl:template match="prim:record[@name='delivery']">  
99     <xsl:if test="$has_fulltext">
100       <pz:metadata type="has-fulltext">
101         <xsl:value-of select="$has_fulltext" />
102       </pz:metadata>
103     </xsl:if>
104
105     <xsl:apply-templates />
106   </xsl:template>
107
108   <xsl:template match="prim:record[@tag='display']">
109
110     <xsl:if test="@creator">
111       <pz:metadata type="author">
112         <xsl:value-of select="@creator" />
113       </pz:metadata>
114     </xsl:if>  
115
116     <xsl:if test="@type">
117       <xsl:variable name="type" select="@type"/>
118       <pz:metadata type="medium">
119         <xsl:choose>
120           <xsl:when test="$type ='article' and $has_fulltext = 'yes'">
121             <xsl:text>e-article</xsl:text>
122           </xsl:when>
123           <xsl:when  test="$type = 'article' and $has_fulltext = 'no'">
124             <xsl:text>article</xsl:text>
125           </xsl:when>
126           <xsl:otherwise>
127             <xsl:value-of select="$type"/>
128           </xsl:otherwise>
129         </xsl:choose>
130 <!--        <xsl:value-of select="$type" /> -->
131       </pz:metadata>
132       <pz:metadata type="debug_isarticle"><xsl:value-of select="$is_article"/></pz:metadata>
133     </xsl:if>  
134
135     <xsl:if test="@title">
136       <pz:metadata type="title">
137         <xsl:value-of select="@title" />
138       </pz:metadata>
139     </xsl:if>  
140
141     <xsl:if test="@ispartof">
142       <pz:metadata type="journal-subpart">
143         <xsl:value-of select="@ispartof" />
144       </pz:metadata>
145     </xsl:if>
146     <xsl:apply-templates />
147
148   </xsl:template>
149
150   <xsl:template match="prim:record[@name='search']">
151     <xsl:if test="@description">
152       <pz:metadata type="description">
153         <xsl:value-of select="@description" />
154       </pz:metadata>
155     </xsl:if>
156
157     <xsl:if test="@sub">
158       <pz:metadata type="subject">
159         <xsl:value-of select="@sub" />
160       </pz:metadata>
161     </xsl:if>
162
163     <!-- passthrough id data -->
164     <xsl:for-each select="pz:metadata">
165       <xsl:copy-of select="." />
166     </xsl:for-each>
167     <!-- other stylesheets importing this might want to define this -->
168
169     <xsl:call-template name="record-hook" />
170         
171   </xsl:template>
172
173   <xsl:template match="sear:LINKS" >
174     <xsl:if test="@sear:openurl"> 
175       <pz:metadata type="electronic-url">
176         <xsl:value-of select="@sear:openurl"/>
177       </pz:metadata>
178     </xsl:if>
179     <xsl:apply-templates/>
180   </xsl:template>
181
182
183   <xsl:template match="text()" />
184
185 </xsl:stylesheet>