refdisplay.xsl 18 KB

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