dita2rtf-table.xsl 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- This file is part of the DITA Open Toolkit project hosted on
  3. Sourceforge.net. See the accompanying license.txt file for
  4. applicable licenses.-->
  5. <!-- (c) Copyright IBM Corp. 2005 All Rights Reserved. -->
  6. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  7. xmlns:xs="http://www.w3.org/2001/XMLSchema"
  8. exclude-result-prefixes="xs"
  9. version="2.0">
  10. <xsl:output method="text"/>
  11. <xsl:strip-space elements="*"/>
  12. <!-- =========== CALS (OASIS) TABLE =========== -->
  13. <xsl:template match="*[contains(@class,' topic/table ')]" name="topic.table">
  14. <xsl:call-template name="gen-id"/><xsl:call-template name="dotable"/>
  15. </xsl:template>
  16. <xsl:template name="dotable">
  17. <xsl:text>\par </xsl:text>
  18. <xsl:apply-templates/>
  19. <xsl:text>\pard \qj \li0\ri0\nowidctlpar\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0 {
  20. \par }</xsl:text>
  21. </xsl:template>
  22. <xsl:template match="*[contains(@class,' topic/table ')]/*[contains(@class,' topic/title ')]">
  23. <xsl:variable name="ancestorlang">
  24. <xsl:call-template name="getLowerCaseLang"/>
  25. </xsl:variable>
  26. <xsl:variable name="tbl-count-actual" select="count(preceding::*[contains(@class,' topic/table ') or contains(@class,' topic/simpletable ')]/*[contains(@class,' topic/title ')])+1"/>
  27. <xsl:call-template name="gen-id"/>\pard \plain\s9 \qc\f4\fs24\b <xsl:choose><!-- Hungarian: "1.
  28. Table " --><xsl:when test="( (string-length($ancestorlang)=5 and contains($ancestorlang,'hu-hu')) or
  29. (string-length($ancestorlang)=2 and contains($ancestorlang,'hu')) )"><xsl:value-of
  30. select="$tbl-count-actual"/><xsl:text>. </xsl:text><xsl:call-template
  31. name="getString"><xsl:with-param name="stringName" select="'Table'"/></xsl:call-template><xsl:text>
  32. </xsl:text></xsl:when><xsl:otherwise><xsl:call-template name="getStringRTF"><xsl:with-param
  33. name="stringName" select="'Table'"/></xsl:call-template><xsl:text> </xsl:text><xsl:value-of
  34. select="$tbl-count-actual"/><xsl:text>. </xsl:text></xsl:otherwise></xsl:choose><xsl:value-of select="."/>\par \plain\s0 \qj\f2\fs24
  35. </xsl:template>
  36. <xsl:template match="*[contains(@class,' topic/table ')]/*[contains(@class,' topic/desc ')]">
  37. <xsl:call-template name="gen-id"/>\pard \plain\s0 \f2\fs24 <xsl:apply-templates/>\par \plain\s0 \f2\fs24
  38. </xsl:template>
  39. <xsl:template match="*[contains(@class,' topic/tgroup ')]" name="topic.tgroup">
  40. <xsl:call-template name="gen-id"/><xsl:apply-templates/>
  41. </xsl:template>
  42. <xsl:template match="*[contains(@class,' topic/colspec ')]"></xsl:template>
  43. <xsl:template match="*[contains(@class,' topic/spanspec ')]"></xsl:template>
  44. <xsl:template match="*[contains(@class,' topic/thead ')]" name="topic.thead">
  45. <xsl:call-template name="gen-id"/><xsl:apply-templates/>
  46. </xsl:template>
  47. <xsl:template match="*[contains(@class,' topic/tfoot ')]"/>
  48. <xsl:template match="*[contains(@class,' topic/tbody ')]" name="topic.tbody">
  49. <xsl:call-template name="gen-id"/><xsl:apply-templates/>
  50. <!-- process table footer -->
  51. <xsl:apply-templates select="../*[contains(@class,' topic/tfoot ')]" mode="gen-tfoot" />
  52. </xsl:template>
  53. <!-- special mode for table footers -->
  54. <xsl:template match="*[contains(@class,' topic/tfoot ')]" mode="gen-tfoot">
  55. <xsl:apply-templates/>
  56. </xsl:template>
  57. <xsl:template match="*[contains(@class,' topic/row ')]" name="topic.row">
  58. <xsl:call-template name="gen-id"/>
  59. <xsl:text>\trowd \trgaph108\trleft-108\trbrdrt\brdrs\brdrw10 </xsl:text>
  60. <xsl:if test="parent::*[contains(@class,' topic/thead ')]"><xsl:text>\trhdr </xsl:text></xsl:if>
  61. <xsl:text>\trbrdrl\brdrs\brdrw10 \trbrdrb\brdrs\brdrw10 \trbrdrr\brdrs\brdrw10
  62. \trbrdrh\brdrs\brdrw10 \trbrdrv\brdrs\brdrw10
  63. \trftsWidth1\trautofit1\trpaddl108\trpaddr108\trpaddfl3\trpaddfr3</xsl:text>
  64. <xsl:apply-templates select="*[contains(@class,' topic/entry ')][1]" mode="emit-cell-style"/>
  65. <xsl:choose>
  66. <xsl:when test="parent::*[contains(@class,' topic/thead ')]"><xsl:text>\plain \s7\f4\fs24\b \qc</xsl:text></xsl:when>
  67. <xsl:otherwise>\plain \s0\f4\fs24 <xsl:value-of select="$table-row-default-align"/></xsl:otherwise>
  68. </xsl:choose>
  69. \li0\fi0\ri0\nowidctlpar\intbl\aspalpha\aspnum\faauto\adjustright\rin0\lin0
  70. <xsl:text>{</xsl:text><xsl:apply-templates select="*[contains(@class,' topic/entry ')][1]"/><xsl:text>}\row</xsl:text>
  71. </xsl:template>
  72. <xsl:template name="count-colmax">
  73. <xsl:choose>
  74. <xsl:when test="../../../*[contains(@class,' topic/colspec ')]">
  75. <xsl:value-of select="number(count(../../../*[contains(@class,' topic/colspec ')]))"/>
  76. </xsl:when>
  77. <xsl:otherwise>
  78. <xsl:value-of select="number(count(../../*[contains(@class,' topic/row ')][1]/*[contains(@class,' topic/entry ')]))"/>
  79. </xsl:otherwise>
  80. </xsl:choose>
  81. </xsl:template>
  82. <xsl:template match="*[contains(@class,' topic/entry ')]" name="topic.entry">
  83. <xsl:param name="currentpos" select="1"/>
  84. <xsl:variable name="col-max-num">
  85. <xsl:call-template name="count-colmax"/>
  86. </xsl:variable>
  87. <xsl:variable name="startpos"><xsl:call-template name="find-entry-start-position"/></xsl:variable>
  88. <xsl:variable name="endpos">
  89. <xsl:call-template name="find-entry-end-position">
  90. <xsl:with-param name="startposition" select="$startpos"/>
  91. </xsl:call-template>
  92. </xsl:variable>
  93. <xsl:if test="$startpos &gt; $currentpos">
  94. <xsl:call-template name="emit-empty-cell">
  95. <xsl:with-param name="startpos" select="$startpos"/>
  96. <xsl:with-param name="currentpos" select="$currentpos"/>
  97. </xsl:call-template>
  98. </xsl:if>
  99. <xsl:choose>
  100. <xsl:when test="parent::*/parent::*[contains(@class,' topic/thead ')]">
  101. <xsl:call-template name="topic.thead_entry"/>
  102. </xsl:when>
  103. <xsl:otherwise>
  104. <xsl:call-template name="topic.tbody_entry"/>
  105. </xsl:otherwise>
  106. </xsl:choose>
  107. <xsl:if test="following-sibling::*[contains(@class,' topic/entry ')]">
  108. <xsl:apply-templates select="following-sibling::*[contains(@class,' topic/entry ')][1]">
  109. <xsl:with-param name="currentpos" select="$endpos + 1"/>
  110. </xsl:apply-templates>
  111. </xsl:if>
  112. <xsl:if test="not(following-sibling::*[contains(@class,' topic/entry ')]) and not(($endpos + 1) &gt; $col-max-num)">
  113. <!-- if this is the last entry in current row and next position is not greater than the number of columns in a row-->
  114. <xsl:call-template name="emit-empty-cell">
  115. <xsl:with-param name="startpos" select="$col-max-num + 1"/> <!-- make sure the remaining columns will be generated -->
  116. <xsl:with-param name="currentpos" select="$endpos + 1"/>
  117. </xsl:call-template>
  118. </xsl:if>
  119. </xsl:template>
  120. <!-- do header entries -->
  121. <xsl:template name="topic.thead_entry">
  122. <xsl:call-template name="doentry"/>
  123. </xsl:template>
  124. <!-- do body entries -->
  125. <xsl:template name="topic.tbody_entry">
  126. <xsl:call-template name="doentry"/>
  127. </xsl:template>
  128. <xsl:template name="doentry">
  129. <!--xsl:variable name="colspan-num">
  130. <xsl:call-template name="find-colspan"></xsl:call-template>
  131. </xsl:variable>
  132. <xsl:variable name="empty-cell-num" select="$colspan-num - 1"/-->
  133. <xsl:apply-templates/><xsl:text>\cell </xsl:text>
  134. <!--xsl:call-template name="emit-empty-cell">
  135. <xsl:with-param name="num" select="$empty-cell-num"/>
  136. </xsl:call-template-->
  137. </xsl:template>
  138. <xsl:template match="*[contains(@class,' topic/colspec ')]" mode="count-rowwidth">
  139. <xsl:param name="totalwidth">0</xsl:param> <!-- Total counted width so far -->
  140. <xsl:variable name="thiswidth"> <!-- Width of this column -->
  141. <xsl:choose>
  142. <xsl:when test="not(@colwidth) or @colwidth='*'">1</xsl:when>
  143. <xsl:when test="contains(@colwidth,'*')"><xsl:value-of select="substring-before(@colwidth,'*')"/></xsl:when>
  144. <xsl:when test="contains(@colwidth,'pt')"><xsl:value-of select="substring-before(@colwidth,'pt')"/></xsl:when>
  145. <xsl:when test="contains(@colwidth,'cm')"><xsl:value-of select="substring-before(@colwidth,'cm')"/></xsl:when>
  146. <xsl:when test="contains(@colwidth,'in')"><xsl:value-of select="substring-before(@colwidth,'in')"/></xsl:when>
  147. <xsl:when test="contains(@colwidth,'mm')"><xsl:value-of select="substring-before(@colwidth,'mm')"/></xsl:when>
  148. <xsl:otherwise>1</xsl:otherwise>
  149. </xsl:choose>
  150. </xsl:variable>
  151. <!-- If there are more colspecs, continue, otherwise return the current count -->
  152. <xsl:choose>
  153. <xsl:when test="following-sibling::*[contains(@class,' topic/colspec ')]">
  154. <xsl:apply-templates select="following-sibling::*[contains(@class,' topic/colspec ')][1]" mode="count-rowwidth">
  155. <xsl:with-param name="totalwidth" select="$totalwidth + $thiswidth"/>
  156. </xsl:apply-templates>
  157. </xsl:when>
  158. <xsl:otherwise><xsl:value-of select="$totalwidth + $thiswidth"/></xsl:otherwise>
  159. </xsl:choose>
  160. </xsl:template>
  161. <!-- Find the starting column of an entry in a row. -->
  162. <xsl:template name="find-entry-start-position">
  163. <xsl:choose>
  164. <!-- if the column number is specified, use it -->
  165. <xsl:when test="@colnum">
  166. <xsl:value-of select="@colnum"/>
  167. </xsl:when>
  168. <xsl:when test="not(../../../*[contains(@class,' topic/colspec ')])">
  169. <xsl:variable name="prev-sib">
  170. <xsl:value-of select="count(preceding-sibling::*)"/>
  171. </xsl:variable>
  172. <xsl:value-of select="$prev-sib+1"/>
  173. </xsl:when>
  174. <!-- If there is a defined column name, check the colspans to determine position -->
  175. <xsl:when test="@colname">
  176. <!-- count the number of colspans before the one this entry references, plus one -->
  177. <xsl:value-of select="number(count(../../../*[contains(@class,' topic/colspec ')][@colname=current()/@colname]/preceding-sibling::*)+1)"/>
  178. </xsl:when>
  179. <!-- If the starting column is defined, check colspans to determine position -->
  180. <xsl:when test="@namest">
  181. <xsl:value-of select="number(count(../../../*[contains(@class,' topic/colspec ')][@colname=current()/@namest]/preceding-sibling::*)+1)"/>
  182. </xsl:when>
  183. <!-- Need a test for spanspec -->
  184. <xsl:when test="@spanname">
  185. <xsl:variable name="startspan"> <!-- starting column for this span -->
  186. <xsl:value-of select="../../../*[contains(@class,' topic/spanspec ')][@spanname=current()/@spanname]/@namest"/>
  187. </xsl:variable>
  188. <xsl:value-of select="number(count(../../../*[contains(@class,' topic/colspec ')][@colname=$startspan]/preceding-sibling::*)+1)"/>
  189. </xsl:when>
  190. <!-- Otherwise, just use the count of cells in this row -->
  191. <xsl:otherwise>
  192. <xsl:variable name="prev-sib">
  193. <xsl:value-of select="count(preceding-sibling::*)"/>
  194. </xsl:variable>
  195. <xsl:value-of select="$prev-sib+1"/>
  196. </xsl:otherwise>
  197. </xsl:choose>
  198. </xsl:template>
  199. <!-- Find the end column of a cell. If the cell does not span any columns,
  200. the end position is the same as the start position. -->
  201. <xsl:template name="find-entry-end-position">
  202. <xsl:param name="startposition" select="0"/>
  203. <xsl:choose>
  204. <xsl:when test="not(../../../*[contains(@class,' topic/colspec ')])">
  205. <xsl:value-of select="$startposition"/>
  206. </xsl:when>
  207. <xsl:when test="@nameend">
  208. <xsl:value-of select="number(count(../../../*[contains(@class,' topic/colspec ')][@colname=current()/@nameend]/preceding-sibling::*)+1)"/>
  209. </xsl:when>
  210. <xsl:when test="@spanname">
  211. <xsl:variable name="endspan"> <!-- starting column for this span -->
  212. <xsl:value-of select="../../../*[contains(@class,' topic/spanspec ')][@spanname=current()/@spanname]/@nameend"/>
  213. </xsl:variable>
  214. <xsl:value-of select="number(count(../../../*[contains(@class,' topic/colspec ')][@colname=$endspan]/preceding-sibling::*)+1)"/>
  215. </xsl:when>
  216. <xsl:otherwise>
  217. <xsl:value-of select="$startposition"/>
  218. </xsl:otherwise>
  219. </xsl:choose>
  220. </xsl:template>
  221. <!-- Find the number of column spans between name-start and name-end attrs -->
  222. <xsl:template name="find-colspan">
  223. <xsl:variable name="startpos">
  224. <xsl:call-template name="find-entry-start-position"/>
  225. </xsl:variable>
  226. <xsl:variable name="endpos">
  227. <xsl:call-template name="find-entry-end-position">
  228. <xsl:with-param name="startposition" select="$startpos"/>
  229. </xsl:call-template>
  230. </xsl:variable>
  231. <xsl:value-of select="$endpos - $startpos + 1"/>
  232. </xsl:template>
  233. <xsl:template name="find-spanspec-colspan">
  234. <xsl:variable name="spanname"><xsl:value-of select="@spanname"/></xsl:variable>
  235. <xsl:variable name="startcolname">
  236. <xsl:value-of select="../../../*[contains(@class,' topic/spanspec ')][@spanname=$spanname][1]/@namest"/>
  237. </xsl:variable>
  238. <xsl:variable name="endcolname">
  239. <xsl:value-of select="../../../*[contains(@class,' topic/spanspec ')][@spanname=$spanname][1]/@nameend"/>
  240. </xsl:variable>
  241. <xsl:variable name="startpos">
  242. <xsl:value-of select="number(count(../../../*[contains(@class,' topic/colspec ')][@colname=$startcolname]/preceding-sibling::*)+1)"/>
  243. </xsl:variable>
  244. <xsl:variable name="endpos">
  245. <xsl:value-of select="number(count(../../../*[contains(@class,' topic/colspec ')][@colname=$endcolname]/preceding-sibling::*)+1)"/>
  246. </xsl:variable>
  247. <xsl:value-of select="$endpos - $startpos + 1"/>
  248. </xsl:template>
  249. <xsl:template name="emit-empty-cell">
  250. <xsl:param name="currentpos" select="1"/>
  251. <xsl:param name="startpos" select="1"></xsl:param>
  252. <xsl:if test="$startpos &gt; $currentpos">
  253. <xsl:variable name="colspan">
  254. <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"/>
  255. </xsl:variable>
  256. <xsl:text>\cell </xsl:text>
  257. <xsl:if test="not($colspan='') and ($startpos &gt; ($currentpos + $colspan))">
  258. <xsl:call-template name="emit-empty-cell">
  259. <xsl:with-param name="startpos" select="$startpos"/>
  260. <xsl:with-param name="currentpos" select="$currentpos + $colspan"/>
  261. </xsl:call-template>
  262. </xsl:if>
  263. </xsl:if>
  264. </xsl:template>
  265. <xsl:template match="*[contains(@class,' topic/entry ')]" mode="emit-cell-style">
  266. <xsl:param name="copy-style" select="'false'"/>
  267. <xsl:param name="left-border" select="0"/>
  268. <xsl:param name="currentpos" select="1"/>
  269. <xsl:variable name="col-max-num">
  270. <xsl:call-template name="count-colmax"/>
  271. </xsl:variable>
  272. <xsl:variable name="valign">
  273. <xsl:choose>
  274. <xsl:when test="@valign and not(@valign='')">
  275. <xsl:choose>
  276. <xsl:when test="@valign='top'">\clvertalt</xsl:when>
  277. <xsl:when test="@valign='middle'">\clvertalc</xsl:when>
  278. <xsl:when test="@valign='bottom'">\clvertalb</xsl:when>
  279. </xsl:choose>
  280. </xsl:when>
  281. <xsl:otherwise>
  282. <xsl:choose>
  283. <xsl:when test="../@valign and not(../@valign='')">
  284. <xsl:choose>
  285. <xsl:when test="@valign='top'">\clvertalt</xsl:when>
  286. <xsl:when test="@valign='middle'">\clvertalc</xsl:when>
  287. <xsl:when test="@valign='bottom'">\clvertalb</xsl:when>
  288. </xsl:choose>
  289. </xsl:when>
  290. <xsl:otherwise><xsl:value-of select="table-cell-default-valign"/></xsl:otherwise>
  291. </xsl:choose>
  292. </xsl:otherwise>
  293. </xsl:choose>
  294. </xsl:variable>
  295. <xsl:variable name="colspan-num">
  296. <xsl:call-template name="find-colspan"/>
  297. </xsl:variable>
  298. <xsl:variable name="startpos"><xsl:call-template name="find-entry-start-position"/></xsl:variable>
  299. <xsl:variable name="endpos">
  300. <xsl:call-template name="find-entry-end-position">
  301. <xsl:with-param name="startposition" select="$startpos"/>
  302. </xsl:call-template>
  303. </xsl:variable>
  304. <xsl:variable name="nextpos">
  305. <xsl:choose>
  306. <xsl:when test="$endpos &gt; $startpos">
  307. <xsl:value-of select="$endpos + 1"/>
  308. </xsl:when>
  309. <xsl:otherwise>
  310. <xsl:value-of select="$startpos + 1"/>
  311. </xsl:otherwise>
  312. </xsl:choose>
  313. </xsl:variable>
  314. <xsl:variable name="totalwidth">
  315. <xsl:choose>
  316. <xsl:when test="../../../*[contains(@class,' topic/colspec ')]">
  317. <xsl:apply-templates select="../../../*[contains(@class,' topic/colspec ')][1]" mode="count-rowwidth"/>
  318. </xsl:when>
  319. <xsl:otherwise><xsl:value-of select="$col-max-num"/></xsl:otherwise>
  320. </xsl:choose>
  321. </xsl:variable>
  322. <xsl:variable name="thiswidth">
  323. <xsl:choose>
  324. <xsl:when test="../../../*[contains(@class,' topic/colspec ')]">
  325. <xsl:apply-templates select="../../../*[contains(@class,' topic/colspec ')][number($startpos)]" mode="count-colwidth">
  326. <xsl:with-param name="colnum" select="$colspan-num"/>
  327. </xsl:apply-templates>
  328. </xsl:when>
  329. <xsl:otherwise>1</xsl:otherwise>
  330. </xsl:choose>
  331. </xsl:variable>
  332. <xsl:variable name="thiswidth-twips">
  333. <!--xsl:choose>
  334. <xsl:when test="following-sibling::*[contains(@class,' topic/entry ')]"-->
  335. <xsl:value-of select="round(($thiswidth div $totalwidth) * $table-row-width)"/>
  336. <!--/xsl:when>
  337. <xsl:otherwise>
  338. <xsl:value-of select="($table-row-width) - ($left-border)"/>
  339. </xsl:otherwise>
  340. </xsl:choose-->
  341. </xsl:variable>
  342. <xsl:variable name="left-to-right">
  343. <xsl:choose>
  344. <xsl:when test="../../../*[contains(@class,' topic/colspec ')]">
  345. <xsl:apply-templates select="../../../*[contains(@class,' topic/colspec ')][number($currentpos)]" mode="count-colwidth">
  346. <xsl:with-param name="colnum" select="$colspan-num + $startpos - $currentpos"/>
  347. </xsl:apply-templates>
  348. </xsl:when>
  349. <xsl:otherwise><xsl:value-of select="$thiswidth"/></xsl:otherwise>
  350. </xsl:choose>
  351. </xsl:variable>
  352. <xsl:variable name="right-border">
  353. <xsl:value-of select="$left-border + round(($left-to-right div $totalwidth) * $table-row-width)"/>
  354. </xsl:variable>
  355. <xsl:if test="$startpos &gt; $currentpos">
  356. <!-- the start position of the entry is after current position
  357. we need to emit merged entry style -->
  358. <xsl:call-template name="emit-vmerged-style">
  359. <xsl:with-param name="left-border" select="$left-border"/>
  360. <xsl:with-param name="startpos" select="$startpos"/>
  361. <xsl:with-param name="currentpos" select="$currentpos"/>
  362. </xsl:call-template>
  363. </xsl:if>
  364. <xsl:if test="@morerows and $copy-style='false'"><xsl:text>\clvmgf</xsl:text></xsl:if>
  365. <xsl:value-of select="$valign"/><xsl:text>\clbrdrt\brdrs\brdrw10 \clbrdrl\brdrs\brdrw10 \clbrdrb\brdrs\brdrw10 \clbrdrr\brdrs\brdrw10 \clftsWidth3\clwWidth</xsl:text><xsl:value-of select="$thiswidth-twips"/>
  366. <xsl:text>\cellx</xsl:text><xsl:value-of select="$right-border"/><xsl:text> </xsl:text>
  367. <xsl:if test="following-sibling::*[contains(@class,' topic/entry ')] and $copy-style='false'">
  368. <xsl:apply-templates select="following-sibling::*[contains(@class,' topic/entry ')][1]" mode="emit-cell-style">
  369. <xsl:with-param name="left-border" select="$right-border"/>
  370. <xsl:with-param name="currentpos" select="$nextpos"/>
  371. </xsl:apply-templates>
  372. </xsl:if>
  373. <xsl:if test="not(following-sibling::*[contains(@class,' topic/entry ')]) and not($nextpos &gt; $col-max-num)">
  374. <!-- if this is the last entry in current row and next position is not greater than the number of columns in a row-->
  375. <xsl:call-template name="emit-vmerged-style">
  376. <xsl:with-param name="left-border" select="$right-border"/>
  377. <xsl:with-param name="startpos" select="$col-max-num + 1"/> <!-- make sure the remaining columns will be generated -->
  378. <xsl:with-param name="currentpos" select="$nextpos"/>
  379. </xsl:call-template>
  380. </xsl:if>
  381. </xsl:template>
  382. <xsl:template name="emit-vmerged-style">
  383. <xsl:param name="left-border" select="0"/>
  384. <xsl:param name="startpos" select="1"/>
  385. <xsl:param name="currentpos" select="1"/>
  386. <xsl:if test="$startpos &gt; $currentpos">
  387. <xsl:variable name="colspan">
  388. <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"/>
  389. </xsl:variable>
  390. <xsl:variable name="col-max-num">
  391. <xsl:call-template name="count-colmax"/>
  392. </xsl:variable>
  393. <xsl:variable name="totalwidth">
  394. <xsl:choose>
  395. <xsl:when test="../../../*[contains(@class,' topic/colspec ')]">
  396. <xsl:apply-templates select="../../../*[contains(@class,' topic/colspec ')][1]" mode="count-rowwidth"/>
  397. </xsl:when>
  398. <xsl:otherwise><xsl:value-of select="$col-max-num"/></xsl:otherwise>
  399. </xsl:choose>
  400. </xsl:variable>
  401. <xsl:variable name="thiswidth">
  402. <xsl:choose>
  403. <xsl:when test="../../../*[contains(@class,' topic/colspec ')]">
  404. <xsl:apply-templates select="../../../*[contains(@class,' topic/colspec ')][number($currentpos)]" mode="count-colwidth">
  405. <xsl:with-param name="colnum" select="$colspan"/>
  406. </xsl:apply-templates></xsl:when>
  407. <xsl:otherwise>1</xsl:otherwise>
  408. </xsl:choose>
  409. </xsl:variable>
  410. <xsl:variable name="thiswidth-twips">
  411. <xsl:value-of select="round(($thiswidth div $totalwidth) * $table-row-width)"/>
  412. </xsl:variable>
  413. <xsl:text>\clvmrg</xsl:text>
  414. <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="emit-cell-style">
  415. <xsl:with-param name="left-border" select="$left-border"/>
  416. <xsl:with-param name="copy-style" select="'true'"/>
  417. <xsl:with-param name="currentpos" select="$currentpos"/>
  418. </xsl:apply-templates>
  419. <xsl:if test="not($colspan='') and ($startpos &gt; ($currentpos + $colspan))">
  420. <xsl:call-template name="emit-vmerged-style">
  421. <xsl:with-param name="left-border" select="$left-border + $thiswidth-twips"/>
  422. <xsl:with-param name="startpos" select="$startpos"/>
  423. <xsl:with-param name="currentpos" select="$currentpos + $colspan"/>
  424. </xsl:call-template>
  425. </xsl:if>
  426. </xsl:if>
  427. </xsl:template>
  428. <xsl:template match="*[contains(@class,' topic/entry ')]" mode="find-colspan">
  429. <xsl:call-template name="find-colspan"/>
  430. </xsl:template>
  431. <!--xsl:template name="emit-merged-cstyle">
  432. <xsl:param name="startpos" select="1"/>
  433. <xsl:param name="num" select="0"/>
  434. <xsl:if test="$num &gt; 0">
  435. <xsl:text>\clmrg</xsl:text><xsl:apply-templates select="../../../*[contains(@class,' topic/colspec ')][number($startpos)]" mode="emit-cell-style"></xsl:apply-templates>
  436. <xsl:call-template name="emit-merged-cstyle">
  437. <xsl:with-param name="startpos" select="$startpos + 1"/>
  438. <xsl:with-param name="num" select="$num - 1"/>
  439. </xsl:call-template>
  440. </xsl:if>
  441. </xsl:template>
  442. <xsl:template match="*[contains(@class,' topic/colspec ')]" mode="emit-cell-style">
  443. <xsl:param name="left-border" select="0"/>
  444. <xsl:param name="colnum" select="1"/>
  445. <xsl:param name="valign" select="$table-cell-default-valign"/>
  446. <xsl:variable name="totalwidth">
  447. <xsl:apply-templates select="../*[contains(@class,' topic/colspec ')][1]" mode="count-rowwidth"/>
  448. </xsl:variable>
  449. <xsl:variable name="thiswidth">
  450. <xsl:call-template name="count-colwidth">
  451. <xsl:with-param name="colnum" select="$colnum"/>
  452. </xsl:call-template>
  453. </xsl:variable>
  454. <xsl:variable name="thiswidth-twips">
  455. <xsl:value-of select="($thiswidth div $totalwidth) * $table-row-width"/>
  456. </xsl:variable>
  457. <xsl:value-of select="$valign"/><xsl:text>\clbrdrt\brdrs\brdrw10 \clbrdrl\brdrs\brdrw10 \clbrdrb\brdrs\brdrw10 \clbrdrr\brdrs\brdrw10 \clftsWidth3\clwWidth</xsl:text><xsl:value-of select="round($thiswidth-twips)"/>
  458. <xsl:text>\cellx </xsl:text><xsl:value-of select="$left-border + "/>
  459. </xsl:template-->
  460. <xsl:template match="*[contains(@class,' topic/colspec ')]" mode="count-colwidth">
  461. <xsl:param name="colnum" select="1" as="xs:double"/>
  462. <xsl:param name="span-width" select="0" as="xs:double"></xsl:param>
  463. <xsl:variable name="width" as="xs:double">
  464. <xsl:choose>
  465. <xsl:when test="not(@colwidth) or @colwidth='*'">1</xsl:when>
  466. <xsl:when test="contains(@colwidth,'*')"><xsl:value-of select="substring-before(@colwidth,'*')"/></xsl:when>
  467. <xsl:when test="contains(@colwidth,'pt')"><xsl:value-of select="substring-before(@colwidth,'pt')"/></xsl:when>
  468. <xsl:when test="contains(@colwidth,'cm')"><xsl:value-of select="substring-before(@colwidth,'cm')"/></xsl:when>
  469. <xsl:when test="contains(@colwidth,'in')"><xsl:value-of select="substring-before(@colwidth,'in')"/></xsl:when>
  470. <xsl:when test="contains(@colwidth,'mm')"><xsl:value-of select="substring-before(@colwidth,'mm')"/></xsl:when>
  471. <xsl:otherwise>1</xsl:otherwise>
  472. </xsl:choose>
  473. </xsl:variable>
  474. <xsl:choose>
  475. <xsl:when test="$colnum &gt; 1">
  476. <xsl:apply-templates select="following-sibling::*[1]" mode="count-colwidth">
  477. <xsl:with-param name="colnum" select="$colnum - 1"/>
  478. <xsl:with-param name="span-width" select="$span-width + $width"/>
  479. </xsl:apply-templates>
  480. </xsl:when>
  481. <xsl:otherwise><xsl:value-of select="$span-width + $width"/></xsl:otherwise>
  482. </xsl:choose>
  483. </xsl:template>
  484. <!--xsl:template name="count-colwidth">
  485. <xsl:param name="colnum" select="1"/>
  486. <xsl:param name="span-width" select="0"/>
  487. <xsl:variable name="width">
  488. <xsl:choose>
  489. <xsl:when test="@colwidth and not(@colwidth='')">
  490. <xsl:value-of select="substring-before(@colwidth,'*')"/>
  491. </xsl:when>
  492. <xsl:otherwise>1</xsl:otherwise>
  493. </xsl:choose>
  494. </xsl:variable>
  495. <xsl:choose>
  496. <xsl:when test="$colnum &gt; 1">
  497. <xsl:call-template name="count-colwidth">
  498. <xsl:with-param name="colnum" select="$colnum - 1"/>
  499. <xsl:with-param name="span-width" select="$span-width + $width"/>
  500. </xsl:call-template>
  501. </xsl:when>
  502. <xsl:otherwise><xsl:value-of select="$span-width + $width"/></xsl:otherwise>
  503. </xsl:choose>
  504. </xsl:template-->
  505. <!-- Simple Table -->
  506. <xsl:template match="*[contains(@class,' topic/simpletable ')]">
  507. <xsl:call-template name="gen-id"/><xsl:call-template name="dotable"/>
  508. </xsl:template>
  509. <xsl:template match="*[contains(@class,' topic/simpletable ')]/*[contains(@class,' topic/title ')]">
  510. <xsl:variable name="ancestorlang">
  511. <xsl:call-template name="getLowerCaseLang"/>
  512. </xsl:variable>
  513. <xsl:variable name="tbl-count-actual" select="count(preceding::*[contains(@class,' topic/table ')
  514. or contains(@class,' topic/simpletable ')]/*[contains(@class,' topic/title ')])+1"/>
  515. <xsl:call-template name="gen-id"/>\pard \plain\s9 \qc\f4\fs24\b <xsl:choose><!-- Hungarian: "1.Table " --><xsl:when test="( (string-length($ancestorlang)=5 and contains($ancestorlang,'hu-hu')) or (string-length($ancestorlang)=2 and contains($ancestorlang,'hu')) )"><xsl:value-of select="$tbl-count-actual"/><xsl:text>. </xsl:text><xsl:call-template name="getStringRTF"><xsl:with-param name="stringName" select="'Table'"/></xsl:call-template><xsl:text> </xsl:text></xsl:when><xsl:otherwise><xsl:call-template name="getStringRTF"><xsl:with-param name="stringName" select="'Table'"/></xsl:call-template><xsl:text> </xsl:text><xsl:value-of select="$tbl-count-actual"/><xsl:text>. </xsl:text></xsl:otherwise></xsl:choose><xsl:value-of select="."/>\par \plain\s0 \qj\f2\fs24
  516. </xsl:template>
  517. <xsl:template match="*[contains(@class,' topic/sthead ')]">
  518. <xsl:call-template name="gen-id"/>
  519. <xsl:text>\trowd \trgaph108\trleft-108\trbrdrt\brdrs\brdrw10 \trhdr </xsl:text>
  520. <xsl:text>\trbrdrl\brdrs\brdrw10 \trbrdrb\brdrs\brdrw10 \trbrdrr\brdrs\brdrw10
  521. \trbrdrh\brdrs\brdrw10 \trbrdrv\brdrs\brdrw10
  522. \trftsWidth1\trautofit1\trpaddl108\trpaddr108\trpaddfl3\trpaddfr3</xsl:text>
  523. <xsl:apply-templates mode="emit-cell-style"/>
  524. <xsl:text>\plain \s7\f4\fs24\b \qc</xsl:text>
  525. \li0\fi0\ri0\nowidctlpar\intbl\aspalpha\aspnum\faauto\adjustright\rin0\lin0
  526. <xsl:text>{</xsl:text><xsl:apply-templates/><xsl:text>}\row</xsl:text>
  527. </xsl:template>
  528. <xsl:template match="*[contains(@class,' topic/strow ')]">
  529. <xsl:call-template name="gen-id"/>
  530. <xsl:text>\trowd \trgaph108\trleft-108\trbrdrt\brdrs\brdrw10 </xsl:text>
  531. <xsl:text>\trbrdrl\brdrs\brdrw10 \trbrdrb\brdrs\brdrw10 \trbrdrr\brdrs\brdrw10
  532. \trbrdrh\brdrs\brdrw10 \trbrdrv\brdrs\brdrw10
  533. \trftsWidth1\trautofit1\trpaddl108\trpaddr108\trpaddfl3\trpaddfr3</xsl:text>
  534. <xsl:apply-templates mode="emit-cell-style"/>
  535. <xsl:text>\plain \s0\f4\fs24 </xsl:text><xsl:value-of select="$table-row-default-align"/>
  536. \li0\fi0\ri0\nowidctlpar\intbl\aspalpha\aspnum\faauto\adjustright\rin0\lin0
  537. <xsl:text>{</xsl:text><xsl:apply-templates/><xsl:text>}\row</xsl:text>
  538. </xsl:template>
  539. <xsl:template match="*[contains(@class,' topic/stentry ')]" mode="emit-cell-style">
  540. <xsl:param name="valign" select="$table-cell-default-valign"/>
  541. <xsl:variable name="totalcols" select="count(../*[contains(@class,' topic/stentry ')])">
  542. <!--xsl:apply-templates select="../*[contains(@class,' topic/stentry ')][1]" mode="count-rowwidth"/-->
  543. </xsl:variable>
  544. <xsl:variable name="thiswidth-twips">
  545. <xsl:value-of select="$table-row-width div $totalcols"/>
  546. </xsl:variable>
  547. <xsl:value-of select="$valign"/><xsl:text>\clbrdrt\brdrs\brdrw10 \clbrdrl\brdrs\brdrw10 \clbrdrb\brdrs\brdrw10 \clbrdrr\brdrs\brdrw10 \clftsWidth3\clwWidth</xsl:text><xsl:value-of select="round($thiswidth-twips)"/>
  548. <xsl:text>\cellx </xsl:text>
  549. </xsl:template>
  550. <xsl:template match="*[contains(@class,' topic/stentry ')]">
  551. <xsl:apply-templates/><xsl:text>\cell </xsl:text>
  552. </xsl:template>
  553. <xsl:template match="*[contains(@class,' topic/stentry ')]" mode="count-rowwidth">
  554. <xsl:param name="totalcols">0</xsl:param> <!-- Total counted columns so far -->
  555. <xsl:choose>
  556. <xsl:when test="following-sibling::*[contains(@class,' topic/stentry ')]">
  557. <xsl:apply-templates select="following-sibling::*[contains(@class,' topic/stentry ')][1]" mode="count-rowwidth">
  558. <xsl:with-param name="totalwidth" select="$totalcols + 1"/>
  559. </xsl:apply-templates>
  560. </xsl:when>
  561. <xsl:otherwise><xsl:value-of select="$totalcols + 1"/></xsl:otherwise>
  562. </xsl:choose>
  563. </xsl:template>
  564. </xsl:stylesheet>