Debian Codegraph @

resources/templates/fb2.xsl

raw
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="__FB_NS__">
2 <!--
3 #########################################################################
4 # #
5 # #
6 # copyright 2002 Paul Henry Tremblay #
7 # Copyright 2011 Kovid Goyal
8 # #
9 # This program is distributed in the hope that it will be useful, #
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU #
12 # General Public License for more details. #
13 # #
14 # You should have received a copy of the GNU General Public License #
15 # along with this program; if not, write to the Free Software #
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA #
17 # 02111-1307 USA #
18 # #
19 # #
20 #########################################################################
21
22 -->
23 <xsl:output method="xml" encoding="UTF-8"/>
24 <xsl:key name="note-link" match="fb:section" use="@id"/>
25 <xsl:template match="/*">
26 <html>
27 <head>
28 <xsl:if test="fb:description/fb:title-info/fb:lang = 'ru'">
29 <meta HTTP-EQUIV="content-type" CONTENT="text/html; charset=UTF-8"/>
30 </xsl:if>
31 <title>
32 <xsl:value-of select="fb:description/fb:title-info/fb:book-title"/>
33 </title>
34 <style type="text/css">
35 body { text-align : justify }
36
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
39 h2{ font-size : 130%; font-style : normal; font-weight : bold; text-align : left; background-color : #EEEEEE; border : 1px solid Gray; page-break-before : always; }
40 h3{ font-size : 110%; font-style : normal; font-weight : bold; text-align : left; background-color : #F1F1F1; border : 1px solid Silver;}
41
42 h4{ font-size : 100%; font-style : normal; font-weight : bold; text-align : left; border : 1px solid Gray; background-color : #F4F4F4;}
43
44 h5{ font-size : 100%; font-style : italic; font-weight : bold; text-align : left; border : 1px solid Gray; background-color : #F4F4F4;}
45
46 h6{ font-size : 100%; font-style : italic; font-weight : normal; text-align : left; border : 1px solid Gray; background-color : #F4F4F4;}
47
48 small { font-size : 80% }
49
50 blockquote { margin-left :4em; margin-top:1em; margin-right:0.2em;}
51
52 hr { color : Black }
53
54 ul {margin-left: 0}
55
56 .epigraph{width:75%; margin-left : 25%; font-style: italic;}
57
58 div.paragraph, p.paragraph { text-indent: 2em; margin-top: 0; margin-bottom: 0; }
59
60 .subtitle { text-align: center; }
61 </style>
62 <link rel="stylesheet" type="text/css" href="inline-styles.css" />
63 </head>
64 <body>
65 <xsl:for-each select="fb:description/fb:title-info/fb:annotation">
66 <div>
67 <xsl:call-template name="annotation"/>
68 </div>
69 <hr/>
70 </xsl:for-each>
71 <!-- BUILD TOC -->
72 <ul>
73 <xsl:apply-templates select="fb:body" mode="toc"/>
74 </ul>
75 <hr/>
76 <!-- END BUILD TOC -->
77 <!-- BUILD BOOK -->
78 <xsl:for-each select="fb:body">
79 <xsl:if test="position()!=1">
80 <hr/>
81 </xsl:if>
82 <xsl:if test="@name">
83 <h4 align="center">
84 <xsl:value-of select="@name"/>
85 </h4>
86 </xsl:if>
87 <!-- <xsl:apply-templates /> -->
88 <xsl:apply-templates/>
89 </xsl:for-each>
90 </body>
91 </html>
92 </xsl:template>
93 <!-- author template -->
94 <xsl:template name="author">
95 <xsl:value-of select="fb:first-name"/>
96 <xsl:text disable-output-escaping="no">&#032;</xsl:text>
97 <xsl:value-of select="fb:middle-name"/>&#032;
98 <xsl:text disable-output-escaping="no">&#032;</xsl:text>
99 <xsl:value-of select="fb:last-name"/>
100 <br/>
101 </xsl:template>
102 <!-- sequence template -->
103 <xsl:template name="sequence">
104 <li/>
105 <xsl:value-of select="@name"/>
106 <xsl:if test="@number">
107 <xsl:text disable-output-escaping="no">,&#032;#</xsl:text>
108 <xsl:value-of select="@number"/>
109 </xsl:if>
110 <xsl:if test="fb:sequence">
111 <ul>
112 <xsl:for-each select="fb:sequence">
113 <xsl:call-template name="sequence"/>
114 </xsl:for-each>
115 </ul>
116 </xsl:if>
117 <!-- <br/> -->
118 </xsl:template>
119 <!-- toc template -->
120 <xsl:template match="fb:section|fb:body" mode="toc">
121 <xsl:choose>
122 <xsl:when test="name()='body' and position()=1 and not(fb:title)">
123 <xsl:apply-templates select="fb:section" mode="toc"/>
124 </xsl:when>
125 <xsl:otherwise>
126 <li>
127 <a href="#TOC_{generate-id()}"><xsl:value-of select="normalize-space(fb:title/fb:p[1] | @name)"/></a>
128 <xsl:if test="fb:section">
129 <ul><xsl:apply-templates select="fb:section" mode="toc"/></ul>
130 </xsl:if>
131 </li>
132 </xsl:otherwise>
133 </xsl:choose>
134 </xsl:template>
135 <!-- description -->
136 <xsl:template match="fb:description">
137 <xsl:apply-templates/>
138 </xsl:template>
139 <!-- body -->
140 <xsl:template match="fb:body">
141 <div><xsl:apply-templates/></div>
142 </xsl:template>
143
144 <xsl:template match="fb:section">
145 <xsl:variable name="section_has_title">
146 <xsl:choose>
147 <xsl:when test="./fb:title"><xsl:value-of select="generate-id()" /></xsl:when>
148 <xsl:otherwise>None</xsl:otherwise>
149 </xsl:choose>
150 </xsl:variable>
151 <xsl:if test="$section_has_title = 'None'">
152 <div id="TOC_{generate-id()}">
153 <xsl:if test="@id">
154 <xsl:element name="a">
155 <xsl:attribute name="id"><xsl:value-of select="@id"/></xsl:attribute>
156 </xsl:element>
157 </xsl:if>
158 </div>
159 </xsl:if>
160 <xsl:apply-templates>
161 <xsl:with-param name="section_toc_id" select="$section_has_title" />
162 </xsl:apply-templates>
163 </xsl:template>
164
165
166 <!-- section/title -->
167 <xsl:template match="fb:section/fb:title|fb:poem/fb:title">
168 <xsl:param name="section_toc_id" />
169 <xsl:choose>
170 <xsl:when test="count(ancestor::node()) &lt; 9">
171 <xsl:element name="{concat('h',count(ancestor::node())-3)}">
172 <xsl:if test="../@id">
173 <xsl:attribute name="id"><xsl:value-of select="../@id" /></xsl:attribute>
174 </xsl:if>
175 <xsl:if test="$section_toc_id != 'None'">
176 <xsl:element name="a">
177 <xsl:attribute name="id">TOC_<xsl:value-of select="$section_toc_id"/></xsl:attribute>
178 </xsl:element>
179 </xsl:if>
180 <a name="TOC_{generate-id()}"></a>
181 <xsl:if test="@id">
182 <xsl:element name="a">
183 <xsl:attribute name="id"><xsl:value-of select="@id"/></xsl:attribute>
184 </xsl:element>
185 </xsl:if>
186 <xsl:apply-templates/>
187 </xsl:element>
188 </xsl:when>
189 <xsl:otherwise>
190 <xsl:element name="h6">
191 <xsl:if test="@id">
192 <xsl:element name="a">
193 <xsl:attribute name="id"><xsl:value-of select="@id"/></xsl:attribute>
194 </xsl:element>
195 </xsl:if>
196 <xsl:apply-templates/>
197 </xsl:element>
198 </xsl:otherwise>
199 </xsl:choose>
200 </xsl:template>
201 <!-- section/title -->
202 <xsl:template match="fb:body/fb:title">
203 <xsl:element name="h1">
204 <xsl:apply-templates />
205 </xsl:element>
206 </xsl:template>
207
208 <xsl:template match="fb:title/fb:p">
209 <xsl:apply-templates/><xsl:text disable-output-escaping="no">&#032;</xsl:text><br/>
210 </xsl:template>
211 <!-- subtitle -->
212 <xsl:template match="fb:subtitle">
213 <xsl:if test="@id">
214 <xsl:element name="a">
215 <xsl:attribute name="name"><xsl:value-of select="@id"/></xsl:attribute>
216 </xsl:element>
217 </xsl:if>
218 <h5 class="subtitle">
219 <xsl:apply-templates/>
220 </h5>
221 </xsl:template>
222 <!-- p -->
223 <xsl:template match="fb:p">
224 <xsl:element name="div">
225 <xsl:attribute name="class">paragraph</xsl:attribute>
226 <xsl:if test="@style">
227 <xsl:attribute name="style"><xsl:value-of select="@style"/></xsl:attribute>
228 </xsl:if>
229 <xsl:if test="@id">
230 <xsl:element name="a">
231 <xsl:attribute name="name"><xsl:value-of select="@id"/></xsl:attribute>
232 </xsl:element>
233 </xsl:if>
234 <xsl:apply-templates/>
235 </xsl:element>
236 </xsl:template>
237 <!-- strong -->
238 <xsl:template match="fb:strong">
239 <strong><xsl:apply-templates/></strong>
240 </xsl:template>
241 <!-- emphasis -->
242 <xsl:template match="fb:emphasis">
243 <em> <xsl:apply-templates/></em>
244 </xsl:template>
245 <!-- style -->
246 <xsl:template match="fb:style">
247 <span class="{@name}"><xsl:apply-templates/></span>
248 </xsl:template>
249 <!-- empty-line -->
250 <xsl:template match="fb:empty-line">
251 <br/>
252 </xsl:template>
253 <!-- super/sub-scripts -->
254 <xsl:template match="fb:sup">
255 <sup><xsl:apply-templates/></sup>
256 </xsl:template>
257 <xsl:template match="fb:sub">
258 <sub><xsl:apply-templates/></sub>
259 </xsl:template>
260 <!-- link -->
261 <xsl:template match="fb:a">
262 <xsl:element name="a">
263 <xsl:attribute name="href"><xsl:value-of select="@xlink:href"/></xsl:attribute>
264 <xsl:attribute name="title">
265 <xsl:choose>
266 <xsl:when test="starts-with(@xlink:href,'#')"><xsl:value-of select="key('note-link',substring-after(@xlink:href,'#'))/fb:p"/></xsl:when>
267 <xsl:otherwise><xsl:value-of select="key('note-link',@xlink:href)/fb:p"/></xsl:otherwise>
268 </xsl:choose>
269 </xsl:attribute>
270 <xsl:choose>
271 <xsl:when test="(@type) = 'note'">
272 <xsl:attribute name="link_note"></xsl:attribute>
273 <sup>
274 <xsl:apply-templates/>
275 </sup>
276 </xsl:when>
277 <xsl:when test="(@type) = 'cite' and @id">
278 <xsl:attribute name="link_cite"><xsl:value-of select="@id"/></xsl:attribute>
279 <xsl:apply-templates/>
280 </xsl:when>
281 <xsl:otherwise>
282 <xsl:apply-templates/>
283 </xsl:otherwise>
284 </xsl:choose>
285 </xsl:element>
286 </xsl:template>
287 <!-- annotation -->
288 <xsl:template name="annotation">
289 <xsl:if test="@id">
290 <xsl:element name="a">
291 <xsl:attribute name="name"><xsl:value-of select="@id"/></xsl:attribute>
292 </xsl:element>
293 </xsl:if>
294 <h1>Annotation</h1>
295 <xsl:apply-templates/>
296 </xsl:template>
297 <!-- tables -->
298 <xsl:template match="fb:table">
299 <table>
300 <xsl:apply-templates/>
301 </table>
302 </xsl:template>
303 <xsl:template match="fb:tr">
304 <xsl:element name="tr">
305 <xsl:if test="@align">
306 <xsl:attribute name="align"><xsl:value-of select="@align"/></xsl:attribute>
307 </xsl:if>
308 <xsl:apply-templates/>
309 </xsl:element>
310 </xsl:template>
311 <xsl:template match="fb:td|fb:th">
312 <xsl:element name="{local-name()}">
313 <xsl:if test="@align">
314 <xsl:attribute name="align"><xsl:value-of select="@align"/></xsl:attribute>
315 </xsl:if>
316 <xsl:if test="@style">
317 <xsl:attribute name="style"><xsl:value-of select="@style"/></xsl:attribute>
318 </xsl:if>
319 <xsl:if test="@colspan">
320 <xsl:attribute name="colspan"><xsl:value-of select="@colspan"/></xsl:attribute>
321 </xsl:if>
322 <xsl:if test="@rowspan">
323 <xsl:attribute name="rowspan"><xsl:value-of select="@rowspan"/></xsl:attribute>
324 </xsl:if>
325 <xsl:apply-templates/>
326 </xsl:element>
327 </xsl:template>
328 <!-- epigraph -->
329 <xsl:template match="fb:epigraph">
330 <blockquote class="epigraph">
331 <xsl:if test="@id">
332 <xsl:element name="a">
333 <xsl:attribute name="name"><xsl:value-of select="@id"/></xsl:attribute>
334 </xsl:element>
335 </xsl:if>
336 <div>
337 <xsl:apply-templates/>
338 </div>
339 </blockquote>
340 </xsl:template>
341 <!-- epigraph/text-author -->
342 <xsl:template match="fb:epigraph/fb:text-author">
343 <blockquote>
344 <i><xsl:apply-templates/></i>
345 </blockquote>
346 </xsl:template>
347 <!-- cite -->
348 <xsl:template match="fb:cite">
349 <blockquote>
350 <xsl:if test="@id">
351 <xsl:element name="a">
352 <xsl:attribute name="name"><xsl:value-of select="@id"/></xsl:attribute>
353 </xsl:element>
354 </xsl:if>
355 <div>
356 <xsl:apply-templates/>
357 </div>
358 </blockquote>
359 </xsl:template>
360 <!-- cite/text-author -->
361 <xsl:template match="fb:text-author">
362 <blockquote>
363 <i> <xsl:apply-templates/></i></blockquote>
364 </xsl:template>
365 <!-- date -->
366 <xsl:template match="fb:date">
367 <xsl:choose>
368 <xsl:when test="not(@value)">
369 &#160;&#160;&#160;<xsl:apply-templates/>
370 <br/>
371 </xsl:when>
372 <xsl:otherwise>
373 &#160;&#160;&#160;<xsl:value-of select="@value"/>
374 <br/>
375 </xsl:otherwise>
376 </xsl:choose>
377 </xsl:template>
378 <!-- poem -->
379 <xsl:template match="fb:poem">
380 <blockquote>
381 <xsl:if test="@id">
382 <xsl:element name="a">
383 <xsl:attribute name="name"><xsl:value-of select="@id"/></xsl:attribute>
384 </xsl:element>
385 </xsl:if>
386 <div>
387 <xsl:apply-templates/>
388 </div>
389 </blockquote>
390 </xsl:template>
391
392 <!-- stanza -->
393 <xsl:template match="fb:stanza">
394 <xsl:apply-templates/>
395 <br/>
396 </xsl:template>
397 <!-- v -->
398 <xsl:template match="fb:v">
399 <xsl:if test="@id">
400 <xsl:element name="a">
401 <xsl:attribute name="name"><xsl:value-of select="@id"/></xsl:attribute>
402 </xsl:element>
403 </xsl:if>
404 <xsl:apply-templates/><br/>
405 </xsl:template>
406 <!-- image -->
407 <xsl:template match="fb:body/fb:image|fb:section/fb:image">
408 <div align="center">
409 <xsl:element name="img">
410 <xsl:choose>
411 <xsl:when test="starts-with(@xlink:href,'#')">
412 <xsl:attribute name="src"><xsl:value-of select="substring-after(@xlink:href,'#')"/></xsl:attribute>
413 </xsl:when>
414 <xsl:otherwise>
415 <xsl:attribute name="src"><xsl:value-of select="@xlink:href"/></xsl:attribute>
416 </xsl:otherwise>
417 </xsl:choose>
418 <xsl:if test="@title">
419 <xsl:attribute name="title"><xsl:value-of select="@title"/></xsl:attribute>
420 </xsl:if>
421 </xsl:element>
422 </div>
423 </xsl:template>
424 <xsl:template match="fb:image">
425 <xsl:element name="img">
426 <xsl:choose>
427 <xsl:when test="starts-with(@xlink:href,'#')">
428 <xsl:attribute name="src"><xsl:value-of select="substring-after(@xlink:href,'#')"/></xsl:attribute>
429 </xsl:when>
430 <xsl:otherwise>
431 <xsl:attribute name="src"><xsl:value-of select="@xlink:href"/></xsl:attribute>
432 </xsl:otherwise>
433 </xsl:choose>
434 <xsl:if test="@title">
435 <xsl:attribute name="title"><xsl:value-of select="@title"/></xsl:attribute>
436 </xsl:if>
437 </xsl:element>
438 </xsl:template>
439 <!-- code -->
440 <xsl:template match="fb:code">
441 <code><xsl:apply-templates/></code>
442 </xsl:template>
443 <!-- Strikethrough text -->
444 <xsl:template match="fb:strikethrough">
445 <del><xsl:apply-templates/></del>
446 </xsl:template>
447
448 </xsl:stylesheet>