autolayout.xsl 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. <?xml version="1.0"?>
  2. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  3. version="1.0">
  4. <xsl:output method="xml" indent="no"
  5. doctype-public="-//Norman Walsh//DTD Website Autolayout V2.5.0//EN"
  6. doctype-system="http://docbook.sourceforge.net/release/website/2.5.0/schema/dtd/autolayout.dtd"
  7. />
  8. <xsl:strip-space elements="toc tocentry layout copyright"/>
  9. <xsl:template match="layout">
  10. <autolayout>
  11. <xsl:text>&#10;</xsl:text>
  12. <xsl:apply-templates/>
  13. </autolayout>
  14. <xsl:text>&#10;</xsl:text>
  15. </xsl:template>
  16. <xsl:template match="style|script|headlink|copyright|config">
  17. <xsl:apply-templates select="." mode="copy"/>
  18. </xsl:template>
  19. <xsl:template match="*" mode="copy">
  20. <xsl:element name="{name(.)}">
  21. <xsl:copy-of select="@*"/>
  22. <xsl:apply-templates mode="copy"/>
  23. </xsl:element>
  24. </xsl:template>
  25. <xsl:template match="toc">
  26. <xsl:if test="not(@page)">
  27. <xsl:message terminate="yes">
  28. <xsl:text>All toc entries must have a page attribute.</xsl:text>
  29. </xsl:message>
  30. </xsl:if>
  31. <xsl:variable name="page" select="document(@page,.)"/>
  32. <toc>
  33. <xsl:call-template name="tocentry"/>
  34. </toc>
  35. <xsl:text>&#10;</xsl:text>
  36. </xsl:template>
  37. <xsl:template match="tocentry">
  38. <tocentry>
  39. <xsl:call-template name="tocentry"/>
  40. </tocentry>
  41. <xsl:text>&#10;</xsl:text>
  42. </xsl:template>
  43. <xsl:template match="notoc">
  44. <notoc>
  45. <xsl:call-template name="tocentry"/>
  46. </notoc>
  47. <xsl:text>&#10;</xsl:text>
  48. </xsl:template>
  49. <xsl:template name="tocentry">
  50. <xsl:if test="@revisionflag">
  51. <xsl:attribute name="revisionflag">
  52. <xsl:value-of select="@revisionflag"/>
  53. </xsl:attribute>
  54. </xsl:if>
  55. <xsl:choose>
  56. <xsl:when test="@href">
  57. <xsl:call-template name="tocentry.href"/>
  58. </xsl:when>
  59. <xsl:otherwise>
  60. <xsl:call-template name="tocentry.page"/>
  61. </xsl:otherwise>
  62. </xsl:choose>
  63. </xsl:template>
  64. <xsl:template name="tocentry.href">
  65. <xsl:if test="not(@href)">
  66. <xsl:message terminate="yes">
  67. <xsl:text>All toc entries must have an href attribute.</xsl:text>
  68. </xsl:message>
  69. </xsl:if>
  70. <xsl:if test="not(@id)">
  71. <xsl:message terminate="yes">
  72. <xsl:text>All href toc entries must have an id attribute.</xsl:text>
  73. </xsl:message>
  74. </xsl:if>
  75. <xsl:message>
  76. <xsl:text>off site: </xsl:text>
  77. <xsl:value-of select="@href"/>
  78. </xsl:message>
  79. <xsl:attribute name="id">
  80. <xsl:value-of select="@id"/>
  81. </xsl:attribute>
  82. <xsl:attribute name="href">
  83. <xsl:value-of select="@href"/>
  84. </xsl:attribute>
  85. <xsl:if test="@tocskip = '1'">
  86. <xsl:attribute name="tocskip">
  87. <xsl:value-of select="@tocskip"/>
  88. </xsl:attribute>
  89. </xsl:if>
  90. <xsl:if test="not(title)">
  91. <xsl:message terminate="yes">
  92. <xsl:text>Off-site links must provide a title.</xsl:text>
  93. </xsl:message>
  94. </xsl:if>
  95. <xsl:text>&#10;</xsl:text>
  96. <xsl:apply-templates select="title|titleabbrev|summary" mode="copy"/>
  97. <xsl:text>&#10;</xsl:text>
  98. <xsl:apply-templates select="tocentry"/>
  99. </xsl:template>
  100. <xsl:template name="tocentry.page">
  101. <xsl:if test="not(@page)">
  102. <xsl:message terminate="yes">
  103. <xsl:text>All toc entries must have a page attribute.</xsl:text>
  104. </xsl:message>
  105. </xsl:if>
  106. <xsl:variable name="page" select="document(@page,.)"/>
  107. <xsl:if test="not($page/*[1]/@id)">
  108. <xsl:message terminate="yes">
  109. <xsl:value-of select="@page"/>
  110. <xsl:text>: missing ID.</xsl:text>
  111. </xsl:message>
  112. </xsl:if>
  113. <xsl:variable name="id" select="$page/*[1]/@id"/>
  114. <xsl:variable name="filename">
  115. <xsl:choose>
  116. <xsl:when test="@filename">
  117. <xsl:value-of select="@filename"/>
  118. </xsl:when>
  119. <xsl:when test="/layout/config[@param='default-filename']">
  120. <xsl:value-of select="(/layout/config[@param='default-filename'])[1]/@value"/>
  121. </xsl:when>
  122. <xsl:otherwise>index.html</xsl:otherwise>
  123. </xsl:choose>
  124. </xsl:variable>
  125. <xsl:variable name="dir">
  126. <xsl:apply-templates select="." mode="calculate-dir"/>
  127. </xsl:variable>
  128. <xsl:if test="$filename = ''">
  129. <xsl:message terminate="yes">
  130. <xsl:value-of select="@page"/>
  131. <xsl:text>: missing filename.</xsl:text>
  132. </xsl:message>
  133. </xsl:if>
  134. <xsl:message>
  135. <xsl:value-of select="@page"/>
  136. <xsl:text>: </xsl:text>
  137. <xsl:if test="$dir != ''">
  138. <xsl:value-of select="$dir"/>
  139. </xsl:if>
  140. <xsl:value-of select="$filename"/>
  141. </xsl:message>
  142. <xsl:attribute name="page">
  143. <xsl:value-of select="@page"/>
  144. </xsl:attribute>
  145. <xsl:attribute name="id">
  146. <xsl:value-of select="$id"/>
  147. </xsl:attribute>
  148. <xsl:if test="$dir != ''">
  149. <xsl:attribute name="dir">
  150. <xsl:value-of select="$dir"/>
  151. </xsl:attribute>
  152. </xsl:if>
  153. <xsl:attribute name="filename">
  154. <xsl:value-of select="$filename"/>
  155. </xsl:attribute>
  156. <xsl:if test="@tocskip = '1'">
  157. <xsl:attribute name="tocskip">
  158. <xsl:value-of select="@tocskip"/>
  159. </xsl:attribute>
  160. </xsl:if>
  161. <xsl:text>&#10;</xsl:text>
  162. <xsl:choose>
  163. <xsl:when test="title">
  164. <xsl:apply-templates select="title" mode="copy"/>
  165. </xsl:when>
  166. <xsl:otherwise>
  167. <title>
  168. <xsl:apply-templates select="$page/*[1]/head/title"/>
  169. </title>
  170. </xsl:otherwise>
  171. </xsl:choose>
  172. <xsl:text>&#10;</xsl:text>
  173. <xsl:if test="titleabbrev or $page/*[1]/head/titleabbrev">
  174. <xsl:choose>
  175. <xsl:when test="titleabbrev">
  176. <xsl:apply-templates select="titleabbrev" mode="copy"/>
  177. </xsl:when>
  178. <xsl:otherwise>
  179. <titleabbrev>
  180. <xsl:apply-templates select="$page/*[1]/head/titleabbrev"/>
  181. </titleabbrev>
  182. </xsl:otherwise>
  183. </xsl:choose>
  184. <xsl:text>&#10;</xsl:text>
  185. </xsl:if>
  186. <xsl:if test="summary or $page/*[1]/head/summary">
  187. <xsl:choose>
  188. <xsl:when test="summary">
  189. <xsl:apply-templates select="summary" mode="copy"/>
  190. </xsl:when>
  191. <xsl:otherwise>
  192. <summary>
  193. <xsl:apply-templates select="$page/*[1]/head/summary"/>
  194. </summary>
  195. </xsl:otherwise>
  196. </xsl:choose>
  197. <xsl:text>&#10;</xsl:text>
  198. </xsl:if>
  199. <xsl:apply-templates select="tocentry"/>
  200. </xsl:template>
  201. <xsl:template match="*" mode="calculate-dir">
  202. <xsl:choose>
  203. <xsl:when test="starts-with(@dir, '/')">
  204. <!-- if the directory on this begins with a "/", we're done... -->
  205. <xsl:value-of select="substring-after(@dir, '/')"/>
  206. <xsl:text>/</xsl:text>
  207. </xsl:when>
  208. <xsl:when test="parent::*">
  209. <!-- if there's a parent, try it -->
  210. <xsl:apply-templates select="parent::*" mode="calculate-dir"/>
  211. <xsl:if test="@dir">
  212. <xsl:value-of select="@dir"/>
  213. <xsl:text>/</xsl:text>
  214. </xsl:if>
  215. </xsl:when>
  216. <xsl:otherwise>
  217. <xsl:if test="@dir">
  218. <xsl:value-of select="@dir"/>
  219. <xsl:text>/</xsl:text>
  220. </xsl:if>
  221. </xsl:otherwise>
  222. </xsl:choose>
  223. </xsl:template>
  224. </xsl:stylesheet>