morefloats control
[librarian.git] / librarian / xslt / wl2tex.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     xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" >
12
13 <xsl:output encoding="utf-8" indent="yes" version="2.0" />
14
15 <xsl:template match="utwor">
16     <TeXML xmlns="http://getfo.sourceforge.net/texml/ns1">
17         <TeXML escape="0">
18         \documentclass[a4paper, oneside, 11pt]{book}
19         \usepackage{wl}
20         </TeXML>
21
22         <xsl:choose>
23             <xsl:when test="@morefloats = 'new'">
24                 <TeXML escape="0">
25                     \usepackage[maxfloats=64]{morefloats}
26                 </TeXML>
27             </xsl:when>
28             <xsl:when test="@morefloats = 'old'">
29                 <TeXML escape="0">
30                     \usepackage{morefloats}
31                 </TeXML>
32             </xsl:when>
33             <xsl:when test="@morefloats = 'none'" />
34             <xsl:otherwise>
35                 <TeXML escape="0">
36                     \IfFileExists{morefloats.sty}{
37                         \usepackage{morefloats}
38                     }{}
39                 </TeXML>
40             </xsl:otherwise>
41         </xsl:choose>
42
43         <xsl:apply-templates select="rdf:RDF" mode="titlepage" />
44         <xsl:apply-templates select="powiesc|opowiadanie|liryka_l|liryka_lp|dramat_wierszowany_l|dramat_wierszowany_lp|dramat_wspolczesny" mode='titlepage' />
45
46         <env name="document">
47             <cmd name="maketitle" />
48
49             <xsl:choose>
50                 <xsl:when test="(powiesc|opowiadanie|liryka_l|liryka_lp|dramat_wierszowany_l|dramat_wierszowany_lp|dramat_wspolczesny)/nazwa_utworu">
51                     <xsl:apply-templates select="(powiesc|opowiadanie|liryka_l|liryka_lp|dramat_wierszowany_l|dramat_wierszowany_lp|dramat_wspolczesny)/autor_utworu" mode="title" />
52                     <!-- title in master -->
53                 </xsl:when>
54                 <xsl:otherwise>
55                     <!-- look for author title in dc -->
56                     <xsl:apply-templates select="rdf:RDF" mode="firstdctitle" />
57                     <xsl:apply-templates select="powiesc|opowiadanie|liryka_l|liryka_lp|dramat_wierszowany_l|dramat_wierszowany_lp|dramat_wspolczesny" mode='firstdctitle' />
58                 </xsl:otherwise>
59             </xsl:choose>
60             <xsl:apply-templates select="powiesc|opowiadanie|liryka_l|liryka_lp|dramat_wierszowany_l|dramat_wierszowany_lp|dramat_wspolczesny" />
61             <xsl:apply-templates select="utwor" mode="part" />
62         </env>
63     </TeXML>
64 </xsl:template>
65
66 <xsl:template match="utwor" mode="part">
67     <!-- title for empty dc -->
68     <xsl:choose>
69         <xsl:when test="(powiesc|opowiadanie|liryka_l|liryka_lp|dramat_wierszowany_l|dramat_wierszowany_lp|dramat_wspolczesny)/nazwa_utworu">
70             <!-- title in master -->
71         </xsl:when>
72         <xsl:otherwise>
73             <!-- look for title in dc -->
74             <xsl:apply-templates select="rdf:RDF" mode="dctitle" />
75             <xsl:apply-templates select="powiesc|opowiadanie|liryka_l|liryka_lp|dramat_wierszowany_l|dramat_wierszowany_lp|dramat_wspolczesny" mode='dctitle' />
76         </xsl:otherwise>
77     </xsl:choose>
78
79     <xsl:apply-templates select="powiesc|opowiadanie|liryka_l|liryka_lp|dramat_wierszowany_l|dramat_wierszowany_lp|dramat_wspolczesny" />
80     <xsl:apply-templates select="utwor" mode="part" />
81 </xsl:template>
82
83 <!-- =================== -->
84 <!-- = MAIN TITLE PAGE = -->
85 <!-- = (from DC)       = -->
86 <!-- =================== -->
87
88 <xsl:template match="powiesc|opowiadanie|liryka_l|liryka_lp|dramat_wierszowany_l|dramat_wierszowany_lp|dramat_wspolczesny" mode="titlepage">
89     <xsl:apply-templates select="rdf:RDF" mode="titlepage" />
90 </xsl:template>
91
92 <xsl:template match="rdf:RDF" mode="titlepage">
93     <cmd name='title'><parm>
94         <xsl:apply-templates select=".//dc:title/node()" mode="inline" />
95     </parm></cmd>
96     <cmd name='author'><parm>
97         <xsl:apply-templates select=".//dc:creator_parsed/node()" mode="inline" />
98     </parm></cmd>
99     <TeXML escape="0">
100         \def\sourceinfo{<TeXML escape="1"><xsl:apply-templates select=".//dc:source/node()" mode="inline" /></TeXML>}
101     </TeXML>
102 </xsl:template>
103
104
105 <!-- ============== -->
106 <!-- = BOOK TITLE = -->
107 <!-- = (from DC)  = -->
108 <!-- ============== -->
109
110 <xsl:template match="powiesc|opowiadanie|liryka_l|liryka_lp|dramat_wierszowany_l|dramat_wierszowany_lp|dramat_wspolczesny" mode="dctitle">
111     <xsl:apply-templates select="rdf:RDF" mode="dctitle" />
112 </xsl:template>
113
114 <xsl:template match="rdf:RDF" mode="dctitle">
115     <cmd name="nazwapodutworu"><parm>
116         <xsl:apply-templates select=".//dc:title/node()" mode="inline" />
117     </parm></cmd>
118 </xsl:template>
119
120 <xsl:template match="powiesc|opowiadanie|liryka_l|liryka_lp|dramat_wierszowany_l|dramat_wierszowany_lp|dramat_wspolczesny" mode="firstdctitle">
121     <xsl:apply-templates select="rdf:RDF" mode="firstdctitle" />
122 </xsl:template>
123
124 <xsl:template match="rdf:RDF" mode="firstdctitle">
125     <cmd name="autorutworu"><parm>
126         <xsl:apply-templates select=".//dc:creator_parsed/node()" mode="inline" />
127     </parm></cmd>
128     <cmd name="nazwautworu"><parm>
129         <xsl:apply-templates select=".//dc:title/node()" mode="inline" />
130     </parm></cmd>
131 </xsl:template>
132
133
134 <!-- ============================================================================== -->
135 <!-- = MASTER TAG                                                                 = -->
136 <!-- = (can contain block tags, paragraph tags, standalone tags and special tags) = -->
137 <!-- ============================================================================== -->
138 <!-- ==================================================================================== -->
139 <!-- = BLOCK TAGS                                                                       = -->
140 <!-- = (can contain other block tags, paragraph tags, standalone tags and special tags) = -->
141 <!-- ==================================================================================== -->
142
143 <xsl:template 
144     match="powiesc|opowiadanie|liryka_l|liryka_lp|dramat_wierszowany_l|dramat_wierszowany_lp|dramat_wspolczesny|nota|dedykacja|dlugi_cytat|poezja_cyt|motto">
145     <cmd>
146         <xsl:attribute name="name">
147             <xsl:value-of select="wl:texcommand(name())" />
148         </xsl:attribute>
149         <parm><xsl:apply-templates/></parm>
150     </cmd>
151 </xsl:template>
152
153 <xsl:template match="lista_osob">
154     <cmd name="listaosob">
155         <parm><xsl:apply-templates select="naglowek_listy" /></parm>
156         <parm><xsl:apply-templates select="lista_osoba" /></parm>
157     </cmd>
158 </xsl:template>
159
160 <xsl:template match="kwestia">
161     <cmd name="kwestia">
162         <parm><xsl:apply-templates select="strofa|akap|didaskalia" /></parm>
163     </cmd>
164 </xsl:template>
165
166
167 <!-- ========================================== -->
168 <!-- = PARAGRAPH TAGS                         = -->
169 <!-- = (can contain inline and special tags)  = -->
170 <!-- ========================================== -->
171
172 <!-- only in root -->
173 <xsl:template match="autor_utworu" mode="title">
174     <cmd name="autorutworu"><parm>
175         <xsl:apply-templates mode="inline" />
176     </parm></cmd>
177 </xsl:template>
178
179
180 <xsl:template 
181     match="nazwa_utworu|naglowek_akt|naglowek_czesc|srodtytul|naglowek_osoba|naglowek_podrozdzial|naglowek_scena|naglowek_rozdzial|miejsce_czas|didaskalia|lista_osoba|akap|akap_dialog|akap_cd|motto_podpis|naglowek_listy">
182     <cmd>
183         <xsl:attribute name="name">
184             <xsl:value-of select="wl:texcommand(name())" />
185         </xsl:attribute>
186         <parm><xsl:apply-templates mode="inline"/></parm>
187     </cmd>
188 </xsl:template>
189
190 <xsl:template match="strofa">
191   <cmd name="strofa"><parm>
192     <xsl:choose>
193         <xsl:when test="count(br) > 0">
194             <xsl:call-template name="verse">
195                 <xsl:with-param name="verse-content" select="br[1]/preceding-sibling::text() | br[1]/preceding-sibling::node()" />
196                 <xsl:with-param name="verse-type" select="br[1]/preceding-sibling::*[name() = 'wers_wciety' or name() = 'wers_akap' or name() = 'wers_cd'][1]" />
197             </xsl:call-template>
198             <xsl:for-each select="br">
199                 <TeXML escape="0">\\{}</TeXML>
200                 <!-- Each BR tag "consumes" text after it -->
201                 <xsl:variable name="lnum" select="count(preceding-sibling::br)" />
202                 <xsl:call-template name="verse">
203                     <xsl:with-param name="verse-content"
204                         select="following-sibling::text()[count(preceding-sibling::br) = $lnum+1] | following-sibling::node()[count(preceding-sibling::br) = $lnum+1]" />
205                     <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]" />
206                 </xsl:call-template>
207             </xsl:for-each>
208         </xsl:when>
209         <xsl:otherwise>
210             <xsl:call-template name="verse">
211                 <xsl:with-param name="verse-content" select="text() | node()" />
212                 <xsl:with-param name="verse-type" select="wers_wciety|wers_akap|wers_cd[1]" />
213             </xsl:call-template>
214         </xsl:otherwise>
215     </xsl:choose>
216   </parm></cmd>
217 </xsl:template>
218
219
220 <xsl:template name="verse">
221     <xsl:param name="verse-content" />
222     <xsl:param name="verse-type" />
223
224     <cmd>
225         <xsl:attribute name="name">
226             <xsl:choose>
227                 <xsl:when test="$verse-type != ''">
228                     <xsl:value-of select='wl:texcommand(name($verse-type))' />
229                 </xsl:when>
230                 <xsl:otherwise>wers</xsl:otherwise>
231             </xsl:choose>
232         </xsl:attribute>
233         <xsl:if test="string($verse-content/@typ)">
234             <opt><xsl:value-of select="$verse-content/@typ" />em</opt>
235         </xsl:if>
236         <parm><xsl:apply-templates select="$verse-content" mode="inline"/></parm>
237     </cmd>
238 </xsl:template>
239
240 <!-- ================================================ -->
241 <!-- = INLINE TAGS                                  = -->
242 <!-- = (contain other inline tags and special tags) = -->
243 <!-- ================================================ -->
244
245 <xsl:template mode="inline"
246     match="pa|pe|pr|pt|mat|didask_tekst|slowo_obce|wyroznienie|osoba">
247     <cmd>
248         <xsl:attribute name="name">
249             <xsl:value-of select="wl:texcommand(name())" />
250         </xsl:attribute>
251         <parm><xsl:apply-templates mode="inline"/></parm>
252     </cmd>
253 </xsl:template>
254
255
256
257 <xsl:template match="tytul_dziela" mode="inline">
258     <cmd name="tytuldziela"><parm>
259         <xsl:if test="@typ = '1'">„</xsl:if><xsl:apply-templates mode="inline" /><xsl:if test="@typ = '1'">”</xsl:if>
260     </parm></cmd>
261 </xsl:template>
262
263
264
265 <!-- ============================================== -->
266 <!-- = STANDALONE TAGS                            = -->
267 <!-- = (cannot contain any other tags)            = -->
268 <!-- ============================================== -->
269 <xsl:template
270     match="sekcja_swiatlo|sekcja_asterysk|separator_linia">
271     <cmd>
272         <xsl:attribute name="name">
273             <xsl:value-of select="wl:texcommand(name())" />
274         </xsl:attribute>
275     </cmd>
276 </xsl:template>
277
278
279 <!-- ================ -->
280 <!-- = SPECIAL TAGS = -->
281 <!-- ================ -->
282 <!-- Themes -->
283
284
285 <xsl:template match="begin|end|motyw">
286     <xsl:apply-templates select='.' mode="inline" />
287 </xsl:template>
288
289 <xsl:template match="begin" mode="inline" />
290 <xsl:template match="end" mode="inline" />
291
292 <xsl:template match="motyw" mode="inline">
293     <cmd name="motyw">
294         <xsl:if test="@moved">
295             <opt name="moved"><xsl:value-of select="@moved" /></opt>
296         </xsl:if>
297         <parm><xsl:apply-templates mode="inline" /></parm>
298     </cmd>
299 </xsl:template>
300
301
302 <!-- ============== -->
303 <!-- = ADDED TAGS = -->
304 <!-- ============== -->
305
306
307 <xsl:template match="dywiz" mode="inline">
308     <cmd name="dywiz" />
309 </xsl:template>
310
311 <xsl:template match="nbsp" mode="inline">
312     <spec cat="tilde" />
313 </xsl:template>
314
315 <!-- ================ -->
316 <!-- = IGNORED TAGS = -->
317 <!-- ================ -->
318 <xsl:template match="extra|uwaga" />
319 <xsl:template match="extra|uwaga" mode="inline" />
320
321 <xsl:template match="nota_red" />
322
323 <!-- ======== -->
324 <!-- = TEXT = -->
325 <!-- ======== -->
326 <xsl:template match="text()" />
327 <xsl:template match="text()" mode="inline">
328     <xsl:if test="preceding-sibling::node() and wl:starts_white(.)">
329       <xsl:text> </xsl:text>
330     </xsl:if>
331
332     <xsl:value-of select="wl:substitute_entities(wl:strip(.))" />
333
334     <xsl:if test="following-sibling::node() and wl:ends_white(.)">
335       <xsl:text> </xsl:text>
336     </xsl:if>
337 </xsl:template>
338
339
340 </xsl:stylesheet>