refdisplay.xsl 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!--
  3. This file is part of the DITA Open Toolkit project.
  4. Copyright 2004, 2005 IBM Corporation
  5. See the accompanying LICENSE file for applicable license.
  6. -->
  7. <xsl:stylesheet version="2.0"
  8. xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  9. xmlns:related-links="http://dita-ot.sourceforge.net/ns/200709/related-links"
  10. xmlns:dita2html="http://dita-ot.sourceforge.net/ns/200801/dita2html"
  11. xmlns:xs="http://www.w3.org/2001/XMLSchema"
  12. exclude-result-prefixes="related-links xs dita2html">
  13. <!-- == REFERENCE UNIQUE SUBSTRUCTURES == -->
  14. <xsl:template match="*[contains(@class,' reference/properties ')]" name="reference.properties">
  15. <xsl:call-template name="spec-title"/>
  16. <xsl:apply-templates select="*[contains(@class, ' ditaot-d/ditaval-startprop ')]" mode="out-of-line"/>
  17. <xsl:call-template name="setaname"/>
  18. <table cellpadding="4" cellspacing="0"><!--summary=""-->
  19. <xsl:call-template name="setid"/>
  20. <xsl:attribute name="border" select="if (@frame = 'none') then 0 else 1"/>
  21. <xsl:call-template name="commonattributes">
  22. <xsl:with-param name="default-output-class">
  23. <xsl:choose>
  24. <xsl:when test="@frame = 'none'">simpletablenoborder</xsl:when>
  25. <xsl:otherwise>simpletableborder</xsl:otherwise>
  26. </xsl:choose>
  27. </xsl:with-param>
  28. </xsl:call-template>
  29. <xsl:apply-templates select="." mode="generate-table-summary-attribute"/>
  30. <xsl:call-template name="setscale"/>
  31. <xsl:call-template name="dita2html:simpletable-cols"/>
  32. <xsl:variable name="header" select="*[contains(@class,' reference/prophead ')]"/>
  33. <xsl:variable name="properties" select="*[contains(@class,' reference/property ')]"/>
  34. <xsl:variable name="hasType" select="exists($header/*[contains(@class,' reference/proptypehd ')] | $properties/*[contains(@class,' reference/proptype ')])"/>
  35. <xsl:variable name="hasValue" select="exists($header/*[contains(@class,' reference/propvaluehd ')] | $properties/*[contains(@class,' reference/propvalue ')])"/>
  36. <xsl:variable name="hasDesc" select="exists($header/*[contains(@class,' reference/propdeschd ')] | $properties/*[contains(@class,' reference/propdesc ')])"/>
  37. <xsl:variable name="prophead" as="element()">
  38. <xsl:choose>
  39. <xsl:when test="*[contains(@class, ' reference/prophead ')]">
  40. <xsl:sequence select="*[contains(@class, ' reference/prophead ')]"/>
  41. </xsl:when>
  42. <xsl:otherwise>
  43. <xsl:variable name="gen" as="element(gen)?">
  44. <xsl:call-template name="gen-prophead">
  45. <xsl:with-param name="hasType" select="$hasType"/>
  46. <xsl:with-param name="hasValue" select="$hasValue"/>
  47. <xsl:with-param name="hasDesc" select="$hasDesc"/>
  48. </xsl:call-template>
  49. </xsl:variable>
  50. <xsl:sequence select="$gen/*"/>
  51. </xsl:otherwise>
  52. </xsl:choose>
  53. </xsl:variable>
  54. <xsl:apply-templates select="$prophead">
  55. <xsl:with-param name="hasType" select="$hasType"/>
  56. <xsl:with-param name="hasValue" select="$hasValue"/>
  57. <xsl:with-param name="hasDesc" select="$hasDesc"/>
  58. </xsl:apply-templates>
  59. <tbody>
  60. <xsl:apply-templates select="*[contains(@class, ' reference/property ')] | processing-instruction()">
  61. <xsl:with-param name="hasType" select="$hasType"/>
  62. <xsl:with-param name="hasValue" select="$hasValue"/>
  63. <xsl:with-param name="hasDesc" select="$hasDesc"/>
  64. </xsl:apply-templates>
  65. </tbody>
  66. </table>
  67. <xsl:apply-templates select="*[contains(@class, ' ditaot-d/ditaval-endprop ')]" mode="out-of-line"/>
  68. <xsl:value-of select="$newline"/>
  69. </xsl:template>
  70. <xsl:template name="gen-prophead" as="element(gen)?">
  71. <xsl:param name="hasType" as="xs:boolean"/>
  72. <xsl:param name="hasValue" as="xs:boolean"/>
  73. <xsl:param name="hasDesc" as="xs:boolean"/>
  74. <!-- Generated header needs to be wrapped in gen element to allow correct language detection -->
  75. <gen>
  76. <xsl:copy-of select="ancestor-or-self::*[@xml:lang][1]/@xml:lang"/>
  77. <prophead class="- topic/sthead reference/prophead ">
  78. <xsl:if test="$hasType">
  79. <proptypehd class="- topic/stentry reference/proptypehd " id="{generate-id()}-type">
  80. <xsl:call-template name="getVariable">
  81. <xsl:with-param name="id" select="'Type'"/>
  82. </xsl:call-template>
  83. </proptypehd>
  84. </xsl:if>
  85. <xsl:if test="$hasValue">
  86. <propvaluehd class="- topic/stentry reference/propvaluehd " id="{generate-id()}-value">
  87. <xsl:call-template name="getVariable">
  88. <xsl:with-param name="id" select="'Value'"/>
  89. </xsl:call-template>
  90. </propvaluehd>
  91. </xsl:if>
  92. <xsl:if test="$hasDesc">
  93. <xsl:call-template name="gen-propdeschd"/>
  94. </xsl:if>
  95. </prophead>
  96. </gen>
  97. </xsl:template>
  98. <xsl:template name="gen-propdeschd">
  99. <xsl:variable name="properties" select="ancestor-or-self::*[contains(@class,' reference/properties ')][1]"/>
  100. <propdeschd class="- topic/stentry reference/propdeschd " id="{generate-id($properties)}-desc">
  101. <xsl:call-template name="getVariable">
  102. <xsl:with-param name="id" select="'Description'"/>
  103. </xsl:call-template>
  104. </propdeschd>
  105. </xsl:template>
  106. <xsl:template match="*[contains(@class,' reference/properties ')]" mode="dita2html:get-max-entry-count" as="xs:integer">
  107. <xsl:sequence select="3"/>
  108. </xsl:template>
  109. <!-- Process the header row in a properties table -->
  110. <xsl:template match="*[contains(@class,' reference/prophead ')]" name="topic.reference.prophead">
  111. <xsl:param name="hasType" as="xs:boolean"/>
  112. <xsl:param name="hasValue" as="xs:boolean"/>
  113. <xsl:param name="hasDesc" as="xs:boolean"/>
  114. <thead>
  115. <tr>
  116. <xsl:call-template name="setid"/>
  117. <xsl:call-template name="commonattributes"/>
  118. <xsl:value-of select="$newline"/>
  119. <!-- For each of the 3 entry types: If the entry is in this row, apply-templates.
  120. Otherwise, if it is ever in this table, create empty entry, and add ID for accessibility. -->
  121. <xsl:choose> <!-- Process <proptype> -->
  122. <xsl:when test="*[contains(@class,' reference/proptypehd ')]">
  123. <xsl:apply-templates select="*[contains(@class,' reference/proptypehd ')]"/>
  124. </xsl:when>
  125. <xsl:when test="$hasType">
  126. <th>
  127. <xsl:call-template name="style">
  128. <xsl:with-param name="contents">
  129. <xsl:text>vertical-align:bottom;</xsl:text>
  130. <xsl:call-template name="th-align"/>
  131. </xsl:with-param>
  132. </xsl:call-template>
  133. <xsl:attribute name="id"><xsl:value-of select="generate-id(parent::*)"/>-type</xsl:attribute>
  134. <xsl:call-template name="getVariable">
  135. <xsl:with-param name="id" select="'Type'"/>
  136. </xsl:call-template>
  137. </th><xsl:value-of select="$newline"/>
  138. </xsl:when>
  139. </xsl:choose>
  140. <xsl:choose> <!-- Process <propvalue> -->
  141. <xsl:when test="*[contains(@class,' reference/propvaluehd ')]">
  142. <xsl:apply-templates select="*[contains(@class,' reference/propvaluehd ')]"/>
  143. </xsl:when>
  144. <xsl:when test="$hasValue">
  145. <th>
  146. <xsl:call-template name="style">
  147. <xsl:with-param name="contents">
  148. <xsl:text>vertical-align:bottom;</xsl:text>
  149. <xsl:call-template name="th-align"/>
  150. </xsl:with-param>
  151. </xsl:call-template>
  152. <xsl:attribute name="id"><xsl:value-of select="generate-id(parent::*)"/>-value</xsl:attribute>
  153. <xsl:call-template name="getVariable">
  154. <xsl:with-param name="id" select="'Value'"/>
  155. </xsl:call-template>
  156. </th><xsl:value-of select="$newline"/>
  157. </xsl:when>
  158. </xsl:choose>
  159. <xsl:choose> <!-- Process <propdesc> -->
  160. <xsl:when test="*[contains(@class,' reference/propdeschd ')]">
  161. <xsl:apply-templates select="*[contains(@class,' reference/propdeschd ')]"/>
  162. </xsl:when>
  163. <xsl:when test="$hasDesc">
  164. <xsl:variable name="propdeschd" as="element()">
  165. <xsl:call-template name="gen-propdeschd"/>
  166. </xsl:variable>
  167. <th>
  168. <xsl:call-template name="style">
  169. <xsl:with-param name="contents">
  170. <xsl:text>vertical-align:bottom;</xsl:text>
  171. <xsl:call-template name="th-align"/>
  172. </xsl:with-param>
  173. </xsl:call-template>
  174. <xsl:attribute name="id"><xsl:value-of select="generate-id(parent::*)"/>-desc</xsl:attribute>
  175. <xsl:call-template name="getVariable">
  176. <xsl:with-param name="id" select="'Description'"/>
  177. </xsl:call-template>
  178. </th><xsl:value-of select="$newline"/>
  179. </xsl:when>
  180. </xsl:choose>
  181. </tr>
  182. </thead>
  183. </xsl:template>
  184. <!-- Add the headers attribute to a cell inside the properties table. This may be called from either
  185. a <property> row or from a cell inside the row. -->
  186. <xsl:template name="addPropertiesHeadersAttribute">
  187. <xsl:param name="classVal"/>
  188. <xsl:param name="elementType"/>
  189. <xsl:attribute name="headers">
  190. <xsl:choose>
  191. <!-- First choice: if there is a matching cell inside a user-specified header, and it has an ID -->
  192. <xsl:when test="ancestor::*[contains(@class,' reference/properties ')]/*[1][contains(@class,' reference/prophead ')]/*[contains(@class,$classVal)]/@id">
  193. <xsl:value-of select="ancestor::*[contains(@class,' reference/properties ')]/*[1][contains(@class,' reference/prophead ')]/*[contains(@class,$classVal)]/@id"/>
  194. </xsl:when>
  195. <!-- Second choice: if there is a matching cell inside a user-specified header, use its generated ID -->
  196. <xsl:when test="ancestor::*[contains(@class,' reference/properties ')]/*[1][contains(@class,' reference/prophead ')]/*[contains(@class,$classVal)]">
  197. <xsl:value-of select="generate-id(ancestor::*[contains(@class,' reference/properties ')]/*[1][contains(@class,' reference/prophead ')]/*[contains(@class,$classVal)])"/>
  198. </xsl:when>
  199. <!-- Third choice: no user-specified header for this column. ID is based on the table's generated ID. -->
  200. <xsl:otherwise>
  201. <xsl:value-of select="generate-id(ancestor::*[contains(@class,' reference/properties ')])"/>-<xsl:value-of select="$elementType"/>
  202. </xsl:otherwise>
  203. </xsl:choose>
  204. </xsl:attribute>
  205. </xsl:template>
  206. <!-- Process a standard row in the properties table. Apply-templates on the entries one at a time;
  207. if one is missing which should be present, create an empty cell. -->
  208. <xsl:template match="*[contains(@class,' reference/property ')]" name="topic.reference.property">
  209. <xsl:param name="hasType" as="xs:boolean"/>
  210. <xsl:param name="hasValue" as="xs:boolean"/>
  211. <xsl:param name="hasDesc" as="xs:boolean"/>
  212. <tr>
  213. <xsl:call-template name="setid"/>
  214. <xsl:call-template name="commonattributes"/>
  215. <xsl:value-of select="$newline"/>
  216. <!-- For each of the 3 entry types:
  217. - If it is in this row, apply
  218. - Otherwise, if it is in the table at all, create empty entry -->
  219. <xsl:choose> <!-- Process or create proptype -->
  220. <xsl:when test="*[contains(@class,' reference/proptype ')]">
  221. <xsl:apply-templates select="*[contains(@class,' reference/proptype ')]"/>
  222. </xsl:when>
  223. <xsl:when test="$hasType">
  224. <td> <!-- Create an empty cell. Add accessiblity attribute. -->
  225. <xsl:call-template name="addPropertiesHeadersAttribute">
  226. <xsl:with-param name="classVal"> reference/proptypehd </xsl:with-param>
  227. <xsl:with-param name="elementType">type</xsl:with-param>
  228. </xsl:call-template>
  229. <xsl:text>&#xA0;</xsl:text>
  230. </td>
  231. <xsl:value-of select="$newline"/>
  232. </xsl:when>
  233. </xsl:choose>
  234. <xsl:choose> <!-- Process or create propvalue -->
  235. <xsl:when test="*[contains(@class,' reference/propvalue ')]">
  236. <xsl:apply-templates select="*[contains(@class,' reference/propvalue ')]"/>
  237. </xsl:when>
  238. <xsl:when test="$hasValue">
  239. <td> <!-- Create an empty cell. Add accessiblity attribute. -->
  240. <xsl:call-template name="addPropertiesHeadersAttribute">
  241. <xsl:with-param name="classVal"> reference/propvaluehd </xsl:with-param>
  242. <xsl:with-param name="elementType">value</xsl:with-param>
  243. </xsl:call-template>
  244. <xsl:text>&#xA0;</xsl:text>
  245. </td>
  246. <xsl:value-of select="$newline"/>
  247. </xsl:when>
  248. </xsl:choose>
  249. <xsl:choose> <!-- Process or create propdesc -->
  250. <xsl:when test="*[contains(@class,' reference/propdesc ')]">
  251. <xsl:apply-templates select="*[contains(@class,' reference/propdesc ')]"/>
  252. </xsl:when>
  253. <xsl:when test="$hasDesc">
  254. <td> <!-- Create an empty cell. Add accessiblity attribute. -->
  255. <xsl:call-template name="addPropertiesHeadersAttribute">
  256. <xsl:with-param name="classVal"> reference/propdeschd </xsl:with-param>
  257. <xsl:with-param name="elementType">desc</xsl:with-param>
  258. </xsl:call-template>
  259. <xsl:text>&#xA0;</xsl:text>
  260. </td>
  261. <xsl:value-of select="$newline"/>
  262. </xsl:when>
  263. </xsl:choose>
  264. </tr>
  265. <xsl:value-of select="$newline"/>
  266. </xsl:template>
  267. <xsl:template match="*[contains(@class,' reference/proptype ')]" name="topic.reference.proptype">
  268. <xsl:apply-templates select="." mode="propertiesEntry">
  269. <xsl:with-param name="elementType">type</xsl:with-param>
  270. </xsl:apply-templates>
  271. </xsl:template>
  272. <xsl:template match="*[contains(@class,' reference/propvalue ')]" name="topic.reference.propvalue">
  273. <xsl:apply-templates select="." mode="propertiesEntry">
  274. <xsl:with-param name="elementType">value</xsl:with-param>
  275. </xsl:apply-templates>
  276. </xsl:template>
  277. <xsl:template match="*[contains(@class,' reference/propdesc ')]" name="topic.reference.propdesc">
  278. <xsl:apply-templates select="." mode="propertiesEntry">
  279. <xsl:with-param name="elementType">desc</xsl:with-param>
  280. </xsl:apply-templates>
  281. </xsl:template>
  282. <!-- Template based on the stentry template in dit2htm. Only change is to add elementType
  283. paramenter, and call addPropertiesHeadersAttribute instead of output-stentry-headers. -->
  284. <xsl:template match="*" mode="propertiesEntry">
  285. <xsl:param name="elementType"/>
  286. <xsl:variable name="localkeycol" as="xs:integer">
  287. <xsl:choose>
  288. <xsl:when test="ancestor::*[contains(@class,' topic/simpletable ')][1]/@keycol">
  289. <xsl:value-of select="ancestor::*[contains(@class,' topic/simpletable ')][1]/@keycol"/>
  290. </xsl:when>
  291. <xsl:otherwise>0</xsl:otherwise>
  292. </xsl:choose>
  293. </xsl:variable>
  294. <xsl:variable name="element-name" as="xs:string">
  295. <xsl:choose>
  296. <xsl:when test="$localkeycol = 1 and $elementType = 'type'">th</xsl:when>
  297. <xsl:when test="$localkeycol = 2 and $elementType = 'value'">th</xsl:when>
  298. <xsl:when test="$localkeycol = 3 and $elementType = 'desc'">th</xsl:when>
  299. <xsl:otherwise>td</xsl:otherwise>
  300. </xsl:choose>
  301. </xsl:variable>
  302. <xsl:element name="{$element-name}">
  303. <xsl:call-template name="style">
  304. <xsl:with-param name="contents">
  305. <xsl:text>vertical-align:top;</xsl:text>
  306. </xsl:with-param>
  307. </xsl:call-template>
  308. <xsl:call-template name="output-stentry-id"/>
  309. <xsl:call-template name="addPropertiesHeadersAttribute">
  310. <xsl:with-param name="classVal"> reference/prop<xsl:value-of select="$elementType"/>hd<xsl:text> </xsl:text></xsl:with-param>
  311. <xsl:with-param name="elementType" select="$elementType"/>
  312. </xsl:call-template>
  313. <xsl:call-template name="commonattributes"/>
  314. <xsl:apply-templates select="../*[contains(@class,' ditaot-d/ditaval-startprop ')]" mode="out-of-line"/>
  315. <xsl:call-template name="propentry-templates"/>
  316. <xsl:apply-templates select="../*[contains(@class,' ditaot-d/ditaval-endprop ')]" mode="out-of-line"/>
  317. </xsl:element>
  318. <xsl:value-of select="$newline"/>
  319. </xsl:template>
  320. <xsl:template name="propentry-templates">
  321. <xsl:choose>
  322. <xsl:when test="*[not(contains(@class,' ditaot-d/startprop ') or contains(@class,' dita-ot/endprop '))] | text() | processing-instruction()">
  323. <xsl:apply-templates/>
  324. </xsl:when>
  325. <xsl:otherwise>
  326. <!-- Add flags, then either @specentry or NBSP -->
  327. <xsl:apply-templates select="*[contains(@class,' ditaot-d/ditaval-startprop ')]" mode="out-of-line"/>
  328. <xsl:choose>
  329. <xsl:when test="@specentry"><xsl:value-of select="@specentry"/></xsl:when>
  330. <xsl:otherwise>&#160;</xsl:otherwise>
  331. </xsl:choose>
  332. <xsl:apply-templates select="*[contains(@class,' ditaot-d/ditaval-endprop ')]" mode="out-of-line"/>
  333. </xsl:otherwise>
  334. </xsl:choose>
  335. </xsl:template>
  336. <!-- References have their own group. -->
  337. <xsl:template match="*[contains(@class, ' topic/link ')][@type='reference']" mode="related-links:get-group"
  338. name="related-links:group.reference"
  339. as="xs:string">
  340. <xsl:text>reference</xsl:text>
  341. </xsl:template>
  342. <!-- Priority of reference group. -->
  343. <xsl:template match="*[contains(@class, ' topic/link ')][@type='reference']" mode="related-links:get-group-priority"
  344. name="related-links:group-priority.reference"
  345. as="xs:integer">
  346. <xsl:sequence select="1"/>
  347. </xsl:template>
  348. <!-- Reference wrapper for HTML: "Related reference" in <div>. -->
  349. <xsl:template match="*[contains(@class, ' topic/link ')][@type='reference']" mode="related-links:result-group"
  350. name="related-links:result.reference" as="element()?">
  351. <xsl:param name="links"/>
  352. <xsl:if test="normalize-space(string-join($links, ''))">
  353. <linklist class="- topic/linklist " outputclass="relinfo relref">
  354. <xsl:copy-of select="ancestor-or-self::*[@xml:lang][1]/@xml:lang"/>
  355. <title class="- topic/title ">
  356. <xsl:call-template name="getVariable">
  357. <xsl:with-param name="id" select="'Related reference'"/>
  358. </xsl:call-template>
  359. </title>
  360. <xsl:copy-of select="$links"/>
  361. </linklist>
  362. </xsl:if>
  363. </xsl:template>
  364. </xsl:stylesheet>