f3223d78c420db0118d72b006d60492835b08b22
[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 <xsl:template match="powiesc|opowiadanie|liryka_l|liryka_lp|dramat_wierszowany_l|dramat_wierszowany_lp|dramat_wspolczesny">
42     <xsl:apply-templates />
43 </xsl:template>
44
45 <xsl:template match="naglowek_akt|naglowek_czesc">
46     <h2><xsl:apply-templates mode="inline" /></h2>
47 </xsl:template>
48
49 <xsl:template match="naglowek_scena|naglowek_rozdzial">
50     <h3><xsl:apply-templates mode="inline" /></h3>
51 </xsl:template>
52
53 <xsl:template match="naglowek_osoba">
54     <h4><xsl:apply-templates mode="inline" /></h4>
55 </xsl:template>
56
57 <xsl:template match="kwestia">
58     <div class="kwestia">
59         <xsl:apply-templates select="strofa|akap" />
60     </div>
61 </xsl:template>
62
63 <xsl:template match="didaskalia">
64     <div class="didaskalia"><xsl:apply-templates mode="inline" /></div>
65 </xsl:template>
66
67 <xsl:template match="lista_osob">
68     <div class="person-list">
69         <h3><xsl:value-of select="naglowek_listy" /></h3>
70         <ol>
71             <xsl:apply-templates select="lista_osoba" />
72         </ol>
73     </div>
74 </xsl:template>
75
76 <xsl:template match="lista_osoba">
77     <li><xsl:apply-templates mode="inline" /></li>
78 </xsl:template>
79
80 <xsl:template match="begin" mode="inline">
81     <xsl:variable name="mnum" select="concat('m', substring(@id, 2))" />
82     <span class="theme-begin" fid="{substring(@id, 2)}">
83         <xsl:value-of select="string(following::motyw[@id=$mnum]/text())" />
84     </span>
85 </xsl:template>
86
87 <xsl:template match="end" mode="inline">
88     <span class="theme-end" fid="{substring(@id, 2)}"> </span>
89 </xsl:template>
90
91 <xsl:template match="begin|end">
92     <xsl:apply-templates select='.' mode="inline" />
93 </xsl:template>
94
95 <xsl:template name="verse">
96     <xsl:param name="line-content" />
97     <xsl:param name="line-number" />
98     <p>
99         <xsl:choose>
100             <xsl:when test="name($line-content) = 'wers_akap'">
101                 <xsl:attribute name="style">indent: 1em</xsl:attribute>
102             </xsl:when>
103             <xsl:when test="name($line-content) = 'wers_wciety'">
104                 <xsl:attribute name="style">indent: 2em</xsl:attribute>
105             </xsl:when>
106         </xsl:choose>
107         <xsl:apply-templates select="$line-content" mode="inline" />
108     </p>
109 </xsl:template>
110
111 <xsl:template match="pa|pe|pr|pt" mode="inline">
112     <a name="{concat('anchor-', generate-id(.))}" />
113     <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>
114 </xsl:template>
115
116 <xsl:template match="strofa">
117     <div class="stanza">
118         <xsl:choose>
119             <xsl:when test="count(br) > 0">     
120                 <xsl:call-template name="verse">
121                     <xsl:with-param name="line-content" select="br[1]/preceding-sibling::text() | br[1]/preceding-sibling::node()" />
122                     <xsl:with-param name="line-number" select="1" />
123                 </xsl:call-template>    
124                 <xsl:for-each select="br">              
125                                 <!-- Każdy BR "zjada" to co jest za nim -->
126                     <xsl:variable name="lnum" select="count(preceding-sibling::br)" />
127                     <xsl:call-template name="verse">
128                         <xsl:with-param name="line-number" select="$lnum+2" />
129                         <xsl:with-param name="line-content" 
130                             select="following-sibling::text()[count(preceding-sibling::br) = $lnum+1] | following-sibling::node()[count(preceding-sibling::br) = $lnum+1]" />
131                     </xsl:call-template>
132                 </xsl:for-each>
133             </xsl:when>
134             <xsl:otherwise>
135                 <xsl:call-template name="verse">
136                     <xsl:with-param name="line-content" select="text() | node()" />
137                     <xsl:with-param name="line-number" select="1" />
138                  </xsl:call-template>           
139             </xsl:otherwise>
140         </xsl:choose>
141     </div>
142 </xsl:template>
143
144 <xsl:template match="akap|akap_dialog|akap_cd">
145     <p class="paragraph"><xsl:apply-templates mode="inline" /></p>
146 </xsl:template>
147
148 <xsl:template match="motyw" mode="inline" />
149
150 <xsl:template match="dlugi_cytat">
151     <blockquote><xsl:apply-templates /></blockquote>
152 </xsl:template>
153
154 </xsl:stylesheet>