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