fddb2c46aea2f4e130496eb34cf5bdee628010dc
[librarian.git] / librarian / xslt / wl2fo.xslt
1 <?xml version="1.0" encoding="utf-8"?>
2 <xsl:stylesheet
3     version="1.0"
4
5     xmlns:wlml="http://nowoczesnapolska.org.pl/ML/Lektury/1.1"
6
7     xmlns:xsl="http://www.w3.org/1999/XSL/Transform"   
8     xmlns:fo="http://www.w3.org/1999/XSL/Format"
9     xmlns:wl="http://wolnelektury.pl/functions" >
10
11     <xsl:output method="xml"
12         encoding="utf-8"
13         indent="yes"
14         omit-xml-declaration = "yes" />
15
16 <!-- generic template parameters -->
17
18     <xsl:param name="verse-numbers-interval" select="5" />
19
20 <!-- main templates -->
21
22     <xsl:template match="/">
23         <fo:root >
24
25             <fo:layout-master-set>
26     <!-- layout information -->
27                 <fo:simple-page-master
28                     master-name="title-page"
29                   page-height="29.7cm"
30                   page-width="21cm"
31                   margin-top="2.5cm"
32                   margin-bottom="2.5cm"
33                   margin-left="2.5cm"
34                   margin-right="2.5cm">      
35                     <fo:region-body />     
36                 </fo:simple-page-master>
37
38                 <fo:simple-page-master
39                     master-name="blank-page"
40                     page-height="29.7cm"
41                     page-width="21cm"
42
43                     margin-top="2.5cm"
44                     margin-bottom="2.5cm"
45                     margin-left="2.5cm"
46                     margin-right="2.5cm">
47                     <fo:region-body />
48                 </fo:simple-page-master>
49
50                 <fo:simple-page-master
51         master-name="first-main"
52                   page-height="29.7cm"
53                   page-width="21cm"
54                   margin-top="2cm"
55                   margin-bottom="2cm"
56                   margin-left="3cm"
57                   margin-right="2cm">
58                     <fo:region-body
59                 margin-top="2cm"
60                 margin-bottom="2cm" />
61                     <fo:region-after
62                 region-name="odd-after"
63                 display-align="after"
64                 extent="2cm" />
65                 </fo:simple-page-master>
66
67                 <fo:simple-page-master
68         master-name="odd"
69                   page-height="29.7cm"
70                   page-width="21cm"
71                   margin-top="2cm"
72                   margin-bottom="2cm"
73                   margin-left="3cm"
74                   margin-right="2cm">
75                     <fo:region-body
76                 margin-top="2cm"
77                 margin-bottom="2cm" />
78
79                     <fo:region-before
80                 region-name="odd-before"
81                 extent="2cm" />
82
83                     <fo:region-after
84                 region-name="odd-after"
85                 display-align="after"
86                 extent="2cm" />
87                 </fo:simple-page-master>
88
89                 <fo:simple-page-master
90         master-name="even"
91                   page-height="29.7cm"
92                   page-width="21cm"
93                   margin-top="2cm"
94                   margin-bottom="2cm"
95                   margin-left="2cm"
96                   margin-right="3cm">
97                     <fo:region-body
98                 margin-top="2cm"
99                 margin-bottom="2cm" />
100
101                     <fo:region-before
102                 region-name="even-before"
103                 extent="2cm" />
104
105                     <fo:region-after
106                 region-name="even-after"
107                 display-align="after"
108                 extent="2cm" />
109                 </fo:simple-page-master>
110
111
112                 <fo:page-sequence-master master-name="book-titles">
113                     <fo:single-page-master-reference master-reference="title-page" />
114                     <fo:repeatable-page-master-reference master-reference="blank-page" />
115                 </fo:page-sequence-master>
116
117                 <fo:page-sequence-master master-name="main">
118                     <fo:repeatable-page-master-alternatives>
119                         <fo:conditional-page-master-reference
120                 master-reference="first-main"
121                 page-position="first"
122                 odd-or-even="odd" />
123
124                         <fo:conditional-page-master-reference
125                 master-reference="odd"
126                 page-position="rest"
127                 odd-or-even="odd" />
128
129                         <fo:conditional-page-master-reference
130                 master-reference="even"
131                 page-position="any"
132                 odd-or-even="even" />                
133                     </fo:repeatable-page-master-alternatives>
134
135                 </fo:page-sequence-master>
136
137             </fo:layout-master-set>
138   <!-- end: defines page layout -->
139
140 <!--
141     TITLE PAGE, COPYRIGHT, ETC. \
142 -->
143             <fo:page-sequence
144                 master-reference="book-titles">
145
146                 <fo:flow flow-name="xsl-region-body"
147                     font-family="Antique"
148                     text-align="center"
149                 >
150
151                     <fo:block font-size="32pt" display-align="center" >
152                         <fo:marker marker-class-name="author">
153                             <xsl:value-of select="//wlml:author" />
154                         </fo:marker>
155                         <xsl:apply-templates select="//wlml:author/node()" mode="title"/>
156                     </fo:block>
157   
158                     <fo:block font-size="48pt" display-align="center" >
159                         <fo:marker marker-class-name="main-title">
160                             <xsl:value-of select="//wlml:title" />
161                         </fo:marker>
162                         <xsl:apply-templates select="//wlml:title/node()" mode="title"/>
163                     </fo:block>
164                 </fo:flow>
165             </fo:page-sequence>
166
167 <!--
168     MAIN BOOK CONTENT
169 -->
170             <fo:page-sequence
171         master-reference="main"
172         initial-page-number="1"
173         force-page-count="even"
174     >
175
176     <fo:static-content
177      flow-name="xsl-footnote-separator">
178       <fo:block text-align-last="justify">
179         <fo:leader leader-pattern="rule"/>
180       </fo:block>
181     </fo:static-content>
182
183                 <fo:static-content
184                     flow-name="odd-after" font-family="Antique" text-align="center">
185                     <fo:block>
186                         <fo:page-number />
187                     </fo:block>
188                 </fo:static-content>
189
190                 <fo:static-content
191                     flow-name="even-after" font-family="Antique" text-align="center">
192                     <fo:block>
193                         <fo:page-number />
194                     </fo:block>
195                 </fo:static-content>
196
197
198                 <fo:static-content
199         flow-name="even-before"
200         font-family="Antique"
201         text-align="right">
202
203                     <fo:block border-bottom-width="0.2mm"
204         border-bottom-style="solid"
205         border-bottom-color="black">
206                         <fo:retrieve-marker retrieve-class-name="main-title" />
207                     </fo:block>
208                 </fo:static-content>
209
210                 <fo:static-content
211         flow-name="odd-before"
212         font-family="Antique"
213         text-align="left">
214    
215                     <fo:block border-after-width="0.2mm"
216         border-after-style="solid"
217         border-after-color="black">
218                         <fo:retrieve-marker retrieve-class-name="chapter-title" />
219                     </fo:block>
220                 </fo:static-content>
221
222
223     
224                 <fo:flow flow-name="xsl-region-body" font-family="Antique">
225         
226                     <fo:marker marker-class-name="author">
227                         <xsl:value-of select="//wlml:author" />
228                     </fo:marker>
229                     <fo:marker marker-class-name="main-title">
230                         <xsl:value-of select="//wlml:title" />
231                     </fo:marker>
232
233                     <xsl:apply-templates select="//wlml:main-text" />
234                 </fo:flow>
235     
236             </fo:page-sequence>
237         </fo:root>
238     </xsl:template>
239
240     <xsl:template match="wlml:main-text">        
241         <xsl:apply-templates select="child::*" />
242     </xsl:template>
243
244 <!-- 
245     PROZA: elementy proste 
246 -->
247
248     <xsl:template match="wlml:chapter">
249         <fo:block text-align="left" font-size="32pt" font-weight="bold" font-variant="small-caps">
250             <fo:marker marker-class-name="chapter-title">
251                 <xsl:apply-templates select="node()" />
252             </fo:marker>
253             <xsl:apply-templates select="node()" />            
254         </fo:block>
255     </xsl:template>
256
257     <xsl:template match="wlml:p">
258         <fo:block
259         space-before="1em" 
260         space-after="1em" 
261         start-indent="1.5em">        
262             <xsl:apply-templates select="child::node()" />
263         </fo:block>
264     </xsl:template>
265
266     <xsl:template match="wlml:pd">
267         <fo:block
268         space-before="1em" 
269         space-after="1em" 
270         start-indent="0em"
271     >&#x2014;&#x00a0;
272             <xsl:apply-templates select="child::node()" />
273         </fo:block>
274     </xsl:template>
275
276     <xsl:template match="wlml:pd/text()[1]">
277         <xsl:value-of select="substring-after(., '&#x2014; ')" />
278     </xsl:template>
279
280 <!-- 
281     POEZJA
282 -->
283     <xsl:template match="wlml:stanza">
284         <fo:list-block
285             space-before="1.5em" space-after="1.5em">
286             <xsl:apply-templates select="child::node()" />            
287         </fo:list-block>
288     </xsl:template>
289
290     <xsl:template match="wlml:v|wlml:vi|wlml:vc">
291         <fo:list-item>
292             <xsl:attribute name="id"><xsl:value-of select="local-name()"/>-<xsl:value-of select="generate-id()"/></xsl:attribute>
293
294             <xsl:if test="count(preceding-sibling::wlml:v|preceding-sibling::wlml:vi|preceding-sibling::wlml:vc) &lt; 2">
295                 <xsl:attribute name="keep-with-previous.within-page">always</xsl:attribute>
296             </xsl:if>
297
298             <xsl:if test="count(following-sibling::wlml:v|following-sibling::wlml:vi|following-sibling::wlml:vc) &lt; 2">
299                 <xsl:attribute name="keep-with-next.within-page">always</xsl:attribute>
300             </xsl:if>
301
302             <xsl:variable name="vc"><xsl:number count="wlml:v|wlml:vi|wlml:vc" level="any" from="wlml:chapter" /></xsl:variable>
303
304             <fo:list-item-label start-indent="-1cm">
305                 <fo:block><xsl:if test="($vc mod 5) = 0"><xsl:value-of select="$vc" /></xsl:if></fo:block>
306             </fo:list-item-label>
307             <fo:list-item-body start-indent="0cm">
308                 <fo:block><xsl:apply-templates select="node()" /></fo:block>
309             </fo:list-item-body>
310         </fo:list-item>
311     </xsl:template>
312
313 <!--
314     Wyroznienia
315 -->
316     <xsl:template match="wlml:df">
317         <fo:inline font-style="italic">
318             <xsl:apply-templates select="node()" />
319         </fo:inline>
320     </xsl:template>
321
322
323 <!--
324     Przypisy
325 -->
326 <xsl:template match="wlml:mark[//wlml:annotation/@refs = @id]">
327     <xsl:variable name="annot" select="//wlml:annotation[@refs = current()/@id]" />
328     <fo:footnote>
329         <fo:inline><xsl:number level="any" /></fo:inline>
330         <fo:footnote-body>
331             <fo:block><xsl:apply-templates select="$annot/node()" /></fo:block>
332         </fo:footnote-body>
333     </fo:footnote>
334 </xsl:template>
335
336 <xsl:template match="*" />
337
338 </xsl:stylesheet>