Part of PAZ-996.
[pazpar2-moved-to-github.git] / etc / xsl / solr-pz2.xsl
1 <?xml version="1.0"?>
2 <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
3                 xmlns:pz="http://www.indexdata.com/pazpar2/1.0" >
4
5   <xsl:param name="medium" />
6
7   <xsl:template  match="/">
8       <xsl:apply-templates></xsl:apply-templates>
9   </xsl:template>
10
11   <xsl:template  match="response">
12       <xsl:apply-templates></xsl:apply-templates>
13   </xsl:template>
14
15   <xsl:template  match="records">
16       <xsl:apply-templates></xsl:apply-templates>
17   </xsl:template>
18
19   <xsl:template match="doc">
20     <pz:record>
21       <xsl:if test="string-length($medium) &gt; 0">
22         <pz:metadata type="medium">
23            <xsl:value-of select="$medium"/>
24         </pz:metadata>
25       </xsl:if>
26       <xsl:apply-templates></xsl:apply-templates>
27     </pz:record>
28   </xsl:template>
29
30   <xsl:template match="float[@name]">
31     <pz:metadata>
32         <xsl:attribute  name="type">
33           <xsl:value-of select="@name"/>
34         </xsl:attribute>
35         <xsl:value-of select="."/>
36     </pz:metadata>
37   </xsl:template>
38
39   <xsl:template match="str[@name]">
40     <pz:metadata>
41         <xsl:attribute  name="type">
42           <xsl:value-of select="@name"/>
43         </xsl:attribute>
44         <xsl:value-of select="."/>
45     </pz:metadata>
46   </xsl:template>
47
48   <xsl:template match="date[@name]">
49     <pz:metadata>
50         <xsl:attribute  name="type">
51           <xsl:value-of select="@name"/>
52         </xsl:attribute>
53         <xsl:value-of select="."/>
54     </pz:metadata>
55   </xsl:template>
56
57   <xsl:template match="arr">
58     <xsl:for-each select="str">
59       <xsl:call-template name="string"/>
60     </xsl:for-each>
61   </xsl:template>
62
63   <xsl:template name="string">
64     <xsl:choose>
65       <xsl:when test="../@name = 'medium' and string-length($medium) &gt; 0">
66       </xsl:when>
67       <xsl:otherwise>
68         <pz:metadata>
69           <xsl:attribute  name="type">
70             <xsl:value-of select="../@name"/>
71           </xsl:attribute>
72           <xsl:value-of select="."/>
73         </pz:metadata>
74         <xsl:if test="../@name='license_url'">
75          <pz:metadata type="license_name">
76           <xsl:choose>
77            <xsl:when test="starts-with(., 'http://creativecommons.org/licenses/by/')">
78             CC By
79            </xsl:when>
80            <xsl:when test="starts-with(., 'http://creativecommons.org/licenses/by-sa/')">
81             CC By-SA
82            </xsl:when>
83            <xsl:when test="starts-with(., 'http://creativecommons.org/licenses/by-nd/')">
84             CC By-ND
85            </xsl:when>
86            <xsl:when test="starts-with(., 'http://creativecommons.org/licenses/by-nc/')">
87             CC By-NC
88            </xsl:when>
89            <xsl:when test="starts-with(., 'http://creativecommons.org/licenses/by-nc-nd/')">
90             CC By-NC-ND
91            </xsl:when>
92            <!-- There is actually no such licence as this, but East London uses it anyway! -->
93            <xsl:when test="starts-with(., 'http://creativecommons.org/licenses/by-nd-sa/')">
94             CC By-ND-SA
95            </xsl:when>
96            <xsl:otherwise>
97             [unknown]
98            </xsl:otherwise>
99           </xsl:choose>
100          </pz:metadata>
101         </xsl:if>
102       </xsl:otherwise>
103     </xsl:choose>
104   </xsl:template>
105
106 </xsl:stylesheet>