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