blob: 6f9529aa4f21afdb8a96f1c360d2998c8e76e085 [file] [log] [blame]
Marc Kupietz1a422662024-03-16 09:34:10 +01001<xsl:stylesheet version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
2 xmlns:xs="http://www.w3.org/2001/XMLSchema"
3 xmlns:opf="http://www.idpf.org/2007/opf"
4 xmlns:dc="http://purl.org/dc/elements/1.1/"
5 xmlns:ids="http://www.ids-mannheim.de/ids"
6 xmlns:hlu="http://www.ids-mannheim.de/hlu"
7 xmlns:saxon="http://saxon.sf.net/"
8 xmlns:xhtml="http://www.w3.org/1999/xhtml"
9 exclude-result-prefixes="xs opf dc ids hlu saxon xhtml">
10
11 <xsl:output method="xml" indent="yes" omit-xml-declaration="yes" saxon:line-length="1000"/>
12 <xsl:strip-space elements="*"/>
13
14 <xsl:variable name="ev"/>
15 <xsl:variable name="x"/>
16
17 <xsl:variable name="isbn" as="xs:string" select="replace(document-uri(), '.*([0-9]{13,}).*' , '$1')"/>
18
19
20 <xsl:variable name="dnbBookdata">
21 <xsl:copy-of select="doc(concat('https://services.dnb.de/sru/dnb?version=1.1&amp;operation=searchRetrieve&amp;query=NUM%3D', $isbn, '&amp;recordSchema=oai_dc'))"/>
22 </xsl:variable>
23
24 <xsl:variable name="autor"
25 select="string-join(replace($dnbBookdata//dc:creator, ' *\[[^\]]*\]', ''), ' ; ')"/>
26
Marc Kupietzb660ed62024-03-16 11:45:53 +010027 <xsl:variable name="straight_autor" select="normalize-space(replace(hlu:reversedAuthors($autor), ',', ''))"/>
Marc Kupietz1a422662024-03-16 09:34:10 +010028
29 <xsl:variable name="ina"/>
30 <xsl:variable name="_corpus"/>
31 <xsl:variable name="ent_known"/>
32
33
34 <!-- added HLU 2012-02-09: -->
35 <xsl:variable name="ent">
36 <xsl:choose>
37 <xsl:when test="$ent_known">
38 <xsl:value-of select="$ent_known"/>
39 </xsl:when>
40 <xsl:when test="$ev">
41 <xsl:value-of select="$ev"/>
42 </xsl:when>
43 <xsl:otherwise>
44 <xsl:value-of select="$j"/>
45 </xsl:otherwise>
46 </xsl:choose>
47 </xsl:variable>
48
49 <xsl:variable name="titel">
50 <xsl:choose>
51 <xsl:when test="contains($dnbBookdata//dc:title,':')">
52 <xsl:value-of select="normalize-space(substring-before(substring-before($dnbBookdata//dc:title, '/'), ':'))"
53 />
54 </xsl:when>
55 <xsl:otherwise>
56 <xsl:value-of select="normalize-space(substring-before($dnbBookdata//dc:title, '/'))"/>
57 </xsl:otherwise>
58 </xsl:choose>
59 </xsl:variable>
60
61 <xsl:variable name="erscheinungsort">
62 <xsl:choose>
63 <xsl:when test="contains($dnbBookdata//dc:publisher,':')">
64 <xsl:value-of select="normalize-space(substring-before($dnbBookdata//dc:publisher, ':'))"/>
65 </xsl:when>
66 <xsl:otherwise>
67 <xsl:value-of select="normalize-space($dnbBookdata//dc:publisher)"/>
68 </xsl:otherwise>
69 </xsl:choose>
70 </xsl:variable>
71
72 <xsl:variable name="verlag">
73 <xsl:choose>
74 <xsl:when test="contains($dnbBookdata//dc:publisher,':')">
75 <xsl:value-of select="normalize-space(substring-after($dnbBookdata//dc:publisher, ':'))"/>
76 </xsl:when>
77 <xsl:otherwise>
78 <xsl:value-of select="normalize-space($dnbBookdata//dc:publisher)"/>
79 </xsl:otherwise>
80 </xsl:choose>
81 </xsl:variable>
82
83 <xsl:variable name="erscheinungsjahr">
84 <xsl:choose>
85 <xsl:when test="matches($dnbBookdata//dc:date, '^[0-9]{4}$')">
86 <xsl:value-of select="$dnbBookdata//dc:date"/>
87 </xsl:when>
88 <xsl:otherwise>
89 <xsl:value-of select="substring-before($dnbBookdata//dc:date, '-')"/>
90 </xsl:otherwise>
91 </xsl:choose>
92 </xsl:variable>
93
94 <xsl:variable name="untertitel"
95 select="normalize-space(substring-after(substring-before($dnbBookdata//dc:title, '/'), ':'))"/>
96
97 <xsl:variable name="herausgeber">
98 <xsl:choose>
99 <xsl:when test="$dnbBookdata//dc:creator[ends-with(.,'[Hrsg.]')]">
100 <xsl:value-of
101 select="replace(string-join($dnbBookdata//dc:creator[ends-with(.,'[Hrsg.]')], ' ; '),'\s?\[Hrsg.\]','')"
102 />
103 </xsl:when>
104 <xsl:otherwise>.</xsl:otherwise>
105 </xsl:choose>
106 </xsl:variable>
107
108 <xsl:variable name="straight_herausgeber"
109 select="replace(hlu:reversedAuthors($herausgeber), ',', '')"/>
110
111 <xsl:variable name="j" select="$dnbBookdata//dc:date"/>
112
113 <!-- for BOT+s: -->
114 <xsl:variable name="seiten" select="replace($dnbBookdata//dc:format,'S\.','')"/>
115
116 <!-- fuer BOT+b: -->
117 <xsl:variable name="_b">
118 <xsl:variable name="regexp1" select="'(Band|Bd\.)\s*([0-9]?[0-9]?[0-9])'"/>
119 <xsl:choose>
120 <xsl:when test="matches($dnbBookdata, $regexp1)">
121 <xsl:analyze-string select="$dnbBookdata//dc:title" regex="{$regexp1}">
122 <xsl:matching-substring>
123 <xsl:value-of select="."/>
124 </xsl:matching-substring>
125 </xsl:analyze-string>
126 </xsl:when>
127 <xsl:otherwise>
128 <xsl:value-of select="'.'"/>
129 </xsl:otherwise>
130 </xsl:choose>
131 </xsl:variable>
132
133 <!-- for BOT+x: -->
134 <xsl:variable name="txtart">
135 <xsl:choose>
136 <xsl:when test="$x">
137 <xsl:value-of select="concat('[', $x, ']')"/>
138 </xsl:when>
139 <xsl:when
140 test="matches($untertitel, '([Rr]oman|[Ee]rzhlung(en)?|[Aa]nthologie|[Gg]eschichte(n)?|[Nn]ovelle)')">
141 <xsl:value-of
142 select="concat('[', replace(replace($untertitel, '.*?(((^|\P{L})\p{L}+)?([Rr]oman|[Ee]rzhlung(en)?|[Aa]nthologie|[Gg]eschichte(n)?|[Nn]ovelle)).*', '$1'), '\P{L}*(.+)', '$1'), ']')"
143 />
144 </xsl:when>
145 <xsl:otherwise>
146 <xsl:value-of>Roman</xsl:value-of>
147 </xsl:otherwise>
148 </xsl:choose>
149 </xsl:variable>
150
151
152
153 <!-- fuer BOTd: -->
154 <xsl:variable name="dok"
155 select="concat((if(string-length($autor) &gt; 0) then concat($straight_autor, ': ') else ''), $titel, ', ', $txtart, ', (', $j, ')')"/>
156
157 <!-- END variables derived from sru request to dnb archive -->
158
159
160 <xsl:variable name="corpus_sigle" select="'DNB'"/>
161
162 <!-- for BOTD: -->
163 <!-- Dokumentsigle muss zusammen mit Korpussigle (z.B DIV fuer loz-div und loz-div-pub) eindeutig sein -->
164 <xsl:variable name="doc_sigle">
165 <xsl:variable name="firstContentWordTitleInitial">
166 <xsl:variable name="helper">
167 <xsl:analyze-string select="$titel" regex="\w+">
168 <xsl:matching-substring>
169 <xsl:choose>
170 <xsl:when
171 test="matches(.,'^[A-Z]') and not(matches(.,'^(Der|Die|Das|Des|Ein|Eine|Eines|Einmal|Von|Mit|Zu|Zurck)$'))">
172 <!-- TODO: Fktnswoerter nachtragen -->
173 <xsl:sequence select="."/>
174 </xsl:when>
175 <xsl:otherwise/>
176 </xsl:choose>
177 </xsl:matching-substring>
178 </xsl:analyze-string>
179 </xsl:variable>
180 <xsl:value-of
181 select="upper-case(substring(normalize-space(replace($helper,'\s+.+$','')),1,1))"/>
182 <!-- longest match of .+ -->
183 </xsl:variable>
184 <xsl:choose>
185 <xsl:when test="contains($autor,';')">
186 <xsl:variable name="lastname_aut1"
187 select="upper-case(substring(normalize-space(substring-before(substring-before($autor,';'),',')), 1, 1))"/>
188 <xsl:variable name="lastname_aut2"
189 select="upper-case(substring(normalize-space(substring-before(substring-before(substring-after($autor, ';'),';'),',')), 1, 1))"/>
190 <xsl:value-of select="concat($lastname_aut1, $lastname_aut2)"/>
191 </xsl:when>
192 <xsl:otherwise>
193 <xsl:variable name="lastname_aut1"
194 select="upper-case(substring(normalize-space(substring-before($autor,',')),1,1))"/>
195 <xsl:variable name="firstname_aut1"
196 select="upper-case(substring(normalize-space(substring-after($autor,',')),1,1))"/>
197 <xsl:value-of select="concat($lastname_aut1, $firstname_aut1)"/>
198 </xsl:otherwise>
199 </xsl:choose>
200 <xsl:value-of select="$firstContentWordTitleInitial"/>
201 </xsl:variable>
202
203
204 <xsl:variable name="text_sigle" select="substring($isbn, 8, 5)"/>
205 <xsl:variable name="sigle" select="concat($corpus_sigle, '/', $doc_sigle, '.', $text_sigle)"/>
206
207 <!-- fuer BOT+xy: (?) -->
208 <xsl:variable name="xyref">
209 <xsl:value-of select="document-uri(.)"/>
210 <xsl:text>; </xsl:text>
211 <xsl:text>ISBN:</xsl:text>
212 <xsl:value-of select="$isbn"/>
213 <xsl:text>; </xsl:text>
214 <xsl:value-of select="string-join($dnbBookdata//dc:identifier)"/>
215 </xsl:variable>
216
Marc Kupietzb660ed62024-03-16 11:45:53 +0100217 <xsl:variable name="long-reference"
218 select="concat($sigle, ' ', $autor, ': ', $titel, '. ', $erscheinungsort, ': ', $verlag, ', ', $erscheinungsjahr)"/>
219
220 <xsl:variable name="short-reference"
221 select="concat($straight_autor, ': ', $titel, ' (', $erscheinungsjahr, ')')"/>
Marc Kupietz1a422662024-03-16 09:34:10 +0100222
223 <xsl:template match="/">
224 <idsDoc TEIform="TEI.2" type="text" version="1.0">
225 <idsHeader TEIform="teiHeader" pattern="text" status="new" type="document" version="1.1">
226 <fileDesc>
227 <titleStmt>
Marc Kupietzb660ed62024-03-16 11:45:53 +0100228 <dokumentSigle><xsl:value-of select="string-join(($corpus_sigle, $doc_sigle), '/')"/></dokumentSigle>
229 <d.title><xsl:value-of select="$short-reference"/></d.title>
Marc Kupietz1a422662024-03-16 09:34:10 +0100230 </titleStmt>
231 <publicationStmt>
232 <distributor/>
233 <pubAddress/>
234 <availability region="world" status="unknown">QAO-NC</availability>
235 <pubDate/>
236 </publicationStmt>
237 <sourceDesc>
238 <biblStruct>
239 <monogr>
240 <h.title type="main"/>
241 <imprint/>
242 </monogr>
243 </biblStruct>
244 </sourceDesc>
245 </fileDesc>
246 </idsHeader>
247 <idsText version="1.0">
248 <idsHeader TEIform="teiHeader" pattern="text" status="new" type="text" version="1.1">
249 <fileDesc>
250 <titleStmt>
251 <textSigle><xsl:sequence select="$sigle"/></textSigle>
Marc Kupietzb660ed62024-03-16 11:45:53 +0100252 <t.title assemblage="regular"><xsl:value-of select="$long-reference"/></t.title>
Marc Kupietz1a422662024-03-16 09:34:10 +0100253 </titleStmt>
254 <publicationStmt>
255 <distributor/>
256 <pubAddress/>
257 <availability region="world" status="unknown">QAO-NC</availability>
258 <pubDate/>
259 </publicationStmt>
260 <sourceDesc>
261 <biblStruct>
262 <monogr>
263 <h.title type="main"><xsl:value-of select="$titel"/></h.title>
264 <h.title type="sub"><xsl:value-of select="$untertitel"/></h.title>
265 <h.author><xsl:value-of select="$autor"/></h.author>
266 <editor/>
267 <edition>
268 <further/>
269 <kind>E-Book-Ausgabe</kind>
270 <appearance>EPUB-Datei</appearance>
271 </edition>
272 <imprint>
Marc Kupietzb660ed62024-03-16 11:45:53 +0100273 <publisher><xsl:value-of select="$verlag"/></publisher>
Marc Kupietz1a422662024-03-16 09:34:10 +0100274 <pubDate type="year"><xsl:value-of select="$j"/></pubDate>
275 <pubDate type="month"/>
276 <pubDate type="day"/>
277 <pubPlace key="DE"><xsl:value-of select="$erscheinungsort"/></pubPlace>
278 </imprint>
279 <biblScope type="subsume"/>
280 <biblScope type="pp"/>
281 <biblScope type="vol"/>
282 <biblScope type="volume-title"/>
283 </monogr>
284 </biblStruct>
285 <reference assemblage="regular" type="complete"><xsl:value-of select="concat($sigle, ' ', $autor, ': ', $titel, '. ', $erscheinungsort, ': ', $verlag, ', ', $erscheinungsjahr)"/></reference>
Marc Kupietz1a422662024-03-16 09:34:10 +0100286 </sourceDesc>
287 </fileDesc>
288 <profileDesc>
289 <creation>
290 <creatDate><xsl:value-of select="$j"/></creatDate>
291 </creation>
292 <textClass/>
293 <textDesc>
294 <textType>Jugendliteratur</textType>
295 <textTypeRef>Jugendliteratur</textTypeRef>
296 <textDomain/>
297 </textDesc>
298 </profileDesc>
299 </idsHeader>
300 <text>
301 <body>
302 <!-- Call the template for each link in the TOC
303 <xsl:apply-templates select="//xhtml:ol[@class='toc']/xhtml:li/xhtml:a" mode="collect"/> -->
304 <xsl:apply-templates select="//opf:package/opf:manifest/opf:item[matches(@href, '\.x?html$') and not(matches(@href, '(cover|toc|copyright|feedback).*'))]" mode="collect"/>
305 </body>
306 </text>
307 </idsText>
308 </idsDoc>
309 </xsl:template>
310
311 <xsl:template match="opf:item" mode="collect">
312 <xsl:variable name="href" select="@href"/>
313 <xsl:message>
314 <xsl:text>converting: </xsl:text><xsl:value-of select="$href"/><xsl:text> </xsl:text><xsl:value-of select="$isbn"/>
315 </xsl:message>
316 <xsl:apply-templates select="doc(resolve-uri($href, base-uri()))/xhtml:html/xhtml:body"/>
317 </xsl:template>
318
319 <xsl:template match="xhtml:body">
320 <div type="chapter">
321 <xsl:apply-templates/>
322 </div>
323 </xsl:template>
324
325 <xsl:template match="xhtml:title">
326 <head>
327 <xsl:apply-templates/>
328 </head>
329 </xsl:template>
330
331 <xsl:template match="xhtml:h1">
332 <head>
333 <xsl:apply-templates/>
334 </head>
335 </xsl:template>
336
337 <xsl:template match="xhtml:h2|xhtml:h3">
338 <head type="sub">
339 <xsl:apply-templates/>
340 </head>
341 </xsl:template>
342
Marc Kupietz99ec04b2024-03-16 11:30:03 +0100343 <xsl:template match="xhtml:em">
344 <emph>
345 <xsl:apply-templates/>
346 </emph>
347 </xsl:template>
Marc Kupietz1a422662024-03-16 09:34:10 +0100348
Marc Kupietz99ec04b2024-03-16 11:30:03 +0100349 <xsl:template match="xhtml:span[matches(@class, '(bold|italic|big| )+')]">
350 <hi rend="{@class}">
Marc Kupietz1a422662024-03-16 09:34:10 +0100351 <xsl:apply-templates/>
352 </hi>
353 </xsl:template>
354
Marc Kupietz99ec04b2024-03-16 11:30:03 +0100355 <xsl:template match="xhtml:sub|xhtml:span[@class='sub']">
Marc Kupietz1a422662024-03-16 09:34:10 +0100356 <hi rend="sub">
357 <xsl:apply-templates/>
358 </hi>
359 </xsl:template>
360
Marc Kupietz99ec04b2024-03-16 11:30:03 +0100361 <xsl:template match="xhtml:sup|xhtml:span[@class='sup']">
Marc Kupietz1a422662024-03-16 09:34:10 +0100362 <hi rend="sup">
363 <xsl:apply-templates/>
364 </hi>
365 </xsl:template>
366
367 <xsl:template match="xhtml:div">
368 <div type="section">
369 <xsl:apply-templates/>
370 </div>
371 </xsl:template>
372
373 <xsl:template match="xhtml:p">
374 <p>
375 <xsl:apply-templates/>
376 </p>
377 </xsl:template>
378
379 <xsl:template match="xhtml:img">
380 <!-- <gap reason="image"/> -->
381 </xsl:template>
382
Marc Kupietz99ec04b2024-03-16 11:30:03 +0100383 <xsl:template match="xhtml:a">
384 <ref target="{@href}">
385 <xsl:apply-templates />
386 </ref>
387 </xsl:template>
388
389 <xsl:template match="xhtml:br"/>
390
Marc Kupietz1a422662024-03-16 09:34:10 +0100391 <xsl:template match="xhtml:*">
392 <xsl:message>
393 <xsl:text>unhandled element: </xsl:text><xsl:value-of select="concat(name(), ' ', string-join(./@*[normalize-space(.) != '']/concat(name(), ':', ., ' '), '_'))"/>
394 </xsl:message>
395 <xsl:apply-templates/>
396 </xsl:template>
397
398 <xsl:function name="ids:reversedAuthors">
399 <xsl:param name="s" />
400 <xsl:value-of
401 select="
402 if (matches($s, ';')) then
403 concat(ids:reversedAuthors(substring-before($s, ' ; ')), ' ; ', ids:reversedAuthors(substring-after($s, ' ; ')))
404 else
405 replace($s, '(.+) (.+)', '$2, $1')"
406 />
407 </xsl:function>
408
409 <xsl:function name="hlu:reversedAuthors">
410 <xsl:param name="s"/>
411 <xsl:value-of
412 select="if (matches($s, ';')) then concat(ids:reversedAuthors(substring-before($s, ' ; ')), ' ; ', ids:reversedAuthors(substring-after($s, ' ; '))) else replace($s, '(.+),(.+)', '$2, $1')"
413 />
414 </xsl:function>
415
416</xsl:stylesheet>