table_of_content.xsl 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!--
  3. * This file is part of the LibreOffice project.
  4. *
  5. * This Source Code Form is subject to the terms of the Mozilla Public
  6. * License, v. 2.0. If a copy of the MPL was not distributed with this
  7. * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  8. *
  9. * This file incorporates work covered by the following license notice:
  10. *
  11. * Licensed to the Apache Software Foundation (ASF) under one or more
  12. * contributor license agreements. See the NOTICE file distributed
  13. * with this work for additional information regarding copyright
  14. * ownership. The ASF licenses this file to you under the Apache
  15. * License, Version 2.0 (the "License"); you may not use this file
  16. * except in compliance with the License. You may obtain a copy of
  17. * the License at http://www.apache.org/licenses/LICENSE-2.0 .
  18. -->
  19. <!--
  20. For further documentation and updates visit http://xml.openoffice.org/odf2xhtml
  21. -->
  22. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0" xmlns:config="urn:oasis:names:tc:opendocument:xmlns:config:1.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dom="http://www.w3.org/2001/xml-events" xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0" xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0" xmlns:math="http://www.w3.org/1998/Math/MathML" xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:ooo="http://openoffice.org/2004/office" xmlns:oooc="http://openoffice.org/2004/calc" xmlns:ooow="http://openoffice.org/2004/writer" xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:xforms="http://www.w3.org/2002/xforms" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:java="http://xml.apache.org/xslt/java" xmlns:sxg="http://www.jclark.com/xt/java/org.openoffice.xslt.OOoMasterDocument" xmlns:common="http://exslt.org/common" xmlns:xt="http://www.jclark.com/xt" xmlns:xalan="http://xml.apache.org/xalan" exclude-result-prefixes="chart config dc dom dr3d draw fo form math meta number office ooo oooc ooow script style svg table text xforms xlink xsd xsi java sxg xt common xalan">
  23. <!-- ****************************** -->
  24. <!-- *** Table of Content *** -->
  25. <!-- ****************************** -->
  26. <xsl:param name="currentChildContentRef" />
  27. <xsl:param name="contentTableHeadings" />
  28. <xsl:param name="contentTableURL" />
  29. <xsl:template match="text:table-of-content">
  30. <xsl:param name="globalData"/>
  31. <xsl:apply-templates>
  32. <xsl:with-param name="globalData" select="$globalData"/>
  33. </xsl:apply-templates>
  34. </xsl:template>
  35. <xsl:template match="text:index-body">
  36. <xsl:param name="globalData"/>
  37. <xsl:choose>
  38. <xsl:when test="parent::table-of-content and */text:tab[1] or */*/text:tab[1]">
  39. <xsl:call-template name="createIndexBodyTable">
  40. <xsl:with-param name="globalData" select="$globalData"/>
  41. </xsl:call-template>
  42. </xsl:when>
  43. <xsl:otherwise>
  44. <xsl:apply-templates>
  45. <xsl:with-param name="globalData" select="$globalData"/>
  46. </xsl:apply-templates>
  47. </xsl:otherwise>
  48. </xsl:choose>
  49. </xsl:template>
  50. <xsl:template match="text:index-title" mode="content-table">
  51. <xsl:param name="globalData"/>
  52. <xsl:apply-templates>
  53. <xsl:with-param name="globalData" select="$globalData"/>
  54. </xsl:apply-templates>
  55. </xsl:template>
  56. <xsl:template name="createIndexBodyTable">
  57. <xsl:param name="globalData"/>
  58. <xsl:variable name="allStyleTabStops-RTF">
  59. <xsl:element name="style:tab-stops">
  60. <xsl:call-template name="get-tab-stops">
  61. <xsl:with-param name="globalData" select="$globalData"/>
  62. <xsl:with-param name="styleName" select="current()/@text:style-name"/>
  63. <!--
  64. Currently only the style of text:index-body is recognized, but not of a paragraph child containing the text:tab element!
  65. <xsl:with-param name="styleName" select="descendant-or-self::*/@text:style-name"/>
  66. The column width needs to be tabstop plus fo:margin-left paragraph-properties
  67. -->
  68. </xsl:call-template>
  69. </xsl:element>
  70. </xsl:variable>
  71. <xsl:element namespace="{$namespace}" name="table">
  72. <xsl:attribute name="border">0</xsl:attribute>
  73. <xsl:attribute name="cellspacing">0</xsl:attribute>
  74. <xsl:attribute name="cellpadding">0</xsl:attribute>
  75. <xsl:if test="parent::*/@text:style-name">
  76. <!-- parent as index:body has no style -->
  77. <xsl:variable name="value" select="$globalData/all-doc-styles/style[@style:name = current()/parent::*/@text:style-name]/*/@style:rel-width"/>
  78. <xsl:if test="$value">
  79. <xsl:attribute name="width">
  80. <xsl:value-of select="$value"/>
  81. </xsl:attribute>
  82. </xsl:if>
  83. <xsl:attribute name="class">
  84. <xsl:value-of select="translate(parent::*/@text:style-name, '.,;: %()[]/\+', '_____________')"/>
  85. </xsl:attribute>
  86. </xsl:if>
  87. <xsl:element namespace="{$namespace}" name="colgroup">
  88. <xsl:choose>
  89. <xsl:when test="function-available('common:node-set')">
  90. <xsl:call-template name="create-col-element">
  91. <xsl:with-param name="lastNodePosition" select="count(common:node-set($allStyleTabStops-RTF)/style:tab-stops/style:tab-stop)"/>
  92. <xsl:with-param name="allStyleTabStops" select="common:node-set($allStyleTabStops-RTF)"/>
  93. </xsl:call-template>
  94. </xsl:when>
  95. <xsl:when test="function-available('xalan:nodeset')">
  96. <xsl:call-template name="create-col-element">
  97. <xsl:with-param name="lastNodePosition" select="count(xalan:nodeset($allStyleTabStops-RTF)/style:tab-stops/style:tab-stop)"/>
  98. <xsl:with-param name="allStyleTabStops" select="xalan:nodeset($allStyleTabStops-RTF)"/>
  99. </xsl:call-template>
  100. </xsl:when>
  101. <xsl:when test="function-available('xt:node-set')">
  102. <xsl:call-template name="create-col-element">
  103. <xsl:with-param name="lastNodePosition" select="count(xt:node-set($allStyleTabStops-RTF)/style:tab-stops/style:tab-stop)"/>
  104. <xsl:with-param name="allStyleTabStops" select="xt:node-set($allStyleTabStops-RTF)"/>
  105. </xsl:call-template>
  106. </xsl:when>
  107. <xsl:otherwise>
  108. <xsl:message terminate="yes">ERROR: Function not found: nodeset</xsl:message>
  109. </xsl:otherwise>
  110. </xsl:choose>
  111. </xsl:element>
  112. <!-- add table data -->
  113. <xsl:choose>
  114. <xsl:when test="function-available('common:node-set')">
  115. <xsl:apply-templates mode="content-table">
  116. <xsl:with-param name="globalData" select="$globalData"/>
  117. <xsl:with-param name="allStyleTabStops" select="common:node-set($allStyleTabStops-RTF)"/>
  118. </xsl:apply-templates>
  119. </xsl:when>
  120. <xsl:when test="function-available('xalan:nodeset')">
  121. <xsl:apply-templates mode="content-table">
  122. <xsl:with-param name="globalData" select="$globalData"/>
  123. <xsl:with-param name="allStyleTabStops" select="xalan:nodeset($allStyleTabStops-RTF)"/>
  124. </xsl:apply-templates>
  125. </xsl:when>
  126. <xsl:when test="function-available('xt:node-set')">
  127. <xsl:apply-templates mode="content-table">
  128. <xsl:with-param name="globalData" select="$globalData"/>
  129. <xsl:with-param name="allStyleTabStops" select="xt:node-set($allStyleTabStops-RTF)"/>
  130. </xsl:apply-templates>
  131. </xsl:when>
  132. <xsl:otherwise>
  133. <xsl:message terminate="yes">ERROR: Function not found: nodeset</xsl:message>
  134. </xsl:otherwise>
  135. </xsl:choose>
  136. </xsl:element>
  137. </xsl:template>
  138. <!-- ************************************************ -->
  139. <!-- *** Create Table for Content Table Paragraph *** -->
  140. <!-- ************************************************ -->
  141. <!-- Usually the paragraphs in a content-table are ordered by tab-stops, which can not be displayed correctly by XHTML/CSS
  142. Therefore they will be simulated by a table -->
  143. <xsl:template match="text:p" mode="content-table">
  144. <xsl:param name="globalData"/>
  145. <xsl:param name="allStyleTabStops"/>
  146. <!-- all elements before the first tabStop -->
  147. <xsl:variable name="testNo-RTF">
  148. <xsl:apply-templates select="node()" mode="cell-content"/>
  149. </xsl:variable>
  150. <xsl:choose>
  151. <xsl:when test="function-available('common:node-set')">
  152. <xsl:variable name="tabNodePositions" select="common:node-set($testNo-RTF)"/>
  153. <xsl:element namespace="{$namespace}" name="tr">
  154. <xsl:call-template name="create-td-elements">
  155. <xsl:with-param name="lastNodePosition" select="count($allStyleTabStops/style:tab-stops/style:tab-stop)"/>
  156. <xsl:with-param name="position" select="1"/>
  157. <xsl:with-param name="allStyleTabStops" select="$allStyleTabStops"/>
  158. <xsl:with-param name="tabNodePositions" select="$tabNodePositions"/>
  159. <xsl:with-param name="globalData" select="$globalData"/>
  160. </xsl:call-template>
  161. </xsl:element>
  162. </xsl:when>
  163. <xsl:when test="function-available('xalan:nodeset')">
  164. <xsl:variable name="tabNodePositions" select="xalan:nodeset($testNo-RTF)"/>
  165. <xsl:element namespace="{$namespace}" name="tr">
  166. <xsl:call-template name="create-td-elements">
  167. <xsl:with-param name="lastNodePosition" select="count($allStyleTabStops/style:tab-stops/style:tab-stop)"/>
  168. <xsl:with-param name="position" select="1"/>
  169. <xsl:with-param name="allStyleTabStops" select="$allStyleTabStops"/>
  170. <xsl:with-param name="tabNodePositions" select="$tabNodePositions"/>
  171. <xsl:with-param name="globalData" select="$globalData"/>
  172. </xsl:call-template>
  173. </xsl:element>
  174. </xsl:when>
  175. <xsl:when test="function-available('xt:node-set')">
  176. <xsl:variable name="tabNodePositions" select="xt:node-set($testNo-RTF)"/>
  177. <xsl:element namespace="{$namespace}" name="tr">
  178. <xsl:call-template name="create-td-elements">
  179. <xsl:with-param name="lastNodePosition" select="count($allStyleTabStops/style:tab-stops/style:tab-stop)"/>
  180. <xsl:with-param name="position" select="1"/>
  181. <xsl:with-param name="allStyleTabStops" select="$allStyleTabStops"/>
  182. <xsl:with-param name="tabNodePositions" select="$tabNodePositions"/>
  183. <xsl:with-param name="globalData" select="$globalData"/>
  184. </xsl:call-template>
  185. </xsl:element>
  186. </xsl:when>
  187. <xsl:otherwise>
  188. <xsl:message terminate="yes">ERROR: Function not found: nodeset</xsl:message>
  189. </xsl:otherwise>
  190. </xsl:choose>
  191. </xsl:template>
  192. <!-- Gathering all style:tab-stops from a style-hierarchy as siblings -->
  193. <xsl:template name="get-tab-stops">
  194. <xsl:param name="globalData"/>
  195. <xsl:param name="styleName"/>
  196. <xsl:variable name="tabStyle" select="key('styles', $styleName)"/>
  197. <xsl:if test="$tabStyle/*/style:tab-stops/style:tab-stop/@style:position">
  198. <xsl:for-each select="$tabStyle/*/style:tab-stops/style:tab-stop">
  199. <xsl:copy-of select="."/>
  200. </xsl:for-each>
  201. </xsl:if>
  202. <xsl:if test="$tabStyle/@style:parent-style-name">
  203. <xsl:call-template name="get-tab-stops">
  204. <xsl:with-param name="globalData" select="$globalData"/>
  205. <xsl:with-param name="styleName" select="$tabStyle/@style:parent-style-name"/>
  206. </xsl:call-template>
  207. </xsl:if>
  208. </xsl:template>
  209. <xsl:template name="create-col-element">
  210. <xsl:param name="lastNodePosition"/>
  211. <xsl:param name="allStyleTabStops"/>
  212. <xsl:for-each select="$allStyleTabStops/style:tab-stops/style:tab-stop">
  213. <xsl:element namespace="{$namespace}" name="col">
  214. <xsl:attribute name="style">
  215. <xsl:text>width: </xsl:text>
  216. <xsl:choose>
  217. <xsl:when test="contains(@style:position, 'cm')">
  218. <xsl:call-template name="create-cell-width">
  219. <xsl:with-param name="width" select="number(substring-before(@style:position,'cm'))"/>
  220. <xsl:with-param name="unit" select="'cm'"/>
  221. <xsl:with-param name="position" select="position() - 1"/>
  222. <xsl:with-param name="allStyleTabStops" select="$allStyleTabStops"/>
  223. </xsl:call-template>
  224. </xsl:when>
  225. <xsl:when test="contains(@style:position, 'in')">
  226. <xsl:call-template name="create-cell-width">
  227. <xsl:with-param name="width" select="number(substring-before(@style:position,'in'))"/>
  228. <xsl:with-param name="unit" select="'in'"/>
  229. <xsl:with-param name="position" select="position() - 1"/>
  230. <xsl:with-param name="allStyleTabStops" select="$allStyleTabStops"/>
  231. </xsl:call-template>
  232. </xsl:when>
  233. <xsl:when test="contains(@style:position, 'ch')">
  234. <xsl:call-template name="create-cell-width">
  235. <xsl:with-param name="width" select="number(substring-before(@style:position,'ch'))"/>
  236. <xsl:with-param name="unit" select="'ch'"/>
  237. <xsl:with-param name="position" select="position() - 1"/>
  238. <xsl:with-param name="allStyleTabStops" select="$allStyleTabStops"/>
  239. </xsl:call-template>
  240. </xsl:when>
  241. <xsl:when test="contains(@style:position, 'pt')">
  242. <xsl:call-template name="create-cell-width">
  243. <xsl:with-param name="width" select="number(substring-before(@style:position,'pt'))"/>
  244. <xsl:with-param name="unit" select="'pt'"/>
  245. <xsl:with-param name="position" select="position() - 1"/>
  246. <xsl:with-param name="allStyleTabStops" select="$allStyleTabStops"/>
  247. </xsl:call-template>
  248. </xsl:when>
  249. </xsl:choose>
  250. </xsl:attribute>
  251. </xsl:element>
  252. </xsl:for-each>
  253. </xsl:template>
  254. <!--
  255. Scenarios tabstops
  256. 1) style:type of style:tab-stop is 'right' and earlier tabStop is not right
  257. -> Earlier text-nodes and following text-nodes, will be put into an inner table, with two TD first aligned left, with preceding textnodes, the latter aligned right.
  258. 2) style:type is 'right' and earlier tabStop is right
  259. -> following text-nodes, will be put into a right aligned TD
  260. 3) style:type is 'non-right' and earlier tabStop 'non-right' as well
  261. -> put the preceding tab stops into a TD (left aligned is default)
  262. 4) first style:type would have no right preceding tabStop
  263. -> works well with first sceanrios 1 and 3
  264. 5) last style:type would be a special case, if it would be left aligned, but this won't happen in our case... :D
  265. Scenarios unmatched:
  266. - text:styleposition 'center' will not be matched in our case (effort for nothing), there will be only 'right' and not 'right'
  267. - If the last tabStop is not from text:styleposition 'right', the length of the last cell is undefined and a document length must be found.
  268. Not happens in our master document case. Also the algorithm below would have to be expanded (cp. scenario 5).
  269. -->
  270. <xsl:template name="create-td-elements">
  271. <xsl:param name="globalData"/>
  272. <xsl:param name="lastNodePosition"/>
  273. <xsl:param name="position"/>
  274. <xsl:param name="allStyleTabStops"/>
  275. <xsl:param name="tabNodePositions"/>
  276. <xsl:variable name="currentTabStop" select="$allStyleTabStops/style:tab-stops/style:tab-stop[$position]"/>
  277. <xsl:variable name="earlierTabStop" select="$allStyleTabStops/style:tab-stops/style:tab-stop[$position - 1]"/>
  278. <xsl:choose>
  279. <xsl:when test="not($currentTabStop/@style:position) and not($earlierTabStop/@style:position)">
  280. <!-- in case no TAB STOP is being set -->
  281. <xsl:element namespace="{$namespace}" name="td">
  282. <xsl:element namespace="{$namespace}" name="p">
  283. <xsl:if test="$position = 1">
  284. <xsl:attribute name="class">
  285. <xsl:value-of select="translate(@text:style-name, '.,;: %()[]/\+', '_____________')"/>
  286. </xsl:attribute>
  287. </xsl:if>
  288. <xsl:apply-templates mode="content-table">
  289. <xsl:with-param name="globalData" select="$globalData"/>
  290. </xsl:apply-templates>
  291. </xsl:element>
  292. </xsl:element>
  293. </xsl:when>
  294. <xsl:otherwise>
  295. <xsl:choose>
  296. <xsl:when test="$currentTabStop/@style:type = 'right'">
  297. <xsl:choose>
  298. <xsl:when test="$earlierTabStop/@style:type = 'right'">
  299. <!--
  300. 2) style:type is 'right' and earlier tabStop is right
  301. -> following text-nodes, will be put into a right aligned TD -->
  302. <xsl:element namespace="{$namespace}" name="td">
  303. <xsl:attribute name="style">
  304. <xsl:text>align: right</xsl:text>
  305. </xsl:attribute>
  306. <xsl:element namespace="{$namespace}" name="p">
  307. <xsl:if test="$position = 1">
  308. <xsl:attribute name="class">
  309. <xsl:value-of select="translate(@text:style-name, '.,;: %()[]/\+', '_____________')"/>
  310. </xsl:attribute>
  311. </xsl:if>
  312. <xsl:call-template name="grab-cell-content-before-tab-stop">
  313. <xsl:with-param name="globalData" select="$globalData"/>
  314. <xsl:with-param name="endingTabStopPosition" select="$position + 1"/>
  315. <xsl:with-param name="lastNodePosition" select="$lastNodePosition"/>
  316. <xsl:with-param name="tabNodePositions" select="$tabNodePositions"/>
  317. </xsl:call-template>
  318. </xsl:element>
  319. </xsl:element>
  320. </xsl:when>
  321. <xsl:otherwise>
  322. <xsl:element namespace="{$namespace}" name="td">
  323. <xsl:element namespace="{$namespace}" name="p">
  324. <xsl:if test="$position = 1">
  325. <xsl:attribute name="class">
  326. <xsl:value-of select="translate(@text:style-name, '.,;: %()[]/\+', '_____________')"/>
  327. </xsl:attribute>
  328. </xsl:if>
  329. <xsl:call-template name="grab-cell-content-before-tab-stop">
  330. <xsl:with-param name="globalData" select="$globalData"/>
  331. <xsl:with-param name="endingTabStopPosition" select="$position"/>
  332. <xsl:with-param name="lastNodePosition" select="$lastNodePosition"/>
  333. <xsl:with-param name="tabNodePositions" select="$tabNodePositions"/>
  334. </xsl:call-template>
  335. </xsl:element>
  336. </xsl:element>
  337. </xsl:otherwise>
  338. </xsl:choose>
  339. </xsl:when>
  340. <xsl:otherwise>
  341. <xsl:choose>
  342. <xsl:when test="$earlierTabStop/@style:type = 'right'"></xsl:when>
  343. <xsl:otherwise>
  344. <!--
  345. 3) style:type is 'non-right' and earlier tabStop 'non-right' as well
  346. -> put the preceding tab stops into a TD (left aligned is default) -->
  347. <xsl:element namespace="{$namespace}" name="p">
  348. <xsl:if test="$position = 1">
  349. <xsl:attribute name="class">
  350. <xsl:value-of select="translate(@text:style-name, '.,;: %()[]/\+', '_____________')"/>
  351. </xsl:attribute>
  352. </xsl:if>
  353. <xsl:element namespace="{$namespace}" name="td">
  354. <xsl:call-template name="grab-cell-content-before-tab-stop">
  355. <xsl:with-param name="globalData" select="$globalData"/>
  356. <xsl:with-param name="endingTabStopPosition" select="$position"/>
  357. <xsl:with-param name="lastNodePosition" select="$lastNodePosition"/>
  358. <xsl:with-param name="tabNodePositions" select="$tabNodePositions"/>
  359. </xsl:call-template>
  360. </xsl:element>
  361. </xsl:element>
  362. </xsl:otherwise>
  363. </xsl:choose>
  364. </xsl:otherwise>
  365. </xsl:choose>
  366. <xsl:if test="$position != $lastNodePosition">
  367. <xsl:call-template name="create-td-elements">
  368. <xsl:with-param name="globalData" select="$globalData"/>
  369. <xsl:with-param name="lastNodePosition" select="$lastNodePosition"/>
  370. <xsl:with-param name="position" select="$position + 1"/>
  371. <xsl:with-param name="allStyleTabStops" select="$allStyleTabStops"/>
  372. <xsl:with-param name="tabNodePositions" select="$tabNodePositions"/>
  373. </xsl:call-template>
  374. </xsl:if>
  375. </xsl:otherwise>
  376. </xsl:choose>
  377. </xsl:template>
  378. <xsl:template name="grab-cell-content-before-tab-stop">
  379. <xsl:param name="globalData"/>
  380. <xsl:param name="endingTabStopPosition"/>
  381. <xsl:param name="tabNodePositions"/>
  382. <xsl:param name="lastNodePosition"/>
  383. <xsl:choose>
  384. <xsl:when test="$endingTabStopPosition = 1">
  385. <xsl:apply-templates mode="content-table" select="node()[position() &lt; $tabNodePositions/tab-stop-node-position[$endingTabStopPosition]]">
  386. <xsl:with-param name="globalData" select="$globalData"/>
  387. </xsl:apply-templates>
  388. </xsl:when>
  389. <xsl:when test="$endingTabStopPosition > $lastNodePosition">
  390. <xsl:apply-templates mode="content-table" select="node()[position() > $tabNodePositions/tab-stop-node-position[$endingTabStopPosition - 1]]">
  391. <xsl:with-param name="globalData" select="$globalData"/>
  392. </xsl:apply-templates>
  393. </xsl:when>
  394. <xsl:otherwise>
  395. <xsl:variable name="nodesOfNextColumn" select="node()[position() &lt; $tabNodePositions/tab-stop-node-position[$endingTabStopPosition]][position() &gt; $tabNodePositions/tab-stop-node-position[$endingTabStopPosition - 1]]"/>
  396. <xsl:choose>
  397. <xsl:when test="$nodesOfNextColumn != ''">
  398. <xsl:apply-templates mode="content-table" select="$nodesOfNextColumn">
  399. <xsl:with-param name="globalData" select="$globalData"/>
  400. </xsl:apply-templates>
  401. </xsl:when>
  402. <xsl:otherwise>
  403. <xsl:apply-templates mode="content-table">
  404. <xsl:with-param name="globalData" select="$globalData"/>
  405. </xsl:apply-templates>
  406. </xsl:otherwise>
  407. </xsl:choose>
  408. </xsl:otherwise>
  409. </xsl:choose>
  410. </xsl:template>
  411. <!-- As the span width will be mapped to column width, the preceding span widths have to be subtracted -->
  412. <xsl:template name="create-cell-width">
  413. <xsl:param name="width"/>
  414. <xsl:param name="unit"/>
  415. <xsl:param name="position"/>
  416. <xsl:param name="allStyleTabStops"/>
  417. <xsl:choose>
  418. <!-- beyond second width -->
  419. <xsl:when test="$position > 1">
  420. <xsl:call-template name="create-cell-width">
  421. <xsl:with-param name="width" select="$width - number(substring-before($allStyleTabStops/style:tab-stops/style:tab-stop[$position]/@style:position,$unit))"/>
  422. <xsl:with-param name="unit" select="$unit"/>
  423. <xsl:with-param name="position" select="$position - 1"/>
  424. <xsl:with-param name="allStyleTabStops" select="$allStyleTabStops"/>
  425. </xsl:call-template>
  426. </xsl:when>
  427. <!-- second width -->
  428. <xsl:when test="$position = 1">
  429. <xsl:value-of select="concat($width - number(substring-before($allStyleTabStops/style:tab-stops/style:tab-stop[$position]/@style:position,$unit)), $unit)"/>
  430. </xsl:when>
  431. <!-- first width -->
  432. <xsl:otherwise>
  433. <xsl:value-of select="concat($width, $unit)"/>
  434. </xsl:otherwise>
  435. </xsl:choose>
  436. </xsl:template>
  437. <!-- ************************************** -->
  438. <!-- CREATION OF A CONTENT TABLE LINK -->
  439. <!-- ************************************** -->
  440. <xsl:key name="bookmark" match="text:bookmark | text:bookmark-start" use="@text:name"/>
  441. <!-- content table link -->
  442. <xsl:template match="text:a" mode="content-table">
  443. <xsl:param name="globalData"/>
  444. <xsl:variable name="name" select="substring(@xlink:href,2)"/>
  445. <xsl:variable name="text">
  446. <xsl:choose>
  447. <!-- heuristic assumption that first in a content table row, there is numbering (if at all) and then the text,
  448. furthermore that a tab will separate the to be neglected page number -->
  449. <xsl:when test="text:tab">
  450. <xsl:call-template name="write-text-without-line-numbers">
  451. <xsl:with-param name="textCount" select="count(text())"/>
  452. </xsl:call-template>
  453. </xsl:when>
  454. <xsl:otherwise>
  455. <xsl:value-of select="text()"/>
  456. </xsl:otherwise>
  457. </xsl:choose>
  458. </xsl:variable>
  459. <!-- REFERENCE HANDLING - HREF -->
  460. <xsl:element namespace="{$namespace}" name="a">
  461. <xsl:attribute name="href">
  462. <xsl:text>#</xsl:text>
  463. <xsl:choose>
  464. <xsl:when test="key('bookmark',$name)">
  465. <xsl:value-of select="$name"/>
  466. </xsl:when>
  467. <xsl:otherwise>
  468. <xsl:value-of select='concat("a_", translate(normalize-space($text), "&#xA;&amp;&lt;&gt;.,;: %()[]/\+", "_______________________________"))'/>
  469. </xsl:otherwise>
  470. </xsl:choose>
  471. </xsl:attribute>
  472. <xsl:value-of select="$text"/>
  473. </xsl:element>
  474. </xsl:template>
  475. <!-- Heuristic: write out text separated by elements, leaving the last number out (mostly text number) -->
  476. <xsl:template name="write-text-without-line-numbers">
  477. <xsl:param name="textCount"/>
  478. <xsl:param name="textNodeNumber" select="1"/>
  479. <xsl:choose>
  480. <xsl:when test="$textCount &gt; $textNodeNumber">
  481. <xsl:value-of select="text()[$textNodeNumber]"/>
  482. <xsl:call-template name="write-text-without-line-numbers">
  483. <xsl:with-param name="textCount" select="$textCount"/>
  484. <xsl:with-param name="textNodeNumber" select="$textNodeNumber + 1"/>
  485. </xsl:call-template>
  486. </xsl:when>
  487. <xsl:otherwise>
  488. <xsl:if test="not(number(text()[$textNodeNumber]) &gt; -1)">
  489. <xsl:value-of select="text()[$textNodeNumber]"/>
  490. </xsl:if>
  491. </xsl:otherwise>
  492. </xsl:choose>
  493. </xsl:template>
  494. <xsl:template match="text:s" mode="content-table">
  495. <xsl:call-template name="write-breakable-whitespace">
  496. <xsl:with-param name="whitespaces" select="@text:c"/>
  497. </xsl:call-template>
  498. </xsl:template>
  499. <!-- ******************** -->
  500. <!-- *** Common Rules *** -->
  501. <!-- ******************** -->
  502. <xsl:template match="*" mode="content-table">
  503. <xsl:param name="globalData"/>
  504. <xsl:apply-templates select=".">
  505. <xsl:with-param name="globalData" select="$globalData"/>
  506. </xsl:apply-templates>
  507. </xsl:template>
  508. <xsl:template match="*" mode="cell-content">
  509. <xsl:if test="name() = 'text:tab' or *[name() = 'text:tab']">
  510. <xsl:element name="tab-stop-node-position" namespace="">
  511. <xsl:value-of select="position()"/>
  512. </xsl:element>
  513. </xsl:if>
  514. </xsl:template>
  515. <xsl:template match="text()" mode="content-table">
  516. <!-- Heuristic to remove page numbers (useless in HTML) in the content table
  517. usually after a tab -->
  518. <xsl:if test="name(preceding-sibling::*[1]) != 'text:tab' and not(number() &gt; -1)">
  519. <xsl:value-of select="."/>
  520. </xsl:if>
  521. </xsl:template>
  522. </xsl:stylesheet>