tables.xsl 55 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159
  1. <!--
  2. This file is part of the DITA Open Toolkit project.
  3. Copyright 2006 IBM Corporation
  4. See the accompanying LICENSE file for applicable license.
  5. -->
  6. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  7. xmlns:opentopic-func="http://www.idiominc.com/opentopic/exsl/function"
  8. xmlns:fo="http://www.w3.org/1999/XSL/Format"
  9. xmlns:xs="http://www.w3.org/2001/XMLSchema"
  10. xmlns:dita2xslfo="http://dita-ot.sourceforge.net/ns/200910/dita2xslfo"
  11. xmlns:dita-ot="http://dita-ot.sourceforge.net/ns/201007/dita-ot"
  12. exclude-result-prefixes="opentopic-func xs dita2xslfo dita-ot"
  13. version="2.0">
  14. <xsl:variable name="tableAttrs" select="'../../cfg/fo/attrs/tables-attr.xsl'"/>
  15. <xsl:param name="tableSpecNonProportional" select="'false'"/>
  16. <!-- XML Exchange Table Model Document Type Definition default is all -->
  17. <xsl:variable name="table.frame-default" select="'all'"/>
  18. <!-- XML Exchange Table Model Document Type Definition default is 1 -->
  19. <xsl:variable name="table.rowsep-default" select="'0'"/>
  20. <!-- XML Exchange Table Model Document Type Definition default is 1 -->
  21. <xsl:variable name="table.colsep-default" select="'0'"/>
  22. <!--Definition list-->
  23. <xsl:template match="*[contains(@class,' topic/dl ')][empty(*[contains(@class,' topic/dlentry ')])]" priority="10"/>
  24. <xsl:template match="*[contains(@class, ' topic/dl ')]">
  25. <xsl:apply-templates select="*[contains(@class,' ditaot-d/ditaval-startprop ')]" mode="outofline"/>
  26. <fo:table xsl:use-attribute-sets="dl">
  27. <xsl:call-template name="commonattributes"/>
  28. <xsl:apply-templates select="*[contains(@class, ' topic/dlhead ')]"/>
  29. <fo:table-body xsl:use-attribute-sets="dl__body">
  30. <xsl:choose>
  31. <xsl:when test="contains(@otherprops,'sortable')">
  32. <xsl:apply-templates select="*[contains(@class, ' topic/dlentry ')]">
  33. <xsl:sort select="opentopic-func:getSortString(normalize-space( opentopic-func:fetchValueableText(*[contains(@class, ' topic/dt ')]) ))" lang="{$locale}"/>
  34. </xsl:apply-templates>
  35. </xsl:when>
  36. <xsl:otherwise>
  37. <xsl:apply-templates select="*[contains(@class, ' topic/dlentry ')]"/>
  38. </xsl:otherwise>
  39. </xsl:choose>
  40. </fo:table-body>
  41. </fo:table>
  42. <xsl:apply-templates select="*[contains(@class,' ditaot-d/ditaval-endprop ')]" mode="outofline"/>
  43. </xsl:template>
  44. <xsl:template match="*[contains(@class,' topic/dlhead ')]
  45. [empty(*[contains(@class,' topic/dthd ')] | *[contains(@class,' topic/ddhd ')])]" priority="10"/>
  46. <xsl:template match="*[contains(@class, ' topic/dl ')]/*[contains(@class, ' topic/dlhead ')]">
  47. <fo:table-header xsl:use-attribute-sets="dl.dlhead">
  48. <xsl:call-template name="commonattributes"/>
  49. <fo:table-row xsl:use-attribute-sets="dl.dlhead__row">
  50. <xsl:apply-templates/>
  51. </fo:table-row>
  52. </fo:table-header>
  53. </xsl:template>
  54. <xsl:template match="*[contains(@class, ' topic/dlhead ')]/*[contains(@class, ' topic/dthd ')]">
  55. <fo:table-cell xsl:use-attribute-sets="dlhead.dthd__cell">
  56. <xsl:call-template name="commonattributes"/>
  57. <fo:block xsl:use-attribute-sets="dlhead.dthd__content">
  58. <xsl:apply-templates select="../*[contains(@class,' ditaot-d/ditaval-startprop ')]" mode="outofline"/>
  59. <xsl:apply-templates/>
  60. </fo:block>
  61. </fo:table-cell>
  62. </xsl:template>
  63. <xsl:template match="*[contains(@class, ' topic/dlhead ')]/*[contains(@class, ' topic/ddhd ')]">
  64. <fo:table-cell xsl:use-attribute-sets="dlhead.ddhd__cell">
  65. <xsl:call-template name="commonattributes"/>
  66. <fo:block xsl:use-attribute-sets="dlhead.ddhd__content">
  67. <xsl:apply-templates/>
  68. <xsl:apply-templates select="../*[contains(@class,' ditaot-d/ditaval-endprop ')]" mode="outofline"/>
  69. </fo:block>
  70. </fo:table-cell>
  71. </xsl:template>
  72. <xsl:template match="*[contains(@class, ' topic/dlentry ')]">
  73. <fo:table-row xsl:use-attribute-sets="dlentry">
  74. <xsl:call-template name="commonattributes"/>
  75. <fo:table-cell xsl:use-attribute-sets="dlentry.dt">
  76. <xsl:apply-templates select="*[contains(@class, ' topic/dt ')]"/>
  77. <xsl:if test="empty(*[contains(@class, ' topic/dt ')])"><fo:block/></xsl:if>
  78. </fo:table-cell>
  79. <fo:table-cell xsl:use-attribute-sets="dlentry.dd">
  80. <xsl:apply-templates select="*[contains(@class, ' topic/dd ')]"/>
  81. <xsl:if test="empty(*[contains(@class, ' topic/dd ')])"><fo:block/></xsl:if>
  82. </fo:table-cell>
  83. </fo:table-row>
  84. </xsl:template>
  85. <xsl:template match="*[contains(@class, ' topic/dt ')]">
  86. <fo:block xsl:use-attribute-sets="dlentry.dt__content">
  87. <xsl:if test="not(preceding-sibling::*[contains(@class,' topic/dt ')])">
  88. <xsl:apply-templates select="../*[contains(@class,' ditaot-d/ditaval-startprop ')]" mode="outofline"/>
  89. </xsl:if>
  90. <xsl:apply-templates select="." mode="inlineTextOptionalKeyref"/>
  91. </fo:block>
  92. </xsl:template>
  93. <xsl:template match="*[contains(@class, ' topic/dd ')]">
  94. <fo:block xsl:use-attribute-sets="dlentry.dd__content">
  95. <xsl:call-template name="commonattributes"/>
  96. <xsl:apply-templates/>
  97. <xsl:if test="not(following-sibling::*[contains(@class,' topic/dd ')])">
  98. <xsl:apply-templates select="../*[contains(@class,' ditaot-d/ditaval-endprop ')]" mode="outofline"/>
  99. </xsl:if>
  100. </fo:block>
  101. </xsl:template>
  102. <!-- Map processing -->
  103. <xsl:template match="*[contains(@class, ' map/map ')]/*[contains(@class, ' map/reltable ')]">
  104. <fo:table-and-caption>
  105. <fo:table-caption>
  106. <fo:block xsl:use-attribute-sets="reltable__title">
  107. <xsl:value-of select="@title"/>
  108. </fo:block>
  109. </fo:table-caption>
  110. <fo:table xsl:use-attribute-sets="reltable">
  111. <xsl:call-template name="topicrefAttsNoToc"/>
  112. <xsl:call-template name="selectAtts"/>
  113. <xsl:call-template name="globalAtts"/>
  114. <xsl:apply-templates select="relheader"/>
  115. <fo:table-body>
  116. <xsl:apply-templates select="relrow"/>
  117. </fo:table-body>
  118. </fo:table>
  119. </fo:table-and-caption>
  120. </xsl:template>
  121. <xsl:template match="*[contains(@class, ' map/relheader ')]">
  122. <fo:table-header xsl:use-attribute-sets="relheader">
  123. <xsl:call-template name="globalAtts"/>
  124. <xsl:apply-templates/>
  125. </fo:table-header>
  126. </xsl:template>
  127. <xsl:template match="*[contains(@class, ' map/relcolspec ')]">
  128. <fo:table-cell xsl:use-attribute-sets="relcolspec">
  129. <xsl:apply-templates/>
  130. </fo:table-cell>
  131. </xsl:template>
  132. <xsl:template match="*[contains(@class, ' map/relrow ')]">
  133. <fo:table-row xsl:use-attribute-sets="relrow">
  134. <xsl:call-template name="globalAtts"/>
  135. <xsl:apply-templates/>
  136. </fo:table-row>
  137. </xsl:template>
  138. <xsl:template match="*[contains(@class, ' map/relcell ')]">
  139. <fo:table-cell xsl:use-attribute-sets="relcell">
  140. <xsl:call-template name="globalAtts"/>
  141. <xsl:call-template name="topicrefAtts"/>
  142. <xsl:apply-templates/>
  143. </fo:table-cell>
  144. </xsl:template>
  145. <!-- DITA-OT flagging preprocess may add flag info directly into simpletable; account for that and
  146. skip to next row. Currently known to match ditaval-startprop when flagging used on simpletable
  147. as well as suitesol:changebar-start when revision bar used on sthead or stentry. -->
  148. <xsl:template match="*" mode="count-max-simpletable-cells" as="xs:integer">
  149. <xsl:param name="maxcount" select="0" as="xs:integer"/>
  150. <xsl:apply-templates select="following-sibling::*[1]" mode="count-max-simpletable-cells">
  151. <xsl:with-param name="maxcount" select="$maxcount"/>
  152. </xsl:apply-templates>
  153. </xsl:template>
  154. <!-- Count the max number of cells in any row of a simpletable -->
  155. <xsl:template match="*[contains(@class, ' topic/sthead ')] | *[contains(@class, ' topic/strow ')]" mode="count-max-simpletable-cells" as="xs:integer">
  156. <xsl:param name="maxcount" select="0" as="xs:integer"/>
  157. <xsl:variable name="newmaxcount" as="xs:integer">
  158. <xsl:variable name="row-cell-count" select="count(*[contains(@class, ' topic/stentry ')])" as="xs:integer"/>
  159. <xsl:sequence select="max(($row-cell-count, $maxcount))"/>
  160. </xsl:variable>
  161. <xsl:choose>
  162. <xsl:when test="not(following-sibling::*[contains(@class, ' topic/strow ')])">
  163. <xsl:sequence select="$newmaxcount"/>
  164. </xsl:when>
  165. <xsl:otherwise>
  166. <xsl:apply-templates select="following-sibling::*[contains(@class, ' topic/strow ')][1]" mode="count-max-simpletable-cells">
  167. <xsl:with-param name="maxcount" select="$newmaxcount"/>
  168. </xsl:apply-templates>
  169. </xsl:otherwise>
  170. </xsl:choose>
  171. </xsl:template>
  172. <!-- If there are more cells in any row than there are relcolwidth values,
  173. add 1* for each missing cell, otherwise the FO processor may crash. -->
  174. <xsl:template match="*" mode="fix-relcolwidth">
  175. <xsl:param name="number-cells" as="xs:integer"/>
  176. <xsl:variable name="relcolwidth-tokens" select="tokenize(normalize-space(@relcolwidth), '\s+')" as="xs:string*"/>
  177. <xsl:variable name="number-relwidths" select="count($relcolwidth-tokens)" as="xs:integer"/>
  178. <xsl:variable name="result" as="xs:string*">
  179. <xsl:sequence select="$relcolwidth-tokens"/>
  180. <xsl:for-each select="1 to ($number-cells - $number-relwidths)">1*</xsl:for-each>
  181. </xsl:variable>
  182. <xsl:value-of select="$result" separator=" "/>
  183. </xsl:template>
  184. <xsl:function name="dita-ot:get-length">
  185. <xsl:param name="width" as="xs:string"/>
  186. <xsl:value-of select="normalize-space(translate($width,
  187. '+-0123456789.abcdefghijklmnopqrstuvwxyz%',
  188. '+-0123456789.'))"/>
  189. </xsl:function>
  190. <xsl:function name="dita-ot:get-entry-end-position" as="xs:integer">
  191. <xsl:param name="thisentry" as="element()"/>
  192. <xsl:choose>
  193. <xsl:when test="$thisentry/@dita-ot:x and $thisentry/@dita-ot:morecols">
  194. <xsl:sequence select="xs:integer($thisentry/@dita-ot:x) + xs:integer($thisentry/@dita-ot:morecols)"/>
  195. </xsl:when>
  196. <xsl:when test="$thisentry/@dita-ot:x">
  197. <xsl:sequence select="xs:integer($thisentry/@dita-ot:x)"/>
  198. </xsl:when>
  199. <xsl:otherwise>0</xsl:otherwise>
  200. </xsl:choose>
  201. </xsl:function>
  202. <xsl:function name="dita-ot:get-unit">
  203. <xsl:param name="width" as="xs:string"/>
  204. <xsl:value-of select="normalize-space(translate($width,
  205. 'abcdefghijklmnopqrstuvwxyz%+-0123456789.',
  206. 'abcdefghijklmnopqrstuvwxyz%'))"/>
  207. </xsl:function>
  208. <xsl:template name="univAttrs">
  209. <xsl:apply-templates select="@platform | @product | @audience | @otherprops | @importance | @rev | @status"/>
  210. </xsl:template>
  211. <xsl:function name="opentopic-func:getSortString" as="xs:string">
  212. <xsl:param name="text" as="xs:string"/>
  213. <xsl:choose>
  214. <xsl:when test="contains($text, '[') and contains($text, ']')">
  215. <xsl:value-of select="substring-before(substring-after($text, '['),']')"/>
  216. </xsl:when>
  217. <xsl:otherwise>
  218. <xsl:value-of select="$text"/>
  219. </xsl:otherwise>
  220. </xsl:choose>
  221. </xsl:function>
  222. <xsl:function name="opentopic-func:fetchValueableText" as="xs:string">
  223. <xsl:param name="node" as="element()*"/>
  224. <xsl:value-of>
  225. <xsl:apply-templates select="$node" mode="insert-text"/>
  226. </xsl:value-of>
  227. </xsl:function>
  228. <xsl:template match="*" mode="insert-text">
  229. <xsl:apply-templates mode="insert-text"/>
  230. </xsl:template>
  231. <xsl:template match="*[contains(@class, ' topic/indexterm ')]" mode="insert-text"/>
  232. <xsl:template match="text()[contains(., '[') and contains(., ']')][ancestor::*[contains(@class, ' topic/dl ')][contains(@otherprops,'sortable')]]" priority="10">
  233. <xsl:value-of select="substring-before(.,'[')"/>
  234. </xsl:template>
  235. <xsl:template match="*[contains(@class, ' topic/table ')]">
  236. <!-- FIXME, empty value -->
  237. <xsl:variable name="scale" as="xs:string?">
  238. <xsl:call-template name="getTableScale"/>
  239. </xsl:variable>
  240. <fo:block-container xsl:use-attribute-sets="table__container">
  241. <fo:block xsl:use-attribute-sets="table">
  242. <xsl:call-template name="commonattributes"/>
  243. <xsl:if test="not(@id)">
  244. <xsl:attribute name="id">
  245. <xsl:call-template name="get-id"/>
  246. </xsl:attribute>
  247. </xsl:if>
  248. <xsl:if test="exists($scale)">
  249. <xsl:attribute name="font-size" select="concat($scale, '%')"/>
  250. </xsl:if>
  251. <xsl:apply-templates select="*[contains(@class,' ditaot-d/ditaval-startprop ')]" mode="outofline"/>
  252. <xsl:apply-templates/>
  253. <xsl:apply-templates select="*[contains(@class,' ditaot-d/ditaval-endprop ')]" mode="outofline"/>
  254. </fo:block>
  255. </fo:block-container>
  256. </xsl:template>
  257. <xsl:template match="*[contains(@class, ' topic/table ')]/*[contains(@class, ' topic/title ')]">
  258. <fo:block xsl:use-attribute-sets="table.title">
  259. <xsl:call-template name="commonattributes"/>
  260. <xsl:apply-templates select="." mode="customTitleAnchor"/>
  261. <xsl:call-template name="getVariable">
  262. <xsl:with-param name="id" select="'Table.title'"/>
  263. <xsl:with-param name="params">
  264. <number>
  265. <xsl:apply-templates select="." mode="table.title-number"/>
  266. </number>
  267. <title>
  268. <xsl:apply-templates/>
  269. </title>
  270. </xsl:with-param>
  271. </xsl:call-template>
  272. </fo:block>
  273. </xsl:template>
  274. <xsl:template match="*[contains(@class, ' topic/table ')]/*[contains(@class, ' topic/title ')]" mode="table.title-number">
  275. <xsl:value-of select="count(key('enumerableByClass', 'topic/table')[. &lt;&lt; current()][dita-ot:notExcludedByDraftElement(.)])"/>
  276. </xsl:template>
  277. <xsl:template match="*[contains(@class, ' topic/tgroup ')]" name="tgroup">
  278. <xsl:if test="not(@cols)">
  279. <xsl:call-template name="output-message">
  280. <xsl:with-param name="id" select="'PDFX006E'"/>
  281. </xsl:call-template>
  282. </xsl:if>
  283. <xsl:variable name="scale" as="xs:string?">
  284. <xsl:call-template name="getTableScale"/>
  285. </xsl:variable>
  286. <xsl:variable name="table" as="element()">
  287. <fo:table xsl:use-attribute-sets="table.tgroup">
  288. <xsl:call-template name="commonattributes"/>
  289. <xsl:call-template name="displayAtts">
  290. <xsl:with-param name="element" select=".."/>
  291. </xsl:call-template>
  292. <xsl:if test="(parent::*/@pgwide) = '1'">
  293. <xsl:attribute name="start-indent">0</xsl:attribute>
  294. <xsl:attribute name="end-indent">0</xsl:attribute>
  295. <xsl:attribute name="width">auto</xsl:attribute>
  296. </xsl:if>
  297. <xsl:apply-templates/>
  298. </fo:table>
  299. </xsl:variable>
  300. <xsl:choose>
  301. <xsl:when test="exists($scale)">
  302. <xsl:apply-templates select="$table" mode="setTableEntriesScale"/>
  303. </xsl:when>
  304. <xsl:otherwise>
  305. <xsl:copy-of select="$table"/>
  306. </xsl:otherwise>
  307. </xsl:choose>
  308. </xsl:template>
  309. <xsl:template match="*[contains(@class, ' topic/tgroup ')][empty(*[contains(@class, ' topic/tbody ')]//*[contains(@class, ' topic/row ')])]" priority="10"/>
  310. <xsl:template match="*[contains(@class, ' topic/colspec ')]">
  311. <fo:table-column>
  312. <xsl:attribute name="column-number" select="@colnum"/>
  313. <xsl:if test="normalize-space(@colwidth)">
  314. <xsl:attribute name="column-width">
  315. <xsl:choose>
  316. <xsl:when test="not(normalize-space(@colwidth))">
  317. <xsl:call-template name="calculateColumnWidth.Proportional">
  318. <xsl:with-param name="colwidth" select="'1*'"/>
  319. </xsl:call-template>
  320. </xsl:when>
  321. <xsl:when test="contains(@colwidth, '*')">
  322. <xsl:call-template name="calculateColumnWidth.Proportional">
  323. <xsl:with-param name="colwidth" select="@colwidth"/>
  324. </xsl:call-template>
  325. </xsl:when>
  326. <xsl:otherwise>
  327. <xsl:call-template name="calculateColumnWidth.nonProportional">
  328. <xsl:with-param name="colwidth" select="@colwidth"/>
  329. </xsl:call-template>
  330. </xsl:otherwise>
  331. </xsl:choose>
  332. </xsl:attribute>
  333. </xsl:if>
  334. <xsl:call-template name="applyAlignAttrs"/>
  335. </fo:table-column>
  336. </xsl:template>
  337. <xsl:template match="*[contains(@class, ' topic/thead ')]">
  338. <fo:table-header xsl:use-attribute-sets="tgroup.thead">
  339. <xsl:call-template name="commonattributes"/>
  340. <xsl:apply-templates/>
  341. </fo:table-header>
  342. </xsl:template>
  343. <xsl:template match="*[contains(@class, ' topic/tbody ')]">
  344. <fo:table-body xsl:use-attribute-sets="tgroup.tbody">
  345. <xsl:call-template name="commonattributes"/>
  346. <xsl:apply-templates/>
  347. </fo:table-body>
  348. </xsl:template>
  349. <xsl:template match="*[contains(@class, ' topic/thead ')]/*[contains(@class, ' topic/row ')]">
  350. <fo:table-row xsl:use-attribute-sets="thead.row">
  351. <xsl:call-template name="commonattributes"/>
  352. <xsl:apply-templates/>
  353. </fo:table-row>
  354. </xsl:template>
  355. <xsl:template match="*[contains(@class, ' topic/tbody ')]/*[contains(@class, ' topic/row ')]">
  356. <fo:table-row xsl:use-attribute-sets="tbody.row">
  357. <xsl:call-template name="commonattributes"/>
  358. <xsl:apply-templates/>
  359. </fo:table-row>
  360. </xsl:template>
  361. <xsl:template match="*[contains(@class, ' topic/entry ')]" mode="validate-entry-position">
  362. <xsl:if test="dita-ot:get-entry-end-position(.) gt number(ancestor::*[contains(@class,' topic/tgroup ')][1]/@cols)">
  363. <xsl:call-template name="output-message">
  364. <xsl:with-param name="id" select="'PDFX012E'"/>
  365. </xsl:call-template>
  366. </xsl:if>
  367. </xsl:template>
  368. <xsl:template match="*[contains(@class, ' topic/thead ')]/*[contains(@class, ' topic/row ')]/*[contains(@class, ' topic/entry ')]">
  369. <xsl:apply-templates select="." mode="validate-entry-position"/>
  370. <fo:table-cell xsl:use-attribute-sets="thead.row.entry">
  371. <xsl:call-template name="commonattributes"/>
  372. <xsl:call-template name="applySpansAttrs"/>
  373. <xsl:call-template name="applyAlignAttrs"/>
  374. <xsl:call-template name="generateTableEntryBorder"/>
  375. <xsl:choose>
  376. <xsl:when test="@rotate eq '1'">
  377. <xsl:apply-templates select="." mode="rotateTableEntryContent"/>
  378. </xsl:when>
  379. <xsl:otherwise>
  380. <fo:block xsl:use-attribute-sets="thead.row.entry__content">
  381. <xsl:call-template name="processEntryContent"/>
  382. </fo:block>
  383. </xsl:otherwise>
  384. </xsl:choose>
  385. </fo:table-cell>
  386. </xsl:template>
  387. <xsl:template match="*[contains(@class, ' topic/thead ')]/*[contains(@class, ' topic/row ')]/*[contains(@class, ' topic/entry ')]" mode="rotateTableEntryContent">
  388. <fo:block-container reference-orientation="90">
  389. <fo:block xsl:use-attribute-sets="thead.row.entry__content">
  390. <xsl:call-template name="processEntryContent"/>
  391. </fo:block>
  392. </fo:block-container>
  393. </xsl:template>
  394. <xsl:template match="*[contains(@class, ' topic/tbody ')]/*[contains(@class, ' topic/row ')]/*[contains(@class, ' topic/entry ')]">
  395. <xsl:apply-templates select="." mode="validate-entry-position"/>
  396. <xsl:choose>
  397. <xsl:when test="ancestor::*[contains(@class, ' topic/table ')][1]/@rowheader = 'firstcol'
  398. and @dita-ot:x = '1'">
  399. <fo:table-cell xsl:use-attribute-sets="tbody.row.entry__firstcol">
  400. <xsl:apply-templates select="." mode="processTableEntry"/>
  401. </fo:table-cell>
  402. </xsl:when>
  403. <xsl:otherwise>
  404. <fo:table-cell xsl:use-attribute-sets="tbody.row.entry">
  405. <xsl:apply-templates select="." mode="processTableEntry"/>
  406. </fo:table-cell>
  407. </xsl:otherwise>
  408. </xsl:choose>
  409. </xsl:template>
  410. <xsl:template match="*" mode="processTableEntry">
  411. <xsl:call-template name="commonattributes"/>
  412. <xsl:call-template name="applySpansAttrs"/>
  413. <xsl:call-template name="applyAlignAttrs"/>
  414. <xsl:call-template name="generateTableEntryBorder"/>
  415. <xsl:choose>
  416. <xsl:when test="@rotate eq '1'">
  417. <xsl:apply-templates select="." mode="rotateTableEntryContent"/>
  418. </xsl:when>
  419. <xsl:otherwise>
  420. <fo:block xsl:use-attribute-sets="tbody.row.entry__content">
  421. <xsl:call-template name="processEntryContent"/>
  422. </fo:block>
  423. </xsl:otherwise>
  424. </xsl:choose>
  425. </xsl:template>
  426. <xsl:template match="*[contains(@class, ' topic/tbody ')]/*[contains(@class, ' topic/row ')]/*[contains(@class, ' topic/entry ')]" mode="rotateTableEntryContent">
  427. <fo:block-container reference-orientation="90">
  428. <fo:block xsl:use-attribute-sets="tbody.row.entry__content">
  429. <xsl:call-template name="processEntryContent"/>
  430. </fo:block>
  431. </fo:block-container>
  432. </xsl:template>
  433. <xsl:template name="processEntryContent">
  434. <xsl:variable name="entryNumber" select="@dita-ot:x" as="xs:integer?"/>
  435. <xsl:variable name="colspec" select="ancestor::*[contains(@class, ' topic/tgroup ')][1]/*[contains(@class, ' topic/colspec ')][position() = $entryNumber]" as="element()?"/>
  436. <xsl:variable name="char" as="xs:string?">
  437. <xsl:choose>
  438. <xsl:when test="@char">
  439. <xsl:value-of select="@char"/>
  440. </xsl:when>
  441. <xsl:when test="$colspec/@char">
  442. <xsl:value-of select="$colspec/@char"/>
  443. </xsl:when>
  444. </xsl:choose>
  445. </xsl:variable>
  446. <xsl:variable name="charoff" as="xs:integer">
  447. <xsl:choose>
  448. <xsl:when test="@charoff">
  449. <xsl:sequence select="xs:integer(@charoff)"/>
  450. </xsl:when>
  451. <xsl:when test="$colspec/@charoff">
  452. <xsl:sequence select="xs:integer($colspec/@charoff)"/>
  453. </xsl:when>
  454. <xsl:otherwise>
  455. <xsl:sequence select="xs:integer(50)"/>
  456. </xsl:otherwise>
  457. </xsl:choose>
  458. </xsl:variable>
  459. <xsl:apply-templates select="." mode="ancestor-start-flag"/>
  460. <xsl:choose>
  461. <xsl:when test="exists($char) and string-length($char) ne 0">
  462. <xsl:call-template name="processCharAlignment">
  463. <xsl:with-param name="char" select="$char"/>
  464. <xsl:with-param name="charoff" select="$charoff"/>
  465. </xsl:call-template>
  466. </xsl:when>
  467. <xsl:otherwise>
  468. <xsl:apply-templates/>
  469. </xsl:otherwise>
  470. </xsl:choose>
  471. <xsl:apply-templates select="." mode="ancestor-end-flag"/>
  472. </xsl:template>
  473. <xsl:template name="processCharAlignment">
  474. <xsl:param name="char" as="xs:string"/>
  475. <xsl:param name="charoff" as="xs:integer"/>
  476. <xsl:choose>
  477. <xsl:when test="not(descendant::* | descendant::processing-instruction() | descendant::comment())">
  478. <xsl:variable name="text-before" select="substring-before(text(), $char)"/>
  479. <xsl:variable name="text-after" select="substring-after(text(), $text-before)"/>
  480. <fo:list-block start-indent="0pt"
  481. provisional-label-separation="0pt"
  482. provisional-distance-between-starts="{concat($charoff, '%')}">
  483. <fo:list-item>
  484. <fo:list-item-label end-indent="label-end()">
  485. <fo:block text-align="end">
  486. <xsl:copy-of select="$text-before"/>
  487. </fo:block>
  488. </fo:list-item-label>
  489. <fo:list-item-body start-indent="body-start()">
  490. <fo:block text-align="start">
  491. <xsl:copy-of select="$text-after"/>
  492. </fo:block>
  493. </fo:list-item-body>
  494. </fo:list-item>
  495. </fo:list-block>
  496. </xsl:when>
  497. </xsl:choose>
  498. </xsl:template>
  499. <xsl:template name="calculateColumnWidth.Proportional">
  500. <xsl:param name="colwidth" as="xs:string"/>
  501. <xsl:text>proportional-column-width(</xsl:text>
  502. <xsl:choose>
  503. <xsl:when test="substring-before($colwidth, '*') != ''">
  504. <xsl:value-of select="normalize-space(substring-before($colwidth, '*'))"/>
  505. </xsl:when>
  506. <xsl:otherwise>
  507. <xsl:text>1.00</xsl:text>
  508. </xsl:otherwise>
  509. </xsl:choose>
  510. <xsl:text>)</xsl:text>
  511. </xsl:template>
  512. <xsl:template name="calculateColumnWidth.nonProportional">
  513. <xsl:param name="colwidth" as="xs:string"/>
  514. <xsl:variable name="width-units" as="xs:string">
  515. <xsl:choose>
  516. <!-- XXX: This should never occur -->
  517. <xsl:when test="contains($colwidth, '*')">
  518. <xsl:value-of select="normalize-space(substring-after($colwidth, '*'))"/>
  519. </xsl:when>
  520. <xsl:otherwise>
  521. <xsl:value-of select="normalize-space($colwidth)"/>
  522. </xsl:otherwise>
  523. </xsl:choose>
  524. </xsl:variable>
  525. <xsl:variable name="width" select="dita-ot:get-length($width-units)"/>
  526. <xsl:variable name="units" select="dita-ot:get-unit($width-units)"/>
  527. <xsl:value-of select="$width"/>
  528. <xsl:choose>
  529. <xsl:when test="$units = 'pi'">pc</xsl:when>
  530. <xsl:when test="$units = '' and $width != ''">pt</xsl:when>
  531. <xsl:otherwise>
  532. <xsl:value-of select="$units"/>
  533. </xsl:otherwise>
  534. </xsl:choose>
  535. </xsl:template>
  536. <xsl:template name="applySpansAttrs">
  537. <xsl:if test="exists(@morerows) and xs:integer(@morerows) gt 0">
  538. <xsl:attribute name="number-rows-spanned">
  539. <xsl:value-of select="xs:integer(@morerows) + 1"/>
  540. </xsl:attribute>
  541. </xsl:if>
  542. <xsl:if test="exists(@dita-ot:morecols) and xs:integer(@dita-ot:morecols) gt 0">
  543. <xsl:attribute name="number-columns-spanned">
  544. <xsl:value-of select="xs:integer(@dita-ot:morecols) + 1"/>
  545. </xsl:attribute>
  546. </xsl:if>
  547. </xsl:template>
  548. <xsl:template name="applyAlignAttrs">
  549. <xsl:variable name="align" as="xs:string?">
  550. <xsl:choose>
  551. <xsl:when test="@align">
  552. <xsl:value-of select="@align"/>
  553. </xsl:when>
  554. <xsl:when test="ancestor::*[contains(@class, ' topic/tbody ')][1][@align]">
  555. <xsl:value-of select="ancestor::*[contains(@class, ' topic/tbody ')][1]/@align"/>
  556. </xsl:when>
  557. <xsl:when test="ancestor::*[contains(@class, ' topic/thead ')][1][@align]">
  558. <xsl:value-of select="ancestor::*[contains(@class, ' topic/thead ')][1]/@align"/>
  559. </xsl:when>
  560. <xsl:when test="ancestor::*[contains(@class, ' topic/tgroup ')][1][@align]">
  561. <xsl:value-of select="ancestor::*[contains(@class, ' topic/tgroup ')][1]/@align"/>
  562. </xsl:when>
  563. </xsl:choose>
  564. </xsl:variable>
  565. <xsl:variable name="valign" as="xs:string?">
  566. <xsl:choose>
  567. <xsl:when test="@valign">
  568. <xsl:value-of select="@valign"/>
  569. </xsl:when>
  570. <xsl:when test="parent::*[contains(@class, ' topic/row ')][@valign]">
  571. <xsl:value-of select="parent::*[contains(@class, ' topic/row ')]/@valign"/>
  572. </xsl:when>
  573. </xsl:choose>
  574. </xsl:variable>
  575. <xsl:choose>
  576. <xsl:when test="not(normalize-space($align) = '')">
  577. <xsl:attribute name="text-align">
  578. <xsl:value-of select="$align"/>
  579. </xsl:attribute>
  580. </xsl:when>
  581. <xsl:when test="(normalize-space($align) = '') and contains(@class, ' topic/colspec ')"/>
  582. <xsl:otherwise>
  583. <xsl:attribute name="text-align">from-table-column()</xsl:attribute>
  584. </xsl:otherwise>
  585. </xsl:choose>
  586. <xsl:choose>
  587. <xsl:when test="$valign='top'">
  588. <xsl:attribute name="display-align">
  589. <xsl:value-of select="'before'"/>
  590. </xsl:attribute>
  591. </xsl:when>
  592. <xsl:when test="$valign='middle'">
  593. <xsl:attribute name="display-align">
  594. <xsl:value-of select="'center'"/>
  595. </xsl:attribute>
  596. </xsl:when>
  597. <xsl:when test="$valign='bottom'">
  598. <xsl:attribute name="display-align">
  599. <xsl:value-of select="'after'"/>
  600. </xsl:attribute>
  601. </xsl:when>
  602. </xsl:choose>
  603. </xsl:template>
  604. <xsl:template name="generateTableEntryBorder">
  605. <xsl:variable name="colsep" as="xs:string">
  606. <xsl:call-template name="getTableColsep"/>
  607. </xsl:variable>
  608. <xsl:variable name="rowsep" as="xs:string">
  609. <xsl:call-template name="getTableRowsep"/>
  610. </xsl:variable>
  611. <xsl:variable name="frame" as="xs:string" select="(ancestor::*[contains(@class, ' topic/table ')][1]/@frame, $table.frame-default)[1]"/>
  612. <xsl:variable name="needTopBorderOnBreak" as="xs:boolean">
  613. <xsl:choose>
  614. <xsl:when test="$frame = ('all', 'topbot', 'top')">
  615. <xsl:choose>
  616. <xsl:when test="../parent::node()[contains(@class, ' topic/thead ')]">
  617. <xsl:sequence select="true()"/>
  618. </xsl:when>
  619. <xsl:when test="(../parent::node()[contains(@class, ' topic/tbody ')]) and not(../preceding-sibling::*[contains(@class, ' topic/row ')])">
  620. <xsl:sequence select="true()"/>
  621. </xsl:when>
  622. <xsl:when test="../parent::node()[contains(@class, ' topic/tbody ')]">
  623. <xsl:variable name="entryNum" select="count(preceding-sibling::*[contains(@class, ' topic/entry ')]) + 1"/>
  624. <xsl:variable name="prevEntryRowsep" as="xs:string?">
  625. <xsl:for-each select="../preceding-sibling::*[contains(@class, ' topic/row ')][1]/*[contains(@class, ' topic/entry ')][$entryNum]">
  626. <xsl:call-template name="getTableRowsep"/>
  627. </xsl:for-each>
  628. </xsl:variable>
  629. <xsl:choose>
  630. <xsl:when test="$prevEntryRowsep != '0'">
  631. <xsl:sequence select="true()"/>
  632. </xsl:when>
  633. <xsl:otherwise>
  634. <xsl:sequence select="false()"/>
  635. </xsl:otherwise>
  636. </xsl:choose>
  637. </xsl:when>
  638. <xsl:otherwise>
  639. <xsl:sequence select="false()"/>
  640. </xsl:otherwise>
  641. </xsl:choose>
  642. </xsl:when>
  643. <xsl:otherwise>
  644. <xsl:sequence select="false()"/>
  645. </xsl:otherwise>
  646. </xsl:choose>
  647. </xsl:variable>
  648. <xsl:if test="number($rowsep) = 1 and (../parent::node()[contains(@class, ' topic/thead ')])">
  649. <xsl:call-template name="processAttrSetReflection">
  650. <xsl:with-param name="attrSet" select="'thead__tableframe__bottom'"/>
  651. <xsl:with-param name="path" select="$tableAttrs"/>
  652. </xsl:call-template>
  653. </xsl:if>
  654. <xsl:if test="number($rowsep) = 1 and ((../following-sibling::*[contains(@class, ' topic/row ')]) or (../parent::node()[contains(@class, ' topic/tbody ')] and ancestor::*[contains(@class, ' topic/tgroup ')][1]/*[contains(@class, ' topic/tfoot ')]))">
  655. <xsl:call-template name="processAttrSetReflection">
  656. <xsl:with-param name="attrSet" select="'__tableframe__bottom'"/>
  657. <xsl:with-param name="path" select="$tableAttrs"/>
  658. </xsl:call-template>
  659. </xsl:if>
  660. <xsl:if test="$needTopBorderOnBreak">
  661. <xsl:call-template name="processAttrSetReflection">
  662. <xsl:with-param name="attrSet" select="'__tableframe__top'"/>
  663. <xsl:with-param name="path" select="$tableAttrs"/>
  664. </xsl:call-template>
  665. </xsl:if>
  666. <xsl:if test="number($colsep) = 1 and following-sibling::*[contains(@class, ' topic/entry ')]">
  667. <xsl:call-template name="processAttrSetReflection">
  668. <xsl:with-param name="attrSet" select="'__tableframe__right'"/>
  669. <xsl:with-param name="path" select="$tableAttrs"/>
  670. </xsl:call-template>
  671. </xsl:if>
  672. <xsl:if test="number($colsep) = 1 and not(following-sibling::*[contains(@class, ' topic/entry ')]) and ((count(preceding-sibling::*) + 1) &lt; ancestor::*[contains(@class, ' topic/tgroup ')][1]/@cols)">
  673. <xsl:call-template name="processAttrSetReflection">
  674. <xsl:with-param name="attrSet" select="'__tableframe__right'"/>
  675. <xsl:with-param name="path" select="$tableAttrs"/>
  676. </xsl:call-template>
  677. </xsl:if>
  678. </xsl:template>
  679. <!-- DITA spec prose defines as either 0 or 1, but DTD as NMTOKENS. However, OASIS Table Exchange model uses 0 or anything else. -->
  680. <xsl:template name="getTableColsep" as="xs:string">
  681. <xsl:variable name="colname" select="@colname"/>
  682. <xsl:choose>
  683. <xsl:when test="@colsep">
  684. <xsl:value-of select="@colsep"/>
  685. </xsl:when>
  686. <xsl:when test="ancestor::*[contains(@class, ' topic/tgroup ')][1]/*[contains(@class, ' topic/colspec ')][@colname = $colname]/@colsep">
  687. <xsl:value-of select="ancestor::*[contains(@class, ' topic/tgroup ')][1]/*[contains(@class, ' topic/colspec ')][@colname = $colname]/@colsep"/>
  688. </xsl:when>
  689. <xsl:when test="ancestor::*[contains(@class, ' topic/tgroup ')][1]/@colsep">
  690. <xsl:value-of select="ancestor::*[contains(@class, ' topic/tgroup ')][1]/@colsep"/>
  691. </xsl:when>
  692. <xsl:when test="ancestor::*[contains(@class, ' topic/table ')][1]/@colsep">
  693. <xsl:value-of select="ancestor::*[contains(@class, ' topic/table ')][1]/@colsep"/>
  694. </xsl:when>
  695. <xsl:otherwise>
  696. <xsl:value-of select="$table.colsep-default"/>
  697. </xsl:otherwise>
  698. </xsl:choose>
  699. </xsl:template>
  700. <xsl:template name="getTableRowsep" as="xs:string">
  701. <xsl:variable name="colname" select="@colname"/>
  702. <xsl:choose>
  703. <xsl:when test="@rowsep">
  704. <xsl:value-of select="@rowsep"/>
  705. </xsl:when>
  706. <xsl:when test="ancestor::*[contains(@class, ' topic/row ')][1]/@rowsep">
  707. <xsl:value-of select="ancestor::*[contains(@class, ' topic/row ')][1]/@rowsep"/>
  708. </xsl:when>
  709. <xsl:when test="ancestor::*[contains(@class, ' topic/tgroup ')][1]/*[contains(@class, ' topic/colspec ')][@colname = $colname]/@rowsep">
  710. <xsl:value-of select="ancestor::*[contains(@class, ' topic/tgroup ')][1]/*[contains(@class, ' topic/colspec ')][@colname = $colname]/@rowsep"/>
  711. </xsl:when>
  712. <xsl:when test="ancestor::*[contains(@class, ' topic/tgroup ')][1]/@rowsep">
  713. <xsl:value-of select="ancestor::*[contains(@class, ' topic/tgroup ')][1]/@rowsep"/>
  714. </xsl:when>
  715. <xsl:when test="ancestor::*[contains(@class, ' topic/table ')][1]/@rowsep">
  716. <xsl:value-of select="ancestor::*[contains(@class, ' topic/table ')][1]/@rowsep"/>
  717. </xsl:when>
  718. <xsl:otherwise>
  719. <xsl:value-of select="$table.rowsep-default"/>
  720. </xsl:otherwise>
  721. </xsl:choose>
  722. </xsl:template>
  723. <xsl:template name="displayAtts">
  724. <xsl:param name="element" as="element()"/>
  725. <xsl:variable name="frame" as="xs:string" select="($element/@frame, $table.frame-default)[1]"/>
  726. <xsl:if test="$element/@expanse">
  727. <xsl:for-each select="$element">
  728. <xsl:call-template name="setExpanse"/>
  729. </xsl:for-each>
  730. </xsl:if>
  731. <xsl:choose>
  732. <xsl:when test="$frame = 'all'">
  733. <xsl:call-template name="processAttrSetReflection">
  734. <xsl:with-param name="attrSet" select="'table__tableframe__all'"/>
  735. <xsl:with-param name="path" select="$tableAttrs"/>
  736. </xsl:call-template>
  737. </xsl:when>
  738. <xsl:when test="$frame = 'topbot'">
  739. <xsl:call-template name="processAttrSetReflection">
  740. <xsl:with-param name="attrSet" select="'table__tableframe__topbot'"/>
  741. <xsl:with-param name="path" select="$tableAttrs"/>
  742. </xsl:call-template>
  743. </xsl:when>
  744. <xsl:when test="$frame = 'top'">
  745. <xsl:call-template name="processAttrSetReflection">
  746. <xsl:with-param name="attrSet" select="'table__tableframe__top'"/>
  747. <xsl:with-param name="path" select="$tableAttrs"/>
  748. </xsl:call-template>
  749. </xsl:when>
  750. <xsl:when test="$frame = 'bottom'">
  751. <xsl:call-template name="processAttrSetReflection">
  752. <xsl:with-param name="attrSet" select="'table__tableframe__bottom'"/>
  753. <xsl:with-param name="path" select="$tableAttrs"/>
  754. </xsl:call-template>
  755. </xsl:when>
  756. <xsl:when test="$frame = 'sides'">
  757. <xsl:call-template name="processAttrSetReflection">
  758. <xsl:with-param name="attrSet" select="'table__tableframe__sides'"/>
  759. <xsl:with-param name="path" select="$tableAttrs"/>
  760. </xsl:call-template>
  761. </xsl:when>
  762. </xsl:choose>
  763. </xsl:template>
  764. <xsl:template name="getTableScale" as="xs:string?">
  765. <xsl:sequence select="ancestor-or-self::*[contains(@class, ' topic/table ')][1]/@scale"/>
  766. </xsl:template>
  767. <xsl:template match="@*" mode="setTableEntriesScale">
  768. <xsl:choose>
  769. <xsl:when test="name() = 'font-size'">
  770. </xsl:when>
  771. <xsl:otherwise>
  772. <xsl:copy-of select="."/>
  773. </xsl:otherwise>
  774. </xsl:choose>
  775. </xsl:template>
  776. <xsl:template match="node() | text()" mode="setTableEntriesScale">
  777. <xsl:copy>
  778. <xsl:apply-templates select="node() | @* | text()" mode="setTableEntriesScale"/>
  779. </xsl:copy>
  780. </xsl:template>
  781. <!-- Simpletable processing -->
  782. <xsl:template match="*[contains(@class, ' topic/simpletable ')]">
  783. <xsl:variable name="number-cells" as="xs:integer">
  784. <!-- Contains the number of cells in the widest row -->
  785. <xsl:apply-templates select="*[1]" mode="count-max-simpletable-cells"/>
  786. </xsl:variable>
  787. <xsl:apply-templates select="*[contains(@class,' ditaot-d/ditaval-startprop ')]" mode="outofline"/>
  788. <fo:table xsl:use-attribute-sets="simpletable">
  789. <xsl:call-template name="commonattributes"/>
  790. <xsl:call-template name="globalAtts"/>
  791. <xsl:call-template name="displayAtts">
  792. <xsl:with-param name="element" select="."/>
  793. </xsl:call-template>
  794. <xsl:if test="@relcolwidth">
  795. <xsl:variable name="fix-relcolwidth" as="xs:string">
  796. <xsl:apply-templates select="." mode="fix-relcolwidth">
  797. <xsl:with-param name="number-cells" select="$number-cells"/>
  798. </xsl:apply-templates>
  799. </xsl:variable>
  800. <xsl:call-template name="createSimpleTableColumns">
  801. <xsl:with-param name="theColumnWidthes" select="$fix-relcolwidth"/>
  802. </xsl:call-template>
  803. </xsl:if>
  804. <!-- Toss processing to another template to process the simpletable
  805. heading, and/or create a default table heading row. -->
  806. <xsl:apply-templates select="." mode="dita2xslfo:simpletable-heading">
  807. <xsl:with-param name="number-cells" select="$number-cells"/>
  808. </xsl:apply-templates>
  809. <fo:table-body xsl:use-attribute-sets="simpletable__body">
  810. <xsl:choose>
  811. <xsl:when test="empty(*[contains(@class, ' topic/strow ')])">
  812. <fo:table-row>
  813. <fo:table-cell>
  814. <fo:block/>
  815. </fo:table-cell>
  816. </fo:table-row>
  817. </xsl:when>
  818. <xsl:otherwise>
  819. <xsl:apply-templates select="*[contains(@class, ' topic/strow ')]">
  820. <xsl:with-param name="number-cells" select="$number-cells"/>
  821. </xsl:apply-templates>
  822. </xsl:otherwise>
  823. </xsl:choose>
  824. </fo:table-body>
  825. </fo:table>
  826. <xsl:apply-templates select="*[contains(@class,' ditaot-d/ditaval-endprop ')]" mode="outofline"/>
  827. </xsl:template>
  828. <xsl:template match="*[contains(@class,' topic/simpletable ')]
  829. [empty(*[contains(@class,' topic/strow ')]/*[contains(@class,' topic/stentry ')])]" priority="10"/>
  830. <xsl:template match="*[contains(@class,' topic/strow ') or contains(@class,' topic/sthead ')][empty(*[contains(@class,' topic/stentry ')])]" priority="10"/>
  831. <xsl:template name="createSimpleTableColumns">
  832. <xsl:param name="theColumnWidthes" as="xs:string"/>
  833. <xsl:for-each select="tokenize(normalize-space($theColumnWidthes), '\s+')">
  834. <fo:table-column>
  835. <xsl:attribute name="column-width">
  836. <xsl:call-template name="calculateColumnWidth.Proportional">
  837. <xsl:with-param name="colwidth" select="."/>
  838. </xsl:call-template>
  839. </xsl:attribute>
  840. </fo:table-column>
  841. </xsl:for-each>
  842. </xsl:template>
  843. <!-- Fill in empty cells when one is missing from strow or sthead.
  844. Context for this call is strow or sthead. -->
  845. <xsl:template match="*" mode="fillInMissingSimpletableCells">
  846. <xsl:param name="fill-in-count" select="0" as="xs:integer"/>
  847. <xsl:variable name="current" select="."/>
  848. <xsl:for-each select="1 to $fill-in-count">
  849. <xsl:for-each select="$current">
  850. <fo:table-cell xsl:use-attribute-sets="strow.stentry">
  851. <xsl:call-template name="commonattributes"/>
  852. <xsl:variable name="frame" as="xs:string" select="(../@frame, $table.frame-default)[1]"/>
  853. <xsl:if test="following-sibling::*[contains(@class, ' topic/strow ')]">
  854. <xsl:apply-templates select="." mode="simpletableHorizontalBorders">
  855. <xsl:with-param name="frame" select="$frame" as="xs:string"/>
  856. </xsl:apply-templates>
  857. </xsl:if>
  858. <xsl:apply-templates select="." mode="simpletableTopBorder">
  859. <xsl:with-param name="frame" select="$frame" as="xs:string"/>
  860. </xsl:apply-templates>
  861. <xsl:apply-templates select="." mode="simpletableSideBorders">
  862. <xsl:with-param name="frame" select="$frame" as="xs:string"/>
  863. </xsl:apply-templates>
  864. <fo:block>
  865. <fo:inline>&#160;</fo:inline>
  866. </fo:block>
  867. </fo:table-cell>
  868. </xsl:for-each>
  869. </xsl:for-each>
  870. </xsl:template>
  871. <!-- Specialized simpletable elements may override this rule to add
  872. default headings for the table. By default, the existing sthead
  873. element is used when specified. -->
  874. <xsl:template match="*[contains(@class, ' topic/simpletable ')]" mode="dita2xslfo:simpletable-heading">
  875. <xsl:param name="number-cells" as="xs:integer">
  876. <xsl:apply-templates select="*[1]" mode="count-max-simpletable-cells"/>
  877. </xsl:param>
  878. <xsl:apply-templates select="*[contains(@class, ' topic/sthead ')]">
  879. <xsl:with-param name="number-cells" select="$number-cells"/>
  880. </xsl:apply-templates>
  881. </xsl:template>
  882. <xsl:template match="*[contains(@class, ' topic/sthead ')]">
  883. <xsl:param name="number-cells" as="xs:integer">
  884. <xsl:apply-templates select="../*[1]" mode="count-max-simpletable-cells"/>
  885. </xsl:param>
  886. <fo:table-header xsl:use-attribute-sets="sthead">
  887. <xsl:call-template name="commonattributes"/>
  888. <fo:table-row xsl:use-attribute-sets="sthead__row">
  889. <xsl:apply-templates select="*[contains(@class, ' topic/stentry ')]"/>
  890. <xsl:variable name="row-cell-count" select="count(*[contains(@class, ' topic/stentry ')])" as="xs:integer"/>
  891. <xsl:if test="$row-cell-count &lt; $number-cells">
  892. <xsl:apply-templates select="." mode="fillInMissingSimpletableCells">
  893. <xsl:with-param name="fill-in-count" select="$number-cells - $row-cell-count"/>
  894. </xsl:apply-templates>
  895. </xsl:if>
  896. </fo:table-row>
  897. </fo:table-header>
  898. </xsl:template>
  899. <xsl:template match="*[contains(@class, ' topic/strow ')]">
  900. <xsl:param name="number-cells" as="xs:integer">
  901. <xsl:apply-templates select="../*[1]" mode="count-max-simpletable-cells"/>
  902. </xsl:param>
  903. <fo:table-row xsl:use-attribute-sets="strow">
  904. <xsl:call-template name="commonattributes"/>
  905. <xsl:apply-templates select="*[contains(@class, ' topic/stentry ')]"/>
  906. <xsl:variable name="row-cell-count" select="count(*[contains(@class, ' topic/stentry ')])" as="xs:integer"/>
  907. <xsl:if test="$row-cell-count &lt; $number-cells">
  908. <xsl:apply-templates select="." mode="fillInMissingSimpletableCells">
  909. <xsl:with-param name="fill-in-count" select="$number-cells - $row-cell-count"/>
  910. </xsl:apply-templates>
  911. </xsl:if>
  912. </fo:table-row>
  913. </xsl:template>
  914. <xsl:template match="*[contains(@class, ' topic/sthead ')]/*[contains(@class, ' topic/stentry ')]">
  915. <fo:table-cell xsl:use-attribute-sets="sthead.stentry">
  916. <xsl:call-template name="commonattributes"/>
  917. <xsl:variable name="entryCol" select="count(preceding-sibling::*[contains(@class, ' topic/stentry ')]) + 1"/>
  918. <xsl:variable name="frame" as="xs:string" select="(ancestor::*[contains(@class, ' topic/simpletable ')][1]/@frame, $table.frame-default)[1]"/>
  919. <xsl:apply-templates select="." mode="simpletableHorizontalBorders">
  920. <xsl:with-param name="frame" select="$frame" as="xs:string"/>
  921. </xsl:apply-templates>
  922. <xsl:apply-templates select="." mode="simpletableTopBorder">
  923. <xsl:with-param name="frame" select="$frame" as="xs:string"/>
  924. </xsl:apply-templates>
  925. <xsl:if test="following-sibling::*[contains(@class, ' topic/stentry ')]">
  926. <xsl:apply-templates select="." mode="simpletableVerticalBorders">
  927. <xsl:with-param name="frame" select="$frame" as="xs:string"/>
  928. </xsl:apply-templates>
  929. </xsl:if>
  930. <xsl:choose>
  931. <xsl:when test="number(ancestor::*[contains(@class, ' topic/simpletable ')][1]/@keycol) = $entryCol">
  932. <fo:block xsl:use-attribute-sets="sthead.stentry__keycol-content">
  933. <xsl:apply-templates select="." mode="ancestor-start-flag"/>
  934. <xsl:apply-templates/>
  935. <xsl:apply-templates select="." mode="ancestor-end-flag"/>
  936. </fo:block>
  937. </xsl:when>
  938. <xsl:otherwise>
  939. <fo:block xsl:use-attribute-sets="sthead.stentry__content">
  940. <xsl:apply-templates select="." mode="ancestor-start-flag"/>
  941. <xsl:apply-templates/>
  942. <xsl:apply-templates select="." mode="ancestor-end-flag"/>
  943. </fo:block>
  944. </xsl:otherwise>
  945. </xsl:choose>
  946. </fo:table-cell>
  947. </xsl:template>
  948. <xsl:template match="*[contains(@class, ' topic/strow ')]/*[contains(@class, ' topic/stentry ')]">
  949. <fo:table-cell xsl:use-attribute-sets="strow.stentry">
  950. <xsl:call-template name="commonattributes"/>
  951. <xsl:variable name="entryCol" select="count(preceding-sibling::*[contains(@class, ' topic/stentry ')]) + 1"/>
  952. <xsl:variable name="frame" as="xs:string" select="(ancestor::*[contains(@class, ' topic/simpletable ')][1]/@frame, $table.frame-default)[1]"/>
  953. <xsl:if test="../following-sibling::*[contains(@class, ' topic/strow ')]">
  954. <xsl:apply-templates select="." mode="simpletableHorizontalBorders">
  955. <xsl:with-param name="frame" select="$frame" as="xs:string"/>
  956. </xsl:apply-templates>
  957. </xsl:if>
  958. <xsl:if test="following-sibling::*[contains(@class, ' topic/stentry ')]">
  959. <xsl:apply-templates select="." mode="simpletableVerticalBorders">
  960. <xsl:with-param name="frame" select="$frame" as="xs:string"/>
  961. </xsl:apply-templates>
  962. </xsl:if>
  963. <xsl:choose>
  964. <xsl:when test="number(ancestor::*[contains(@class, ' topic/simpletable ')][1]/@keycol) = $entryCol">
  965. <fo:block xsl:use-attribute-sets="strow.stentry__keycol-content">
  966. <xsl:apply-templates select="." mode="ancestor-start-flag"/>
  967. <xsl:apply-templates/>
  968. <xsl:apply-templates select="." mode="ancestor-end-flag"/>
  969. </fo:block>
  970. </xsl:when>
  971. <xsl:otherwise>
  972. <fo:block xsl:use-attribute-sets="strow.stentry__content">
  973. <xsl:apply-templates select="." mode="ancestor-start-flag"/>
  974. <xsl:apply-templates/>
  975. <xsl:apply-templates select="." mode="ancestor-end-flag"/>
  976. </fo:block>
  977. </xsl:otherwise>
  978. </xsl:choose>
  979. </fo:table-cell>
  980. </xsl:template>
  981. <xsl:template match="*" mode="simpletableHorizontalBorders">
  982. <xsl:param name="frame" select="(ancestor-or-self::*[contains(@class, ' topic/simpletable ')][1]/@frame, $table.frame-default)[1]"
  983. as="xs:string"/>
  984. <xsl:call-template name="generateSimpleTableHorizontalBorders">
  985. <xsl:with-param name="frame" select="$frame"/>
  986. </xsl:call-template>
  987. </xsl:template>
  988. <xsl:template match="*" mode="simpletableTopBorder">
  989. <xsl:param name="frame" select="(ancestor-or-self::*[contains(@class, ' topic/simpletable ')][1]/@frame, $table.frame-default)[1]"
  990. as="xs:string"/>
  991. <xsl:if test="$frame = ('all', 'topbot', 'top')">
  992. <xsl:call-template name="processAttrSetReflection">
  993. <xsl:with-param name="attrSet" select="'__tableframe__top'"/>
  994. <xsl:with-param name="path" select="$tableAttrs"/>
  995. </xsl:call-template>
  996. </xsl:if>
  997. </xsl:template>
  998. <xsl:template match="*" mode="simpletableSideBorders">
  999. <xsl:param name="frame" select="(ancestor-or-self::*[contains(@class, ' topic/simpletable ')][1]/@frame, $table.frame-default)[1]"
  1000. as="xs:string"/>
  1001. <xsl:if test="$frame = ('all', 'topbot', 'sides')">
  1002. <xsl:call-template name="processAttrSetReflection">
  1003. <xsl:with-param name="attrSet" select="'__tableframe__left'"/>
  1004. <xsl:with-param name="path" select="$tableAttrs"/>
  1005. </xsl:call-template>
  1006. <xsl:call-template name="processAttrSetReflection">
  1007. <xsl:with-param name="attrSet" select="'__tableframe__right'"/>
  1008. <xsl:with-param name="path" select="$tableAttrs"/>
  1009. </xsl:call-template>
  1010. </xsl:if>
  1011. </xsl:template>
  1012. <xsl:template match="*" mode="simpletableVerticalBorders">
  1013. <xsl:param name="frame" select="(ancestor-or-self::*[contains(@class, ' topic/simpletable ')][1]/@frame, $table.frame-default)[1]"
  1014. as="xs:string"/>
  1015. <xsl:call-template name="generateSimpleTableVerticalBorders">
  1016. <xsl:with-param name="frame" select="$frame"/>
  1017. </xsl:call-template>
  1018. </xsl:template>
  1019. <xsl:template name="generateSimpleTableHorizontalBorders">
  1020. <xsl:param name="frame" as="xs:string?"/>
  1021. <xsl:choose>
  1022. <xsl:when test="$frame = ('all', 'topbot', 'sides') or empty($frame)">
  1023. <xsl:call-template name="processAttrSetReflection">
  1024. <xsl:with-param name="attrSet" select="'__tableframe__bottom'"/>
  1025. <xsl:with-param name="path" select="$tableAttrs"/>
  1026. </xsl:call-template>
  1027. </xsl:when>
  1028. </xsl:choose>
  1029. </xsl:template>
  1030. <xsl:template name="generateSimpleTableVerticalBorders">
  1031. <xsl:param name="frame" as="xs:string?"/>
  1032. <xsl:choose>
  1033. <xsl:when test="$frame = ('all', 'topbot', 'sides') or empty($frame)">
  1034. <xsl:call-template name="processAttrSetReflection">
  1035. <xsl:with-param name="attrSet" select="'__tableframe__right'"/>
  1036. <xsl:with-param name="path" select="$tableAttrs"/>
  1037. </xsl:call-template>
  1038. </xsl:when>
  1039. </xsl:choose>
  1040. </xsl:template>
  1041. <xsl:template name="topicrefAttsNoToc">
  1042. <!--TODO-->
  1043. </xsl:template>
  1044. <xsl:template name="topicrefAtts">
  1045. <!--TODO-->
  1046. </xsl:template>
  1047. <xsl:template name="selectAtts">
  1048. <!--TODO-->
  1049. </xsl:template>
  1050. <xsl:template name="globalAtts">
  1051. <!--TODO-->
  1052. </xsl:template>
  1053. </xsl:stylesheet>