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