First attempt to parse primo to pz2
[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:control"> 
50     <xsl:if test="@prim:recordid">
51       <pz:metadata type="id">
52         <xsl:value-of select="@prim:recordid"/>
53       </pz:metadata>
54     </xsl:if>
55     <xsl:apply-templates />
56   </xsl:template>
57
58   <xsl:template match="prim:addata">
59     <!--    <xsl:variable name="yearmonthday" select="@date" /> -->
60
61     <xsl:if test="@prim:date">
62       <pz:metadata type="date">
63         <xsl:value-of select="substring(@date,1,4)" />
64       </pz:metadata>
65       <pz:metadata type="journal-month">
66         <xsl:value-of select="substring(@date,4,1)" />
67       </pz:metadata>
68     </xsl:if>
69
70     <xsl:if test="@prim:volume">
71       <pz:metadata type="journal-number">
72         <xsl:value-of select="@prim:volume" />
73       </pz:metadata>
74     </xsl:if>
75
76     <xsl:if test="@prim:issue">
77       <pz:metadata type="issue-number">
78         <xsl:value-of select="@prim:issue" />
79       </pz:metadata>
80     </xsl:if>
81
82     <xsl:if test="@prim:issn">
83       <pz:metadata type="issn">
84         <xsl:value-of select="@prim:issn" />
85       </pz:metadata>
86     </xsl:if>
87
88     <xsl:if test="@prim:jtitle">
89       <pz:metadata type="journal-title">
90         <xsl:value-of select="@prim:jtitle" />
91       </pz:metadata>
92     </xsl:if>
93     
94     <xsl:apply-templates />
95   </xsl:template>
96
97   <xsl:template match="prim:delivery">  
98     <xsl:if test="$has_fulltext">
99       <pz:metadata type="has-fulltext">
100         <xsl:value-of select="$has_fulltext" />
101       </pz:metadata>
102     </xsl:if>
103
104     <xsl:apply-templates />
105   </xsl:template>
106
107   <xsl:template match="prim:display" name="display" >
108     <xsl:if test="@prim:creator">
109       <pz:metadata type="author">
110         <xsl:value-of select="@prim:creator" />
111       </pz:metadata>
112     </xsl:if>  
113
114
115     <xsl:if test="@prim:type">
116       <xsl:variable name="type" select="@prim:type"/>
117       <pz:metadata type="medium">
118         <xsl:choose>
119           <xsl:when test="$type ='article' and $has_fulltext = 'yes'">
120             <xsl:text>e-article</xsl:text>
121           </xsl:when>
122           <xsl:when  test="$type = 'article' and $has_fulltext = 'no'">
123             <xsl:text>article</xsl:text>
124           </xsl:when>
125           <xsl:otherwise>
126             <xsl:value-of select="$type"/>
127           </xsl:otherwise>
128         </xsl:choose>
129 <!--        <xsl:value-of select="$type" /> -->
130       </pz:metadata>
131       <pz:metadata type="debug_isarticle"><xsl:value-of select="$is_article"/></pz:metadata>
132     </xsl:if>  
133
134
135     <xsl:if test="@prim:title">
136       <pz:metadata type="title">
137         <xsl:value-of select="@prim:title" />
138       </pz:metadata>
139     </xsl:if>  
140
141     <xsl:if test="@prim:ispartof">
142       <pz:metadata type="journal-subpart">
143         <xsl:value-of select="@prim:ispartof" />
144       </pz:metadata>
145     </xsl:if>
146     <xsl:apply-templates />
147   </xsl:template>
148
149   <xsl:template match="sear:LINKS" >
150     <xsl:if test="@sear:openurl"> 
151       <pz:metadata type="electronic-url">
152         <xsl:value-of select="@sear:openurl"/>
153       </pz:metadata>
154     </xsl:if>
155     <xsl:apply-templates/>
156   </xsl:template>
157
158   <xsl:template match="prim:search">
159     <xsl:if test="@prim:description">
160       <pz:metadata type="description">
161         <xsl:value-of select="@prim:description" />
162       </pz:metadata>
163     </xsl:if>
164
165
166     <xsl:if test="@prim:sub">
167       <pz:metadata type="subject">
168         <xsl:value-of select="@prim:sub" />
169       </pz:metadata>
170     </xsl:if>
171
172     <!-- passthrough id data -->
173     <xsl:for-each select="pz:metadata">
174       <xsl:copy-of select="." />
175     </xsl:for-each>
176     <!-- other stylesheets importing this might want to define this -->
177
178     <xsl:call-template name="record-hook" />
179         
180   </xsl:template>
181
182   <xsl:template match="text()" />
183
184 </xsl:stylesheet>