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