dita2odt-utilities.xsl 62 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- This file is part of the DITA Open Toolkit project.
  3. See the accompanying license.txt file for applicable licenses. -->
  4. <!-- (c) Copyright IBM Corp. 2006 All Rights Reserved. -->
  5. <xsl:stylesheet
  6. xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  7. xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0"
  8. xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0"
  9. xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0"
  10. xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0"
  11. xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0"
  12. xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0"
  13. xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:dc="http://purl.org/dc/elements/1.1/"
  14. xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0"
  15. xmlns:presentation="urn:oasis:names:tc:opendocument:xmlns:presentation:1.0"
  16. xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0"
  17. xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0"
  18. xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0"
  19. xmlns:math="http://www.w3.org/1998/Math/MathML"
  20. xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0"
  21. xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0"
  22. xmlns:dom="http://www.w3.org/2001/xml-events" xmlns:xforms="http://www.w3.org/2002/xforms"
  23. xmlns:xsd="http://www.w3.org/2001/XMLSchema"
  24. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  25. xmlns:anim="urn:oasis:names:tc:opendocument:xmlns:animation:1.0"
  26. xmlns:smil="urn:oasis:names:tc:opendocument:xmlns:smil-compatible:1.0"
  27. xmlns:prodtools="http://www.ibm.com/xmlns/prodtools"
  28. version="2.0"
  29. xmlns:ditamsg="http://dita-ot.sourceforge.net/ns/200704/ditamsg"
  30. exclude-result-prefixes="ditamsg">
  31. <!-- =========== TEMPLATES FOR CALCULATING NESTED TAGS
  32. NOTE:SOME TAGS' NUMBER ARE MULTPLIED BY A NUMBER FOR FLAGGING STYLES.=========== -->
  33. <xsl:template name="calculate_list_depth">
  34. <xsl:param name="list_class" select="' topic/li '"/>
  35. <xsl:value-of select="count(ancestor::*[contains(@class, $list_class)])"/>
  36. </xsl:template>
  37. <xsl:template name="calculate_span_depth_for_tag">
  38. <xsl:param name="tag_class" select="' topic/fn '"/>
  39. <xsl:variable name="fig_count" select="(count(ancestor::*[contains(@class, ' topic/fig ')]) -
  40. count(ancestor::*[contains(@class, $tag_class)][1]/ancestor::*[contains(@class, ' topic/fig ')])) * 2"/>
  41. <xsl:variable name="lq_count" select="(count(ancestor::*[contains(@class, ' topic/lq ')]) -
  42. count(ancestor::*[contains(@class, $tag_class)][1]/ancestor::*[contains(@class, ' topic/lq ')])) * 2"/>
  43. <xsl:variable name="note_count" select="(count(ancestor::*[contains(@class, ' topic/note ')]) -
  44. count(ancestor::*[contains(@class, $tag_class)][1]/ancestor::*[contains(@class, ' topic/note ')])) * 3"/>
  45. <xsl:variable name="itemgroup_count" select="(count(ancestor::*[contains(@class, ' topic/itemgroup ')]) -
  46. count(ancestor::*[contains(@class, $tag_class)][1]/ancestor::*[contains(@class, ' topic/itemgroup ')])) * 2"/>
  47. <xsl:variable name="p_count" select="(count(ancestor::*[contains(@class, ' topic/p ')]) -
  48. count(ancestor::*[contains(@class, $tag_class)][1]/ancestor::*[contains(@class, ' topic/p ')])) * 2"/>
  49. <xsl:variable name="draft-comment_count" select="(count(ancestor::*[contains(@class, ' topic/draft-comment ')]) -
  50. count(ancestor::*[contains(@class, $tag_class)][1]/ancestor::*[contains(@class, ' topic/draft-comment ')])) * 2"/>
  51. <xsl:variable name="required-cleanup_count" select="(count(ancestor::*[contains(@class, ' topic/required-cleanup ')]) -
  52. count(ancestor::*[contains(@class, $tag_class)][1]/ancestor::*[contains(@class, ' topic/required-cleanup ')])) * 2"/>
  53. <xsl:variable name="dd_count" select="(count(ancestor::*[contains(@class, ' topic/dd ')]) -
  54. count(ancestor::*[contains(@class, $tag_class)][1]/ancestor::*[contains(@class, ' topic/dd ')])) * 2"/>
  55. <!-- sthead/thead count important! -->
  56. <xsl:variable name="thead_count">
  57. <xsl:choose>
  58. <xsl:when test="ancestor::*[contains(@class, ' topic/sthead ')]">
  59. <xsl:value-of select="1"/>
  60. </xsl:when>
  61. <xsl:when test="ancestor::*[contains(@class, ' topic/thead ')]">
  62. <xsl:value-of select="1"/>
  63. </xsl:when>
  64. <xsl:otherwise>0</xsl:otherwise>
  65. </xsl:choose>
  66. </xsl:variable>
  67. <xsl:variable name="total_count" select="$fig_count + $lq_count +
  68. $note_count + $itemgroup_count + $p_count + $draft-comment_count +
  69. $required-cleanup_count + $dd_count + $thead_count"/>
  70. <xsl:choose>
  71. <!-- fn is rendered as text:p plus flagging styles-->
  72. <xsl:when test="$tag_class = ' topic/fn '">
  73. <xsl:value-of select="$total_count + 1"/>
  74. </xsl:when>
  75. <xsl:otherwise>
  76. <!-- 1st one is rendered as p -->
  77. <xsl:value-of select="$total_count - 1"/>
  78. </xsl:otherwise>
  79. </xsl:choose>
  80. </xsl:template>
  81. <xsl:template name="calculate_span_depth">
  82. <xsl:variable name="desc_count" select="count(ancestor::*[contains(@class, ' topic/desc ')])"/>
  83. <xsl:variable name="fig_count" select="count(ancestor::*[contains(@class, ' topic/fig ')]) * 2"/>
  84. <xsl:variable name="figgroup_count" select="count(ancestor::*[contains(@class, ' topic/figgroup ')]) * 2"/>
  85. <xsl:variable name="lq_count" select="count(ancestor::*[contains(@class, ' topic/lq ')]) * 2"/>
  86. <xsl:variable name="lines_count" select="count(ancestor::*[contains(@class, ' topic/lines ')]) * 2"/>
  87. <!-- Add 1 for flagging sytles -->
  88. <xsl:variable name="note_count" select="count(ancestor::*[contains(@class, ' topic/note ')]) * 3"/>
  89. <xsl:variable name="p_count" select="count(ancestor::*[contains(@class, ' topic/p ')]) * 2"/>
  90. <xsl:variable name="ph_count" select="count(ancestor::*[contains(@class, ' topic/ph ')]) * 2"/>
  91. <xsl:variable name="pre_count" select="count(ancestor::*[contains(@class, ' topic/pre ')]) * 2"/>
  92. <xsl:variable name="draft-comment_count" select="count(ancestor::*[contains(@class, ' topic/draft-comment ')]) * 2"/>
  93. <xsl:variable name="required-cleanup_count" select="count(ancestor::*[contains(@class, ' topic/required-cleanup ')]) * 2"/>
  94. <xsl:variable name="itemgroup_count" select="count(ancestor::*[contains(@class, ' topic/itemgroup ')]) * 2"/>
  95. <xsl:variable name="dd_count" select="count(ancestor::*[contains(@class, ' topic/dd ')]) * 2"/>
  96. <xsl:variable name="fn_count" select="count(ancestor::*[contains(@class, ' topic/fn ')]) * 2"/>
  97. <xsl:variable name="abstract_count" select="count(ancestor::*[contains(@class, ' topic/abstract ')])"/>
  98. <xsl:variable name="bodydiv_count" select="count(ancestor::*[contains(@class, ' topic/bodydiv ')])"/>
  99. <xsl:variable name="section_count" select="count(ancestor::*[contains(@class, ' topic/section ')]) * 2"/>
  100. <xsl:variable name="sectiondiv_count" select="count(ancestor::*[contains(@class, ' topic/sectiondiv ')])"/>
  101. <xsl:variable name="example_count">
  102. <xsl:choose>
  103. <xsl:when test="ancestor::*[contains(@class, ' topic/example ')]">
  104. <xsl:value-of select="count(ancestor::*[contains(@class, ' topic/example ')]) * 2"/>
  105. </xsl:when>
  106. <xsl:otherwise>0</xsl:otherwise>
  107. </xsl:choose>
  108. </xsl:variable>
  109. <xsl:variable name="linkinfo_count" select="0"/>
  110. <xsl:variable name="related-links_count" select="count(ancestor::*[contains(@class, ' topic/related-links ')])"/>
  111. <xsl:variable name="pd_count" select="count(ancestor::*[contains(@class, ' topic/pd ')])"/>
  112. <xsl:variable name="total_count" select="$desc_count + $fig_count + $figgroup_count
  113. + $lq_count + $lines_count + $note_count + $p_count + $ph_count + $pre_count + $draft-comment_count + $required-cleanup_count
  114. + $itemgroup_count + $dd_count + $fn_count + $abstract_count + $bodydiv_count + $section_count + $sectiondiv_count
  115. + $example_count + $linkinfo_count + $related-links_count + $pd_count"/>
  116. <!-- remove the first one rendered by text:p -->
  117. <xsl:value-of select="$total_count - 1"/>
  118. </xsl:template>
  119. <xsl:template name="break_span_tags">
  120. <xsl:param name="depth" select="0"/>
  121. <xsl:param name="order" select="0"/>
  122. <!--1st: move out -->
  123. <xsl:if test="$depth &gt; 0 and $order = 0">
  124. <xsl:text disable-output-escaping="yes">&lt;/text:span&gt;</xsl:text>
  125. <xsl:call-template name="break_span_tags">
  126. <xsl:with-param name="depth" select="$depth - 1"/>
  127. <xsl:with-param name="order" select="$order"/>
  128. </xsl:call-template>
  129. </xsl:if>
  130. <!--2nd: move in -->
  131. <xsl:if test="$depth &gt; 0 and $order &gt; 0">
  132. <xsl:text disable-output-escaping="yes">&lt;text:span&gt;</xsl:text>
  133. <xsl:call-template name="break_span_tags">
  134. <xsl:with-param name="depth" select="$depth - 1"/>
  135. <xsl:with-param name="order" select="$order"/>
  136. </xsl:call-template>
  137. </xsl:if>
  138. </xsl:template>
  139. <xsl:template name="create_items_for_list">
  140. <xsl:param name="depth" select="0"/>
  141. <xsl:param name="order" select="0"/>
  142. <!--1st: move out -->
  143. <xsl:if test="$depth &gt; 0 and $order = 0">
  144. <xsl:text disable-output-escaping="yes">&lt;/text:list-item&gt;</xsl:text>
  145. <xsl:text disable-output-escaping="yes">&lt;/text:list&gt;</xsl:text>
  146. <xsl:call-template name="create_items_for_list">
  147. <xsl:with-param name="depth" select="$depth - 1"/>
  148. <xsl:with-param name="order" select="$order"/>
  149. </xsl:call-template>
  150. </xsl:if>
  151. <!--2nd: move in -->
  152. <xsl:if test="$depth &gt; 0 and $order &gt; 0">
  153. <!-- for ol, we should keep the item number correctly. -->
  154. <xsl:choose>
  155. <xsl:when test="ancestor::*[contains(@class, ' topic/ol ')]">
  156. <xsl:text disable-output-escaping="yes">&lt;text:list text:continue-numbering="true" text:style-name="ordered_list_style"&gt;</xsl:text>
  157. </xsl:when>
  158. <xsl:otherwise>
  159. <xsl:text disable-output-escaping="yes">&lt;text:list text:continue-numbering="true" text:style-name="list_style"&gt;</xsl:text>
  160. </xsl:otherwise>
  161. </xsl:choose>
  162. <!-- render list item -->
  163. <xsl:text disable-output-escaping="yes">&lt;text:list-item&gt;</xsl:text>
  164. <xsl:call-template name="create_items_for_list">
  165. <xsl:with-param name="depth" select="$depth - 1"/>
  166. <xsl:with-param name="order" select="$order"/>
  167. </xsl:call-template>
  168. </xsl:if>
  169. </xsl:template>
  170. <xsl:template name="set_align_value">
  171. <xsl:choose>
  172. <xsl:when test="parent::*[contains(@class, ' topic/entry ')]/@align = 'left'">
  173. <xsl:attribute name="text:style-name">left</xsl:attribute>
  174. </xsl:when>
  175. <xsl:when test="parent::*[contains(@class, ' topic/entry ')]/@align = 'right'">
  176. <xsl:attribute name="text:style-name">right</xsl:attribute>
  177. </xsl:when>
  178. <xsl:when test="parent::*[contains(@class, ' topic/entry ')]/@align = 'center'">
  179. <xsl:attribute name="text:style-name">center</xsl:attribute>
  180. </xsl:when>
  181. <xsl:when test="parent::*[contains(@class, ' topic/entry ')]/@align = 'justify'">
  182. <xsl:attribute name="text:style-name">justify</xsl:attribute>
  183. </xsl:when>
  184. <xsl:otherwise>
  185. <xsl:attribute name="text:style-name">left</xsl:attribute>
  186. </xsl:otherwise>
  187. </xsl:choose>
  188. </xsl:template>
  189. <xsl:template name="render_simpletable">
  190. <xsl:variable name="dlentry_count_for_list" select="count(ancestor::*[contains(@class, ' topic/dlentry ')]) -
  191. count(ancestor::*[contains(@class, ' topic/li ')][1]/ancestor::*[contains(@class, ' topic/dlentry ')])"/>
  192. <xsl:variable name="fn_depth" select="count(ancestor::*[contains(@class, ' topic/fn ')][1]/ancestor::*)"/>
  193. <xsl:variable name="list_depth" select="count(ancestor::*[contains(@class, ' topic/li ')][1]/ancestor::*)"/>
  194. <xsl:variable name="dlist_depth" select="count(ancestor::*[contains(@class, ' topic/dlentry ')][1]/ancestor::*)"/>
  195. <xsl:variable name="table_depth" select="count(ancestor::*[contains(@class, ' topic/entry ')][1]/ancestor::*)"/>
  196. <xsl:variable name="stable_depth" select="count(ancestor::*[contains(@class, ' topic/stentry ')][1]/ancestor::*)"/>
  197. <xsl:variable name="max_depth" select="max(($fn_depth, $list_depth, $dlist_depth, $table_depth, $stable_depth))"/>
  198. <!-- if the table is under p(direct child) -->
  199. <xsl:choose>
  200. <!-- parent tag is body -->
  201. <xsl:when test="parent::*[contains(@class, ' topic/body ')]">
  202. <!-- start render table -->
  203. <xsl:call-template name="create_simpletable"/>
  204. </xsl:when>
  205. <!-- nested by list -->
  206. <xsl:when test="ancestor::*[contains(@class, ' topic/li ')] and $dlentry_count_for_list = 0">
  207. <xsl:choose>
  208. <!-- nearest tag is list -->
  209. <xsl:when test="$max_depth = $list_depth">
  210. <!-- caculate list depth -->
  211. <xsl:variable name="depth">
  212. <xsl:call-template name="calculate_list_depth"/>
  213. </xsl:variable>
  214. <!-- caculate span tag depth -->
  215. <xsl:variable name="span_depth">
  216. <xsl:call-template name="calculate_span_depth_for_tag">
  217. <xsl:with-param name="tag_class" select="' topic/li '"/>
  218. </xsl:call-template>
  219. </xsl:variable>
  220. <!-- break span tags -->
  221. <xsl:call-template name="break_span_tags">
  222. <xsl:with-param name="depth" select="$span_depth"/>
  223. <xsl:with-param name="order" select="0"/>
  224. </xsl:call-template>
  225. <!-- break first p tag if there are span tags -->
  226. <xsl:if test="$span_depth &gt;= 0">
  227. <xsl:text disable-output-escaping="yes">&lt;/text:p&gt;</xsl:text>
  228. </xsl:if>
  229. <!-- break list tag -->
  230. <xsl:call-template name="create_items_for_list">
  231. <xsl:with-param name="depth" select="$depth"/>
  232. <xsl:with-param name="order" select="0"/>
  233. </xsl:call-template>
  234. <!-- start render table -->
  235. <xsl:call-template name="create_simpletable"/>
  236. <!-- start list tag again -->
  237. <xsl:call-template name="create_items_for_list">
  238. <xsl:with-param name="depth" select="$depth"/>
  239. <xsl:with-param name="order" select="1"/>
  240. </xsl:call-template>
  241. <!-- start p tag again if there are span tags-->
  242. <xsl:if test="$span_depth &gt;= 0">
  243. <xsl:text disable-output-escaping="yes">&lt;text:p&gt;</xsl:text>
  244. </xsl:if>
  245. <!-- start render span tags again-->
  246. <xsl:call-template name="break_span_tags">
  247. <xsl:with-param name="depth" select="$span_depth"/>
  248. <xsl:with-param name="order" select="1"/>
  249. </xsl:call-template>
  250. </xsl:when>
  251. <!-- nearest tag is fn -->
  252. <xsl:when test="$max_depth = $fn_depth">
  253. <!-- normal process -->
  254. <xsl:variable name="span_depth">
  255. <xsl:call-template name="calculate_span_depth"/>
  256. </xsl:variable>
  257. <!-- break span tags -->
  258. <xsl:call-template name="break_span_tags">
  259. <xsl:with-param name="depth" select="$span_depth"/>
  260. <xsl:with-param name="order" select="0"/>
  261. </xsl:call-template>
  262. <!-- break first p tag if there are span tags -->
  263. <xsl:text disable-output-escaping="yes">&lt;/text:p&gt;</xsl:text>
  264. <!-- start render table -->
  265. <xsl:call-template name="create_simpletable"/>
  266. <!-- start p tag again if there are span tags-->
  267. <xsl:text disable-output-escaping="yes">&lt;text:p&gt;</xsl:text>
  268. <!-- start render span tags again-->
  269. <xsl:call-template name="break_span_tags">
  270. <xsl:with-param name="depth" select="$span_depth"/>
  271. <xsl:with-param name="order" select="1"/>
  272. </xsl:call-template>
  273. </xsl:when>
  274. <!-- nearest tag is table -->
  275. <xsl:when test="$max_depth = $table_depth">
  276. <xsl:variable name="span_depth">
  277. <xsl:call-template name="calculate_span_depth_for_tag">
  278. <xsl:with-param name="tag_class" select="' topic/entry '"/>
  279. </xsl:call-template>
  280. </xsl:variable>
  281. <!-- break span tags -->
  282. <xsl:call-template name="break_span_tags">
  283. <xsl:with-param name="depth" select="$span_depth"/>
  284. <xsl:with-param name="order" select="0"/>
  285. </xsl:call-template>
  286. <!-- break first p tag if there are span tags -->
  287. <xsl:text disable-output-escaping="yes">&lt;/text:p&gt;</xsl:text>
  288. <!-- start render table -->
  289. <xsl:call-template name="create_simpletable"/>
  290. <!-- start p tag again if there are span tags-->
  291. <xsl:text disable-output-escaping="yes">&lt;text:p&gt;</xsl:text>
  292. <!-- start render span tags again-->
  293. <xsl:call-template name="break_span_tags">
  294. <xsl:with-param name="depth" select="$span_depth"/>
  295. <xsl:with-param name="order" select="1"/>
  296. </xsl:call-template>
  297. </xsl:when>
  298. <!-- nearest tag is simpletable -->
  299. <xsl:when test="$max_depth = $stable_depth">
  300. <xsl:variable name="span_depth">
  301. <xsl:call-template name="calculate_span_depth_for_tag">
  302. <xsl:with-param name="tag_class" select="' topic/stentry '"/>
  303. </xsl:call-template>
  304. </xsl:variable>
  305. <!-- break span tags -->
  306. <xsl:call-template name="break_span_tags">
  307. <xsl:with-param name="depth" select="$span_depth"/>
  308. <xsl:with-param name="order" select="0"/>
  309. </xsl:call-template>
  310. <!-- break first p tag if there are span tags -->
  311. <xsl:text disable-output-escaping="yes">&lt;/text:p&gt;</xsl:text>
  312. <!-- start render table -->
  313. <xsl:call-template name="create_simpletable"/>
  314. <!-- start p tag again if there are span tags-->
  315. <xsl:text disable-output-escaping="yes">&lt;text:p&gt;</xsl:text>
  316. <!-- start render span tags again-->
  317. <xsl:call-template name="break_span_tags">
  318. <xsl:with-param name="depth" select="$span_depth"/>
  319. <xsl:with-param name="order" select="1"/>
  320. </xsl:call-template>
  321. </xsl:when>
  322. </xsl:choose>
  323. </xsl:when>
  324. <!-- nested by dlist -->
  325. <xsl:when test="ancestor::*[contains(@class, ' topic/dlentry ')]">
  326. <xsl:choose>
  327. <!-- nearest tag is dlist -->
  328. <xsl:when test="$max_depth = $dlist_depth">
  329. <!-- caculate list depth -->
  330. <xsl:variable name="depth">
  331. <xsl:call-template name="calculate_list_depth">
  332. <xsl:with-param name="list_class" select="' topic/dlentry '"/>
  333. </xsl:call-template>
  334. </xsl:variable>
  335. <!-- caculate span tag depth -->
  336. <xsl:variable name="span_depth">
  337. <xsl:call-template name="calculate_span_depth_for_tag">
  338. <xsl:with-param name="tag_class" select="' topic/dlentry '"/>
  339. </xsl:call-template>
  340. </xsl:variable>
  341. <!-- break span tags -->
  342. <xsl:call-template name="break_span_tags">
  343. <xsl:with-param name="depth" select="$span_depth"/>
  344. <xsl:with-param name="order" select="0"/>
  345. </xsl:call-template>
  346. <!-- break first p tag if there are span tags -->
  347. <xsl:if test="$span_depth &gt;= 0">
  348. <xsl:text disable-output-escaping="yes">&lt;/text:p&gt;</xsl:text>
  349. </xsl:if>
  350. <!-- break list tag -->
  351. <xsl:call-template name="create_items_for_list">
  352. <xsl:with-param name="depth" select="$depth"/>
  353. <xsl:with-param name="order" select="0"/>
  354. </xsl:call-template>
  355. <!-- start render table -->
  356. <xsl:call-template name="create_simpletable"/>
  357. <!-- start list tag again -->
  358. <xsl:call-template name="create_items_for_list">
  359. <xsl:with-param name="depth" select="$depth"/>
  360. <xsl:with-param name="order" select="1"/>
  361. </xsl:call-template>
  362. <!-- start p tag again if there are span tags-->
  363. <xsl:if test="$span_depth &gt;= 0">
  364. <xsl:text disable-output-escaping="yes">&lt;text:p&gt;</xsl:text>
  365. </xsl:if>
  366. <!-- start render span tags again-->
  367. <xsl:call-template name="break_span_tags">
  368. <xsl:with-param name="depth" select="$span_depth"/>
  369. <xsl:with-param name="order" select="1"/>
  370. </xsl:call-template>
  371. </xsl:when>
  372. <!-- nearest tag is fn -->
  373. <xsl:when test="$max_depth = $fn_depth">
  374. <!-- normal process -->
  375. <xsl:variable name="span_depth">
  376. <xsl:call-template name="calculate_span_depth"/>
  377. </xsl:variable>
  378. <!-- break span tags -->
  379. <xsl:call-template name="break_span_tags">
  380. <xsl:with-param name="depth" select="$span_depth"/>
  381. <xsl:with-param name="order" select="0"/>
  382. </xsl:call-template>
  383. <!-- break first p tag if there are span tags -->
  384. <xsl:text disable-output-escaping="yes">&lt;/text:p&gt;</xsl:text>
  385. <!-- start render table -->
  386. <xsl:call-template name="create_simpletable"/>
  387. <!-- start p tag again if there are span tags-->
  388. <xsl:text disable-output-escaping="yes">&lt;text:p&gt;</xsl:text>
  389. <!-- start render span tags again-->
  390. <xsl:call-template name="break_span_tags">
  391. <xsl:with-param name="depth" select="$span_depth"/>
  392. <xsl:with-param name="order" select="1"/>
  393. </xsl:call-template>
  394. </xsl:when>
  395. <!-- nearest tag is simpletable -->
  396. <xsl:when test="$max_depth = $stable_depth">
  397. <xsl:variable name="span_depth">
  398. <xsl:call-template name="calculate_span_depth_for_tag">
  399. <xsl:with-param name="tag_class" select="' topic/stentry '"/>
  400. </xsl:call-template>
  401. </xsl:variable>
  402. <!-- break span tags -->
  403. <xsl:call-template name="break_span_tags">
  404. <xsl:with-param name="depth" select="$span_depth"/>
  405. <xsl:with-param name="order" select="0"/>
  406. </xsl:call-template>
  407. <!-- break first p tag if there are span tags -->
  408. <xsl:text disable-output-escaping="yes">&lt;/text:p&gt;</xsl:text>
  409. <!-- start render table -->
  410. <xsl:call-template name="create_simpletable"/>
  411. <!-- start p tag again if there are span tags-->
  412. <xsl:text disable-output-escaping="yes">&lt;text:p&gt;</xsl:text>
  413. <!-- start render span tags again-->
  414. <xsl:call-template name="break_span_tags">
  415. <xsl:with-param name="depth" select="$span_depth"/>
  416. <xsl:with-param name="order" select="1"/>
  417. </xsl:call-template>
  418. </xsl:when>
  419. <!-- nearest tag is table -->
  420. <xsl:when test="$max_depth = $table_depth">
  421. <xsl:variable name="span_depth">
  422. <xsl:call-template name="calculate_span_depth_for_tag">
  423. <xsl:with-param name="tag_class" select="' topic/entry '"/>
  424. </xsl:call-template>
  425. </xsl:variable>
  426. <!-- break span tags -->
  427. <xsl:call-template name="break_span_tags">
  428. <xsl:with-param name="depth" select="$span_depth"/>
  429. <xsl:with-param name="order" select="0"/>
  430. </xsl:call-template>
  431. <!-- break first p tag if there are span tags -->
  432. <xsl:text disable-output-escaping="yes">&lt;/text:p&gt;</xsl:text>
  433. <!-- start render table -->
  434. <xsl:call-template name="create_simpletable"/>
  435. <!-- start p tag again if there are span tags-->
  436. <xsl:text disable-output-escaping="yes">&lt;text:p&gt;</xsl:text>
  437. <!-- start render span tags again-->
  438. <xsl:call-template name="break_span_tags">
  439. <xsl:with-param name="depth" select="$span_depth"/>
  440. <xsl:with-param name="order" select="1"/>
  441. </xsl:call-template>
  442. </xsl:when>
  443. </xsl:choose>
  444. </xsl:when>
  445. <!-- nested by simpletable -->
  446. <xsl:when test="ancestor::*[contains(@class, ' topic/simpletable ')]">
  447. <xsl:variable name="span_depth">
  448. <xsl:call-template name="calculate_span_depth_for_tag">
  449. <xsl:with-param name="tag_class" select="' topic/stentry '"/>
  450. </xsl:call-template>
  451. </xsl:variable>
  452. <!-- break span tags -->
  453. <xsl:call-template name="break_span_tags">
  454. <xsl:with-param name="depth" select="$span_depth"/>
  455. <xsl:with-param name="order" select="0"/>
  456. </xsl:call-template>
  457. <!-- break first p tag if there are span tags -->
  458. <xsl:text disable-output-escaping="yes">&lt;/text:p&gt;</xsl:text>
  459. <!-- start render table -->
  460. <xsl:call-template name="create_simpletable"/>
  461. <!-- start p tag again if there are span tags-->
  462. <xsl:text disable-output-escaping="yes">&lt;text:p&gt;</xsl:text>
  463. <!-- start render span tags again-->
  464. <xsl:call-template name="break_span_tags">
  465. <xsl:with-param name="depth" select="$span_depth"/>
  466. <xsl:with-param name="order" select="1"/>
  467. </xsl:call-template>
  468. </xsl:when>
  469. <!-- nested by table -->
  470. <xsl:when test="ancestor::*[contains(@class, ' topic/table ')]">
  471. <xsl:variable name="span_depth">
  472. <xsl:call-template name="calculate_span_depth_for_tag">
  473. <xsl:with-param name="tag_class" select="' topic/entry '"/>
  474. </xsl:call-template>
  475. </xsl:variable>
  476. <!-- break span tags -->
  477. <xsl:call-template name="break_span_tags">
  478. <xsl:with-param name="depth" select="$span_depth"/>
  479. <xsl:with-param name="order" select="0"/>
  480. </xsl:call-template>
  481. <!-- break first p tag if there are span tags -->
  482. <xsl:text disable-output-escaping="yes">&lt;/text:p&gt;</xsl:text>
  483. <!-- start render table -->
  484. <xsl:call-template name="create_simpletable"/>
  485. <!-- start p tag again if there are span tags-->
  486. <xsl:text disable-output-escaping="yes">&lt;text:p&gt;</xsl:text>
  487. <!-- start render span tags again-->
  488. <xsl:call-template name="break_span_tags">
  489. <xsl:with-param name="depth" select="$span_depth"/>
  490. <xsl:with-param name="order" select="1"/>
  491. </xsl:call-template>
  492. </xsl:when>
  493. <xsl:otherwise>
  494. <!-- normal process -->
  495. <xsl:variable name="span_depth">
  496. <xsl:call-template name="calculate_span_depth"/>
  497. </xsl:variable>
  498. <!-- break span tags -->
  499. <xsl:call-template name="break_span_tags">
  500. <xsl:with-param name="depth" select="$span_depth"/>
  501. <xsl:with-param name="order" select="0"/>
  502. </xsl:call-template>
  503. <!-- break first p tag if there are span tags -->
  504. <xsl:text disable-output-escaping="yes">&lt;/text:p&gt;</xsl:text>
  505. <!-- start render table -->
  506. <xsl:call-template name="create_simpletable"/>
  507. <!-- start p tag again if there are span tags-->
  508. <xsl:text disable-output-escaping="yes">&lt;text:p&gt;</xsl:text>
  509. <!-- start render span tags again-->
  510. <xsl:call-template name="break_span_tags">
  511. <xsl:with-param name="depth" select="$span_depth"/>
  512. <xsl:with-param name="order" select="1"/>
  513. </xsl:call-template>
  514. </xsl:otherwise>
  515. </xsl:choose>
  516. </xsl:template>
  517. <xsl:template name="render_table">
  518. <xsl:variable name="dlentry_count_for_list" select="count(ancestor::*[contains(@class, ' topic/dlentry ')]) - count(ancestor::*[contains(@class, ' topic/li ')][1] /ancestor::*[contains(@class, ' topic/dlentry ')])"/>
  519. <xsl:variable name="fn_depth" select="count(ancestor::*[contains(@class, ' topic/fn ')][1]/ancestor::*)"/>
  520. <xsl:variable name="list_depth" select="count(ancestor::*[contains(@class, ' topic/li ')][1]/ancestor::*)"/>
  521. <xsl:variable name="dlist_depth" select="count(ancestor::*[contains(@class, ' topic/dlentry ')][1]/ancestor::*)"/>
  522. <xsl:variable name="table_depth" select="count(ancestor::*[contains(@class, ' topic/entry ')][1]/ancestor::*)"/>
  523. <xsl:variable name="stable_depth" select="count(ancestor::*[contains(@class, ' topic/stentry ')][1]/ancestor::*)"/>
  524. <xsl:variable name="max_depth" select="max(($fn_depth, $list_depth, $dlist_depth, $table_depth, $stable_depth))"/>
  525. <!-- if the table is under p(direct child) -->
  526. <xsl:choose>
  527. <!-- parent tag is body -->
  528. <xsl:when test="parent::*[contains(@class, ' topic/body ')]">
  529. <!-- start render table -->
  530. <xsl:apply-templates/>
  531. </xsl:when>
  532. <!-- nested by list -->
  533. <xsl:when test="ancestor::*[contains(@class, ' topic/li ')] and $dlentry_count_for_list = 0">
  534. <!-- nearest tag is list -->
  535. <xsl:choose>
  536. <xsl:when test="$max_depth = $list_depth">
  537. <!-- caculate list depth -->
  538. <xsl:variable name="depth">
  539. <xsl:call-template name="calculate_list_depth"/>
  540. </xsl:variable>
  541. <!-- caculate span tag depth -->
  542. <xsl:variable name="span_depth">
  543. <xsl:call-template name="calculate_span_depth_for_tag">
  544. <xsl:with-param name="tag_class" select="' topic/li '"/>
  545. </xsl:call-template>
  546. </xsl:variable>
  547. <!-- break span tags -->
  548. <xsl:call-template name="break_span_tags">
  549. <xsl:with-param name="depth" select="$span_depth"/>
  550. <xsl:with-param name="order" select="0"/>
  551. </xsl:call-template>
  552. <!-- break first p tag if there are span tags -->
  553. <xsl:if test="$span_depth &gt;= 0">
  554. <xsl:text disable-output-escaping="yes">&lt;/text:p&gt;</xsl:text>
  555. </xsl:if>
  556. <!-- break list tag -->
  557. <xsl:call-template name="create_items_for_list">
  558. <xsl:with-param name="depth" select="$depth"/>
  559. <xsl:with-param name="order" select="0"/>
  560. </xsl:call-template>
  561. <!-- start render table -->
  562. <xsl:apply-templates/>
  563. <!-- start list tag again -->
  564. <xsl:call-template name="create_items_for_list">
  565. <xsl:with-param name="depth" select="$depth"/>
  566. <xsl:with-param name="order" select="1"/>
  567. </xsl:call-template>
  568. <!-- start p tag again if there are span tags-->
  569. <xsl:if test="$span_depth &gt;= 0">
  570. <xsl:text disable-output-escaping="yes">&lt;text:p&gt;</xsl:text>
  571. </xsl:if>
  572. <!-- start render span tags again-->
  573. <xsl:call-template name="break_span_tags">
  574. <xsl:with-param name="depth" select="$span_depth"/>
  575. <xsl:with-param name="order" select="1"/>
  576. </xsl:call-template>
  577. </xsl:when>
  578. <!-- nearest tag is fn -->
  579. <xsl:when test="$max_depth = $fn_depth">
  580. <!-- normal process -->
  581. <xsl:variable name="span_depth">
  582. <xsl:call-template name="calculate_span_depth"/>
  583. </xsl:variable>
  584. <!-- break span tags -->
  585. <xsl:call-template name="break_span_tags">
  586. <xsl:with-param name="depth" select="$span_depth"/>
  587. <xsl:with-param name="order" select="0"/>
  588. </xsl:call-template>
  589. <!-- break first p tag -->
  590. <xsl:text disable-output-escaping="yes">&lt;/text:p&gt;</xsl:text>
  591. <!-- start render table -->
  592. <xsl:apply-templates/>
  593. <!-- start first p tag again -->
  594. <xsl:text disable-output-escaping="yes">&lt;text:p&gt;</xsl:text>
  595. <!-- start render span tags again-->
  596. <xsl:call-template name="break_span_tags">
  597. <xsl:with-param name="depth" select="$span_depth"/>
  598. <xsl:with-param name="order" select="1"/>
  599. </xsl:call-template>
  600. </xsl:when>
  601. <!-- nearest tag is table -->
  602. <xsl:when test="$max_depth = $table_depth">
  603. <xsl:variable name="span_depth">
  604. <xsl:call-template name="calculate_span_depth_for_tag">
  605. <xsl:with-param name="tag_class" select="' topic/entry '"/>
  606. </xsl:call-template>
  607. </xsl:variable>
  608. <!-- break span tags -->
  609. <xsl:call-template name="break_span_tags">
  610. <xsl:with-param name="depth" select="$span_depth"/>
  611. <xsl:with-param name="order" select="0"/>
  612. </xsl:call-template>
  613. <!-- break first p tag if there are span tags -->
  614. <xsl:text disable-output-escaping="yes">&lt;/text:p&gt;</xsl:text>
  615. <!-- start render table -->
  616. <xsl:apply-templates/>
  617. <!-- start p tag again if there are span tags-->
  618. <xsl:text disable-output-escaping="yes">&lt;text:p&gt;</xsl:text>
  619. <!-- start render span tags again-->
  620. <xsl:call-template name="break_span_tags">
  621. <xsl:with-param name="depth" select="$span_depth"/>
  622. <xsl:with-param name="order" select="1"/>
  623. </xsl:call-template>
  624. </xsl:when>
  625. <!-- nearest tag is simpletable -->
  626. <xsl:when test="$max_depth = $stable_depth">
  627. <xsl:variable name="span_depth">
  628. <xsl:call-template name="calculate_span_depth_for_tag">
  629. <xsl:with-param name="tag_class" select="' topic/stentry '"/>
  630. </xsl:call-template>
  631. </xsl:variable>
  632. <!-- break span tags -->
  633. <xsl:call-template name="break_span_tags">
  634. <xsl:with-param name="depth" select="$span_depth"/>
  635. <xsl:with-param name="order" select="0"/>
  636. </xsl:call-template>
  637. <!-- break first p tag if there are span tags -->
  638. <xsl:text disable-output-escaping="yes">&lt;/text:p&gt;</xsl:text>
  639. <!-- start render table -->
  640. <xsl:apply-templates/>
  641. <!-- start p tag again if there are span tags-->
  642. <xsl:text disable-output-escaping="yes">&lt;text:p&gt;</xsl:text>
  643. <!-- start render span tags again-->
  644. <xsl:call-template name="break_span_tags">
  645. <xsl:with-param name="depth" select="$span_depth"/>
  646. <xsl:with-param name="order" select="1"/>
  647. </xsl:call-template>
  648. </xsl:when>
  649. </xsl:choose>
  650. </xsl:when>
  651. <!-- nested by dlist -->
  652. <xsl:when test="ancestor::*[contains(@class, ' topic/dlentry ')]">
  653. <!-- nearest tag is dlist -->
  654. <xsl:choose>
  655. <!-- nearest tag is dlist -->
  656. <xsl:when test="$max_depth &gt; $dlist_depth">
  657. <!-- caculate list depth -->
  658. <xsl:variable name="depth">
  659. <xsl:call-template name="calculate_list_depth">
  660. <xsl:with-param name="list_class" select="' topic/dlentry '"/>
  661. </xsl:call-template>
  662. </xsl:variable>
  663. <!-- caculate span tag depth -->
  664. <xsl:variable name="span_depth">
  665. <xsl:call-template name="calculate_span_depth_for_tag">
  666. <xsl:with-param name="tag_class" select="' topic/dlentry '"/>
  667. </xsl:call-template>
  668. </xsl:variable>
  669. <!-- break span tags -->
  670. <xsl:call-template name="break_span_tags">
  671. <xsl:with-param name="depth" select="$span_depth"/>
  672. <xsl:with-param name="order" select="0"/>
  673. </xsl:call-template>
  674. <!-- break first p tag if there are span tags -->
  675. <xsl:if test="$span_depth &gt;= 0">
  676. <xsl:text disable-output-escaping="yes">&lt;/text:p&gt;</xsl:text>
  677. </xsl:if>
  678. <!-- break list tag -->
  679. <xsl:call-template name="create_items_for_list">
  680. <xsl:with-param name="depth" select="$depth"/>
  681. <xsl:with-param name="order" select="0"/>
  682. </xsl:call-template>
  683. <!-- start render table -->
  684. <xsl:apply-templates/>
  685. <!-- start list tag again -->
  686. <xsl:call-template name="create_items_for_list">
  687. <xsl:with-param name="depth" select="$depth"/>
  688. <xsl:with-param name="order" select="1"/>
  689. </xsl:call-template>
  690. <!-- start p tag again if there are span tags-->
  691. <xsl:if test="$span_depth &gt;= 0">
  692. <xsl:text disable-output-escaping="yes">&lt;text:p&gt;</xsl:text>
  693. </xsl:if>
  694. <!-- start render span tags again-->
  695. <xsl:call-template name="break_span_tags">
  696. <xsl:with-param name="depth" select="$span_depth"/>
  697. <xsl:with-param name="order" select="1"/>
  698. </xsl:call-template>
  699. </xsl:when>
  700. <!-- nearest tag is fn -->
  701. <xsl:when test="$max_depth = $fn_depth">
  702. <!-- normal process -->
  703. <xsl:variable name="span_depth">
  704. <xsl:call-template name="calculate_span_depth"/>
  705. </xsl:variable>
  706. <!-- break span tags -->
  707. <xsl:call-template name="break_span_tags">
  708. <xsl:with-param name="depth" select="$span_depth"/>
  709. <xsl:with-param name="order" select="0"/>
  710. </xsl:call-template>
  711. <!-- break first p tag -->
  712. <xsl:text disable-output-escaping="yes">&lt;/text:p&gt;</xsl:text>
  713. <!-- start render table -->
  714. <xsl:apply-templates/>
  715. <!-- start first p tag again -->
  716. <xsl:text disable-output-escaping="yes">&lt;text:p&gt;</xsl:text>
  717. <!-- start render span tags again-->
  718. <xsl:call-template name="break_span_tags">
  719. <xsl:with-param name="depth" select="$span_depth"/>
  720. <xsl:with-param name="order" select="1"/>
  721. </xsl:call-template>
  722. </xsl:when>
  723. <!-- nearest tag is table -->
  724. <xsl:when test="$max_depth = $table_depth">
  725. <xsl:variable name="span_depth">
  726. <xsl:call-template name="calculate_span_depth_for_tag">
  727. <xsl:with-param name="tag_class" select="' topic/entry '"/>
  728. </xsl:call-template>
  729. </xsl:variable>
  730. <!-- break span tags -->
  731. <xsl:call-template name="break_span_tags">
  732. <xsl:with-param name="depth" select="$span_depth"/>
  733. <xsl:with-param name="order" select="0"/>
  734. </xsl:call-template>
  735. <!-- break first p tag if there are span tags -->
  736. <xsl:text disable-output-escaping="yes">&lt;/text:p&gt;</xsl:text>
  737. <!-- start render table -->
  738. <xsl:apply-templates/>
  739. <!-- start p tag again if there are span tags-->
  740. <xsl:text disable-output-escaping="yes">&lt;text:p&gt;</xsl:text>
  741. <!-- start render span tags again-->
  742. <xsl:call-template name="break_span_tags">
  743. <xsl:with-param name="depth" select="$span_depth"/>
  744. <xsl:with-param name="order" select="1"/>
  745. </xsl:call-template>
  746. </xsl:when>
  747. <!-- nearst tag is simpletable -->
  748. <xsl:when test="$max_depth = $stable_depth">
  749. <xsl:variable name="span_depth">
  750. <xsl:call-template name="calculate_span_depth_for_tag">
  751. <xsl:with-param name="tag_class" select="' topic/stentry '"/>
  752. </xsl:call-template>
  753. </xsl:variable>
  754. <!-- break span tags -->
  755. <xsl:call-template name="break_span_tags">
  756. <xsl:with-param name="depth" select="$span_depth"/>
  757. <xsl:with-param name="order" select="0"/>
  758. </xsl:call-template>
  759. <!-- break first p tag if there are span tags -->
  760. <xsl:text disable-output-escaping="yes">&lt;/text:p&gt;</xsl:text>
  761. <!-- start render table -->
  762. <xsl:apply-templates/>
  763. <!-- start p tag again if there are span tags-->
  764. <xsl:text disable-output-escaping="yes">&lt;text:p&gt;</xsl:text>
  765. <!-- start render span tags again-->
  766. <xsl:call-template name="break_span_tags">
  767. <xsl:with-param name="depth" select="$span_depth"/>
  768. <xsl:with-param name="order" select="1"/>
  769. </xsl:call-template>
  770. </xsl:when>
  771. </xsl:choose>
  772. </xsl:when>
  773. <!-- nested by simpletable -->
  774. <xsl:when test="ancestor::*[contains(@class, ' topic/simpletable ')]">
  775. <xsl:variable name="span_depth">
  776. <xsl:call-template name="calculate_span_depth_for_tag">
  777. <xsl:with-param name="tag_class" select="' topic/stentry '"/>
  778. </xsl:call-template>
  779. </xsl:variable>
  780. <!-- break span tags -->
  781. <xsl:call-template name="break_span_tags">
  782. <xsl:with-param name="depth" select="$span_depth"/>
  783. <xsl:with-param name="order" select="0"/>
  784. </xsl:call-template>
  785. <!-- break first p tag if there are span tags -->
  786. <xsl:text disable-output-escaping="yes">&lt;/text:p&gt;</xsl:text>
  787. <!-- start render table -->
  788. <xsl:apply-templates/>
  789. <!-- start p tag again if there are span tags-->
  790. <xsl:text disable-output-escaping="yes">&lt;text:p&gt;</xsl:text>
  791. <!-- start render span tags again-->
  792. <xsl:call-template name="break_span_tags">
  793. <xsl:with-param name="depth" select="$span_depth"/>
  794. <xsl:with-param name="order" select="1"/>
  795. </xsl:call-template>
  796. </xsl:when>
  797. <!-- nested by table -->
  798. <xsl:when test="ancestor::*[contains(@class, ' topic/table ')]">
  799. <xsl:variable name="span_depth">
  800. <xsl:call-template name="calculate_span_depth_for_tag">
  801. <xsl:with-param name="tag_class" select="' topic/entry '"/>
  802. </xsl:call-template>
  803. </xsl:variable>
  804. <!-- break span tags -->
  805. <xsl:call-template name="break_span_tags">
  806. <xsl:with-param name="depth" select="$span_depth"/>
  807. <xsl:with-param name="order" select="0"/>
  808. </xsl:call-template>
  809. <!-- break first p tag if there are span tags -->
  810. <xsl:text disable-output-escaping="yes">&lt;/text:p&gt;</xsl:text>
  811. <!-- start render table -->
  812. <xsl:apply-templates/>
  813. <!-- start p tag again if there are span tags-->
  814. <xsl:text disable-output-escaping="yes">&lt;text:p&gt;</xsl:text>
  815. <!-- start render span tags again-->
  816. <xsl:call-template name="break_span_tags">
  817. <xsl:with-param name="depth" select="$span_depth"/>
  818. <xsl:with-param name="order" select="1"/>
  819. </xsl:call-template>
  820. </xsl:when>
  821. <xsl:otherwise>
  822. <!-- normal process -->
  823. <xsl:variable name="span_depth">
  824. <xsl:call-template name="calculate_span_depth"/>
  825. </xsl:variable>
  826. <!-- break span tags -->
  827. <xsl:call-template name="break_span_tags">
  828. <xsl:with-param name="depth" select="$span_depth"/>
  829. <xsl:with-param name="order" select="0"/>
  830. </xsl:call-template>
  831. <!-- break first p tag -->
  832. <xsl:text disable-output-escaping="yes">&lt;/text:p&gt;</xsl:text>
  833. <!-- start render table -->
  834. <xsl:apply-templates/>
  835. <!-- start first p tag again -->
  836. <xsl:text disable-output-escaping="yes">&lt;text:p&gt;</xsl:text>
  837. <!-- start render span tags again-->
  838. <xsl:call-template name="break_span_tags">
  839. <xsl:with-param name="depth" select="$span_depth"/>
  840. <xsl:with-param name="order" select="1"/>
  841. </xsl:call-template>
  842. </xsl:otherwise>
  843. </xsl:choose>
  844. </xsl:template>
  845. <xsl:template name="render_list">
  846. <xsl:param name="list_style"/>
  847. <xsl:variable name="li_count_for_table" select="count(ancestor::*[contains(@class, ' topic/li ')]) -
  848. count(ancestor::*[contains(@class, ' topic/entry ')][1]
  849. /ancestor::*[contains(@class, ' topic/li ')])"/>
  850. <xsl:variable name="li_count_for_simpletable" select="count(ancestor::*[contains(@class, ' topic/li ')]) -
  851. count(ancestor::*[contains(@class, ' topic/stentry ')][1]
  852. /ancestor::*[contains(@class, ' topic/li ')])"/>
  853. <xsl:variable name="dlentry_count_for_table" select="count(ancestor::*[contains(@class, ' topic/dlentry ')]) -
  854. count(ancestor::*[contains(@class, ' topic/entry ')][1]
  855. /ancestor::*[contains(@class, ' topic/dlentry ')])"/>
  856. <xsl:variable name="dlentry_count_for_simpletable" select="count(ancestor::*[contains(@class, ' topic/dlentry ')]) -
  857. count(ancestor::*[contains(@class, ' topic/stentry ')][1]
  858. /ancestor::*[contains(@class, ' topic/dlentry ')])"/>
  859. <xsl:variable name="dlentry_count_for_list" select="count(ancestor::*[contains(@class, ' topic/dlentry ')]) -
  860. count(ancestor::*[contains(@class, ' topic/li ')][1]
  861. /ancestor::*[contains(@class, ' topic/dlentry ')])"/>
  862. <xsl:choose>
  863. <!-- parent tag is body -->
  864. <xsl:when test="parent::*[contains(@class, ' topic/body ')]">
  865. <!-- start flagging -->
  866. <xsl:apply-templates select="." mode="start-add-odt-flags">
  867. <xsl:with-param name="family" select="'_list'"/>
  868. </xsl:apply-templates>
  869. <!-- start render list -->
  870. <text:list text:style-name="{$list_style}">
  871. <xsl:apply-templates/>
  872. </text:list>
  873. <!-- end flagging -->
  874. <xsl:apply-templates select="." mode="end-add-odt-flags">
  875. <xsl:with-param name="family" select="'_list'"/>
  876. </xsl:apply-templates>
  877. </xsl:when>
  878. <!-- parent by list -->
  879. <xsl:when test="parent::*[contains(@class, ' topic/li ')] or parent::*[contains(@class, ' topic/sli ')]">
  880. <!-- start flagging -->
  881. <xsl:apply-templates select="." mode="start-add-odt-flags">
  882. <xsl:with-param name="family" select="'_list'"/>
  883. </xsl:apply-templates>
  884. <!-- start render list -->
  885. <text:list text:style-name="{$list_style}">
  886. <xsl:apply-templates/>
  887. </text:list>
  888. <!-- end flagging -->
  889. <xsl:apply-templates select="." mode="end-add-odt-flags">
  890. <xsl:with-param name="family" select="'_list'"/>
  891. </xsl:apply-templates>
  892. </xsl:when>
  893. <!-- parent by entry-->
  894. <xsl:when test="parent::*[contains(@class, ' topic/entry ')]">
  895. <!-- start flagging -->
  896. <xsl:apply-templates select="." mode="start-add-odt-flags">
  897. <xsl:with-param name="family" select="'_list'"/>
  898. </xsl:apply-templates>
  899. <!-- start render list -->
  900. <text:list text:style-name="{$list_style}">
  901. <xsl:apply-templates/>
  902. </text:list>
  903. <!-- end flagging -->
  904. <xsl:apply-templates select="." mode="end-add-odt-flags">
  905. <xsl:with-param name="family" select="'_list'"/>
  906. </xsl:apply-templates>
  907. </xsl:when>
  908. <!-- parent by stentry-->
  909. <xsl:when test="parent::*[contains(@class, ' topic/stentry ')]">
  910. <!-- start flagging -->
  911. <xsl:apply-templates select="." mode="start-add-odt-flags">
  912. <xsl:with-param name="family" select="'_list'"/>
  913. </xsl:apply-templates>
  914. <!-- start render list -->
  915. <text:list text:style-name="{$list_style}">
  916. <xsl:apply-templates/>
  917. </text:list>
  918. <!-- end flagging -->
  919. <xsl:apply-templates select="." mode="end-add-odt-flags">
  920. <xsl:with-param name="family" select="'_list'"/>
  921. </xsl:apply-templates>
  922. </xsl:when>
  923. <!-- parent tag is fn -->
  924. <xsl:when test="parent::*[contains(@class, ' topic/fn ')]">
  925. <!-- break span tag(for flagging)-->
  926. <xsl:call-template name="break_span_tags">
  927. <xsl:with-param name="depth" select="1"/>
  928. <xsl:with-param name="order" select="0"/>
  929. </xsl:call-template>
  930. <!-- break p tag -->
  931. <xsl:text disable-output-escaping="yes">&lt;/text:p&gt;</xsl:text>
  932. <!-- start flagging -->
  933. <xsl:apply-templates select="." mode="start-add-odt-flags">
  934. <xsl:with-param name="family" select="'_list'"/>
  935. </xsl:apply-templates>
  936. <!-- start render list -->
  937. <text:list text:style-name="{$list_style}">
  938. <xsl:apply-templates/>
  939. </text:list>
  940. <!-- end flagging -->
  941. <xsl:apply-templates select="." mode="end-add-odt-flags">
  942. <xsl:with-param name="family" select="'_list'"/>
  943. </xsl:apply-templates>
  944. <!-- start p tag again -->
  945. <xsl:text disable-output-escaping="yes">&lt;text:p text:style-name="footnote"&gt;</xsl:text>
  946. <!-- start render span tags again-->
  947. <xsl:call-template name="break_span_tags">
  948. <xsl:with-param name="depth" select="1"/>
  949. <xsl:with-param name="order" select="1"/>
  950. </xsl:call-template>
  951. </xsl:when>
  952. <!-- nearest ancestor tag is table -->
  953. <xsl:when test="ancestor::*[contains(@class, ' topic/entry ')] and $li_count_for_table = 0 and $dlentry_count_for_table = 0">
  954. <xsl:variable name="span_depth">
  955. <xsl:call-template name="calculate_span_depth_for_tag">
  956. <xsl:with-param name="tag_class" select="' topic/entry '"/>
  957. </xsl:call-template>
  958. </xsl:variable>
  959. <!-- break span tags -->
  960. <xsl:call-template name="break_span_tags">
  961. <xsl:with-param name="depth" select="$span_depth"/>
  962. <xsl:with-param name="order" select="0"/>
  963. </xsl:call-template>
  964. <!-- break first p tag -->
  965. <xsl:text disable-output-escaping="yes">&lt;/text:p&gt;</xsl:text>
  966. <!-- start flagging -->
  967. <xsl:apply-templates select="." mode="start-add-odt-flags">
  968. <xsl:with-param name="family" select="'_list'"/>
  969. </xsl:apply-templates>
  970. <!-- start render list -->
  971. <text:list text:style-name="{$list_style}">
  972. <xsl:apply-templates/>
  973. </text:list>
  974. <!-- end flagging -->
  975. <xsl:apply-templates select="." mode="end-add-odt-flags">
  976. <xsl:with-param name="family" select="'_list'"/>
  977. </xsl:apply-templates>
  978. <!-- start first p tag again -->
  979. <xsl:text disable-output-escaping="yes">&lt;text:p&gt;</xsl:text>
  980. <!-- start render span tags again-->
  981. <xsl:call-template name="break_span_tags">
  982. <xsl:with-param name="depth" select="$span_depth"/>
  983. <xsl:with-param name="order" select="1"/>
  984. </xsl:call-template>
  985. </xsl:when>
  986. <!-- nearest ancestor tag is simpletable -->
  987. <xsl:when test="ancestor::*[contains(@class, ' topic/stentry ')] and $li_count_for_simpletable = 0
  988. and $dlentry_count_for_simpletable = 0">
  989. <xsl:variable name="span_depth">
  990. <xsl:call-template name="calculate_span_depth_for_tag">
  991. <xsl:with-param name="tag_class" select="' topic/stentry '"/>
  992. </xsl:call-template>
  993. </xsl:variable>
  994. <!-- break span tags -->
  995. <xsl:call-template name="break_span_tags">
  996. <xsl:with-param name="depth" select="$span_depth"/>
  997. <xsl:with-param name="order" select="0"/>
  998. </xsl:call-template>
  999. <!-- break first p tag -->
  1000. <xsl:text disable-output-escaping="yes">&lt;/text:p&gt;</xsl:text>
  1001. <!-- start flagging -->
  1002. <xsl:apply-templates select="." mode="start-add-odt-flags">
  1003. <xsl:with-param name="family" select="'_list'"/>
  1004. </xsl:apply-templates>
  1005. <!-- start render list -->
  1006. <text:list text:style-name="{$list_style}">
  1007. <xsl:apply-templates/>
  1008. </text:list>
  1009. <!-- end flagging -->
  1010. <xsl:apply-templates select="." mode="end-add-odt-flags">
  1011. <xsl:with-param name="family" select="'_list'"/>
  1012. </xsl:apply-templates>
  1013. <!-- start first p tag again -->
  1014. <xsl:text disable-output-escaping="yes">&lt;text:p&gt;</xsl:text>
  1015. <!-- start render span tags again-->
  1016. <xsl:call-template name="break_span_tags">
  1017. <xsl:with-param name="depth" select="$span_depth"/>
  1018. <xsl:with-param name="order" select="1"/>
  1019. </xsl:call-template>
  1020. </xsl:when>
  1021. <!-- nearest ancestor tag is li -->
  1022. <xsl:when test="ancestor::*[contains(@class, ' topic/li ')] and $dlentry_count_for_list = 0">
  1023. <xsl:variable name="span_depth">
  1024. <xsl:call-template name="calculate_span_depth_for_tag">
  1025. <xsl:with-param name="tag_class" select="' topic/li '"/>
  1026. </xsl:call-template>
  1027. </xsl:variable>
  1028. <!-- break span tags -->
  1029. <xsl:call-template name="break_span_tags">
  1030. <xsl:with-param name="depth" select="$span_depth"/>
  1031. <xsl:with-param name="order" select="0"/>
  1032. </xsl:call-template>
  1033. <!-- break first p tag -->
  1034. <xsl:text disable-output-escaping="yes">&lt;/text:p&gt;</xsl:text>
  1035. <!-- start flagging -->
  1036. <xsl:apply-templates select="." mode="start-add-odt-flags">
  1037. <xsl:with-param name="family" select="'_list'"/>
  1038. </xsl:apply-templates>
  1039. <!-- start render list -->
  1040. <text:list text:style-name="{$list_style}">
  1041. <xsl:apply-templates/>
  1042. </text:list>
  1043. <!-- end flagging -->
  1044. <xsl:apply-templates select="." mode="end-add-odt-flags">
  1045. <xsl:with-param name="family" select="'_list'"/>
  1046. </xsl:apply-templates>
  1047. <!-- start first p tag again -->
  1048. <xsl:text disable-output-escaping="yes">&lt;text:p&gt;</xsl:text>
  1049. <!-- start render span tags again-->
  1050. <xsl:call-template name="break_span_tags">
  1051. <xsl:with-param name="depth" select="$span_depth"/>
  1052. <xsl:with-param name="order" select="1"/>
  1053. </xsl:call-template>
  1054. </xsl:when>
  1055. <!-- nearest ancestor tag is dlentry -->
  1056. <xsl:when test="ancestor::*[contains(@class, ' topic/dlentry ')]">
  1057. <xsl:variable name="span_depth">
  1058. <xsl:call-template name="calculate_span_depth_for_tag">
  1059. <xsl:with-param name="tag_class" select="' topic/dlentry '"/>
  1060. </xsl:call-template>
  1061. </xsl:variable>
  1062. <!-- break span tags -->
  1063. <xsl:call-template name="break_span_tags">
  1064. <xsl:with-param name="depth" select="$span_depth"/>
  1065. <xsl:with-param name="order" select="0"/>
  1066. </xsl:call-template>
  1067. <!-- break first p tag -->
  1068. <xsl:text disable-output-escaping="yes">&lt;/text:p&gt;</xsl:text>
  1069. <!-- start flagging -->
  1070. <xsl:apply-templates select="." mode="start-add-odt-flags">
  1071. <xsl:with-param name="family" select="'_list'"/>
  1072. </xsl:apply-templates>
  1073. <!-- start render list -->
  1074. <text:list text:style-name="{$list_style}">
  1075. <xsl:apply-templates/>
  1076. </text:list>
  1077. <!-- end flagging -->
  1078. <xsl:apply-templates select="." mode="end-add-odt-flags">
  1079. <xsl:with-param name="family" select="'_list'"/>
  1080. </xsl:apply-templates>
  1081. <!-- start first p tag again -->
  1082. <xsl:text disable-output-escaping="yes">&lt;text:p&gt;</xsl:text>
  1083. <!-- start render span tags again-->
  1084. <xsl:call-template name="break_span_tags">
  1085. <xsl:with-param name="depth" select="$span_depth"/>
  1086. <xsl:with-param name="order" select="1"/>
  1087. </xsl:call-template>
  1088. </xsl:when>
  1089. <!-- nearest ancestor tag is fn -->
  1090. <xsl:when test="ancestor::*[contains(@class, ' topic/fn ')]">
  1091. <xsl:variable name="span_depth">
  1092. <xsl:call-template name="calculate_span_depth_for_tag"/>
  1093. </xsl:variable>
  1094. <!-- break span tags -->
  1095. <xsl:call-template name="break_span_tags">
  1096. <xsl:with-param name="depth" select="$span_depth"/>
  1097. <xsl:with-param name="order" select="0"/>
  1098. </xsl:call-template>
  1099. <!-- break first p tag -->
  1100. <xsl:text disable-output-escaping="yes">&lt;/text:p&gt;</xsl:text>
  1101. <!-- start flagging -->
  1102. <xsl:apply-templates select="." mode="start-add-odt-flags">
  1103. <xsl:with-param name="family" select="'_list'"/>
  1104. </xsl:apply-templates>
  1105. <!-- start render list -->
  1106. <text:list text:style-name="{$list_style}">
  1107. <xsl:apply-templates/>
  1108. </text:list>
  1109. <!-- end flagging -->
  1110. <xsl:apply-templates select="." mode="end-add-odt-flags">
  1111. <xsl:with-param name="family" select="'_list'"/>
  1112. </xsl:apply-templates>
  1113. <!-- start first p tag again -->
  1114. <xsl:text disable-output-escaping="yes">&lt;text:p text:style-name="footnote"&gt;</xsl:text>
  1115. <!-- start render span tags again-->
  1116. <xsl:call-template name="break_span_tags">
  1117. <xsl:with-param name="depth" select="$span_depth"/>
  1118. <xsl:with-param name="order" select="1"/>
  1119. </xsl:call-template>
  1120. </xsl:when>
  1121. <!-- nested by other tags. -->
  1122. <xsl:otherwise>
  1123. <xsl:variable name="span_depth">
  1124. <xsl:call-template name="calculate_span_depth"/>
  1125. </xsl:variable>
  1126. <!-- break span tags -->
  1127. <xsl:call-template name="break_span_tags">
  1128. <xsl:with-param name="depth" select="$span_depth"/>
  1129. <xsl:with-param name="order" select="0"/>
  1130. </xsl:call-template>
  1131. <!-- break first p tag -->
  1132. <xsl:text disable-output-escaping="yes">&lt;/text:p&gt;</xsl:text>
  1133. <!-- start flagging -->
  1134. <xsl:apply-templates select="." mode="start-add-odt-flags">
  1135. <xsl:with-param name="family" select="'_list'"/>
  1136. </xsl:apply-templates>
  1137. <!-- start render list -->
  1138. <text:list text:style-name="{$list_style}">
  1139. <xsl:apply-templates/>
  1140. </text:list>
  1141. <!-- end flagging -->
  1142. <xsl:apply-templates select="." mode="end-add-odt-flags">
  1143. <xsl:with-param name="family" select="'_list'"/>
  1144. </xsl:apply-templates>
  1145. <!-- start first p tag again -->
  1146. <xsl:text disable-output-escaping="yes">&lt;text:p&gt;</xsl:text>
  1147. <!-- start render span tags again-->
  1148. <xsl:call-template name="break_span_tags">
  1149. <xsl:with-param name="depth" select="$span_depth"/>
  1150. <xsl:with-param name="order" select="1"/>
  1151. </xsl:call-template>
  1152. </xsl:otherwise>
  1153. </xsl:choose>
  1154. </xsl:template>
  1155. <!-- =========== FUNCTIONS FOR RELATED-LINKS =========== -->
  1156. <!-- same file or not -->
  1157. <xsl:template name="check_file_location">
  1158. <xsl:choose>
  1159. <xsl:when test="@href and starts-with(@href,'#')">
  1160. <xsl:value-of select="'true'"/>
  1161. </xsl:when>
  1162. <xsl:otherwise>
  1163. <xsl:value-of select="'false'"/>
  1164. </xsl:otherwise>
  1165. </xsl:choose>
  1166. </xsl:template>
  1167. <xsl:template name="format_href_value">
  1168. <xsl:choose>
  1169. <xsl:when test="@href and starts-with(@href,'#')">
  1170. <xsl:choose>
  1171. <!-- get element id -->
  1172. <xsl:when test="contains(@href,'/')">
  1173. <xsl:value-of select="concat('#', substring-after(@href,'/'))"/>
  1174. </xsl:when>
  1175. <xsl:otherwise>
  1176. <xsl:value-of select="@href"/>
  1177. </xsl:otherwise>
  1178. </xsl:choose>
  1179. </xsl:when>
  1180. <xsl:when test="@href and contains(@href,'#')">
  1181. <xsl:value-of select="substring-before(@href,'#')"/>
  1182. </xsl:when>
  1183. <xsl:when test="@href and not(@href='')">
  1184. <xsl:value-of select="@href"/>
  1185. </xsl:when>
  1186. </xsl:choose>
  1187. </xsl:template>
  1188. <!-- create related links -->
  1189. <xsl:template name="create_related_links">
  1190. <xsl:param name="samefile"/>
  1191. <xsl:param name="text"/>
  1192. <xsl:param name="href-value"/>
  1193. <xsl:choose>
  1194. <xsl:when test="@href and not(@href='')">
  1195. <text:a>
  1196. <xsl:choose>
  1197. <xsl:when test="$samefile='true'">
  1198. <xsl:attribute name="xlink:href">
  1199. <xsl:value-of select="$href-value"/>
  1200. </xsl:attribute>
  1201. </xsl:when>
  1202. <xsl:otherwise>
  1203. <xsl:variable name="NORMAMLIZEDOUTPUT" select="translate($OUTPUTDIR, '\', '/')"/>
  1204. <xsl:attribute name="xlink:href">
  1205. <xsl:value-of select="concat($FILEREF, $NORMAMLIZEDOUTPUT, '/', $href-value)"/>
  1206. </xsl:attribute>
  1207. </xsl:otherwise>
  1208. </xsl:choose>
  1209. <xsl:call-template name="gen-linktxt"/>
  1210. <xsl:if test="contains(@class,' topic/link ')">
  1211. <xsl:apply-templates select="*[contains(@class,' topic/desc ')]"/>
  1212. <text:line-break/>
  1213. </xsl:if>
  1214. </text:a>
  1215. </xsl:when>
  1216. <xsl:otherwise>
  1217. <xsl:call-template name="output-message">
  1218. <xsl:with-param name="id" select="'DOTX028E'"/>
  1219. </xsl:call-template>
  1220. </xsl:otherwise>
  1221. </xsl:choose>
  1222. </xsl:template>
  1223. <xsl:template name="gen-linktxt">
  1224. <xsl:choose>
  1225. <xsl:when test="contains(@class,' topic/xref ')">
  1226. <xsl:choose>
  1227. <xsl:when test="text() or *">
  1228. <xsl:apply-templates/>
  1229. </xsl:when>
  1230. <xsl:otherwise>
  1231. <xsl:value-of select="@href"/>
  1232. </xsl:otherwise>
  1233. </xsl:choose>
  1234. </xsl:when>
  1235. <xsl:when test="contains(@class,' topic/link ')">
  1236. <xsl:choose>
  1237. <xsl:when test="*[contains(@class,' topic/linktext ')]">
  1238. <xsl:value-of select="*[contains(@class,' topic/linktext ')]"/>
  1239. </xsl:when>
  1240. <xsl:when test="text()">
  1241. <xsl:value-of select="text()"/>
  1242. </xsl:when>
  1243. <xsl:otherwise>
  1244. <xsl:value-of select="@href"/>
  1245. </xsl:otherwise>
  1246. </xsl:choose>
  1247. </xsl:when>
  1248. </xsl:choose>
  1249. </xsl:template>
  1250. <xsl:template match="*" mode="ditamsg:draft-comment-in-content">
  1251. <xsl:call-template name="output-message">
  1252. <xsl:with-param name="id" select="'DOTX040I'"/>
  1253. </xsl:call-template>
  1254. </xsl:template>
  1255. <xsl:template match="*" mode="ditamsg:required-cleanup-in-content">
  1256. <xsl:call-template name="output-message">
  1257. <xsl:with-param name="id" select="'DOTX039W'"/>
  1258. </xsl:call-template>
  1259. </xsl:template>
  1260. </xsl:stylesheet>