/xmlbench/trunk

To get this branch, use:
bzr branch http://darksoft.org/webbzr/xmlbench/trunk

« back to all changes in this revision

Viewing changes to xml.files/odt/export/common/styles/style_mapping_css.xsl

  • Committer: Suren A. Chilingaryan
  • Date: 2009-02-16 09:27:17 UTC
  • Revision ID: csa@dside.dyndns.org-20090216092717-wipyvaaw2srxhgns
Initial import

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?xml version="1.0" encoding="UTF-8"?>
 
2
<!--
 
3
 
 
4
  DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 
5
  
 
6
  Copyright 2008 by Sun Microsystems, Inc.
 
7
 
 
8
  OpenOffice.org - a multi-platform office productivity suite
 
9
 
 
10
  $RCSfile: style_mapping_css.xsl,v $
 
11
 
 
12
  $Revision: 1.2.62.1 $
 
13
 
 
14
  This file is part of OpenOffice.org.
 
15
 
 
16
  OpenOffice.org is free software: you can redistribute it and/or modify
 
17
  it under the terms of the GNU Lesser General Public License version 3
 
18
  only, as published by the Free Software Foundation.
 
19
 
 
20
  OpenOffice.org is distributed in the hope that it will be useful,
 
21
  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
22
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
23
  GNU Lesser General Public License version 3 for more details
 
24
  (a copy is included in the LICENSE file that accompanied this code).
 
25
 
 
26
  You should have received a copy of the GNU Lesser General Public License
 
27
  version 3 along with OpenOffice.org.  If not, see
 
28
  <http://www.openoffice.org/license.html>
 
29
  for a copy of the LGPLv3 License.
 
30
 
 
31
-->
 
32
<!--
 
33
        For further documentation and updates visit http://xml.openoffice.org/odf2xhtml
 
34
-->
 
35
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0" xmlns:config="urn:oasis:names:tc:opendocument:xmlns:config:1.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dom="http://www.w3.org/2001/xml-events" xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0" xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0" xmlns:math="http://www.w3.org/1998/Math/MathML" xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:ooo="http://openoffice.org/2004/office" xmlns:oooc="http://openoffice.org/2004/calc" xmlns:ooow="http://openoffice.org/2004/writer" xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:xforms="http://www.w3.org/2002/xforms" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" exclude-result-prefixes="chart config dc dom dr3d draw fo form math meta number office ooo oooc ooow script style svg table text xforms xlink xsd xsi">
 
36
 
 
37
 
 
38
        <!-- *** Properties with a 'fo:' prefix *** -->
 
39
        <xsl:template match="@fo:background-color">
 
40
                <xsl:text>background-color:</xsl:text>
 
41
                <xsl:value-of select="."/>
 
42
                <xsl:text>; </xsl:text>
 
43
        </xsl:template>
 
44
 
 
45
        <xsl:template match="@fo:border | @fo:border-top | @fo:border-bottom | @fo:border-left | @fo:border-right">
 
46
                <xsl:variable name="borderType" select="substring-after(name(), ':')"/>
 
47
                <xsl:choose>
 
48
                        <xsl:when test=". = 'none'">
 
49
                                <xsl:value-of select="$borderType"/>
 
50
                                <xsl:text>-style:none; </xsl:text>
 
51
                        </xsl:when>
 
52
                        <xsl:otherwise>
 
53
                                <xsl:variable name="borderWidth" select="substring-before(., ' ')"/>
 
54
                                <xsl:variable name="borderStyle" select="substring-before(substring-after(., ' '), ' ')"/>
 
55
                                <xsl:variable name="borderColor" select="substring-after(substring-after(., ' '), ' ')"/>
 
56
 
 
57
                           <!-- More information at template 'round-up-border-width' -->
 
58
                                <xsl:variable name="borderWidthFixed">
 
59
                                        <xsl:call-template name="round-up-border-width">
 
60
                                                <xsl:with-param name="borderWidth" select="$borderWidth"/>
 
61
                                                <xsl:with-param name="multiplier">
 
62
                                                        <xsl:choose>
 
63
                                                                <xsl:when test="$borderStyle = 'double'">3</xsl:when>
 
64
                                                                <xsl:otherwise>1</xsl:otherwise>
 
65
                                                        </xsl:choose>
 
66
                                                </xsl:with-param>
 
67
                                        </xsl:call-template>
 
68
                                </xsl:variable>
 
69
 
 
70
                                <xsl:value-of select="$borderType"/>
 
71
                                <xsl:text>-width:</xsl:text>
 
72
                                <xsl:value-of select="$borderWidthFixed"/>
 
73
                                <xsl:text>; </xsl:text>
 
74
                                <xsl:value-of select="$borderType"/>
 
75
                                <xsl:text>-style:</xsl:text>
 
76
                                <xsl:value-of select="$borderStyle"/>
 
77
                                <xsl:text>; </xsl:text>
 
78
                                <xsl:value-of select="$borderType"/>
 
79
                                <xsl:text>-color:</xsl:text>
 
80
                                <xsl:value-of select="$borderColor"/>
 
81
                                <xsl:text>; </xsl:text>
 
82
                        </xsl:otherwise>
 
83
                </xsl:choose>
 
84
        </xsl:template>
 
85
 
 
86
        <!-- NOTE: Still there have to be placed a <br clear='all' /> to disable the flow!!!!-->
 
87
        <xsl:template match="@fo:clear">
 
88
                <xsl:text>clear:both; </xsl:text>
 
89
        </xsl:template>
 
90
 
 
91
        <!-- text-shadow is a CSS2 feature and yet not common used in user-agents -->
 
92
        <xsl:template match="@fo:color |@svg:font-family |@fo:font-size |@fo:font-style |@fo:font-weight |@fo:text-indent |@fo:text-shadow">
 
93
                <xsl:value-of select="substring-after(name(), ':')"/>
 
94
                <xsl:text>:</xsl:text>
 
95
                <xsl:value-of select="."/>
 
96
                <xsl:text>; </xsl:text>
 
97
        </xsl:template>
 
98
 
 
99
        <!-- Maps fo:margin as well fo:margin-top, fo:margin-bottom, fo:padding-left, fo:margin-right -->
 
100
        <!-- Maps fo:padding as well fo:padding-top, fo:padding-bottom, fo:padding-left, fo:padding-right -->
 
101
        <xsl:template match="@fo:line-height | @fo:width |@fo:margin | @fo:margin-top | @fo:margin-bottom | @fo:margin-left | @fo:margin-right | @fo:padding | @fo:padding-top | @fo:padding-bottom | @fo:padding-left | @fo:padding-right">
 
102
                <xsl:value-of select="substring-after(name(), ':')"/>
 
103
                <xsl:text>:</xsl:text>
 
104
                <!-- Map once erroneusly used inch shortage 'inch' to CSS shortage 'in' -->
 
105
                <xsl:choose>
 
106
                        <xsl:when test="contains(., 'inch')">
 
107
                                <xsl:value-of select="substring-before(.,'ch')"/>
 
108
                        </xsl:when>
 
109
                        <xsl:otherwise>
 
110
                                <xsl:value-of select="."/>
 
111
                        </xsl:otherwise>
 
112
                </xsl:choose>
 
113
                <xsl:text>; </xsl:text>
 
114
        </xsl:template>
 
115
 
 
116
        <xsl:template match="@fo:text-align">
 
117
                <!-- 'important' is necessary as table cell value alignment is decided by runtime over the valuetype
 
118
                        Otherwise a table cell style-class would always be outnumbered by the run-time alignment value -->
 
119
                <xsl:choose>
 
120
                        <xsl:when test="contains(., 'start')">
 
121
                                <xsl:text>text-align:left ! important; </xsl:text>
 
122
                        </xsl:when>
 
123
                        <xsl:when test="contains(., 'end')">
 
124
                                <xsl:text>text-align:right ! important; </xsl:text>
 
125
                        </xsl:when>
 
126
                        <xsl:otherwise>
 
127
                                <xsl:text>text-align:</xsl:text>
 
128
                                <xsl:value-of select="."/>
 
129
                                <xsl:text> ! important; </xsl:text>
 
130
                        </xsl:otherwise>
 
131
                </xsl:choose>
 
132
        </xsl:template>
 
133
 
 
134
        <xsl:template match="@style:vertical-align">
 
135
                <xsl:choose>
 
136
                        <xsl:when test="contains(., 'bottom')">
 
137
                                <xsl:text>vertical-align:bottom; </xsl:text>
 
138
                        </xsl:when>
 
139
                        <xsl:when test="contains(., 'middle')">
 
140
                                <xsl:text>vertical-align:middle; </xsl:text>
 
141
                        </xsl:when>
 
142
                        <xsl:otherwise>
 
143
                                <xsl:text>vertical-align:top; </xsl:text>
 
144
                        </xsl:otherwise>
 
145
                </xsl:choose>
 
146
        </xsl:template>
 
147
 
 
148
<!-- *** Properties with a 'style:' prefix *** -->
 
149
        <!-- NOTE: Can 'inside' | 'from-inside' better be handled:
 
150
        <!ATTLIST * style:horizontal-pos (from-left|left|center|right|from-inside|inside|outside)#IMPLIED>-->
 
151
        <xsl:template match="@style:horizontal-pos">
 
152
                <xsl:choose>
 
153
                        <xsl:when test=".='left'">
 
154
                                <xsl:text>text-align:left; </xsl:text>
 
155
                        </xsl:when>
 
156
                        <xsl:when test=". = 'right'">
 
157
                                <xsl:text>text-align:right; </xsl:text>
 
158
                        </xsl:when>
 
159
                        <xsl:when test=".='center'">
 
160
                                <xsl:text>text-align:center; </xsl:text>
 
161
                        </xsl:when>
 
162
                        <!-- NOTE: currently other values are not used.
 
163
                                If the property value is from-left or from-inside,
 
164
                                the svg:x attribute associated with the frame element specifies
 
165
                                the horizontal position of the frame.
 
166
                                Otherwise the svg:x attribute is ignored for text documents.
 
167
                        -->
 
168
                </xsl:choose>
 
169
        </xsl:template>
 
170
 
 
171
        <xsl:template match="@style:column-width">
 
172
                <xsl:text>width:</xsl:text>
 
173
                <xsl:choose>
 
174
                        <!-- changing the distance measure: inch to in -->
 
175
                        <xsl:when test="contains(., 'inch')">
 
176
                                <xsl:value-of select="substring-before(.,'ch')"/>
 
177
                        </xsl:when>
 
178
                        <xsl:otherwise>
 
179
                                <xsl:value-of select="."/>
 
180
                        </xsl:otherwise>
 
181
                </xsl:choose>
 
182
                <xsl:text>; </xsl:text>
 
183
        </xsl:template>
 
184
 
 
185
        <xsl:template match="@style:text-underline-style">
 
186
                <xsl:text>text-decoration:</xsl:text>
 
187
                <xsl:choose>
 
188
                        <!-- changing the distance measure: inch to in -->
 
189
                        <xsl:when test=".='none'">
 
190
                                <xsl:text>none ! important</xsl:text>
 
191
                        </xsl:when>
 
192
                        <xsl:otherwise>
 
193
                                <xsl:text>underline</xsl:text>
 
194
                        </xsl:otherwise>
 
195
                </xsl:choose>
 
196
                <xsl:text>; </xsl:text>
 
197
        </xsl:template>
 
198
 
 
199
        <xsl:template match="@style:font-name">
 
200
                <xsl:param name="globalData" />
 
201
 
 
202
                <xsl:text>font-family:</xsl:text>
 
203
                <xsl:variable name="content" select="."/>
 
204
                <xsl:variable name="quote">'</xsl:variable>
 
205
                <xsl:variable name="fontName" select="$globalData/office:font-face-decls/style:font-face[@style:name=$content]/@svg:font-family" />
 
206
                <xsl:value-of select="translate($fontName, $quote, '')"/>
 
207
                <xsl:text>; </xsl:text>
 
208
        </xsl:template>
 
209
 
 
210
        <xsl:template match="@style:row-height">
 
211
                <xsl:text>height:</xsl:text>
 
212
                <xsl:choose>
 
213
                        <!-- changing the distance measure: inch to in -->
 
214
                        <xsl:when test="contains(., 'inch')">
 
215
                                <xsl:value-of select="substring-before(.,'ch')"/>
 
216
                        </xsl:when>
 
217
                        <xsl:otherwise>
 
218
                                <xsl:value-of select="."/>
 
219
                        </xsl:otherwise>
 
220
                </xsl:choose>
 
221
                <xsl:text>; </xsl:text>
 
222
        </xsl:template>
 
223
 
 
224
        <xsl:template match="@svg:strikethrough-position">
 
225
                <xsl:if test="not(.='none')">
 
226
                        <xsl:text>text-decoration:line-through; </xsl:text>
 
227
                </xsl:if>
 
228
        </xsl:template>
 
229
        <xsl:template match="@style:text-position">
 
230
                <xsl:if test="contains(., 'sub')">
 
231
                        <xsl:text>vertical-align:sub; </xsl:text>
 
232
                        <xsl:if test="contains(., '%')">
 
233
                                <xsl:text>font-size:</xsl:text>
 
234
                                <xsl:value-of select="substring-after(., 'sub ')"/>
 
235
                                <xsl:text>;</xsl:text>
 
236
                        </xsl:if>
 
237
                </xsl:if>
 
238
                <xsl:if test="contains(., 'super')">
 
239
                        <xsl:text>vertical-align:super; </xsl:text>
 
240
                        <xsl:if test="contains(., '%')">
 
241
                                <xsl:text>font-size:</xsl:text>
 
242
                                <xsl:value-of select="substring-after(., 'super ')"/>
 
243
                                <xsl:text>;</xsl:text>
 
244
                        </xsl:if>
 
245
                </xsl:if>
 
246
        </xsl:template>
 
247
 
 
248
        <xsl:template match="@style:vertical-pos">
 
249
                <xsl:choose>
 
250
                        <xsl:when test=".='from-top'">
 
251
                                <xsl:text>vertical-align:top; </xsl:text>
 
252
                        </xsl:when>
 
253
                        <xsl:otherwise>
 
254
                                <xsl:text>vertical-align:</xsl:text>
 
255
                                <xsl:value-of select="."/>
 
256
                                <xsl:text>; </xsl:text>
 
257
                        </xsl:otherwise>
 
258
                </xsl:choose>
 
259
        </xsl:template>
 
260
 
 
261
        <xsl:template match="@style:width">
 
262
                <xsl:text>width:</xsl:text>
 
263
                <xsl:choose>
 
264
                        <!-- changing the distance measure: inch to in -->
 
265
                        <xsl:when test="contains(., 'inch')">
 
266
                                <xsl:value-of select="substring-before(.,'ch')"/>
 
267
                        </xsl:when>
 
268
                        <xsl:otherwise>
 
269
                                <xsl:value-of select="."/>
 
270
                        </xsl:otherwise>
 
271
                </xsl:choose>
 
272
                <xsl:text>; </xsl:text>
 
273
        </xsl:template>
 
274
        <xsl:template match="@style:wrap">
 
275
                <xsl:choose>
 
276
                        <xsl:when test=".='left'">
 
277
                                <xsl:text>float:right; </xsl:text>
 
278
                        </xsl:when>
 
279
                        <xsl:when test=".='right'">
 
280
                                <xsl:text>float:left; </xsl:text>
 
281
                        </xsl:when>
 
282
                </xsl:choose>
 
283
        </xsl:template>
 
284
                                <!-- *** Properties with a no 'fo:' or 'style:' prefix *** -->
 
285
 
 
286
        <xsl:template match="@table:align">
 
287
                <xsl:choose>
 
288
                        <xsl:when test=".='left'">
 
289
                        <!-- Note: problems with meeting minutes example
 
290
                                <xsl:text>float:right; </xsl:text> --></xsl:when>
 
291
                        <xsl:when test=".='right'">
 
292
                        <!-- Note: problems with meeting minutes example
 
293
                                <xsl:text>float:left; </xsl:text> --></xsl:when>
 
294
                        <xsl:otherwise>
 
295
                                <xsl:text>float:none; </xsl:text>
 
296
                        </xsl:otherwise>
 
297
                </xsl:choose>
 
298
        </xsl:template>
 
299
 
 
300
        <xsl:template match="style:background-image">
 
301
                <xsl:text>background-image:url(</xsl:text>
 
302
                <xsl:value-of select="@xlink:href"/>
 
303
                <xsl:text>); </xsl:text>
 
304
                <xsl:choose>
 
305
                        <xsl:when test="@style:repeat = 'repeat'">
 
306
                                <xsl:text>background-repeat:repeat; </xsl:text>
 
307
                        </xsl:when>
 
308
                        <xsl:otherwise>
 
309
                                <xsl:text>background-repeat:no-repeat; </xsl:text>
 
310
                        </xsl:otherwise>
 
311
                </xsl:choose>
 
312
        </xsl:template>
 
313
 
 
314
        <!-- Changing border width measure to cm and enlarging border-width to the Mozilla browser(1.7)
 
315
                 visible minimum width
 
316
                        - 0.0133cm for solid style
 
317
                        - 0.0399cm for double style
 
318
                 as there are three border lines painted -->
 
319
        <xsl:template name="round-up-border-width">
 
320
                <xsl:param name="borderWidth"/>
 
321
                <xsl:param name="multiplier"/>
 
322
 
 
323
                <xsl:variable name="borderWidthByCentimeter">
 
324
                        <xsl:call-template name="convert2cm">
 
325
                                <xsl:with-param name="value" select="$borderWidth"/>
 
326
                        </xsl:call-template>
 
327
                </xsl:variable>
 
328
                <xsl:variable name="minimalBorderWidth" select="0.0133 * $multiplier"/>
 
329
                <xsl:choose>
 
330
                        <xsl:when test="number($borderWidthByCentimeter) &lt; $minimalBorderWidth">
 
331
                                <xsl:value-of select="$minimalBorderWidth"/>
 
332
                                <xsl:text>cm</xsl:text>
 
333
                        </xsl:when>
 
334
                        <xsl:otherwise>
 
335
                                <xsl:value-of select="$borderWidthByCentimeter"/>
 
336
                                <xsl:text>cm</xsl:text>
 
337
                        </xsl:otherwise>
 
338
                </xsl:choose>
 
339
        </xsl:template>
 
340
</xsl:stylesheet>
 
341