1
<?xml version="1.0" encoding="UTF-8"?>
4
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6
Copyright 2008 by Sun Microsystems, Inc.
8
OpenOffice.org - a multi-platform office productivity suite
10
$RCSfile: header.xsl,v $
14
This file is part of OpenOffice.org.
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.
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).
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.
33
For further documentation and updates visit http://xml.openoffice.org/odf2xhtml
35
<xsl:stylesheet version="1.0"
36
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
37
xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0"
38
xmlns:config="urn:oasis:names:tc:opendocument:xmlns:config:1.0"
39
xmlns:dc="http://purl.org/dc/elements/1.1/"
40
xmlns:dom="http://www.w3.org/2001/xml-events"
41
xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0"
42
xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0"
43
xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0"
44
xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0"
45
xmlns:math="http://www.w3.org/1998/Math/MathML"
46
xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0"
47
xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0"
48
xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0"
49
xmlns:ooo="http://openoffice.org/2004/office"
50
xmlns:oooc="http://openoffice.org/2004/calc"
51
xmlns:ooow="http://openoffice.org/2004/writer"
52
xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0"
53
xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0"
54
xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0"
55
xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0"
56
xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0"
57
xmlns:xforms="http://www.w3.org/2002/xforms"
58
xmlns:xlink="http://www.w3.org/1999/xlink"
59
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
60
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
61
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 xforms xsd xsi"
62
xmlns="http://www.w3.org/1999/xhtml">
65
<!-- ************** -->
66
<!-- *** header *** -->
67
<!-- ************** -->
69
<xsl:template name="create-header">
70
<xsl:param name="globalData" />
72
<xsl:element name="head">
73
<xsl:attribute name="profile">http://dublincore.org/documents/dcmi-terms/</xsl:attribute>
74
<xsl:if test="$debugEnabled"><xsl:message>CSS helper variable will be created....</xsl:message></xsl:if>
75
<xsl:call-template name='xhtml-header-properties'>
76
<xsl:with-param name="globalData" select="$globalData" />
79
<xsl:if test="$debugEnabled"><xsl:message>CSS variable ready, header will be created....</xsl:message></xsl:if>
80
<!-- constructing the css header simulating inheritance of style-families by style order -->
81
<xsl:call-template name='create-css-styleheader'>
82
<xsl:with-param name="globalData" select="$globalData" />
84
<xsl:if test="$debugEnabled"><xsl:message>CSS header creation finished!</xsl:message></xsl:if>
90
<!-- Creating a CSS style header from the collected styles of the 'globalData' parameter -->
91
<xsl:template name='create-css-styleheader'>
92
<xsl:param name="globalData" />
94
<xsl:element name="style">
95
<xsl:attribute name="type">text/css</xsl:attribute>
98
<xsl:call-template name='create-page-layout'>
99
<xsl:with-param name="globalData" select="$globalData" />
101
<xsl:text>table { border-collapse:collapse; border-spacing:0; empty-cells:show }
104
<xsl:when test="/*/office:body/office:spreadsheet"><xsl:text>td, th { vertical-align:top; font-size:10pt;}
105
</xsl:text></xsl:when>
106
<xsl:otherwise><xsl:text>td, th { vertical-align:top; font-size:12pt;}
107
</xsl:text></xsl:otherwise>
109
<xsl:text>h1, h2, h3, h4, h5, h6 { clear:both }
111
<xsl:text>ol, ul { margin:0; padding:0;}
113
<xsl:text>li { list-style: none; margin:0; padding:0;}
115
<xsl:text>li span.odfLiEnd { clear: both; line-height:0; width:0; height:0; margin:0; padding:0; }
117
<xsl:text>span.footnodeNumber { padding-right:1em; }
119
<xsl:text>* { margin:0; }
121
<xsl:call-template name="write-mapped-CSS-styles">
122
<xsl:with-param name="globalData" select="$globalData" />
127
<xsl:template name="write-mapped-CSS-styles">
128
<xsl:param name="globalData" />
129
<xsl:param name="styleNo" select="1"/>
130
<xsl:param name="emptyStyles"/>
133
<xsl:when test="$globalData/all-styles/style[$styleNo]">
134
<!-- If there is still a style to be written -->
135
<!-- setting the context -->
136
<xsl:for-each select="$globalData/all-styles/style[$styleNo]">
138
<xsl:when test="final-properties != ''">
139
<!-- NOTE: easy process, as only the style family in conjunction with the style name, makes the style unambigous -->
140
<xsl:text>.</xsl:text><!--<xsl:value-of select="@style:family" /><xsl:text>:</xsl:text>--><xsl:value-of select="translate(@style:name, '.,;: %()[]/\+', '_____________')"/><xsl:text> { </xsl:text> <xsl:value-of select="final-properties" /><xsl:text>}
142
<xsl:call-template name="write-mapped-CSS-styles">
143
<xsl:with-param name="globalData" select="$globalData" />
144
<xsl:with-param name="emptyStyles" select="$emptyStyles"/>
145
<xsl:with-param name="styleNo" select="$styleNo + 1"/>
149
<xsl:call-template name="write-mapped-CSS-styles">
150
<xsl:with-param name="globalData" select="$globalData" />
151
<xsl:with-param name="emptyStyles" select="concat($emptyStyles, '.', @style:name, ' ')"/>
152
<xsl:with-param name="styleNo" select="$styleNo + 1"/>
159
<!-- Otherwise all styles have been processed and the empty styles have to be given out -->
160
<xsl:comment> ODF styles with no properties representable as CSS </xsl:comment><xsl:text>
161
</xsl:text><xsl:value-of select="$emptyStyles"/><xsl:text>{ }
168
<!-- Creating CSS page layout based on first office master style -->
169
<xsl:template name='create-page-layout'>
170
<xsl:param name="globalData" />
172
<xsl:text>@page { </xsl:text>
174
<xsl:call-template name="page-size">
175
<xsl:with-param name="globalData" select="$globalData" />
177
<xsl:call-template name="page-margin">
178
<xsl:with-param name="globalData" select="$globalData" />
187
<xsl:template name="page-size">
188
<xsl:param name="globalData" />
190
<!-- approximation as attribute belongs to a page style, which won't work in XHTML -->
191
<xsl:variable name="pageProperties" select="$globalData/styles-file/*/office:automatic-styles/style:page-layout[1]/style:page-layout-properties"/>
193
<xsl:variable name="printOrientation" select="$pageProperties/@style:print-orientation" />
194
<xsl:variable name="pageWidth" select="$pageProperties/@fo:page-width" />
195
<xsl:variable name="pageHeight" select="$pageProperties/@fo:page-height" />
197
<xsl:when test="$pageWidth and $pageHeight">
198
<xsl:text>size: </xsl:text>
199
<xsl:value-of select="$pageWidth" />
200
<xsl:text> </xsl:text>
201
<xsl:value-of select="$pageHeight" />
202
<xsl:text>; </xsl:text>
204
<xsl:when test="$printOrientation">
205
<xsl:text>size: </xsl:text>
206
<xsl:value-of select="$printOrientation" />
207
<xsl:text>; </xsl:text>
214
<xsl:template name="page-margin">
215
<xsl:param name="globalData" />
217
<!-- approximation as attribute belongs to a page style, which won't work in XHTML -->
218
<xsl:variable name="pageProperties" select="$globalData/styles-file/*/office:automatic-styles/style:page-layout[1]/style:page-layout-properties"/>
220
<xsl:variable name="marginTop" select="$pageProperties/@fo:margin-top" />
221
<xsl:if test="$marginTop">
222
<xsl:text>margin-top: </xsl:text>
223
<xsl:value-of select="$marginTop" />
224
<xsl:text>; </xsl:text>
226
<xsl:variable name="marginBottom" select="$pageProperties/@fo:margin-bottom" />
227
<xsl:if test="$marginBottom">
228
<xsl:text>margin-bottom: </xsl:text>
229
<xsl:value-of select="$marginBottom" />
230
<xsl:text>; </xsl:text>
232
<xsl:variable name="marginLeft" select="$pageProperties/@fo:margin-left" />
233
<xsl:if test="$marginLeft">
234
<xsl:text>margin-left: </xsl:text>
235
<xsl:value-of select="$marginLeft" />
236
<xsl:text>; </xsl:text>
238
<xsl:variable name="marginRight" select="$pageProperties/@fo:margin-right" />
239
<xsl:if test="$marginRight">
240
<xsl:text>margin-right: </xsl:text>
241
<xsl:value-of select="$marginRight" />
246
<!-- *************************** -->
247
<!-- *** Common XHTML header *** -->
248
<!-- *************************** -->
250
<xsl:template name='xhtml-header-properties'>
251
<xsl:param name="globalData" />
253
<xsl:variable name="netloc">
254
<xsl:for-each select="$globalData/meta-file/*/office:meta/meta:user-defined">
255
<xsl:if test="./@meta:name='ODF.base'">
256
<xsl:value-of select="." />
259
<xsl:for-each select="$globalData/meta-file/*/office:meta/meta:user-defined">
260
<xsl:if test="./@meta:name='ODF.filename'">
261
<xsl:value-of select="." />
266
<xsl:variable name="lang">
268
<xsl:when test="$globalData/meta-file/*/office:meta/dc:language">
269
<xsl:value-of select="$globalData/meta-file/*/office:meta/dc:language" />
271
<xsl:otherwise>en-US</xsl:otherwise>
275
<xsl:variable name="prov">
277
<xsl:when test="$globalData/meta-file/*/office:meta/meta:printed-by">
278
<xsl:value-of select="concat('Printed by "',$globalData/meta-file/*/office:meta/meta:printed-by,'"[dc:publisher] on "',$globalData/meta-file/*/office:meta/meta:print-date,'"[dc:date] in "',$lang,'"[dc:language]')" />
284
<xsl:variable name="keywords">
285
<xsl:for-each select="$globalData/meta-file/*/office:meta/meta:keyword">
286
<xsl:value-of select="." />
287
<xsl:if test="position() != last()">
288
<xsl:text>, </xsl:text>
293
<!-- explicit output content-type for low-tech browser (e.g. IE6) -->
294
<xsl:element name="meta">
295
<xsl:attribute name="http-equiv">Content-Type</xsl:attribute>
296
<xsl:attribute name="content">text/html; charset=utf-8</xsl:attribute>
299
<!-- title of document for browser frame title -->
300
<xsl:element name="title">
301
<xsl:attribute name="lang" namespace="http://www.w3.org/XML/1998/namespace">
302
<xsl:value-of select="$lang" />
306
<xsl:when test="$globalData/meta-file/*/office:meta/dc:title">
307
<xsl:value-of select="$globalData/meta-file/*/office:meta/dc:title" />
309
<!-- providing the mandatory title is a workaround for an IE bug-->
311
<xsl:text>- no title specified</xsl:text>
316
<!-- title, in DC syntax -->
317
<xsl:element name="meta">
318
<xsl:attribute name="name">DCTERMS.title</xsl:attribute>
319
<xsl:attribute name="content">
320
<xsl:value-of select="$globalData/meta-file/*/office:meta/dc:title" />
322
<xsl:attribute name="lang" namespace="http://www.w3.org/XML/1998/namespace">
323
<xsl:value-of select="$lang" />
327
<!-- the identifier for source (identifier) -->
328
<xsl:call-template name="add-meta-tag">
329
<xsl:with-param name="meta-name" select="'DCTERMS.identifier'" />
330
<xsl:with-param name="meta-data" select="translate($netloc, ' ','')" />
331
<xsl:with-param name="meta-enc" select="'DCTERMS.URI'" />
334
<!-- the language for source (language) -->
335
<xsl:call-template name="add-meta-tag">
336
<xsl:with-param name="meta-name" select="'DCTERMS.language'" />
337
<xsl:with-param name="meta-data" select="$lang" />
338
<xsl:with-param name="meta-enc" select="'DCTERMS.RFC4646'" />
341
<!-- a bit commercial (generator) -->
342
<xsl:element name="meta">
343
<xsl:attribute name="name">DCTERMS.source</xsl:attribute>
344
<xsl:attribute name="content">http://xml.openoffice.org/odf2xhtml</xsl:attribute>
347
<!-- the author of the input source (author) -->
348
<xsl:call-template name="add-meta-tag">
349
<xsl:with-param name="meta-name" select="'DCTERMS.creator'" />
350
<xsl:with-param name="meta-data" select="$globalData/meta-file/*/office:meta/meta:initial-creator" />
353
<!-- creation-date of the input source (issued) -->
354
<xsl:call-template name="add-meta-tag">
355
<xsl:with-param name="meta-name" select="'DCTERMS.issued'" />
356
<xsl:with-param name="meta-data" select="$globalData/meta-file/*/office:meta/meta:creation-date" />
357
<xsl:with-param name="meta-enc" select="'DCTERMS.W3CDTF'" />
360
<!-- name of last changing person of the input source (changedby) -->
361
<xsl:call-template name="add-meta-tag">
362
<xsl:with-param name="meta-name" select="'DCTERMS.contributor'" />
363
<xsl:with-param name="meta-data" select="$globalData/meta-file/*/office:meta/dc:creator" />
366
<!-- last changing date of the input source (changed) -->
367
<xsl:call-template name="add-meta-tag">
368
<xsl:with-param name="meta-name" select="'DCTERMS.modified'" />
369
<xsl:with-param name="meta-data" select="$globalData/meta-file/*/office:meta/dc:date" />
370
<xsl:with-param name="meta-enc" select="'DCTERMS.W3CDTF'" />
373
<!-- Last print, as provenance -->
374
<xsl:if test="$prov">
375
<xsl:call-template name="add-meta-tag">
376
<xsl:with-param name="meta-name" select="'DCTERMS.provenance'" />
377
<xsl:with-param name="meta-data" select="$prov" />
378
<xsl:with-param name="meta-lang" select="$lang" />
382
<!-- keywords about the input source (keywords) -->
383
<xsl:call-template name="add-meta-tag">
384
<xsl:with-param name="meta-name" select="'DCTERMS.subject'" />
385
<xsl:with-param name="meta-data" select="normalize-space(concat($globalData/meta-file/*/office:meta/dc:subject,', ',$keywords))" />
386
<xsl:with-param name="meta-lang" select="$lang" />
389
<!-- detailed description about the input source (description) -->
390
<xsl:call-template name="add-meta-tag">
391
<xsl:with-param name="meta-name" select="'DCTERMS.description'" />
392
<xsl:with-param name="meta-data" select="$globalData/meta-file/*/office:meta/dc:description" />
393
<xsl:with-param name="meta-lang" select="$lang" />
397
<!-- user defined use of DCTERM tags -->
398
<xsl:for-each select="$globalData/meta-file/*/office:meta/meta:user-defined[starts-with(@meta:name,'DCTERMS.')][not(.='')]">
399
<xsl:call-template name="add-meta-tag">
400
<xsl:with-param name="meta-name" select="@meta:name" />
401
<xsl:with-param name="meta-data" select="." />
402
<!-- <xsl:with-param name="meta-lang" select="$lang" /> -->
405
<!-- user defined use of DC tags (legacy) -->
406
<xsl:for-each select="$globalData/meta-file/*/office:meta/meta:user-defined[starts-with(@meta:name,'DC.')][not(.='')]">
407
<xsl:call-template name="add-meta-tag">
408
<xsl:with-param name="meta-name" select="@meta:name" />
409
<xsl:with-param name="meta-data" select="." />
410
<!-- <xsl:with-param name="meta-lang" select="$lang" /> -->
414
<link rel="schema.DC" href="http://purl.org/dc/elements/1.1/" hreflang="en" />
415
<link rel="schema.DCTERMS" href="http://purl.org/dc/terms/" hreflang="en" />
416
<link rel="schema.DCTYPE" href="http://purl.org/dc/dcmitype/" hreflang="en" />
417
<link rel="schema.DCAM" href="http://purl.org/dc/dcam/" hreflang="en" />
418
<!-- W3C GRDDL Profile -->
420
<link rel="transformation" href="http://xml.openoffice.org/odf2xhtml/rdf-extract.xsl" />
423
<!-- base URL of document for resolving relative links -->
424
<xsl:element name="base">
425
<xsl:attribute name="href">
426
<!-- earlier 'targetURL' was used for an absoulte reference of base provided by the Office (file URL)
427
<xsl:value-of select="$targetURL" />
428
now '.' let relative links work, even if document has been moved -->
429
<xsl:text>.</xsl:text>
434
<!-- generic template for adding common meta tags -->
435
<xsl:template name="add-meta-tag">
436
<xsl:param name="meta-name" />
437
<xsl:param name="meta-data" />
438
<xsl:param name="meta-enc" />
439
<xsl:param name="meta-lang" />
441
<xsl:if test="$meta-data">
442
<xsl:element name="meta">
443
<xsl:attribute name="name">
444
<xsl:value-of select="$meta-name" />
446
<xsl:attribute name="content">
447
<xsl:value-of select="$meta-data" />
449
<xsl:if test="$meta-enc">
450
<xsl:attribute name="scheme">
451
<xsl:value-of select="$meta-enc" />
454
<xsl:if test="$meta-lang">
455
<xsl:attribute name="lang" namespace="http://www.w3.org/XML/1998/namespace">
456
<xsl:value-of select="$meta-lang" />