toc-tabular.xsl 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480
  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="nav.graphics" select="1"/>
  6. <xsl:param name="nav.pointer" select="1"/>
  7. <xsl:param name="nav.revisionflag" select="1"/>
  8. <xsl:param name="toc.spacer.text">&#160;&#160;&#160;</xsl:param>
  9. <xsl:param name="toc.spacer.image">graphics/blank.gif</xsl:param>
  10. <xsl:param name="nav.icon.path">graphics/navicons/</xsl:param>
  11. <xsl:param name="nav.icon.extension">.gif</xsl:param>
  12. <!-- styles: folder, folder16, plusminus, triangle, arrow -->
  13. <xsl:param name="nav.icon.style">triangle</xsl:param>
  14. <xsl:param name="nav.text.spacer">&#160;</xsl:param>
  15. <xsl:param name="nav.text.current.open">+</xsl:param>
  16. <xsl:param name="nav.text.current.page">+</xsl:param>
  17. <xsl:param name="nav.text.other.open">&#160;</xsl:param>
  18. <xsl:param name="nav.text.other.closed">&#160;</xsl:param>
  19. <xsl:param name="nav.text.other.page">&#160;</xsl:param>
  20. <xsl:param name="nav.text.revisionflag.added">New</xsl:param>
  21. <xsl:param name="nav.text.revisionflag.changed">Changed</xsl:param>
  22. <xsl:param name="nav.text.revisionflag.deleted"></xsl:param>
  23. <xsl:param name="nav.text.revisionflag.off"></xsl:param>
  24. <xsl:param name="nav.text.pointer">&lt;-</xsl:param>
  25. <xsl:param name="toc.expand.depth" select="1"/>
  26. <!-- ==================================================================== -->
  27. <xsl:template match="toc/title|tocentry/title|titleabbrev">
  28. <xsl:apply-templates/>
  29. </xsl:template>
  30. <xsl:template match="toc">
  31. <xsl:param name="pageid" select="@id"/>
  32. <xsl:variable name="relpath">
  33. <xsl:call-template name="toc-rel-path">
  34. <xsl:with-param name="pageid" select="$pageid"/>
  35. </xsl:call-template>
  36. </xsl:variable>
  37. <xsl:variable name="homebanner"
  38. select="/autolayout/config[@param='homebanner-tabular'][1]"/>
  39. <xsl:variable name="banner"
  40. select="/autolayout/config[@param='banner-tabular'][1]"/>
  41. <xsl:choose>
  42. <xsl:when test="$pageid = @id">
  43. <img align="left" border="0">
  44. <xsl:attribute name="src">
  45. <xsl:value-of select="$relpath"/>
  46. <xsl:value-of select="$homebanner/@value"/>
  47. </xsl:attribute>
  48. <xsl:attribute name="alt">
  49. <xsl:value-of select="$homebanner/@altval"/>
  50. </xsl:attribute>
  51. </img>
  52. <br clear="all"/>
  53. <br/>
  54. </xsl:when>
  55. <xsl:otherwise>
  56. <a href="{$relpath}{@dir}{$filename-prefix}{@filename}">
  57. <img align="left" border="0">
  58. <xsl:attribute name="src">
  59. <xsl:value-of select="$relpath"/>
  60. <xsl:value-of select="$banner/@value"/>
  61. </xsl:attribute>
  62. <xsl:attribute name="alt">
  63. <xsl:value-of select="$banner/@altval"/>
  64. </xsl:attribute>
  65. </img>
  66. </a>
  67. <br clear="all"/>
  68. <br/>
  69. </xsl:otherwise>
  70. </xsl:choose>
  71. <xsl:apply-templates select="tocentry">
  72. <xsl:with-param name="pageid" select="$pageid"/>
  73. <xsl:with-param name="relpath" select="$relpath"/>
  74. </xsl:apply-templates>
  75. <br/>
  76. </xsl:template>
  77. <!-- ==================================================================== -->
  78. <xsl:template match="tocentry">
  79. <xsl:param name="pageid" select="@id"/>
  80. <xsl:param name="toclevel" select="count(ancestor::*)"/>
  81. <xsl:param name="relpath" select="''"/>
  82. <xsl:param name="revisionflag" select="@revisionflag"/>
  83. <xsl:variable name="page" select="."/>
  84. <xsl:variable name="target"
  85. select="($page/descendant-or-self::tocentry[not(@tocskip) or @tocskip = '0']
  86. |$page/following::tocentry[@tocskip and @tocskip='0'])[1]"/>
  87. <xsl:variable name="depth" select="count(ancestor::*)-1"/>
  88. <xsl:variable name="isdescendant">
  89. <xsl:choose>
  90. <xsl:when test="ancestor::*[@id=$pageid]">1</xsl:when>
  91. <xsl:otherwise>0</xsl:otherwise>
  92. </xsl:choose>
  93. </xsl:variable>
  94. <xsl:variable name="hasdescendant">
  95. <xsl:choose>
  96. <xsl:when test="descendant::tocentry != ''">1</xsl:when>
  97. <xsl:otherwise>0</xsl:otherwise>
  98. </xsl:choose>
  99. </xsl:variable>
  100. <xsl:variable name="isancestor">
  101. <xsl:choose>
  102. <xsl:when test="descendant::*[@id=$pageid]">1</xsl:when>
  103. <xsl:otherwise>0</xsl:otherwise>
  104. </xsl:choose>
  105. </xsl:variable>
  106. <xsl:variable name="use.toc.expand.depth">
  107. <xsl:variable name="config-param" select="ancestor::autolayout/config[@param='toc.expand.depth']/@value"/>
  108. <xsl:choose>
  109. <!-- toc.expand.depth attribute is not in DTD -->
  110. <xsl:when test="ancestor::toc/@toc.expand.depth">
  111. <xsl:value-of select="ancestor::toc/@toc.expand.depth"/>
  112. </xsl:when>
  113. <xsl:when test="floor($config-param) > 0">
  114. <xsl:value-of select="$config-param"/>
  115. </xsl:when>
  116. <xsl:otherwise>
  117. <xsl:value-of select="$toc.expand.depth"/>
  118. </xsl:otherwise>
  119. </xsl:choose>
  120. </xsl:variable>
  121. <xsl:variable name="is.open">
  122. <xsl:choose>
  123. <xsl:when test="$pageid = @id
  124. or $isancestor='1'
  125. or $depth &lt; $use.toc.expand.depth">1</xsl:when>
  126. <xsl:otherwise>0</xsl:otherwise>
  127. </xsl:choose>
  128. </xsl:variable>
  129. <!-- For any entry in the TOC:
  130. 1. It is the current page
  131. a. it is a leaf current/leaf
  132. b. it is an open page current/open
  133. 2. It is not the current page
  134. a. it is a leaf other/leaf
  135. b. it is an open page other/open
  136. c. it is a closed page other/closed
  137. -->
  138. <xsl:variable name="preceding-icon">
  139. <xsl:value-of select="$relpath"/>
  140. <xsl:value-of select="$nav.icon.path"/>
  141. <xsl:value-of select="$nav.icon.style"/>
  142. <xsl:choose>
  143. <xsl:when test="$pageid=@id">
  144. <xsl:choose>
  145. <xsl:when test="$hasdescendant != 0">
  146. <xsl:text>/current/open</xsl:text>
  147. </xsl:when>
  148. <xsl:otherwise>
  149. <xsl:text>/current/leaf</xsl:text>
  150. </xsl:otherwise>
  151. </xsl:choose>
  152. </xsl:when>
  153. <xsl:otherwise>
  154. <xsl:choose>
  155. <xsl:when test="$hasdescendant = 0">
  156. <xsl:text>/other/leaf</xsl:text>
  157. </xsl:when>
  158. <xsl:when test="$is.open != 0">
  159. <xsl:text>/other/open</xsl:text>
  160. </xsl:when>
  161. <xsl:otherwise>
  162. <xsl:text>/other/closed</xsl:text>
  163. </xsl:otherwise>
  164. </xsl:choose>
  165. </xsl:otherwise>
  166. </xsl:choose>
  167. <xsl:value-of select="$nav.icon.extension"/>
  168. </xsl:variable>
  169. <xsl:variable name="preceding-text">
  170. <xsl:choose>
  171. <xsl:when test="$pageid=@id">
  172. <xsl:choose>
  173. <xsl:when test="$hasdescendant != 0">
  174. <xsl:value-of select="$nav.text.current.open"/>
  175. </xsl:when>
  176. <xsl:otherwise>
  177. <xsl:value-of select="$nav.text.current.page"/>
  178. </xsl:otherwise>
  179. </xsl:choose>
  180. </xsl:when>
  181. <xsl:otherwise>
  182. <xsl:choose>
  183. <xsl:when test="$isancestor != 0">
  184. <xsl:value-of select="$nav.text.other.open"/>
  185. </xsl:when>
  186. <xsl:when test="$hasdescendant != 0">
  187. <xsl:value-of select="$nav.text.other.closed"/>
  188. </xsl:when>
  189. <xsl:otherwise>
  190. <xsl:value-of select="$nav.text.other.page"/>
  191. </xsl:otherwise>
  192. </xsl:choose>
  193. </xsl:otherwise>
  194. </xsl:choose>
  195. </xsl:variable>
  196. <xsl:variable name="following-icon">
  197. <xsl:value-of select="$relpath"/>
  198. <xsl:value-of select="$nav.icon.path"/>
  199. <xsl:value-of select="$nav.icon.style"/>
  200. <xsl:text>/current/pointer</xsl:text>
  201. <xsl:value-of select="$nav.icon.extension"/>
  202. </xsl:variable>
  203. <xsl:variable name="following-text">
  204. <xsl:value-of select="$nav.text.pointer"/>
  205. </xsl:variable>
  206. <xsl:variable name="revisionflag-icon">
  207. <xsl:value-of select="$relpath"/>
  208. <xsl:value-of select="$nav.icon.path"/>
  209. <xsl:value-of select="$nav.icon.style"/>
  210. <xsl:text>/</xsl:text>
  211. <xsl:value-of select="$revisionflag"/>
  212. <xsl:value-of select="$nav.icon.extension"/>
  213. </xsl:variable>
  214. <xsl:variable name="revisionflag-text">
  215. <xsl:choose>
  216. <xsl:when test="$revisionflag = 'changed'">
  217. <xsl:value-of select="$nav.text.revisionflag.changed"/>
  218. </xsl:when>
  219. <xsl:when test="$revisionflag = 'added'">
  220. <xsl:value-of select="$nav.text.revisionflag.added"/>
  221. </xsl:when>
  222. <xsl:when test="$revisionflag = 'deleted'">
  223. <xsl:value-of select="$nav.text.revisionflag.deleted"/>
  224. </xsl:when>
  225. <xsl:otherwise>
  226. <xsl:value-of select="$nav.text.revisionflag.off"/>
  227. </xsl:otherwise>
  228. </xsl:choose>
  229. </xsl:variable>
  230. <span>
  231. <xsl:if test="$toclevel = 2">
  232. <xsl:attribute name="class">
  233. <xsl:text>toplevel</xsl:text>
  234. </xsl:attribute>
  235. </xsl:if>
  236. <xsl:if test="$toclevel &gt; 2">
  237. <xsl:attribute name="class">
  238. <xsl:text>shrink</xsl:text>
  239. <xsl:value-of select="$toclevel - 2"/>
  240. </xsl:attribute>
  241. </xsl:if>
  242. <xsl:call-template name="insert.spacers">
  243. <xsl:with-param name="count" select="$toclevel - 1"/>
  244. <xsl:with-param name="relpath" select="$relpath"/>
  245. </xsl:call-template>
  246. <xsl:choose>
  247. <xsl:when test="$nav.graphics != 0">
  248. <xsl:call-template name="link.to.page">
  249. <xsl:with-param name="href" select="@href"/>
  250. <xsl:with-param name="page" select="$target"/>
  251. <xsl:with-param name="relpath" select="$relpath"/>
  252. <xsl:with-param name="linktext">
  253. <img src="{$preceding-icon}" alt="{$preceding-text}" border="0"/>
  254. </xsl:with-param>
  255. </xsl:call-template>
  256. </xsl:when>
  257. <xsl:otherwise>
  258. <xsl:value-of select="$preceding-text"/>
  259. </xsl:otherwise>
  260. </xsl:choose>
  261. <xsl:choose>
  262. <xsl:when test="$pageid = @id">
  263. <span class="curpage">
  264. <xsl:choose>
  265. <xsl:when test="titleabbrev">
  266. <xsl:apply-templates select="titleabbrev"/>
  267. </xsl:when>
  268. <xsl:otherwise>
  269. <xsl:apply-templates select="title"/>
  270. </xsl:otherwise>
  271. </xsl:choose>
  272. <xsl:if test="$nav.revisionflag != '0' and $revisionflag">
  273. <xsl:value-of select="$nav.text.spacer"/>
  274. <xsl:choose>
  275. <xsl:when test="$nav.graphics = '1'">
  276. <img src="{$revisionflag-icon}" alt="{$revisionflag-text}" align="bottom"/>
  277. </xsl:when>
  278. <xsl:otherwise>
  279. <xsl:text>(</xsl:text>
  280. <xsl:value-of select="$revisionflag-text"/>
  281. <xsl:text>)</xsl:text>
  282. </xsl:otherwise>
  283. </xsl:choose>
  284. </xsl:if>
  285. <xsl:if test="$nav.pointer != '0'">
  286. <xsl:value-of select="$nav.text.spacer"/>
  287. <xsl:choose>
  288. <xsl:when test="$nav.graphics = '1'">
  289. <img src="{$following-icon}" alt="{$following-text}"/>
  290. </xsl:when>
  291. <xsl:otherwise>
  292. <xsl:value-of select="$following-text"/>
  293. </xsl:otherwise>
  294. </xsl:choose>
  295. </xsl:if>
  296. </span>
  297. <br/>
  298. </xsl:when>
  299. <xsl:otherwise>
  300. <span>
  301. <xsl:choose>
  302. <xsl:when test="$isdescendant='0'">
  303. <xsl:choose>
  304. <xsl:when test="$isancestor='1'">
  305. <xsl:attribute name="class">ancestor</xsl:attribute>
  306. </xsl:when>
  307. <xsl:otherwise>
  308. <xsl:attribute name="class">otherpage</xsl:attribute>
  309. </xsl:otherwise>
  310. </xsl:choose>
  311. </xsl:when>
  312. <xsl:otherwise>
  313. <!-- IS a descendant of curpage -->
  314. <xsl:attribute name="class">descendant</xsl:attribute>
  315. </xsl:otherwise>
  316. </xsl:choose>
  317. <xsl:call-template name="link.to.page">
  318. <xsl:with-param name="href" select="@href"/>
  319. <xsl:with-param name="page" select="$target"/>
  320. <xsl:with-param name="relpath" select="$relpath"/>
  321. <xsl:with-param name="linktext">
  322. <xsl:choose>
  323. <xsl:when test="titleabbrev">
  324. <xsl:apply-templates select="titleabbrev"/>
  325. </xsl:when>
  326. <xsl:otherwise>
  327. <xsl:apply-templates select="title"/>
  328. </xsl:otherwise>
  329. </xsl:choose>
  330. </xsl:with-param>
  331. </xsl:call-template>
  332. <xsl:if test="$nav.revisionflag != '0' and $revisionflag">
  333. <xsl:value-of select="$nav.text.spacer"/>
  334. <xsl:choose>
  335. <xsl:when test="$nav.graphics = '1'">
  336. <img src="{$revisionflag-icon}" alt="{$revisionflag-text}"/>
  337. </xsl:when>
  338. <xsl:otherwise>
  339. <xsl:text>(</xsl:text>
  340. <xsl:value-of select="$revisionflag-text"/>
  341. <xsl:text>)</xsl:text>
  342. </xsl:otherwise>
  343. </xsl:choose>
  344. </xsl:if>
  345. </span>
  346. <br/>
  347. </xsl:otherwise>
  348. </xsl:choose>
  349. </span>
  350. <xsl:if test="$is.open != 0">
  351. <xsl:apply-templates select="tocentry">
  352. <xsl:with-param name="pageid" select="$pageid"/>
  353. <xsl:with-param name="relpath" select="$relpath"/>
  354. </xsl:apply-templates>
  355. </xsl:if>
  356. </xsl:template>
  357. <xsl:template name="insert.spacers">
  358. <xsl:param name="count" select="0"/>
  359. <xsl:param name="relpath"/>
  360. <xsl:if test="$count>0">
  361. <xsl:choose>
  362. <xsl:when test="$nav.graphics != 0">
  363. <img src="{$relpath}{$toc.spacer.image}" alt="{$toc.spacer.text}"/>
  364. </xsl:when>
  365. <xsl:otherwise>
  366. <xsl:value-of select="$toc.spacer.text"/>
  367. </xsl:otherwise>
  368. </xsl:choose>
  369. <xsl:call-template name="insert.spacers">
  370. <xsl:with-param name="count" select="$count - 1"/>
  371. <xsl:with-param name="relpath" select="$relpath"/>
  372. </xsl:call-template>
  373. </xsl:if>
  374. </xsl:template>
  375. <xsl:template match="toc|tocentry|notoc" mode="toc-rel-path">
  376. <xsl:call-template name="toc-rel-path"/>
  377. </xsl:template>
  378. <xsl:template name="toc-rel-path">
  379. <xsl:param name="pageid" select="@id"/>
  380. <xsl:variable name="entry" select="$autolayout//*[@id=$pageid]"/>
  381. <xsl:variable name="filename" select="concat($entry/@dir,$entry/@filename)"/>
  382. <xsl:variable name="slash-count">
  383. <xsl:call-template name="toc-directory-depth">
  384. <xsl:with-param name="filename" select="$filename"/>
  385. </xsl:call-template>
  386. </xsl:variable>
  387. <xsl:variable name="depth">
  388. <xsl:choose>
  389. <xsl:when test="starts-with($filename, '/')">
  390. <xsl:value-of select="$slash-count - 1"/>
  391. </xsl:when>
  392. <xsl:otherwise>
  393. <xsl:value-of select="$slash-count"/>
  394. </xsl:otherwise>
  395. </xsl:choose>
  396. </xsl:variable>
  397. <!--
  398. <xsl:message>
  399. <xsl:value-of select="$filename"/>
  400. <xsl:text> depth=</xsl:text>
  401. <xsl:value-of select="$depth"/>
  402. </xsl:message>
  403. -->
  404. <xsl:if test="$depth > 0">
  405. <xsl:call-template name="copy-string">
  406. <xsl:with-param name="string">../</xsl:with-param>
  407. <xsl:with-param name="count" select="$depth"/>
  408. </xsl:call-template>
  409. </xsl:if>
  410. </xsl:template>
  411. <xsl:template name="toc-directory-depth">
  412. <xsl:param name="filename"></xsl:param>
  413. <xsl:param name="count" select="0"/>
  414. <xsl:choose>
  415. <xsl:when test='contains($filename,"/")'>
  416. <xsl:call-template name="toc-directory-depth">
  417. <xsl:with-param name="filename"
  418. select="substring-after($filename,'/')"/>
  419. <xsl:with-param name="count" select="$count + 1"/>
  420. </xsl:call-template>
  421. </xsl:when>
  422. <xsl:otherwise>
  423. <xsl:value-of select="$count"/>
  424. </xsl:otherwise>
  425. </xsl:choose>
  426. </xsl:template>
  427. </xsl:stylesheet>