-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathodf2html.xsl
More file actions
272 lines (239 loc) · 9.58 KB
/
odf2html.xsl
File metadata and controls
272 lines (239 loc) · 9.58 KB
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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0"
xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0"
xmlns:config="urn:oasis:names:tc:opendocument:xmlns:config:1.0"
xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0"
xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0"
xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0"
xmlns:presentation="urn:oasis:names:tc:opendocument:xmlns:presentation:1.0"
xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0"
xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0"
xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0"
xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0"
xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0"
xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0"
xmlns:anim="urn:oasis:names:tc:opendocument:xmlns:animation:1.0"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:math="http://www.w3.org/1998/Math/MathML"
xmlns:xforms="http://www.w3.org/2002/xforms"
xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0"
xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0"
xmlns:smil="urn:oasis:names:tc:opendocument:xmlns:smil-compatible:1.0"
xmlns:ooo="http://openoffice.org/2004/office"
xmlns:ooow="http://openoffice.org/2004/writer"
xmlns:oooc="http://openoffice.org/2004/calc"
xmlns:int="http://opendocumentfellowship.org/internal"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="2.0">
<xsl:param xmlns:dom="http://www.w3.org/2001/xml-events" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="param_no_css"/>
<xsl:param xmlns:dom="http://www.w3.org/2001/xml-events" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="param_css_only"/>
<xsl:param xmlns:dom="http://www.w3.org/2001/xml-events" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="scale">1</xsl:param>
<xsl:param xmlns:dom="http://www.w3.org/2001/xml-events" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="style.background-color">#A0A0A0</xsl:param>
<xsl:param xmlns:dom="http://www.w3.org/2001/xml-events" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="CSS.debug">0</xsl:param>
<xsl:variable xmlns:dom="http://www.w3.org/2001/xml-events" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="linebreak">
</xsl:variable>
<xsl:template match="office:document">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="/office:document">
<html>
<head>
<!-- meta must be first -->
<xsl:apply-templates select="office:document-meta"/>
<!-- must be second -->
<style>
<xsl:apply-templates select="office:document-styles"/>
</style>
</head>
<!-- body must be after head -->
<body>
<xsl:apply-templates select="office:document-content"/>
</body>
</html>
</xsl:template>
<xsl:template match="office:document-meta">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="office:meta">
<xsl:comment>office:metadata begin</xsl:comment>
<xsl:apply-templates select="dc:title"/>
<xsl:apply-templates select="dc:creator"/>
<xsl:apply-templates select="dc:date"/>
<xsl:apply-templates select="dc:language"/>
<xsl:apply-templates select="dc:description"/>
<xsl:apply-templates select="meta:keyword"/>
<xsl:apply-templates select="meta:generator"/>
<meta http-equiv="Content-Type" content="application/xhtml+xml;charset=utf-8"/>
<xsl:comment>office:metadata end</xsl:comment>
</xsl:template>
<xsl:template match="dc:title">
<title><xsl:apply-templates/></title>
</xsl:template>
<xsl:template match="dc:language">
<meta http-equiv="content-language" content="{current()}"/>
</xsl:template>
<xsl:template match="dc:creator">
<meta name="author" content="{current()}"/>
<meta name="DC.creator" content="{current()}"/>
</xsl:template>
<xsl:template match="dc:description">
<meta name="description" content="{current()}"/>
</xsl:template>
<xsl:template match="dc:date">
<meta name="revised" content="{current()}"/>
<meta name="DC.date" content="{current()}"/>
</xsl:template>
<xsl:template match="meta:keyword">
<meta name="keywords" content="{current()}"/>
</xsl:template>
<xsl:template match="meta:generator">
<meta name="generator" content="{current()}"/>
</xsl:template>
<xsl:template name="office:document-styles">
html
{
font-family: Verdana, SunSans-Regular, Sans-Serif;
font-size: <xsl:value-of select="$scale * 14"/>pt;
}
@media print
{
html
{
}
}
@media screen
{
html
{
background-color: <xsl:value-of select="$style.background-color"/>;
margin: 1.5em;
position: absolute;
}
body
{
position: absolute;
}
}
table
{
border: thin solid gray;
border-collapse: collapse;
empty-cells: show;
font-size: 10pt;
table-layout: fixed;
}
td
{
border: thin solid gray;
vertical-align: bottom;
}
.cell_string
{
text-align: left;
}
.cell_time
{
text-align: right;
}
td p
{
max-height: 2.5ex;
overflow: hidden;
}
td p:hover
{
max-height: none;
}
p
{
margin-top: 0;
margin-bottom: 0;
}
.page-break
{
margin: 1em;
}
</xsl:template>
<xsl:template match="office:document-styles">
<!-- office:document-styles begin -->
<xsl:call-template name="office:document-styles">
</xsl:call-template>
<xsl:apply-templates></xsl:apply-templates>
<!-- office:document-styles end -->
</xsl:template>
<xsl:template match="office:styles">
<xsl:text><!-- office:styles begin --></xsl:text>
<xsl:apply-templates />
<xsl:text><!-- office:styles end --></xsl:text>
</xsl:template>
<xsl:template match="office:automatic-styles">
<xsl:text><!-- office:automatic-styles begin1 --></xsl:text>
<xsl:apply-templates/>
<xsl:text><!-- office:automatic-styles end --></xsl:text>
</xsl:template>
<xsl:template match="office:master-styles">
<xsl:text><!-- office:master-styles begin --></xsl:text>
<xsl:apply-templates/>
<xsl:text><!-- office:master-styles end --></xsl:text>
</xsl:template>
<xsl:template match="style:default-style">
<xsl:text>p{</xsl:text>
<xsl:text>}</xsl:text>
</xsl:template>
<xsl:template match="office:styles/style:style">
<xsl:text>.</xsl:text><xsl:value-of select="@style:family"></xsl:value-of><xsl:text>_</xsl:text>
<xsl:value-of select="@style:name"></xsl:value-of>
<xsl:text>
{</xsl:text>
<xsl:apply-templates/>
<xsl:text>}
</xsl:text>
</xsl:template>
<xsl:template match="office:styles/style:paragraph-properties">
<xsl:text> padding-top:</xsl:text>
<xsl:value-of select="@fo:padding-top"></xsl:value-of><xsl:text>; </xsl:text>
<xsl:text> font-size:</xsl:text>
<xsl:value-of select="@fo:font-size"></xsl:value-of><xsl:text>; </xsl:text>
</xsl:template>
<xsl:template match="office:styles/style:text-properties">
<xsl:text> font-size:</xsl:text>
<xsl:value-of select="@fo:font-size"></xsl:value-of><xsl:text>; </xsl:text>
<xsl:text> font-weight:</xsl:text>
<xsl:value-of select="@fo:font-weight"></xsl:value-of><xsl:text>; </xsl:text>
<xsl:text> font-family:</xsl:text>
<xsl:value-of select="@fo:font-family"></xsl:value-of><xsl:text>; </xsl:text>
<xsl:text> font-style:</xsl:text>
<xsl:value-of select="@fo:font-style"></xsl:value-of><xsl:text>; </xsl:text>
</xsl:template>
<xsl:template match="office:document-content">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="text:p">
<p><xsl:apply-templates/></p>
</xsl:template>
<xsl:template match="text:span[@text:style-name='T1']">
<b><xsl:apply-templates/></b>
</xsl:template>
<xsl:template match="table:table">
<table border = "1">
<xsl:for-each select="table:table-row">
<tr>
<xsl:for-each select="table:table-cell">
<td>
<xsl:value-of select="text:p"/>
</td>
</xsl:for-each>
</tr>
</xsl:for-each>
</table>
</xsl:template>
<xsl:template match="draw:frame/draw:image">
<xsl:element name="img">
<xsl:attribute name="src">
<xsl:value-of select="@xlink:href"/>
</xsl:attribute>
</xsl:element>
</xsl:template>
</xsl:stylesheet>