styles.xsl 29 KB

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