Added copyright notice about AGPL. Removed setuputils in favour of plain distutils.
[librarian.git] / librarian / xslt / book2txt.xslt
1 <?xml version="1.0" encoding="utf-8"?>
2 <!--
3 #
4 #    This file is part of Librarian.
5 #
6 #    Copyright © 2008,2009,2010 Fundacja Nowoczesna Polska <fundacja@nowoczesnapolska.org.pl>
7 #    
8 #    For full list of contributors see AUTHORS file. 
9 #
10 #    This program is free software: you can redistribute it and/or modify
11 #    it under the terms of the GNU Affero General Public License as published by
12 #    the Free Software Foundation, either version 3 of the License, or
13 #    (at your option) any later version.
14 #
15 #    This program is distributed in the hope that it will be useful,
16 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
17 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 #    GNU Affero General Public License for more details.
19 #
20 #    You should have received a copy of the GNU Affero General Public License
21 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
22 #
23 -->
24 <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
25     xmlns:wl="http://wolnelektury.pl/functions" >
26
27 <xsl:output encoding="utf-8" method="text" />
28
29 <xsl:param name="wrapping" select="0" />
30
31 <!-- ============================================================================== -->
32 <!-- = MASTER TAG                                                                 = -->
33 <!-- = (can contain block tags, paragraph tags, standalone tags and special tags) = -->
34 <!-- ============================================================================== -->
35 <xsl:template match="powiesc|opowiadanie|liryka_l|liryka_lp|dramat_wierszowany_l|dramat_wierszowany_lp|dramat_wspolczesny">
36 <xsl:if test="nazwa_utworu"><xsl:apply-templates select="autor_utworu|dzielo_nadrzedne|nazwa_utworu|podtytul" mode="header" /></xsl:if>
37 <xsl:text>
38
39 </xsl:text>
40 <xsl:apply-templates />
41 </xsl:template>
42
43
44 <!-- ==================================================================================== -->
45 <!-- = BLOCK TAGS                                                                       = -->
46 <!-- = (can contain other block tags, paragraph tags, standalone tags and special tags) = -->
47 <!-- ==================================================================================== -->
48 <xsl:template match="nota">
49 <xsl:apply-templates />
50 </xsl:template>
51
52 <xsl:template match="lista_osob">
53 <xsl:text>
54
55
56 </xsl:text>
57 <xsl:value-of select="naglowek_listy" />
58 <xsl:apply-templates select="lista_osoba" />
59 <xsl:text>
60 </xsl:text>
61 </xsl:template>
62
63 <xsl:template match="dedykacja">
64 <xsl:text>
65
66 </xsl:text>
67 <xsl:apply-templates />
68 </xsl:template>
69
70 <xsl:template match="kwestia">
71 <xsl:apply-templates select="strofa|akap|didaskalia" />
72 </xsl:template>
73
74 <xsl:template match="dlugi_cytat|poezja_cyt">
75 <xsl:text>
76 </xsl:text>
77 <xsl:apply-templates />
78 </xsl:template>
79
80 <xsl:template match="motto">
81 <xsl:text>
82
83
84
85 </xsl:text>
86 <xsl:apply-templates /><xsl:text>
87
88 </xsl:text>
89 </xsl:template>
90
91
92 <!-- ========================================== -->
93 <!-- = PARAGRAPH TAGS                         = -->
94 <!-- = (can contain inline and special tags)  = -->
95 <!-- ========================================== -->
96 <!-- Title page -->
97 <xsl:template match="autor_utworu" mode="header">
98 <xsl:text>
99
100 </xsl:text>
101 <xsl:apply-templates mode="inline" />
102 </xsl:template>
103
104 <xsl:template match="nazwa_utworu" mode="header">
105 <xsl:text>
106
107 </xsl:text>
108 <xsl:apply-templates mode="inline" />
109 </xsl:template>
110
111 <xsl:template match="dzielo_nadrzedne" mode="header">
112 <xsl:text>
113     
114 </xsl:text>
115 <xsl:apply-templates mode="inline" />
116 </xsl:template>
117
118 <xsl:template match="podtytul" mode="header">
119 <xsl:text>
120 </xsl:text>
121 <xsl:apply-templates mode="inline" />
122 </xsl:template>
123
124 <!-- Section headers (included in index)-->
125 <xsl:template match="naglowek_akt|naglowek_czesc|srodtytul">
126 <xsl:text>
127
128
129
130
131 </xsl:text>
132 <xsl:apply-templates mode="inline" />
133 </xsl:template>
134
135 <xsl:template match="naglowek_scena|naglowek_rozdzial">
136 <xsl:text>
137
138
139
140 </xsl:text>
141 <xsl:apply-templates mode="inline" />
142 </xsl:template>
143
144 <xsl:template match="naglowek_osoba|naglowek_podrozdzial">
145 <xsl:text>
146
147
148 </xsl:text>
149 <xsl:apply-templates mode="inline" />
150 </xsl:template>
151
152 <!-- Other paragraph tags -->
153 <xsl:template match="miejsce_czas">
154 <xsl:text>
155
156
157
158 </xsl:text>
159 <xsl:apply-templates mode="inline" />
160 </xsl:template>
161
162 <xsl:template match="didaskalia">
163 <xsl:variable name="content">
164     <xsl:apply-templates select="*|text()" mode="inline" />
165 </xsl:variable>
166 <xsl:text>
167     
168 / </xsl:text><xsl:value-of select="wl:wrap_words(wl:strip($content), $wrapping)" /><xsl:text> /</xsl:text>
169 </xsl:template>
170
171 <xsl:template match="lista_osoba">
172 <xsl:text>
173  * </xsl:text>
174 <xsl:apply-templates mode="inline" />
175 </xsl:template>
176
177 <xsl:template match="akap|akap_dialog|akap_cd">
178 <xsl:variable name="content">
179     <xsl:apply-templates select="*|text()" mode="inline" />
180 </xsl:variable>
181 <xsl:text>
182
183 </xsl:text>
184 <xsl:value-of select="wl:wrap_words(wl:strip($content), $wrapping)" />
185 </xsl:template>
186
187 <xsl:template match="strofa">
188 <xsl:text>
189 </xsl:text>
190     <xsl:choose>
191         <xsl:when test="count(br) > 0">     
192             <xsl:call-template name="verse">
193                 <xsl:with-param name="verse-content" select="br[1]/preceding-sibling::text() | br[1]/preceding-sibling::node()" />
194                 <xsl:with-param name="verse-type" select="br[1]/preceding-sibling::*[name() = 'wers_wciety' or name() = 'wers_akap' or name() = 'wers_cd'][1]" />
195             </xsl:call-template>    
196             <xsl:for-each select="br">          
197                         <!-- Each BR tag "consumes" text after it -->
198                 <xsl:variable name="lnum" select="count(preceding-sibling::br)" />
199                 <xsl:call-template name="verse">
200                     <xsl:with-param name="verse-content" 
201                         select="following-sibling::text()[count(preceding-sibling::br) = $lnum+1] | following-sibling::node()[count(preceding-sibling::br) = $lnum+1]" />
202                     <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]" />
203                 </xsl:call-template>
204             </xsl:for-each>
205         </xsl:when>
206         <xsl:otherwise>
207             <xsl:call-template name="verse">
208                 <xsl:with-param name="verse-content" select="text() | node()" />
209                 <xsl:with-param name="verse-type" select="wers_wciety|wers_akap|wers_cd[1]" />
210              </xsl:call-template>           
211         </xsl:otherwise>
212     </xsl:choose>
213 </xsl:template>
214
215 <xsl:template name="verse">
216     <xsl:param name="verse-content" />
217     <xsl:param name="verse-type" />
218 <xsl:text>
219 </xsl:text>
220     <xsl:variable name="content">
221         <xsl:apply-templates select="$verse-content" mode="inline" />
222     </xsl:variable>
223     <xsl:choose>
224         <xsl:when test="name($verse-type) = 'wers_akap'">
225             <xsl:text>  </xsl:text>
226         </xsl:when>
227         <xsl:when test="name($verse-type) = 'wers_wciety'">
228             <xsl:choose>
229                 <xsl:when test="$verse-content/@typ">
230                     <xsl:text>    </xsl:text>
231                 </xsl:when>
232                 <xsl:otherwise>
233                     <xsl:text>  </xsl:text>
234                 </xsl:otherwise>
235             </xsl:choose>
236         </xsl:when>
237         <xsl:when test="name($verse-type) = 'wers_cd'">
238             <xsl:text>                        </xsl:text>
239         </xsl:when>
240     </xsl:choose>
241 <xsl:value-of select="wl:strip($content)" />
242 </xsl:template>
243
244 <xsl:template match="motto_podpis">
245 <xsl:apply-templates mode="inline" />
246 </xsl:template>
247
248
249 <!-- ================================================ -->
250 <!-- = INLINE TAGS                                  = -->
251 <!-- = (contain other inline tags and special tags) = -->
252 <!-- ================================================ -->
253 <!-- Annotations -->
254 <xsl:template match="pa|pe|pr|pt" mode="inline" />
255
256 <!-- Other inline tags -->
257 <xsl:template match="mat" mode="inline"><xsl:apply-templates mode="inline" /></xsl:template>
258
259 <xsl:template match="didask_tekst" mode="inline"><xsl:apply-templates mode="inline" /></xsl:template>
260
261 <xsl:template match="slowo_obce" mode="inline"><xsl:apply-templates mode="inline" /></xsl:template>
262
263 <xsl:template match="tytul_dziela" mode="inline">
264 <xsl:if test="@typ = '1'">„</xsl:if><xsl:apply-templates mode="inline" /><xsl:if test="@typ = '1'">”</xsl:if>
265 </xsl:template>
266
267 <xsl:template match="wyroznienie" mode="inline">
268 <xsl:text>*</xsl:text><xsl:apply-templates mode="inline" /><xsl:text>*</xsl:text>
269 </xsl:template>
270
271 <xsl:template match="osoba" mode="inline">
272 <xsl:apply-templates mode="inline" />
273 </xsl:template>
274
275
276 <!-- ============================================== -->
277 <!-- = STANDALONE TAGS                            = -->
278 <!-- = (cannot contain any other tags)            = -->
279 <!-- ============================================== -->
280 <xsl:template match="sekcja_swiatlo">
281 <xsl:text>
282
283
284
285 </xsl:text>
286 </xsl:template>
287
288 <xsl:template match="sekcja_asterysk">
289 <xsl:text>
290
291 *
292
293 </xsl:text>
294 </xsl:template>
295
296 <xsl:template match="separator_linia">
297 <xsl:text>
298
299 ------------------------------------------------
300
301 </xsl:text>
302 </xsl:template>
303
304
305 <!-- ================ -->
306 <!-- = SPECIAL TAGS = -->
307 <!-- ================ -->
308 <!-- Themes -->
309 <xsl:template match="begin" mode="inline" />
310
311 <xsl:template match="end" mode="inline" />
312
313 <xsl:template match="begin|end" />
314
315 <xsl:template match="motyw" mode="inline" />
316
317
318 <!-- ================ -->
319 <!-- = IGNORED TAGS = -->
320 <!-- ================ -->
321 <xsl:template match="extra|uwaga" />
322 <xsl:template match="extra|uwaga" mode="inline" />
323
324
325 <!-- ======== -->
326 <!-- = TEXT = -->
327 <!-- ======== -->
328 <xsl:template match="text()" />
329 <xsl:template match="text()" mode="inline">
330     <xsl:value-of select="wl:substitute_entities(.)" />
331 </xsl:template>
332
333
334 </xsl:stylesheet>
335