refdisplay.xsl 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <xsl:stylesheet version="2.0"
  3. xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  4. xmlns:related-links="http://dita-ot.sourceforge.net/ns/200709/related-links"
  5. xmlns:xs="http://www.w3.org/2001/XMLSchema"
  6. exclude-result-prefixes="related-links xs">
  7. <xsl:template match="*[contains(@class,' reference/prophead ')]" name="topic.reference.prophead">
  8. <xsl:param name="width-multiplier"/>
  9. <tr>
  10. <xsl:call-template name="setid"/>
  11. <xsl:call-template name="commonattributes"/>
  12. <!-- For each of the 3 entry types: If the entry is in this row, apply-templates.
  13. Otherwise, if it is ever in this table, create empty entry, and add ID for accessibility. -->
  14. <xsl:choose> <!-- Process <proptype> -->
  15. <xsl:when test="*[contains(@class,' reference/proptypehd ')]">
  16. <xsl:apply-templates select="*[contains(@class,' reference/proptypehd ')]">
  17. <xsl:with-param name="width-multiplier" select="$width-multiplier"/>
  18. </xsl:apply-templates>
  19. </xsl:when>
  20. <xsl:when test="following-sibling::*/*[contains(@class,' reference/proptype ')]">
  21. <th valign="bottom">
  22. <xsl:attribute name="id"><xsl:value-of select="generate-id(parent::*)"/>-type</xsl:attribute>
  23. <xsl:call-template name="th-align"/>
  24. <xsl:call-template name="getVariable">
  25. <xsl:with-param name="id" select="'Type'"/>
  26. </xsl:call-template>
  27. </th>
  28. </xsl:when>
  29. </xsl:choose>
  30. <xsl:choose> <!-- Process <propvalue> -->
  31. <xsl:when test="*[contains(@class,' reference/propvaluehd ')]">
  32. <xsl:apply-templates select="*[contains(@class,' reference/propvaluehd ')]">
  33. <xsl:with-param name="width-multiplier" select="$width-multiplier"/>
  34. </xsl:apply-templates>
  35. </xsl:when>
  36. <xsl:when test="following-sibling::*/*[contains(@class,' reference/propvalue ')]">
  37. <th valign="bottom">
  38. <xsl:attribute name="id"><xsl:value-of select="generate-id(parent::*)"/>-value</xsl:attribute>
  39. <xsl:call-template name="th-align"/>
  40. <xsl:call-template name="getVariable">
  41. <xsl:with-param name="id" select="'Value'"/>
  42. </xsl:call-template>
  43. </th>
  44. </xsl:when>
  45. </xsl:choose>
  46. <xsl:choose> <!-- Process <propdesc> -->
  47. <xsl:when test="*[contains(@class,' reference/propdeschd ')]">
  48. <xsl:apply-templates select="*[contains(@class,' reference/propdeschd ')]">
  49. <xsl:with-param name="width-multiplier" select="$width-multiplier"/>
  50. </xsl:apply-templates>
  51. </xsl:when>
  52. <xsl:when test="following-sibling::*/*[contains(@class,' reference/propdesc ')]">
  53. <th valign="bottom">
  54. <xsl:attribute name="id"><xsl:value-of select="generate-id(parent::*)"/>-desc</xsl:attribute>
  55. <xsl:call-template name="th-align"/>
  56. <xsl:call-template name="getVariable">
  57. <xsl:with-param name="id" select="'Description'"/>
  58. </xsl:call-template>
  59. </th>
  60. </xsl:when>
  61. </xsl:choose>
  62. </tr>
  63. </xsl:template>
  64. <!-- Add the headers attribute to a cell inside the properties table. This may be called from either
  65. a <property> row or from a cell inside the row. -->
  66. <xsl:template name="addPropertiesHeadersAttribute">
  67. <xsl:param name="classVal"/>
  68. <xsl:param name="elementType"/>
  69. <xsl:attribute name="headers">
  70. <xsl:choose>
  71. <!-- First choice: if there is a matching cell inside a user-specified header, and it has an ID -->
  72. <xsl:when test="ancestor::*[contains(@class,' reference/properties ')]/*[1][contains(@class,' reference/prophead ')]/*[contains(@class,$classVal)]/@id">
  73. <xsl:value-of select="ancestor::*[contains(@class,' reference/properties ')]/*[1][contains(@class,' reference/prophead ')]/*[contains(@class,$classVal)]/@id"/>
  74. </xsl:when>
  75. <!-- Second choice: if there is a matching cell inside a user-specified header, use its generated ID -->
  76. <xsl:when test="ancestor::*[contains(@class,' reference/properties ')]/*[1][contains(@class,' reference/prophead ')]/*[contains(@class,$classVal)]">
  77. <xsl:value-of select="generate-id(ancestor::*[contains(@class,' reference/properties ')]/*[1][contains(@class,' reference/prophead ')]/*[contains(@class,$classVal)])"/>
  78. </xsl:when>
  79. <!-- Third choice: no user-specified header for this column. ID is based on the table's generated ID. -->
  80. <xsl:otherwise>
  81. <xsl:value-of select="generate-id(ancestor::*[contains(@class,' reference/properties ')])"/>-<xsl:value-of select="$elementType"/>
  82. </xsl:otherwise>
  83. </xsl:choose>
  84. </xsl:attribute>
  85. </xsl:template>
  86. <!-- Process a standard row in the properties table. Apply-templates on the entries one at a time;
  87. if one is missing which should be present, create an empty cell. -->
  88. <xsl:template match="*[contains(@class,' reference/property ')]" name="topic.reference.property">
  89. <xsl:param name="width-multiplier"/>
  90. <!-- If there was no header, then this is the first child of properties; create default headers -->
  91. <xsl:if test=".=../*[1]">
  92. <tr>
  93. <xsl:if test="../*/*[contains(@class,' reference/proptype ')]">
  94. <th id="{generate-id(parent::*)}-type" valign="bottom">
  95. <xsl:call-template name="th-align"/>
  96. <xsl:call-template name="getVariable">
  97. <xsl:with-param name="id" select="'Type'"/>
  98. </xsl:call-template>
  99. </th>
  100. </xsl:if>
  101. <xsl:if test="../*/*[contains(@class,' reference/propvalue ')]">
  102. <th id="{generate-id(parent::*)}-value" valign="bottom">
  103. <xsl:call-template name="th-align"/>
  104. <xsl:call-template name="getVariable">
  105. <xsl:with-param name="id" select="'Value'"/>
  106. </xsl:call-template>
  107. </th>
  108. </xsl:if>
  109. <xsl:if test="../*/*[contains(@class,' reference/propdesc ')]">
  110. <th id="{generate-id(parent::*)}-desc" valign="bottom">
  111. <xsl:call-template name="th-align"/>
  112. <xsl:call-template name="getVariable">
  113. <xsl:with-param name="id" select="'Description'"/>
  114. </xsl:call-template>
  115. </th>
  116. </xsl:if>
  117. </tr>
  118. </xsl:if>
  119. <tr>
  120. <xsl:call-template name="setid"/>
  121. <xsl:call-template name="commonattributes"/>
  122. <!-- For each of the 3 entry types:
  123. - If it is in this row, apply
  124. - Otherwise, if it is in the table at all, create empty entry -->
  125. <xsl:choose> <!-- Process or create proptype -->
  126. <xsl:when test="*[contains(@class,' reference/proptype ')]">
  127. <xsl:apply-templates select="*[contains(@class,' reference/proptype ')]">
  128. <xsl:with-param name="width-multiplier" select="$width-multiplier"/>
  129. </xsl:apply-templates>
  130. </xsl:when>
  131. <xsl:when test="../*/*[contains(@class,' reference/proptype ')] | ../*[1]/*[contains(@class,' reference/proptypehd ')]">
  132. <td> <!-- Create an empty cell. Add accessiblity attribute. -->
  133. <xsl:call-template name="addPropertiesHeadersAttribute">
  134. <xsl:with-param name="classVal"> reference/proptypehd </xsl:with-param>
  135. <xsl:with-param name="elementType">type</xsl:with-param>
  136. </xsl:call-template>
  137. <xsl:text disable-output-escaping="no">&#xA0;</xsl:text>
  138. </td>
  139. </xsl:when>
  140. </xsl:choose>
  141. <xsl:choose> <!-- Process or create propvalue -->
  142. <xsl:when test="*[contains(@class,' reference/propvalue ')]">
  143. <xsl:apply-templates select="*[contains(@class,' reference/propvalue ')]">
  144. <xsl:with-param name="width-multiplier" select="$width-multiplier"/>
  145. </xsl:apply-templates>
  146. </xsl:when>
  147. <xsl:when test="../*/*[contains(@class,' reference/propvalue ')] | ../*[1]/*[contains(@class,' reference/propvaluehd ')]">
  148. <td> <!-- Create an empty cell. Add accessiblity attribute. -->
  149. <xsl:call-template name="addPropertiesHeadersAttribute">
  150. <xsl:with-param name="classVal"> reference/propvaluehd </xsl:with-param>
  151. <xsl:with-param name="elementType">value</xsl:with-param>
  152. </xsl:call-template>
  153. <xsl:text disable-output-escaping="no">&#xA0;</xsl:text>
  154. </td>
  155. </xsl:when>
  156. </xsl:choose>
  157. <xsl:choose> <!-- Process or create propdesc -->
  158. <xsl:when test="*[contains(@class,' reference/propdesc ')]">
  159. <xsl:apply-templates select="*[contains(@class,' reference/propdesc ')]">
  160. <xsl:with-param name="width-multiplier" select="$width-multiplier"/>
  161. </xsl:apply-templates>
  162. </xsl:when>
  163. <xsl:when test="../*/*[contains(@class,' reference/propdesc ')] | ../*[1]/*[contains(@class,' reference/propdeschd ')]">
  164. <td> <!-- Create an empty cell. Add accessiblity attribute. -->
  165. <xsl:call-template name="addPropertiesHeadersAttribute">
  166. <xsl:with-param name="classVal"> reference/propdeschd </xsl:with-param>
  167. <xsl:with-param name="elementType">desc</xsl:with-param>
  168. </xsl:call-template>
  169. <xsl:text disable-output-escaping="no">&#xA0;</xsl:text>
  170. </td>
  171. </xsl:when>
  172. </xsl:choose>
  173. </tr>
  174. </xsl:template>
  175. <xsl:template match="*[contains(@class,' reference/proptype ')]" name="topic.reference.proptype">
  176. <xsl:param name="width-multiplier">0</xsl:param>
  177. <xsl:apply-templates select="." mode="propertiesEntry">
  178. <xsl:with-param name="width-multiplier" select="$width-multiplier"/>
  179. <xsl:with-param name="elementType">type</xsl:with-param>
  180. </xsl:apply-templates>
  181. </xsl:template>
  182. <xsl:template match="*[contains(@class,' reference/propvalue ')]" name="topic.reference.propvalue">
  183. <xsl:param name="width-multiplier">0</xsl:param>
  184. <xsl:apply-templates select="." mode="propertiesEntry">
  185. <xsl:with-param name="width-multiplier" select="$width-multiplier"/>
  186. <xsl:with-param name="elementType">value</xsl:with-param>
  187. </xsl:apply-templates>
  188. </xsl:template>
  189. <xsl:template match="*[contains(@class,' reference/propdesc ')]" name="topic.reference.propdesc">
  190. <xsl:param name="width-multiplier">0</xsl:param>
  191. <xsl:apply-templates select="." mode="propertiesEntry">
  192. <xsl:with-param name="width-multiplier" select="$width-multiplier"/>
  193. <xsl:with-param name="elementType">desc</xsl:with-param>
  194. </xsl:apply-templates>
  195. </xsl:template>
  196. <!-- Template based on the stentry template in dit2htm. Only change is to add elementType
  197. paramenter, and call addPropertiesHeadersAttribute instead of output-stentry-headers. -->
  198. <xsl:template match="*" mode="propertiesEntry">
  199. <xsl:param name="width-multiplier">0</xsl:param>
  200. <xsl:param name="elementType"/>
  201. <td valign="top">
  202. <xsl:call-template name="output-stentry-id"/>
  203. <xsl:call-template name="addPropertiesHeadersAttribute">
  204. <xsl:with-param name="classVal"> reference/prop<xsl:value-of select="$elementType"/>hd<xsl:text> </xsl:text></xsl:with-param>
  205. <xsl:with-param name="elementType"><xsl:value-of select="$elementType"/></xsl:with-param>
  206. </xsl:call-template>
  207. <xsl:call-template name="commonattributes"/>
  208. <xsl:variable name="localkeycol">
  209. <xsl:choose>
  210. <xsl:when test="ancestor::*[contains(@class,' topic/simpletable ')]/@keycol">
  211. <xsl:value-of select="ancestor::*[contains(@class,' topic/simpletable ')]/@keycol"/>
  212. </xsl:when>
  213. <xsl:otherwise>0</xsl:otherwise>
  214. </xsl:choose>
  215. </xsl:variable>
  216. <!-- Determine which column this entry is in. -->
  217. <xsl:variable name="thiscolnum"><xsl:value-of select="number(count(preceding-sibling::*[contains(@class,' topic/stentry ')])+1)"/></xsl:variable>
  218. <!-- If width-multiplier=0, then either @relcolwidth was not specified, or this is not the first
  219. row, so do not create a width value. Otherwise, find out the relative width of this column. -->
  220. <xsl:variable name="widthpercent">
  221. <xsl:if test="$width-multiplier != 0">
  222. <xsl:call-template name="get-current-entry-percentage">
  223. <xsl:with-param name="multiplier"><xsl:value-of select="$width-multiplier"/></xsl:with-param>
  224. <xsl:with-param name="entry-num"><xsl:value-of select="$thiscolnum"/></xsl:with-param>
  225. </xsl:call-template>
  226. </xsl:if>
  227. </xsl:variable>
  228. <!-- If we calculated a width, create the width attribute. -->
  229. <xsl:if test="string-length($widthpercent)>0">
  230. <xsl:attribute name="width">
  231. <xsl:value-of select="$widthpercent"/><xsl:text>%</xsl:text>
  232. </xsl:attribute>
  233. </xsl:if>
  234. <xsl:apply-templates select="../*[contains(@class,' ditaot-d/ditaval-startprop ')]" mode="out-of-line"/>
  235. <xsl:choose>
  236. <xsl:when test="$thiscolnum=$localkeycol">
  237. <strong>
  238. <xsl:call-template name="propentry-templates"/>
  239. </strong>
  240. </xsl:when>
  241. <xsl:otherwise>
  242. <xsl:call-template name="propentry-templates"/>
  243. </xsl:otherwise>
  244. </xsl:choose>
  245. <xsl:apply-templates select="../*[contains(@class,' ditaot-d/ditaval-endprop ')]" mode="out-of-line"/>
  246. </td>
  247. </xsl:template>
  248. <xsl:template name="propentry-templates">
  249. <xsl:choose>
  250. <xsl:when test="*[not(contains(@class,' ditaot-d/startprop ') or contains(@class,' dita-ot/endprop '))] | text() | processing-instruction()">
  251. <xsl:apply-templates/>
  252. </xsl:when>
  253. <xsl:otherwise>
  254. <!-- Add flags, then either @specentry or NBSP -->
  255. <xsl:apply-templates select="*[contains(@class,' ditaot-d/ditaval-startprop ')]" mode="out-of-line"/>
  256. <xsl:choose>
  257. <xsl:when test="@specentry"><xsl:value-of select="@specentry"/></xsl:when>
  258. <xsl:otherwise>&#160;</xsl:otherwise>
  259. </xsl:choose>
  260. <xsl:apply-templates select="*[contains(@class,' ditaot-d/ditaval-endprop ')]" mode="out-of-line"/>
  261. </xsl:otherwise>
  262. </xsl:choose>
  263. </xsl:template>
  264. <!-- References have their own group. -->
  265. <xsl:template match="*[contains(@class, ' topic/link ')][@type='reference']" mode="related-links:get-group"
  266. name="related-links:group.reference"
  267. as="xs:string">
  268. <xsl:text>reference</xsl:text>
  269. </xsl:template>
  270. <!-- Priority of reference group. -->
  271. <xsl:template match="*[contains(@class, ' topic/link ')][@type='reference']" mode="related-links:get-group-priority"
  272. name="related-links:group-priority.reference"
  273. as="xs:integer">
  274. <xsl:sequence select="1"/>
  275. </xsl:template>
  276. <!-- Reference wrapper for HTML: "Related reference" in <div>. -->
  277. <xsl:template match="*[contains(@class, ' topic/link ')][@type='reference']" mode="related-links:result-group"
  278. name="related-links:result.reference" as="element(linklist)">
  279. <xsl:param name="links"/>
  280. <xsl:if test="normalize-space(string-join($links, ''))">
  281. <linklist class="- topic/linklist " outputclass="relinfo relref">
  282. <title class="- topic/title ">
  283. <xsl:call-template name="getVariable">
  284. <xsl:with-param name="id" select="'Related reference'"/>
  285. </xsl:call-template>
  286. </title>
  287. <xsl:copy-of select="$links"/>
  288. </linklist>
  289. </xsl:if>
  290. </xsl:template>
  291. </xsl:stylesheet>