header.xsl 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!--
  3. * This file is part of the LibreOffice project.
  4. *
  5. * This Source Code Form is subject to the terms of the Mozilla Public
  6. * License, v. 2.0. If a copy of the MPL was not distributed with this
  7. * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  8. *
  9. * This file incorporates work covered by the following license notice:
  10. *
  11. * Licensed to the Apache Software Foundation (ASF) under one or more
  12. * contributor license agreements. See the NOTICE file distributed
  13. * with this work for additional information regarding copyright
  14. * ownership. The ASF licenses this file to you under the Apache
  15. * License, Version 2.0 (the "License"); you may not use this file
  16. * except in compliance with the License. You may obtain a copy of
  17. * the License at http://www.apache.org/licenses/LICENSE-2.0 .
  18. -->
  19. <!--
  20. For further documentation and updates visit http://xml.openoffice.org/odf2xhtml
  21. -->
  22. <xsl:stylesheet version="1.0"
  23. xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  24. xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0"
  25. xmlns:config="urn:oasis:names:tc:opendocument:xmlns:config:1.0"
  26. xmlns:dc="http://purl.org/dc/elements/1.1/"
  27. xmlns:dom="http://www.w3.org/2001/xml-events"
  28. xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0"
  29. xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0"
  30. xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0"
  31. xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0"
  32. xmlns:math="http://www.w3.org/1998/Math/MathML"
  33. xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0"
  34. xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0"
  35. xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0"
  36. xmlns:ooo="http://openoffice.org/2004/office"
  37. xmlns:oooc="http://openoffice.org/2004/calc"
  38. xmlns:ooow="http://openoffice.org/2004/writer"
  39. xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0"
  40. xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0"
  41. xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0"
  42. xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0"
  43. xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0"
  44. xmlns:xforms="http://www.w3.org/2002/xforms"
  45. xmlns:xlink="http://www.w3.org/1999/xlink"
  46. xmlns:xsd="http://www.w3.org/2001/XMLSchema"
  47. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  48. 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"
  49. xmlns="http://www.w3.org/1999/xhtml">
  50. <!-- ************** -->
  51. <!-- *** header *** -->
  52. <!-- ************** -->
  53. <xsl:template name="create-header">
  54. <xsl:param name="globalData" />
  55. <xsl:element name="head">
  56. <xsl:attribute name="profile">http://dublincore.org/documents/dcmi-terms/</xsl:attribute>
  57. <xsl:if test="$debugEnabled"><xsl:message>CSS helper variable will be created...</xsl:message></xsl:if>
  58. <xsl:call-template name='xhtml-header-properties'>
  59. <xsl:with-param name="globalData" select="$globalData" />
  60. </xsl:call-template>
  61. <xsl:if test="$debugEnabled"><xsl:message>CSS variable ready, header will be created...</xsl:message></xsl:if>
  62. <!-- constructing the css header simulating inheritance of style-families by style order -->
  63. <xsl:call-template name='create-css-styleheader'>
  64. <xsl:with-param name="globalData" select="$globalData" />
  65. </xsl:call-template>
  66. <xsl:if test="$debugEnabled"><xsl:message>CSS header creation finished!</xsl:message></xsl:if>
  67. </xsl:element>
  68. </xsl:template>
  69. <!-- Creating a CSS style header from the collected styles of the 'globalData' parameter -->
  70. <xsl:template name='create-css-styleheader'>
  71. <xsl:param name="globalData" />
  72. <xsl:element name="style">
  73. <xsl:attribute name="type">text/css</xsl:attribute>
  74. <xsl:text>
  75. </xsl:text>
  76. <xsl:call-template name='create-page-layout'>
  77. <xsl:with-param name="globalData" select="$globalData" />
  78. </xsl:call-template>
  79. <xsl:text>table { border-collapse:collapse; border-spacing:0; empty-cells:show }
  80. </xsl:text>
  81. <xsl:choose>
  82. <xsl:when test="/*/office:body/office:spreadsheet"><xsl:text>td, th { vertical-align:top; font-size:10pt;}
  83. </xsl:text></xsl:when>
  84. <xsl:otherwise><xsl:text>td, th { vertical-align:top; font-size:12pt;}
  85. </xsl:text></xsl:otherwise>
  86. </xsl:choose>
  87. <xsl:text>h1, h2, h3, h4, h5, h6 { clear:both;}
  88. </xsl:text>
  89. <xsl:choose>
  90. <xsl:when test="/*/office:body/office:spreadsheet">
  91. <xsl:text>p { white-space: nowrap; }
  92. </xsl:text>
  93. </xsl:when>
  94. </xsl:choose>
  95. <xsl:text>ol, ul { margin:0; padding:0;}
  96. </xsl:text>
  97. <xsl:text>li { list-style: none; margin:0; padding:0;}
  98. </xsl:text>
  99. <xsl:text>/* "li span.odfLiEnd" - IE 7 issue*/</xsl:text>
  100. <xsl:text>
  101. </xsl:text>
  102. <xsl:text>li span. { clear: both; line-height:0; width:0; height:0; margin:0; padding:0; }
  103. </xsl:text>
  104. <xsl:text>span.footnodeNumber { padding-right:1em; }
  105. </xsl:text>
  106. <xsl:text>span.annotation_style_by_filter { font-size:95%; font-family:Arial; background-color:#fff000; margin:0; border:0; padding:0; }
  107. </xsl:text>
  108. <!-- Simulate tabs. They are around 0.64cm in LO, we convert that to 0.8rem. -->
  109. <xsl:text>span.heading_numbering { margin-right: 0.8rem; }</xsl:text>
  110. <xsl:text>* { margin:0;}
  111. </xsl:text>
  112. <xsl:call-template name="write-mapped-CSS-styles">
  113. <xsl:with-param name="globalData" select="$globalData" />
  114. </xsl:call-template>
  115. </xsl:element>
  116. </xsl:template>
  117. <xsl:template name="write-mapped-CSS-styles">
  118. <xsl:param name="globalData" />
  119. <xsl:param name="emptyStyles"/>
  120. <xsl:for-each select="$globalData/all-styles/style">
  121. <xsl:if test="final-properties != ''">
  122. <!-- NOTE: easy process, as only the style family in conjunction with the style name, makes the style unambiguous -->
  123. <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>}
  124. </xsl:text>
  125. </xsl:if>
  126. </xsl:for-each>
  127. <!-- Otherwise all styles have been processed and the empty styles have to be given out -->
  128. <xsl:text>/* ODF styles with no properties representable as CSS */</xsl:text><xsl:text>
  129. </xsl:text><xsl:for-each select="$globalData/all-styles/style[final-properties = '']"><xsl:value-of select="concat('.', @style:name, ' ')"/></xsl:for-each> { }
  130. </xsl:template>
  131. <!-- Creating CSS page layout based on first office master style -->
  132. <xsl:template name='create-page-layout'>
  133. <xsl:param name="globalData" />
  134. <!-- approximation to find the correct master page style (with page dimensions) -->
  135. <xsl:variable name="masterPageNames">
  136. <!-- set context to styles.xml -->
  137. <xsl:for-each select="$globalData/all-doc-styles/style">
  138. <!-- Loop over every style:style containing a @style:master-page-name attribute -->
  139. <xsl:for-each select="key('masterPage','count')">
  140. <!-- set context to styles.xml -->
  141. <xsl:for-each select="/*/office:body">
  142. <!-- Check if this style is being used in the body -->
  143. <xsl:if test="key('elementUsingStyle', ../@style:name)">
  144. <!-- Check every master-page-name if it is not empty and return as ';' separated list -->
  145. <xsl:if test="string-length(../@style:master-page-name) &gt; 0"><xsl:value-of select="../@style:master-page-name"/>;</xsl:if>
  146. </xsl:if>
  147. </xsl:for-each>
  148. </xsl:for-each>
  149. </xsl:for-each>
  150. </xsl:variable>
  151. <!-- Take the first of the masterpage list and get the according style:master-page element and find the @style:page-layout-name -->
  152. <xsl:variable name="pageLayoutName" select="key('masterPageElements', substring-before($masterPageNames,';'))/@style:page-layout-name"/>
  153. <!-- Find the according style:page-layout and store the properties in a variable -->
  154. <xsl:variable name="pageProperties" select="key('pageLayoutElements', $pageLayoutName)/style:page-layout-properties"/>
  155. <xsl:text>@page { </xsl:text>
  156. <xsl:call-template name="page-size">
  157. <xsl:with-param name="globalData" select="$globalData" />
  158. <xsl:with-param name="pageProperties" select="$pageProperties" />
  159. </xsl:call-template>
  160. <xsl:call-template name="page-margin">
  161. <xsl:with-param name="globalData" select="$globalData" />
  162. <xsl:with-param name="pageProperties" select="$pageProperties" />
  163. </xsl:call-template>
  164. <xsl:text> }
  165. </xsl:text>
  166. </xsl:template>
  167. <xsl:template name="page-size">
  168. <xsl:param name="globalData" />
  169. <xsl:param name="pageProperties" />
  170. <xsl:variable name="printOrientation" select="$pageProperties/@style:print-orientation" />
  171. <xsl:variable name="pageWidth" select="$pageProperties/@fo:page-width" />
  172. <xsl:variable name="pageHeight" select="$pageProperties/@fo:page-height" />
  173. <xsl:choose>
  174. <xsl:when test="$pageWidth and $pageHeight">
  175. <xsl:text>size: </xsl:text>
  176. <xsl:value-of select="$pageWidth" />
  177. <xsl:text> </xsl:text>
  178. <xsl:value-of select="$pageHeight" />
  179. <xsl:text>; </xsl:text>
  180. </xsl:when>
  181. <xsl:when test="$printOrientation">
  182. <xsl:text>size: </xsl:text>
  183. <xsl:value-of select="$printOrientation" />
  184. <xsl:text>; </xsl:text>
  185. </xsl:when>
  186. </xsl:choose>
  187. </xsl:template>
  188. <xsl:template name="page-margin">
  189. <xsl:param name="globalData" />
  190. <xsl:param name="pageProperties" />
  191. <xsl:variable name="marginTop" select="$pageProperties/@fo:margin-top" />
  192. <xsl:if test="$marginTop">
  193. <xsl:text>margin-top: </xsl:text>
  194. <xsl:value-of select="$marginTop" />
  195. <xsl:text>; </xsl:text>
  196. </xsl:if>
  197. <xsl:variable name="marginBottom" select="$pageProperties/@fo:margin-bottom" />
  198. <xsl:if test="$marginBottom">
  199. <xsl:text>margin-bottom: </xsl:text>
  200. <xsl:value-of select="$marginBottom" />
  201. <xsl:text>; </xsl:text>
  202. </xsl:if>
  203. <xsl:variable name="marginLeft" select="$pageProperties/@fo:margin-left" />
  204. <xsl:if test="$marginLeft">
  205. <xsl:text>margin-left: </xsl:text>
  206. <xsl:value-of select="$marginLeft" />
  207. <xsl:text>; </xsl:text>
  208. </xsl:if>
  209. <xsl:variable name="marginRight" select="$pageProperties/@fo:margin-right" />
  210. <xsl:if test="$marginRight">
  211. <xsl:text>margin-right: </xsl:text>
  212. <xsl:value-of select="$marginRight" />
  213. </xsl:if>
  214. </xsl:template>
  215. <!-- *************************** -->
  216. <!-- *** Common XHTML header *** -->
  217. <!-- *************************** -->
  218. <xsl:template name='xhtml-header-properties'>
  219. <xsl:param name="globalData" />
  220. <xsl:variable name="netloc">
  221. <xsl:for-each select="$globalData/meta-file/*/office:meta/meta:user-defined">
  222. <xsl:if test="./@meta:name='ODF.base'">
  223. <xsl:value-of select="." />
  224. </xsl:if>
  225. </xsl:for-each>
  226. <xsl:for-each select="$globalData/meta-file/*/office:meta/meta:user-defined">
  227. <xsl:if test="./@meta:name='ODF.filename'">
  228. <xsl:value-of select="." />
  229. </xsl:if>
  230. </xsl:for-each>
  231. </xsl:variable>
  232. <xsl:variable name="lang">
  233. <xsl:choose>
  234. <xsl:when test="$globalData/meta-file/*/office:meta/dc:language">
  235. <xsl:value-of select="$globalData/meta-file/*/office:meta/dc:language" />
  236. </xsl:when>
  237. <xsl:otherwise>en-US</xsl:otherwise>
  238. </xsl:choose>
  239. </xsl:variable>
  240. <xsl:variable name="prov">
  241. <xsl:choose>
  242. <xsl:when test="$globalData/meta-file/*/office:meta/meta:printed-by">
  243. <xsl:value-of select="concat('Printed by &quot;',$globalData/meta-file/*/office:meta/meta:printed-by,'&quot;[dc:publisher] on &quot;',$globalData/meta-file/*/office:meta/meta:print-date,'&quot;[dc:date] in &quot;',$lang,'&quot;[dc:language]')" />
  244. </xsl:when>
  245. <xsl:otherwise />
  246. </xsl:choose>
  247. </xsl:variable>
  248. <xsl:variable name="keywords">
  249. <xsl:for-each select="$globalData/meta-file/*/office:meta/meta:keyword">
  250. <xsl:value-of select="." />
  251. <xsl:if test="position() != last()">
  252. <xsl:text>, </xsl:text>
  253. </xsl:if>
  254. </xsl:for-each>
  255. </xsl:variable>
  256. <!-- explicit output content-type for low-tech browser (e.g. IE6) -->
  257. <xsl:element name="meta">
  258. <xsl:attribute name="http-equiv">Content-Type</xsl:attribute>
  259. <xsl:attribute name="content">application/xhtml+xml; charset=utf-8</xsl:attribute>
  260. </xsl:element>
  261. <!-- title of document for browser frame title -->
  262. <xsl:element name="title">
  263. <xsl:attribute name="xml:lang">
  264. <xsl:value-of select="$lang" />
  265. </xsl:attribute>
  266. <xsl:choose>
  267. <xsl:when test="$globalData/meta-file/*/office:meta/dc:title">
  268. <xsl:value-of select="$globalData/meta-file/*/office:meta/dc:title" />
  269. </xsl:when>
  270. <!-- providing the mandatory title is a workaround for an IE bug-->
  271. <xsl:otherwise>
  272. <xsl:text>- no title specified</xsl:text>
  273. </xsl:otherwise>
  274. </xsl:choose>
  275. </xsl:element>
  276. <!-- title, in DC syntax -->
  277. <xsl:element name="meta">
  278. <xsl:attribute name="name">DCTERMS.title</xsl:attribute>
  279. <xsl:attribute name="content">
  280. <xsl:value-of select="$globalData/meta-file/*/office:meta/dc:title" />
  281. </xsl:attribute>
  282. <xsl:attribute name="xml:lang">
  283. <xsl:value-of select="$lang" />
  284. </xsl:attribute>
  285. </xsl:element>
  286. <!-- the identifier for source (identifier) -->
  287. <xsl:call-template name="add-meta-tag">
  288. <xsl:with-param name="meta-name" select="'DCTERMS.identifier'" />
  289. <xsl:with-param name="meta-data" select="translate($netloc, ' ','')" />
  290. <xsl:with-param name="meta-enc" select="'DCTERMS.URI'" />
  291. </xsl:call-template>
  292. <!-- the language for source (language) -->
  293. <xsl:call-template name="add-meta-tag">
  294. <xsl:with-param name="meta-name" select="'DCTERMS.language'" />
  295. <xsl:with-param name="meta-data" select="$lang" />
  296. <xsl:with-param name="meta-enc" select="'DCTERMS.RFC4646'" />
  297. </xsl:call-template>
  298. <!-- a bit commercial (generator) -->
  299. <xsl:element name="meta">
  300. <xsl:attribute name="name">DCTERMS.source</xsl:attribute>
  301. <xsl:attribute name="content">http://xml.openoffice.org/odf2xhtml</xsl:attribute>
  302. </xsl:element>
  303. <!-- the author of the input source (author) -->
  304. <xsl:call-template name="add-meta-tag">
  305. <xsl:with-param name="meta-name" select="'DCTERMS.creator'" />
  306. <xsl:with-param name="meta-data" select="$globalData/meta-file/*/office:meta/meta:initial-creator" />
  307. </xsl:call-template>
  308. <!-- creation-date of the input source (issued) -->
  309. <xsl:call-template name="add-meta-tag">
  310. <xsl:with-param name="meta-name" select="'DCTERMS.issued'" />
  311. <xsl:with-param name="meta-data" select="$globalData/meta-file/*/office:meta/meta:creation-date" />
  312. <xsl:with-param name="meta-enc" select="'DCTERMS.W3CDTF'" />
  313. </xsl:call-template>
  314. <!-- name of last changing person of the input source (changedby) -->
  315. <xsl:call-template name="add-meta-tag">
  316. <xsl:with-param name="meta-name" select="'DCTERMS.contributor'" />
  317. <xsl:with-param name="meta-data" select="$globalData/meta-file/*/office:meta/dc:creator" />
  318. </xsl:call-template>
  319. <!-- last changing date of the input source (changed) -->
  320. <xsl:call-template name="add-meta-tag">
  321. <xsl:with-param name="meta-name" select="'DCTERMS.modified'" />
  322. <xsl:with-param name="meta-data" select="$globalData/meta-file/*/office:meta/dc:date" />
  323. <xsl:with-param name="meta-enc" select="'DCTERMS.W3CDTF'" />
  324. </xsl:call-template>
  325. <!-- Last print, as provenance -->
  326. <xsl:if test="$prov">
  327. <xsl:call-template name="add-meta-tag">
  328. <xsl:with-param name="meta-name" select="'DCTERMS.provenance'" />
  329. <xsl:with-param name="meta-data" select="$prov" />
  330. <xsl:with-param name="meta-lang" select="$lang" />
  331. </xsl:call-template>
  332. </xsl:if>
  333. <!-- keywords about the input source (keywords) -->
  334. <xsl:call-template name="add-meta-tag">
  335. <xsl:with-param name="meta-name" select="'DCTERMS.subject'" />
  336. <xsl:with-param name="meta-data" select="normalize-space(concat($globalData/meta-file/*/office:meta/dc:subject,', ',$keywords))" />
  337. <xsl:with-param name="meta-lang" select="$lang" />
  338. </xsl:call-template>
  339. <!-- detailed description about the input source (description) -->
  340. <xsl:call-template name="add-meta-tag">
  341. <xsl:with-param name="meta-name" select="'DCTERMS.description'" />
  342. <xsl:with-param name="meta-data" select="$globalData/meta-file/*/office:meta/dc:description" />
  343. <xsl:with-param name="meta-lang" select="$lang" />
  344. </xsl:call-template>
  345. <!-- user defined use of DCTERM tags -->
  346. <xsl:for-each select="$globalData/meta-file/*/office:meta/meta:user-defined[starts-with(@meta:name,'DCTERMS.')][not(.='')]">
  347. <xsl:call-template name="add-meta-tag">
  348. <xsl:with-param name="meta-name" select="@meta:name" />
  349. <xsl:with-param name="meta-data" select="." />
  350. <!-- <xsl:with-param name="meta-lang" select="$lang" /> -->
  351. </xsl:call-template>
  352. </xsl:for-each>
  353. <!-- user defined use of DC tags (legacy) -->
  354. <xsl:for-each select="$globalData/meta-file/*/office:meta/meta:user-defined[starts-with(@meta:name,'DC.')][not(.='')]">
  355. <xsl:call-template name="add-meta-tag">
  356. <xsl:with-param name="meta-name" select="@meta:name" />
  357. <xsl:with-param name="meta-data" select="." />
  358. <!-- <xsl:with-param name="meta-lang" select="$lang" /> -->
  359. </xsl:call-template>
  360. </xsl:for-each>
  361. <link rel="schema.DC" href="http://purl.org/dc/elements/1.1/" hreflang="en" />
  362. <link rel="schema.DCTERMS" href="http://purl.org/dc/terms/" hreflang="en" />
  363. <link rel="schema.DCTYPE" href="http://purl.org/dc/dcmitype/" hreflang="en" />
  364. <link rel="schema.DCAM" href="http://purl.org/dc/dcam/" hreflang="en" />
  365. <!-- W3C GRDDL Profile -->
  366. <!--
  367. <link rel="transformation" href="http://xml.openoffice.org/odf2xhtml/rdf-extract.xsl" />
  368. -->
  369. <!-- base URL of document for resolving relative links
  370. NOTE: CHROME has a problem, with relative references as from content table, referencing to root directory instead of document
  371. <xsl:element name="base">
  372. <xsl:attribute name="href">-->
  373. <!-- earlier 'targetURL' was used for an absolute reference of base provided by the Office (file URL)
  374. <xsl:value-of select="$targetURL" />
  375. now '.' let relative links work, even if document has been moved -->
  376. <!--<xsl:text>.</xsl:text>
  377. </xsl:attribute>
  378. </xsl:element>-->
  379. </xsl:template>
  380. <!-- generic template for adding common meta tags -->
  381. <xsl:template name="add-meta-tag">
  382. <xsl:param name="meta-name" />
  383. <xsl:param name="meta-data" />
  384. <xsl:param name="meta-enc" />
  385. <xsl:param name="meta-lang" />
  386. <xsl:if test="$meta-data">
  387. <xsl:element name="meta">
  388. <xsl:attribute name="name">
  389. <xsl:value-of select="$meta-name" />
  390. </xsl:attribute>
  391. <xsl:attribute name="content">
  392. <xsl:value-of select="$meta-data" />
  393. </xsl:attribute>
  394. <xsl:if test="$meta-enc">
  395. <xsl:attribute name="scheme">
  396. <xsl:value-of select="$meta-enc" />
  397. </xsl:attribute>
  398. </xsl:if>
  399. <xsl:if test="$meta-lang">
  400. <xsl:attribute name="xml:lang">
  401. <xsl:value-of select="$meta-lang" />
  402. </xsl:attribute>
  403. </xsl:if>
  404. </xsl:element>
  405. </xsl:if>
  406. </xsl:template>
  407. </xsl:stylesheet>