increased word spacing in WL XML
[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="lista_osob">
44 <xsl:text>
45
46
47 </xsl:text>
48 <xsl:value-of select="naglowek_listy" />
49 <xsl:apply-templates select="lista_osoba" />
50 <xsl:text>
51 </xsl:text>
52 </xsl:template>
53
54 <xsl:template match="dedykacja">
55 <xsl:text>
56
57 </xsl:text>
58 <xsl:apply-templates />
59 </xsl:template>
60
61 <xsl:template match="kwestia">
62 <xsl:apply-templates select="strofa|akap|didaskalia" />
63 </xsl:template>
64
65 <xsl:template match="dlugi_cytat|poezja_cyt">
66 <xsl:text>
67 </xsl:text>
68 <xsl:apply-templates />
69 </xsl:template>
70
71 <xsl:template match="motto">
72 <xsl:text>
73
74
75
76 </xsl:text>
77 <xsl:apply-templates /><xsl:text>
78
79 </xsl:text>
80 </xsl:template>
81
82
83 <!-- ========================================== -->
84 <!-- = PARAGRAPH TAGS                         = -->
85 <!-- = (can contain inline and special tags)  = -->
86 <!-- ========================================== -->
87 <!-- Title page -->
88 <xsl:template match="autor_utworu" mode="header">
89 <xsl:apply-templates mode="inline" />
90 <xsl:text>
91
92 </xsl:text>
93 </xsl:template>
94
95 <xsl:template match="nazwa_utworu" mode="header">
96 <xsl:apply-templates mode="inline" />
97 <xsl:text>
98 </xsl:text>
99 </xsl:template>
100
101 <xsl:template match="dzielo_nadrzedne" mode="header">
102 <xsl:apply-templates mode="inline" />
103 <xsl:text>
104 </xsl:text>
105 </xsl:template>
106
107 <xsl:template match="podtytul" mode="header">
108 <xsl:apply-templates mode="inline" />
109 <xsl:text>
110 </xsl:text>
111 </xsl:template>
112
113 <!-- Section headers (included in index)-->
114 <xsl:template match="naglowek_akt|naglowek_czesc|srodtytul">
115 <xsl:text>
116
117
118
119
120 </xsl:text>
121 <xsl:apply-templates mode="inline" />
122 </xsl:template>
123
124 <xsl:template match="naglowek_scena|naglowek_rozdzial">
125 <xsl:text>
126
127
128
129 </xsl:text>
130 <xsl:apply-templates mode="inline" />
131 </xsl:template>
132
133 <xsl:template match="naglowek_osoba|naglowek_podrozdzial">
134 <xsl:text>
135
136
137 </xsl:text>
138 <xsl:apply-templates mode="inline" />
139 </xsl:template>
140
141 <!-- Other paragraph tags -->
142 <xsl:template match="miejsce_czas">
143 <xsl:text>
144
145
146
147 </xsl:text>
148 <xsl:apply-templates mode="inline" />
149 </xsl:template>
150
151 <xsl:template match="didaskalia">
152 <xsl:variable name="content">
153     <xsl:apply-templates select="*|text()" mode="inline" />
154 </xsl:variable>
155 <xsl:text>
156
157 / </xsl:text><xsl:value-of select="wl:wrap_words(wl:strip($content), $wrapping)" /><xsl:text> /</xsl:text>
158 </xsl:template>
159
160 <xsl:template match="lista_osoba">
161 <xsl:text>
162  * </xsl:text>
163 <xsl:apply-templates mode="inline" />
164 </xsl:template>
165
166 <xsl:template match="akap|akap_dialog|akap_cd">
167 <xsl:variable name="content">
168     <xsl:apply-templates select="*|text()" mode="inline" />
169 </xsl:variable>
170 <xsl:text>
171
172 </xsl:text>
173 <xsl:value-of select="wl:wrap_words(wl:strip($content), $wrapping)" />
174 </xsl:template>
175
176 <xsl:template match="strofa">
177 <xsl:text>
178 </xsl:text>
179     <xsl:choose>
180         <xsl:when test="count(br) > 0">
181             <xsl:call-template name="verse">
182                 <xsl:with-param name="verse-content" select="br[1]/preceding-sibling::text() | br[1]/preceding-sibling::node()" />
183                 <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]" />
184             </xsl:call-template>
185             <xsl:for-each select="br">          
186                         <!-- Each BR tag "consumes" text after it -->
187                 <xsl:variable name="lnum" select="count(preceding-sibling::br)" />
188                 <xsl:call-template name="verse">
189                     <xsl:with-param name="verse-content"
190                         select="following-sibling::text()[count(preceding-sibling::br) = $lnum+1] | following-sibling::node()[count(preceding-sibling::br) = $lnum+1]" />
191                     <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]" />
192                 </xsl:call-template>
193             </xsl:for-each>
194         </xsl:when>
195         <xsl:otherwise>
196             <xsl:call-template name="verse">
197                 <xsl:with-param name="verse-content" select="text() | node()" />
198                 <xsl:with-param name="verse-type" select="wers_wciety|wers_akap|wers_cd|wers_do_prawej[1]" />
199              </xsl:call-template>
200         </xsl:otherwise>
201     </xsl:choose>
202 </xsl:template>
203
204 <xsl:template name="verse">
205     <xsl:param name="verse-content" />
206     <xsl:param name="verse-type" />
207 <xsl:text>
208 </xsl:text>
209     <xsl:variable name="content">
210         <xsl:apply-templates select="$verse-content" mode="inline" />
211     </xsl:variable>
212     <xsl:choose>
213         <xsl:when test="name($verse-type) = 'wers_akap'">
214             <xsl:text>  </xsl:text>
215         </xsl:when>
216         <xsl:when test="name($verse-type) = 'wers_wciety'">
217             <xsl:choose>
218                 <xsl:when test="$verse-content/@typ">
219                     <xsl:text>    </xsl:text>
220                 </xsl:when>
221                 <xsl:otherwise>
222                     <xsl:text>  </xsl:text>
223                 </xsl:otherwise>
224             </xsl:choose>
225         </xsl:when>
226         <xsl:when test="name($verse-type) = 'wers_cd'">
227             <xsl:text>                        </xsl:text>
228         </xsl:when>
229         <xsl:when test="name($verse-type) = 'wers_do_prawej'">
230             <xsl:text>                        </xsl:text>
231         </xsl:when>
232     </xsl:choose>
233 <xsl:value-of select="wl:strip($content)" />
234 </xsl:template>
235
236 <xsl:template match="motto_podpis">
237 <xsl:apply-templates mode="inline" />
238 </xsl:template>
239
240 <xsl:template match="tabela|tabelka">
241         <xsl:text>
242
243 </xsl:text>
244 <xsl:apply-templates/>
245 <xsl:text>
246 </xsl:text>
247 </xsl:template>
248 <xsl:template match="wiersz">
249         <xsl:apply-templates />
250         <xsl:text>
251 </xsl:text>
252 </xsl:template>
253 <xsl:template match="kol">
254         <xsl:apply-templates mode="inline" />
255         <xsl:text>    </xsl:text>
256 </xsl:template>
257
258
259 <!-- ================================================ -->
260 <!-- = INLINE TAGS                                  = -->
261 <!-- = (contain other inline tags and special tags) = -->
262 <!-- ================================================ -->
263 <!-- Annotations -->
264 <xsl:template match="pa|pe|pr|pt" mode="inline" />
265
266 <!-- Other inline tags -->
267 <xsl:template match="mat" mode="inline"><xsl:apply-templates mode="inline" /></xsl:template>
268
269 <xsl:template match="didask_tekst" mode="inline"><xsl:apply-templates mode="inline" /></xsl:template>
270
271 <xsl:template match="slowo_obce" mode="inline"><xsl:apply-templates mode="inline" /></xsl:template>
272
273 <xsl:template match="tytul_dziela" mode="inline">
274 <xsl:if test="@typ = '1'">„</xsl:if><xsl:apply-templates mode="inline" /><xsl:if test="@typ = '1'">”</xsl:if>
275 </xsl:template>
276
277 <xsl:template match="wyroznienie" mode="inline">
278 <xsl:text>*</xsl:text><xsl:apply-templates mode="inline" /><xsl:text>*</xsl:text>
279 </xsl:template>
280
281 <xsl:template match="indeks_dolny" mode="inline">
282 <xsl:apply-templates mode="inline" />
283 </xsl:template>
284
285 <xsl:template match="wieksze_odstepy" mode="inline">
286 <xsl:apply-templates mode="inline" />
287 </xsl:template>
288
289 <xsl:template match="osoba" mode="inline">
290 <xsl:apply-templates mode="inline" />
291 </xsl:template>
292
293
294 <!-- ============================================== -->
295 <!-- = STANDALONE TAGS                            = -->
296 <!-- = (cannot contain any other tags)            = -->
297 <!-- ============================================== -->
298 <xsl:template match="sekcja_swiatlo">
299 <xsl:text>
300
301
302
303 </xsl:text>
304 </xsl:template>
305
306 <xsl:template match="sekcja_asterysk">
307 <xsl:text>
308
309 *
310
311 </xsl:text>
312 </xsl:template>
313
314 <xsl:template match="separator_linia">
315 <xsl:text>
316
317 ------------------------------------------------
318
319 </xsl:text>
320 </xsl:template>
321
322
323 <!-- ================ -->
324 <!-- = SPECIAL TAGS = -->
325 <!-- ================ -->
326 <!-- Themes -->
327 <xsl:template match="begin" mode="inline" />
328
329 <xsl:template match="end" mode="inline" />
330
331 <xsl:template match="begin|end" />
332
333 <xsl:template match="motyw" mode="inline" />
334
335 <xsl:template name="translators">
336     <xsl:if test="//dc:contributor.translator">
337         <text>tłum. </text>
338         <xsl:for-each select="//dc:contributor.translator/text()">
339             <xsl:if test="position() != 1">
340                 <xsl:text>, </xsl:text>
341             </xsl:if>
342             <xsl:value-of select="wl:person_name(.)" />
343         </xsl:for-each>
344         <xsl:text>
345 </xsl:text>
346     </xsl:if>
347 </xsl:template>
348
349 <xsl:template name="isbn">
350     <xsl:if test="//meta[@id='txt-id']">
351         <xsl:variable name="isbn" select="//meta[@id='txt-id']"/>
352         <text>
353 ISBN </text><xsl:value-of select="substring-after($isbn, 'ISBN-')"/>
354     </xsl:if>
355 </xsl:template>
356
357
358 <!-- ================ -->
359 <!-- = IGNORED TAGS = -->
360 <!-- ================ -->
361 <xsl:template match="extra|uwaga" />
362 <xsl:template match="extra|uwaga" mode="inline" />
363
364 <xsl:template match="nota_red" />
365 <xsl:template match="abstrakt" />
366
367 <!-- ======== -->
368 <!-- = TEXT = -->
369 <!-- ======== -->
370 <xsl:template match="text()" />
371 <xsl:template match="text()" mode="inline">
372     <xsl:value-of select="wl:substitute_entities(.)" />
373 </xsl:template>
374
375
376 </xsl:stylesheet>
377