-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfb2-xhtml.xsl
212 lines (180 loc) · 5.44 KB
/
fb2-xhtml.xsl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
<t:stylesheet
version="1.0"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:t="http://www.w3.org/1999/XSL/Transform"
xmlns:l="http://www.w3.org/1999/xlink"
xmlns:f="http://www.gribuser.ru/xml/fictionbook/2.0"
exclude-result-prefixes="l f">
<t:output method="xml" encoding="UTF-8" omit-xml-declaration="yes"/>
<t:strip-space elements="*"/>
<t:preserve-space elements="f:p f:v f:subtitle f:text-author"/>
<t:template match="/f:FictionBook">
<t:text disable-output-escaping='yes'><!DOCTYPE html> </t:text>
<html lang="{//f:lang}">
<t:text> </t:text><head>
<t:text> </t:text><meta charset="UTF-8"/>
<t:text> </t:text><title><t:value-of select="//f:title-info/f:book-title"/></title>
<t:text> </t:text><link rel="stylesheet" href="/local/css/fb2.css"/>
<t:text> </t:text></head>
<t:text> </t:text><body>
<t:apply-templates select="f:body"/>
<t:text> </t:text></body>
<t:text> </t:text></html>
</t:template>
<t:template match="f:title">
<t:text> </t:text>
<t:variable name="level" select="count(ancestor::node())-2"/>
<t:choose>
<t:when test="$level < 6">
<t:element name="{concat('h',$level)}">
<t:apply-templates/>
</t:element>
</t:when>
<t:otherwise>
<h6><t:apply-templates/></h6>
</t:otherwise>
</t:choose>
</t:template>
<t:template match="f:subtitle">
<t:text> </t:text>
<t:variable name="level" select="count(ancestor::node())-1"/>
<t:choose>
<t:when test="$level < 6">
<t:element name="{concat('h',$level)}">
<t:apply-templates/>
</t:element>
</t:when>
<t:otherwise>
<h6><t:apply-templates/></h6>
</t:otherwise>
</t:choose>
</t:template>
<t:template match="f:title/f:p">
<t:apply-templates />
<t:if test="position()!=last()">
<br/><t:text> </t:text>
</t:if>
</t:template>
<t:template match="f:title/f:empty-line">
<br/><t:text> </t:text>
</t:template>
<t:template match="f:style">
<span class="{@name}"><t:apply-templates/></span>
</t:template>
<t:template match="f:style[@name='aux']">
<small><t:apply-templates/></small>
</t:template>
<t:template match="f:section">
<t:text> </t:text><t:element name="{name()}">
<t:apply-templates select="node()|@*"/>
<t:text> </t:text></t:element>
</t:template>
<t:template match="f:section/f:image | f:body/f:image" name="divimage">
<t:text> </t:text><figure>
<t:copy-of select="@id"/>
<t:text> </t:text><t:call-template name="image"/>
<t:if test="@title">
<t:text> </t:text><figcaption><t:value-of select="@title"/></figcaption>
</t:if>
<t:text> </t:text></figure>
</t:template>
<t:template match="f:body[@name='notes']">
<t:text> </t:text>
<section class="notes">
<t:apply-templates/><t:text> </t:text>
</section><t:text> </t:text>
</t:template>
<t:template match="f:p | f:v">
<t:text> </t:text><p><t:copy-of select="@id"/><t:apply-templates match="node()|@*"/></p>
</t:template>
<t:template match="@id">
<t:copy-of select="."/>
</t:template>
<t:template match="f:strong">
<strong><t:apply-templates/></strong>
</t:template>
<t:template match="f:emphasis">
<em><t:apply-templates/></em>
</t:template>
<t:template match="f:sup">
<sup><t:apply-templates/></sup>
</t:template>
<t:template match="f:sub">
<sub><t:apply-templates/></sub>
</t:template>
<t:template match="f:empty-line">
<t:text> </t:text><div class="empty-line"/>
</t:template>
<t:template match="f:section/node()[last()][self::f:empty-line]|f:section/node()[1][self::f:empty-line]">
</t:template>
<t:template match="f:a">
<t:choose>
<t:when test="(@type) = 'note'">
<a class="note" href="{@l:href}"><sup><t:apply-templates/></sup></a>
</t:when>
<t:otherwise>
<a href="{@l:href}"><t:apply-templates/></a>
</t:otherwise>
</t:choose>
</t:template>
<t:template match="f:epigraph | f:cite | f:poem">
<t:text> </t:text><blockquote class="{name()}">
<t:apply-templates/>
<t:text> </t:text></blockquote>
</t:template>
<t:template match="f:text-author">
<t:text> </t:text><p class="author"><t:apply-templates/></p>
</t:template>
<t:template match="f:stanza">
<t:text> </t:text><div class="stanza">
<t:apply-templates/>
<t:text> </t:text></div>
</t:template>
<t:template match="f:annotation">
<t:text> </t:text>
<blockquote class="annotation">
<t:apply-templates/>
<t:text> </t:text>
</blockquote>
</t:template>
<t:template match="f:image" name="image">
<img>
<t:copy-of select="@alt"/>
<t:choose>
<t:when test="starts-with(@l:href,'#')">
<t:variable name="href" select="substring-after(@l:href,'#')"/>
<t:attribute name="src">
<t:text>data:</t:text>
<t:value-of select="/f:binary[@id=$href]/@content-type"/>
<t:text>;base64,</t:text>
<t:value-of select="translate(normalize-space(/f:binary[@id=$href]), ' ', '')"/>
</t:attribute>
</t:when>
<t:otherwise>
<t:attribute name="src"><t:value-of select="@l:href"/></t:attribute>
</t:otherwise>
</t:choose>
</img>
</t:template>
<t:template match="f:table">
<t:text> </t:text><table>
<t:text> </t:text><tbody>
<t:apply-templates/>
<t:text> </t:text></tbody>
<t:text> </t:text></table>
</t:template>
<t:template match="f:tr">
<t:text> </t:text><tr>
<t:copy-of select="@*"/>
<t:apply-templates/></tr>
</t:template>
<t:template match="f:td | f:th">
<t:element name="{name()}">
<t:copy-of select="@rowspan|@colspan"/>
<t:if test="@align">
<t:attribute name="class"><t:value-of select="@align"/></t:attribute>
</t:if>
<t:apply-templates/>
</t:element>
</t:template>
</t:stylesheet>