lfs-sections.xsl 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <?xml version='1.0' encoding='ISO-8859-1'?>
  2. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  3. xmlns="http://www.w3.org/1999/xhtml"
  4. version="1.0">
  5. <!-- REVISED -->
  6. <!-- This stylesheet controls how sections are handled -->
  7. <!-- Chunk the first top-level section? 1 = yes, 0 = no
  8. If chapters TOC are generated, this must be 1.
  9. See also sect1.titlepage template in lfs-titles.xsl -->
  10. <xsl:param name="chunk.first.sections" select="1"></xsl:param>
  11. <!-- sect1:
  12. When there is a role attibute, use it as the class value.
  13. Removed unused code. -->
  14. <!-- The original template is in {docbook-xsl}/xhtml/sections.xsl -->
  15. <xsl:template match="sect1">
  16. <div>
  17. <xsl:choose>
  18. <xsl:when test="@role">
  19. <xsl:attribute name="class">
  20. <xsl:value-of select="@role"/>
  21. </xsl:attribute>
  22. </xsl:when>
  23. <xsl:otherwise>
  24. <xsl:apply-templates select="." mode="class.attribute"/>
  25. </xsl:otherwise>
  26. </xsl:choose>
  27. <xsl:call-template name="language.attribute"/>
  28. <xsl:call-template name="sect1.titlepage"/>
  29. <xsl:apply-templates/>
  30. <xsl:call-template name="process.chunk.footnotes"/>
  31. </div>
  32. </xsl:template>
  33. <!-- sect2:
  34. When there is a role attibute, use it as the class value.
  35. Removed unused code. -->
  36. <!-- The original template is in {docbook-xsl}/xhtml/sections.xsl -->
  37. <xsl:template match="sect2">
  38. <div>
  39. <xsl:choose>
  40. <xsl:when test="@role">
  41. <xsl:attribute name="class">
  42. <xsl:value-of select="@role"/>
  43. </xsl:attribute>
  44. </xsl:when>
  45. <xsl:otherwise>
  46. <xsl:attribute name="class">
  47. <xsl:value-of select="name(.)"/>
  48. </xsl:attribute>
  49. </xsl:otherwise>
  50. </xsl:choose>
  51. <xsl:call-template name="language.attribute"/>
  52. <xsl:call-template name="sect2.titlepage"/>
  53. <xsl:apply-templates/>
  54. <xsl:call-template name="process.chunk.footnotes"/>
  55. </div>
  56. </xsl:template>
  57. <!-- Are sections enumerated? 1 = yes, 0 = no -->
  58. <xsl:param name="section.autolabel" select="1"/>
  59. <!-- Do section labels include the component label? 1 = yes, 0 = no -->
  60. <xsl:param name="section.label.includes.component.label" select="1"/>
  61. <!-- sect1 label.markup:
  62. Use lowercase roman numbers for sect1 in preface. -->
  63. <!-- The original template is in {docbook-xsl}/common/labels.xsl -->
  64. <xsl:template match="sect1" mode="label.markup">
  65. <!-- if the parent is a component, maybe label that too -->
  66. <xsl:variable name="parent.is.component">
  67. <xsl:call-template name="is.component">
  68. <xsl:with-param name="node" select=".."/>
  69. </xsl:call-template>
  70. </xsl:variable>
  71. <xsl:variable name="component.label">
  72. <xsl:if test="$section.label.includes.component.label != 0
  73. and $parent.is.component != 0">
  74. <xsl:variable name="parent.label">
  75. <xsl:apply-templates select=".." mode="label.markup"/>
  76. </xsl:variable>
  77. <xsl:if test="$parent.label != ''">
  78. <xsl:apply-templates select=".." mode="label.markup"/>
  79. <xsl:apply-templates select=".." mode="intralabel.punctuation"/>
  80. </xsl:if>
  81. </xsl:if>
  82. </xsl:variable>
  83. <xsl:choose>
  84. <xsl:when test="@label">
  85. <xsl:value-of select="@label"/>
  86. </xsl:when>
  87. <xsl:when test="$section.autolabel != 0">
  88. <xsl:copy-of select="$component.label"/>
  89. <xsl:choose>
  90. <xsl:when test="ancestor::preface">
  91. <xsl:number format="i" count="sect1"/>
  92. </xsl:when>
  93. <xsl:otherwise>
  94. <xsl:number format="1" count="sect1"/>
  95. </xsl:otherwise>
  96. </xsl:choose>
  97. </xsl:when>
  98. </xsl:choose>
  99. </xsl:template>
  100. <!-- sect2 label.markup:
  101. Skip numeration for sect2 with empty title -->
  102. <!-- The original template is in {docbook-xsl}/common/labels.xsl
  103. It match also sect3, sect4, and sect5, that are unchanged. -->
  104. <xsl:template match="sect2" mode="label.markup">
  105. <xsl:if test="string-length(title) > 0">
  106. <!-- label the parent -->
  107. <xsl:variable name="parent.section.label">
  108. <xsl:call-template name="label.this.section">
  109. <xsl:with-param name="section" select=".."/>
  110. </xsl:call-template>
  111. </xsl:variable>
  112. <xsl:if test="$parent.section.label != '0'">
  113. <xsl:apply-templates select=".." mode="label.markup"/>
  114. <xsl:apply-templates select=".." mode="intralabel.punctuation"/>
  115. </xsl:if>
  116. <xsl:choose>
  117. <xsl:when test="@label">
  118. <xsl:value-of select="@label"/>
  119. </xsl:when>
  120. <xsl:when test="$section.autolabel != 0">
  121. <xsl:choose>
  122. <!-- If the first sect2 isn't numbered, renumber the remainig sections -->
  123. <xsl:when test="string-length(../sect2[1]/title) = 0">
  124. <xsl:variable name="totalsect2">
  125. <xsl:number count="sect2"/>
  126. </xsl:variable>
  127. <xsl:number value="$totalsect2 - 1"/>
  128. </xsl:when>
  129. <xsl:otherwise>
  130. <xsl:number count="sect2"/>
  131. </xsl:otherwise>
  132. </xsl:choose>
  133. </xsl:when>
  134. <xsl:otherwise>
  135. <xsl:message>label.markup: this can't happen!</xsl:message>
  136. </xsl:otherwise>
  137. </xsl:choose>
  138. </xsl:if>
  139. </xsl:template>
  140. </xsl:stylesheet>