lfs-sections.xsl 5.2 KB

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