Updated book2txt.py.
[wolnelektury.git] / lib / librarian / book2html.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" indent="yes" omit-xml-declaration = "yes" />
5
6
7 <xsl:template match="utwor">
8     <!-- <html>
9         <head>
10             <title>book2html output</title>
11             <meta http-equiv="content-type" content="text/html;charset=utf-8"/>
12             <link rel="stylesheet" href="master.css" type="text/css" media="all" charset="utf-8" />
13         </head>
14         <body> -->
15         <div id="book-text">
16             <xsl:apply-templates select="powiesc|opowiadanie|liryka_l|liryka_lp|dramat_wierszowany_l|dramat_wierszowany_lp|dramat_wspolczesny" />
17             <xsl:if test="count(descendant::*[self::pe or self::pa or self::pr or self::pt][not(parent::extra)])">
18                 <div id="footnotes">
19                     <h3>Przypisy</h3>
20                     <xsl:for-each select="descendant::*[self::pe or self::pa or self::pr or self::pt][not(parent::extra)]">
21                         <div>
22                             <a name="{concat('footnote-', generate-id(.))}" />
23                             <a href="{concat('#anchor-', generate-id(.))}" class="annotation">[<xsl:number value="count(preceding::*[self::pa or self::pe or self::pr or self::pt]) + 1" />]</a>
24                             <xsl:choose>
25                                 <xsl:when test="count(akap|akap_cd|strofa) = 0">
26                                     <p><xsl:apply-templates select="text()|*" mode="inline" /></p>
27                                 </xsl:when>
28                                 <xsl:otherwise>
29                                     <xsl:apply-templates select="text()|*" mode="inline" />
30                                 </xsl:otherwise>
31                             </xsl:choose>
32                         </div>
33                     </xsl:for-each>
34                 </div>
35             </xsl:if>
36         </div>
37         <!-- </body>
38     </html> -->
39 </xsl:template>
40
41
42 <!-- ============================================================================== -->
43 <!-- = MASTER TAG                                                                 = -->
44 <!-- = (can contain block tags, paragraph tags, standalone tags and special tags) = -->
45 <!-- ============================================================================== -->
46 <xsl:template match="powiesc|opowiadanie|liryka_l|liryka_lp|dramat_wierszowany_l|dramat_wierszowany_lp|dramat_wspolczesny">
47     <xsl:if test="nazwa_utworu">
48         <h1>
49             <xsl:apply-templates select="autor_utworu|dzielo_nadrzedne|nazwa_utworu|podtytul" mode="header" />
50         </h1>
51     </xsl:if>
52     <xsl:apply-templates />
53 </xsl:template>
54
55
56 <!-- ==================================================================================== -->
57 <!-- = BLOCK TAGS                                                                       = -->
58 <!-- = (can contain other block tags, paragraph tags, standalone tags and special tags) = -->
59 <!-- ==================================================================================== -->
60 <xsl:template match="nota">
61     <div class="note"><xsl:apply-templates /></div>
62 </xsl:template>
63
64 <xsl:template match="lista_osob">
65     <div class="person-list">
66         <h3><xsl:value-of select="naglowek_listy" /></h3>
67         <ol>
68             <xsl:apply-templates select="lista_osoba" />
69         </ol>
70     </div>
71 </xsl:template>
72
73 <xsl:template match="dedykacja">
74     <div class="dedication"><xsl:apply-templates /></div>
75 </xsl:template>
76
77 <xsl:template match="kwestia">
78     <div class="kwestia">
79         <xsl:apply-templates select="strofa|akap" />
80     </div>
81 </xsl:template>
82
83 <xsl:template match="dlugi_cytat|poezja_cyt">
84     <blockquote><xsl:apply-templates /></blockquote>
85 </xsl:template>
86
87 <xsl:template match="motto">
88     <div class="motto"><xsl:apply-templates mode="inline" /></div>
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     <span class="author"><xsl:apply-templates mode="inline" /></span>
99 </xsl:template>
100
101 <xsl:template match="nazwa_utworu" mode="header">
102     <span class="title"><xsl:apply-templates mode="inline" /></span>
103 </xsl:template>
104
105 <xsl:template match="dzielo_nadrzedne" mode="header">
106     <span class="collection"><xsl:apply-templates mode="inline" /></span>
107 </xsl:template>
108
109 <xsl:template match="podtytul" mode="header">
110     <span class="subtitle"><xsl:apply-templates mode="inline" /></span>
111 </xsl:template>
112
113 <!-- Section headers (included in index)-->
114 <xsl:template match="naglowek_akt|naglowek_czesc|srodtytul">
115     <h2><xsl:apply-templates mode="inline" /></h2>
116 </xsl:template>
117
118 <xsl:template match="naglowek_scena|naglowek_rozdzial">
119     <h3><xsl:apply-templates mode="inline" /></h3>
120 </xsl:template>
121
122 <xsl:template match="naglowek_osoba|naglowek_podrozdzial">
123     <h4><xsl:apply-templates mode="inline" /></h4>
124 </xsl:template>
125
126 <!-- Other paragraph tags -->
127 <xsl:template match="miejsce_czas">
128     <p class="place-and-time"><xsl:apply-templates mode="inline" /></p>
129 </xsl:template>
130
131 <xsl:template match="didaskalia">
132     <div class="didaskalia"><xsl:apply-templates mode="inline" /></div>
133 </xsl:template>
134
135 <xsl:template match="lista_osoba">
136     <li><xsl:apply-templates mode="inline" /></li>
137 </xsl:template>
138
139 <xsl:template match="akap|akap_dialog|akap_cd">
140     <p class="paragraph"><xsl:apply-templates mode="inline" /></p>
141 </xsl:template>
142
143 <xsl:template match="strofa">
144     <div class="stanza">
145         <xsl:choose>
146             <xsl:when test="count(br) > 0">     
147                 <xsl:call-template name="verse">
148                     <xsl:with-param name="line-content" select="br[1]/preceding-sibling::text() | br[1]/preceding-sibling::node()" />
149                     <xsl:with-param name="line-number" select="1" />
150                 </xsl:call-template>    
151                 <xsl:for-each select="br">              
152                                 <!-- Each BR tag "consumes" text after it -->
153                     <xsl:variable name="lnum" select="count(preceding-sibling::br)" />
154                     <xsl:call-template name="verse">
155                         <xsl:with-param name="line-number" select="$lnum+2" />
156                         <xsl:with-param name="line-content" 
157                             select="following-sibling::text()[count(preceding-sibling::br) = $lnum+1] | following-sibling::node()[count(preceding-sibling::br) = $lnum+1]" />
158                     </xsl:call-template>
159                 </xsl:for-each>
160             </xsl:when>
161             <xsl:otherwise>
162                 <xsl:call-template name="verse">
163                     <xsl:with-param name="line-content" select="text() | node()" />
164                     <xsl:with-param name="line-number" select="1" />
165                  </xsl:call-template>           
166             </xsl:otherwise>
167         </xsl:choose>
168     </div>
169 </xsl:template>
170
171 <xsl:template name="verse">
172     <xsl:param name="line-content" />
173     <xsl:param name="line-number" />
174     <p class="verse">
175         <xsl:choose>
176             <xsl:when test="name($line-content) = 'wers_akap'">
177                 <xsl:attribute name="style">padding-left: 1em</xsl:attribute>
178             </xsl:when>
179             <xsl:when test="name($line-content) = 'wers_wciety'">
180                 <xsl:attribute name="style">padding-left: <xsl:value-of select="$line-content/@typ" />em</xsl:attribute>
181             </xsl:when>
182         </xsl:choose>
183         <xsl:apply-templates select="$line-content" mode="inline" />
184     </p>
185 </xsl:template>
186
187 <xsl:template match="motto_podpis">
188     <p class="motto_podpis"><xsl:apply-templates mode="inline" /></p>
189 </xsl:template>
190
191
192 <!-- ================================================ -->
193 <!-- = INLINE TAGS                                  = -->
194 <!-- = (contain other inline tags and special tags) = -->
195 <!-- ================================================ -->
196 <!-- Annotations -->
197 <xsl:template match="pa|pe|pr|pt" mode="inline">
198     <a name="{concat('anchor-', generate-id(.))}" />
199     <a href="{concat('#footnote-', generate-id(.))}" class="annotation">[<xsl:number value="count(preceding::*[self::pa or self::pe or self::pr or self::pt]) + 1" />]</a>
200 </xsl:template>
201
202 <!-- Other inline tags -->
203 <xsl:template match="mat" mode="inline">
204     <em class="math"><xsl:apply-templates mode="inline" /></em>
205 </xsl:template>
206
207 <xsl:template match="didask_tekst" mode="inline">
208     <em class="didaskalia"><xsl:apply-templates mode="inline" /></em>
209 </xsl:template>
210
211 <xsl:template match="slowo_obce" mode="inline">
212     <em class="foreign-word"><xsl:apply-templates mode="inline" /></em>
213 </xsl:template>
214
215 <xsl:template match="tytul_dziela" mode="inline">
216     <em class="book-title">
217         <xsl:if test="@typ = '1'">„</xsl:if><xsl:apply-templates mode="inline" /><xsl:if test="@typ = '1'">”</xsl:if>
218     </em>
219 </xsl:template>
220
221 <xsl:template match="wyroznienie" mode="inline">
222     <em class="author-emphasis"><xsl:apply-templates mode="inline" /></em>
223 </xsl:template>
224
225 <xsl:template match="osoba" mode="inline">
226     <em class="person"><xsl:apply-templates mode="inline" /></em>
227 </xsl:template>
228
229
230 <!-- ============================================== -->
231 <!-- = STANDALONE TAGS                            = -->
232 <!-- = (cannot contain any other tags)            = -->
233 <!-- ============================================== -->
234 <xsl:template match="sekcja_swiatlo">
235     <hr class="spacer" />
236 </xsl:template>
237
238 <xsl:template match="sekcja_asterysk">
239     <p class="spacer-asterisk">*</p>
240 </xsl:template>
241
242 <xsl:template match="separator_linia">
243     <hr class="spacer-line" />
244 </xsl:template>
245
246
247 <!-- ================ -->
248 <!-- = SPECIAL TAGS = -->
249 <!-- ================ -->
250 <!-- Themes -->
251 <xsl:template match="begin" mode="inline">
252     <xsl:variable name="mnum" select="concat('m', substring(@id, 2))" />
253     <a name="m{substring(@id, 2)}" class="theme-begin" fid="{substring(@id, 2)}">
254         <xsl:value-of select="string(following::motyw[@id=$mnum]/text())" />
255     </a>
256 </xsl:template>
257
258 <xsl:template match="end" mode="inline">
259     <span class="theme-end" fid="{substring(@id, 2)}"> </span>
260 </xsl:template>
261
262 <xsl:template match="begin|end">
263     <xsl:apply-templates select='.' mode="inline" />
264 </xsl:template>
265
266 <xsl:template match="motyw" mode="inline" />
267
268
269 <!-- ================ -->
270 <!-- = IGNORED TAGS = -->
271 <!-- ================ -->
272 <xsl:template match="extra|uwaga" />
273 <xsl:template match="extra|uwaga" mode="inline" />
274
275
276 <!-- ======== -->
277 <!-- = TEXT = -->
278 <!-- ======== -->
279 <xsl:template match="text()" />
280 <xsl:template match="text()" mode="inline">
281     <xsl:value-of select="wl:substitute_entities(.)" />
282 </xsl:template>
283
284
285 </xsl:stylesheet>
286