dita2odt-table.xsl 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- This file is part of the DITA Open Toolkit project.
  3. See the accompanying license.txt file for applicable licenses. -->
  4. <!-- (c) Copyright IBM Corp. 2005 All Rights Reserved. -->
  5. <xsl:stylesheet
  6. xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  7. xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0"
  8. xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0"
  9. xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0"
  10. xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0"
  11. xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0"
  12. xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0"
  13. xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:dc="http://purl.org/dc/elements/1.1/"
  14. xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0"
  15. xmlns:presentation="urn:oasis:names:tc:opendocument:xmlns:presentation:1.0"
  16. xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0"
  17. xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0"
  18. xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0"
  19. xmlns:math="http://www.w3.org/1998/Math/MathML"
  20. xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0"
  21. xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0"
  22. xmlns:dom="http://www.w3.org/2001/xml-events" xmlns:xforms="http://www.w3.org/2002/xforms"
  23. xmlns:xsd="http://www.w3.org/2001/XMLSchema"
  24. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  25. xmlns:anim="urn:oasis:names:tc:opendocument:xmlns:animation:1.0"
  26. xmlns:smil="urn:oasis:names:tc:opendocument:xmlns:smil-compatible:1.0"
  27. xmlns:prodtools="http://www.ibm.com/xmlns/prodtools"
  28. version="2.0"
  29. >
  30. <xsl:output method="xml"/>
  31. <xsl:output indent="yes"/>
  32. <xsl:strip-space elements="*"/>
  33. <!-- =========== CALS (OASIS) TABLE =========== -->
  34. <xsl:template match="*[contains(@class,' topic/table ')]" name="topic.table">
  35. <!-- render table -->
  36. <xsl:call-template name="render_table"/>
  37. </xsl:template>
  38. <xsl:template name="create_columns_for_table">
  39. <xsl:param name="column" select="0"/>
  40. <xsl:if test="$column &gt; 0">
  41. <table:table-column/>
  42. <xsl:call-template name="create_columns_for_table">
  43. <xsl:with-param name="column" select="$column - 1"/>
  44. </xsl:call-template>
  45. </xsl:if>
  46. </xsl:template>
  47. <xsl:template name="dotable">
  48. <xsl:apply-templates/>
  49. </xsl:template>
  50. <xsl:template match="*[contains(@class,' topic/tgroup ')]" name="topic.tgroup">
  51. <xsl:variable name="tablenameId" select="generate-id(.)"/>
  52. <xsl:variable name="columnNum">
  53. <xsl:call-template name="count_columns_for_table"/>
  54. </xsl:variable>
  55. <!-- start flagging -->
  56. <xsl:apply-templates select="parent::*[contains(@class, ' topic/table ')]" mode="start-add-odt-flags">
  57. <xsl:with-param name="family" select="'_table'"/>
  58. </xsl:apply-templates>
  59. <table:table table:name="{concat('Table', $tablenameId)}">
  60. <!-- table background flagging -->
  61. <xsl:apply-templates select="parent::*[contains(@class, ' topic/table ')]" mode="start-add-odt-flags">
  62. <xsl:with-param name="family" select="'_table_attr'"/>
  63. </xsl:apply-templates>
  64. <xsl:call-template name="create_columns_for_table">
  65. <xsl:with-param name="column" select="$columnNum"/>
  66. </xsl:call-template>
  67. <xsl:call-template name="dotable"/>
  68. </table:table>
  69. <!-- end flagging -->
  70. <xsl:apply-templates select="parent::*[contains(@class, ' topic/table ')]" mode="end-add-odt-flags">
  71. <xsl:with-param name="family" select="'_table'"/>
  72. </xsl:apply-templates>
  73. </xsl:template>
  74. <xsl:template name="count_columns_for_table">
  75. <xsl:choose>
  76. <xsl:when test="@cols">
  77. <xsl:value-of select="@cols"/>
  78. </xsl:when>
  79. <xsl:when test="not(child::*[contains(@class, ' topic/colspec ')])">
  80. <xsl:choose>
  81. <xsl:when test="child::*[contains(@class, ' topic/thead ')]">
  82. <xsl:value-of select="count(child::*[contains(@class, ' topic/thead ')][1]
  83. /child::*[contains(@class, ' topic/row ')][1]
  84. /child::*[contains(@class, ' topic/entry ')])"/>
  85. </xsl:when>
  86. <xsl:otherwise>
  87. <xsl:value-of select="count(descendant::*[contains(@class, ' topic/row ')][1]
  88. /child::*[contains(@class, ' topic/entry ')])"/>
  89. </xsl:otherwise>
  90. </xsl:choose>
  91. </xsl:when>
  92. <xsl:otherwise>
  93. <xsl:value-of select="count(child::*[contains(@class, ' topic/colspec ')])"/>
  94. </xsl:otherwise>
  95. </xsl:choose>
  96. </xsl:template>
  97. <xsl:template match="*[contains(@class,' topic/table ')]/*[contains(@class,' topic/title ')]">
  98. <xsl:variable name="ancestorlang">
  99. <xsl:call-template name="getLowerCaseLang"/>
  100. </xsl:variable>
  101. <xsl:variable name="tbl-count-actual" select="count(preceding::*[contains(@class,' topic/table ') or contains(@class,' topic/simpletable ')]/*[contains(@class,' topic/title ')])+1"/>
  102. <text:p text:style-name="center">
  103. <text:span text:style-name="bold">
  104. <xsl:choose>
  105. <!-- Hungarian: "1.
  106. Table " -->
  107. <xsl:when test="( (string-length($ancestorlang)=5 and contains($ancestorlang,'hu-hu')) or
  108. (string-length($ancestorlang)=2 and contains($ancestorlang,'hu')) )">
  109. <xsl:value-of
  110. select="$tbl-count-actual"/><xsl:text>. </xsl:text>
  111. <xsl:call-template
  112. name="getVariable">
  113. <xsl:with-param name="id" select="'Table'"/>
  114. </xsl:call-template>
  115. <xsl:text>
  116. </xsl:text>
  117. </xsl:when>
  118. <xsl:otherwise>
  119. <xsl:call-template name="getVariable">
  120. <xsl:with-param name="id" select="'Table'"/>
  121. </xsl:call-template>
  122. <xsl:text> </xsl:text>
  123. <xsl:value-of select="$tbl-count-actual"/><xsl:text>. </xsl:text>
  124. </xsl:otherwise>
  125. </xsl:choose>
  126. <xsl:value-of select="."/>
  127. </text:span>
  128. </text:p>
  129. </xsl:template>
  130. <xsl:template match="*[contains(@class,' topic/table ')]/*[contains(@class,' topic/desc ')]">
  131. <text:p text:style-name="center">
  132. <xsl:apply-templates/>
  133. </text:p>
  134. </xsl:template>
  135. <xsl:template match="*[contains(@class,' topic/colspec ')]"/>
  136. <xsl:template match="*[contains(@class,' topic/spanspec ')]"/>
  137. <xsl:template match="*[contains(@class,' topic/thead ')]" name="topic.thead">
  138. <xsl:apply-templates/>
  139. </xsl:template>
  140. <xsl:template match="*[contains(@class,' topic/tfoot ')]"/>
  141. <xsl:template match="*[contains(@class,' topic/tbody ')]" name="topic.tbody">
  142. <xsl:apply-templates/>
  143. <!-- process table footer -->
  144. <xsl:apply-templates select="../*[contains(@class,' topic/tfoot ')]" mode="gen-tfoot"/>
  145. </xsl:template>
  146. <!-- special mode for table footers -->
  147. <xsl:template match="*[contains(@class,' topic/tfoot ')]" mode="gen-tfoot">
  148. <xsl:apply-templates/>
  149. </xsl:template>
  150. <xsl:template match="*[contains(@class,' topic/row ')]" name="topic.row">
  151. <xsl:choose>
  152. <xsl:when test="parent::*[contains(@class,' topic/thead ')]">
  153. <table:table-header-rows>
  154. <table:table-row>
  155. <xsl:apply-templates select="*[contains(@class,' topic/entry ')][1]"/>
  156. </table:table-row>
  157. </table:table-header-rows>
  158. </xsl:when>
  159. <xsl:otherwise>
  160. <table:table-row>
  161. <xsl:apply-templates select="*[contains(@class,' topic/entry ')][1]"/>
  162. </table:table-row>
  163. </xsl:otherwise>
  164. </xsl:choose>
  165. </xsl:template>
  166. <xsl:template name="count-colmax">
  167. <xsl:choose>
  168. <xsl:when test="../../../*[contains(@class,' topic/colspec ')]">
  169. <xsl:value-of select="number(count(../../../*[contains(@class,' topic/colspec ')]))"/>
  170. </xsl:when>
  171. <xsl:otherwise>
  172. <xsl:value-of select="number(count(../../*[contains(@class,' topic/row ')][1]/*[contains(@class,' topic/entry ')]))"/>
  173. </xsl:otherwise>
  174. </xsl:choose>
  175. </xsl:template>
  176. <xsl:template match="*[contains(@class,' topic/entry ')]" name="topic.entry">
  177. <xsl:param name="currentpos" select="1"/>
  178. <xsl:variable name="rowspan">
  179. <xsl:call-template name="get-rows-span"/>
  180. </xsl:variable>
  181. <xsl:variable name="col-max-num">
  182. <xsl:call-template name="count-colmax"/>
  183. </xsl:variable>
  184. <xsl:variable name="startpos">
  185. <xsl:call-template name="find-entry-start-position"/>
  186. </xsl:variable>
  187. <xsl:variable name="endpos">
  188. <xsl:call-template name="find-entry-end-position">
  189. <xsl:with-param name="startposition" select="$startpos"/>
  190. </xsl:call-template>
  191. </xsl:variable>
  192. <xsl:if test="$startpos &gt; $currentpos">
  193. <!-- render col/row spanned cell.-->
  194. <xsl:call-template name="emit-empty-cell">
  195. <xsl:with-param name="startpos" select="$startpos"/>
  196. <xsl:with-param name="currentpos" select="$currentpos"/>
  197. </xsl:call-template>
  198. </xsl:if>
  199. <!-- finding colspan -->
  200. <xsl:variable name="colspan">
  201. <xsl:call-template name="find-colspan"/>
  202. </xsl:variable>
  203. <!--
  204. <xsl:choose>
  205. <xsl:when test="parent::*/parent::*[contains(@class,' topic/thead ')]">
  206. <xsl:call-template name="topic.thead_entry"/>
  207. </xsl:when>
  208. <xsl:otherwise>
  209. <xsl:call-template name="topic.tbody_entry"/>
  210. </xsl:otherwise>
  211. </xsl:choose>
  212. -->
  213. <table:table-cell office:value-type="string">
  214. <xsl:if test="$colspan &gt; 1">
  215. <xsl:attribute name="table:number-columns-spanned">
  216. <xsl:value-of select="$colspan"/>
  217. </xsl:attribute>
  218. </xsl:if>
  219. <xsl:if test="$rowspan &gt; 1">
  220. <xsl:attribute name="table:number-rows-spanned">
  221. <xsl:value-of select="$rowspan"/>
  222. </xsl:attribute>
  223. </xsl:if>
  224. <xsl:call-template name="create_style_table"/>
  225. <text:p text:style-name="indent_paragraph_style">
  226. <xsl:apply-templates/>
  227. </text:p>
  228. </table:table-cell>
  229. <!-- render col spanned cell.-->
  230. <!--
  231. <xsl:call-template name="emit-empty-cell-for-colspan">
  232. <xsl:with-param name="span" select="$colspan"/>
  233. </xsl:call-template>
  234. -->
  235. <xsl:if test="following-sibling::*[contains(@class,' topic/entry ')]">
  236. <xsl:apply-templates select="following-sibling::*[contains(@class,' topic/entry ')][1]">
  237. <xsl:with-param name="currentpos" select="$endpos + 1"/>
  238. </xsl:apply-templates>
  239. </xsl:if>
  240. <xsl:if test="not(following-sibling::*[contains(@class,' topic/entry ')]) and not(($endpos + 1) &gt; $col-max-num)">
  241. <!-- if this is the last entry in current row and next position is not greater than the number of columns in a row-->
  242. <xsl:call-template name="emit-empty-cell">
  243. <xsl:with-param name="startpos" select="$col-max-num + 1"/> <!-- make sure the remaining columns will be generated -->
  244. <xsl:with-param name="currentpos" select="$endpos + 1"/>
  245. </xsl:call-template>
  246. </xsl:if>
  247. <!-- get text node -->
  248. </xsl:template>
  249. <!-- create style for table
  250. for simpletable refer create_style_stable template
  251. -->
  252. <xsl:template name="create_style_table">
  253. <!-- create style attribute -->
  254. <xsl:variable name="colpos" select="number(substring-after(@colname, 'col'))"/>
  255. <xsl:variable name="rowpos">
  256. <xsl:choose>
  257. <!-- row belongs to thead -->
  258. <xsl:when test="parent::*[contains(@class, ' topic/row ')]
  259. /parent::*[contains(@class, ' topic/thead ')]">
  260. <xsl:value-of select="1"/>
  261. </xsl:when>
  262. <!-- there's no thead -->
  263. <xsl:when test="not(parent::*[contains(@class, ' topic/row ')]
  264. /parent::*[contains(@class, ' topic/tbody ')]
  265. /preceding-sibling::*[contains(@class, ' topic/thead ')])">
  266. <xsl:value-of select="count(parent::*[contains(@class, ' topic/row ')]/
  267. preceding-sibling::*[contains(@class, ' topic/row ')]) + 1"/>
  268. </xsl:when>
  269. <!-- there is thead and row belongs to tbody -->
  270. <xsl:when test="parent::*[contains(@class, ' topic/row ')]
  271. /parent::*[contains(@class, ' topic/tbody ')]
  272. /preceding-sibling::*[contains(@class, ' topic/thead ')]">
  273. <xsl:value-of select="2"/>
  274. </xsl:when>
  275. </xsl:choose>
  276. </xsl:variable>
  277. <xsl:choose>
  278. <!-- first cell in the first row -->
  279. <xsl:when test="$rowpos = 1 and $colpos = 1 ">
  280. <xsl:attribute name="table:style-name">cell_style_1</xsl:attribute>
  281. </xsl:when>
  282. <!-- not first cell but in the first row -->
  283. <xsl:when test="$rowpos = 1 and $colpos != 1 ">
  284. <xsl:attribute name="table:style-name">cell_style_2</xsl:attribute>
  285. </xsl:when>
  286. <!-- first cell but not in the first row -->
  287. <xsl:when test="$rowpos != 1 and $colpos = 1 ">
  288. <xsl:attribute name="table:style-name">cell_style_3</xsl:attribute>
  289. </xsl:when>
  290. <!-- other cells -->
  291. <xsl:otherwise>
  292. <xsl:attribute name="table:style-name">cell_style_4</xsl:attribute>
  293. </xsl:otherwise>
  294. </xsl:choose>
  295. </xsl:template>
  296. <!-- do header entries -->
  297. <xsl:template name="topic.thead_entry">
  298. <xsl:call-template name="doentry"/>
  299. </xsl:template>
  300. <!-- do body entries -->
  301. <xsl:template name="topic.tbody_entry">
  302. <xsl:call-template name="doentry"/>
  303. </xsl:template>
  304. <xsl:template name="doentry">
  305. <!--xsl:variable name="colspan-num">
  306. <xsl:call-template name="find-colspan"></xsl:call-template>
  307. </xsl:variable>
  308. <xsl:variable name="empty-cell-num" select="$colspan-num - 1"/-->
  309. <xsl:apply-templates/>
  310. <!--xsl:call-template name="emit-empty-cell">
  311. <xsl:with-param name="num" select="$empty-cell-num"/>
  312. </xsl:call-template-->
  313. </xsl:template>
  314. <xsl:template match="*[contains(@class,' topic/colspec ')]" mode="count-rowwidth">
  315. <xsl:param name="totalwidth">0</xsl:param> <!-- Total counted width so far -->
  316. <xsl:variable name="thiswidth"> <!-- Width of this column -->
  317. <xsl:choose>
  318. <xsl:when test="@colwidth and contains(@colwidth,'*') and not(@colwidth='*')"><xsl:value-of select="substring-before(@colwidth,'*')"/></xsl:when>
  319. <xsl:otherwise>1</xsl:otherwise>
  320. </xsl:choose>
  321. </xsl:variable>
  322. <!-- If there are more colspecs, continue, otherwise return the current count -->
  323. <xsl:choose>
  324. <xsl:when test="following-sibling::*[contains(@class,' topic/colspec ')]">
  325. <xsl:apply-templates select="following-sibling::*[contains(@class,' topic/colspec ')][1]" mode="count-rowwidth">
  326. <xsl:with-param name="totalwidth" select="$totalwidth + $thiswidth"/>
  327. </xsl:apply-templates>
  328. </xsl:when>
  329. <xsl:otherwise><xsl:value-of select="$totalwidth + $thiswidth"/></xsl:otherwise>
  330. </xsl:choose>
  331. </xsl:template>
  332. <!-- Find the starting column of an entry in a row. -->
  333. <xsl:template name="find-entry-start-position">
  334. <xsl:choose>
  335. <!-- if the column number is specified, use it -->
  336. <xsl:when test="@colnum">
  337. <xsl:value-of select="@colnum"/>
  338. </xsl:when>
  339. <xsl:when test="not(../../../*[contains(@class,' topic/colspec ')])">
  340. <xsl:variable name="prev-sib" select="count(preceding-sibling::*)"/>
  341. <xsl:value-of select="$prev-sib+1"/>
  342. </xsl:when>
  343. <!-- If there is a defined column name, check the colspans to determine position -->
  344. <xsl:when test="@colname">
  345. <!-- count the number of colspans before the one this entry references, plus one -->
  346. <xsl:value-of select="number(count(../../../*[contains(@class,' topic/colspec ')][@colname=current()/@colname]/preceding-sibling::*[contains(@class, ' topic/colspec ')])+1)"/>
  347. </xsl:when>
  348. <!-- If the starting column is defined, check colspans to determine position -->
  349. <xsl:when test="@namest">
  350. <xsl:value-of select="number(count(../../../*[contains(@class,' topic/colspec ')][@colname=current()/@namest]/preceding-sibling::*[contains(@class, ' topic/colspec ')])+1)"/>
  351. </xsl:when>
  352. <!-- Need a test for spanspec -->
  353. <xsl:when test="@spanname">
  354. <xsl:variable name="startspan"> <!-- starting column for this span -->
  355. <xsl:value-of select="../../../*[contains(@class,' topic/spanspec ')][@spanname=current()/@spanname]/@namest"/>
  356. </xsl:variable>
  357. <xsl:value-of select="number(count(../../../*[contains(@class,' topic/colspec ')][@colname=$startspan]/preceding-sibling::*[contains(@class, ' topic/colspec ')])+1)"/>
  358. </xsl:when>
  359. <!-- Otherwise, just use the count of cells in this row -->
  360. <xsl:otherwise>
  361. <xsl:variable name="prev-sib" select="count(preceding-sibling::*)"/>
  362. <xsl:value-of select="$prev-sib+1"/>
  363. </xsl:otherwise>
  364. </xsl:choose>
  365. </xsl:template>
  366. <!-- Find the end column of a cell. If the cell does not span any columns,
  367. the end position is the same as the start position. -->
  368. <xsl:template name="find-entry-end-position">
  369. <xsl:param name="startposition" select="0"/>
  370. <xsl:choose>
  371. <xsl:when test="not(../../../*[contains(@class,' topic/colspec ')])">
  372. <xsl:value-of select="$startposition"/>
  373. </xsl:when>
  374. <xsl:when test="@nameend">
  375. <xsl:value-of select="number(count(../../../*[contains(@class,' topic/colspec ')][@colname=current()/@nameend]/preceding-sibling::*[contains(@class, ' topic/colspec ')])+1)"/>
  376. </xsl:when>
  377. <xsl:when test="@spanname">
  378. <xsl:variable name="endspan"> <!-- starting column for this span -->
  379. <xsl:value-of select="../../../*[contains(@class,' topic/spanspec ')][@spanname=current()/@spanname]/@nameend"/>
  380. </xsl:variable>
  381. <xsl:value-of select="number(count(../../../*[contains(@class,' topic/colspec ')][@colname=$endspan]/preceding-sibling::*[contains(@class, ' topic/colspec ')])+1)"/>
  382. </xsl:when>
  383. <xsl:otherwise>
  384. <xsl:value-of select="$startposition"/>
  385. </xsl:otherwise>
  386. </xsl:choose>
  387. </xsl:template>
  388. <!-- Find the number of column spans between name-start and name-end attrs -->
  389. <xsl:template name="find-colspan">
  390. <xsl:variable name="startpos">
  391. <xsl:call-template name="find-entry-start-position"/>
  392. </xsl:variable>
  393. <xsl:variable name="endpos">
  394. <xsl:call-template name="find-entry-end-position">
  395. <xsl:with-param name="startposition" select="$startpos"/>
  396. </xsl:call-template>
  397. </xsl:variable>
  398. <xsl:value-of select="$endpos - $startpos + 1"/>
  399. </xsl:template>
  400. <xsl:template name="find-spanspec-colspan">
  401. <xsl:variable name="spanname" select="@spanname"/>
  402. <xsl:variable name="startcolname" select="../../../*[contains(@class,' topic/spanspec ')][@spanname=$spanname][1]/@namest"/>
  403. <xsl:variable name="endcolname" select="../../../*[contains(@class,' topic/spanspec ')][@spanname=$spanname][1]/@nameend"/>
  404. <xsl:variable name="startpos" select="number(count(../../../*[contains(@class,' topic/colspec ')][@colname=$startcolname]/preceding-sibling::*[contains(@class, ' topic/colspec ')])+1)"/>
  405. <xsl:variable name="endpos" select="number(count(../../../*[contains(@class,' topic/colspec ')][@colname=$endcolname]/preceding-sibling::*[contains(@class, ' topic/colspec ')])+1)"/>
  406. <xsl:value-of select="$endpos - $startpos + 1"/>
  407. </xsl:template>
  408. <xsl:template name="emit-empty-cell">
  409. <xsl:param name="currentpos" select="1"/>
  410. <xsl:param name="startpos" select="1"/>
  411. <xsl:if test="$startpos &gt; $currentpos">
  412. <xsl:variable name="colspan">
  413. <xsl:apply-templates select="../preceding-sibling::*[*[contains(@class,' topic/entry ')][@morerows][@colnum=$currentpos or @colname=concat('col',$currentpos) or @namest=concat('col',$currentpos)]][1]/*[contains(@class,' topic/entry ')][@morerows][@colnum=$currentpos or @colname=concat('col',$currentpos) or @namest=concat('col',$currentpos)]" mode="find-colspan"/>
  414. </xsl:variable>
  415. <table:covered-table-cell/>
  416. <xsl:if test="not($colspan='') and ($startpos &gt; ($currentpos + $colspan))">
  417. <xsl:call-template name="emit-empty-cell">
  418. <xsl:with-param name="startpos" select="$startpos"/>
  419. <xsl:with-param name="currentpos" select="$currentpos + $colspan"/>
  420. </xsl:call-template>
  421. </xsl:if>
  422. </xsl:if>
  423. </xsl:template>
  424. <!--
  425. <xsl:template name="emit-empty-cell-for-colspan">
  426. <xsl:param name="span" select="0"/>
  427. <xsl:if test="$span &gt; 1">
  428. <table:covered-table-cell/>
  429. <xsl:call-template name="emit-empty-cell-for-colspan">
  430. <xsl:with-param name="span" select="$span - 1"></xsl:with-param>
  431. </xsl:call-template>
  432. </xsl:if>
  433. </xsl:template>
  434. -->
  435. <xsl:template name="get-rows-span">
  436. <xsl:choose>
  437. <xsl:when test="@morerows">
  438. <xsl:value-of select="number(@morerows + 1)"/>
  439. </xsl:when>
  440. <xsl:otherwise>1</xsl:otherwise>
  441. </xsl:choose>
  442. </xsl:template>
  443. <xsl:template match="*[contains(@class,' topic/entry ')]" mode="find-colspan">
  444. <xsl:call-template name="find-colspan"/>
  445. </xsl:template>
  446. <xsl:template match="*[contains(@class,' topic/colspec ')]" mode="count-colwidth">
  447. <xsl:param name="colnum" select="1"/>
  448. <xsl:param name="span-width" select="0"/>
  449. <xsl:variable name="width">
  450. <xsl:choose>
  451. <xsl:when test="@colwidth and not(@colwidth='' or @colwidth='*')">
  452. <xsl:value-of select="substring-before(@colwidth,'*')"/>
  453. </xsl:when>
  454. <xsl:otherwise>1</xsl:otherwise>
  455. </xsl:choose>
  456. </xsl:variable>
  457. <xsl:choose>
  458. <xsl:when test="$colnum &gt; 1">
  459. <xsl:apply-templates select="following-sibling::*[1]" mode="count-colwidth">
  460. <xsl:with-param name="colnum" select="$colnum - 1"/>
  461. <xsl:with-param name="span-width" select="$span-width + $width"/>
  462. </xsl:apply-templates>
  463. </xsl:when>
  464. <xsl:otherwise><xsl:value-of select="$span-width + $width"/></xsl:otherwise>
  465. </xsl:choose>
  466. </xsl:template>
  467. <!--xsl:template name="count-colwidth">
  468. <xsl:param name="colnum" select="1"/>
  469. <xsl:param name="span-width" select="0"/>
  470. <xsl:variable name="width">
  471. <xsl:choose>
  472. <xsl:when test="@colwidth and not(@colwidth='')">
  473. <xsl:value-of select="substring-before(@colwidth,'*')"/>
  474. </xsl:when>
  475. <xsl:otherwise>1</xsl:otherwise>
  476. </xsl:choose>
  477. </xsl:variable>
  478. <xsl:choose>
  479. <xsl:when test="$colnum &gt; 1">
  480. <xsl:call-template name="count-colwidth">
  481. <xsl:with-param name="colnum" select="$colnum - 1"/>
  482. <xsl:with-param name="span-width" select="$span-width + $width"/>
  483. </xsl:call-template>
  484. </xsl:when>
  485. <xsl:otherwise><xsl:value-of select="$span-width + $width"/></xsl:otherwise>
  486. </xsl:choose>
  487. </xsl:template-->
  488. <!-- Simple Table -->
  489. <xsl:template match="*[contains(@class,' topic/simpletable ')]" name="topic.simpletable">
  490. <!-- render stable -->
  491. <xsl:call-template name="render_simpletable"/>
  492. </xsl:template>
  493. <xsl:template name="create_simpletable">
  494. <xsl:variable name="tablenameId" select="generate-id(.)"/>
  495. <!-- start flagging -->
  496. <xsl:apply-templates select="." mode="start-add-odt-flags">
  497. <xsl:with-param name="family" select="'_table'"/>
  498. </xsl:apply-templates>
  499. <table:table table:name="{concat('Table', $tablenameId)}">
  500. <!-- table background flagging -->
  501. <xsl:apply-templates select="." mode="start-add-odt-flags">
  502. <xsl:with-param name="family" select="'_table_attr'"/>
  503. </xsl:apply-templates>
  504. <xsl:variable name="colnumNum">
  505. <xsl:call-template name="count_columns_for_simpletable"/>
  506. </xsl:variable>
  507. <xsl:call-template name="create_columns_for_simpletable">
  508. <xsl:with-param name="column" select="$colnumNum"/>
  509. </xsl:call-template>
  510. <xsl:call-template name="dotable"/>
  511. </table:table>
  512. <!-- end flagging -->
  513. <xsl:apply-templates select="." mode="end-add-odt-flags">
  514. <xsl:with-param name="family" select="'_table'"/>
  515. </xsl:apply-templates>
  516. </xsl:template>
  517. <xsl:template name="count_columns_for_simpletable">
  518. <xsl:choose>
  519. <xsl:when test="child::*[contains(@class, ' topic/sthead ')]">
  520. <xsl:value-of select="count(child::*[contains(@class, ' topic/sthead ')][1]
  521. /child::*[contains(@class, ' topic/stentry ')])"/>
  522. </xsl:when>
  523. <xsl:otherwise>
  524. <xsl:value-of select="count(child::*[contains(@class, ' topic/strow ')][1]
  525. /child::*[contains(@class, ' topic/stentry ')])"/>
  526. </xsl:otherwise>
  527. </xsl:choose>
  528. </xsl:template>
  529. <xsl:template name="create_columns_for_simpletable">
  530. <xsl:param name="column" select="0"/>
  531. <xsl:if test="$column &gt; 0">
  532. <table:table-column/>
  533. <xsl:call-template name="create_columns_for_simpletable">
  534. <xsl:with-param name="column" select="$column - 1"/>
  535. </xsl:call-template>
  536. </xsl:if>
  537. </xsl:template>
  538. <xsl:template match="*[contains(@class,' topic/simpletable ')]/*[contains(@class,' topic/title ')]">
  539. <xsl:variable name="ancestorlang">
  540. <xsl:call-template name="getLowerCaseLang"/>
  541. </xsl:variable>
  542. <xsl:variable name="tbl-count-actual" select="count(preceding::*[contains(@class,' topic/table ')
  543. or contains(@class,' topic/simpletable ')]/*[contains(@class,' topic/title ')])+1"/>
  544. <text:p text:style-name="bold">
  545. <xsl:choose>
  546. <!-- Hungarian: "1.Table " -->
  547. <xsl:when test="( (string-length($ancestorlang)=5 and contains($ancestorlang,'hu-hu')) or (string-length($ancestorlang)=2 and contains($ancestorlang,'hu')) )">
  548. <xsl:value-of select="$tbl-count-actual"/><xsl:text>. </xsl:text>
  549. <xsl:call-template name="getVariable">
  550. <xsl:with-param name="id" select="'Table'"/>
  551. </xsl:call-template><xsl:text>
  552. </xsl:text>
  553. </xsl:when>
  554. <xsl:otherwise>
  555. <xsl:call-template name="getVariable">
  556. <xsl:with-param name="id" select="'Table'"/>
  557. </xsl:call-template>
  558. <xsl:text> </xsl:text>
  559. <xsl:value-of select="$tbl-count-actual"/>
  560. <xsl:text>. </xsl:text>
  561. </xsl:otherwise>
  562. </xsl:choose>
  563. <xsl:value-of select="."/>
  564. </text:p>
  565. </xsl:template>
  566. <xsl:template match="*[contains(@class,' topic/sthead ')]">
  567. <table:table-header-rows>
  568. <table:table-row>
  569. <xsl:apply-templates mode="emit-cell-style"/>
  570. </table:table-row>
  571. </table:table-header-rows>
  572. </xsl:template>
  573. <xsl:template match="*[contains(@class,' topic/strow ')]">
  574. <table:table-row>
  575. <xsl:apply-templates mode="emit-cell-style"/>
  576. </table:table-row>
  577. </xsl:template>
  578. <xsl:template match="*[contains(@class,' topic/stentry ')]" mode="emit-cell-style">
  579. <xsl:variable name="totalcols" select="count(../*[contains(@class,' topic/stentry ')])">
  580. <!--xsl:apply-templates select="../*[contains(@class,' topic/stentry ')][1]" mode="count-rowwidth"/-->
  581. </xsl:variable>
  582. <!--
  583. <xsl:variable name="thiswidth-twips" select="$table-row-width div $totalcols"/>
  584. <xsl:value-of select="$valign"/>
  585. -->
  586. <table:table-cell office:value-type="string">
  587. <xsl:call-template name="create_style_stable"/>
  588. <text:p text:style-name="indent_paragraph_style">
  589. <xsl:apply-templates/>
  590. </text:p>
  591. </table:table-cell>
  592. </xsl:template>
  593. <xsl:template match="text()" mode="tags_in_sthead">
  594. <text:span text:style-name="bold">
  595. <xsl:apply-templates select="."/>
  596. </text:span>
  597. </xsl:template>
  598. <xsl:template match="*" mode="tags_in_sthead">
  599. <xsl:apply-templates select="."/>
  600. </xsl:template>
  601. <xsl:template name="create_style_stable">
  602. <!-- create style attribute -->
  603. <xsl:variable name="colpos" select="position()"/>
  604. <xsl:variable name="rowpos">
  605. <xsl:choose>
  606. <!-- row belongs to thead -->
  607. <xsl:when test="parent::*[contains(@class, ' topic/sthead ')]">
  608. <xsl:value-of select="1"/>
  609. </xsl:when>
  610. <!-- there's no thead -->
  611. <xsl:when test="not(parent::*[contains(@class, ' topic/strow ')]
  612. /preceding-sibling::*[contains(@class, ' topic/sthead ')])">
  613. <xsl:value-of select="count(parent::*[contains(@class, ' topic/strow ')]/
  614. preceding-sibling::*[contains(@class, ' topic/strow ')]) + 1"/>
  615. </xsl:when>
  616. <!-- there is thead and row belongs to tbody -->
  617. <xsl:when test="parent::*[contains(@class, ' topic/strow ')]
  618. /preceding-sibling::*[contains(@class, ' topic/sthead ')]">
  619. <xsl:value-of select="2"/>
  620. </xsl:when>
  621. </xsl:choose>
  622. </xsl:variable>
  623. <xsl:choose>
  624. <!-- first column and first row -->
  625. <xsl:when test="$rowpos = 1 and $colpos = 1 ">
  626. <xsl:attribute name="table:style-name">cell_style_1</xsl:attribute>
  627. </xsl:when>
  628. <!-- not first column but first row -->
  629. <xsl:when test="$rowpos = 1 and $colpos != 1 ">
  630. <xsl:attribute name="table:style-name">cell_style_2</xsl:attribute>
  631. </xsl:when>
  632. <!-- first column but not first row -->
  633. <xsl:when test="$rowpos != 1 and $colpos = 1 ">
  634. <xsl:attribute name="table:style-name">cell_style_3</xsl:attribute>
  635. </xsl:when>
  636. <!-- other cells -->
  637. <xsl:otherwise>
  638. <xsl:attribute name="table:style-name">cell_style_4</xsl:attribute>
  639. </xsl:otherwise>
  640. </xsl:choose>
  641. </xsl:template>
  642. <xsl:template match="*[contains(@class,' topic/stentry ')]" mode="count-rowwidth">
  643. <xsl:param name="totalcols">0</xsl:param> <!-- Total counted columns so far -->
  644. <xsl:choose>
  645. <xsl:when test="following-sibling::*[contains(@class,' topic/stentry ')]">
  646. <xsl:apply-templates select="following-sibling::*[contains(@class,' topic/stentry ')][1]" mode="count-rowwidth">
  647. <xsl:with-param name="totalwidth" select="$totalcols + 1"/>
  648. </xsl:apply-templates>
  649. </xsl:when>
  650. <xsl:otherwise><xsl:value-of select="$totalcols + 1"/></xsl:otherwise>
  651. </xsl:choose>
  652. </xsl:template>
  653. <xsl:template name="output-stentry-id">
  654. <!-- Find the position in this row -->
  655. <xsl:variable name="thiscolnum"><xsl:number level="single" count="*"/></xsl:variable>
  656. <xsl:choose>
  657. <xsl:when test="@id"> <!-- If ID is specified, always use it -->
  658. <xsl:attribute name="id"><xsl:value-of select="@id"/></xsl:attribute>
  659. </xsl:when>
  660. <!-- If no ID is specified, and this is a header cell, generate an ID -->
  661. <xsl:when test="parent::*[contains(@class,' topic/sthead ')] or
  662. (parent::*/parent::*/@keycol and number(parent::*/parent::*/@keycol)=number($thiscolnum))">
  663. <xsl:attribute name="id"><xsl:value-of select="generate-id(.)"/></xsl:attribute>
  664. </xsl:when>
  665. </xsl:choose>
  666. </xsl:template>
  667. <xsl:template name="create_table_cell_styles">
  668. <!-- for normal table -->
  669. <style:style style:name="cell_style_1" style:family="table-cell">
  670. <style:table-cell-properties fo:padding="0.0201in" fo:border="0.0007in solid #000000"/>
  671. </style:style>
  672. <style:style style:name="cell_style_2" style:family="table-cell">
  673. <style:table-cell-properties fo:padding="0.0201in" fo:border-left="none"
  674. fo:border-right="0.0007in solid #000000" fo:border-top="0.0007in solid #000000"
  675. fo:border-bottom="0.0007in solid #000000" />
  676. </style:style>
  677. <style:style style:name="cell_style_3" style:family="table-cell">
  678. <style:table-cell-properties fo:padding="0.0201in"
  679. fo:border-right="0.0007in solid #000000" fo:border-left="0.0007in solid #000000" fo:border-top="none"
  680. fo:border-bottom="0.0007in solid #000000"/>
  681. </style:style>
  682. <style:style style:name="cell_style_4" style:family="table-cell">
  683. <style:table-cell-properties fo:padding="0.0201in"
  684. fo:border-right="0.0007in solid #000000" fo:border-bottom="0.0007in solid #000000"
  685. fo:border-top="none" fo:border-left="none"/>
  686. </style:style>
  687. <!-- for task choice table without head, it is simple.-->
  688. <style:style style:name="cell_style_1_task" style:family="table-cell">
  689. <style:table-cell-properties fo:padding="0.0201in" fo:border-left="0.0007in solid #000000"
  690. fo:border-right="0.0007in solid #000000" fo:border-top="0.0007in solid #000000"
  691. fo:border-bottom="none" />
  692. </style:style>
  693. <style:style style:name="cell_style_2_task" style:family="table-cell">
  694. <style:table-cell-properties fo:padding="0.0201in" fo:border-left="none"
  695. fo:border-right="0.0007in solid #000000" fo:border-top="0.0007in solid #000000"
  696. fo:border-bottom="none"/>
  697. </style:style>
  698. </xsl:template>
  699. </xsl:stylesheet>