Even shorter NOTCIE.
[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
11 <xsl:output encoding="utf-8" method="text" />
12
13 <xsl:param name="wrapping" select="0" />
14
15 <!-- ============================================================================== -->
16 <!-- = MASTER TAG                                                                 = -->
17 <!-- = (can contain block tags, paragraph tags, standalone tags and special tags) = -->
18 <!-- ============================================================================== -->
19 <xsl:template match="powiesc|opowiadanie|liryka_l|liryka_lp|dramat_wierszowany_l|dramat_wierszowany_lp|dramat_wspolczesny">
20 <xsl:if test="nazwa_utworu"><xsl:apply-templates select="autor_utworu|dzielo_nadrzedne|nazwa_utworu|podtytul" mode="header" /></xsl:if>
21 <xsl:text>
22
23 </xsl:text>
24 <xsl:apply-templates />
25 </xsl:template>
26
27
28 <!-- ==================================================================================== -->
29 <!-- = BLOCK TAGS                                                                       = -->
30 <!-- = (can contain other block tags, paragraph tags, standalone tags and special tags) = -->
31 <!-- ==================================================================================== -->
32 <xsl:template match="nota">
33 <xsl:apply-templates />
34 </xsl:template>
35
36 <xsl:template match="lista_osob">
37 <xsl:text>
38
39
40 </xsl:text>
41 <xsl:value-of select="naglowek_listy" />
42 <xsl:apply-templates select="lista_osoba" />
43 <xsl:text>
44 </xsl:text>
45 </xsl:template>
46
47 <xsl:template match="dedykacja">
48 <xsl:text>
49
50 </xsl:text>
51 <xsl:apply-templates />
52 </xsl:template>
53
54 <xsl:template match="kwestia">
55 <xsl:apply-templates select="strofa|akap|didaskalia" />
56 </xsl:template>
57
58 <xsl:template match="dlugi_cytat|poezja_cyt">
59 <xsl:text>
60 </xsl:text>
61 <xsl:apply-templates />
62 </xsl:template>
63
64 <xsl:template match="motto">
65 <xsl:text>
66
67
68
69 </xsl:text>
70 <xsl:apply-templates /><xsl:text>
71
72 </xsl:text>
73 </xsl:template>
74
75
76 <!-- ========================================== -->
77 <!-- = PARAGRAPH TAGS                         = -->
78 <!-- = (can contain inline and special tags)  = -->
79 <!-- ========================================== -->
80 <!-- Title page -->
81 <xsl:template match="autor_utworu" mode="header">
82 <xsl:text>
83
84 </xsl:text>
85 <xsl:apply-templates mode="inline" />
86 </xsl:template>
87
88 <xsl:template match="nazwa_utworu" mode="header">
89 <xsl:text>
90
91 </xsl:text>
92 <xsl:apply-templates mode="inline" />
93 </xsl:template>
94
95 <xsl:template match="dzielo_nadrzedne" mode="header">
96 <xsl:text>
97     
98 </xsl:text>
99 <xsl:apply-templates mode="inline" />
100 </xsl:template>
101
102 <xsl:template match="podtytul" mode="header">
103 <xsl:text>
104 </xsl:text>
105 <xsl:apply-templates mode="inline" />
106 </xsl:template>
107
108 <!-- Section headers (included in index)-->
109 <xsl:template match="naglowek_akt|naglowek_czesc|srodtytul">
110 <xsl:text>
111
112
113
114
115 </xsl:text>
116 <xsl:apply-templates mode="inline" />
117 </xsl:template>
118
119 <xsl:template match="naglowek_scena|naglowek_rozdzial">
120 <xsl:text>
121
122
123
124 </xsl:text>
125 <xsl:apply-templates mode="inline" />
126 </xsl:template>
127
128 <xsl:template match="naglowek_osoba|naglowek_podrozdzial">
129 <xsl:text>
130
131
132 </xsl:text>
133 <xsl:apply-templates mode="inline" />
134 </xsl:template>
135
136 <!-- Other paragraph tags -->
137 <xsl:template match="miejsce_czas">
138 <xsl:text>
139
140
141
142 </xsl:text>
143 <xsl:apply-templates mode="inline" />
144 </xsl:template>
145
146 <xsl:template match="didaskalia">
147 <xsl:variable name="content">
148     <xsl:apply-templates select="*|text()" mode="inline" />
149 </xsl:variable>
150 <xsl:text>
151     
152 / </xsl:text><xsl:value-of select="wl:wrap_words(wl:strip($content), $wrapping)" /><xsl:text> /</xsl:text>
153 </xsl:template>
154
155 <xsl:template match="lista_osoba">
156 <xsl:text>
157  * </xsl:text>
158 <xsl:apply-templates mode="inline" />
159 </xsl:template>
160
161 <xsl:template match="akap|akap_dialog|akap_cd">
162 <xsl:variable name="content">
163     <xsl:apply-templates select="*|text()" mode="inline" />
164 </xsl:variable>
165 <xsl:text>
166
167 </xsl:text>
168 <xsl:value-of select="wl:wrap_words(wl:strip($content), $wrapping)" />
169 </xsl:template>
170
171 <xsl:template match="strofa">
172 <xsl:text>
173 </xsl:text>
174     <xsl:choose>
175         <xsl:when test="count(br) > 0">     
176             <xsl:call-template name="verse">
177                 <xsl:with-param name="verse-content" select="br[1]/preceding-sibling::text() | br[1]/preceding-sibling::node()" />
178                 <xsl:with-param name="verse-type" select="br[1]/preceding-sibling::*[name() = 'wers_wciety' or name() = 'wers_akap' or name() = 'wers_cd'][1]" />
179             </xsl:call-template>    
180             <xsl:for-each select="br">          
181                         <!-- Each BR tag "consumes" text after it -->
182                 <xsl:variable name="lnum" select="count(preceding-sibling::br)" />
183                 <xsl:call-template name="verse">
184                     <xsl:with-param name="verse-content" 
185                         select="following-sibling::text()[count(preceding-sibling::br) = $lnum+1] | following-sibling::node()[count(preceding-sibling::br) = $lnum+1]" />
186                     <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')][1]" />
187                 </xsl:call-template>
188             </xsl:for-each>
189         </xsl:when>
190         <xsl:otherwise>
191             <xsl:call-template name="verse">
192                 <xsl:with-param name="verse-content" select="text() | node()" />
193                 <xsl:with-param name="verse-type" select="wers_wciety|wers_akap|wers_cd[1]" />
194              </xsl:call-template>           
195         </xsl:otherwise>
196     </xsl:choose>
197 </xsl:template>
198
199 <xsl:template name="verse">
200     <xsl:param name="verse-content" />
201     <xsl:param name="verse-type" />
202 <xsl:text>
203 </xsl:text>
204     <xsl:variable name="content">
205         <xsl:apply-templates select="$verse-content" mode="inline" />
206     </xsl:variable>
207     <xsl:choose>
208         <xsl:when test="name($verse-type) = 'wers_akap'">
209             <xsl:text>  </xsl:text>
210         </xsl:when>
211         <xsl:when test="name($verse-type) = 'wers_wciety'">
212             <xsl:choose>
213                 <xsl:when test="$verse-content/@typ">
214                     <xsl:text>    </xsl:text>
215                 </xsl:when>
216                 <xsl:otherwise>
217                     <xsl:text>  </xsl:text>
218                 </xsl:otherwise>
219             </xsl:choose>
220         </xsl:when>
221         <xsl:when test="name($verse-type) = 'wers_cd'">
222             <xsl:text>                        </xsl:text>
223         </xsl:when>
224     </xsl:choose>
225 <xsl:value-of select="wl:strip($content)" />
226 </xsl:template>
227
228 <xsl:template match="motto_podpis">
229 <xsl:apply-templates mode="inline" />
230 </xsl:template>
231
232
233 <!-- ================================================ -->
234 <!-- = INLINE TAGS                                  = -->
235 <!-- = (contain other inline tags and special tags) = -->
236 <!-- ================================================ -->
237 <!-- Annotations -->
238 <xsl:template match="pa|pe|pr|pt" mode="inline" />
239
240 <!-- Other inline tags -->
241 <xsl:template match="mat" mode="inline"><xsl:apply-templates mode="inline" /></xsl:template>
242
243 <xsl:template match="didask_tekst" mode="inline"><xsl:apply-templates mode="inline" /></xsl:template>
244
245 <xsl:template match="slowo_obce" mode="inline"><xsl:apply-templates mode="inline" /></xsl:template>
246
247 <xsl:template match="tytul_dziela" mode="inline">
248 <xsl:if test="@typ = '1'">„</xsl:if><xsl:apply-templates mode="inline" /><xsl:if test="@typ = '1'">”</xsl:if>
249 </xsl:template>
250
251 <xsl:template match="wyroznienie" mode="inline">
252 <xsl:text>*</xsl:text><xsl:apply-templates mode="inline" /><xsl:text>*</xsl:text>
253 </xsl:template>
254
255 <xsl:template match="osoba" mode="inline">
256 <xsl:apply-templates mode="inline" />
257 </xsl:template>
258
259
260 <!-- ============================================== -->
261 <!-- = STANDALONE TAGS                            = -->
262 <!-- = (cannot contain any other tags)            = -->
263 <!-- ============================================== -->
264 <xsl:template match="sekcja_swiatlo">
265 <xsl:text>
266
267
268
269 </xsl:text>
270 </xsl:template>
271
272 <xsl:template match="sekcja_asterysk">
273 <xsl:text>
274
275 *
276
277 </xsl:text>
278 </xsl:template>
279
280 <xsl:template match="separator_linia">
281 <xsl:text>
282
283 ------------------------------------------------
284
285 </xsl:text>
286 </xsl:template>
287
288
289 <!-- ================ -->
290 <!-- = SPECIAL TAGS = -->
291 <!-- ================ -->
292 <!-- Themes -->
293 <xsl:template match="begin" mode="inline" />
294
295 <xsl:template match="end" mode="inline" />
296
297 <xsl:template match="begin|end" />
298
299 <xsl:template match="motyw" mode="inline" />
300
301
302 <!-- ================ -->
303 <!-- = IGNORED TAGS = -->
304 <!-- ================ -->
305 <xsl:template match="extra|uwaga" />
306 <xsl:template match="extra|uwaga" mode="inline" />
307
308
309 <!-- ======== -->
310 <!-- = TEXT = -->
311 <!-- ======== -->
312 <xsl:template match="text()" />
313 <xsl:template match="text()" mode="inline">
314     <xsl:value-of select="wl:substitute_entities(.)" />
315 </xsl:template>
316
317
318 </xsl:stylesheet>
319