reference-elements.xsl 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!--
  3. This file is part of the DITA Open Toolkit project.
  4. Copyright 2012 Eero Helenius
  5. See the accompanying LICENSE file for applicable license.
  6. -->
  7. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  8. xmlns:xs="http://www.w3.org/2001/XMLSchema"
  9. xmlns:fo="http://www.w3.org/1999/XSL/Format"
  10. xmlns:dita2xslfo="http://dita-ot.sourceforge.net/ns/200910/dita2xslfo"
  11. exclude-result-prefixes="xs dita2xslfo"
  12. version="2.0">
  13. <xsl:template match="*[contains(@class, ' reference/reference ')]" mode="processTopic"
  14. name="processReference">
  15. <fo:block xsl:use-attribute-sets="reference">
  16. <xsl:apply-templates select="." mode="commonTopicProcessing"/>
  17. </fo:block>
  18. </xsl:template>
  19. <!-- Deprecated, retained for backwards compatibility -->
  20. <xsl:template match="*" mode="processReference">
  21. <xsl:call-template name="processReference"/>
  22. </xsl:template>
  23. <xsl:template match="*[contains(@class, ' reference/refbody ')]" priority="1">
  24. <xsl:variable name="level" as="xs:integer">
  25. <xsl:apply-templates select="." mode="get-topic-level"/>
  26. </xsl:variable>
  27. <xsl:choose>
  28. <xsl:when test="not(node())"/>
  29. <xsl:when test="$level = 1">
  30. <fo:block xsl:use-attribute-sets="body__toplevel refbody">
  31. <xsl:call-template name="commonattributes"/>
  32. <xsl:apply-templates/>
  33. </fo:block>
  34. </xsl:when>
  35. <xsl:when test="$level = 2">
  36. <fo:block xsl:use-attribute-sets="body__secondLevel refbody">
  37. <xsl:call-template name="commonattributes"/>
  38. <xsl:apply-templates/>
  39. </fo:block>
  40. </xsl:when>
  41. <xsl:otherwise>
  42. <fo:block xsl:use-attribute-sets="refbody">
  43. <xsl:call-template name="commonattributes"/>
  44. <xsl:apply-templates/>
  45. </fo:block>
  46. </xsl:otherwise>
  47. </xsl:choose>
  48. </xsl:template>
  49. <xsl:template match="*[contains(@class, ' reference/refsyn ')]">
  50. <fo:block xsl:use-attribute-sets="refsyn">
  51. <xsl:call-template name="commonattributes"/>
  52. <xsl:apply-templates select="." mode="dita2xslfo:section-heading"/>
  53. <xsl:apply-templates select="*[contains(@class,' topic/title ')]"/>
  54. <fo:block xsl:use-attribute-sets="refsyn__content">
  55. <xsl:apply-templates select="node() except (*[contains(@class,' topic/title ')])"/>
  56. </fo:block>
  57. </fo:block>
  58. </xsl:template>
  59. <xsl:template match="*[contains(@class, ' reference/properties ')]
  60. [empty(*[contains(@class,' reference/property ')]/
  61. *[contains(@class,' reference/proptype ') or contains(@class,' reference/propvalue ') or contains(@class,' reference/propdesc ')])]" priority="10"/>
  62. <xsl:template match="*[contains(@class, ' reference/property ')]
  63. [empty(*[contains(@class,' reference/proptype ') or contains(@class,' reference/propvalue ') or contains(@class,' reference/propdesc ')])]" priority="10"/>
  64. <xsl:template match="*[contains(@class, ' reference/properties ')]">
  65. <fo:table xsl:use-attribute-sets="properties">
  66. <xsl:call-template name="commonattributes"/>
  67. <xsl:call-template name="univAttrs"/>
  68. <xsl:call-template name="globalAtts"/>
  69. <xsl:call-template name="displayAtts">
  70. <xsl:with-param name="element" select="."/>
  71. </xsl:call-template>
  72. <xsl:if test="@relcolwidth">
  73. <xsl:variable name="fix-relcolwidth">
  74. <xsl:apply-templates select="." mode="fix-relcolwidth">
  75. <xsl:with-param name="number-cells">
  76. <xsl:apply-templates select="*[1]" mode="count-max-simpletable-cells"/>
  77. </xsl:with-param>
  78. </xsl:apply-templates>
  79. </xsl:variable>
  80. <xsl:call-template name="createSimpleTableColumns">
  81. <xsl:with-param name="theColumnWidthes" select="$fix-relcolwidth"/>
  82. </xsl:call-template>
  83. </xsl:if>
  84. <xsl:if test="*[contains(@class, ' reference/prophead ')]">
  85. <xsl:apply-templates select="*[contains(@class, ' reference/prophead ')]"/>
  86. </xsl:if>
  87. <fo:table-body xsl:use-attribute-sets="properties__body">
  88. <xsl:apply-templates select="*[contains(@class, ' reference/property ')]"/>
  89. </fo:table-body>
  90. </fo:table>
  91. </xsl:template>
  92. <!-- If there is no "type" column, value is in column 1 -->
  93. <xsl:template match="*" mode="get-propvalue-position">
  94. <xsl:choose>
  95. <xsl:when test="../*[contains(@class, ' reference/property ')]/*[contains(@class, ' reference/proptype ')] |
  96. ../*[contains(@class, ' reference/prophead ')]/*[contains(@class, ' reference/propheadhd ')]">
  97. <xsl:text>2</xsl:text>
  98. </xsl:when>
  99. <xsl:otherwise>1</xsl:otherwise>
  100. </xsl:choose>
  101. </xsl:template>
  102. <!-- If there is a type and value column, desc is 3;
  103. Otherwise, if there is type or value, desc is 2;
  104. Otherwise, desc is the only column. -->
  105. <xsl:template match="*" mode="get-propdesc-position">
  106. <xsl:choose>
  107. <xsl:when test="../*/*[contains(@class, ' reference/proptype ') or contains(@class, ' reference/proptypehd ')] and
  108. ../*/*[contains(@class, ' reference/propvalue ') or contains(@class, ' reference/propvaluehd ')]">
  109. <xsl:text>3</xsl:text>
  110. </xsl:when>
  111. <xsl:when test="../*/*[contains(@class, ' reference/proptype ') or contains(@class, ' reference/proptypehd ')] |
  112. ../*/*[contains(@class, ' reference/propvalue ') or contains(@class, ' reference/propvaluehd ')]">
  113. <xsl:text>2</xsl:text>
  114. </xsl:when>
  115. <xsl:otherwise>1</xsl:otherwise>
  116. </xsl:choose>
  117. </xsl:template>
  118. <xsl:template match="*[contains(@class, ' reference/property ')]">
  119. <fo:table-row xsl:use-attribute-sets="property">
  120. <xsl:call-template name="commonattributes"/>
  121. <xsl:variable name="valuePos">
  122. <xsl:apply-templates select="." mode="get-propvalue-position"/>
  123. </xsl:variable>
  124. <xsl:variable name="descPos">
  125. <xsl:apply-templates select="." mode="get-propdesc-position"/>
  126. </xsl:variable>
  127. <xsl:variable name="frame">
  128. <xsl:variable name="f" select="ancestor::*[contains(@class, ' reference/properties ')][1]/@frame"/>
  129. <xsl:choose>
  130. <xsl:when test="$f">
  131. <xsl:value-of select="$f"/>
  132. </xsl:when>
  133. <xsl:otherwise>
  134. <xsl:value-of select="$table.frame-default"/>
  135. </xsl:otherwise>
  136. </xsl:choose>
  137. </xsl:variable>
  138. <xsl:variable name="keyCol" select="number(ancestor::*[contains(@class, ' reference/properties ')][1]/@keycol)"/>
  139. <xsl:variable name="hasHorisontalBorder">
  140. <xsl:choose>
  141. <xsl:when test="following-sibling::*[contains(@class, ' reference/property ')]">
  142. <xsl:value-of select="'yes'"/>
  143. </xsl:when>
  144. <xsl:otherwise>
  145. <xsl:value-of select="'no'"/>
  146. </xsl:otherwise>
  147. </xsl:choose>
  148. </xsl:variable>
  149. <xsl:choose>
  150. <xsl:when test="*[contains(@class, ' reference/proptype ')]">
  151. <xsl:apply-templates select="*[contains(@class, ' reference/proptype ')]">
  152. <xsl:with-param name="entryCol" select="1"/>
  153. </xsl:apply-templates>
  154. </xsl:when>
  155. <xsl:when test="../*/*[contains(@class, ' reference/proptype ') or contains(@class, ' reference/proptypehd ')]">
  156. <xsl:call-template name="createEmptyPropertyEntry">
  157. <xsl:with-param name="entryCol" select="1"/>
  158. <xsl:with-param name="keyCol" select="$keyCol"/>
  159. <xsl:with-param name="hasHorisontalBorder" select="$hasHorisontalBorder"/>
  160. <xsl:with-param name="hasVerticalBorder" select="'yes'"/>
  161. <xsl:with-param name="frame" select="$frame"/>
  162. </xsl:call-template>
  163. </xsl:when>
  164. </xsl:choose>
  165. <xsl:choose>
  166. <xsl:when test="*[contains(@class, ' reference/propvalue ')]">
  167. <xsl:apply-templates select="*[contains(@class, ' reference/propvalue ')]">
  168. <xsl:with-param name="entryCol" select="$valuePos"/>
  169. </xsl:apply-templates>
  170. </xsl:when>
  171. <xsl:when test="../*/*[contains(@class, ' reference/propvalue ') or contains(@class, ' reference/propvaluehd ')]">
  172. <xsl:call-template name="createEmptyPropertyEntry">
  173. <xsl:with-param name="entryCol" select="$valuePos"/>
  174. <xsl:with-param name="keyCol" select="$keyCol"/>
  175. <xsl:with-param name="hasHorisontalBorder" select="$hasHorisontalBorder"/>
  176. <xsl:with-param name="hasVerticalBorder" select="'yes'"/>
  177. <xsl:with-param name="frame" select="$frame"/>
  178. </xsl:call-template>
  179. </xsl:when>
  180. </xsl:choose>
  181. <xsl:choose>
  182. <xsl:when test="*[contains(@class, ' reference/propdesc ')]">
  183. <xsl:apply-templates select="*[contains(@class, ' reference/propdesc ')]">
  184. <xsl:with-param name="entryCol" select="$descPos"/>
  185. </xsl:apply-templates>
  186. </xsl:when>
  187. <xsl:when test="../*/*[contains(@class, ' reference/propdesc ') or contains(@class, ' reference/propdeschd ')]">
  188. <xsl:call-template name="createEmptyPropertyEntry">
  189. <xsl:with-param name="entryCol" select="$descPos"/>
  190. <xsl:with-param name="keyCol" select="$keyCol"/>
  191. <xsl:with-param name="hasHorisontalBorder" select="$hasHorisontalBorder"/>
  192. <xsl:with-param name="hasVerticalBorder" select="'no'"/>
  193. <xsl:with-param name="frame" select="$frame"/>
  194. </xsl:call-template>
  195. </xsl:when>
  196. </xsl:choose>
  197. </fo:table-row>
  198. </xsl:template>
  199. <xsl:template name="createEmptyPropertyEntry">
  200. <xsl:param name="entryCol"/>
  201. <xsl:param name="keyCol"/>
  202. <xsl:param name="hasHorisontalBorder"/>
  203. <xsl:param name="hasVerticalBorder"/>
  204. <xsl:param name="frame"/>
  205. <fo:table-cell xsl:use-attribute-sets="property.entry">
  206. <xsl:if test="$hasHorisontalBorder = 'yes'">
  207. <xsl:call-template name="generateSimpleTableHorizontalBorders">
  208. <xsl:with-param name="frame" select="$frame"/>
  209. </xsl:call-template>
  210. </xsl:if>
  211. <xsl:if test="$hasVerticalBorder = 'yes'">
  212. <xsl:call-template name="generateSimpleTableVerticalBorders">
  213. <xsl:with-param name="frame" select="$frame"/>
  214. </xsl:call-template>
  215. </xsl:if>
  216. <xsl:choose>
  217. <xsl:when test="$keyCol = $entryCol">
  218. <fo:block xsl:use-attribute-sets="property.entry__keycol-content"></fo:block>
  219. </xsl:when>
  220. <xsl:otherwise>
  221. <fo:block xsl:use-attribute-sets="property.entry__content"></fo:block>
  222. </xsl:otherwise>
  223. </xsl:choose>
  224. </fo:table-cell>
  225. </xsl:template>
  226. <xsl:template match="*[contains(@class, ' reference/proptype ') or contains(@class, ' reference/propvalue ') or contains(@class, ' reference/propdesc ')]">
  227. <xsl:param name="entryCol"/>
  228. <fo:table-cell xsl:use-attribute-sets="property.entry">
  229. <xsl:call-template name="commonattributes"/>
  230. <xsl:variable name="frame">
  231. <xsl:variable name="f" select="ancestor::*[contains(@class, ' reference/properties ')][1]/@frame"/>
  232. <xsl:choose>
  233. <xsl:when test="$f">
  234. <xsl:value-of select="$f"/>
  235. </xsl:when>
  236. <xsl:otherwise>
  237. <xsl:value-of select="$table.frame-default"/>
  238. </xsl:otherwise>
  239. </xsl:choose>
  240. </xsl:variable>
  241. <xsl:if test="../following-sibling::*[contains(@class, ' reference/property ')]">
  242. <xsl:call-template name="generateSimpleTableHorizontalBorders">
  243. <xsl:with-param name="frame" select="$frame"/>
  244. </xsl:call-template>
  245. </xsl:if>
  246. <xsl:if test="following-sibling::*[contains(@class, ' reference/proptype ') or contains(@class, ' reference/propvalue ') or contains(@class, ' reference/propdesc ')]">
  247. <xsl:call-template name="generateSimpleTableVerticalBorders">
  248. <xsl:with-param name="frame" select="$frame"/>
  249. </xsl:call-template>
  250. </xsl:if>
  251. <xsl:choose>
  252. <xsl:when test="number(ancestor::*[contains(@class, ' reference/properties ')][1]/@keycol) = $entryCol">
  253. <fo:block xsl:use-attribute-sets="property.entry__keycol-content">
  254. <xsl:apply-templates/>
  255. </fo:block>
  256. </xsl:when>
  257. <xsl:otherwise>
  258. <fo:block xsl:use-attribute-sets="property.entry__content">
  259. <xsl:apply-templates/>
  260. </fo:block>
  261. </xsl:otherwise>
  262. </xsl:choose>
  263. </fo:table-cell>
  264. </xsl:template>
  265. <xsl:template match="*[contains(@class, ' reference/prophead ')]">
  266. <fo:table-header xsl:use-attribute-sets="prophead">
  267. <xsl:call-template name="commonattributes"/>
  268. <xsl:variable name="frame">
  269. <xsl:variable name="f" select="ancestor::*[contains(@class, ' reference/properties ')][1]/@frame"/>
  270. <xsl:choose>
  271. <xsl:when test="$f">
  272. <xsl:value-of select="$f"/>
  273. </xsl:when>
  274. <xsl:otherwise>
  275. <xsl:value-of select="$table.frame-default"/>
  276. </xsl:otherwise>
  277. </xsl:choose>
  278. </xsl:variable>
  279. <xsl:variable name="keyCol" select="number(ancestor::*[contains(@class, ' reference/properties ')][1]/@keycol)"/>
  280. <fo:table-row xsl:use-attribute-sets="prophead__row">
  281. <xsl:choose>
  282. <xsl:when test="*[contains(@class, ' reference/proptypehd ')]">
  283. <xsl:apply-templates select="*[contains(@class, ' reference/proptypehd ')]">
  284. <xsl:with-param name="entryCol" select="1"/>
  285. </xsl:apply-templates>
  286. </xsl:when>
  287. <xsl:when test="../*[contains(@class,' reference/property ')]/*[contains(@class,' reference/proptype ')]">
  288. <xsl:call-template name="createEmptyPropertyHeadEntry">
  289. <xsl:with-param name="entryCol" select="1"/>
  290. <xsl:with-param name="keyCol" select="$keyCol"/>
  291. <xsl:with-param name="hasVerticalBorder" select="'yes'"/>
  292. <xsl:with-param name="frame" select="$frame"/>
  293. </xsl:call-template>
  294. </xsl:when>
  295. </xsl:choose>
  296. <xsl:choose>
  297. <xsl:when test="*[contains(@class, ' reference/propvaluehd ')]">
  298. <xsl:apply-templates select="*[contains(@class, ' reference/propvaluehd ')]">
  299. <xsl:with-param name="entryCol" select="2"/>
  300. </xsl:apply-templates>
  301. </xsl:when>
  302. <xsl:when test="../*[contains(@class,' reference/property ')]/*[contains(@class,' reference/propvalue ')]">
  303. <xsl:call-template name="createEmptyPropertyHeadEntry">
  304. <xsl:with-param name="entryCol" select="2"/>
  305. <xsl:with-param name="keyCol" select="$keyCol"/>
  306. <xsl:with-param name="hasVerticalBorder" select="'yes'"/>
  307. <xsl:with-param name="frame" select="$frame"/>
  308. </xsl:call-template>
  309. </xsl:when>
  310. </xsl:choose>
  311. <xsl:choose>
  312. <xsl:when test="*[contains(@class, ' reference/propdeschd ')]">
  313. <xsl:apply-templates select="*[contains(@class, ' reference/propdeschd ')]">
  314. <xsl:with-param name="entryCol" select="3"/>
  315. </xsl:apply-templates>
  316. </xsl:when>
  317. <xsl:when test="../*[contains(@class,' reference/property ')]/*[contains(@class,' reference/propdesc ')]">
  318. <xsl:call-template name="createEmptyPropertyHeadEntry">
  319. <xsl:with-param name="entryCol" select="3"/>
  320. <xsl:with-param name="keyCol" select="$keyCol"/>
  321. <xsl:with-param name="hasVerticalBorder" select="'no'"/>
  322. <xsl:with-param name="frame" select="$frame"/>
  323. </xsl:call-template>
  324. </xsl:when>
  325. </xsl:choose>
  326. </fo:table-row>
  327. </fo:table-header>
  328. </xsl:template>
  329. <xsl:template name="createEmptyPropertyHeadEntry">
  330. <xsl:param name="entryCol"/>
  331. <xsl:param name="keyCol"/>
  332. <xsl:param name="hasVerticalBorder"/>
  333. <xsl:param name="frame"/>
  334. <fo:table-cell xsl:use-attribute-sets="prophead.entry">
  335. <xsl:call-template name="generateSimpleTableHorizontalBorders">
  336. <xsl:with-param name="frame" select="$frame"/>
  337. </xsl:call-template>
  338. <xsl:if test="$frame = 'all' or $frame = 'topbot' or $frame = 'top' or not($frame)">
  339. <xsl:call-template name="processAttrSetReflection">
  340. <xsl:with-param name="attrSet" select="'__tableframe__top'"/>
  341. <xsl:with-param name="path" select="$tableAttrs"/>
  342. </xsl:call-template>
  343. </xsl:if>
  344. <xsl:if test="$hasVerticalBorder = 'yes'">
  345. <xsl:call-template name="generateSimpleTableVerticalBorders">
  346. <xsl:with-param name="frame" select="$frame"/>
  347. </xsl:call-template>
  348. </xsl:if>
  349. <xsl:choose>
  350. <xsl:when test="$keyCol = $entryCol">
  351. <fo:block xsl:use-attribute-sets="prophead.entry__keycol-content"></fo:block>
  352. </xsl:when>
  353. <xsl:otherwise>
  354. <fo:block xsl:use-attribute-sets="prophead.entry__content"></fo:block>
  355. </xsl:otherwise>
  356. </xsl:choose>
  357. </fo:table-cell>
  358. </xsl:template>
  359. <xsl:template match="*[contains(@class, ' reference/proptypehd ') or contains(@class, ' reference/propvaluehd ') or contains(@class, ' reference/propdeschd ')]">
  360. <xsl:param name="entryCol"/>
  361. <fo:table-cell xsl:use-attribute-sets="prophead.entry">
  362. <xsl:call-template name="commonattributes"/>
  363. <xsl:variable name="frame">
  364. <xsl:variable name="f" select="ancestor::*[contains(@class, ' reference/properties ')][1]/@frame"/>
  365. <xsl:choose>
  366. <xsl:when test="$f">
  367. <xsl:value-of select="$f"/>
  368. </xsl:when>
  369. <xsl:otherwise>
  370. <xsl:value-of select="$table.frame-default"/>
  371. </xsl:otherwise>
  372. </xsl:choose>
  373. </xsl:variable>
  374. <xsl:call-template name="generateSimpleTableHorizontalBorders">
  375. <xsl:with-param name="frame" select="$frame"/>
  376. </xsl:call-template>
  377. <xsl:if test="$frame = 'all' or $frame = 'topbot' or $frame = 'top' or not($frame)">
  378. <xsl:call-template name="processAttrSetReflection">
  379. <xsl:with-param name="attrSet" select="'__tableframe__top'"/>
  380. <xsl:with-param name="path" select="$tableAttrs"/>
  381. </xsl:call-template>
  382. </xsl:if>
  383. <xsl:if test="following-sibling::*[contains(@class, ' reference/proptypehd ') or contains(@class, ' reference/propvaluehd ') or contains(@class, ' reference/propdeschd ')]">
  384. <xsl:call-template name="generateSimpleTableVerticalBorders">
  385. <xsl:with-param name="frame" select="$frame"/>
  386. </xsl:call-template>
  387. </xsl:if>
  388. <xsl:choose>
  389. <xsl:when test="number(ancestor::*[contains(@class, ' reference/properties ')][1]/@keycol) = $entryCol">
  390. <fo:block xsl:use-attribute-sets="prophead.entry__keycol-content">
  391. <xsl:apply-templates/>
  392. </fo:block>
  393. </xsl:when>
  394. <xsl:otherwise>
  395. <fo:block xsl:use-attribute-sets="prophead.entry__content">
  396. <xsl:apply-templates/>
  397. </fo:block>
  398. </xsl:otherwise>
  399. </xsl:choose>
  400. </fo:table-cell>
  401. </xsl:template>
  402. </xsl:stylesheet>