lfs-sections.xsl 5.4 KB

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