Add podtytul_* tags; refs #4005.
[librarian.git] / 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 Nowoczesna Polska. 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">
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="strofa">
191 <xsl:text>
192 </xsl:text>
193     <xsl:choose>
194         <xsl:when test="count(br) > 0">
195             <xsl:call-template name="verse">
196                 <xsl:with-param name="verse-content" select="br[1]/preceding-sibling::text() | br[1]/preceding-sibling::node()" />
197                 <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]" />
198             </xsl:call-template>
199             <xsl:for-each select="br">          
200                         <!-- Each BR tag "consumes" text after it -->
201                 <xsl:variable name="lnum" select="count(preceding-sibling::br)" />
202                 <xsl:call-template name="verse">
203                     <xsl:with-param name="verse-content"
204                         select="following-sibling::text()[count(preceding-sibling::br) = $lnum+1] | following-sibling::node()[count(preceding-sibling::br) = $lnum+1]" />
205                     <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]" />
206                 </xsl:call-template>
207             </xsl:for-each>
208         </xsl:when>
209         <xsl:otherwise>
210             <xsl:call-template name="verse">
211                 <xsl:with-param name="verse-content" select="text() | node()" />
212                 <xsl:with-param name="verse-type" select="wers_wciety|wers_akap|wers_cd|wers_do_prawej[1]" />
213              </xsl:call-template>
214         </xsl:otherwise>
215     </xsl:choose>
216 </xsl:template>
217
218 <xsl:template name="verse">
219     <xsl:param name="verse-content" />
220     <xsl:param name="verse-type" />
221 <xsl:text>
222 </xsl:text>
223     <xsl:variable name="content">
224         <xsl:apply-templates select="$verse-content" mode="inline" />
225     </xsl:variable>
226     <xsl:choose>
227         <xsl:when test="name($verse-type) = 'wers_akap'">
228             <xsl:text>  </xsl:text>
229         </xsl:when>
230         <xsl:when test="name($verse-type) = 'wers_wciety'">
231             <xsl:choose>
232                 <xsl:when test="$verse-content/@typ">
233                     <xsl:text>    </xsl:text>
234                 </xsl:when>
235                 <xsl:otherwise>
236                     <xsl:text>  </xsl:text>
237                 </xsl:otherwise>
238             </xsl:choose>
239         </xsl:when>
240         <xsl:when test="name($verse-type) = 'wers_cd'">
241             <xsl:text>                        </xsl:text>
242         </xsl:when>
243         <xsl:when test="name($verse-type) = 'wers_do_prawej'">
244             <xsl:text>                        </xsl:text>
245         </xsl:when>
246     </xsl:choose>
247 <xsl:value-of select="wl:strip($content)" />
248 </xsl:template>
249
250 <xsl:template match="motto_podpis">
251 <xsl:apply-templates mode="inline" />
252 </xsl:template>
253
254 <xsl:template match="tabela|tabelka">
255         <xsl:text>
256
257 </xsl:text>
258 <xsl:apply-templates/>
259 <xsl:text>
260 </xsl:text>
261 </xsl:template>
262 <xsl:template match="wiersz">
263         <xsl:apply-templates />
264         <xsl:text>
265 </xsl:text>
266 </xsl:template>
267 <xsl:template match="kol">
268         <xsl:apply-templates mode="inline" />
269         <xsl:text>    </xsl:text>
270 </xsl:template>
271
272
273 <!-- ================================================ -->
274 <!-- = INLINE TAGS                                  = -->
275 <!-- = (contain other inline tags and special tags) = -->
276 <!-- ================================================ -->
277 <!-- Annotations -->
278 <xsl:template match="pa|pe|pr|pt" mode="inline" />
279
280 <!-- Other inline tags -->
281 <xsl:template match="mat" mode="inline"><xsl:apply-templates mode="inline" /></xsl:template>
282
283 <xsl:template match="didask_tekst" mode="inline"><xsl:apply-templates mode="inline" /></xsl:template>
284
285 <xsl:template match="slowo_obce" mode="inline"><xsl:apply-templates mode="inline" /></xsl:template>
286
287 <xsl:template match="tytul_dziela" mode="inline">
288 <xsl:if test="@typ = '1'">„</xsl:if><xsl:apply-templates mode="inline" /><xsl:if test="@typ = '1'">”</xsl:if>
289 </xsl:template>
290
291 <xsl:template match="wyroznienie" mode="inline">
292 <xsl:text>*</xsl:text><xsl:apply-templates mode="inline" /><xsl:text>*</xsl:text>
293 </xsl:template>
294
295 <xsl:template match="indeks_dolny" mode="inline">
296 <xsl:apply-templates mode="inline" />
297 </xsl:template>
298
299 <xsl:template match="wieksze_odstepy" mode="inline">
300 <xsl:apply-templates mode="inline" />
301 </xsl:template>
302
303 <xsl:template match="osoba" mode="inline">
304 <xsl:apply-templates mode="inline" />
305 </xsl:template>
306
307
308 <!-- ============================================== -->
309 <!-- = STANDALONE TAGS                            = -->
310 <!-- = (cannot contain any other tags)            = -->
311 <!-- ============================================== -->
312 <xsl:template match="sekcja_swiatlo">
313 <xsl:text>
314
315
316
317 </xsl:text>
318 </xsl:template>
319
320 <xsl:template match="sekcja_asterysk">
321 <xsl:text>
322
323 *
324
325 </xsl:text>
326 </xsl:template>
327
328 <xsl:template match="separator_linia">
329 <xsl:text>
330
331 ------------------------------------------------
332
333 </xsl:text>
334 </xsl:template>
335
336
337 <!-- ================ -->
338 <!-- = SPECIAL TAGS = -->
339 <!-- ================ -->
340 <!-- Themes -->
341 <xsl:template match="begin" mode="inline" />
342
343 <xsl:template match="end" mode="inline" />
344
345 <xsl:template match="begin|end" />
346
347 <xsl:template match="motyw" mode="inline" />
348
349 <xsl:template name="translators">
350     <xsl:if test="//dc:contributor.translator">
351         <text>tłum. </text>
352         <xsl:for-each select="//dc:contributor.translator/text()">
353             <xsl:if test="position() != 1">
354                 <xsl:text>, </xsl:text>
355             </xsl:if>
356             <xsl:value-of select="wl:person_name(.)" />
357         </xsl:for-each>
358         <xsl:text>
359 </xsl:text>
360     </xsl:if>
361 </xsl:template>
362
363 <xsl:template name="isbn">
364     <xsl:if test="//meta[@id='txt-id']">
365         <xsl:variable name="isbn" select="//meta[@id='txt-id']"/>
366         <text>
367 ISBN </text><xsl:value-of select="substring-after($isbn, 'ISBN-')"/>
368     </xsl:if>
369 </xsl:template>
370
371
372 <!-- ================ -->
373 <!-- = IGNORED TAGS = -->
374 <!-- ================ -->
375 <xsl:template match="extra|uwaga" />
376 <xsl:template match="extra|uwaga" mode="inline" />
377
378 <xsl:template match="nota_red" />
379 <xsl:template match="abstrakt" />
380
381 <!-- ======== -->
382 <!-- = TEXT = -->
383 <!-- ======== -->
384 <xsl:template match="text()" />
385 <xsl:template match="text()" mode="inline">
386     <xsl:value-of select="wl:substitute_entities(.)" />
387 </xsl:template>
388
389
390 </xsl:stylesheet>
391