lfs-navigational.xsl 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  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. <!-- This stylesheet controls how page header and navigational links
  6. are generated. -->
  7. <!-- html.head:
  8. Drop all navigational links from inside head xhtml output. -->
  9. <!-- The original template is in {docbook-xsl}/xhtml/chunk-common.xsl -->
  10. <xsl:template name="html.head">
  11. <head>
  12. <xsl:call-template name="system.head.content"/>
  13. <xsl:call-template name="head.content"/>
  14. <xsl:call-template name="user.head.content"/>
  15. </head>
  16. </xsl:template>
  17. <!-- header.navigation:
  18. Self-made template that full replaces the original one -->
  19. <!-- The original template is in {docbook-xsl}/xhtml/chunk-common.xsl -->
  20. <xsl:template name="header.navigation">
  21. <xsl:param name="prev" select="/foo"/>
  22. <xsl:param name="next" select="/foo"/>
  23. <xsl:variable name="up" select="parent::*"/>
  24. <xsl:variable name="home" select="/*[1]"/>
  25. <xsl:variable name="row" select="count($prev) &gt; 0 or (count($up) &gt; 0
  26. and generate-id($up) != generate-id($home)) or count($next) &gt; 0"/>
  27. <!-- Don't generate the header in index.html -->
  28. <xsl:if test="$row and $home != .">
  29. <div class="navheader">
  30. <!-- Add common titles -->
  31. <div class="headertitles">
  32. <!-- Book title and version -->
  33. <h4>
  34. <xsl:apply-templates select="$home" mode="object.title.markup"/>
  35. <xsl:text> - </xsl:text>
  36. <xsl:apply-templates select="$home" mode="object.subtitle.markup"/>
  37. </h4>
  38. <!-- Except for preface, part, and index, add the title of the parent -->
  39. <xsl:if test="$up != $home">
  40. <h3>
  41. <xsl:apply-templates select="$up" mode="object.title.markup"/>
  42. </h3>
  43. </xsl:if>
  44. </div>
  45. <!-- Create header navigational links -->
  46. <xsl:call-template name="navigational.links">
  47. <xsl:with-param name="prev" select="$prev"/>
  48. <xsl:with-param name="next" select="$next"/>
  49. <xsl:with-param name="up" select="$up"/>
  50. <xsl:with-param name="home" select="$home"/>
  51. </xsl:call-template>
  52. </div>
  53. </xsl:if>
  54. </xsl:template>
  55. <!-- footer.navigation:
  56. Self-made template that full replaces the original one -->
  57. <!-- The original template is in {docbook-xsl}/xhtml/chunk-common.xsl -->
  58. <xsl:template name="footer.navigation">
  59. <xsl:param name="prev" select="/foo"/>
  60. <xsl:param name="next" select="/foo"/>
  61. <xsl:variable name="up" select="parent::*"/>
  62. <xsl:variable name="home" select="/*[1]"/>
  63. <xsl:variable name="row" select="count($prev) &gt; 0 or count($up) &gt; 0
  64. or count($next) &gt; 0 or generate-id($home) != generate-id(.)"/>
  65. <xsl:if test="$row">
  66. <div class="navfooter">
  67. <!-- Create footer navigational links -->
  68. <xsl:call-template name="navigational.links">
  69. <xsl:with-param name="prev" select="$prev"/>
  70. <xsl:with-param name="next" select="$next"/>
  71. <xsl:with-param name="up" select="$up"/>
  72. <xsl:with-param name="home" select="$home"/>
  73. </xsl:call-template>
  74. </div>
  75. </xsl:if>
  76. <xsl:if test="$book-type = 'hlfs'">
  77. <script type="text/javascript">
  78. <xsl:attribute name="src">
  79. <xsl:choose>
  80. <xsl:when test="local-name(.)='book' or local-name(.)='part' or
  81. local-name(.)='index'">../features.js</xsl:when>
  82. <xsl:otherwise>../../features.js</xsl:otherwise>
  83. </xsl:choose>
  84. </xsl:attribute>
  85. </script>
  86. </xsl:if>
  87. </xsl:template>
  88. <!-- navigational.links:
  89. Self-made template to generate navigational links.
  90. Most of the code come from the original header.navigation and
  91. footer.navigation templates, with this changes:
  92. Changed the output format from table to ul.
  93. Placed the same links on both header and footer.
  94. Added a title attribute to the link containing the target title
  95. (it content is displayed when placing the mouse over the link)
  96. For "Prev" and "Next" links, added the target title under it.
  97. When "Next" target is the Index, added gentext support for the
  98. Index title.
  99. Skip links to dummy sect1. -->
  100. <xsl:template name="navigational.links">
  101. <xsl:param name="prev"/>
  102. <xsl:param name="next"/>
  103. <xsl:param name="up"/>
  104. <xsl:param name="home"/>
  105. <ul>
  106. <xsl:if test="count($prev)&gt;0 and $prev != $home">
  107. <li class="prev">
  108. <xsl:choose>
  109. <xsl:when test="$prev[@role='dummy'] and
  110. count(preceding-sibling::sect1)=1">
  111. <a accesskey="p">
  112. <xsl:attribute name="href">
  113. <xsl:call-template name="href.target">
  114. <xsl:with-param name="object" select=".."/>
  115. </xsl:call-template>
  116. </xsl:attribute>
  117. <xsl:attribute name="title">
  118. <xsl:value-of select="../title"/>
  119. </xsl:attribute>
  120. <xsl:call-template name="navig.content">
  121. <xsl:with-param name="direction" select="'prev'"/>
  122. </xsl:call-template>
  123. </a>
  124. <p>
  125. <xsl:value-of select="../title"/>
  126. </p>
  127. </xsl:when>
  128. <xsl:when test="$prev[@role='dummy'] and
  129. count(preceding-sibling::sect1)&gt;1">
  130. <a accesskey="p">
  131. <xsl:attribute name="href">
  132. <xsl:call-template name="href.target">
  133. <xsl:with-param name="object" select="preceding-sibling::sect1[position()=2]"/>
  134. </xsl:call-template>
  135. </xsl:attribute>
  136. <xsl:attribute name="title">
  137. <xsl:value-of select="preceding-sibling::sect1[position()=2]/title"/>
  138. </xsl:attribute>
  139. <xsl:call-template name="navig.content">
  140. <xsl:with-param name="direction" select="'prev'"/>
  141. </xsl:call-template>
  142. </a>
  143. <p>
  144. <xsl:value-of select="preceding-sibling::sect1[position()=2]/title"/>
  145. </p>
  146. </xsl:when>
  147. <xsl:otherwise>
  148. <a accesskey="p">
  149. <xsl:attribute name="href">
  150. <xsl:call-template name="href.target">
  151. <xsl:with-param name="object" select="$prev"/>
  152. </xsl:call-template>
  153. </xsl:attribute>
  154. <xsl:attribute name="title">
  155. <xsl:value-of select="$prev/title"/>
  156. </xsl:attribute>
  157. <xsl:call-template name="navig.content">
  158. <xsl:with-param name="direction" select="'prev'"/>
  159. </xsl:call-template>
  160. </a>
  161. <p>
  162. <xsl:value-of select="$prev/title"/>
  163. </p>
  164. </xsl:otherwise>
  165. </xsl:choose>
  166. </li>
  167. </xsl:if>
  168. <xsl:if test="count($next)&gt;0">
  169. <li class="next">
  170. <xsl:choose>
  171. <xsl:when test="$next[@role='dummy'] and local-name(.) = 'sect1'">
  172. <a accesskey="n">
  173. <xsl:attribute name="href">
  174. <xsl:call-template name="href.target">
  175. <xsl:with-param name="object" select="following-sibling::sect1[position()=2]"/>
  176. </xsl:call-template>
  177. </xsl:attribute>
  178. <xsl:attribute name="title">
  179. <xsl:value-of select="following-sibling::sect1[position()=2]/title"/>
  180. </xsl:attribute>
  181. <xsl:call-template name="navig.content">
  182. <xsl:with-param name="direction" select="'next'"/>
  183. </xsl:call-template>
  184. </a>
  185. <p>
  186. <xsl:value-of select="following-sibling::sect1[position()=2]/title"/>
  187. </p>
  188. </xsl:when>
  189. <xsl:when test="$next[@role='dummy'] and local-name(.) = 'chapter'">
  190. <a accesskey="n">
  191. <xsl:attribute name="href">
  192. <xsl:call-template name="href.target">
  193. <xsl:with-param name="object" select="descendant::sect1[position()=2]"/>
  194. </xsl:call-template>
  195. </xsl:attribute>
  196. <xsl:attribute name="title">
  197. <xsl:value-of select="descendant::sect1[position()=2]/title"/>
  198. </xsl:attribute>
  199. <xsl:call-template name="navig.content">
  200. <xsl:with-param name="direction" select="'next'"/>
  201. </xsl:call-template>
  202. </a>
  203. <p>
  204. <xsl:value-of select="descendant::sect1[position()=2]/title"/>
  205. </p>
  206. </xsl:when>
  207. <xsl:otherwise>
  208. <a accesskey="n">
  209. <xsl:attribute name="href">
  210. <xsl:call-template name="href.target">
  211. <xsl:with-param name="object" select="$next"/>
  212. </xsl:call-template>
  213. </xsl:attribute>
  214. <xsl:attribute name="title">
  215. <xsl:choose>
  216. <xsl:when test="local-name($next)='index'">
  217. <xsl:call-template name="gentext">
  218. <xsl:with-param name="key">Index</xsl:with-param>
  219. </xsl:call-template>
  220. </xsl:when>
  221. <xsl:otherwise>
  222. <xsl:value-of select="$next/title"/>
  223. </xsl:otherwise>
  224. </xsl:choose>
  225. </xsl:attribute>
  226. <xsl:call-template name="navig.content">
  227. <xsl:with-param name="direction" select="'next'"/>
  228. </xsl:call-template>
  229. </a>
  230. <p>
  231. <xsl:choose>
  232. <xsl:when test="local-name($next)='index'">
  233. <xsl:call-template name="gentext">
  234. <xsl:with-param name="key">Index</xsl:with-param>
  235. </xsl:call-template>
  236. </xsl:when>
  237. <xsl:otherwise>
  238. <xsl:value-of select="$next/title"/>
  239. </xsl:otherwise>
  240. </xsl:choose>
  241. </p>
  242. </xsl:otherwise>
  243. </xsl:choose>
  244. </li>
  245. </xsl:if>
  246. <li class="up">
  247. <xsl:choose>
  248. <xsl:when test="count($up)&gt;0 and $up != $home">
  249. <a accesskey="u">
  250. <xsl:attribute name="href">
  251. <xsl:call-template name="href.target">
  252. <xsl:with-param name="object" select="$up"/>
  253. </xsl:call-template>
  254. </xsl:attribute>
  255. <xsl:attribute name="title">
  256. <xsl:apply-templates select="$up" mode="object.title.markup"/>
  257. </xsl:attribute>
  258. <xsl:call-template name="navig.content">
  259. <xsl:with-param name="direction" select="'up'"/>
  260. </xsl:call-template>
  261. </a>
  262. </xsl:when>
  263. <!-- Hack to let the CSS code do its work when there is no up link -->
  264. <xsl:otherwise>
  265. <xsl:text>.</xsl:text>
  266. </xsl:otherwise>
  267. </xsl:choose>
  268. </li>
  269. <li class="home">
  270. <xsl:choose>
  271. <xsl:when test="$home != .">
  272. <a accesskey="h">
  273. <xsl:attribute name="href">
  274. <xsl:call-template name="href.target">
  275. <xsl:with-param name="object" select="$home"/>
  276. </xsl:call-template>
  277. </xsl:attribute>
  278. <xsl:attribute name="title">
  279. <xsl:value-of select="$home/bookinfo/title"/>
  280. <xsl:text> - </xsl:text>
  281. <xsl:value-of select="$home/bookinfo/subtitle"/>
  282. </xsl:attribute>
  283. <xsl:call-template name="navig.content">
  284. <xsl:with-param name="direction" select="'home'"/>
  285. </xsl:call-template>
  286. </a>
  287. </xsl:when>
  288. <!-- Hack to let the CSS code do its work when there is no home link -->
  289. <xsl:otherwise>
  290. <xsl:text>.</xsl:text>
  291. </xsl:otherwise>
  292. </xsl:choose>
  293. </li>
  294. </ul>
  295. </xsl:template>
  296. </xsl:stylesheet>