blob: ad6685699e6b27abb82527bae8416ee22529924a [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
Marc Kupietz7df4ccc2024-03-16 15:27:45 +010072 <xsl:variable name="texttype" select="replace($dnbBookdata//dc:subject[matches(., '^[A-Z] ')], '^[A-Z] (.*)', '$1')"/>
73
Marc Kupietz1a422662024-03-16 09:34:10 +010074 <xsl:variable name="verlag">
75 <xsl:choose>
76 <xsl:when test="contains($dnbBookdata//dc:publisher,':')">
77 <xsl:value-of select="normalize-space(substring-after($dnbBookdata//dc:publisher, ':'))"/>
78 </xsl:when>
79 <xsl:otherwise>
80 <xsl:value-of select="normalize-space($dnbBookdata//dc:publisher)"/>
81 </xsl:otherwise>
82 </xsl:choose>
83 </xsl:variable>
84
85 <xsl:variable name="erscheinungsjahr">
86 <xsl:choose>
87 <xsl:when test="matches($dnbBookdata//dc:date, '^[0-9]{4}$')">
88 <xsl:value-of select="$dnbBookdata//dc:date"/>
89 </xsl:when>
90 <xsl:otherwise>
91 <xsl:value-of select="substring-before($dnbBookdata//dc:date, '-')"/>
92 </xsl:otherwise>
93 </xsl:choose>
94 </xsl:variable>
95
96 <xsl:variable name="untertitel"
97 select="normalize-space(substring-after(substring-before($dnbBookdata//dc:title, '/'), ':'))"/>
98
99 <xsl:variable name="herausgeber">
100 <xsl:choose>
101 <xsl:when test="$dnbBookdata//dc:creator[ends-with(.,'[Hrsg.]')]">
102 <xsl:value-of
103 select="replace(string-join($dnbBookdata//dc:creator[ends-with(.,'[Hrsg.]')], ' ; '),'\s?\[Hrsg.\]','')"
104 />
105 </xsl:when>
106 <xsl:otherwise>.</xsl:otherwise>
107 </xsl:choose>
108 </xsl:variable>
109
110 <xsl:variable name="straight_herausgeber"
111 select="replace(hlu:reversedAuthors($herausgeber), ',', '')"/>
112
113 <xsl:variable name="j" select="$dnbBookdata//dc:date"/>
114
115 <!-- for BOT+s: -->
116 <xsl:variable name="seiten" select="replace($dnbBookdata//dc:format,'S\.','')"/>
117
118 <!-- fuer BOT+b: -->
119 <xsl:variable name="_b">
120 <xsl:variable name="regexp1" select="'(Band|Bd\.)\s*([0-9]?[0-9]?[0-9])'"/>
121 <xsl:choose>
122 <xsl:when test="matches($dnbBookdata, $regexp1)">
123 <xsl:analyze-string select="$dnbBookdata//dc:title" regex="{$regexp1}">
124 <xsl:matching-substring>
125 <xsl:value-of select="."/>
126 </xsl:matching-substring>
127 </xsl:analyze-string>
128 </xsl:when>
129 <xsl:otherwise>
130 <xsl:value-of select="'.'"/>
131 </xsl:otherwise>
132 </xsl:choose>
133 </xsl:variable>
134
135 <!-- for BOT+x: -->
136 <xsl:variable name="txtart">
137 <xsl:choose>
138 <xsl:when test="$x">
139 <xsl:value-of select="concat('[', $x, ']')"/>
140 </xsl:when>
141 <xsl:when
142 test="matches($untertitel, '([Rr]oman|[Ee]rzhlung(en)?|[Aa]nthologie|[Gg]eschichte(n)?|[Nn]ovelle)')">
143 <xsl:value-of
144 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'), ']')"
145 />
146 </xsl:when>
147 <xsl:otherwise>
148 <xsl:value-of>Roman</xsl:value-of>
149 </xsl:otherwise>
150 </xsl:choose>
151 </xsl:variable>
152
153
154
155 <!-- fuer BOTd: -->
156 <xsl:variable name="dok"
157 select="concat((if(string-length($autor) &gt; 0) then concat($straight_autor, ': ') else ''), $titel, ', ', $txtart, ', (', $j, ')')"/>
158
159 <!-- END variables derived from sru request to dnb archive -->
160
161
162 <xsl:variable name="corpus_sigle" select="'DNB'"/>
163
164 <!-- for BOTD: -->
165 <!-- Dokumentsigle muss zusammen mit Korpussigle (z.B DIV fuer loz-div und loz-div-pub) eindeutig sein -->
166 <xsl:variable name="doc_sigle">
167 <xsl:variable name="firstContentWordTitleInitial">
168 <xsl:variable name="helper">
169 <xsl:analyze-string select="$titel" regex="\w+">
170 <xsl:matching-substring>
171 <xsl:choose>
172 <xsl:when
173 test="matches(.,'^[A-Z]') and not(matches(.,'^(Der|Die|Das|Des|Ein|Eine|Eines|Einmal|Von|Mit|Zu|Zurck)$'))">
174 <!-- TODO: Fktnswoerter nachtragen -->
175 <xsl:sequence select="."/>
176 </xsl:when>
177 <xsl:otherwise/>
178 </xsl:choose>
179 </xsl:matching-substring>
180 </xsl:analyze-string>
181 </xsl:variable>
182 <xsl:value-of
183 select="upper-case(substring(normalize-space(replace($helper,'\s+.+$','')),1,1))"/>
184 <!-- longest match of .+ -->
185 </xsl:variable>
186 <xsl:choose>
187 <xsl:when test="contains($autor,';')">
188 <xsl:variable name="lastname_aut1"
189 select="upper-case(substring(normalize-space(substring-before(substring-before($autor,';'),',')), 1, 1))"/>
190 <xsl:variable name="lastname_aut2"
191 select="upper-case(substring(normalize-space(substring-before(substring-before(substring-after($autor, ';'),';'),',')), 1, 1))"/>
192 <xsl:value-of select="concat($lastname_aut1, $lastname_aut2)"/>
193 </xsl:when>
194 <xsl:otherwise>
195 <xsl:variable name="lastname_aut1"
196 select="upper-case(substring(normalize-space(substring-before($autor,',')),1,1))"/>
197 <xsl:variable name="firstname_aut1"
198 select="upper-case(substring(normalize-space(substring-after($autor,',')),1,1))"/>
199 <xsl:value-of select="concat($lastname_aut1, $firstname_aut1)"/>
200 </xsl:otherwise>
201 </xsl:choose>
202 <xsl:value-of select="$firstContentWordTitleInitial"/>
203 </xsl:variable>
204
205
206 <xsl:variable name="text_sigle" select="substring($isbn, 8, 5)"/>
207 <xsl:variable name="sigle" select="concat($corpus_sigle, '/', $doc_sigle, '.', $text_sigle)"/>
208
209 <!-- fuer BOT+xy: (?) -->
210 <xsl:variable name="xyref">
211 <xsl:value-of select="document-uri(.)"/>
212 <xsl:text>; </xsl:text>
213 <xsl:text>ISBN:</xsl:text>
214 <xsl:value-of select="$isbn"/>
215 <xsl:text>; </xsl:text>
216 <xsl:value-of select="string-join($dnbBookdata//dc:identifier)"/>
217 </xsl:variable>
218
Marc Kupietzb660ed62024-03-16 11:45:53 +0100219 <xsl:variable name="long-reference"
220 select="concat($sigle, ' ', $autor, ': ', $titel, '. ', $erscheinungsort, ': ', $verlag, ', ', $erscheinungsjahr)"/>
221
222 <xsl:variable name="short-reference"
223 select="concat($straight_autor, ': ', $titel, ' (', $erscheinungsjahr, ')')"/>
Marc Kupietz1a422662024-03-16 09:34:10 +0100224
225 <xsl:template match="/">
226 <idsDoc TEIform="TEI.2" type="text" version="1.0">
227 <idsHeader TEIform="teiHeader" pattern="text" status="new" type="document" version="1.1">
228 <fileDesc>
229 <titleStmt>
Marc Kupietzb660ed62024-03-16 11:45:53 +0100230 <dokumentSigle><xsl:value-of select="string-join(($corpus_sigle, $doc_sigle), '/')"/></dokumentSigle>
231 <d.title><xsl:value-of select="$short-reference"/></d.title>
Marc Kupietz1a422662024-03-16 09:34:10 +0100232 </titleStmt>
233 <publicationStmt>
234 <distributor/>
235 <pubAddress/>
236 <availability region="world" status="unknown">QAO-NC</availability>
237 <pubDate/>
238 </publicationStmt>
239 <sourceDesc>
240 <biblStruct>
241 <monogr>
242 <h.title type="main"/>
243 <imprint/>
244 </monogr>
245 </biblStruct>
246 </sourceDesc>
247 </fileDesc>
248 </idsHeader>
249 <idsText version="1.0">
250 <idsHeader TEIform="teiHeader" pattern="text" status="new" type="text" version="1.1">
251 <fileDesc>
252 <titleStmt>
253 <textSigle><xsl:sequence select="$sigle"/></textSigle>
Marc Kupietzb660ed62024-03-16 11:45:53 +0100254 <t.title assemblage="regular"><xsl:value-of select="$long-reference"/></t.title>
Marc Kupietz1a422662024-03-16 09:34:10 +0100255 </titleStmt>
256 <publicationStmt>
257 <distributor/>
258 <pubAddress/>
259 <availability region="world" status="unknown">QAO-NC</availability>
260 <pubDate/>
261 </publicationStmt>
262 <sourceDesc>
263 <biblStruct>
264 <monogr>
265 <h.title type="main"><xsl:value-of select="$titel"/></h.title>
266 <h.title type="sub"><xsl:value-of select="$untertitel"/></h.title>
267 <h.author><xsl:value-of select="$autor"/></h.author>
268 <editor/>
269 <edition>
270 <further/>
271 <kind>E-Book-Ausgabe</kind>
272 <appearance>EPUB-Datei</appearance>
273 </edition>
274 <imprint>
Marc Kupietzb660ed62024-03-16 11:45:53 +0100275 <publisher><xsl:value-of select="$verlag"/></publisher>
Marc Kupietz1a422662024-03-16 09:34:10 +0100276 <pubDate type="year"><xsl:value-of select="$j"/></pubDate>
277 <pubDate type="month"/>
278 <pubDate type="day"/>
279 <pubPlace key="DE"><xsl:value-of select="$erscheinungsort"/></pubPlace>
280 </imprint>
281 <biblScope type="subsume"/>
282 <biblScope type="pp"/>
283 <biblScope type="vol"/>
284 <biblScope type="volume-title"/>
285 </monogr>
286 </biblStruct>
287 <reference assemblage="regular" type="complete"><xsl:value-of select="concat($sigle, ' ', $autor, ': ', $titel, '. ', $erscheinungsort, ': ', $verlag, ', ', $erscheinungsjahr)"/></reference>
Marc Kupietz1a422662024-03-16 09:34:10 +0100288 </sourceDesc>
289 </fileDesc>
290 <profileDesc>
291 <creation>
292 <creatDate><xsl:value-of select="$j"/></creatDate>
293 </creation>
294 <textClass/>
295 <textDesc>
Marc Kupietz7df4ccc2024-03-16 15:27:45 +0100296 <textType><xsl:value-of select="$texttype"/></textType>
297 <textTypeRef><xsl:value-of select="$texttype"/></textTypeRef>
Marc Kupietz1a422662024-03-16 09:34:10 +0100298 <textDomain/>
299 </textDesc>
300 </profileDesc>
301 </idsHeader>
302 <text>
303 <body>
304 <!-- Call the template for each link in the TOC
305 <xsl:apply-templates select="//xhtml:ol[@class='toc']/xhtml:li/xhtml:a" mode="collect"/> -->
306 <xsl:apply-templates select="//opf:package/opf:manifest/opf:item[matches(@href, '\.x?html$') and not(matches(@href, '(cover|toc|copyright|feedback).*'))]" mode="collect"/>
307 </body>
308 </text>
309 </idsText>
310 </idsDoc>
311 </xsl:template>
312
313 <xsl:template match="opf:item" mode="collect">
314 <xsl:variable name="href" select="@href"/>
315 <xsl:message>
316 <xsl:text>converting: </xsl:text><xsl:value-of select="$href"/><xsl:text> </xsl:text><xsl:value-of select="$isbn"/>
317 </xsl:message>
318 <xsl:apply-templates select="doc(resolve-uri($href, base-uri()))/xhtml:html/xhtml:body"/>
319 </xsl:template>
320
321 <xsl:template match="xhtml:body">
322 <div type="chapter">
323 <xsl:apply-templates/>
324 </div>
325 </xsl:template>
326
327 <xsl:template match="xhtml:title">
328 <head>
329 <xsl:apply-templates/>
330 </head>
331 </xsl:template>
332
333 <xsl:template match="xhtml:h1">
334 <head>
335 <xsl:apply-templates/>
336 </head>
337 </xsl:template>
338
339 <xsl:template match="xhtml:h2|xhtml:h3">
340 <head type="sub">
341 <xsl:apply-templates/>
342 </head>
343 </xsl:template>
344
Marc Kupietz99ec04b2024-03-16 11:30:03 +0100345 <xsl:template match="xhtml:em">
346 <emph>
347 <xsl:apply-templates/>
348 </emph>
349 </xsl:template>
Marc Kupietz1a422662024-03-16 09:34:10 +0100350
Marc Kupietz99ec04b2024-03-16 11:30:03 +0100351 <xsl:template match="xhtml:span[matches(@class, '(bold|italic|big| )+')]">
352 <hi rend="{@class}">
Marc Kupietz1a422662024-03-16 09:34:10 +0100353 <xsl:apply-templates/>
354 </hi>
355 </xsl:template>
356
Marc Kupietz99ec04b2024-03-16 11:30:03 +0100357 <xsl:template match="xhtml:sub|xhtml:span[@class='sub']">
Marc Kupietz1a422662024-03-16 09:34:10 +0100358 <hi rend="sub">
359 <xsl:apply-templates/>
360 </hi>
361 </xsl:template>
362
Marc Kupietz99ec04b2024-03-16 11:30:03 +0100363 <xsl:template match="xhtml:sup|xhtml:span[@class='sup']">
Marc Kupietz1a422662024-03-16 09:34:10 +0100364 <hi rend="sup">
365 <xsl:apply-templates/>
366 </hi>
367 </xsl:template>
368
369 <xsl:template match="xhtml:div">
370 <div type="section">
371 <xsl:apply-templates/>
372 </div>
373 </xsl:template>
374
375 <xsl:template match="xhtml:p">
376 <p>
377 <xsl:apply-templates/>
378 </p>
379 </xsl:template>
380
381 <xsl:template match="xhtml:img">
382 <!-- <gap reason="image"/> -->
383 </xsl:template>
384
Marc Kupietz99ec04b2024-03-16 11:30:03 +0100385 <xsl:template match="xhtml:a">
386 <ref target="{@href}">
387 <xsl:apply-templates />
388 </ref>
389 </xsl:template>
390
391 <xsl:template match="xhtml:br"/>
392
Marc Kupietz1a422662024-03-16 09:34:10 +0100393 <xsl:template match="xhtml:*">
394 <xsl:message>
395 <xsl:text>unhandled element: </xsl:text><xsl:value-of select="concat(name(), ' ', string-join(./@*[normalize-space(.) != '']/concat(name(), ':', ., ' '), '_'))"/>
396 </xsl:message>
397 <xsl:apply-templates/>
398 </xsl:template>
399
400 <xsl:function name="ids:reversedAuthors">
401 <xsl:param name="s" />
402 <xsl:value-of
403 select="
404 if (matches($s, ';')) then
405 concat(ids:reversedAuthors(substring-before($s, ' ; ')), ' ; ', ids:reversedAuthors(substring-after($s, ' ; ')))
406 else
407 replace($s, '(.+) (.+)', '$2, $1')"
408 />
409 </xsl:function>
410
411 <xsl:function name="hlu:reversedAuthors">
412 <xsl:param name="s"/>
413 <xsl:value-of
414 select="if (matches($s, ';')) then concat(ids:reversedAuthors(substring-before($s, ' ; ')), ' ; ', ids:reversedAuthors(substring-after($s, ' ; '))) else replace($s, '(.+),(.+)', '$2, $1')"
415 />
416 </xsl:function>
417
418</xsl:stylesheet>