f52d830892ad0f6ee1d4763fbf697c794ce59da8
[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 <xsl:template match="text()" />
7 <xsl:template match="text()" mode="inline">
8     <xsl:value-of select="wl:substitute_entities(.)" />
9 </xsl:template>
10
11 <xsl:template match="extra|uwaga" />
12 <xsl:template match="extra|uwaga" mode="inline" />
13
14 <xsl:template match="utwor">
15     <html>
16         <head>
17             <title>book2html output</title>
18             <meta http-equiv="content-type" content="text/html;charset=utf-8"/>
19             <link rel="stylesheet" href="master.css" type="text/css" media="all" charset="utf-8" />
20         </head>
21         <body>
22             <xsl:apply-templates select="powiesc|opowiadanie|liryka_l|liryka_lp|dramat_wierszowany_l|dramat_wierszowany_lp|dramat_wspolczesny" />
23             <xsl:if test="count(descendant::*[self::pe or self::pa or self::pr or self::pt][not(parent::extra)])">
24                 <div id="footnotes">
25                     <h3>Przypisy</h3>
26                     <xsl:for-each select="descendant::*[self::pe or self::pa or self::pr or self::pt][not(parent::extra)]">
27                         <div>
28                             <a name="{concat('footnote-', generate-id(.))}" />
29                             <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>
30                             <xsl:choose>
31                                 <xsl:when test="count(akap|akap_cd|strofa) = 0">
32                                     <p><xsl:apply-templates select="text()|*" mode="inline" /></p>
33                                 </xsl:when>
34                                 <xsl:otherwise>
35                                     <xsl:apply-templates select="text()|*" mode="inline" />
36                                 </xsl:otherwise>
37                             </xsl:choose>
38                         </div>
39                     </xsl:for-each>
40                 </div>
41             </xsl:if>
42         </body>
43     </html>
44 </xsl:template>
45
46
47 <xsl:template match="powiesc|opowiadanie|liryka_l|liryka_lp|dramat_wierszowany_l|dramat_wierszowany_lp|dramat_wspolczesny">
48     <xsl:if test="nazwa_utworu">
49         <h1>
50             <xsl:apply-templates select="autor_utworu|dzielo_nadrzedne|nazwa_utworu|podtytul" mode="header" />
51         </h1>
52     </xsl:if>
53     <xsl:apply-templates />
54 </xsl:template>
55
56 <!-- ======================= -->
57 <!-- = Header (title page) = -->
58 <!-- ======================= -->
59 <xsl:template match="autor_utworu" mode="header">
60     <span class="author"><xsl:apply-templates mode="inline" /></span>
61 </xsl:template>
62
63 <xsl:template match="nazwa_utworu" mode="header">
64     <span class="title"><xsl:apply-templates mode="inline" /></span>
65 </xsl:template>
66
67 <xsl:template match="dzielo_nadrzedne" mode="header">
68     <span class="collection"><xsl:apply-templates mode="inline" /></span>
69 </xsl:template>
70
71 <xsl:template match="podtytul" mode="header">
72     <span class="subtitle"><xsl:apply-templates mode="inline" /></span>
73 </xsl:template>
74
75 <xsl:template match="nota">
76     <div class="note"><xsl:apply-templates /></div>
77 </xsl:template>
78
79 <xsl:template match="naglowek_akt|naglowek_czesc|srodtytul">
80     <h2><xsl:apply-templates mode="inline" /></h2>
81 </xsl:template>
82
83 <xsl:template match="naglowek_scena|naglowek_rozdzial">
84     <h3><xsl:apply-templates mode="inline" /></h3>
85 </xsl:template>
86
87 <xsl:template match="naglowek_osoba">
88     <h4><xsl:apply-templates mode="inline" /></h4>
89 </xsl:template>
90
91 <xsl:template match="kwestia">
92     <div class="kwestia">
93         <xsl:apply-templates select="strofa|akap" />
94     </div>
95 </xsl:template>
96
97 <xsl:template match="didaskalia">
98     <div class="didaskalia"><xsl:apply-templates mode="inline" /></div>
99 </xsl:template>
100
101 <xsl:template match="lista_osob">
102     <div class="person-list">
103         <h3><xsl:value-of select="naglowek_listy" /></h3>
104         <ol>
105             <xsl:apply-templates select="lista_osoba" />
106         </ol>
107     </div>
108 </xsl:template>
109
110 <xsl:template match="lista_osoba">
111     <li><xsl:apply-templates mode="inline" /></li>
112 </xsl:template>
113
114 <xsl:template match="begin" mode="inline">
115     <xsl:variable name="mnum" select="concat('m', substring(@id, 2))" />
116     <span class="theme-begin" fid="{substring(@id, 2)}">
117         <xsl:value-of select="string(following::motyw[@id=$mnum]/text())" />
118     </span>
119 </xsl:template>
120
121 <xsl:template match="end" mode="inline">
122     <span class="theme-end" fid="{substring(@id, 2)}"> </span>
123 </xsl:template>
124
125 <xsl:template match="begin|end">
126     <xsl:apply-templates select='.' mode="inline" />
127 </xsl:template>
128
129 <xsl:template name="verse">
130     <xsl:param name="line-content" />
131     <xsl:param name="line-number" />
132     <p>
133         <xsl:choose>
134             <xsl:when test="name($line-content) = 'wers_akap'">
135                 <xsl:attribute name="style">indent: 1em</xsl:attribute>
136             </xsl:when>
137             <xsl:when test="name($line-content) = 'wers_wciety'">
138                 <xsl:attribute name="style">indent: 2em</xsl:attribute>
139             </xsl:when>
140         </xsl:choose>
141         <xsl:apply-templates select="$line-content" mode="inline" />
142     </p>
143 </xsl:template>
144
145 <xsl:template match="pa|pe|pr|pt" mode="inline">
146     <a name="{concat('anchor-', generate-id(.))}" />
147     <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>
148 </xsl:template>
149
150 <xsl:template match="strofa">
151     <div class="stanza">
152         <xsl:choose>
153             <xsl:when test="count(br) > 0">     
154                 <xsl:call-template name="verse">
155                     <xsl:with-param name="line-content" select="br[1]/preceding-sibling::text() | br[1]/preceding-sibling::node()" />
156                     <xsl:with-param name="line-number" select="1" />
157                 </xsl:call-template>    
158                 <xsl:for-each select="br">              
159                                 <!-- Każdy BR "zjada" to co jest za nim -->
160                     <xsl:variable name="lnum" select="count(preceding-sibling::br)" />
161                     <xsl:call-template name="verse">
162                         <xsl:with-param name="line-number" select="$lnum+2" />
163                         <xsl:with-param name="line-content" 
164                             select="following-sibling::text()[count(preceding-sibling::br) = $lnum+1] | following-sibling::node()[count(preceding-sibling::br) = $lnum+1]" />
165                     </xsl:call-template>
166                 </xsl:for-each>
167             </xsl:when>
168             <xsl:otherwise>
169                 <xsl:call-template name="verse">
170                     <xsl:with-param name="line-content" select="text() | node()" />
171                     <xsl:with-param name="line-number" select="1" />
172                  </xsl:call-template>           
173             </xsl:otherwise>
174         </xsl:choose>
175     </div>
176 </xsl:template>
177
178 <xsl:template match="akap|akap_dialog|akap_cd">
179     <p class="paragraph"><xsl:apply-templates mode="inline" /></p>
180 </xsl:template>
181
182 <xsl:template match="motyw" mode="inline" />
183
184 <xsl:template match="dlugi_cytat">
185     <blockquote><xsl:apply-templates /></blockquote>
186 </xsl:template>
187
188 <xsl:template match="motto">
189     <p class="motto"><xsl:apply-templates mode="inline" /></p>
190 </xsl:template>
191
192 <xsl:template match="motto_podpis">
193     <p class="motto_podpis"><xsl:apply-templates mode="inline" /></p>
194 </xsl:template>
195
196 <xsl:template match="sekcja_swiatlo">
197     <hr class="spacer" />
198 </xsl:template>
199
200 </xsl:stylesheet>