letters
[librarian.git] / src / librarian / xslt / book2txt.xslt
1 <?xml version="1.0" encoding="utf-8"?>
2 <!--
3
4    This file is part of Librarian, licensed under GNU Affero GPLv3 or later.
5    Copyright © Fundacja Wolne Lektury. See NOTICE for more information.
6
7 -->
8 <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
9     xmlns:wl="http://wolnelektury.pl/functions"
10     xmlns:dc="http://purl.org/dc/elements/1.1/" >
11
12 <xsl:output encoding="utf-8" method="text" />
13
14 <xsl:param name="wrapping" select="0" />
15
16 <!-- ============================================================================== -->
17 <!-- = MASTER TAG                                                                 = -->
18 <!-- = (can contain block tags, paragraph tags, standalone tags and special tags) = -->
19 <!-- ============================================================================== -->
20 <xsl:template match="powiesc|opowiadanie|liryka_l|liryka_lp|dramat_wierszowany_l|dramat_wierszowany_lp|dramat_wspolczesny">
21 <xsl:if test="not (../@raw-text) and nazwa_utworu">
22     <xsl:apply-templates select="autor_utworu|dzielo_nadrzedne|nazwa_utworu|podtytul" mode="header" />
23     <xsl:call-template name="translators" />
24     <xsl:call-template name="isbn" />
25     <xsl:text>
26 </xsl:text>
27 </xsl:if>
28 <xsl:apply-templates />
29 <xsl:text>
30
31 </xsl:text>
32 </xsl:template>
33
34
35 <!-- ==================================================================================== -->
36 <!-- = BLOCK TAGS                                                                       = -->
37 <!-- = (can contain other block tags, paragraph tags, standalone tags and special tags) = -->
38 <!-- ==================================================================================== -->
39 <xsl:template match="nota">
40 <xsl:apply-templates />
41 </xsl:template>
42
43 <xsl:template match="ramka">
44 <xsl:apply-templates />
45 </xsl:template>
46
47 <xsl:template match="lista_osob">
48 <xsl:text>
49
50
51 </xsl:text>
52 <xsl:value-of select="naglowek_listy" />
53 <xsl:apply-templates select="lista_osoba" />
54 <xsl:text>
55 </xsl:text>
56 </xsl:template>
57
58 <xsl:template match="dedykacja">
59 <xsl:text>
60
61 </xsl:text>
62 <xsl:apply-templates />
63 </xsl:template>
64
65 <xsl:template match="kwestia">
66 <xsl:apply-templates select="strofa|akap|didaskalia" />
67 </xsl:template>
68
69 <xsl:template match="dlugi_cytat|poezja_cyt">
70 <xsl:text>
71 </xsl:text>
72 <xsl:apply-templates />
73 </xsl:template>
74
75 <xsl:template match="motto">
76 <xsl:text>
77
78
79
80 </xsl:text>
81 <xsl:apply-templates /><xsl:text>
82
83 </xsl:text>
84 </xsl:template>
85
86
87 <!-- ========================================== -->
88 <!-- = PARAGRAPH TAGS                         = -->
89 <!-- = (can contain inline and special tags)  = -->
90 <!-- ========================================== -->
91 <!-- Title page -->
92 <xsl:template match="autor_utworu" mode="header">
93 <xsl:apply-templates mode="inline" />
94 <xsl:text>
95
96 </xsl:text>
97 </xsl:template>
98
99 <xsl:template match="nazwa_utworu" mode="header">
100 <xsl:apply-templates mode="inline" />
101 <xsl:text>
102 </xsl:text>
103 </xsl:template>
104
105 <xsl:template match="dzielo_nadrzedne" mode="header">
106 <xsl:apply-templates mode="inline" />
107 <xsl:text>
108 </xsl:text>
109 </xsl:template>
110
111 <xsl:template match="podtytul" mode="header">
112 <xsl:apply-templates mode="inline" />
113 <xsl:text>
114 </xsl:text>
115 </xsl:template>
116
117 <!-- Section headers (included in index)-->
118 <xsl:template match="naglowek_akt|naglowek_czesc|srodtytul">
119 <xsl:text>
120
121
122
123
124 </xsl:text>
125 <xsl:apply-templates mode="inline" />
126 </xsl:template>
127
128 <xsl:template match="naglowek_scena|naglowek_rozdzial">
129 <xsl:text>
130
131
132
133 </xsl:text>
134 <xsl:apply-templates mode="inline" />
135 </xsl:template>
136
137 <xsl:template match="naglowek_osoba|naglowek_podrozdzial">
138 <xsl:text>
139
140
141 </xsl:text>
142 <xsl:apply-templates mode="inline" />
143 </xsl:template>
144
145
146 <xsl:template match="podtytul_czesc|podtytul_rozdzial|podtytul_podrozdzial|podtytul_akt|podtytul_scena">
147 <xsl:text>
148
149 </xsl:text>
150 <xsl:apply-templates mode="inline" />
151 </xsl:template>
152
153
154
155 <!-- Other paragraph tags -->
156 <xsl:template match="miejsce_czas">
157 <xsl:text>
158
159
160
161 </xsl:text>
162 <xsl:apply-templates mode="inline" />
163 </xsl:template>
164
165 <xsl:template match="didaskalia">
166 <xsl:variable name="content">
167     <xsl:apply-templates select="*|text()" mode="inline" />
168 </xsl:variable>
169 <xsl:text>
170
171 / </xsl:text><xsl:value-of select="wl:wrap_words(wl:strip($content), $wrapping)" /><xsl:text> /</xsl:text>
172 </xsl:template>
173
174 <xsl:template match="lista_osoba">
175 <xsl:text>
176  * </xsl:text>
177 <xsl:apply-templates mode="inline" />
178 </xsl:template>
179
180 <xsl:template match="akap|akap_dialog|akap_cd|werset">
181 <xsl:variable name="content">
182     <xsl:apply-templates select="*|text()" mode="inline" />
183 </xsl:variable>
184 <xsl:text>
185
186 </xsl:text>
187 <xsl:value-of select="wl:wrap_words(wl:strip($content), $wrapping)" />
188 </xsl:template>
189
190 <xsl:template match="list">
191 <xsl:text>
192
193
194 </xsl:text>
195 <xsl:apply-templates />
196 <xsl:text>
197
198
199 </xsl:text>
200 </xsl:template>
201 <xsl:template match="adesat">
202   <xsl:text>
203                 </xsl:text>
204   <xsl:apply-templates select="*|text()" mode="inline" />
205   <xsl:text>
206 </xsl:text>
207 </xsl:template>
208 <xsl:template match="miejsce_data">
209   <xsl:text>
210                 </xsl:text>
211   <xsl:apply-templates select="*|text()" mode="inline" />
212   <xsl:text>
213 </xsl:text>
214 </xsl:template>
215 <xsl:template match="naglowek_listu">
216   <xsl:text>
217
218         </xsl:text>
219   <xsl:apply-templates select="*|text()" mode="inline" />
220   <xsl:text>
221 </xsl:text>
222 </xsl:template>
223 <xsl:template match="pozdrowienie">
224   <xsl:text>
225     </xsl:text>
226   <xsl:apply-templates select="*|text()" mode="inline" />
227   <xsl:text>
228 </xsl:text>
229 </xsl:template>
230 <xsl:template match="podpis">
231   <xsl:text>
232         </xsl:text>
233   <xsl:apply-templates select="*|text()" mode="inline" />
234   <xsl:text>
235 </xsl:text>
236 </xsl:template>
237
238 <xsl:template match="strofa">
239 <xsl:text>
240 </xsl:text>
241     <xsl:choose>
242         <xsl:when test="count(br) > 0">
243             <xsl:call-template name="verse">
244                 <xsl:with-param name="verse-content" select="br[1]/preceding-sibling::text() | br[1]/preceding-sibling::node()" />
245                 <xsl:with-param name="verse-type" select="br[1]/preceding-sibling::*[name() = 'wers_wciety' or name() = 'wers_akap' or name() = 'wers_cd' or name() = 'wers_do_prawej'][1]" />
246             </xsl:call-template>
247             <xsl:for-each select="br">          
248                         <!-- Each BR tag "consumes" text after it -->
249                 <xsl:variable name="lnum" select="count(preceding-sibling::br)" />
250                 <xsl:call-template name="verse">
251                     <xsl:with-param name="verse-content"
252                         select="following-sibling::text()[count(preceding-sibling::br) = $lnum+1] | following-sibling::node()[count(preceding-sibling::br) = $lnum+1]" />
253                     <xsl:with-param name="verse-type" select="following-sibling::*[count(preceding-sibling::br) = $lnum+1 and (name() = 'wers_wciety' or name() = 'wers_akap' or name() = 'wers_cd' or name() = 'wers_do_prawej')][1]" />
254                 </xsl:call-template>
255             </xsl:for-each>
256         </xsl:when>
257         <xsl:otherwise>
258             <xsl:call-template name="verse">
259                 <xsl:with-param name="verse-content" select="text() | node()" />
260                 <xsl:with-param name="verse-type" select="wers_wciety|wers_akap|wers_cd|wers_do_prawej[1]" />
261              </xsl:call-template>
262         </xsl:otherwise>
263     </xsl:choose>
264 </xsl:template>
265
266 <xsl:template name="verse">
267     <xsl:param name="verse-content" />
268     <xsl:param name="verse-type" />
269 <xsl:text>
270 </xsl:text>
271     <xsl:variable name="content">
272         <xsl:apply-templates select="$verse-content" mode="inline" />
273     </xsl:variable>
274     <xsl:choose>
275         <xsl:when test="name($verse-type) = 'wers_akap'">
276             <xsl:text>  </xsl:text>
277         </xsl:when>
278         <xsl:when test="name($verse-type) = 'wers_wciety'">
279             <xsl:choose>
280                 <xsl:when test="$verse-content/@typ">
281                     <xsl:text>    </xsl:text>
282                 </xsl:when>
283                 <xsl:otherwise>
284                     <xsl:text>  </xsl:text>
285                 </xsl:otherwise>
286             </xsl:choose>
287         </xsl:when>
288         <xsl:when test="name($verse-type) = 'wers_cd'">
289             <xsl:text>                        </xsl:text>
290         </xsl:when>
291         <xsl:when test="name($verse-type) = 'wers_do_prawej'">
292             <xsl:text>                        </xsl:text>
293         </xsl:when>
294     </xsl:choose>
295 <xsl:value-of select="wl:strip($content)" />
296 </xsl:template>
297
298 <xsl:template match="motto_podpis">
299 <xsl:apply-templates mode="inline" />
300 </xsl:template>
301
302 <xsl:template match="tabela|tabelka">
303         <xsl:text>
304
305 </xsl:text>
306 <xsl:apply-templates/>
307 <xsl:text>
308 </xsl:text>
309 </xsl:template>
310 <xsl:template match="wiersz">
311         <xsl:apply-templates />
312         <xsl:text>
313 </xsl:text>
314 </xsl:template>
315 <xsl:template match="kol">
316         <xsl:apply-templates mode="inline" />
317         <xsl:text>    </xsl:text>
318 </xsl:template>
319
320
321 <!-- ================================================ -->
322 <!-- = INLINE TAGS                                  = -->
323 <!-- = (contain other inline tags and special tags) = -->
324 <!-- ================================================ -->
325 <!-- Annotations -->
326 <xsl:template match="pa|pe|pr|pt|ptrad" mode="inline" />
327
328 <!-- Other inline tags -->
329 <xsl:template match="mat" mode="inline"><xsl:apply-templates mode="inline" /></xsl:template>
330
331 <xsl:template match="didask_tekst" mode="inline"><xsl:apply-templates mode="inline" /></xsl:template>
332
333 <xsl:template match="slowo_obce" mode="inline"><xsl:apply-templates mode="inline" /></xsl:template>
334
335 <xsl:template match="tytul_dziela" mode="inline">
336 <xsl:if test="@typ = '1'">„</xsl:if><xsl:apply-templates mode="inline" /><xsl:if test="@typ = '1'">”</xsl:if>
337 </xsl:template>
338
339 <xsl:template match="wyroznienie" mode="inline">
340 <xsl:text>*</xsl:text><xsl:apply-templates mode="inline" /><xsl:text>*</xsl:text>
341 </xsl:template>
342
343 <xsl:template match="indeks_dolny" mode="inline">
344 <xsl:apply-templates mode="inline" />
345 </xsl:template>
346
347 <xsl:template match="wieksze_odstepy" mode="inline">
348 <xsl:apply-templates mode="inline" />
349 </xsl:template>
350
351 <xsl:template match="osoba" mode="inline">
352 <xsl:apply-templates mode="inline" />
353 </xsl:template>
354
355
356 <!-- ============================================== -->
357 <!-- = STANDALONE TAGS                            = -->
358 <!-- = (cannot contain any other tags)            = -->
359 <!-- ============================================== -->
360 <xsl:template match="sekcja_swiatlo">
361 <xsl:text>
362
363
364
365 </xsl:text>
366 </xsl:template>
367
368 <xsl:template match="sekcja_asterysk">
369 <xsl:text>
370
371 *
372
373 </xsl:text>
374 </xsl:template>
375
376 <xsl:template match="separator_linia">
377 <xsl:text>
378
379 ------------------------------------------------
380
381 </xsl:text>
382 </xsl:template>
383
384
385 <!-- ================ -->
386 <!-- = SPECIAL TAGS = -->
387 <!-- ================ -->
388 <!-- Themes -->
389 <xsl:template match="begin" mode="inline" />
390
391 <xsl:template match="end" mode="inline" />
392
393 <xsl:template match="begin|end" />
394
395 <xsl:template match="motyw" mode="inline" />
396
397 <xsl:template name="translators">
398     <xsl:if test="//dc:contributor.translator">
399         <text>tłum. </text>
400         <xsl:for-each select="//dc:contributor.translator/text()">
401             <xsl:if test="position() != 1">
402                 <xsl:text>, </xsl:text>
403             </xsl:if>
404             <xsl:value-of select="wl:person_name(.)" />
405         </xsl:for-each>
406         <xsl:text>
407 </xsl:text>
408     </xsl:if>
409 </xsl:template>
410
411 <xsl:template name="isbn">
412     <xsl:if test="//meta[@id='txt-id']">
413         <xsl:variable name="isbn" select="//meta[@id='txt-id']"/>
414         <text>
415 ISBN </text><xsl:value-of select="substring-after($isbn, 'ISBN-')"/>
416     </xsl:if>
417 </xsl:template>
418
419
420 <!-- ================ -->
421 <!-- = IGNORED TAGS = -->
422 <!-- ================ -->
423 <xsl:template match="extra|uwaga" />
424 <xsl:template match="extra|uwaga" mode="inline" />
425
426 <xsl:template match="nota_red" />
427 <xsl:template match="abstrakt" />
428
429 <!-- ======== -->
430 <!-- = TEXT = -->
431 <!-- ======== -->
432 <xsl:template match="text()" />
433 <xsl:template match="text()" mode="inline">
434     <xsl:value-of select="wl:substitute_entities(.)" />
435 </xsl:template>
436
437
438 </xsl:stylesheet>
439