reference-elements.xsl 18 KB

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