tables.xsl 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- This file is part of the DITA Open Toolkit project.
  3. See the accompanying license.txt file for applicable licenses. -->
  4. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  5. xmlns:xs="http://www.w3.org/2001/XMLSchema"
  6. xmlns:dita-ot="http://dita-ot.sourceforge.net/ns/201007/dita-ot"
  7. xmlns:table="http://dita-ot.sourceforge.net/ns/201007/dita-ot/table"
  8. version="2.0"
  9. exclude-result-prefixes="xs dita-ot table">
  10. <xsl:template match="*" mode="table:common">
  11. <xsl:call-template name="commonattributes"/>
  12. <xsl:call-template name="setid"/>
  13. <xsl:apply-templates select="." mode="css-class"/>
  14. </xsl:template>
  15. <xsl:template match="*[contains(@class,' topic/table ')]" name="topic.table">
  16. <xsl:apply-templates select="*[contains(@class, ' ditaot-d/ditaval-startprop ')]" mode="out-of-line"/>
  17. <table>
  18. <xsl:apply-templates select="." mode="table:common"/>
  19. <xsl:apply-templates select="." mode="table:title"/>
  20. <!-- title and desc are processed elsewhere -->
  21. <xsl:apply-templates select="*[contains(@class, ' topic/tgroup ')]"/>
  22. </table>
  23. <xsl:apply-templates select="*[contains(@class, ' ditaot-d/ditaval-endprop ')]" mode="out-of-line"/>
  24. </xsl:template>
  25. <xsl:template match="*[contains(@class, ' topic/thead ')]" name="topic.thead">
  26. <thead>
  27. <xsl:apply-templates select="." mode="table:section"/>
  28. </thead>
  29. </xsl:template>
  30. <xsl:template match="*[contains(@class, ' topic/tbody ')]" name="topic.tbody">
  31. <tbody>
  32. <xsl:apply-templates select="." mode="table:section"/>
  33. </tbody>
  34. </xsl:template>
  35. <xsl:template match="*[contains(@class, ' topic/tgroup ')]/*" mode="table:section">
  36. <xsl:apply-templates select="../*[contains(@class, ' ditaot-d/ditaval-startprop ')]/@outputclass" mode="add-ditaval-style"/>
  37. <xsl:apply-templates select="." mode="table:common"/>
  38. <xsl:apply-templates/>
  39. </xsl:template>
  40. <xsl:template match="*[contains(@class, ' topic/row ')]" name="topic.row">
  41. <tr>
  42. <xsl:apply-templates select="." mode="table:common"/>
  43. <xsl:apply-templates/>
  44. </tr>
  45. </xsl:template>
  46. <xsl:template match="*[table:is-thead-entry(.)]">
  47. <th>
  48. <xsl:apply-templates select="." mode="table:entry"/>
  49. </th>
  50. </xsl:template>
  51. <xsl:template match="*[table:is-tbody-entry(.)][table:is-row-header(.)]">
  52. <th scope="row">
  53. <xsl:apply-templates select="." mode="table:entry"/>
  54. </th>
  55. </xsl:template>
  56. <xsl:template match="*[table:is-tbody-entry(.)][not(table:is-row-header(.))]" name="topic.entry">
  57. <td>
  58. <xsl:apply-templates select="." mode="table:entry"/>
  59. </td>
  60. </xsl:template>
  61. <xsl:template match="*[contains(@class, ' topic/entry ')]" mode="table:entry">
  62. <xsl:apply-templates select="." mode="table:common"/>
  63. <xsl:apply-templates select="." mode="headers"/>
  64. <xsl:apply-templates select="@morerows, @dita-ot:morecols"/>
  65. <xsl:apply-templates/>
  66. </xsl:template>
  67. <xsl:template match="@pgwide" mode="css-class">
  68. <xsl:sequence select="dita-ot:css-class(.)"/>
  69. </xsl:template>
  70. <xsl:template match="*[contains(@class, ' topic/table ')]" mode="css-class">
  71. <xsl:apply-templates select="@frame, @pgwide, @scale" mode="#current"/>
  72. </xsl:template>
  73. <xsl:template match="@align | @valign | @colsep | @rowsep" mode="css-class">
  74. <xsl:sequence select="dita-ot:css-class((), .)"/>
  75. </xsl:template>
  76. <xsl:template match="*[contains(@class, ' topic/tgroup ')]/*" mode="css-class">
  77. <xsl:apply-templates select="@valign" mode="#current"/>
  78. </xsl:template>
  79. <xsl:template match="*[contains(@class, ' topic/row ')]" mode="css-class">
  80. <xsl:apply-templates select="@rowsep, @valign" mode="#current"/>
  81. </xsl:template>
  82. <xsl:template match="*[contains(@class, ' topic/entry ')]" mode="css-class">
  83. <xsl:variable name="colsep" as="attribute(colsep)?" select="table:get-entry-colsep(.)"/>
  84. <xsl:variable name="rowsep" as="attribute(rowsep)?" select="table:get-entry-rowsep(.)"/>
  85. <xsl:apply-templates select="." mode="legacy-css-class">
  86. <xsl:with-param name="colsep" as="xs:integer"
  87. select="xs:integer(($colsep, $table.colsep-default)[1])"/>
  88. <xsl:with-param name="rowsep" as="xs:integer"
  89. select="xs:integer(($rowsep, $table.rowsep-default)[1])"/>
  90. </xsl:apply-templates>
  91. <xsl:apply-templates mode="#current" select="
  92. table:get-entry-align(.), $colsep, $rowsep, @valign
  93. "/>
  94. </xsl:template>
  95. <!-- deprecated since 2.3 -->
  96. <xsl:template match="*[contains(@class, ' topic/entry ')]" mode="legacy-css-class" as="xs:string*">
  97. <xsl:param name="colsep" as="xs:integer"/>
  98. <xsl:param name="rowsep" as="xs:integer"/>
  99. <xsl:if test="table:is-row-header(.)">firstcol</xsl:if>
  100. <xsl:choose>
  101. <xsl:when test="not($rowsep) and not($colsep)">nocellnorowborder</xsl:when>
  102. <xsl:when test="$rowsep = 1 and not($colsep)">row-nocellborder</xsl:when>
  103. <xsl:when test="not($rowsep) and $colsep = 1">cell-norowborder</xsl:when>
  104. <xsl:when test="$rowsep = 1 and $colsep = 1">cellrowborder</xsl:when>
  105. </xsl:choose>
  106. </xsl:template>
  107. <xsl:template match="*[table:is-thead-entry(.)]" mode="headers">
  108. <xsl:attribute name="id" select="dita-ot:generate-html-id(.)"/>
  109. </xsl:template>
  110. <xsl:template match="*[table:is-tbody-entry(.)]" mode="headers">
  111. <xsl:call-template name="add-headers-attribute"/>
  112. </xsl:template>
  113. <xsl:template match="@morerows">
  114. <xsl:attribute name="rowspan" select="xs:integer(.) + 1"/>
  115. </xsl:template>
  116. <xsl:template match="@dita-ot:morecols">
  117. <xsl:attribute name="colspan" select="xs:integer(.) + 1"/>
  118. </xsl:template>
  119. <xsl:template match="*[contains(@class, ' topic/table ')]" mode="table:title">
  120. <caption>
  121. <xsl:apply-templates select="*[contains(@class, ' topic/title ')]" mode="label"/>
  122. <xsl:apply-templates select="
  123. *[contains(@class, ' topic/title ')] | *[contains(@class, ' topic/desc ')]
  124. "/>
  125. </caption>
  126. </xsl:template>
  127. <xsl:template match="*[contains(@class, ' topic/table ')]/*[contains(@class, ' topic/title ')]" mode="label">
  128. <span class="table--title-label">
  129. <xsl:apply-templates select="." mode="title-number">
  130. <xsl:with-param name="number" as="xs:integer"
  131. select="count(key('enumerableByClass', 'topic/table')[. &lt;&lt; current()])"/>
  132. </xsl:apply-templates>
  133. </span>
  134. </xsl:template>
  135. <xsl:template match="*[contains(@class, ' topic/table ')]/*[contains(@class, ' topic/title ')]" mode="title-number">
  136. <xsl:param name="number" as="xs:integer"/>
  137. <xsl:sequence select="concat(dita-ot:get-variable(., 'Table'), ' ', $number, '. ')"/>
  138. </xsl:template>
  139. <xsl:template mode="title-number" priority="1" match="
  140. *[contains(@class, ' topic/table ')]
  141. [dita-ot:get-current-language(.) = ('hu', 'hu-hu')]
  142. /*[contains(@class, ' topic/title ')]
  143. ">
  144. <xsl:param name="number" as="xs:integer"/>
  145. <xsl:sequence select="concat($number, '. ', dita-ot:get-variable(., 'Table'), ' ')"/>
  146. </xsl:template>
  147. <xsl:template match="
  148. *[contains(@class, ' topic/table ')]/*[contains(@class, ' topic/title ')]
  149. | *[contains(@class, ' topic/table ')]/*[contains(@class, ' topic/desc ')]
  150. ">
  151. <span>
  152. <xsl:call-template name="setid"/>
  153. <xsl:call-template name="commonattributes"/>
  154. <xsl:apply-templates/>
  155. </span>
  156. </xsl:template>
  157. </xsl:stylesheet>