reference.xsl 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!--
  3. This file is part of the DITA Open Toolkit project.
  4. Copyright 2016 Jarno Elovirta
  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:dita-ot="http://dita-ot.sourceforge.net/ns/201007/dita-ot"
  10. xmlns:dita2html="http://dita-ot.sourceforge.net/ns/200801/dita2html"
  11. xmlns:related-links="http://dita-ot.sourceforge.net/ns/200709/related-links"
  12. version="2.0"
  13. exclude-result-prefixes="xs dita-ot dita2html related-links">
  14. <xsl:template match="*[contains(@class, ' reference/properties ')]
  15. [empty(*[contains(@class,' reference/property ')]/
  16. *[contains(@class,' reference/proptype ') or contains(@class,' reference/propvalue ') or contains(@class,' reference/propdesc ')])]" priority="10"/>
  17. <xsl:template match="*[contains(@class,' reference/properties ')]" name="reference.properties">
  18. <xsl:call-template name="spec-title"/>
  19. <xsl:apply-templates select="*[contains(@class, ' ditaot-d/ditaval-startprop ')]" mode="out-of-line"/>
  20. <xsl:call-template name="setaname"/>
  21. <table cellpadding="4" cellspacing="0"><!--summary=""-->
  22. <xsl:call-template name="setid"/>
  23. <xsl:if test="not(@frame = 'none')">
  24. <xsl:attribute name="border" select="1"/>
  25. </xsl:if>
  26. <xsl:call-template name="commonattributes">
  27. <xsl:with-param name="default-output-class">
  28. <xsl:choose>
  29. <xsl:when test="@frame = 'none'">simpletablenoborder</xsl:when>
  30. <xsl:otherwise>simpletableborder</xsl:otherwise>
  31. </xsl:choose>
  32. </xsl:with-param>
  33. </xsl:call-template>
  34. <xsl:apply-templates select="." mode="generate-table-summary-attribute"/>
  35. <xsl:call-template name="setscale"/>
  36. <xsl:call-template name="dita2html:simpletable-cols"/>
  37. <xsl:variable name="header" select="*[contains(@class,' reference/prophead ')]"/>
  38. <xsl:variable name="properties" select="*[contains(@class,' reference/property ')]"/>
  39. <xsl:variable name="hasType" select="exists($header/*[contains(@class,' reference/proptypehd ')] | $properties/*[contains(@class,' reference/proptype ')])"/>
  40. <xsl:variable name="hasValue" select="exists($header/*[contains(@class,' reference/propvaluehd ')] | $properties/*[contains(@class,' reference/propvalue ')])"/>
  41. <xsl:variable name="hasDesc" select="exists($header/*[contains(@class,' reference/propdeschd ')] | $properties/*[contains(@class,' reference/propdesc ')])"/>
  42. <xsl:variable name="prophead" as="element()">
  43. <xsl:choose>
  44. <xsl:when test="*[contains(@class, ' reference/prophead ')]">
  45. <xsl:sequence select="*[contains(@class, ' reference/prophead ')]"/>
  46. </xsl:when>
  47. <xsl:otherwise>
  48. <xsl:variable name="gen" as="element(gen)?">
  49. <xsl:call-template name="gen-prophead">
  50. <xsl:with-param name="hasType" select="$hasType"/>
  51. <xsl:with-param name="hasValue" select="$hasValue"/>
  52. <xsl:with-param name="hasDesc" select="$hasDesc"/>
  53. </xsl:call-template>
  54. </xsl:variable>
  55. <xsl:sequence select="$gen/*"/>
  56. </xsl:otherwise>
  57. </xsl:choose>
  58. </xsl:variable>
  59. <xsl:apply-templates select="$prophead">
  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. <xsl:apply-templates select="*[contains(@class, ' reference/property ')] | processing-instruction()">
  66. <xsl:with-param name="hasType" select="$hasType"/>
  67. <xsl:with-param name="hasValue" select="$hasValue"/>
  68. <xsl:with-param name="hasDesc" select="$hasDesc"/>
  69. </xsl:apply-templates>
  70. </tbody>
  71. </table>
  72. <xsl:apply-templates select="*[contains(@class, ' ditaot-d/ditaval-endprop ')]" mode="out-of-line"/>
  73. </xsl:template>
  74. <xsl:template name="gen-prophead" as="element(gen)?">
  75. <xsl:param name="hasType" as="xs:boolean"/>
  76. <xsl:param name="hasValue" as="xs:boolean"/>
  77. <xsl:param name="hasDesc" as="xs:boolean"/>
  78. <!-- Generated header needs to be wrapped in gen element to allow correct language detection -->
  79. <gen>
  80. <xsl:copy-of select="ancestor-or-self::*[@xml:lang][1]/@xml:lang"/>
  81. <prophead class="- topic/sthead reference/prophead ">
  82. <xsl:if test="$hasType">
  83. <proptypehd class="- topic/stentry reference/proptypehd ">
  84. <xsl:call-template name="getVariable">
  85. <xsl:with-param name="id" select="'Type'"/>
  86. </xsl:call-template>
  87. </proptypehd>
  88. </xsl:if>
  89. <xsl:if test="$hasValue">
  90. <propvaluehd class="- topic/stentry reference/propvaluehd ">
  91. <xsl:call-template name="getVariable">
  92. <xsl:with-param name="id" select="'Value'"/>
  93. </xsl:call-template>
  94. </propvaluehd>
  95. </xsl:if>
  96. <xsl:if test="$hasDesc">
  97. <xsl:call-template name="gen-propdeschd"/>
  98. </xsl:if>
  99. </prophead>
  100. </gen>
  101. </xsl:template>
  102. <xsl:template name="gen-propdeschd">
  103. <xsl:variable name="properties" select="ancestor-or-self::*[contains(@class,' reference/properties ')][1]"/>
  104. <propdeschd class="- topic/stentry reference/propdeschd ">
  105. <xsl:call-template name="getVariable">
  106. <xsl:with-param name="id" select="'Description'"/>
  107. </xsl:call-template>
  108. </propdeschd>
  109. </xsl:template>
  110. <xsl:template match="*[contains(@class,' reference/properties ')]" mode="dita2html:get-max-entry-count" as="xs:integer">
  111. <xsl:sequence select="3"/>
  112. </xsl:template>
  113. <!-- Process the header row in a properties table -->
  114. <xsl:template match="*[contains(@class,' reference/prophead ')]" name="topic.reference.prophead">
  115. <xsl:param name="hasType" as="xs:boolean"/>
  116. <xsl:param name="hasValue" as="xs:boolean"/>
  117. <xsl:param name="hasDesc" as="xs:boolean"/>
  118. <thead>
  119. <tr>
  120. <xsl:call-template name="setid"/>
  121. <xsl:call-template name="commonattributes"/>
  122. <!-- For each of the 3 entry types: If the entry is in this row, apply-templates.
  123. Otherwise, if it is ever in this table, create empty entry, and add ID for accessibility. -->
  124. <xsl:choose> <!-- Process <proptype> -->
  125. <xsl:when test="*[contains(@class,' reference/proptypehd ')]">
  126. <xsl:apply-templates select="*[contains(@class,' reference/proptypehd ')]"/>
  127. </xsl:when>
  128. <xsl:when test="$hasType">
  129. <th scope="col">
  130. <xsl:call-template name="style">
  131. <xsl:with-param name="contents">
  132. <xsl:text>vertical-align:bottom;</xsl:text>
  133. <xsl:call-template name="th-align"/>
  134. </xsl:with-param>
  135. </xsl:call-template>
  136. <xsl:call-template name="getVariable">
  137. <xsl:with-param name="id" select="'Type'"/>
  138. </xsl:call-template>
  139. </th>
  140. </xsl:when>
  141. </xsl:choose>
  142. <xsl:choose> <!-- Process <propvalue> -->
  143. <xsl:when test="*[contains(@class,' reference/propvaluehd ')]">
  144. <xsl:apply-templates select="*[contains(@class,' reference/propvaluehd ')]"/>
  145. </xsl:when>
  146. <xsl:when test="$hasValue">
  147. <th scope="col">
  148. <xsl:call-template name="style">
  149. <xsl:with-param name="contents">
  150. <xsl:text>vertical-align:bottom;</xsl:text>
  151. <xsl:call-template name="th-align"/>
  152. </xsl:with-param>
  153. </xsl:call-template>
  154. <xsl:call-template name="getVariable">
  155. <xsl:with-param name="id" select="'Value'"/>
  156. </xsl:call-template>
  157. </th>
  158. </xsl:when>
  159. </xsl:choose>
  160. <xsl:choose> <!-- Process <propdesc> -->
  161. <xsl:when test="*[contains(@class,' reference/propdeschd ')]">
  162. <xsl:apply-templates select="*[contains(@class,' reference/propdeschd ')]"/>
  163. </xsl:when>
  164. <xsl:when test="$hasDesc">
  165. <xsl:variable name="propdeschd" as="element()">
  166. <xsl:call-template name="gen-propdeschd"/>
  167. </xsl:variable>
  168. <th scope="col">
  169. <xsl:call-template name="style">
  170. <xsl:with-param name="contents">
  171. <xsl:text>vertical-align:bottom;</xsl:text>
  172. <xsl:call-template name="th-align"/>
  173. </xsl:with-param>
  174. </xsl:call-template>
  175. <xsl:call-template name="getVariable">
  176. <xsl:with-param name="id" select="'Description'"/>
  177. </xsl:call-template>
  178. </th>
  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. <xsl:template match="*[contains(@class,' reference/proptype ')]" name="topic.reference.proptype">
  207. <xsl:apply-templates select="." mode="propertiesEntry">
  208. <xsl:with-param name="elementType">type</xsl:with-param>
  209. </xsl:apply-templates>
  210. </xsl:template>
  211. <xsl:template match="*[contains(@class,' reference/propvalue ')]" name="topic.reference.propvalue">
  212. <xsl:apply-templates select="." mode="propertiesEntry">
  213. <xsl:with-param name="elementType">value</xsl:with-param>
  214. </xsl:apply-templates>
  215. </xsl:template>
  216. <xsl:template match="*[contains(@class,' reference/propdesc ')]" name="topic.reference.propdesc">
  217. <xsl:apply-templates select="." mode="propertiesEntry">
  218. <xsl:with-param name="elementType">desc</xsl:with-param>
  219. </xsl:apply-templates>
  220. </xsl:template>
  221. <!-- Template based on the stentry template in dit2htm. Only change is to add elementType
  222. paramenter, and call addPropertiesHeadersAttribute instead of output-stentry-headers. -->
  223. <xsl:template match="*" mode="propertiesEntry">
  224. <xsl:param name="elementType"/>
  225. <xsl:variable name="localkeycol" as="xs:integer">
  226. <xsl:choose>
  227. <xsl:when test="ancestor::*[contains(@class,' topic/simpletable ')][1]/@keycol">
  228. <xsl:value-of select="ancestor::*[contains(@class,' topic/simpletable ')][1]/@keycol"/>
  229. </xsl:when>
  230. <xsl:otherwise>0</xsl:otherwise>
  231. </xsl:choose>
  232. </xsl:variable>
  233. <xsl:variable name="element-name" as="xs:string">
  234. <xsl:choose>
  235. <xsl:when test="$localkeycol = 1 and $elementType = 'type'">th</xsl:when>
  236. <xsl:when test="$localkeycol = 2 and $elementType = 'value'">th</xsl:when>
  237. <xsl:when test="$localkeycol = 3 and $elementType = 'desc'">th</xsl:when>
  238. <xsl:otherwise>td</xsl:otherwise>
  239. </xsl:choose>
  240. </xsl:variable>
  241. <xsl:element name="{$element-name}">
  242. <xsl:call-template name="setid"/>
  243. <xsl:if test="$element-name='th'">
  244. <xsl:attribute name="scope" select="'row'"/>
  245. </xsl:if>
  246. <xsl:call-template name="style">
  247. <xsl:with-param name="contents">
  248. <xsl:text>vertical-align:top;</xsl:text>
  249. </xsl:with-param>
  250. </xsl:call-template>
  251. <xsl:call-template name="commonattributes"/>
  252. <xsl:apply-templates select="../*[contains(@class,' ditaot-d/ditaval-startprop ')]" mode="out-of-line"/>
  253. <xsl:call-template name="propentry-templates"/>
  254. <xsl:apply-templates select="../*[contains(@class,' ditaot-d/ditaval-endprop ')]" mode="out-of-line"/>
  255. </xsl:element>
  256. </xsl:template>
  257. <xsl:template name="propentry-templates">
  258. <xsl:choose>
  259. <xsl:when test="*[not(contains(@class,' ditaot-d/startprop ') or contains(@class,' dita-ot/endprop '))] | text() | processing-instruction()">
  260. <xsl:apply-templates/>
  261. </xsl:when>
  262. <xsl:otherwise>
  263. <!-- Add flags, then either @specentry or NBSP -->
  264. <xsl:apply-templates select="*[contains(@class,' ditaot-d/ditaval-startprop ')]" mode="out-of-line"/>
  265. <xsl:choose>
  266. <xsl:when test="@specentry"><xsl:value-of select="@specentry"/></xsl:when>
  267. <xsl:otherwise>&#160;</xsl:otherwise>
  268. </xsl:choose>
  269. <xsl:apply-templates select="*[contains(@class,' ditaot-d/ditaval-endprop ')]" mode="out-of-line"/>
  270. </xsl:otherwise>
  271. </xsl:choose>
  272. </xsl:template>
  273. <!-- References have their own group. -->
  274. <xsl:template match="*[contains(@class, ' topic/link ')][@type='reference']" mode="related-links:get-group"
  275. name="related-links:group.reference"
  276. as="xs:string">
  277. <xsl:text>reference</xsl:text>
  278. </xsl:template>
  279. <!-- Priority of reference group. -->
  280. <xsl:template match="*[contains(@class, ' topic/link ')][@type='reference']" mode="related-links:get-group-priority"
  281. name="related-links:group-priority.reference"
  282. as="xs:integer">
  283. <xsl:sequence select="1"/>
  284. </xsl:template>
  285. <!-- Reference wrapper for HTML: "Related reference" in <div>. -->
  286. <xsl:template match="*[contains(@class, ' topic/link ')][@type='reference']" mode="related-links:result-group"
  287. name="related-links:result.reference" as="element()">
  288. <xsl:param name="links"/>
  289. <xsl:if test="normalize-space(string-join($links, ''))">
  290. <linklist class="- topic/linklist " outputclass="relinfo relref">
  291. <xsl:copy-of select="ancestor-or-self::*[@xml:lang][1]/@xml:lang"/>
  292. <title class="- topic/title ">
  293. <xsl:call-template name="getVariable">
  294. <xsl:with-param name="id" select="'Related reference'"/>
  295. </xsl:call-template>
  296. </title>
  297. <xsl:copy-of select="$links"/>
  298. </linklist>
  299. </xsl:if>
  300. </xsl:template>
  301. <xsl:include href="plugin:org.dita.html5:xsl/properties.xsl"/>
  302. </xsl:stylesheet>