styles.xsl 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686
  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. <xsl:stylesheet version="1.0"
  20. xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  21. xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0"
  22. xmlns:config="urn:oasis:names:tc:opendocument:xmlns:config:1.0"
  23. xmlns:dc="http://purl.org/dc/elements/1.1/"
  24. xmlns:dom="http://www.w3.org/2001/xml-events"
  25. xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0"
  26. xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0"
  27. xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0"
  28. xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0"
  29. xmlns:math="http://www.w3.org/1998/Math/MathML"
  30. xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0"
  31. xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0"
  32. xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0"
  33. xmlns:ooo="http://openoffice.org/2004/office"
  34. xmlns:oooc="http://openoffice.org/2004/calc"
  35. xmlns:ooow="http://openoffice.org/2004/writer"
  36. xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0"
  37. xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0"
  38. xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0"
  39. xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0"
  40. xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0"
  41. xmlns:xlink="http://www.w3.org/1999/xlink"
  42. xmlns:xt="http://www.jclark.com/xt"
  43. xmlns:common="http://exslt.org/common"
  44. xmlns:xalan="http://xml.apache.org/xalan"
  45. xmlns="urn:schemas-microsoft-com:office:spreadsheet" xmlns:c="urn:schemas-microsoft-com:office:component:spreadsheet" xmlns:html="http://www.w3.org/TR/REC-html40" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet" xmlns:x2="http://schemas.microsoft.com/office/excel/2003/xml" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  46. exclude-result-prefixes="chart config dc dom dr3d draw fo form math meta number office ooo oooc ooow script style svg table text xlink xt common xalan">
  47. <!-- Used in case of 'style:map', conditional formatting, where a style references to another -->
  48. <xsl:key name="styles" match="/*/office:styles/style:style | /*/office:automatic-styles/style:style" use="@style:name" />
  49. <!--
  50. Mapping of OOo style:name and style:family to excel ss:ID
  51. Styles form style:style map from style:name to ss:Name
  52. style:parent-style map to ss:Parent
  53. -->
  54. <!-- default styles of the application
  55. <xsl:template match="style:default-style" mode="styles" >
  56. <xsl:call-template name="style:style">
  57. <xsl:with-param name="styleName" select="'Default'" />
  58. </xsl:call-template>
  59. </xsl:template>
  60. -->
  61. <xsl:template match="style:style" mode="styles">
  62. <xsl:param name="isAutomatic" />
  63. <xsl:param name="styleName" select="@style:name" />
  64. <xsl:param name="styleParentName" select="@style:parent-style-name" />
  65. <!-- only row styles used by cells are exported,
  66. as usual row style properties are already exported as row attributes -->
  67. <xsl:if test="not(@style:family='table-row') or @style:family='table-row' and key('getCellByStyle', '.')">
  68. <xsl:element name="Style">
  69. <xsl:attribute name="ss:ID">
  70. <!-- neglecting that a style is only unique in conjunction with its family name -->
  71. <xsl:value-of select="@style:name" />
  72. </xsl:attribute>
  73. <xsl:choose>
  74. <xsl:when test="not($isAutomatic)">
  75. <xsl:choose>
  76. <xsl:when test="@style:display-name">
  77. <xsl:attribute name="ss:Name"><xsl:value-of select="@style:display-name"/></xsl:attribute>
  78. </xsl:when>
  79. <xsl:otherwise>
  80. <xsl:attribute name="ss:Name"><xsl:value-of select="@style:name" /></xsl:attribute>
  81. </xsl:otherwise>
  82. </xsl:choose>
  83. <xsl:choose>
  84. <!-- when a non-allowed parent style is found
  85. (in spreadsheetml no style with ss:Name is able to have a ss:Parent) -->
  86. <xsl:when test="@style:parent-style-name">
  87. <!-- styles have to be merged (flatting heritance tree) -->
  88. <xsl:variable name="stylePropertiesContainer">
  89. <xsl:call-template name="merge-all-parent-styles">
  90. <xsl:with-param name="currentStyle" select="." />
  91. </xsl:call-template>
  92. </xsl:variable>
  93. <xsl:choose>
  94. <xsl:when test="function-available('xalan:nodeset')">
  95. <xsl:call-template name="write-style-properties">
  96. <xsl:with-param name="styleProperties" select="xalan:nodeset($stylePropertiesContainer)/*" />
  97. </xsl:call-template>
  98. </xsl:when>
  99. <xsl:when test="function-available('common:node-set')">
  100. <xsl:call-template name="write-style-properties">
  101. <xsl:with-param name="styleProperties" select="common:node-set($stylePropertiesContainer)/*" />
  102. </xsl:call-template>
  103. </xsl:when>
  104. <xsl:when test="function-available('xt:node-set')">
  105. <xsl:call-template name="write-style-properties">
  106. <xsl:with-param name="styleProperties" select="xt:node-set($stylePropertiesContainer)/*" />
  107. </xsl:call-template>
  108. </xsl:when>
  109. <xsl:otherwise>
  110. <xsl:message terminate="yes">WARNING: The required node set function was not found!</xsl:message>
  111. </xsl:otherwise>
  112. </xsl:choose>
  113. </xsl:when>
  114. <xsl:otherwise>
  115. <xsl:call-template name="write-style-properties" />
  116. </xsl:otherwise>
  117. </xsl:choose>
  118. </xsl:when>
  119. <xsl:otherwise>
  120. <!-- automatic styles are implicit inheriting from a style called 'Default',
  121. furthermore nor in spreadsheetml nor in OpenDocument automatic styles are able to inherit from each other -->
  122. <xsl:choose>
  123. <xsl:when test="@style:parent-style-name and not(@style:parent-style-name = 'Default')">
  124. <xsl:attribute name="ss:Parent"><xsl:value-of select="@style:parent-style-name" /></xsl:attribute>
  125. </xsl:when>
  126. </xsl:choose>
  127. <xsl:call-template name="write-style-properties" />
  128. </xsl:otherwise>
  129. </xsl:choose>
  130. </xsl:element>
  131. </xsl:if>
  132. </xsl:template>
  133. <!-- resolving the style inheritance by starting from uppermost parent and
  134. overriding existing style properties by new found child properties -->
  135. <xsl:template name="merge-all-parent-styles">
  136. <xsl:param name="currentStyle" />
  137. <xsl:choose>
  138. <!-- in case of a parent, styles have to be merged (flatting heritance tree) -->
  139. <xsl:when test="$currentStyle/@style:parent-style-name">
  140. <!-- collect parent style properties -->
  141. <xsl:variable name="parentStyleContainer">
  142. <!-- take a look if the parent style has a parent himself -->
  143. <xsl:call-template name="merge-all-parent-styles" >
  144. <xsl:with-param name="currentStyle" select="key('styles', $currentStyle/@style:parent-style-name)" />
  145. </xsl:call-template>
  146. </xsl:variable>
  147. <xsl:choose>
  148. <xsl:when test="function-available('xalan:nodeset')">
  149. <xsl:call-template name="merge-style-properties">
  150. <xsl:with-param name="childStyleContainer" select="$currentStyle" />
  151. <xsl:with-param name="parentStyleContainer" select="xalan:nodeset($parentStyleContainer)" />
  152. </xsl:call-template>
  153. </xsl:when>
  154. <xsl:when test="function-available('common:node-set')">
  155. <xsl:call-template name="merge-style-properties">
  156. <xsl:with-param name="childStyleContainer" select="$currentStyle" />
  157. <xsl:with-param name="parentStyleContainer" select="common:node-set($parentStyleContainer)" />
  158. </xsl:call-template>
  159. </xsl:when>
  160. <xsl:when test="function-available('xt:node-set')">
  161. <xsl:call-template name="merge-style-properties">
  162. <xsl:with-param name="childStyleContainer" select="$currentStyle" />
  163. <xsl:with-param name="parentStyleContainer" select="xt:node-set($parentStyleContainer)" />
  164. </xsl:call-template>
  165. </xsl:when>
  166. <xsl:otherwise>
  167. <xsl:message terminate="yes">WARNING: The required node-set function was not found!</xsl:message>
  168. </xsl:otherwise>
  169. </xsl:choose>
  170. </xsl:when>
  171. <!-- called for top parents (or styles without parents) -->
  172. <xsl:otherwise>
  173. <xsl:copy-of select="$currentStyle/*"/>
  174. </xsl:otherwise>
  175. </xsl:choose>
  176. </xsl:template>
  177. <xsl:template name="merge-style-properties">
  178. <xsl:param name="childStyleContainer" />
  179. <xsl:param name="parentStyleContainer" />
  180. <xsl:choose>
  181. <xsl:when test="$parentStyleContainer/*">
  182. <xsl:apply-templates select="$parentStyleContainer/*" mode="inheritance">
  183. <xsl:with-param name="childStyleContainer" select="$childStyleContainer" />
  184. </xsl:apply-templates>
  185. </xsl:when>
  186. <xsl:otherwise>
  187. <xsl:copy-of select="$childStyleContainer/*"/>
  188. </xsl:otherwise>
  189. </xsl:choose>
  190. </xsl:template>
  191. <xsl:template match="*" mode="inheritance">
  192. <xsl:param name="childStyleContainer" />
  193. <!-- create an element named equal to the current properties parent element (e.g. style:table-cell-properties) -->
  194. <xsl:element name="{name()}" namespace="urn:oasis:names:tc:opendocument:xmlns:style:1.0">
  195. <!-- attributes will be automatically replaced -->
  196. <xsl:copy-of select="@*" />
  197. <xsl:copy-of select="$childStyleContainer/*[name() = name(current() )]/@*"/>
  198. <!-- elements are not needed yet, will be neglected for simplicity reasons -->
  199. </xsl:element>
  200. </xsl:template>
  201. <xsl:key match="/*/office:styles/number:date-style |
  202. /*/office:styles/number:time-style |
  203. /*/office:styles/number:number-style |
  204. /*/office:styles/number:percentage-style |
  205. /*/office:styles/number:currency-style |
  206. /*/office:automatic-styles/number:date-style |
  207. /*/office:automatic-styles/number:time-style |
  208. /*/office:automatic-styles/number:number-style |
  209. /*/office:automatic-styles/number:percentage-style |
  210. /*/office:automatic-styles/number:currency-style" name="number-style" use="@style:name" />
  211. <xsl:template name="write-style-properties">
  212. <xsl:param name="styleProperties" select="key('styles', @style:name)/*" />
  213. <xsl:call-template name="Alignment">
  214. <xsl:with-param name="styleProperties" select="$styleProperties" />
  215. </xsl:call-template>
  216. <xsl:call-template name="Border">
  217. <xsl:with-param name="styleProperties" select="$styleProperties" />
  218. </xsl:call-template>
  219. <xsl:call-template name="Font">
  220. <xsl:with-param name="styleProperties" select="$styleProperties" />
  221. <xsl:with-param name="styleParentName" select="@style:parent-style-name" />
  222. </xsl:call-template>
  223. <xsl:call-template name="Interior">
  224. <xsl:with-param name="styleProperties" select="$styleProperties" />
  225. </xsl:call-template>
  226. <xsl:call-template name="NumberFormat">
  227. <xsl:with-param name="styleProperties" select="$styleProperties" />
  228. </xsl:call-template>
  229. </xsl:template>
  230. <!-- context is element 'style:style' -->
  231. <xsl:template name="NumberFormat">
  232. <xsl:if test="@style:data-style-name">
  233. <xsl:variable name="numberStyleName" select="@style:data-style-name" />
  234. <xsl:variable name="numberStyle" select="key('number-style', $numberStyleName)" />
  235. <xsl:element name="NumberFormat">
  236. <xsl:attribute name="ss:Format">
  237. <xsl:choose>
  238. <xsl:when test="not($numberStyle/node())">
  239. <!-- Excel2003sp1 issue: 'General' and 'General Number' is not supported -->
  240. <xsl:text>General</xsl:text>
  241. </xsl:when>
  242. <xsl:when test="name($numberStyle) = 'number:number-style'">
  243. <xsl:choose>
  244. <xsl:when test="$numberStyle/number:scientific-number">
  245. <xsl:text>Scientific</xsl:text>
  246. </xsl:when>
  247. <!-- Excel2003sp1 issue: 'General Number' not supported -->
  248. <xsl:when test="$numberStyle/number:number/@number:decimal-places and
  249. $numberStyle/number:number/@number:decimal-places='0'">
  250. <xsl:text>General</xsl:text>
  251. </xsl:when>
  252. <xsl:when test="$numberStyle/number:text">
  253. <xsl:choose>
  254. <xsl:when test="$numberStyle/number:text = 'No' or $numberStyle/number:text = 'Nein'">
  255. <xsl:text>Yes/No</xsl:text>
  256. </xsl:when>
  257. <xsl:when test="$numberStyle/number:text = 'False' or $numberStyle/number:text = 'Falsch'">
  258. <xsl:text>True/False</xsl:text>
  259. </xsl:when>
  260. <xsl:when test="$numberStyle/number:text = 'Off' or $numberStyle/number:text = 'Aus'">
  261. <xsl:text>On/Off</xsl:text>
  262. </xsl:when>
  263. <!-- Excel2003sp1 issue: currency is saved as 'float' -->
  264. <xsl:when test="$numberStyle/number:currency-symbol">
  265. <xsl:choose>
  266. <xsl:when test="contains($numberStyle/number:currency-symbol, '€')">
  267. <xsl:text>Euro Currency</xsl:text>
  268. </xsl:when>
  269. <xsl:otherwise>
  270. <xsl:text>Currency</xsl:text>
  271. </xsl:otherwise>
  272. </xsl:choose>
  273. </xsl:when>
  274. <!-- Excel2003sp1 issue: 'Currency' is saved as 'float' -->
  275. <xsl:when test="contains($numberStyle/number:text, '$')">
  276. <xsl:text>Currency</xsl:text>
  277. </xsl:when>
  278. <!-- OASIS XML adaptation -->
  279. <xsl:otherwise>
  280. <xsl:text>General</xsl:text>
  281. </xsl:otherwise>
  282. </xsl:choose>
  283. </xsl:when>
  284. <xsl:when test="$numberStyle/number:grouping">
  285. <xsl:text>Standard</xsl:text>
  286. </xsl:when>
  287. <xsl:otherwise>
  288. <xsl:text>Fixed</xsl:text>
  289. </xsl:otherwise>
  290. </xsl:choose>
  291. </xsl:when>
  292. <xsl:when test="name($numberStyle) = 'number:time-style'">
  293. <xsl:choose>
  294. <xsl:when test="$numberStyle/number:am-pm">
  295. <xsl:choose>
  296. <xsl:when test="$numberStyle/number:seconds">
  297. <xsl:text>Long Time</xsl:text>
  298. </xsl:when>
  299. <xsl:otherwise>
  300. <xsl:text>Medium Time</xsl:text>
  301. </xsl:otherwise>
  302. </xsl:choose>
  303. </xsl:when>
  304. <xsl:otherwise>
  305. <xsl:text>Short Time</xsl:text>
  306. </xsl:otherwise>
  307. </xsl:choose>
  308. </xsl:when>
  309. <xsl:when test="name($numberStyle) = 'number:percentage-style'">
  310. <xsl:text>Percent</xsl:text>
  311. </xsl:when>
  312. <xsl:when test="name($numberStyle) = 'number:currency-style'">
  313. <xsl:choose>
  314. <xsl:when test="contains($numberStyle/number:currency-symbol, '€')">
  315. <xsl:text>Euro Currency</xsl:text>
  316. </xsl:when>
  317. <xsl:otherwise>
  318. <xsl:text>Currency</xsl:text>
  319. </xsl:otherwise>
  320. </xsl:choose>
  321. </xsl:when>
  322. <xsl:otherwise>
  323. <xsl:choose>
  324. <xsl:when test="$numberStyle/number:month">
  325. <xsl:choose>
  326. <xsl:when test="$numberStyle/number:month/@number:textual and
  327. $numberStyle/number:month/@number:textual=true()">
  328. <xsl:text>Medium Date</xsl:text>
  329. <!-- Excel2003 sp1 issue: No difference between 'Long Date' and 'Medium Date' -->
  330. </xsl:when>
  331. <xsl:when test="$numberStyle/number:hours">
  332. <xsl:text>General Date</xsl:text>
  333. </xsl:when>
  334. <xsl:when test="$numberStyle/number:year/@number:style and
  335. $numberStyle/number:year/@number:style='long'">
  336. <xsl:text>Short Date</xsl:text>
  337. </xsl:when>
  338. <!-- OASIS XML adaptation -->
  339. <xsl:otherwise>
  340. <xsl:text>Short Date</xsl:text>
  341. </xsl:otherwise>
  342. </xsl:choose>
  343. </xsl:when>
  344. <!-- OASIS XML adaptation -->
  345. <xsl:otherwise>
  346. <xsl:text>General</xsl:text>
  347. </xsl:otherwise>
  348. </xsl:choose>
  349. </xsl:otherwise>
  350. </xsl:choose>
  351. </xsl:attribute>
  352. </xsl:element>
  353. </xsl:if>
  354. </xsl:template>
  355. <xsl:template name="Alignment">
  356. <xsl:param name="styleProperties" />
  357. <!-- An empty Alignment element, might overwrite parents setting by
  358. the default attributes -->
  359. <xsl:if test="$styleProperties/@fo:text-align or
  360. $styleProperties/@style:vertical-align or
  361. $styleProperties/@fo:wrap-option or
  362. $styleProperties/@fo:margin-left or
  363. $styleProperties/@style:rotation-angle or
  364. $styleProperties/@style:direction">
  365. <xsl:element name="Alignment">
  366. <xsl:if test="$styleProperties/@fo:text-align">
  367. <xsl:attribute name="ss:Horizontal">
  368. <xsl:choose>
  369. <xsl:when test="$styleProperties/@fo:text-align = 'center'">Center</xsl:when>
  370. <xsl:when test="$styleProperties/@fo:text-align = 'end'">Right</xsl:when>
  371. <xsl:when test="$styleProperties/@fo:text-align = 'justify'">Justify</xsl:when>
  372. <xsl:otherwise>Left</xsl:otherwise>
  373. </xsl:choose>
  374. </xsl:attribute>
  375. </xsl:if>
  376. <xsl:if test="$styleProperties/@style:vertical-align">
  377. <xsl:attribute name="ss:Vertical">
  378. <xsl:choose>
  379. <xsl:when test="$styleProperties/@style:vertical-align = 'top'">Top</xsl:when>
  380. <xsl:when test="$styleProperties/@style:vertical-align = 'bottom'">Bottom</xsl:when>
  381. <xsl:when test="$styleProperties/@style:vertical-align = 'middle'">Center</xsl:when>
  382. <xsl:otherwise>Automatic</xsl:otherwise>
  383. </xsl:choose>
  384. </xsl:attribute>
  385. </xsl:if>
  386. <xsl:if test="$styleProperties/@fo:wrap-option = 'wrap'">
  387. <xsl:attribute name="ss:WrapText">1</xsl:attribute>
  388. </xsl:if>
  389. <xsl:if test="$styleProperties/@fo:margin-left">
  390. <xsl:attribute name="ss:Indent">
  391. <xsl:variable name="margin">
  392. <xsl:call-template name="convert2pt">
  393. <xsl:with-param name="value" select="$styleProperties/@fo:margin-left" />
  394. <xsl:with-param name="rounding-factor" select="1" />
  395. </xsl:call-template>
  396. </xsl:variable>
  397. <!-- one ss:Indent is equal to 10 points -->
  398. <xsl:value-of select="number($margin) div 10"/>
  399. </xsl:attribute>
  400. </xsl:if>
  401. <!-- Excel is only able to rotate between 90 and -90 degree (inclusive).
  402. Other degrees will be mapped by 180 degrees -->
  403. <xsl:if test="$styleProperties/@style:rotation-angle">
  404. <xsl:attribute name="ss:Rotate">
  405. <xsl:choose>
  406. <xsl:when test="$styleProperties/@style:rotation-angle &gt; 90">
  407. <xsl:choose>
  408. <xsl:when test="$styleProperties/@style:rotation-angle &gt;= 270">
  409. <xsl:value-of select="$styleProperties/@style:rotation-angle - 360" />
  410. </xsl:when>
  411. <xsl:otherwise>
  412. <xsl:value-of select="$styleProperties/@style:rotation-angle - 180" />
  413. </xsl:otherwise>
  414. </xsl:choose>
  415. </xsl:when>
  416. <xsl:when test="$styleProperties/@style:rotation-angle &lt; -90">
  417. <xsl:choose>
  418. <xsl:when test="$styleProperties/@style:rotation-angle &lt;= -270">
  419. <xsl:value-of select="$styleProperties/@style:rotation-angle + 360" />
  420. </xsl:when>
  421. <xsl:otherwise>
  422. <xsl:value-of select="$styleProperties/@style:rotation-angle + 180" />
  423. </xsl:otherwise>
  424. </xsl:choose>
  425. </xsl:when>
  426. <xsl:otherwise>
  427. <xsl:value-of select="$styleProperties/@style:rotation-angle" />
  428. </xsl:otherwise>
  429. </xsl:choose>
  430. </xsl:attribute>
  431. </xsl:if>
  432. <xsl:if test="$styleProperties/@style:direction = 'ttb'">
  433. <xsl:attribute name="ss:VerticalText">1</xsl:attribute>
  434. </xsl:if>
  435. </xsl:element>
  436. </xsl:if>
  437. </xsl:template>
  438. <xsl:template name="Border">
  439. <xsl:param name="styleProperties" />
  440. <!-- An empty border element, might overwrite parents setting by
  441. the default attributes -->
  442. <xsl:if test="$styleProperties/@fo:border or
  443. $styleProperties/@fo:border-bottom or
  444. $styleProperties/@fo:border-left or
  445. $styleProperties/@fo:border-right or
  446. $styleProperties/@fo:border-top">
  447. <xsl:element name="Borders">
  448. <xsl:if test="$styleProperties/@fo:border-bottom and not($styleProperties/@fo:border-bottom = 'none')">
  449. <xsl:element name="Border">
  450. <xsl:attribute name="ss:Position">Bottom</xsl:attribute>
  451. <xsl:call-template name="border-attributes">
  452. <xsl:with-param name="border_properties" select="$styleProperties/@fo:border-bottom" />
  453. </xsl:call-template>
  454. </xsl:element>
  455. </xsl:if>
  456. <xsl:if test="$styleProperties/@fo:border-left and not($styleProperties/@fo:border-left = 'none')">
  457. <xsl:element name="Border">
  458. <xsl:attribute name="ss:Position">Left</xsl:attribute>
  459. <xsl:call-template name="border-attributes">
  460. <xsl:with-param name="border_properties" select="$styleProperties/@fo:border-left" />
  461. </xsl:call-template>
  462. </xsl:element>
  463. </xsl:if>
  464. <xsl:if test="$styleProperties/@fo:border-right and not($styleProperties/@fo:border-right = 'none')">
  465. <xsl:element name="Border">
  466. <xsl:attribute name="ss:Position">Right</xsl:attribute>
  467. <xsl:call-template name="border-attributes">
  468. <xsl:with-param name="border_properties" select="$styleProperties/@fo:border-right" />
  469. </xsl:call-template>
  470. </xsl:element>
  471. </xsl:if>
  472. <xsl:if test="$styleProperties/@fo:border-top and not($styleProperties/@fo:border-top = 'none')">
  473. <xsl:element name="Border">
  474. <xsl:attribute name="ss:Position">Top</xsl:attribute>
  475. <xsl:call-template name="border-attributes">
  476. <xsl:with-param name="border_properties" select="$styleProperties/@fo:border-top" />
  477. </xsl:call-template>
  478. </xsl:element>
  479. </xsl:if>
  480. <!-- write out all table border -->
  481. <xsl:if test="$styleProperties/@fo:border and not($styleProperties/@fo:border = 'none')">
  482. <xsl:element name="Border">
  483. <xsl:attribute name="ss:Position">Bottom</xsl:attribute>
  484. <xsl:call-template name="border-attributes">
  485. <xsl:with-param name="border_properties" select="$styleProperties/@fo:border" />
  486. </xsl:call-template>
  487. </xsl:element>
  488. <xsl:element name="Border">
  489. <xsl:attribute name="ss:Position">Left</xsl:attribute>
  490. <xsl:call-template name="border-attributes">
  491. <xsl:with-param name="border_properties" select="$styleProperties/@fo:border" />
  492. </xsl:call-template>
  493. </xsl:element>
  494. <xsl:element name="Border">
  495. <xsl:attribute name="ss:Position">Right</xsl:attribute>
  496. <xsl:call-template name="border-attributes">
  497. <xsl:with-param name="border_properties" select="$styleProperties/@fo:border" />
  498. </xsl:call-template>
  499. </xsl:element>
  500. <xsl:element name="Border">
  501. <xsl:attribute name="ss:Position">Top</xsl:attribute>
  502. <xsl:call-template name="border-attributes">
  503. <xsl:with-param name="border_properties" select="$styleProperties/@fo:border" />
  504. </xsl:call-template>
  505. </xsl:element>
  506. </xsl:if>
  507. </xsl:element>
  508. </xsl:if>
  509. </xsl:template>
  510. <xsl:template name="border-attributes">
  511. <xsl:param name="border_properties" />
  512. <xsl:variable name="border-width">
  513. <xsl:call-template name="convert2cm">
  514. <xsl:with-param name="value" select="substring-before($border_properties, ' ')" />
  515. </xsl:call-template>
  516. </xsl:variable>
  517. <xsl:variable name="border-style" select="substring-before(substring-after($border_properties, ' '), ' ')" />
  518. <xsl:variable name="border-color" select="substring-after(substring-after($border_properties, ' '), ' ')" />
  519. <!--
  520. <xsl:message>border-width:<xsl:value-of select="$border-width" /></xsl:message>
  521. <xsl:message>border-style:<xsl:value-of select="$border-style" /></xsl:message>
  522. <xsl:message>border-color:<xsl:value-of select="$border-color" /></xsl:message>
  523. -->
  524. <!-- Dash, Dot, DashDot, DashDotDot, SlantDashDot are not supported yet -->
  525. <xsl:attribute name="ss:LineStyle">
  526. <xsl:choose>
  527. <xsl:when test="$border-style = 'none'">None</xsl:when>
  528. <xsl:when test="$border-style = 'double'">Double</xsl:when>
  529. <xsl:otherwise>Continuous</xsl:otherwise>
  530. </xsl:choose>
  531. </xsl:attribute>
  532. <xsl:attribute name="ss:Weight">
  533. <xsl:choose>
  534. <!-- 0: Hairline -->
  535. <xsl:when test="$border-width &lt;= 0.002">0</xsl:when>
  536. <!-- 1: Thin -->
  537. <xsl:when test="$border-width &lt;= 0.035">1</xsl:when>
  538. <!-- 2: Medium -->
  539. <xsl:when test="$border-width &lt;= 0.088">2</xsl:when>
  540. <!-- 3: Thick -->
  541. <xsl:otherwise>3</xsl:otherwise>
  542. </xsl:choose>
  543. </xsl:attribute>
  544. <xsl:attribute name="ss:Color">
  545. <xsl:choose>
  546. <xsl:when test="$border-color"><xsl:value-of select="$border-color" /></xsl:when>
  547. <xsl:otherwise>Automatic</xsl:otherwise>
  548. </xsl:choose>
  549. </xsl:attribute>
  550. </xsl:template>
  551. <xsl:template name="Font">
  552. <xsl:param name="styleProperties" />
  553. <xsl:param name="styleParentName" />
  554. <!-- An empty font element, might overwrite parents setting by
  555. the default attributes -->
  556. <xsl:if test="$styleProperties/@style:font-weight or
  557. $styleProperties/@fo:color or
  558. $styleProperties/@style:font-name or
  559. $styleProperties/@fo:font-style or
  560. $styleProperties/@style:text-outline or
  561. $styleProperties/@style:text-shadow or
  562. $styleProperties/@style:font-size or
  563. $styleProperties/@style:text-line-through-style or
  564. $styleProperties/@style:text-underline-type or
  565. $styleProperties/@style:text-underline-style or
  566. $styleProperties/@style:text-position">
  567. <xsl:element name="Font">
  568. <xsl:call-template name="getParentBold">
  569. <xsl:with-param name="styleProperties" select="$styleProperties" />
  570. <xsl:with-param name="styleParentName" select="$styleParentName" />
  571. </xsl:call-template>
  572. <xsl:if test="$styleProperties/@fo:color">
  573. <xsl:attribute name="ss:Color"><xsl:value-of select="$styleProperties/@fo:color" /></xsl:attribute>
  574. </xsl:if>
  575. <xsl:if test="$styleProperties/@style:font-name">
  576. <xsl:attribute name="ss:FontName"><xsl:value-of select="$styleProperties/@style:font-name" /></xsl:attribute>
  577. </xsl:if>
  578. <xsl:if test="$styleProperties/@fo:font-style = 'italic'">
  579. <xsl:attribute name="ss:Italic">1</xsl:attribute>
  580. </xsl:if>
  581. <xsl:if test="$styleProperties/@style:text-outline = 'true'">
  582. <xsl:attribute name="ss:Outline">1</xsl:attribute>
  583. </xsl:if>
  584. <xsl:if test="$styleProperties/@style:text-shadow = 'shadow'">
  585. <xsl:attribute name="ss:Shadow">1</xsl:attribute>
  586. </xsl:if>
  587. <xsl:if test="$styleProperties/@fo:font-size">
  588. <xsl:attribute name="ss:Size">
  589. <xsl:call-template name="convert2pt">
  590. <xsl:with-param name="value" select="$styleProperties/@fo:font-size" />
  591. </xsl:call-template>
  592. </xsl:attribute>
  593. </xsl:if>
  594. <xsl:if test="$styleProperties/@style:text-line-through-style and $styleProperties/@style:text-line-through-style != 'none'">
  595. <xsl:attribute name="ss:StrikeThrough">1</xsl:attribute>
  596. </xsl:if>
  597. <xsl:if test="($styleProperties/@style:text-underline-type and $styleProperties/@style:text-underline-type != 'none') or
  598. ($styleProperties/@style:text-underline-style and $styleProperties/@style:text-underline-style != 'none')">
  599. <xsl:attribute name="ss:Underline">
  600. <xsl:choose>
  601. <xsl:when test="$styleProperties/@style:text-underline-type = 'double'">Double</xsl:when>
  602. <xsl:otherwise>Single</xsl:otherwise>
  603. </xsl:choose>
  604. </xsl:attribute>
  605. </xsl:if>
  606. <xsl:if test="$styleProperties/@style:text-position">
  607. <xsl:attribute name="ss:VerticalAlign">
  608. <xsl:choose>
  609. <xsl:when test="substring-before($styleProperties/@style:text-position, '% ') &gt; 0">Superscript</xsl:when>
  610. <xsl:otherwise>Subscript</xsl:otherwise>
  611. </xsl:choose>
  612. </xsl:attribute>
  613. </xsl:if>
  614. </xsl:element>
  615. </xsl:if>
  616. </xsl:template>
  617. <xsl:template name="Interior">
  618. <xsl:param name="styleProperties" />
  619. <xsl:if test="$styleProperties/@fo:background-color and not($styleProperties/@fo:background-color = 'transparent')">
  620. <xsl:element name="Interior">
  621. <xsl:attribute name="ss:Color">
  622. <xsl:value-of select="$styleProperties/@fo:background-color" />
  623. </xsl:attribute>
  624. <!-- Background color (i.e. Interior/ss:Color) not shown without ss:Pattern (or with 'none')
  625. Therefore a default is set -->
  626. <xsl:attribute name="ss:Pattern">Solid</xsl:attribute>
  627. </xsl:element>
  628. </xsl:if>
  629. </xsl:template>
  630. <!-- Excel issue workaround: <Font ss:Bold="1"> is not inherited -->
  631. <xsl:template name="getParentBold">
  632. <xsl:param name="styleProperties" />
  633. <xsl:param name="styleParentName" />
  634. <xsl:param name="styleName" />
  635. <xsl:if test="$styleParentName and $styleParentName != $styleName">
  636. <xsl:choose>
  637. <xsl:when test="$styleProperties/@fo:font-weight = 'bold'">
  638. <xsl:attribute name="ss:Bold">1</xsl:attribute>
  639. </xsl:when>
  640. <xsl:otherwise>
  641. <xsl:call-template name="getParentBold">
  642. <xsl:with-param name="styleProperties" select="key('styles', $styleParentName)/*" />
  643. <xsl:with-param name="styleParentName" select="key('styles', $styleParentName)/@style:parent-style-name" />
  644. <xsl:with-param name="styleName" select="$styleParentName" />
  645. </xsl:call-template>
  646. </xsl:otherwise>
  647. </xsl:choose>
  648. </xsl:if>
  649. </xsl:template>
  650. </xsl:stylesheet>