lfs-sections.xsl 4.9 KB

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