Last 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            <!-- Creative Commons licenses -->
78            <xsl:when test="starts-with(., 'http://creativecommons.org/licenses/by/')">
79             CC By
80            </xsl:when>
81            <xsl:when test="starts-with(., 'http://creativecommons.org/licenses/by-sa/')">
82             CC By-SA
83            </xsl:when>
84            <xsl:when test="starts-with(., 'http://creativecommons.org/licenses/by-nd/')">
85             CC By-ND
86            </xsl:when>
87            <xsl:when test="starts-with(., 'http://creativecommons.org/licenses/by-nc/')">
88             CC By-NC
89            </xsl:when>
90            <xsl:when test="starts-with(., 'http://creativecommons.org/licenses/by-nc-sa/')">
91             CC By-NC-SA
92            </xsl:when>
93            <xsl:when test="starts-with(., 'http://creativecommons.org/licenses/by-nc-nd/')">
94             CC By-NC-ND
95            </xsl:when>
96
97            <!-- There is actually no such license as this, but East London uses it anyway! -->
98            <xsl:when test="starts-with(., 'http://creativecommons.org/licenses/by-nd-sa/')">
99             CC By-ND-SA
100            </xsl:when>
101
102            <!-- Creative Commons' public-domain tools are not actually licences, may well be used -->
103            <xsl:when test=". = 'http://creativecommons.org/about/cc0'">
104             CC0 (public domain)
105            </xsl:when>
106            <xsl:when test=". = 'http://creativecommons.org/about/pdm2'">
107             CC PDL (public domain)
108            </xsl:when>
109  
110            <!-- The RIOXX profile itself provides two ways of saying "all rights reserved" -->
111            <xsl:when test=". = 'http://www.rioxx.net/licenses/all-rights-reserved'">
112             All rights reserved
113            </xsl:when>
114            <xsl:when test=". = 'http://www.rioxx.net/licenses/under-embargo-all-rights-reserved'">
115             Under embargo
116            </xsl:when>
117
118            <xsl:otherwise>
119             [unknown]
120            </xsl:otherwise>
121           </xsl:choose>
122          </pz:metadata>
123         </xsl:if>
124       </xsl:otherwise>
125     </xsl:choose>
126   </xsl:template>
127
128 </xsl:stylesheet>