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