Version 2.0.59
[idzebra-moved-to-github.git] / test / xslt / gpdctodc.xsl
1 <xsl:stylesheet
2   version="1.0"
3   xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
4   xmlns:pgterms="http://www.gutenberg.org/rdfterms/"
5   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
6   xmlns:dcterms="http://purl.org/dc/terms/"
7   xmlns:dc="http://purl.org/dc/elements/1.1/"
8   exclude-result-prefixes="pgterms rdf dcterms">
9
10   <xsl:output method="xml" indent="yes"/>
11
12   <!-- Record element -->
13   <xsl:template match="/pgterms:etext">
14     <srw_dc:dc
15         xmlns:srw_dc="info:srw/schema/1/dc-schema"
16         xmlns:dc="http://purl.org/dc/elements/1.1/"
17         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
18         xsi:schemaLocation="info:srw/schema/1/dc-schema
19         http://www.loc.gov/standards/sru/dc-schema.xsd">
20
21       <!-- Generate GP permalink -->
22       <dc:identifier>
23         <xsl:text>http://www.gutenberg.org/etext/</xsl:text>
24         <xsl:value-of select="substring(@rdf:ID, 6)"/>
25       </dc:identifier>
26
27       <xsl:apply-templates/>
28
29     </srw_dc:dc>
30   </xsl:template>
31
32   <!-- Ignore other elements by mapping into empty DOM XML trees -->
33   <xsl:template match="/*"/>
34
35   <!-- Any DC element (except special cases below -->
36   <xsl:template match="/pgterms:etext/*[namespace-uri() = 'http://purl.org/dc/elements/1.1/']">
37     <xsl:choose>
38       <xsl:when test="rdf:Bag">
39         <xsl:variable name="myname" select="name()"/>
40         <xsl:for-each select="rdf:Bag/*">
41           <xsl:call-template name="cond-display">
42             <xsl:with-param name="name" select="$myname"/>
43             <xsl:with-param name="value" select="."/>
44           </xsl:call-template>
45         </xsl:for-each>
46       </xsl:when>
47       <xsl:otherwise>
48         <xsl:call-template name="cond-display">
49           <xsl:with-param name="name" select="name()"/>
50           <xsl:with-param name="value" select="."/>
51         </xsl:call-template>
52       </xsl:otherwise>
53     </xsl:choose>
54   </xsl:template>
55
56   <!-- Display this element only if we know and like what kind of content it has -->
57   <xsl:template name="cond-display">
58     <xsl:param name="name"/>
59     <xsl:param name="value"/>
60
61     <xsl:choose>
62       <xsl:when test="$value/text()">
63         <xsl:element name="{$name}">
64           <xsl:value-of select="normalize-space($value)"/>
65         </xsl:element>
66       </xsl:when>
67       <xsl:otherwise>
68         <xsl:choose>
69           <xsl:when test="dcterms:LCSH or dcterms:W3CDTF or dcterms:ISO639-2">
70             <xsl:element name="{$name}">
71               <xsl:value-of select="normalize-space($value)"/>
72             </xsl:element>
73           </xsl:when>
74           <xsl:otherwise>
75             <unknown-type name="{$name}" type="{local-name($value/*)}">
76               <xsl:value-of select="normalize-space($value)"/>
77             </unknown-type>
78           </xsl:otherwise>
79         </xsl:choose>
80       </xsl:otherwise>
81     </xsl:choose>
82   </xsl:template>
83
84   <xsl:template match="//dc:rights">
85     <dc:rights>
86       <xsl:value-of select="@rdf:resource"/>
87     </dc:rights>
88   </xsl:template>
89
90   <!-- This is hardly a DC element -->
91   <xsl:template match="//dc:tableOfContents">
92     <tableOfContents>
93       <xsl:value-of select="."/>
94     </tableOfContents>
95   </xsl:template>
96
97   <xsl:template match="text()"/>
98
99 </xsl:stylesheet>
100