chunk-common.xsl 83 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995
  1. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  2. xmlns:exsl="http://exslt.org/common"
  3. xmlns:cf="http://docbook.sourceforge.net/xmlns/chunkfast/1.0"
  4. xmlns:ng="http://docbook.org/docbook-ng"
  5. xmlns:db="http://docbook.org/ns/docbook"
  6. version="1.0"
  7. exclude-result-prefixes="exsl cf ng db">
  8. <!-- ********************************************************************
  9. $Id: chunk-common.xsl 9717 2013-01-25 18:13:36Z bobstayton $
  10. ********************************************************************
  11. This file is part of the XSL DocBook Stylesheet distribution.
  12. See ../README or http://docbook.sf.net/release/xsl/current/ for
  13. copyright and other information.
  14. ******************************************************************** -->
  15. <!-- ==================================================================== -->
  16. <xsl:param name="onechunk" select="0"/>
  17. <xsl:param name="refentry.separator" select="0"/>
  18. <xsl:param name="chunk.fast" select="0"/>
  19. <xsl:key name="genid" match="*" use="generate-id()"/>
  20. <!-- ==================================================================== -->
  21. <xsl:variable name="chunk.hierarchy">
  22. <xsl:if test="$chunk.fast != 0">
  23. <xsl:choose>
  24. <!-- Are we handling a docbook5 document? -->
  25. <xsl:when test="$exsl.node.set.available != 0
  26. and (*/self::ng:* or */self::db:*)">
  27. <xsl:if test="$chunk.quietly = 0">
  28. <xsl:message>Computing stripped namespace chunks...</xsl:message>
  29. </xsl:if>
  30. <xsl:apply-templates mode="find.chunks" select="exsl:node-set($no.namespace)"/>
  31. </xsl:when>
  32. <xsl:when test="$exsl.node.set.available != 0">
  33. <xsl:if test="$chunk.quietly = 0">
  34. <xsl:message>Computing chunks...</xsl:message>
  35. </xsl:if>
  36. <xsl:apply-templates select="/*" mode="find.chunks"/>
  37. </xsl:when>
  38. <xsl:otherwise>
  39. <xsl:if test="$chunk.quietly = 0">
  40. <xsl:message>
  41. <xsl:text>Fast chunking requires exsl:node-set(). </xsl:text>
  42. <xsl:text>Using "slow" chunking.</xsl:text>
  43. </xsl:message>
  44. </xsl:if>
  45. </xsl:otherwise>
  46. </xsl:choose>
  47. </xsl:if>
  48. </xsl:variable>
  49. <!-- ==================================================================== -->
  50. <xsl:template name="process-chunk-element">
  51. <xsl:param name="content">
  52. <xsl:apply-imports/>
  53. </xsl:param>
  54. <xsl:choose>
  55. <xsl:when test="$chunk.fast != 0 and $exsl.node.set.available != 0">
  56. <xsl:variable name="chunks" select="exsl:node-set($chunk.hierarchy)//cf:div"/>
  57. <xsl:variable name="genid" select="generate-id()"/>
  58. <xsl:variable name="div" select="$chunks[@id=$genid or @xml:id=$genid]"/>
  59. <xsl:variable name="prevdiv"
  60. select="($div/preceding-sibling::cf:div|$div/preceding::cf:div|$div/parent::cf:div)[last()]"/>
  61. <xsl:variable name="prev" select="key('genid', ($prevdiv/@id|$prevdiv/@xml:id)[1])"/>
  62. <xsl:variable name="nextdiv"
  63. select="($div/following-sibling::cf:div|$div/following::cf:div|$div/cf:div)[1]"/>
  64. <xsl:variable name="next" select="key('genid', ($nextdiv/@id|$nextdiv/@xml:id)[1])"/>
  65. <xsl:choose>
  66. <xsl:when test="$onechunk != 0 and parent::*">
  67. <xsl:copy-of select="$content"/>
  68. </xsl:when>
  69. <xsl:otherwise>
  70. <xsl:call-template name="process-chunk">
  71. <xsl:with-param name="prev" select="$prev"/>
  72. <xsl:with-param name="next" select="$next"/>
  73. <xsl:with-param name="content" select="$content"/>
  74. </xsl:call-template>
  75. </xsl:otherwise>
  76. </xsl:choose>
  77. </xsl:when>
  78. <xsl:otherwise>
  79. <xsl:choose>
  80. <xsl:when test="$onechunk != 0 and not(parent::*)">
  81. <xsl:call-template name="chunk-all-sections">
  82. <xsl:with-param name="content" select="$content"/>
  83. </xsl:call-template>
  84. </xsl:when>
  85. <xsl:when test="$onechunk != 0">
  86. <xsl:copy-of select="$content"/>
  87. </xsl:when>
  88. <xsl:when test="$chunk.first.sections = 0">
  89. <xsl:call-template name="chunk-first-section-with-parent">
  90. <xsl:with-param name="content" select="$content"/>
  91. </xsl:call-template>
  92. </xsl:when>
  93. <xsl:otherwise>
  94. <xsl:call-template name="chunk-all-sections">
  95. <xsl:with-param name="content" select="$content"/>
  96. </xsl:call-template>
  97. </xsl:otherwise>
  98. </xsl:choose>
  99. </xsl:otherwise>
  100. </xsl:choose>
  101. </xsl:template>
  102. <xsl:template name="process-chunk">
  103. <xsl:param name="prev" select="."/>
  104. <xsl:param name="next" select="."/>
  105. <xsl:param name="content">
  106. <xsl:apply-imports/>
  107. </xsl:param>
  108. <xsl:variable name="ischunk">
  109. <xsl:call-template name="chunk"/>
  110. </xsl:variable>
  111. <xsl:variable name="chunkfn">
  112. <xsl:if test="$ischunk='1'">
  113. <xsl:apply-templates mode="chunk-filename" select="."/>
  114. </xsl:if>
  115. </xsl:variable>
  116. <xsl:if test="$ischunk='0'">
  117. <xsl:message>
  118. <xsl:text>Error </xsl:text>
  119. <xsl:value-of select="name(.)"/>
  120. <xsl:text> is not a chunk!</xsl:text>
  121. </xsl:message>
  122. </xsl:if>
  123. <xsl:variable name="filename">
  124. <xsl:call-template name="make-relative-filename">
  125. <xsl:with-param name="base.dir" select="$chunk.base.dir"/>
  126. <xsl:with-param name="base.name" select="$chunkfn"/>
  127. </xsl:call-template>
  128. </xsl:variable>
  129. <xsl:call-template name="write.chunk">
  130. <xsl:with-param name="filename" select="$filename"/>
  131. <xsl:with-param name="content">
  132. <xsl:call-template name="chunk-element-content">
  133. <xsl:with-param name="prev" select="$prev"/>
  134. <xsl:with-param name="next" select="$next"/>
  135. <xsl:with-param name="content" select="$content"/>
  136. </xsl:call-template>
  137. </xsl:with-param>
  138. <xsl:with-param name="quiet" select="$chunk.quietly"/>
  139. </xsl:call-template>
  140. </xsl:template>
  141. <xsl:template name="chunk-first-section-with-parent">
  142. <xsl:param name="content">
  143. <xsl:apply-imports/>
  144. </xsl:param>
  145. <!-- These xpath expressions are really hairy. The trick is to pick sections -->
  146. <!-- that are not first children and are not the children of first children -->
  147. <!-- Break these variables into pieces to work around
  148. http://nagoya.apache.org/bugzilla/show_bug.cgi?id=6063 -->
  149. <xsl:variable name="prev-v1"
  150. select="(ancestor::sect1[$chunk.section.depth &gt; 0
  151. and not(ancestor::*/processing-instruction('dbhtml')[normalize-space(.) ='stop-chunking'])
  152. and preceding-sibling::sect1][1]
  153. |ancestor::sect2[$chunk.section.depth &gt; 1
  154. and not(ancestor::*/processing-instruction('dbhtml')[normalize-space(.) ='stop-chunking'])
  155. and preceding-sibling::sect2
  156. and parent::sect1[preceding-sibling::sect1]][1]
  157. |ancestor::sect3[$chunk.section.depth &gt; 2
  158. and not(ancestor::*/processing-instruction('dbhtml')[normalize-space(.) ='stop-chunking'])
  159. and preceding-sibling::sect3
  160. and parent::sect2[preceding-sibling::sect2]
  161. and ancestor::sect1[preceding-sibling::sect1]][1]
  162. |ancestor::sect4[$chunk.section.depth &gt; 3
  163. and not(ancestor::*/processing-instruction('dbhtml')[normalize-space(.) ='stop-chunking'])
  164. and preceding-sibling::sect4
  165. and parent::sect3[preceding-sibling::sect3]
  166. and ancestor::sect2[preceding-sibling::sect2]
  167. and ancestor::sect1[preceding-sibling::sect1]][1]
  168. |ancestor::sect5[$chunk.section.depth &gt; 4
  169. and not(ancestor::*/processing-instruction('dbhtml')[normalize-space(.) ='stop-chunking'])
  170. and preceding-sibling::sect5
  171. and parent::sect4[preceding-sibling::sect4]
  172. and ancestor::sect3[preceding-sibling::sect3]
  173. and ancestor::sect2[preceding-sibling::sect2]
  174. and ancestor::sect1[preceding-sibling::sect1]][1]
  175. |ancestor::section[$chunk.section.depth &gt; count(ancestor::section)
  176. and not(ancestor::*/processing-instruction('dbhtml')[normalize-space(.) ='stop-chunking'])
  177. and not(ancestor::section[not(preceding-sibling::section)])][1])[last()]"/>
  178. <xsl:variable name="prev-v2"
  179. select="(preceding::sect1[$chunk.section.depth &gt; 0
  180. and not(ancestor::*/processing-instruction('dbhtml')[normalize-space(.) ='stop-chunking'])
  181. and preceding-sibling::sect1][1]
  182. |preceding::sect2[$chunk.section.depth &gt; 1
  183. and not(ancestor::*/processing-instruction('dbhtml')[normalize-space(.) ='stop-chunking'])
  184. and preceding-sibling::sect2
  185. and parent::sect1[preceding-sibling::sect1]][1]
  186. |preceding::sect3[$chunk.section.depth &gt; 2
  187. and not(ancestor::*/processing-instruction('dbhtml')[normalize-space(.) ='stop-chunking'])
  188. and preceding-sibling::sect3
  189. and parent::sect2[preceding-sibling::sect2]
  190. and ancestor::sect1[preceding-sibling::sect1]][1]
  191. |preceding::sect4[$chunk.section.depth &gt; 3
  192. and not(ancestor::*/processing-instruction('dbhtml')[normalize-space(.) ='stop-chunking'])
  193. and preceding-sibling::sect4
  194. and parent::sect3[preceding-sibling::sect3]
  195. and ancestor::sect2[preceding-sibling::sect2]
  196. and ancestor::sect1[preceding-sibling::sect1]][1]
  197. |preceding::sect5[$chunk.section.depth &gt; 4
  198. and not(ancestor::*/processing-instruction('dbhtml')[normalize-space(.) ='stop-chunking'])
  199. and preceding-sibling::sect5
  200. and parent::sect4[preceding-sibling::sect4]
  201. and ancestor::sect3[preceding-sibling::sect3]
  202. and ancestor::sect2[preceding-sibling::sect2]
  203. and ancestor::sect1[preceding-sibling::sect1]][1]
  204. |preceding::section[$chunk.section.depth &gt; count(ancestor::section)
  205. and not(ancestor::*/processing-instruction('dbhtml')[normalize-space(.) ='stop-chunking'])
  206. and preceding-sibling::section
  207. and not(ancestor::section[not(preceding-sibling::section)])][1])[last()]"/>
  208. <xsl:variable name="prev"
  209. select="(preceding::book[1]
  210. |preceding::preface[1]
  211. |preceding::chapter[1]
  212. |preceding::appendix[1]
  213. |preceding::part[1]
  214. |preceding::reference[1]
  215. |preceding::refentry[1]
  216. |preceding::colophon[1]
  217. |preceding::article[1]
  218. |preceding::topic[1]
  219. |preceding::bibliography[parent::article or parent::book or parent::part][1]
  220. |preceding::glossary[parent::article or parent::book or parent::part][1]
  221. |preceding::index[$generate.index != 0]
  222. [parent::article or parent::book or parent::part][1]
  223. |preceding::setindex[$generate.index != 0][1]
  224. |ancestor::set
  225. |ancestor::book[1]
  226. |ancestor::preface[1]
  227. |ancestor::chapter[1]
  228. |ancestor::appendix[1]
  229. |ancestor::part[1]
  230. |ancestor::reference[1]
  231. |ancestor::article[1]
  232. |ancestor::topic[1]
  233. |$prev-v1
  234. |$prev-v2)[last()]"/>
  235. <xsl:variable name="next-v1"
  236. select="(following::sect1[$chunk.section.depth &gt; 0
  237. and not(ancestor::*/processing-instruction('dbhtml')[normalize-space(.) ='stop-chunking'])
  238. and preceding-sibling::sect1][1]
  239. |following::sect2[$chunk.section.depth &gt; 1
  240. and not(ancestor::*/processing-instruction('dbhtml')[normalize-space(.) ='stop-chunking'])
  241. and preceding-sibling::sect2
  242. and parent::sect1[preceding-sibling::sect1]][1]
  243. |following::sect3[$chunk.section.depth &gt; 2
  244. and not(ancestor::*/processing-instruction('dbhtml')[normalize-space(.) ='stop-chunking'])
  245. and preceding-sibling::sect3
  246. and parent::sect2[preceding-sibling::sect2]
  247. and ancestor::sect1[preceding-sibling::sect1]][1]
  248. |following::sect4[$chunk.section.depth &gt; 3
  249. and not(ancestor::*/processing-instruction('dbhtml')[normalize-space(.) ='stop-chunking'])
  250. and preceding-sibling::sect4
  251. and parent::sect3[preceding-sibling::sect3]
  252. and ancestor::sect2[preceding-sibling::sect2]
  253. and ancestor::sect1[preceding-sibling::sect1]][1]
  254. |following::sect5[$chunk.section.depth &gt; 4
  255. and not(ancestor::*/processing-instruction('dbhtml')[normalize-space(.) ='stop-chunking'])
  256. and preceding-sibling::sect5
  257. and parent::sect4[preceding-sibling::sect4]
  258. and ancestor::sect3[preceding-sibling::sect3]
  259. and ancestor::sect2[preceding-sibling::sect2]
  260. and ancestor::sect1[preceding-sibling::sect1]][1]
  261. |following::section[$chunk.section.depth &gt; count(ancestor::section)
  262. and not(ancestor::*/processing-instruction('dbhtml')[normalize-space(.) ='stop-chunking'])
  263. and preceding-sibling::section
  264. and not(ancestor::section[not(preceding-sibling::section)])][1])[1]"/>
  265. <xsl:variable name="next-v2"
  266. select="(descendant::sect1[$chunk.section.depth &gt; 0
  267. and not(ancestor::*/processing-instruction('dbhtml')[normalize-space(.) ='stop-chunking'])
  268. and preceding-sibling::sect1][1]
  269. |descendant::sect2[$chunk.section.depth &gt; 1
  270. and not(ancestor::*/processing-instruction('dbhtml')[normalize-space(.) ='stop-chunking'])
  271. and preceding-sibling::sect2
  272. and parent::sect1[preceding-sibling::sect1]][1]
  273. |descendant::sect3[$chunk.section.depth &gt; 2
  274. and not(ancestor::*/processing-instruction('dbhtml')[normalize-space(.) ='stop-chunking'])
  275. and preceding-sibling::sect3
  276. and parent::sect2[preceding-sibling::sect2]
  277. and ancestor::sect1[preceding-sibling::sect1]][1]
  278. |descendant::sect4[$chunk.section.depth &gt; 3
  279. and not(ancestor::*/processing-instruction('dbhtml')[normalize-space(.) ='stop-chunking'])
  280. and preceding-sibling::sect4
  281. and parent::sect3[preceding-sibling::sect3]
  282. and ancestor::sect2[preceding-sibling::sect2]
  283. and ancestor::sect1[preceding-sibling::sect1]][1]
  284. |descendant::sect5[$chunk.section.depth &gt; 4
  285. and not(ancestor::*/processing-instruction('dbhtml')[normalize-space(.) ='stop-chunking'])
  286. and preceding-sibling::sect5
  287. and parent::sect4[preceding-sibling::sect4]
  288. and ancestor::sect3[preceding-sibling::sect3]
  289. and ancestor::sect2[preceding-sibling::sect2]
  290. and ancestor::sect1[preceding-sibling::sect1]][1]
  291. |descendant::section[$chunk.section.depth &gt; count(ancestor::section)
  292. and not(ancestor::*/processing-instruction('dbhtml')[normalize-space(.) ='stop-chunking'])
  293. and preceding-sibling::section
  294. and not(ancestor::section[not(preceding-sibling::section)])])[1]"/>
  295. <xsl:variable name="next"
  296. select="(following::book[1]
  297. |following::preface[1]
  298. |following::chapter[1]
  299. |following::appendix[1]
  300. |following::part[1]
  301. |following::reference[1]
  302. |following::refentry[1]
  303. |following::colophon[1]
  304. |following::bibliography[parent::article or parent::book or parent::part][1]
  305. |following::glossary[parent::article or parent::book or parent::part][1]
  306. |following::index[$generate.index != 0]
  307. [parent::article or parent::book or parent::part][1]
  308. |following::article[1]
  309. |following::topic[1]
  310. |following::setindex[$generate.index != 0][1]
  311. |descendant::book[1]
  312. |descendant::preface[1]
  313. |descendant::chapter[1]
  314. |descendant::appendix[1]
  315. |descendant::article[1]
  316. |descendant::topic[1]
  317. |descendant::bibliography[parent::article or parent::book or parent::part][1]
  318. |descendant::glossary[parent::article or parent::book or parent::part][1]
  319. |descendant::index[$generate.index != 0]
  320. [parent::article or parent::book or parent::part][1]
  321. |descendant::colophon[1]
  322. |descendant::setindex[$generate.index != 0][1]
  323. |descendant::part[1]
  324. |descendant::reference[1]
  325. |descendant::refentry[1]
  326. |$next-v1
  327. |$next-v2)[1]"/>
  328. <xsl:call-template name="process-chunk">
  329. <xsl:with-param name="prev" select="$prev"/>
  330. <xsl:with-param name="next" select="$next"/>
  331. <xsl:with-param name="content" select="$content"/>
  332. </xsl:call-template>
  333. </xsl:template>
  334. <xsl:template name="chunk-all-sections">
  335. <xsl:param name="content">
  336. <xsl:apply-imports/>
  337. </xsl:param>
  338. <xsl:variable name="prev-v1"
  339. select="(preceding::sect1[$chunk.section.depth &gt; 0 and not(ancestor::*/processing-instruction('dbhtml')[normalize-space(.) ='stop-chunking'])][1]
  340. |preceding::sect2[$chunk.section.depth &gt; 1 and not(ancestor::*/processing-instruction('dbhtml')[normalize-space(.) ='stop-chunking'])][1]
  341. |preceding::sect3[$chunk.section.depth &gt; 2 and not(ancestor::*/processing-instruction('dbhtml')[normalize-space(.) ='stop-chunking'])][1]
  342. |preceding::sect4[$chunk.section.depth &gt; 3 and not(ancestor::*/processing-instruction('dbhtml')[normalize-space(.) ='stop-chunking'])][1]
  343. |preceding::sect5[$chunk.section.depth &gt; 4 and not(ancestor::*/processing-instruction('dbhtml')[normalize-space(.) ='stop-chunking'])][1]
  344. |preceding::section[$chunk.section.depth &gt; count(ancestor::section) and not(ancestor::*/processing-instruction('dbhtml')[normalize-space(.) ='stop-chunking'])][1])[last()]"/>
  345. <xsl:variable name="prev-v2"
  346. select="(ancestor::sect1[$chunk.section.depth &gt; 0 and not(ancestor::*/processing-instruction('dbhtml')[normalize-space(.) ='stop-chunking'])][1]
  347. |ancestor::sect2[$chunk.section.depth &gt; 1 and not(ancestor::*/processing-instruction('dbhtml')[normalize-space(.) ='stop-chunking'])][1]
  348. |ancestor::sect3[$chunk.section.depth &gt; 2 and not(ancestor::*/processing-instruction('dbhtml')[normalize-space(.) ='stop-chunking'])][1]
  349. |ancestor::sect4[$chunk.section.depth &gt; 3 and not(ancestor::*/processing-instruction('dbhtml')[normalize-space(.) ='stop-chunking'])][1]
  350. |ancestor::sect5[$chunk.section.depth &gt; 4 and not(ancestor::*/processing-instruction('dbhtml')[normalize-space(.) ='stop-chunking'])][1]
  351. |ancestor::section[$chunk.section.depth &gt; count(ancestor::section) and not(ancestor::*/processing-instruction('dbhtml')[normalize-space(.) ='stop-chunking'])][1])[last()]"/>
  352. <xsl:variable name="prev"
  353. select="(preceding::book[1]
  354. |preceding::preface[1]
  355. |preceding::chapter[1]
  356. |preceding::appendix[1]
  357. |preceding::part[1]
  358. |preceding::reference[1]
  359. |preceding::refentry[1]
  360. |preceding::colophon[1]
  361. |preceding::article[1]
  362. |preceding::topic[1]
  363. |preceding::bibliography[parent::article or parent::book or parent::part][1]
  364. |preceding::glossary[parent::article or parent::book or parent::part][1]
  365. |preceding::index[$generate.index != 0]
  366. [parent::article or parent::book or parent::part][1]
  367. |preceding::setindex[$generate.index != 0][1]
  368. |ancestor::set
  369. |ancestor::book[1]
  370. |ancestor::preface[1]
  371. |ancestor::chapter[1]
  372. |ancestor::appendix[1]
  373. |ancestor::part[1]
  374. |ancestor::reference[1]
  375. |ancestor::article[1]
  376. |ancestor::topic[1]
  377. |$prev-v1
  378. |$prev-v2)[last()]"/>
  379. <xsl:variable name="next-v1"
  380. select="(following::sect1[$chunk.section.depth &gt; 0 and not(ancestor::*/processing-instruction('dbhtml')[normalize-space(.) ='stop-chunking'])][1]
  381. |following::sect2[$chunk.section.depth &gt; 1 and not(ancestor::*/processing-instruction('dbhtml')[normalize-space(.) ='stop-chunking'])][1]
  382. |following::sect3[$chunk.section.depth &gt; 2 and not(ancestor::*/processing-instruction('dbhtml')[normalize-space(.) ='stop-chunking'])][1]
  383. |following::sect4[$chunk.section.depth &gt; 3 and not(ancestor::*/processing-instruction('dbhtml')[normalize-space(.) ='stop-chunking'])][1]
  384. |following::sect5[$chunk.section.depth &gt; 4 and not(ancestor::*/processing-instruction('dbhtml')[normalize-space(.) ='stop-chunking'])][1]
  385. |following::section[$chunk.section.depth &gt; count(ancestor::section) and not(ancestor::*/processing-instruction('dbhtml')[normalize-space(.) ='stop-chunking'])][1])[1]"/>
  386. <xsl:variable name="next-v2"
  387. select="(descendant::sect1[$chunk.section.depth &gt; 0 and not(ancestor::*/processing-instruction('dbhtml')[normalize-space(.) ='stop-chunking'])][1]
  388. |descendant::sect2[$chunk.section.depth &gt; 1 and not(ancestor::*/processing-instruction('dbhtml')[normalize-space(.) ='stop-chunking'])][1]
  389. |descendant::sect3[$chunk.section.depth &gt; 2 and not(ancestor::*/processing-instruction('dbhtml')[normalize-space(.) ='stop-chunking'])][1]
  390. |descendant::sect4[$chunk.section.depth &gt; 3 and not(ancestor::*/processing-instruction('dbhtml')[normalize-space(.) ='stop-chunking'])][1]
  391. |descendant::sect5[$chunk.section.depth &gt; 4 and not(ancestor::*/processing-instruction('dbhtml')[normalize-space(.) ='stop-chunking'])][1]
  392. |descendant::section[$chunk.section.depth
  393. &gt; count(ancestor::section) and not(ancestor::*/processing-instruction('dbhtml')[normalize-space(.) ='stop-chunking'])][1])[1]"/>
  394. <xsl:variable name="next"
  395. select="(following::book[1]
  396. |following::preface[1]
  397. |following::chapter[1]
  398. |following::appendix[1]
  399. |following::part[1]
  400. |following::reference[1]
  401. |following::refentry[1]
  402. |following::colophon[1]
  403. |following::bibliography[parent::article or parent::book or parent::part][1]
  404. |following::glossary[parent::article or parent::book or parent::part][1]
  405. |following::index[$generate.index != 0]
  406. [parent::article or parent::book][1]
  407. |following::article[1]
  408. |following::topic[1]
  409. |following::setindex[$generate.index != 0][1]
  410. |descendant::book[1]
  411. |descendant::preface[1]
  412. |descendant::chapter[1]
  413. |descendant::appendix[1]
  414. |descendant::article[1]
  415. |descendant::topic[1]
  416. |descendant::bibliography[parent::article or parent::book][1]
  417. |descendant::glossary[parent::article or parent::book or parent::part][1]
  418. |descendant::index[$generate.index != 0]
  419. [parent::article or parent::book][1]
  420. |descendant::colophon[1]
  421. |descendant::setindex[$generate.index != 0][1]
  422. |descendant::part[1]
  423. |descendant::reference[1]
  424. |descendant::refentry[1]
  425. |$next-v1
  426. |$next-v2)[1]"/>
  427. <xsl:call-template name="process-chunk">
  428. <xsl:with-param name="prev" select="$prev"/>
  429. <xsl:with-param name="next" select="$next"/>
  430. <xsl:with-param name="content" select="$content"/>
  431. </xsl:call-template>
  432. </xsl:template>
  433. <!-- ==================================================================== -->
  434. <!-- ==================================================================== -->
  435. <xsl:template name="make.lots">
  436. <xsl:param name="toc.params" select="''"/>
  437. <xsl:param name="toc"/>
  438. <xsl:variable name="lots">
  439. <xsl:if test="contains($toc.params, 'toc')">
  440. <xsl:copy-of select="$toc"/>
  441. </xsl:if>
  442. <xsl:if test="contains($toc.params, 'figure')">
  443. <xsl:choose>
  444. <xsl:when test="$chunk.separate.lots != '0'">
  445. <xsl:call-template name="make.lot.chunk">
  446. <xsl:with-param name="type" select="'figure'"/>
  447. <xsl:with-param name="lot">
  448. <xsl:call-template name="list.of.titles">
  449. <xsl:with-param name="titles" select="'figure'"/>
  450. <xsl:with-param name="nodes" select=".//figure"/>
  451. </xsl:call-template>
  452. </xsl:with-param>
  453. </xsl:call-template>
  454. </xsl:when>
  455. <xsl:otherwise>
  456. <xsl:call-template name="list.of.titles">
  457. <xsl:with-param name="titles" select="'figure'"/>
  458. <xsl:with-param name="nodes" select=".//figure"/>
  459. </xsl:call-template>
  460. </xsl:otherwise>
  461. </xsl:choose>
  462. </xsl:if>
  463. <xsl:if test="contains($toc.params, 'table')">
  464. <xsl:choose>
  465. <xsl:when test="$chunk.separate.lots != '0'">
  466. <xsl:call-template name="make.lot.chunk">
  467. <xsl:with-param name="type" select="'table'"/>
  468. <xsl:with-param name="lot">
  469. <xsl:call-template name="list.of.titles">
  470. <xsl:with-param name="titles" select="'table'"/>
  471. <xsl:with-param name="nodes" select=".//table[not(@tocentry = 0)]"/>
  472. </xsl:call-template>
  473. </xsl:with-param>
  474. </xsl:call-template>
  475. </xsl:when>
  476. <xsl:otherwise>
  477. <xsl:call-template name="list.of.titles">
  478. <xsl:with-param name="titles" select="'table'"/>
  479. <xsl:with-param name="nodes" select=".//table[not(@tocentry = 0)]"/>
  480. </xsl:call-template>
  481. </xsl:otherwise>
  482. </xsl:choose>
  483. </xsl:if>
  484. <xsl:if test="contains($toc.params, 'example')">
  485. <xsl:choose>
  486. <xsl:when test="$chunk.separate.lots != '0'">
  487. <xsl:call-template name="make.lot.chunk">
  488. <xsl:with-param name="type" select="'example'"/>
  489. <xsl:with-param name="lot">
  490. <xsl:call-template name="list.of.titles">
  491. <xsl:with-param name="titles" select="'example'"/>
  492. <xsl:with-param name="nodes" select=".//example"/>
  493. </xsl:call-template>
  494. </xsl:with-param>
  495. </xsl:call-template>
  496. </xsl:when>
  497. <xsl:otherwise>
  498. <xsl:call-template name="list.of.titles">
  499. <xsl:with-param name="titles" select="'example'"/>
  500. <xsl:with-param name="nodes" select=".//example"/>
  501. </xsl:call-template>
  502. </xsl:otherwise>
  503. </xsl:choose>
  504. </xsl:if>
  505. <xsl:if test="contains($toc.params, 'equation')">
  506. <xsl:choose>
  507. <xsl:when test="$chunk.separate.lots != '0'">
  508. <xsl:call-template name="make.lot.chunk">
  509. <xsl:with-param name="type" select="'equation'"/>
  510. <xsl:with-param name="lot">
  511. <xsl:call-template name="list.of.titles">
  512. <xsl:with-param name="titles" select="'equation'"/>
  513. <xsl:with-param name="nodes" select=".//equation[title or info/title]"/>
  514. </xsl:call-template>
  515. </xsl:with-param>
  516. </xsl:call-template>
  517. </xsl:when>
  518. <xsl:otherwise>
  519. <xsl:call-template name="list.of.titles">
  520. <xsl:with-param name="titles" select="'equation'"/>
  521. <xsl:with-param name="nodes" select=".//equation[title or info/title]"/>
  522. </xsl:call-template>
  523. </xsl:otherwise>
  524. </xsl:choose>
  525. </xsl:if>
  526. <xsl:if test="contains($toc.params, 'procedure')">
  527. <xsl:choose>
  528. <xsl:when test="$chunk.separate.lots != '0'">
  529. <xsl:call-template name="make.lot.chunk">
  530. <xsl:with-param name="type" select="'procedure'"/>
  531. <xsl:with-param name="lot">
  532. <xsl:call-template name="list.of.titles">
  533. <xsl:with-param name="titles" select="'procedure'"/>
  534. <xsl:with-param name="nodes" select=".//procedure[title]"/>
  535. </xsl:call-template>
  536. </xsl:with-param>
  537. </xsl:call-template>
  538. </xsl:when>
  539. <xsl:otherwise>
  540. <xsl:call-template name="list.of.titles">
  541. <xsl:with-param name="titles" select="'procedure'"/>
  542. <xsl:with-param name="nodes" select=".//procedure[title]"/>
  543. </xsl:call-template>
  544. </xsl:otherwise>
  545. </xsl:choose>
  546. </xsl:if>
  547. </xsl:variable>
  548. <xsl:if test="string($lots) != ''">
  549. <xsl:choose>
  550. <xsl:when test="$chunk.tocs.and.lots != 0 and not(parent::*)">
  551. <xsl:call-template name="write.chunk">
  552. <xsl:with-param name="filename">
  553. <xsl:call-template name="make-relative-filename">
  554. <xsl:with-param name="base.dir" select="$chunk.base.dir"/>
  555. <xsl:with-param name="base.name">
  556. <xsl:call-template name="dbhtml-dir"/>
  557. <xsl:value-of select="$chunked.filename.prefix"/>
  558. <xsl:apply-templates select="." mode="recursive-chunk-filename">
  559. <xsl:with-param name="recursive" select="true()"/>
  560. </xsl:apply-templates>
  561. <xsl:text>-toc</xsl:text>
  562. <xsl:value-of select="$html.ext"/>
  563. </xsl:with-param>
  564. </xsl:call-template>
  565. </xsl:with-param>
  566. <xsl:with-param name="content">
  567. <xsl:call-template name="chunk-element-content">
  568. <xsl:with-param name="prev" select="/foo"/>
  569. <xsl:with-param name="next" select="/foo"/>
  570. <xsl:with-param name="nav.context" select="'toc'"/>
  571. <xsl:with-param name="content">
  572. <xsl:if test="$chunk.tocs.and.lots.has.title != 0">
  573. <h1>
  574. <xsl:apply-templates select="." mode="object.title.markup"/>
  575. </h1>
  576. </xsl:if>
  577. <xsl:copy-of select="$lots"/>
  578. </xsl:with-param>
  579. </xsl:call-template>
  580. </xsl:with-param>
  581. <xsl:with-param name="quiet" select="$chunk.quietly"/>
  582. </xsl:call-template>
  583. </xsl:when>
  584. <xsl:otherwise>
  585. <xsl:copy-of select="$lots"/>
  586. </xsl:otherwise>
  587. </xsl:choose>
  588. </xsl:if>
  589. </xsl:template>
  590. <xsl:template name="make.lot.chunk">
  591. <xsl:param name="type" select="''"/>
  592. <xsl:param name="lot"/>
  593. <xsl:if test="string($lot) != ''">
  594. <xsl:variable name="filename">
  595. <xsl:call-template name="make-relative-filename">
  596. <xsl:with-param name="base.dir" select="$chunk.base.dir"/>
  597. <xsl:with-param name="base.name">
  598. <xsl:call-template name="dbhtml-dir"/>
  599. <xsl:value-of select="$type"/>
  600. <xsl:text>-toc</xsl:text>
  601. <xsl:value-of select="$html.ext"/>
  602. </xsl:with-param>
  603. </xsl:call-template>
  604. </xsl:variable>
  605. <xsl:variable name="href">
  606. <xsl:call-template name="make-relative-filename">
  607. <xsl:with-param name="base.dir" select="''"/>
  608. <xsl:with-param name="base.name">
  609. <xsl:call-template name="dbhtml-dir"/>
  610. <xsl:value-of select="$type"/>
  611. <xsl:text>-toc</xsl:text>
  612. <xsl:value-of select="$html.ext"/>
  613. </xsl:with-param>
  614. </xsl:call-template>
  615. </xsl:variable>
  616. <xsl:call-template name="write.chunk">
  617. <xsl:with-param name="filename" select="$filename"/>
  618. <xsl:with-param name="content">
  619. <xsl:call-template name="chunk-element-content">
  620. <xsl:with-param name="prev" select="/foo"/>
  621. <xsl:with-param name="next" select="/foo"/>
  622. <xsl:with-param name="nav.context" select="'toc'"/>
  623. <xsl:with-param name="content">
  624. <xsl:copy-of select="$lot"/>
  625. </xsl:with-param>
  626. </xsl:call-template>
  627. </xsl:with-param>
  628. <xsl:with-param name="quiet" select="$chunk.quietly"/>
  629. </xsl:call-template>
  630. <!-- And output a link to this file -->
  631. <div>
  632. <xsl:attribute name="class">
  633. <xsl:text>ListofTitles</xsl:text>
  634. </xsl:attribute>
  635. <a href="{$href}">
  636. <xsl:call-template name="gentext">
  637. <xsl:with-param name="key">
  638. <xsl:choose>
  639. <xsl:when test="$type='table'">ListofTables</xsl:when>
  640. <xsl:when test="$type='figure'">ListofFigures</xsl:when>
  641. <xsl:when test="$type='equation'">ListofEquations</xsl:when>
  642. <xsl:when test="$type='example'">ListofExamples</xsl:when>
  643. <xsl:when test="$type='procedure'">ListofProcedures</xsl:when>
  644. <xsl:otherwise>ListofUnknown</xsl:otherwise>
  645. </xsl:choose>
  646. </xsl:with-param>
  647. </xsl:call-template>
  648. </a>
  649. </div>
  650. </xsl:if>
  651. </xsl:template>
  652. <!-- ==================================================================== -->
  653. <xsl:template name="in.other.chunk">
  654. <xsl:param name="chunk" select="."/>
  655. <xsl:param name="node" select="."/>
  656. <xsl:variable name="is.chunk">
  657. <xsl:call-template name="chunk">
  658. <xsl:with-param name="node" select="$node"/>
  659. </xsl:call-template>
  660. </xsl:variable>
  661. <!--
  662. <xsl:message>
  663. <xsl:text>in.other.chunk: </xsl:text>
  664. <xsl:value-of select="name($chunk)"/>
  665. <xsl:text> </xsl:text>
  666. <xsl:value-of select="name($node)"/>
  667. <xsl:text> </xsl:text>
  668. <xsl:value-of select="$chunk = $node"/>
  669. <xsl:text> </xsl:text>
  670. <xsl:value-of select="$is.chunk"/>
  671. </xsl:message>
  672. -->
  673. <xsl:choose>
  674. <xsl:when test="$chunk = $node">0</xsl:when>
  675. <xsl:when test="$is.chunk = 1">1</xsl:when>
  676. <xsl:when test="count($node) = 0">0</xsl:when>
  677. <xsl:otherwise>
  678. <xsl:call-template name="in.other.chunk">
  679. <xsl:with-param name="chunk" select="$chunk"/>
  680. <xsl:with-param name="node" select="$node/parent::*"/>
  681. </xsl:call-template>
  682. </xsl:otherwise>
  683. </xsl:choose>
  684. </xsl:template>
  685. <xsl:template name="count.footnotes.in.this.chunk">
  686. <xsl:param name="node" select="."/>
  687. <xsl:param name="footnotes" select="$node//footnote"/>
  688. <xsl:param name="count" select="0"/>
  689. <!--
  690. <xsl:message>
  691. <xsl:text>count.footnotes.in.this.chunk: </xsl:text>
  692. <xsl:value-of select="name($node)"/>
  693. </xsl:message>
  694. -->
  695. <xsl:variable name="in.other.chunk">
  696. <xsl:call-template name="in.other.chunk">
  697. <xsl:with-param name="chunk" select="$node"/>
  698. <xsl:with-param name="node" select="$footnotes[1]"/>
  699. </xsl:call-template>
  700. </xsl:variable>
  701. <xsl:choose>
  702. <xsl:when test="count($footnotes) = 0">
  703. <xsl:value-of select="$count"/>
  704. </xsl:when>
  705. <xsl:otherwise>
  706. <xsl:choose>
  707. <xsl:when test="$in.other.chunk != 0">
  708. <xsl:call-template name="count.footnotes.in.this.chunk">
  709. <xsl:with-param name="node" select="$node"/>
  710. <xsl:with-param name="footnotes"
  711. select="$footnotes[position() &gt; 1]"/>
  712. <xsl:with-param name="count" select="$count"/>
  713. </xsl:call-template>
  714. </xsl:when>
  715. <xsl:when test="$footnotes[1]/ancestor::table
  716. |$footnotes[1]/ancestor::informaltable">
  717. <xsl:call-template name="count.footnotes.in.this.chunk">
  718. <xsl:with-param name="node" select="$node"/>
  719. <xsl:with-param name="footnotes"
  720. select="$footnotes[position() &gt; 1]"/>
  721. <xsl:with-param name="count" select="$count"/>
  722. </xsl:call-template>
  723. </xsl:when>
  724. <xsl:otherwise>
  725. <xsl:call-template name="count.footnotes.in.this.chunk">
  726. <xsl:with-param name="node" select="$node"/>
  727. <xsl:with-param name="footnotes"
  728. select="$footnotes[position() &gt; 1]"/>
  729. <xsl:with-param name="count" select="$count + 1"/>
  730. </xsl:call-template>
  731. </xsl:otherwise>
  732. </xsl:choose>
  733. </xsl:otherwise>
  734. </xsl:choose>
  735. </xsl:template>
  736. <xsl:template name="process.footnotes.in.this.chunk">
  737. <xsl:param name="node" select="."/>
  738. <xsl:param name="footnotes" select="$node//footnote"/>
  739. <!--
  740. <xsl:message>process.footnotes.in.this.chunk</xsl:message>
  741. -->
  742. <xsl:variable name="in.other.chunk">
  743. <xsl:call-template name="in.other.chunk">
  744. <xsl:with-param name="chunk" select="$node"/>
  745. <xsl:with-param name="node" select="$footnotes[1]"/>
  746. </xsl:call-template>
  747. </xsl:variable>
  748. <xsl:choose>
  749. <xsl:when test="count($footnotes) = 0">
  750. <!-- nop -->
  751. </xsl:when>
  752. <xsl:otherwise>
  753. <xsl:choose>
  754. <xsl:when test="$in.other.chunk != 0">
  755. <xsl:call-template name="process.footnotes.in.this.chunk">
  756. <xsl:with-param name="node" select="$node"/>
  757. <xsl:with-param name="footnotes"
  758. select="$footnotes[position() &gt; 1]"/>
  759. </xsl:call-template>
  760. </xsl:when>
  761. <xsl:when test="$footnotes[1]/ancestor::table
  762. |$footnotes[1]/ancestor::informaltable">
  763. <xsl:call-template name="process.footnotes.in.this.chunk">
  764. <xsl:with-param name="node" select="$node"/>
  765. <xsl:with-param name="footnotes"
  766. select="$footnotes[position() &gt; 1]"/>
  767. </xsl:call-template>
  768. </xsl:when>
  769. <xsl:otherwise>
  770. <xsl:apply-templates select="$footnotes[1]"
  771. mode="process.footnote.mode"/>
  772. <xsl:call-template name="process.footnotes.in.this.chunk">
  773. <xsl:with-param name="node" select="$node"/>
  774. <xsl:with-param name="footnotes"
  775. select="$footnotes[position() &gt; 1]"/>
  776. </xsl:call-template>
  777. </xsl:otherwise>
  778. </xsl:choose>
  779. </xsl:otherwise>
  780. </xsl:choose>
  781. </xsl:template>
  782. <xsl:template name="process.footnotes">
  783. <xsl:variable name="footnotes" select=".//footnote"/>
  784. <xsl:variable name="fcount">
  785. <xsl:call-template name="count.footnotes.in.this.chunk">
  786. <xsl:with-param name="node" select="."/>
  787. <xsl:with-param name="footnotes" select="$footnotes"/>
  788. </xsl:call-template>
  789. </xsl:variable>
  790. <!--
  791. <xsl:message>
  792. <xsl:value-of select="name(.)"/>
  793. <xsl:text> fcount: </xsl:text>
  794. <xsl:value-of select="$fcount"/>
  795. </xsl:message>
  796. -->
  797. <!-- Only bother to do this if there's at least one non-table footnote -->
  798. <xsl:if test="$fcount &gt; 0">
  799. <div class="footnotes">
  800. <xsl:call-template name="footnotes.attributes"/>
  801. <br/>
  802. <hr>
  803. <xsl:choose>
  804. <xsl:when test="$make.clean.html != 0">
  805. <xsl:attribute name="class">footnote-hr</xsl:attribute>
  806. </xsl:when>
  807. <xsl:when test="$css.decoration != 0">
  808. <xsl:attribute name="style">
  809. <xsl:value-of select="concat('width:100; text-align:',
  810. $direction.align.start,
  811. ';',
  812. 'margin-', $direction.align.start, ': 0')"/>
  813. </xsl:attribute>
  814. </xsl:when>
  815. <xsl:otherwise>
  816. <xsl:attribute name="width">100</xsl:attribute>
  817. <xsl:attribute name="align"><xsl:value-of
  818. select="$direction.align.start"/></xsl:attribute>
  819. </xsl:otherwise>
  820. </xsl:choose>
  821. </hr>
  822. <xsl:call-template name="process.footnotes.in.this.chunk">
  823. <xsl:with-param name="node" select="."/>
  824. <xsl:with-param name="footnotes" select="$footnotes"/>
  825. </xsl:call-template>
  826. </div>
  827. </xsl:if>
  828. <!-- FIXME: When chunking, only the annotations actually used
  829. in this chunk should be referenced. I don't think it
  830. does any harm to reference them all, but it adds
  831. unnecessary bloat to each chunk. -->
  832. <xsl:if test="$annotation.support != 0 and //annotation">
  833. <div class="annotation-list">
  834. <div class="annotation-nocss">
  835. <p>The following annotations are from this essay. You are seeing
  836. them here because your browser doesn’t support the user-interface
  837. techniques used to make them appear as ‘popups’ on modern browsers.</p>
  838. </div>
  839. <xsl:apply-templates select="//annotation"
  840. mode="annotation-popup"/>
  841. </div>
  842. </xsl:if>
  843. </xsl:template>
  844. <xsl:template name="process.chunk.footnotes">
  845. <xsl:variable name="is.chunk">
  846. <xsl:call-template name="chunk"/>
  847. </xsl:variable>
  848. <xsl:if test="$is.chunk = 1">
  849. <xsl:call-template name="process.footnotes"/>
  850. </xsl:if>
  851. </xsl:template>
  852. <!-- ====================================================================== -->
  853. <xsl:template name="chunk">
  854. <xsl:param name="node" select="."/>
  855. <!-- returns 1 if $node is a chunk -->
  856. <!-- ==================================================================== -->
  857. <!-- What's a chunk?
  858. The root element
  859. appendix
  860. article
  861. bibliography in article or part or book
  862. book
  863. chapter
  864. colophon
  865. glossary in article or part or book
  866. index in article or part or book
  867. part
  868. preface
  869. refentry
  870. reference
  871. sect{1,2,3,4,5} if position()>1 && depth < chunk.section.depth
  872. section if position()>1 && depth < chunk.section.depth
  873. set
  874. setindex
  875. topic
  876. -->
  877. <!-- ==================================================================== -->
  878. <!--
  879. <xsl:message>
  880. <xsl:text>chunk: </xsl:text>
  881. <xsl:value-of select="name($node)"/>
  882. <xsl:text>(</xsl:text>
  883. <xsl:value-of select="$node/@id"/>
  884. <xsl:text>)</xsl:text>
  885. <xsl:text> csd: </xsl:text>
  886. <xsl:value-of select="$chunk.section.depth"/>
  887. <xsl:text> cfs: </xsl:text>
  888. <xsl:value-of select="$chunk.first.sections"/>
  889. <xsl:text> ps: </xsl:text>
  890. <xsl:value-of select="count($node/parent::section)"/>
  891. <xsl:text> prs: </xsl:text>
  892. <xsl:value-of select="count($node/preceding-sibling::section)"/>
  893. </xsl:message>
  894. -->
  895. <xsl:choose>
  896. <xsl:when test="$node/parent::*/processing-instruction('dbhtml')[normalize-space(.) = 'stop-chunking']">0</xsl:when>
  897. <xsl:when test="not($node/parent::*)">1</xsl:when>
  898. <xsl:when test="local-name($node) = 'sect1'
  899. and $chunk.section.depth &gt;= 1
  900. and ($chunk.first.sections != 0
  901. or count($node/preceding-sibling::sect1) &gt; 0)">
  902. <xsl:text>1</xsl:text>
  903. </xsl:when>
  904. <xsl:when test="local-name($node) = 'sect2'
  905. and $chunk.section.depth &gt;= 2
  906. and ($chunk.first.sections != 0
  907. or count($node/preceding-sibling::sect2) &gt; 0)">
  908. <xsl:call-template name="chunk">
  909. <xsl:with-param name="node" select="$node/parent::*"/>
  910. </xsl:call-template>
  911. </xsl:when>
  912. <xsl:when test="local-name($node) = 'sect3'
  913. and $chunk.section.depth &gt;= 3
  914. and ($chunk.first.sections != 0
  915. or count($node/preceding-sibling::sect3) &gt; 0)">
  916. <xsl:call-template name="chunk">
  917. <xsl:with-param name="node" select="$node/parent::*"/>
  918. </xsl:call-template>
  919. </xsl:when>
  920. <xsl:when test="local-name($node) = 'sect4'
  921. and $chunk.section.depth &gt;= 4
  922. and ($chunk.first.sections != 0
  923. or count($node/preceding-sibling::sect4) &gt; 0)">
  924. <xsl:call-template name="chunk">
  925. <xsl:with-param name="node" select="$node/parent::*"/>
  926. </xsl:call-template>
  927. </xsl:when>
  928. <xsl:when test="local-name($node) = 'sect5'
  929. and $chunk.section.depth &gt;= 5
  930. and ($chunk.first.sections != 0
  931. or count($node/preceding-sibling::sect5) &gt; 0)">
  932. <xsl:call-template name="chunk">
  933. <xsl:with-param name="node" select="$node/parent::*"/>
  934. </xsl:call-template>
  935. </xsl:when>
  936. <xsl:when test="local-name($node) = 'section'
  937. and $chunk.section.depth &gt;= count($node/ancestor::section)+1
  938. and ($chunk.first.sections != 0
  939. or count($node/preceding-sibling::section) &gt; 0)">
  940. <xsl:call-template name="chunk">
  941. <xsl:with-param name="node" select="$node/parent::*"/>
  942. </xsl:call-template>
  943. </xsl:when>
  944. <xsl:when test="local-name($node)='preface'">1</xsl:when>
  945. <xsl:when test="local-name($node)='chapter'">1</xsl:when>
  946. <xsl:when test="local-name($node)='appendix'">1</xsl:when>
  947. <xsl:when test="local-name($node)='article'">1</xsl:when>
  948. <xsl:when test="local-name($node)='topic'">1</xsl:when>
  949. <xsl:when test="local-name($node)='part'">1</xsl:when>
  950. <xsl:when test="local-name($node)='reference'">1</xsl:when>
  951. <xsl:when test="local-name($node)='refentry'">1</xsl:when>
  952. <xsl:when test="local-name($node)='index' and ($generate.index != 0 or count($node/*) > 0)
  953. and (local-name($node/parent::*) = 'article'
  954. or local-name($node/parent::*) = 'book'
  955. or local-name($node/parent::*) = 'part'
  956. )">1</xsl:when>
  957. <xsl:when test="local-name($node)='bibliography'
  958. and (local-name($node/parent::*) = 'article'
  959. or local-name($node/parent::*) = 'book'
  960. or local-name($node/parent::*) = 'part'
  961. )">1</xsl:when>
  962. <xsl:when test="local-name($node)='glossary'
  963. and (local-name($node/parent::*) = 'article'
  964. or local-name($node/parent::*) = 'book'
  965. or local-name($node/parent::*) = 'part'
  966. )">1</xsl:when>
  967. <xsl:when test="local-name($node)='colophon'">1</xsl:when>
  968. <xsl:when test="local-name($node)='book'">1</xsl:when>
  969. <xsl:when test="local-name($node)='set'">1</xsl:when>
  970. <xsl:when test="local-name($node)='setindex'">1</xsl:when>
  971. <xsl:when test="local-name($node)='legalnotice'
  972. and $generate.legalnotice.link != 0">1</xsl:when>
  973. <xsl:otherwise>0</xsl:otherwise>
  974. </xsl:choose>
  975. </xsl:template>
  976. <!-- ==================================================================== -->
  977. <xsl:template name="href.target.uri">
  978. <xsl:param name="object" select="."/>
  979. <xsl:variable name="ischunk">
  980. <xsl:call-template name="chunk">
  981. <xsl:with-param name="node" select="$object"/>
  982. </xsl:call-template>
  983. </xsl:variable>
  984. <xsl:apply-templates mode="chunk-filename" select="$object"/>
  985. <xsl:if test="$ischunk='0'">
  986. <xsl:text>#</xsl:text>
  987. <xsl:call-template name="object.id">
  988. <xsl:with-param name="object" select="$object"/>
  989. </xsl:call-template>
  990. </xsl:if>
  991. </xsl:template>
  992. <xsl:template name="href.target">
  993. <xsl:param name="context" select="."/>
  994. <xsl:param name="object" select="."/>
  995. <xsl:param name="toc-context" select="."/>
  996. <!-- * If $toc-context contains some node other than the current node, -->
  997. <!-- * it means we're processing a link in a TOC. In that case, to -->
  998. <!-- * ensure the link will work correctly, we need to take a look at -->
  999. <!-- * where the file containing the TOC will get written, and where -->
  1000. <!-- * the file that's being linked to will get written. -->
  1001. <xsl:variable name="toc-output-dir">
  1002. <xsl:if test="not($toc-context = .)">
  1003. <!-- * Get the $toc-context node and all its ancestors, look down -->
  1004. <!-- * through them to find the last/closest node to the -->
  1005. <!-- * toc-context node that has a "dbhtml dir" PI, and get the -->
  1006. <!-- * directory name from that. That's the name of the directory -->
  1007. <!-- * to which the current toc output file will get written. -->
  1008. <xsl:call-template name="dbhtml-dir">
  1009. <xsl:with-param name="context"
  1010. select="$toc-context/ancestor-or-self::*[processing-instruction('dbhtml')[contains(.,'dir')]][last()]"/>
  1011. </xsl:call-template>
  1012. </xsl:if>
  1013. </xsl:variable>
  1014. <xsl:variable name="linked-file-output-dir">
  1015. <xsl:if test="not($toc-context = .)">
  1016. <!-- * Get the current node and all its ancestors, look down -->
  1017. <!-- * through them to find the last/closest node to the current -->
  1018. <!-- * node that has a "dbhtml dir" PI, and get the directory name -->
  1019. <!-- * from that. That's the name of the directory to which the -->
  1020. <!-- * file that's being linked to will get written. -->
  1021. <xsl:call-template name="dbhtml-dir">
  1022. <xsl:with-param name="context"
  1023. select="ancestor-or-self::*[processing-instruction('dbhtml')[contains(.,'dir')]][last()]"/>
  1024. </xsl:call-template>
  1025. </xsl:if>
  1026. </xsl:variable>
  1027. <xsl:variable name="href.to.uri">
  1028. <xsl:call-template name="href.target.uri">
  1029. <xsl:with-param name="object" select="$object"/>
  1030. </xsl:call-template>
  1031. </xsl:variable>
  1032. <xsl:variable name="href.from.uri">
  1033. <xsl:choose>
  1034. <xsl:when test="not($toc-context = .)">
  1035. <xsl:call-template name="href.target.uri">
  1036. <xsl:with-param name="object" select="$toc-context"/>
  1037. </xsl:call-template>
  1038. </xsl:when>
  1039. <xsl:otherwise>
  1040. <xsl:call-template name="href.target.uri">
  1041. <xsl:with-param name="object" select="$context"/>
  1042. </xsl:call-template>
  1043. </xsl:otherwise>
  1044. </xsl:choose>
  1045. </xsl:variable>
  1046. <!-- * <xsl:message>toc-context: <xsl:value-of select="local-name($toc-context)"/></xsl:message> -->
  1047. <!-- * <xsl:message>node: <xsl:value-of select="local-name(.)"/></xsl:message> -->
  1048. <!-- * <xsl:message>context: <xsl:value-of select="local-name($context)"/></xsl:message> -->
  1049. <!-- * <xsl:message>object: <xsl:value-of select="local-name($object)"/></xsl:message> -->
  1050. <!-- * <xsl:message>toc-output-dir: <xsl:value-of select="$toc-output-dir"/></xsl:message> -->
  1051. <!-- * <xsl:message>linked-file-output-dir: <xsl:value-of select="$linked-file-output-dir"/></xsl:message> -->
  1052. <!-- * <xsl:message>href.to.uri: <xsl:value-of select="$href.to.uri"/></xsl:message> -->
  1053. <!-- * <xsl:message>href.from.uri: <xsl:value-of select="$href.from.uri"/></xsl:message> -->
  1054. <xsl:variable name="href.to">
  1055. <xsl:choose>
  1056. <!-- * 2007-07-19, MikeSmith: Added the following conditional to -->
  1057. <!-- * deal with a problem case for links in TOCs. It checks to see -->
  1058. <!-- * if the output dir that a TOC will get written to is -->
  1059. <!-- * different from the output dir of the file being linked to. -->
  1060. <!-- * If it is different, we do not call trim.common.uri.paths. -->
  1061. <!-- * -->
  1062. <!-- * Reason why I added that conditional is: I ran into a bug for -->
  1063. <!-- * this case: -->
  1064. <!-- * -->
  1065. <!-- * 1. we are chunking into separate dirs -->
  1066. <!-- * -->
  1067. <!-- * 2. output for the TOC is written to current dir, but the file -->
  1068. <!-- * being linked to is written to some subdir "foo". -->
  1069. <!-- * -->
  1070. <!-- * For that case, links to that file in that TOC did not show -->
  1071. <!-- * the correct path - they omitted the "foo". -->
  1072. <!-- * -->
  1073. <!-- * The cause of that problem was that the trim.common.uri.paths -->
  1074. <!-- * template[1] was being called under all conditions. But it's -->
  1075. <!-- * apparent that we don't want to call trim.common.uri.paths in -->
  1076. <!-- * the case where a linked file is being written to a different -->
  1077. <!-- * directory than the TOC that contains the link, because doing -->
  1078. <!-- * so will cause a necessary (not redundant) directory-name -->
  1079. <!-- * part of the link to get inadvertently trimmed, resulting in -->
  1080. <!-- * a broken link to that file. Thus, added the conditional. -->
  1081. <!-- * -->
  1082. <!-- * [1] The purpose of the trim.common.uri.paths template is to -->
  1083. <!-- * prevent cases where, if we didn't call it, we end up with -->
  1084. <!-- * unnecessary, redundant directory names getting output; for -->
  1085. <!-- * example, "foo/foo/refname.html". -->
  1086. <xsl:when test="not($toc-output-dir = $linked-file-output-dir)">
  1087. <xsl:value-of select="$href.to.uri"/>
  1088. </xsl:when>
  1089. <xsl:otherwise>
  1090. <xsl:call-template name="trim.common.uri.paths">
  1091. <xsl:with-param name="uriA" select="$href.to.uri"/>
  1092. <xsl:with-param name="uriB" select="$href.from.uri"/>
  1093. <xsl:with-param name="return" select="'A'"/>
  1094. </xsl:call-template>
  1095. </xsl:otherwise>
  1096. </xsl:choose>
  1097. </xsl:variable>
  1098. <xsl:variable name="href.from">
  1099. <xsl:call-template name="trim.common.uri.paths">
  1100. <xsl:with-param name="uriA" select="$href.to.uri"/>
  1101. <xsl:with-param name="uriB" select="$href.from.uri"/>
  1102. <xsl:with-param name="return" select="'B'"/>
  1103. </xsl:call-template>
  1104. </xsl:variable>
  1105. <xsl:variable name="depth">
  1106. <xsl:call-template name="count.uri.path.depth">
  1107. <xsl:with-param name="filename" select="$href.from"/>
  1108. </xsl:call-template>
  1109. </xsl:variable>
  1110. <xsl:variable name="href">
  1111. <xsl:call-template name="copy-string">
  1112. <xsl:with-param name="string" select="'../'"/>
  1113. <xsl:with-param name="count" select="$depth"/>
  1114. </xsl:call-template>
  1115. <xsl:value-of select="$href.to"/>
  1116. </xsl:variable>
  1117. <!--
  1118. <xsl:message>
  1119. <xsl:text>In </xsl:text>
  1120. <xsl:value-of select="name(.)"/>
  1121. <xsl:text> (</xsl:text>
  1122. <xsl:value-of select="$href.from"/>
  1123. <xsl:text>,</xsl:text>
  1124. <xsl:value-of select="$depth"/>
  1125. <xsl:text>) </xsl:text>
  1126. <xsl:value-of select="name($object)"/>
  1127. <xsl:text> href=</xsl:text>
  1128. <xsl:value-of select="$href"/>
  1129. </xsl:message>
  1130. -->
  1131. <xsl:value-of select="$href"/>
  1132. </xsl:template>
  1133. <!-- Returns the complete olink href value if found -->
  1134. <!-- Must take into account any dbhtml dir of the chunk containing the olink -->
  1135. <xsl:template name="make.olink.href">
  1136. <xsl:param name="olink.key" select="''"/>
  1137. <xsl:param name="target.database"/>
  1138. <xsl:if test="$olink.key != ''">
  1139. <xsl:variable name="target.href" >
  1140. <xsl:for-each select="$target.database" >
  1141. <xsl:value-of select="key('targetptr-key', $olink.key)[1]/@href" />
  1142. </xsl:for-each>
  1143. </xsl:variable>
  1144. <!-- an olink starting point may be in a subdirectory, so need
  1145. the "from" reference point to compute a relative path -->
  1146. <xsl:variable name="from.href">
  1147. <xsl:call-template name="olink.from.uri">
  1148. <xsl:with-param name="target.database" select="$target.database"/>
  1149. <xsl:with-param name="object" select="."/>
  1150. <xsl:with-param name="object.targetdoc" select="$current.docid"/>
  1151. </xsl:call-template>
  1152. </xsl:variable>
  1153. <!-- If the from.href has directory path, then must "../" upward
  1154. to document level -->
  1155. <xsl:variable name="upward.from.path">
  1156. <xsl:call-template name="upward.path">
  1157. <xsl:with-param name="path" select="$from.href"/>
  1158. </xsl:call-template>
  1159. </xsl:variable>
  1160. <xsl:variable name="targetdoc">
  1161. <xsl:value-of select="substring-before($olink.key, '/')"/>
  1162. </xsl:variable>
  1163. <!-- Does the target database use a sitemap? -->
  1164. <xsl:variable name="use.sitemap">
  1165. <xsl:choose>
  1166. <xsl:when test="$target.database//sitemap">1</xsl:when>
  1167. <xsl:otherwise>0</xsl:otherwise>
  1168. </xsl:choose>
  1169. </xsl:variable>
  1170. <!-- Get the baseuri for this targetptr -->
  1171. <xsl:variable name="baseuri" >
  1172. <xsl:choose>
  1173. <!-- Does the database use a sitemap? -->
  1174. <xsl:when test="$use.sitemap != 0" >
  1175. <xsl:choose>
  1176. <!-- Was current.docid parameter set? -->
  1177. <xsl:when test="$current.docid != ''">
  1178. <!-- Was it found in the database? -->
  1179. <xsl:variable name="currentdoc.key" >
  1180. <xsl:for-each select="$target.database" >
  1181. <xsl:value-of select="key('targetdoc-key',
  1182. $current.docid)[1]/@targetdoc" />
  1183. </xsl:for-each>
  1184. </xsl:variable>
  1185. <xsl:choose>
  1186. <xsl:when test="$currentdoc.key != ''">
  1187. <xsl:for-each select="$target.database" >
  1188. <xsl:call-template name="targetpath" >
  1189. <xsl:with-param name="dirnode"
  1190. select="key('targetdoc-key', $current.docid)[1]/parent::dir"/>
  1191. <xsl:with-param name="targetdoc" select="$targetdoc"/>
  1192. </xsl:call-template>
  1193. </xsl:for-each >
  1194. </xsl:when>
  1195. <xsl:otherwise>
  1196. <xsl:message>
  1197. <xsl:text>Olink error: cannot compute relative </xsl:text>
  1198. <xsl:text>sitemap path because $current.docid '</xsl:text>
  1199. <xsl:value-of select="$current.docid"/>
  1200. <xsl:text>' not found in target database.</xsl:text>
  1201. </xsl:message>
  1202. </xsl:otherwise>
  1203. </xsl:choose>
  1204. </xsl:when>
  1205. <xsl:otherwise>
  1206. <xsl:message>
  1207. <xsl:text>Olink warning: cannot compute relative </xsl:text>
  1208. <xsl:text>sitemap path without $current.docid parameter</xsl:text>
  1209. </xsl:message>
  1210. </xsl:otherwise>
  1211. </xsl:choose>
  1212. <!-- In either case, add baseuri from its document entry-->
  1213. <xsl:variable name="docbaseuri">
  1214. <xsl:for-each select="$target.database" >
  1215. <xsl:value-of select="key('targetdoc-key', $targetdoc)[1]/@baseuri" />
  1216. </xsl:for-each>
  1217. </xsl:variable>
  1218. <xsl:if test="$docbaseuri != ''" >
  1219. <xsl:value-of select="$docbaseuri"/>
  1220. </xsl:if>
  1221. </xsl:when>
  1222. <!-- No database sitemap in use -->
  1223. <xsl:otherwise>
  1224. <!-- Just use any baseuri from its document entry -->
  1225. <xsl:variable name="docbaseuri">
  1226. <xsl:for-each select="$target.database" >
  1227. <xsl:value-of select="key('targetdoc-key', $targetdoc)[1]/@baseuri" />
  1228. </xsl:for-each>
  1229. </xsl:variable>
  1230. <xsl:if test="$docbaseuri != ''" >
  1231. <xsl:value-of select="$docbaseuri"/>
  1232. </xsl:if>
  1233. </xsl:otherwise>
  1234. </xsl:choose>
  1235. </xsl:variable>
  1236. <!-- Is this olink to be active? -->
  1237. <xsl:variable name="active.olink">
  1238. <xsl:choose>
  1239. <xsl:when test="$activate.external.olinks = 0">
  1240. <xsl:choose>
  1241. <xsl:when test="$current.docid = ''">1</xsl:when>
  1242. <xsl:when test="$targetdoc = ''">1</xsl:when>
  1243. <xsl:when test="$targetdoc = $current.docid">1</xsl:when>
  1244. <xsl:otherwise>0</xsl:otherwise>
  1245. </xsl:choose>
  1246. </xsl:when>
  1247. <xsl:otherwise>1</xsl:otherwise>
  1248. </xsl:choose>
  1249. </xsl:variable>
  1250. <xsl:if test="$active.olink != 0">
  1251. <!-- Form the href information -->
  1252. <xsl:if test="not(contains($baseuri, ':'))">
  1253. <!-- if not an absolute uri, add upward path from olink chunk -->
  1254. <xsl:value-of select="$upward.from.path"/>
  1255. </xsl:if>
  1256. <xsl:if test="$baseuri != ''">
  1257. <xsl:value-of select="$baseuri"/>
  1258. <xsl:if test="substring($target.href,1,1) != '#'">
  1259. <!--xsl:text>/</xsl:text-->
  1260. </xsl:if>
  1261. </xsl:if>
  1262. <!-- optionally turn off frag for PDF references -->
  1263. <xsl:if test="not($insert.olink.pdf.frag = 0 and
  1264. translate(substring($baseuri, string-length($baseuri) - 3),
  1265. 'PDF', 'pdf') = '.pdf'
  1266. and starts-with($target.href, '#') )">
  1267. <xsl:value-of select="$target.href"/>
  1268. </xsl:if>
  1269. </xsl:if>
  1270. </xsl:if>
  1271. </xsl:template>
  1272. <!-- Computes "../" to reach top -->
  1273. <xsl:template name="upward.path">
  1274. <xsl:param name="path" select="''"/>
  1275. <xsl:choose>
  1276. <!-- Don't bother with absolute uris -->
  1277. <xsl:when test="contains($path, ':')"/>
  1278. <xsl:when test="starts-with($path, '/')"/>
  1279. <xsl:when test="contains($path, '/')">
  1280. <xsl:text>../</xsl:text>
  1281. <xsl:call-template name="upward.path">
  1282. <xsl:with-param name="path" select="substring-after($path, '/')"/>
  1283. </xsl:call-template>
  1284. </xsl:when>
  1285. </xsl:choose>
  1286. </xsl:template>
  1287. <!-- ==================================================================== -->
  1288. <xsl:template name="html.head">
  1289. <xsl:param name="prev" select="/foo"/>
  1290. <xsl:param name="next" select="/foo"/>
  1291. <xsl:variable name="this" select="."/>
  1292. <xsl:variable name="home" select="/*[1]"/>
  1293. <xsl:variable name="up" select="parent::*"/>
  1294. <head>
  1295. <xsl:call-template name="system.head.content"/>
  1296. <xsl:call-template name="head.content"/>
  1297. <!-- home link not valid in HTML5 -->
  1298. <xsl:if test="$home and $div.element != 'section'">
  1299. <link rel="home">
  1300. <xsl:attribute name="href">
  1301. <xsl:call-template name="href.target">
  1302. <xsl:with-param name="object" select="$home"/>
  1303. </xsl:call-template>
  1304. </xsl:attribute>
  1305. <xsl:attribute name="title">
  1306. <xsl:apply-templates select="$home"
  1307. mode="object.title.markup.textonly"/>
  1308. </xsl:attribute>
  1309. </link>
  1310. </xsl:if>
  1311. <!-- up link not valid in HTML5 -->
  1312. <xsl:if test="$up and $div.element != 'section'">
  1313. <link rel="up">
  1314. <xsl:attribute name="href">
  1315. <xsl:call-template name="href.target">
  1316. <xsl:with-param name="object" select="$up"/>
  1317. </xsl:call-template>
  1318. </xsl:attribute>
  1319. <xsl:attribute name="title">
  1320. <xsl:apply-templates select="$up" mode="object.title.markup.textonly"/>
  1321. </xsl:attribute>
  1322. </link>
  1323. </xsl:if>
  1324. <xsl:if test="$prev">
  1325. <link rel="prev">
  1326. <xsl:attribute name="href">
  1327. <xsl:call-template name="href.target">
  1328. <xsl:with-param name="object" select="$prev"/>
  1329. </xsl:call-template>
  1330. </xsl:attribute>
  1331. <xsl:attribute name="title">
  1332. <xsl:apply-templates select="$prev" mode="object.title.markup.textonly"/>
  1333. </xsl:attribute>
  1334. </link>
  1335. </xsl:if>
  1336. <xsl:if test="$next">
  1337. <link rel="next">
  1338. <xsl:attribute name="href">
  1339. <xsl:call-template name="href.target">
  1340. <xsl:with-param name="object" select="$next"/>
  1341. </xsl:call-template>
  1342. </xsl:attribute>
  1343. <xsl:attribute name="title">
  1344. <xsl:apply-templates select="$next" mode="object.title.markup.textonly"/>
  1345. </xsl:attribute>
  1346. </link>
  1347. </xsl:if>
  1348. <xsl:if test="$html.extra.head.links != 0">
  1349. <xsl:for-each select="//part
  1350. |//reference
  1351. |//preface
  1352. |//chapter
  1353. |//article
  1354. |//refentry
  1355. |//appendix[not(parent::article)]|appendix
  1356. |//glossary[not(parent::article)]|glossary
  1357. |//index[not(parent::article)]|index">
  1358. <link rel="{local-name(.)}">
  1359. <xsl:attribute name="href">
  1360. <xsl:call-template name="href.target">
  1361. <xsl:with-param name="context" select="$this"/>
  1362. <xsl:with-param name="object" select="."/>
  1363. </xsl:call-template>
  1364. </xsl:attribute>
  1365. <xsl:attribute name="title">
  1366. <xsl:apply-templates select="." mode="object.title.markup.textonly"/>
  1367. </xsl:attribute>
  1368. </link>
  1369. </xsl:for-each>
  1370. <xsl:for-each select="section|sect1|refsection|refsect1">
  1371. <link>
  1372. <xsl:attribute name="rel">
  1373. <xsl:choose>
  1374. <xsl:when test="local-name($this) = 'section'
  1375. or local-name($this) = 'refsection'">
  1376. <xsl:value-of select="'subsection'"/>
  1377. </xsl:when>
  1378. <xsl:otherwise>
  1379. <xsl:value-of select="'section'"/>
  1380. </xsl:otherwise>
  1381. </xsl:choose>
  1382. </xsl:attribute>
  1383. <xsl:attribute name="href">
  1384. <xsl:call-template name="href.target">
  1385. <xsl:with-param name="context" select="$this"/>
  1386. <xsl:with-param name="object" select="."/>
  1387. </xsl:call-template>
  1388. </xsl:attribute>
  1389. <xsl:attribute name="title">
  1390. <xsl:apply-templates select="." mode="object.title.markup.textonly"/>
  1391. </xsl:attribute>
  1392. </link>
  1393. </xsl:for-each>
  1394. <xsl:for-each select="sect2|sect3|sect4|sect5|refsect2|refsect3">
  1395. <link rel="subsection">
  1396. <xsl:attribute name="href">
  1397. <xsl:call-template name="href.target">
  1398. <xsl:with-param name="context" select="$this"/>
  1399. <xsl:with-param name="object" select="."/>
  1400. </xsl:call-template>
  1401. </xsl:attribute>
  1402. <xsl:attribute name="title">
  1403. <xsl:apply-templates select="." mode="object.title.markup.textonly"/>
  1404. </xsl:attribute>
  1405. </link>
  1406. </xsl:for-each>
  1407. </xsl:if>
  1408. <!-- * if we have a legalnotice and user wants it output as a -->
  1409. <!-- * separate page and $html.head.legalnotice.link.types is -->
  1410. <!-- * non-empty, we generate a link or links for each value in -->
  1411. <!-- * $html.head.legalnotice.link.types -->
  1412. <xsl:if test="//legalnotice
  1413. and not($generate.legalnotice.link = 0)
  1414. and not($html.head.legalnotice.link.types = '')">
  1415. <xsl:call-template name="make.legalnotice.head.links"/>
  1416. </xsl:if>
  1417. <xsl:call-template name="user.head.content"/>
  1418. </head>
  1419. </xsl:template>
  1420. <!-- ==================================================================== -->
  1421. <xsl:template name="header.navigation">
  1422. <xsl:param name="prev" select="/foo"/>
  1423. <xsl:param name="next" select="/foo"/>
  1424. <xsl:param name="nav.context"/>
  1425. <xsl:variable name="home" select="/*[1]"/>
  1426. <xsl:variable name="up" select="parent::*"/>
  1427. <xsl:variable name="row1" select="$navig.showtitles != 0"/>
  1428. <xsl:variable name="row2" select="count($prev) &gt; 0
  1429. or (count($up) &gt; 0
  1430. and generate-id($up) != generate-id($home)
  1431. and $navig.showtitles != 0)
  1432. or count($next) &gt; 0"/>
  1433. <xsl:if test="$suppress.navigation = '0' and $suppress.header.navigation = '0'">
  1434. <div class="navheader">
  1435. <xsl:if test="$row1 or $row2">
  1436. <table width="100%" summary="Navigation header">
  1437. <xsl:if test="$row1">
  1438. <tr>
  1439. <th colspan="3" align="center">
  1440. <xsl:apply-templates select="." mode="object.title.markup"/>
  1441. </th>
  1442. </tr>
  1443. </xsl:if>
  1444. <xsl:if test="$row2">
  1445. <tr>
  1446. <td width="20%" align="{$direction.align.start}">
  1447. <xsl:if test="count($prev)>0">
  1448. <a accesskey="p">
  1449. <xsl:attribute name="href">
  1450. <xsl:call-template name="href.target">
  1451. <xsl:with-param name="object" select="$prev"/>
  1452. </xsl:call-template>
  1453. </xsl:attribute>
  1454. <xsl:call-template name="navig.content">
  1455. <xsl:with-param name="direction" select="'prev'"/>
  1456. </xsl:call-template>
  1457. </a>
  1458. </xsl:if>
  1459. <xsl:text>&#160;</xsl:text>
  1460. </td>
  1461. <th width="60%" align="center">
  1462. <xsl:choose>
  1463. <xsl:when test="count($up) > 0
  1464. and generate-id($up) != generate-id($home)
  1465. and $navig.showtitles != 0">
  1466. <xsl:apply-templates select="$up" mode="object.title.markup"/>
  1467. </xsl:when>
  1468. <xsl:otherwise>&#160;</xsl:otherwise>
  1469. </xsl:choose>
  1470. </th>
  1471. <td width="20%" align="{$direction.align.end}">
  1472. <xsl:text>&#160;</xsl:text>
  1473. <xsl:if test="count($next)>0">
  1474. <a accesskey="n">
  1475. <xsl:attribute name="href">
  1476. <xsl:call-template name="href.target">
  1477. <xsl:with-param name="object" select="$next"/>
  1478. </xsl:call-template>
  1479. </xsl:attribute>
  1480. <xsl:call-template name="navig.content">
  1481. <xsl:with-param name="direction" select="'next'"/>
  1482. </xsl:call-template>
  1483. </a>
  1484. </xsl:if>
  1485. </td>
  1486. </tr>
  1487. </xsl:if>
  1488. </table>
  1489. </xsl:if>
  1490. <xsl:if test="$header.rule != 0">
  1491. <hr/>
  1492. </xsl:if>
  1493. </div>
  1494. </xsl:if>
  1495. </xsl:template>
  1496. <!-- ==================================================================== -->
  1497. <xsl:template name="footer.navigation">
  1498. <xsl:param name="prev" select="/foo"/>
  1499. <xsl:param name="next" select="/foo"/>
  1500. <xsl:param name="nav.context"/>
  1501. <xsl:variable name="home" select="/*[1]"/>
  1502. <xsl:variable name="up" select="parent::*"/>
  1503. <xsl:variable name="row1" select="count($prev) &gt; 0
  1504. or count($up) &gt; 0
  1505. or count($next) &gt; 0"/>
  1506. <xsl:variable name="row2" select="($prev and $navig.showtitles != 0)
  1507. or (generate-id($home) != generate-id(.)
  1508. or $nav.context = 'toc')
  1509. or ($chunk.tocs.and.lots != 0
  1510. and $nav.context != 'toc')
  1511. or ($next and $navig.showtitles != 0)"/>
  1512. <xsl:if test="$suppress.navigation = '0' and $suppress.footer.navigation = '0'">
  1513. <div class="navfooter">
  1514. <xsl:if test="$footer.rule != 0">
  1515. <hr/>
  1516. </xsl:if>
  1517. <xsl:if test="$row1 or $row2">
  1518. <table width="100%" summary="Navigation footer">
  1519. <xsl:if test="$row1">
  1520. <tr>
  1521. <td width="40%" align="{$direction.align.start}">
  1522. <xsl:if test="count($prev)>0">
  1523. <a accesskey="p">
  1524. <xsl:attribute name="href">
  1525. <xsl:call-template name="href.target">
  1526. <xsl:with-param name="object" select="$prev"/>
  1527. </xsl:call-template>
  1528. </xsl:attribute>
  1529. <xsl:call-template name="navig.content">
  1530. <xsl:with-param name="direction" select="'prev'"/>
  1531. </xsl:call-template>
  1532. </a>
  1533. </xsl:if>
  1534. <xsl:text>&#160;</xsl:text>
  1535. </td>
  1536. <td width="20%" align="center">
  1537. <xsl:choose>
  1538. <xsl:when test="count($up)&gt;0
  1539. and generate-id($up) != generate-id($home)">
  1540. <a accesskey="u">
  1541. <xsl:attribute name="href">
  1542. <xsl:call-template name="href.target">
  1543. <xsl:with-param name="object" select="$up"/>
  1544. </xsl:call-template>
  1545. </xsl:attribute>
  1546. <xsl:call-template name="navig.content">
  1547. <xsl:with-param name="direction" select="'up'"/>
  1548. </xsl:call-template>
  1549. </a>
  1550. </xsl:when>
  1551. <xsl:otherwise>&#160;</xsl:otherwise>
  1552. </xsl:choose>
  1553. </td>
  1554. <td width="40%" align="{$direction.align.end}">
  1555. <xsl:text>&#160;</xsl:text>
  1556. <xsl:if test="count($next)>0">
  1557. <a accesskey="n">
  1558. <xsl:attribute name="href">
  1559. <xsl:call-template name="href.target">
  1560. <xsl:with-param name="object" select="$next"/>
  1561. </xsl:call-template>
  1562. </xsl:attribute>
  1563. <xsl:call-template name="navig.content">
  1564. <xsl:with-param name="direction" select="'next'"/>
  1565. </xsl:call-template>
  1566. </a>
  1567. </xsl:if>
  1568. </td>
  1569. </tr>
  1570. </xsl:if>
  1571. <xsl:if test="$row2">
  1572. <tr>
  1573. <td width="40%" align="{$direction.align.start}" valign="top">
  1574. <xsl:if test="$navig.showtitles != 0">
  1575. <xsl:apply-templates select="$prev" mode="object.title.markup"/>
  1576. </xsl:if>
  1577. <xsl:text>&#160;</xsl:text>
  1578. </td>
  1579. <td width="20%" align="center">
  1580. <xsl:choose>
  1581. <xsl:when test="$home != . or $nav.context = 'toc'">
  1582. <a accesskey="h">
  1583. <xsl:attribute name="href">
  1584. <xsl:call-template name="href.target">
  1585. <xsl:with-param name="object" select="$home"/>
  1586. </xsl:call-template>
  1587. </xsl:attribute>
  1588. <xsl:call-template name="navig.content">
  1589. <xsl:with-param name="direction" select="'home'"/>
  1590. </xsl:call-template>
  1591. </a>
  1592. <xsl:if test="$chunk.tocs.and.lots != 0 and $nav.context != 'toc'">
  1593. <xsl:text>&#160;|&#160;</xsl:text>
  1594. </xsl:if>
  1595. </xsl:when>
  1596. <xsl:otherwise>&#160;</xsl:otherwise>
  1597. </xsl:choose>
  1598. <xsl:if test="$chunk.tocs.and.lots != 0 and $nav.context != 'toc'">
  1599. <a accesskey="t">
  1600. <xsl:attribute name="href">
  1601. <xsl:value-of select="$chunked.filename.prefix"/>
  1602. <xsl:apply-templates select="/*[1]"
  1603. mode="recursive-chunk-filename">
  1604. <xsl:with-param name="recursive" select="true()"/>
  1605. </xsl:apply-templates>
  1606. <xsl:text>-toc</xsl:text>
  1607. <xsl:value-of select="$html.ext"/>
  1608. </xsl:attribute>
  1609. <xsl:call-template name="gentext">
  1610. <xsl:with-param name="key" select="'nav-toc'"/>
  1611. </xsl:call-template>
  1612. </a>
  1613. </xsl:if>
  1614. </td>
  1615. <td width="40%" align="{$direction.align.end}" valign="top">
  1616. <xsl:text>&#160;</xsl:text>
  1617. <xsl:if test="$navig.showtitles != 0">
  1618. <xsl:apply-templates select="$next" mode="object.title.markup"/>
  1619. </xsl:if>
  1620. </td>
  1621. </tr>
  1622. </xsl:if>
  1623. </table>
  1624. </xsl:if>
  1625. </div>
  1626. </xsl:if>
  1627. </xsl:template>
  1628. <!-- ==================================================================== -->
  1629. <xsl:template name="navig.content">
  1630. <xsl:param name="direction" select="next"/>
  1631. <xsl:variable name="navtext">
  1632. <xsl:choose>
  1633. <xsl:when test="$direction = 'prev'">
  1634. <xsl:call-template name="gentext.nav.prev"/>
  1635. </xsl:when>
  1636. <xsl:when test="$direction = 'next'">
  1637. <xsl:call-template name="gentext.nav.next"/>
  1638. </xsl:when>
  1639. <xsl:when test="$direction = 'up'">
  1640. <xsl:call-template name="gentext.nav.up"/>
  1641. </xsl:when>
  1642. <xsl:when test="$direction = 'home'">
  1643. <xsl:call-template name="gentext.nav.home"/>
  1644. </xsl:when>
  1645. <xsl:otherwise>
  1646. <xsl:text>xxx</xsl:text>
  1647. </xsl:otherwise>
  1648. </xsl:choose>
  1649. </xsl:variable>
  1650. <xsl:choose>
  1651. <xsl:when test="$navig.graphics != 0">
  1652. <img>
  1653. <xsl:attribute name="src">
  1654. <xsl:value-of select="$navig.graphics.path"/>
  1655. <xsl:value-of select="$direction"/>
  1656. <xsl:value-of select="$navig.graphics.extension"/>
  1657. </xsl:attribute>
  1658. <xsl:attribute name="alt">
  1659. <xsl:value-of select="$navtext"/>
  1660. </xsl:attribute>
  1661. </img>
  1662. </xsl:when>
  1663. <xsl:otherwise>
  1664. <xsl:value-of select="$navtext"/>
  1665. </xsl:otherwise>
  1666. </xsl:choose>
  1667. </xsl:template>
  1668. <!-- ==================================================================== -->
  1669. <!-- * The following template assumes that the first legalnotice -->
  1670. <!-- * instance found in a document applies to the contents of the -->
  1671. <!-- * entire document. It generates an HTML link in each chunk, back -->
  1672. <!-- * to the file containing the contents of the first legalnotice. -->
  1673. <!-- * -->
  1674. <!-- * Actually, it may generate multiple link instances in each chunk, -->
  1675. <!-- * because it walks through the space-separated list of link -->
  1676. <!-- * types specified in the $html.head.legalnotice.link.types param, -->
  1677. <!-- * popping off link types and generating links for them until it -->
  1678. <!-- * depletes the list. -->
  1679. <xsl:template name="make.legalnotice.head.links">
  1680. <!-- * the following ID is used as part of the legalnotice filename; -->
  1681. <!-- * we need it in order to construct the filename for use in the -->
  1682. <!-- * value of the href attribute on the link -->
  1683. <xsl:param name="ln-node" select="(//legalnotice)[1]"/>
  1684. <xsl:param name="linktype">
  1685. <xsl:choose>
  1686. <xsl:when test="contains($html.head.legalnotice.link.types, ' ')">
  1687. <xsl:value-of
  1688. select="normalize-space(
  1689. substring-before($html.head.legalnotice.link.types, ' '))"/>
  1690. </xsl:when>
  1691. <xsl:otherwise>
  1692. <xsl:value-of select="$html.head.legalnotice.link.types"/>
  1693. </xsl:otherwise>
  1694. </xsl:choose>
  1695. </xsl:param>
  1696. <xsl:param
  1697. name="remaining.linktypes"
  1698. select="concat(
  1699. normalize-space(
  1700. substring-after($html.head.legalnotice.link.types, ' ')),' ')"/>
  1701. <xsl:if test="not($linktype = '')">
  1702. <!-- Compute name of legalnotice file (see titlepage.xsl) -->
  1703. <xsl:variable name="file">
  1704. <xsl:call-template name="ln.or.rh.filename">
  1705. <xsl:with-param name="node" select="$ln-node"/>
  1706. </xsl:call-template>
  1707. </xsl:variable>
  1708. <link rel="{$linktype}">
  1709. <xsl:attribute name="href">
  1710. <xsl:value-of select="$file"/>
  1711. </xsl:attribute>
  1712. <xsl:attribute name="title">
  1713. <xsl:apply-templates select="(//legalnotice)[1]"
  1714. mode="object.title.markup.textonly"/>
  1715. </xsl:attribute>
  1716. </link>
  1717. <xsl:call-template name="make.legalnotice.head.links">
  1718. <!-- * pop the next value off the list of link types -->
  1719. <xsl:with-param
  1720. name="linktype"
  1721. select="substring-before($remaining.linktypes, ' ')"/>
  1722. <!-- * remove the link type from the list of remaining link types -->
  1723. <xsl:with-param
  1724. name="remaining.linktypes"
  1725. select="substring-after($remaining.linktypes, ' ')"/>
  1726. </xsl:call-template>
  1727. </xsl:if>
  1728. </xsl:template>
  1729. <!-- ==================================================================== -->
  1730. <xsl:template name="chunk-element-content">
  1731. <xsl:param name="prev"/>
  1732. <xsl:param name="next"/>
  1733. <xsl:param name="nav.context"/>
  1734. <xsl:param name="content">
  1735. <xsl:apply-imports/>
  1736. </xsl:param>
  1737. <xsl:call-template name="user.preroot"/>
  1738. <html>
  1739. <xsl:call-template name="root.attributes"/>
  1740. <xsl:call-template name="html.head">
  1741. <xsl:with-param name="prev" select="$prev"/>
  1742. <xsl:with-param name="next" select="$next"/>
  1743. </xsl:call-template>
  1744. <body>
  1745. <xsl:call-template name="body.attributes"/>
  1746. <xsl:call-template name="user.header.navigation">
  1747. <xsl:with-param name="prev" select="$prev"/>
  1748. <xsl:with-param name="next" select="$next"/>
  1749. <xsl:with-param name="nav.context" select="$nav.context"/>
  1750. </xsl:call-template>
  1751. <xsl:call-template name="header.navigation">
  1752. <xsl:with-param name="prev" select="$prev"/>
  1753. <xsl:with-param name="next" select="$next"/>
  1754. <xsl:with-param name="nav.context" select="$nav.context"/>
  1755. </xsl:call-template>
  1756. <xsl:call-template name="user.header.content"/>
  1757. <xsl:copy-of select="$content"/>
  1758. <xsl:call-template name="user.footer.content"/>
  1759. <xsl:call-template name="footer.navigation">
  1760. <xsl:with-param name="prev" select="$prev"/>
  1761. <xsl:with-param name="next" select="$next"/>
  1762. <xsl:with-param name="nav.context" select="$nav.context"/>
  1763. </xsl:call-template>
  1764. <xsl:call-template name="user.footer.navigation">
  1765. <xsl:with-param name="prev" select="$prev"/>
  1766. <xsl:with-param name="next" select="$next"/>
  1767. <xsl:with-param name="nav.context" select="$nav.context"/>
  1768. </xsl:call-template>
  1769. </body>
  1770. </html>
  1771. <xsl:value-of select="$chunk.append"/>
  1772. </xsl:template>
  1773. <!-- ==================================================================== -->
  1774. <xsl:template name="generate.manifest">
  1775. <xsl:param name="node" select="/"/>
  1776. <xsl:call-template name="write.text.chunk">
  1777. <xsl:with-param name="filename">
  1778. <xsl:if test="$manifest.in.base.dir != 0">
  1779. <xsl:value-of select="$chunk.base.dir"/>
  1780. </xsl:if>
  1781. <xsl:value-of select="$manifest"/>
  1782. </xsl:with-param>
  1783. <xsl:with-param name="method" select="'text'"/>
  1784. <xsl:with-param name="content">
  1785. <xsl:apply-templates select="$node" mode="enumerate-files"/>
  1786. </xsl:with-param>
  1787. <xsl:with-param name="encoding" select="$chunker.output.encoding"/>
  1788. </xsl:call-template>
  1789. </xsl:template>
  1790. <!-- ==================================================================== -->
  1791. <xsl:template name="dbhtml-dir">
  1792. <xsl:param name="context" select="."/>
  1793. <!-- directories are now inherited from previous levels -->
  1794. <xsl:variable name="ppath">
  1795. <xsl:if test="$context/parent::*">
  1796. <xsl:call-template name="dbhtml-dir">
  1797. <xsl:with-param name="context" select="$context/parent::*"/>
  1798. </xsl:call-template>
  1799. </xsl:if>
  1800. </xsl:variable>
  1801. <xsl:variable name="path">
  1802. <xsl:call-template name="pi.dbhtml_dir">
  1803. <xsl:with-param name="node" select="$context"/>
  1804. </xsl:call-template>
  1805. </xsl:variable>
  1806. <xsl:choose>
  1807. <xsl:when test="$path = ''">
  1808. <xsl:if test="$ppath != ''">
  1809. <xsl:value-of select="$ppath"/>
  1810. </xsl:if>
  1811. </xsl:when>
  1812. <xsl:otherwise>
  1813. <xsl:if test="$ppath != ''">
  1814. <xsl:value-of select="$ppath"/>
  1815. <xsl:if test="substring($ppath, string-length($ppath), 1) != '/'">
  1816. <xsl:text>/</xsl:text>
  1817. </xsl:if>
  1818. </xsl:if>
  1819. <xsl:value-of select="$path"/>
  1820. <xsl:text>/</xsl:text>
  1821. </xsl:otherwise>
  1822. </xsl:choose>
  1823. </xsl:template>
  1824. </xsl:stylesheet>