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