toc.xsl 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  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="html"/>
  5. <xsl:param name="max.toc.width" select="7"/>
  6. <xsl:template match="toc/title|tocentry/title|titleabbrev">
  7. <xsl:apply-templates/>
  8. </xsl:template>
  9. <xsl:template match="toc">
  10. <xsl:param name="pageid" select="@id"/>
  11. <xsl:variable name="relpath">
  12. <xsl:call-template name="toc-rel-path">
  13. <xsl:with-param name="pageid" select="$pageid"/>
  14. </xsl:call-template>
  15. </xsl:variable>
  16. <xsl:variable name="homebanner"
  17. select="/autolayout/config[@param='homebanner'][1]"/>
  18. <xsl:variable name="banner"
  19. select="/autolayout/config[@param='banner'][1]"/>
  20. <xsl:variable name="homebannertext"
  21. select="/autolayout/config[@param='homebannertext'][1]"/>
  22. <xsl:variable name="bannertext"
  23. select="/autolayout/config[@param='bannertext'][1]"/>
  24. <xsl:choose>
  25. <xsl:when test="$pageid = @id">
  26. <xsl:choose>
  27. <xsl:when test="$homebanner">
  28. <img border="0">
  29. <xsl:attribute name="src">
  30. <xsl:value-of select="$relpath"/>
  31. <xsl:value-of select="$homebanner/@value"/>
  32. </xsl:attribute>
  33. <xsl:attribute name="alt">
  34. <xsl:value-of select="$homebanner/@altval"/>
  35. </xsl:attribute>
  36. </img>
  37. <xsl:value-of select="$currentpage.marker"/>
  38. </xsl:when>
  39. <xsl:when test="$homebannertext">
  40. <xsl:value-of select="$homebannertext/@value"/>
  41. <xsl:value-of select="$currentpage.marker"/>
  42. </xsl:when>
  43. <xsl:otherwise>
  44. <xsl:call-template name="gentext.nav.home"/>
  45. <xsl:value-of select="$currentpage.marker"/>
  46. </xsl:otherwise>
  47. </xsl:choose>
  48. </xsl:when>
  49. <xsl:otherwise>
  50. <a href="{$relpath}{@dir}{$filename-prefix}{@filename}">
  51. <xsl:choose>
  52. <xsl:when test="$banner">
  53. <img border="0">
  54. <xsl:attribute name="src">
  55. <xsl:value-of select="$relpath"/>
  56. <xsl:value-of select="$banner/@value"/>
  57. </xsl:attribute>
  58. <xsl:attribute name="alt">
  59. <xsl:value-of select="$banner/@altval"/>
  60. </xsl:attribute>
  61. </img>
  62. </xsl:when>
  63. <xsl:when test="$bannertext">
  64. <xsl:value-of select="$bannertext/@value"/>
  65. </xsl:when>
  66. <xsl:otherwise>
  67. <xsl:call-template name="gentext.nav.home"/>
  68. </xsl:otherwise>
  69. </xsl:choose>
  70. </a>
  71. </xsl:otherwise>
  72. </xsl:choose>
  73. <xsl:text> | </xsl:text>
  74. <xsl:call-template name="process-children">
  75. <xsl:with-param name="pageid" select="$pageid"/>
  76. <xsl:with-param name="relpath" select="$relpath"/>
  77. </xsl:call-template>
  78. </xsl:template>
  79. <xsl:template match="tocentry">
  80. <xsl:param name="pageid" select="@id"/>
  81. <xsl:param name="relpath" select="''"/>
  82. <xsl:if test="preceding-sibling::tocentry">
  83. <xsl:text> | </xsl:text>
  84. </xsl:if>
  85. <xsl:choose>
  86. <xsl:when test="$pageid = @id">
  87. <xsl:choose>
  88. <xsl:when test="titleabbrev">
  89. <xsl:apply-templates select="titleabbrev"/>
  90. </xsl:when>
  91. <xsl:otherwise>
  92. <xsl:apply-templates select="title"/>
  93. </xsl:otherwise>
  94. </xsl:choose>
  95. <xsl:value-of select="$currentpage.marker"/>
  96. </xsl:when>
  97. <xsl:otherwise>
  98. <a>
  99. <xsl:attribute name="href">
  100. <xsl:choose>
  101. <xsl:when test="@href">
  102. <xsl:value-of select="@href"/>
  103. </xsl:when>
  104. <xsl:otherwise>
  105. <xsl:value-of select="$relpath"/>
  106. <xsl:value-of select="@dir"/>
  107. <xsl:value-of select="$filename-prefix"/>
  108. <xsl:value-of select="@filename"/>
  109. </xsl:otherwise>
  110. </xsl:choose>
  111. </xsl:attribute>
  112. <xsl:choose>
  113. <xsl:when test="titleabbrev">
  114. <xsl:apply-templates select="titleabbrev"/>
  115. </xsl:when>
  116. <xsl:otherwise>
  117. <xsl:apply-templates select="title"/>
  118. </xsl:otherwise>
  119. </xsl:choose>
  120. </a>
  121. </xsl:otherwise>
  122. </xsl:choose>
  123. </xsl:template>
  124. <xsl:template match="toc|tocentry|notoc" mode="toc-rel-path">
  125. <xsl:call-template name="toc-rel-path"/>
  126. </xsl:template>
  127. <xsl:template name="toc-rel-path">
  128. <xsl:param name="pageid" select="@id"/>
  129. <xsl:variable name="entry" select="$autolayout//*[@id=$pageid]"/>
  130. <xsl:variable name="filename" select="concat($entry/@dir,$entry/@filename)"/>
  131. <xsl:variable name="depth">
  132. <xsl:call-template name="toc-directory-depth">
  133. <xsl:with-param name="filename" select="$filename"/>
  134. </xsl:call-template>
  135. </xsl:variable>
  136. <xsl:if test="$depth > 0">
  137. <xsl:call-template name="copy-string">
  138. <xsl:with-param name="string">../</xsl:with-param>
  139. <xsl:with-param name="count" select="$depth"/>
  140. </xsl:call-template>
  141. </xsl:if>
  142. </xsl:template>
  143. <xsl:template name="toc-directory-depth">
  144. <xsl:param name="filename"></xsl:param>
  145. <xsl:param name="count" select="0"/>
  146. <xsl:choose>
  147. <xsl:when test='contains($filename,"/")'>
  148. <xsl:call-template name="toc-directory-depth">
  149. <xsl:with-param name="filename"
  150. select="substring-after($filename,'/')"/>
  151. <xsl:with-param name="count" select="$count + 1"/>
  152. </xsl:call-template>
  153. </xsl:when>
  154. <xsl:otherwise>
  155. <xsl:value-of select="$count"/>
  156. </xsl:otherwise>
  157. </xsl:choose>
  158. </xsl:template>
  159. <xsl:template name="process-children">
  160. <xsl:param name="pageid" select="@id"/>
  161. <xsl:param name="relpath" select="''"/>
  162. <xsl:choose>
  163. <xsl:when test="tocentry[descendant-or-self::*[@id=$pageid]]">
  164. <xsl:call-template name="process-tocentry-children">
  165. <xsl:with-param name="pageid" select="$pageid"/>
  166. <xsl:with-param name="relpath" select="$relpath"/>
  167. </xsl:call-template>
  168. </xsl:when>
  169. <xsl:otherwise>
  170. <xsl:call-template name="process-toc-children">
  171. <xsl:with-param name="pageid" select="$pageid"/>
  172. <xsl:with-param name="relpath" select="$relpath"/>
  173. </xsl:call-template>
  174. </xsl:otherwise>
  175. </xsl:choose>
  176. </xsl:template>
  177. <xsl:template name="process-tocentry-children">
  178. <xsl:param name="pageid" select="@id"/>
  179. <xsl:param name="relpath" select="''"/>
  180. <xsl:choose>
  181. <xsl:when test="count(tocentry) &gt; $max.toc.width">
  182. <xsl:variable name="cur"
  183. select="tocentry[descendant-or-self::*[@id=$pageid]]"/>
  184. <xsl:variable name="half" select="$max.toc.width div 2"/>
  185. <xsl:variable name="all-nodes"
  186. select="$cur/preceding-sibling::tocentry[position() &lt; $half]
  187. | $cur
  188. | $cur/following-sibling::tocentry"/>
  189. <xsl:variable name="nodes"
  190. select="$all-nodes[position() &lt; $max.toc.width]"/>
  191. <xsl:if test="count($cur/preceding-sibling::tocentry) &gt; $half">
  192. <xsl:text>...</xsl:text>
  193. </xsl:if>
  194. <xsl:apply-templates select="$nodes">
  195. <xsl:with-param name="pageid" select="$pageid"/>
  196. <xsl:with-param name="relpath" select="$relpath"/>
  197. </xsl:apply-templates>
  198. <xsl:if test="count($all-nodes) &gt; $max.toc.width">
  199. <xsl:text> | ...</xsl:text>
  200. </xsl:if>
  201. </xsl:when>
  202. <xsl:otherwise>
  203. <xsl:apply-templates select="tocentry">
  204. <xsl:with-param name="pageid" select="$pageid"/>
  205. <xsl:with-param name="relpath" select="$relpath"/>
  206. </xsl:apply-templates>
  207. </xsl:otherwise>
  208. </xsl:choose>
  209. <br/>
  210. <!-- if the current page isn't in this list, keep digging... -->
  211. <xsl:if test="not(tocentry[$pageid=@id])">
  212. <xsl:for-each select="tocentry">
  213. <xsl:if test="descendant::*[@id=$pageid]">
  214. <xsl:call-template name="process-children">
  215. <xsl:with-param name="pageid" select="$pageid"/>
  216. <xsl:with-param name="relpath" select="$relpath"/>
  217. </xsl:call-template>
  218. </xsl:if>
  219. </xsl:for-each>
  220. </xsl:if>
  221. </xsl:template>
  222. <xsl:template name="process-toc-children">
  223. <xsl:param name="pageid" select="@id"/>
  224. <xsl:param name="relpath" select="''"/>
  225. <xsl:choose>
  226. <xsl:when test="count(tocentry) &gt; $max.toc.width">
  227. <xsl:variable name="half" select="$max.toc.width div 2"/>
  228. <xsl:variable name="all-nodes" select="tocentry"/>
  229. <xsl:variable name="nodes"
  230. select="$all-nodes[position() &lt; $max.toc.width]"/>
  231. <xsl:apply-templates select="$nodes">
  232. <xsl:with-param name="pageid" select="$pageid"/>
  233. <xsl:with-param name="relpath" select="$relpath"/>
  234. </xsl:apply-templates>
  235. <xsl:if test="count($all-nodes) &gt; $max.toc.width">
  236. <xsl:text> | ...</xsl:text>
  237. </xsl:if>
  238. </xsl:when>
  239. <xsl:otherwise>
  240. <xsl:apply-templates select="tocentry">
  241. <xsl:with-param name="pageid" select="$pageid"/>
  242. <xsl:with-param name="relpath" select="$relpath"/>
  243. </xsl:apply-templates>
  244. </xsl:otherwise>
  245. </xsl:choose>
  246. <br/>
  247. </xsl:template>
  248. </xsl:stylesheet>