summaryrefslogtreecommitdiffstats
path: root/xslt/isbndb2tellico.xsl
blob: c4152f608e68e81f1bac31c6bedcb7563004afe9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns="http://periapsis.org/tellico/"
                xmlns:str="http://exslt.org/strings"
                xmlns:exsl="http://exslt.org/common"
                xmlns:l="uri:langs"
                extension-element-prefixes="str exsl"
                exclude-result-prefixes="l"
                version="1.0">

<!--
   ===================================================================
   Tellico XSLT file - used for importing data from isbndb.com

   Copyright (C) 2006 Robby Stephenson - [email protected]

   This XSLT stylesheet is designed to be used with the 'Tellico'
   application, which can be found at http://www.periapsis.org/tellico/

   ===================================================================
-->

<l:langs>
 <l:lang id="ara">Arabic</l:lang>
 <l:lang id="cat">Catalan</l:lang>
 <l:lang id="cze">Czech</l:lang>
 <l:lang id="dut">Dutch</l:lang>
 <l:lang id="eng">English</l:lang>
 <l:lang id="fre">French</l:lang>
 <l:lang id="ger">German</l:lang>
 <l:lang id="dut">Dutch</l:lang>
 <l:lang id="heb">Hebrew</l:lang>
 <l:lang id="gre">Greek</l:lang>
 <l:lang id="hin">Hindi</l:lang>
 <l:lang id="hun">Hungarian</l:lang>
 <l:lang id="ita">Italian</l:lang>
 <l:lang id="jpn">Japanese</l:lang>
 <l:lang id="kor">Korean</l:lang>
 <l:lang id="lat">Latin</l:lang>
 <l:lang id="lit">Lithuanian</l:lang>
 <l:lang id="nob">Norwegian Bokm&#229;l</l:lang>
 <l:lang id="nor">Norwegian</l:lang>
 <l:lang id="nno">Norwegian Nynorsk</l:lang>
 <l:lang id="pol">Polish</l:lang>
 <l:lang id="por">Portuguese</l:lang>
 <l:lang id="rus">Russian</l:lang>
 <l:lang id="slo">Slovak</l:lang>
 <l:lang id="spa">Spanish</l:lang>
 <l:lang id="swe">Swedish</l:lang>
 <l:lang id="chi">Chinese</l:lang>
</l:langs>
<xsl:key name="langs" match="l:lang" use="@id"/>
<xsl:variable name="langs-top" select="document('')/*/l:langs"/>

<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"
            doctype-public="-//Robby Stephenson/DTD Tellico V10.0//EN"
            doctype-system="http://periapsis.org/tellico/dtd/v10/tellico.dtd"/>

<xsl:template match="/">
 <tellico syntaxVersion="10">
  <collection title="ISBNdb.com Import" type="2">
   <fields>
    <field name="_default"/>
    <!-- Here so that we can retrive the real publisher name later, gets removed inside Tellico -->
    <field name="pub_id" flags="0" title="Publisher Key" category="Publishing" format="0" type="1"/>
   </fields>
   <xsl:apply-templates select="ISBNdb/BookList/BookData"/>
  </collection>
 </tellico>
</xsl:template>

<xsl:template match="BookData">
 <entry>

  <title>
   <xsl:value-of select="Title"/>
  </title>

  <isbn>
   <xsl:value-of select="@isbn"/>
  </isbn>

  <pub_id>
   <xsl:value-of select="PublisherText/@publisher_id"/>
  </pub_id>

  <publisher>
   <xsl:value-of select="PublisherText"/>
  </publisher>

  <authors>
   <xsl:for-each select="Authors/Person">
    <author>
     <xsl:value-of select="."/>
    </author>
   </xsl:for-each>
  </authors>

  <keywords>
   <xsl:for-each select="Subjects/Subject">
    <xsl:variable name="subject-tokens1">
     <xsl:call-template name="split-string">
      <xsl:with-param name="string" select="."/>
      <xsl:with-param name="pattern" select="' -- '"/>
     </xsl:call-template>
    </xsl:variable>
    <xsl:variable name="subject-tokens2">
     <xsl:call-template name="token-union">
      <xsl:with-param name="tokens" select="exsl:node-set($subject-tokens1)/*"/>
     </xsl:call-template>
    </xsl:variable>
    <xsl:for-each select="exsl:node-set($subject-tokens2)/*">
     <keyword>
      <xsl:value-of select="normalize-space()"/>
     </keyword>
    </xsl:for-each>
   </xsl:for-each>
  </keywords>

  <comments>
   <xsl:value-of select="Details/@physical_description_text"/>
   <xsl:text>&lt;br/&gt;&lt;br/&gt;</xsl:text>
   <xsl:value-of select="Summary"/>
   <xsl:if test="string-length(Summary) &gt; 0 and string-length(Notes) &gt; 0">
    <xsl:text>&lt;br/&gt;&lt;br/&gt;</xsl:text>
   </xsl:if>
   <xsl:value-of select="Notes"/>
  </comments>

  <xsl:variable name="binding">
   <xsl:value-of select="substring-before(Details/@edition_info, ';')"/>
  </xsl:variable>
  <binding i18n="true">
   <xsl:choose>
    <xsl:when test="$binding='Hardcover'">
     <xsl:text>Hardback</xsl:text>
    </xsl:when>
    <xsl:when test="contains($binding, 'Paperback')">
     <xsl:text>Paperback</xsl:text>
    </xsl:when>
    <xsl:otherwise>
     <xsl:value-of select="$binding"/>
    </xsl:otherwise>
   </xsl:choose>
  </binding>

  <languages i18n="true">
   <language>
    <xsl:apply-templates select="$langs-top">
     <xsl:with-param name="lang-id" select="Details/@language"/>
    </xsl:apply-templates>
   </language>
  </languages>

 </entry>
</xsl:template>

<xsl:template name="split-string">
 <xsl:param name="string"/>
 <xsl:param name="pattern"/>
  <xsl:choose>
   <xsl:when test="contains($string, $pattern)">
    <xsl:if test="not(starts-with($string, $pattern))">
     <token>
      <xsl:value-of select="substring-before($string, $pattern)"/>
     </token>
    </xsl:if>
    <xsl:call-template name="split-string">
     <xsl:with-param name="string" select="substring-after($string, $pattern)"/>
     <xsl:with-param name="pattern" select="$pattern"/>
    </xsl:call-template>
   </xsl:when>
   <xsl:otherwise>
    <token>
     <xsl:value-of select="$string"/>
    </token>
   </xsl:otherwise>
  </xsl:choose>
</xsl:template>

<xsl:template name="token-union">
 <xsl:param name="tokens"/>
 <xsl:choose>
  <xsl:when test="not($tokens)"/>
  <xsl:otherwise>
   <xsl:copy-of select="exsl:node-set(str:tokenize($tokens[1], ','))"/>
   <xsl:call-template name="token-union">
    <xsl:with-param name="tokens" select="$tokens[position() &gt; 1]"/>
   </xsl:call-template>
  </xsl:otherwise>
 </xsl:choose>
</xsl:template>

<xsl:template match="l:langs">
 <xsl:param name="lang-id"/>
 <xsl:variable name="l" select="key('langs', $lang-id)"/>
 <xsl:if test="$l">
  <xsl:value-of select="$l"/>
 </xsl:if>
 <xsl:if test="not($l)">
  <xsl:value-of select="$lang-id"/>
 </xsl:if>
</xsl:template>

</xsl:stylesheet>