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