1
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:fb="http://www.gribuser.ru/xml/fictionbook/2.0">
3
#########################################################################
6
# copyright 2002 Paul Henry Tremblay #
8
# This program is distributed in the hope that it will be useful, #
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU #
11
# General Public License for more details. #
13
# You should have received a copy of the GNU General Public License #
14
# along with this program; if not, write to the Free Software #
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA #
19
#########################################################################
22
<xsl:output method="xml" encoding="UTF-8"/>
23
<xsl:key name="note-link" match="fb:section" use="@id"/>
24
<xsl:template match="/*">
27
<xsl:if test="fb:description/fb:title-info/fb:lang = 'ru'">
28
<meta HTTP-EQUIV="content-type" CONTENT="text/html; charset=UTF-8"/>
31
<xsl:value-of select="fb:description/fb:title-info/fb:book-title"/>
33
<style type="text/x-oeb1-css">
35
A:HOVER { color : #BF0000 }
36
BODY { background-color : #FEFEFE; color : #000000; font-family : Verdana, Geneva, Arial, Helvetica, sans-serif; text-align : justify }
37
H1{ font-size : 160%; font-style : normal; font-weight : bold; text-align : left; border : 1px solid Black; background-color : #E7E7E7; margin-left : 0px; page-break-before : always; }
38
H2{ font-size : 130%; font-style : normal; font-weight : bold; text-align : left; background-color : #EEEEEE; border : 1px solid Gray; page-break-before : always; }
39
H3{ font-size : 110%; font-style : normal; font-weight : bold; text-align : left; background-color : #F1F1F1; border : 1px solid Silver;}
40
H4{ font-size : 100%; font-style : normal; font-weight : bold; text-align : left; border : 1px solid Gray; background-color : #F4F4F4;}
41
H5{ font-size : 100%; font-style : italic; font-weight : bold; text-align : left; border : 1px solid Gray; background-color : #F4F4F4;}
42
H6{ font-size : 100%; font-style : italic; font-weight : normal; text-align : left; border : 1px solid Gray; background-color : #F4F4F4;}
43
SMALL{ font-size : 80% }
44
BLOCKQUOTE{ margin-left :4em; margin-top:1em; margin-right:0.2em;}
46
DIV{font-family : "Times New Roman", Times, serif; text-align : justify}
48
.epigraph{width:50%; margin-left : 35%;}
52
<xsl:for-each select="fb:description/fb:title-info/fb:annotation">
54
<xsl:call-template name="annotation"/>
60
<xsl:apply-templates select="fb:body" mode="toc"/>
63
<!-- END BUILD TOC -->
65
<xsl:for-each select="fb:body">
66
<xsl:if test="position()!=1">
71
<xsl:value-of select="@name"/>
74
<!-- <xsl:apply-templates /> -->
75
<xsl:apply-templates/>
80
<!-- author template -->
81
<xsl:template name="author">
82
<xsl:value-of select="fb:first-name"/>
83
<xsl:text disable-output-escaping="no"> </xsl:text>
84
<xsl:value-of select="fb:middle-name"/> 
85
<xsl:text disable-output-escaping="no"> </xsl:text>
86
<xsl:value-of select="fb:last-name"/>
89
<!-- secuence template -->
90
<xsl:template name="sequence">
92
<xsl:value-of select="@name"/>
93
<xsl:if test="@number">
94
<xsl:text disable-output-escaping="no">, #</xsl:text>
95
<xsl:value-of select="@number"/>
97
<xsl:if test="fb:sequence">
99
<xsl:for-each select="fb:sequence">
100
<xsl:call-template name="sequence"/>
106
<!-- toc template -->
107
<xsl:template match="fb:section|fb:body" mode="toc">
109
<xsl:when test="name()='body' and position()=1 and not(fb:title)">
110
<xsl:apply-templates select="fb:section" mode="toc"/>
114
<a href="#TOC_{generate-id()}"><xsl:value-of select="normalize-space(fb:title/fb:p[1] | @name)"/></a>
115
<xsl:if test="fb:section">
116
<ul><xsl:apply-templates select="fb:section" mode="toc"/></ul>
123
<xsl:template match="fb:description">
124
<xsl:apply-templates/>
127
<xsl:template match="fb:body">
128
<div><xsl:apply-templates/></div>
131
<xsl:template match="fb:section">
132
<xsl:variable name="section_has_title">
134
<xsl:when test="./fb:title"><xsl:value-of select="generate-id()" /></xsl:when>
135
<xsl:otherwise>None</xsl:otherwise>
138
<xsl:if test="$section_has_title = 'None'">
139
<a name="TOC_{generate-id()}" />
141
<xsl:element name="a">
142
<xsl:attribute name="name"><xsl:value-of select="@id"/></xsl:attribute>
146
<xsl:apply-templates>
147
<xsl:with-param name="section_toc_id" select="$section_has_title" />
148
</xsl:apply-templates>
152
<!-- section/title -->
153
<xsl:template match="fb:section/fb:title|fb:poem/fb:title">
154
<xsl:param name="section_toc_id" />
156
<xsl:when test="count(ancestor::node()) < 9">
157
<xsl:element name="{concat('h',count(ancestor::node())-3)}">
158
<xsl:if test="../@id">
159
<xsl:attribute name="id"><xsl:value-of select="../@id" /></xsl:attribute>
161
<xsl:if test="$section_toc_id != 'None'">
162
<xsl:element name="a">
163
<xsl:attribute name="name">TOC_<xsl:value-of select="$section_toc_id"/></xsl:attribute>
166
<a name="TOC_{generate-id()}"></a>
168
<xsl:element name="a">
169
<xsl:attribute name="name"><xsl:value-of select="@id"/></xsl:attribute>
172
<xsl:apply-templates/>
176
<xsl:element name="h6">
178
<xsl:element name="a">
179
<xsl:attribute name="name"><xsl:value-of select="@id"/></xsl:attribute>
182
<xsl:apply-templates/>
187
<!-- section/title -->
188
<xsl:template match="fb:body/fb:title">
189
<xsl:element name="h1">
190
<xsl:apply-templates mode="title"/>
194
<xsl:template match="fb:title/fb:p">
195
<xsl:apply-templates/><xsl:text disable-output-escaping="no"> </xsl:text><br/>
198
<xsl:template match="fb:subtitle">
200
<xsl:element name="a">
201
<xsl:attribute name="name"><xsl:value-of select="@id"/></xsl:attribute>
205
<xsl:apply-templates/>
209
<xsl:template match="fb:p">
210
<div align="justify"><xsl:if test="@id">
211
<xsl:element name="a">
212
<xsl:attribute name="name"><xsl:value-of select="@id"/></xsl:attribute>
214
</xsl:if>    <xsl:apply-templates/></div>
217
<xsl:template match="fb:strong">
218
<b><xsl:apply-templates/></b>
221
<xsl:template match="fb:emphasis">
222
<i> <xsl:apply-templates/></i>
225
<xsl:template match="fb:style">
226
<span class="{@name}"><xsl:apply-templates/></span>
229
<xsl:template match="fb:empty-line">
233
<xsl:template match="fb:a">
234
<xsl:element name="a">
235
<xsl:attribute name="href"><xsl:value-of select="@xlink:href"/></xsl:attribute>
236
<xsl:attribute name="title">
238
<xsl:when test="starts-with(@xlink:href,'#')"><xsl:value-of select="key('note-link',substring-after(@xlink:href,'#'))/fb:p"/></xsl:when>
239
<xsl:otherwise><xsl:value-of select="key('note-link',@xlink:href)/fb:p"/></xsl:otherwise>
243
<xsl:when test="(@type) = 'note'">
245
<xsl:apply-templates/>
249
<xsl:apply-templates/>
255
<xsl:template name="annotation">
257
<xsl:element name="a">
258
<xsl:attribute name="name"><xsl:value-of select="@id"/></xsl:attribute>
262
<xsl:apply-templates/>
265
<xsl:template match="fb:epigraph">
266
<blockquote class="epigraph">
268
<xsl:element name="a">
269
<xsl:attribute name="name"><xsl:value-of select="@id"/></xsl:attribute>
272
<xsl:apply-templates/>
275
<!-- epigraph/text-author -->
276
<xsl:template match="fb:epigraph/fb:text-author">
278
<i><xsl:apply-templates/></i>
282
<xsl:template match="fb:cite">
285
<xsl:element name="a">
286
<xsl:attribute name="name"><xsl:value-of select="@id"/></xsl:attribute>
289
<xsl:apply-templates/>
292
<!-- cite/text-author -->
293
<xsl:template match="fb:text-author">
295
<i> <xsl:apply-templates/></i></blockquote>
298
<xsl:template match="fb:date">
300
<xsl:when test="not(@value)">
301
   <xsl:apply-templates/>
305
   <xsl:value-of select="@value"/>
311
<xsl:template match="fb:poem">
314
<xsl:element name="a">
315
<xsl:attribute name="name"><xsl:value-of select="@id"/></xsl:attribute>
318
<xsl:apply-templates/>
323
<xsl:template match="fb:stanza">
324
<xsl:apply-templates/>
328
<xsl:template match="fb:v">
330
<xsl:element name="a">
331
<xsl:attribute name="name"><xsl:value-of select="@id"/></xsl:attribute>
334
<xsl:apply-templates/><br/>
337
<xsl:template match="fb:image">
341
<xsl:when test="starts-with(@xlink:href,'#')">
342
<xsl:attribute name="src"><xsl:value-of select="substring-after(@xlink:href,'#')"/></xsl:attribute>
345
<xsl:attribute name="src"><xsl:value-of select="@xlink:href"/></xsl:attribute>