You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

chunk-experimental.xsl 26KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796
  1. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  2. xmlns:doc="http://nwalsh.com/xsl/documentation/1.0"
  3. version="1.0"
  4. exclude-result-prefixes="doc">
  5. <xsl:param name="html.ext" select="'.html'"/>
  6. <doc:param name="html.ext" xmlns="">
  7. <refpurpose>Extension for chunked files</refpurpose>
  8. <refdescription>
  9. <para>The extension identified by <parameter>html.ext</parameter> will
  10. be used as the filename extension for chunks created by this stylesheet.
  11. </para>
  12. </refdescription>
  13. </doc:param>
  14. <xsl:param name="root.filename" select="'index'"/>
  15. <doc:param name="root.filename" xmlns="">
  16. <refpurpose>Filename for the root chunk</refpurpose>
  17. <refdescription>
  18. <para>The <parameter>root.filename</parameter> is the base filename for
  19. the chunk created for the root of each document processed.
  20. </para>
  21. </refdescription>
  22. </doc:param>
  23. <xsl:param name="base.dir" select="''"/>
  24. <doc:param name="base.dir" xmlns="">
  25. <refpurpose>Output directory for chunks</refpurpose>
  26. <refdescription>
  27. <para>If specified, the <literal>base.dir</literal> identifies
  28. the output directory for chunks. (If not specified, the output directory
  29. is system dependent.)</para>
  30. </refdescription>
  31. </doc:param>
  32. <xsl:param name="chunk.sections" select="'1'"/>
  33. <doc:param name="chunk.sections" xmlns="">
  34. <refpurpose>Create chunks for top-level sections in components?</refpurpose>
  35. <refdescription>
  36. <para>If non-zero, chunks will be created for top-level
  37. <sgmltag>sect1</sgmltag> and <sgmltag>section</sgmltag> elements in
  38. each component.
  39. </para>
  40. </refdescription>
  41. </doc:param>
  42. <xsl:param name="chunk.first.sections" select="'0'"/>
  43. <doc:param name="chunk.first.sections" xmlns="">
  44. <refpurpose>Create a chunk for the first top-level section in each component?</refpurpose>
  45. <refdescription>
  46. <para>If non-zero, a chunk will be created for the first top-level
  47. <sgmltag>sect1</sgmltag> or <sgmltag>section</sgmltag> elements in
  48. each component. Otherwise, that section will be part of the chunk for
  49. its parent.
  50. </para>
  51. </refdescription>
  52. </doc:param>
  53. <xsl:param name="chunk.datafile" select="'.chunks'"/>
  54. <doc:param name="chunk.datafile" xmlns="">
  55. <refpurpose>Name of the temporary file used to hold chunking data</refpurpose>
  56. <refdescription>
  57. <para>Chunking is now a two-step process. The
  58. <parameter>chunk.datafile</parameter> is the name of the file used to
  59. hold the chunking data.
  60. </para>
  61. </refdescription>
  62. </doc:param>
  63. <!-- ==================================================================== -->
  64. <!-- What's a chunk?
  65. appendix
  66. article
  67. bibliography in article or book
  68. book
  69. chapter
  70. colophon
  71. glossary in article or book
  72. index in article or book
  73. part
  74. preface
  75. refentry
  76. reference
  77. sect1 if position()>1
  78. section if position()>1 && parent != section
  79. set
  80. setindex
  81. -->
  82. <!-- ==================================================================== -->
  83. <xsl:template name="chunk">
  84. <xsl:param name="node" select="."/>
  85. <!-- returns 1 if $node is a chunk -->
  86. <xsl:variable name="id">
  87. <xsl:choose>
  88. <xsl:when test="$node/@id">
  89. <xsl:value-of select="$node/@id"/>
  90. </xsl:when>
  91. <xsl:otherwise>
  92. <xsl:value-of select="generate-id($node)"/>
  93. </xsl:otherwise>
  94. </xsl:choose>
  95. </xsl:variable>
  96. <xsl:variable name="chunks" select="document($chunk.datafile,.)"/>
  97. <xsl:choose>
  98. <xsl:when test="$chunks/chunks/chunk[@id=$id]">1</xsl:when>
  99. <xsl:otherwise>0</xsl:otherwise>
  100. </xsl:choose>
  101. </xsl:template>
  102. <!-- ==================================================================== -->
  103. <xsl:template match="*" mode="chunk-filename">
  104. <!-- returns the filename of a chunk -->
  105. <xsl:variable name="id">
  106. <xsl:choose>
  107. <xsl:when test="@id">
  108. <xsl:value-of select="@id"/>
  109. </xsl:when>
  110. <xsl:otherwise>
  111. <xsl:value-of select="generate-id(.)"/>
  112. </xsl:otherwise>
  113. </xsl:choose>
  114. </xsl:variable>
  115. <xsl:variable name="chunks" select="document($chunk.datafile,.)"/>
  116. <xsl:variable name="chunk" select="$chunks/chunks/chunk[@id=$id]"/>
  117. <xsl:choose>
  118. <xsl:when test="$chunk">
  119. <xsl:value-of select="$chunk/@filename"/>
  120. </xsl:when>
  121. <xsl:otherwise>
  122. <xsl:apply-templates select="parent::*" mode="chunk-filename"/>
  123. </xsl:otherwise>
  124. </xsl:choose>
  125. </xsl:template>
  126. <!-- ==================================================================== -->
  127. <xsl:template name="href.target">
  128. <xsl:param name="object" select="."/>
  129. <xsl:variable name="ischunk">
  130. <xsl:call-template name="chunk">
  131. <xsl:with-param name="node" select="$object"/>
  132. </xsl:call-template>
  133. </xsl:variable>
  134. <xsl:apply-templates mode="chunk-filename" select="$object"/>
  135. <xsl:if test="$ischunk='0'">
  136. <xsl:text>#</xsl:text>
  137. <xsl:call-template name="object.id">
  138. <xsl:with-param name="object" select="$object"/>
  139. </xsl:call-template>
  140. </xsl:if>
  141. </xsl:template>
  142. <!-- ==================================================================== -->
  143. <xsl:template name="html.head">
  144. <xsl:param name="prev" select="/foo"/>
  145. <xsl:param name="next" select="/foo"/>
  146. <xsl:variable name="home" select="/*[1]"/>
  147. <xsl:variable name="up" select="parent::*"/>
  148. <head>
  149. <xsl:call-template name="head.content"/>
  150. <xsl:call-template name="user.head.content"/>
  151. <xsl:if test="$home">
  152. <link rel="home">
  153. <xsl:attribute name="href">
  154. <xsl:call-template name="href.target">
  155. <xsl:with-param name="object" select="$home"/>
  156. </xsl:call-template>
  157. </xsl:attribute>
  158. <xsl:attribute name="title">
  159. <xsl:apply-templates select="$home"
  160. mode="object.title.markup.textonly"/>
  161. </xsl:attribute>
  162. </link>
  163. </xsl:if>
  164. <xsl:if test="$up">
  165. <link rel="up">
  166. <xsl:attribute name="href">
  167. <xsl:call-template name="href.target">
  168. <xsl:with-param name="object" select="$up"/>
  169. </xsl:call-template>
  170. </xsl:attribute>
  171. <xsl:attribute name="title">
  172. <xsl:apply-templates select="$up" mode="object.title.markup.textonly"/>
  173. </xsl:attribute>
  174. </link>
  175. </xsl:if>
  176. <xsl:if test="$prev">
  177. <link rel="previous">
  178. <xsl:attribute name="href">
  179. <xsl:call-template name="href.target">
  180. <xsl:with-param name="object" select="$prev"/>
  181. </xsl:call-template>
  182. </xsl:attribute>
  183. <xsl:attribute name="title">
  184. <xsl:apply-templates select="$prev" mode="object.title.markup.textonly"/>
  185. </xsl:attribute>
  186. </link>
  187. </xsl:if>
  188. <xsl:if test="$next">
  189. <link rel="next">
  190. <xsl:attribute name="href">
  191. <xsl:call-template name="href.target">
  192. <xsl:with-param name="object" select="$next"/>
  193. </xsl:call-template>
  194. </xsl:attribute>
  195. <xsl:attribute name="title">
  196. <xsl:apply-templates select="$next" mode="object.title.markup.textonly"/>
  197. </xsl:attribute>
  198. </link>
  199. </xsl:if>
  200. </head>
  201. </xsl:template>
  202. <!-- ==================================================================== -->
  203. <xsl:template name="header.navigation">
  204. <xsl:param name="prev" select="/foo"/>
  205. <xsl:param name="next" select="/foo"/>
  206. <xsl:variable name="home" select="/*[1]"/>
  207. <xsl:variable name="up" select="parent::*"/>
  208. <xsl:if test="$suppress.navigation = '0'">
  209. <div class="navheader">
  210. <table width="100%" summary="Navigation header">
  211. <tr>
  212. <th colspan="3" align="center">
  213. <xsl:apply-templates select="." mode="object.title.markup"/>
  214. </th>
  215. </tr>
  216. <tr>
  217. <td width="20%" align="left">
  218. <xsl:if test="count($prev)>0">
  219. <a accesskey="p">
  220. <xsl:attribute name="href">
  221. <xsl:call-template name="href.target">
  222. <xsl:with-param name="object" select="$prev"/>
  223. </xsl:call-template>
  224. </xsl:attribute>
  225. <xsl:call-template name="gentext">
  226. <xsl:with-param name="key">nav-prev</xsl:with-param>
  227. </xsl:call-template>
  228. </a>
  229. </xsl:if>
  230. <xsl:text>&#160;</xsl:text>
  231. </td>
  232. <th width="60%" align="center">
  233. <xsl:choose>
  234. <xsl:when test="count($up) > 0 and $up != $home">
  235. <xsl:apply-templates select="$up" mode="object.title.markup"/>
  236. </xsl:when>
  237. <xsl:otherwise>&#160;</xsl:otherwise>
  238. </xsl:choose>
  239. </th>
  240. <td width="20%" align="right">
  241. <xsl:text>&#160;</xsl:text>
  242. <xsl:if test="count($next)>0">
  243. <a accesskey="n">
  244. <xsl:attribute name="href">
  245. <xsl:call-template name="href.target">
  246. <xsl:with-param name="object" select="$next"/>
  247. </xsl:call-template>
  248. </xsl:attribute>
  249. <xsl:call-template name="gentext">
  250. <xsl:with-param name="key">nav-next</xsl:with-param>
  251. </xsl:call-template>
  252. </a>
  253. </xsl:if>
  254. </td>
  255. </tr>
  256. </table>
  257. <hr/>
  258. </div>
  259. </xsl:if>
  260. </xsl:template>
  261. <!-- ==================================================================== -->
  262. <xsl:template name="footer.navigation">
  263. <xsl:param name="prev" select="/foo"/>
  264. <xsl:param name="next" select="/foo"/>
  265. <xsl:variable name="home" select="/*[1]"/>
  266. <xsl:variable name="up" select="parent::*"/>
  267. <xsl:if test="$suppress.navigation = '0'">
  268. <div class="navfooter">
  269. <hr/>
  270. <table width="100%" summary="Navigation footer">
  271. <tr>
  272. <td width="40%" align="left">
  273. <xsl:if test="count($prev)>0">
  274. <a accesskey="p">
  275. <xsl:attribute name="href">
  276. <xsl:call-template name="href.target">
  277. <xsl:with-param name="object" select="$prev"/>
  278. </xsl:call-template>
  279. </xsl:attribute>
  280. <xsl:call-template name="gentext">
  281. <xsl:with-param name="key">nav-prev</xsl:with-param>
  282. </xsl:call-template>
  283. </a>
  284. </xsl:if>
  285. <xsl:text>&#160;</xsl:text>
  286. </td>
  287. <td width="20%" align="center">
  288. <xsl:choose>
  289. <xsl:when test="$home != .">
  290. <a accesskey="h">
  291. <xsl:attribute name="href">
  292. <xsl:call-template name="href.target">
  293. <xsl:with-param name="object" select="$home"/>
  294. </xsl:call-template>
  295. </xsl:attribute>
  296. <xsl:call-template name="gentext">
  297. <xsl:with-param name="key">nav-home</xsl:with-param>
  298. </xsl:call-template>
  299. </a>
  300. </xsl:when>
  301. <xsl:otherwise>&#160;</xsl:otherwise>
  302. </xsl:choose>
  303. </td>
  304. <td width="40%" align="right">
  305. <xsl:text>&#160;</xsl:text>
  306. <xsl:if test="count($next)>0">
  307. <a accesskey="n">
  308. <xsl:attribute name="href">
  309. <xsl:call-template name="href.target">
  310. <xsl:with-param name="object" select="$next"/>
  311. </xsl:call-template>
  312. </xsl:attribute>
  313. <xsl:call-template name="gentext">
  314. <xsl:with-param name="key">nav-next</xsl:with-param>
  315. </xsl:call-template>
  316. </a>
  317. </xsl:if>
  318. </td>
  319. </tr>
  320. <tr>
  321. <td width="40%" align="left">
  322. <xsl:apply-templates select="$prev" mode="object.title.markup"/>
  323. <xsl:text>&#160;</xsl:text>
  324. </td>
  325. <td width="20%" align="center">
  326. <xsl:choose>
  327. <xsl:when test="count($up)>0">
  328. <a accesskey="u">
  329. <xsl:attribute name="href">
  330. <xsl:call-template name="href.target">
  331. <xsl:with-param name="object" select="$up"/>
  332. </xsl:call-template>
  333. </xsl:attribute>
  334. <xsl:call-template name="gentext">
  335. <xsl:with-param name="key">nav-up</xsl:with-param>
  336. </xsl:call-template>
  337. </a>
  338. </xsl:when>
  339. <xsl:otherwise>&#160;</xsl:otherwise>
  340. </xsl:choose>
  341. </td>
  342. <td width="40%" align="right">
  343. <xsl:text>&#160;</xsl:text>
  344. <xsl:apply-templates select="$next" mode="object.title.markup"/>
  345. </td>
  346. </tr>
  347. </table>
  348. </div>
  349. </xsl:if>
  350. </xsl:template>
  351. <!-- ==================================================================== -->
  352. <xsl:template match="processing-instruction('dbhtml')">
  353. <!-- nop -->
  354. </xsl:template>
  355. <!-- ==================================================================== -->
  356. <xsl:template name="process-chunk">
  357. <xsl:variable name="id">
  358. <xsl:choose>
  359. <xsl:when test="@id">
  360. <xsl:value-of select="@id"/>
  361. </xsl:when>
  362. <xsl:otherwise>
  363. <xsl:value-of select="generate-id(.)"/>
  364. </xsl:otherwise>
  365. </xsl:choose>
  366. </xsl:variable>
  367. <xsl:variable name="chunks" select="document($chunk.datafile,.)"/>
  368. <xsl:variable name="chunk" select="$chunks/chunks/chunk[@id=$id]"/>
  369. <xsl:variable name="prev-id"
  370. select="$chunk/preceding-sibling::chunk[1]/@id"/>
  371. <xsl:variable name="next-id"
  372. select="$chunk/following-sibling::chunk[1]/@id"/>
  373. <xsl:variable name="prev" select="id($prev-id)"/>
  374. <xsl:variable name="next" select="id($next-id)"/>
  375. <xsl:variable name="ischunk">
  376. <xsl:call-template name="chunk"/>
  377. </xsl:variable>
  378. <xsl:variable name="chunkfn">
  379. <xsl:if test="$ischunk='1'">
  380. <xsl:apply-templates mode="chunk-filename" select="."/>
  381. </xsl:if>
  382. </xsl:variable>
  383. <xsl:if test="$ischunk='0'">
  384. <xsl:message>
  385. <xsl:text>Error </xsl:text>
  386. <xsl:value-of select="name(.)"/>
  387. <xsl:text> is not a chunk!</xsl:text>
  388. </xsl:message>
  389. </xsl:if>
  390. <xsl:variable name="filename">
  391. <xsl:call-template name="make-relative-filename">
  392. <xsl:with-param name="base.dir" select="$base.dir"/>
  393. <xsl:with-param name="base.name" select="$chunkfn"/>
  394. </xsl:call-template>
  395. </xsl:variable>
  396. <xsl:call-template name="write.chunk">
  397. <xsl:with-param name="filename" select="$filename"/>
  398. <xsl:with-param name="content">
  399. <xsl:call-template name="chunk-element-content">
  400. <xsl:with-param name="prev" select="$prev"/>
  401. <xsl:with-param name="next" select="$next"/>
  402. </xsl:call-template>
  403. </xsl:with-param>
  404. </xsl:call-template>
  405. </xsl:template>
  406. <xsl:template name="chunk-element-content">
  407. <xsl:param name="prev"></xsl:param>
  408. <xsl:param name="next"></xsl:param>
  409. <html>
  410. <xsl:call-template name="html.head">
  411. <xsl:with-param name="prev" select="$prev"/>
  412. <xsl:with-param name="next" select="$next"/>
  413. </xsl:call-template>
  414. <body>
  415. <xsl:call-template name="body.attributes"/>
  416. <xsl:call-template name="user.header.navigation"/>
  417. <xsl:call-template name="header.navigation">
  418. <xsl:with-param name="prev" select="$prev"/>
  419. <xsl:with-param name="next" select="$next"/>
  420. </xsl:call-template>
  421. <xsl:call-template name="user.header.content"/>
  422. <xsl:apply-imports/>
  423. <xsl:call-template name="user.footer.content"/>
  424. <xsl:call-template name="footer.navigation">
  425. <xsl:with-param name="prev" select="$prev"/>
  426. <xsl:with-param name="next" select="$next"/>
  427. </xsl:call-template>
  428. <xsl:call-template name="user.footer.navigation"/>
  429. </body>
  430. </html>
  431. </xsl:template>
  432. <!-- ==================================================================== -->
  433. <xsl:template match="set">
  434. <xsl:call-template name="process-chunk"/>
  435. </xsl:template>
  436. <xsl:template match="book">
  437. <xsl:call-template name="process-chunk"/>
  438. </xsl:template>
  439. <xsl:template match="book/appendix">
  440. <xsl:call-template name="process-chunk"/>
  441. </xsl:template>
  442. <xsl:template match="book/glossary">
  443. <xsl:call-template name="process-chunk"/>
  444. </xsl:template>
  445. <xsl:template match="book/bibliography">
  446. <xsl:call-template name="process-chunk"/>
  447. </xsl:template>
  448. <xsl:template match="preface|chapter">
  449. <xsl:call-template name="process-chunk"/>
  450. </xsl:template>
  451. <xsl:template match="part|reference">
  452. <xsl:call-template name="process-chunk"/>
  453. </xsl:template>
  454. <xsl:template match="refentry">
  455. <xsl:call-template name="process-chunk"/>
  456. </xsl:template>
  457. <xsl:template match="colophon">
  458. <xsl:call-template name="process-chunk"/>
  459. </xsl:template>
  460. <xsl:template match="article">
  461. <xsl:call-template name="process-chunk"/>
  462. </xsl:template>
  463. <xsl:template match="article/appendix">
  464. <xsl:call-template name="process-chunk"/>
  465. </xsl:template>
  466. <xsl:template match="article/glossary">
  467. <xsl:call-template name="process-chunk"/>
  468. </xsl:template>
  469. <xsl:template match="article/bibliography">
  470. <xsl:call-template name="process-chunk"/>
  471. </xsl:template>
  472. <xsl:template match="sect1
  473. |/section
  474. |section[local-name(parent::*) != 'section']">
  475. <xsl:choose>
  476. <xsl:when test=". = /section">
  477. <xsl:call-template name="process-chunk"/>
  478. </xsl:when>
  479. <xsl:when test="$chunk.sections = 0">
  480. <xsl:apply-imports/>
  481. </xsl:when>
  482. <xsl:when test="ancestor::partintro">
  483. <xsl:apply-imports/>
  484. </xsl:when>
  485. <xsl:when test="$chunk.first.sections = 0">
  486. <xsl:choose>
  487. <xsl:when test="count(preceding-sibling::section) &gt; 0
  488. or count(preceding-sibling::sect1) &gt; 0">
  489. <xsl:call-template name="process-chunk"/>
  490. </xsl:when>
  491. <xsl:otherwise>
  492. <xsl:apply-imports/>
  493. </xsl:otherwise>
  494. </xsl:choose>
  495. </xsl:when>
  496. <xsl:otherwise>
  497. <xsl:call-template name="process-chunk"/>
  498. </xsl:otherwise>
  499. </xsl:choose>
  500. </xsl:template>
  501. <xsl:template match="setindex
  502. |book/index
  503. |article/index">
  504. <!-- some implementations use completely empty index tags to indicate -->
  505. <!-- where an automatically generated index should be inserted. so -->
  506. <!-- if the index is completely empty, skip it. -->
  507. <xsl:if test="count(*)>0 or $generate.index != '0'">
  508. <xsl:call-template name="process-chunk"/>
  509. </xsl:if>
  510. </xsl:template>
  511. <!-- ==================================================================== -->
  512. <xsl:template match="/">
  513. <xsl:choose>
  514. <xsl:when test="$rootid != ''">
  515. <xsl:choose>
  516. <xsl:when test="count(id($rootid)) = 0">
  517. <xsl:message terminate="yes">
  518. <xsl:text>ID '</xsl:text>
  519. <xsl:value-of select="$rootid"/>
  520. <xsl:text>' not found in document.</xsl:text>
  521. </xsl:message>
  522. </xsl:when>
  523. <xsl:otherwise>
  524. <xsl:apply-templates select="id($rootid)"/>
  525. </xsl:otherwise>
  526. </xsl:choose>
  527. </xsl:when>
  528. <xsl:otherwise>
  529. <xsl:apply-templates select="/" mode="process.root"/>
  530. </xsl:otherwise>
  531. </xsl:choose>
  532. </xsl:template>
  533. <xsl:template match="*" mode="process.root">
  534. <xsl:apply-templates select="."/>
  535. </xsl:template>
  536. <!-- ==================================================================== -->
  537. <xsl:template name="in.other.chunk">
  538. <xsl:param name="chunk" select="."/>
  539. <xsl:param name="node" select="."/>
  540. <xsl:variable name="is.chunk">
  541. <xsl:call-template name="chunk">
  542. <xsl:with-param name="node" select="$node"/>
  543. </xsl:call-template>
  544. </xsl:variable>
  545. <!--
  546. <xsl:message>
  547. <xsl:text>in.other.chunk: </xsl:text>
  548. <xsl:value-of select="name($chunk)"/>
  549. <xsl:text> </xsl:text>
  550. <xsl:value-of select="name($node)"/>
  551. <xsl:text> </xsl:text>
  552. <xsl:value-of select="$chunk = $node"/>
  553. <xsl:text> </xsl:text>
  554. <xsl:value-of select="$is.chunk"/>
  555. </xsl:message>
  556. -->
  557. <xsl:choose>
  558. <xsl:when test="$chunk = $node">0</xsl:when>
  559. <xsl:when test="$is.chunk = 1">1</xsl:when>
  560. <xsl:when test="count($node) = 0">0</xsl:when>
  561. <xsl:otherwise>
  562. <xsl:call-template name="in.other.chunk">
  563. <xsl:with-param name="chunk" select="$chunk"/>
  564. <xsl:with-param name="node" select="$node/parent::*"/>
  565. </xsl:call-template>
  566. </xsl:otherwise>
  567. </xsl:choose>
  568. </xsl:template>
  569. <xsl:template name="count.footnotes.in.this.chunk">
  570. <xsl:param name="node" select="."/>
  571. <xsl:param name="footnotes" select="$node//footnote"/>
  572. <xsl:param name="count" select="0"/>
  573. <!--
  574. <xsl:message>
  575. <xsl:text>count.footnotes.in.this.chunk: </xsl:text>
  576. <xsl:value-of select="name($node)"/>
  577. </xsl:message>
  578. -->
  579. <xsl:variable name="in.other.chunk">
  580. <xsl:call-template name="in.other.chunk">
  581. <xsl:with-param name="chunk" select="$node"/>
  582. <xsl:with-param name="node" select="$footnotes[1]"/>
  583. </xsl:call-template>
  584. </xsl:variable>
  585. <xsl:choose>
  586. <xsl:when test="count($footnotes) = 0">
  587. <xsl:value-of select="$count"/>
  588. </xsl:when>
  589. <xsl:otherwise>
  590. <xsl:choose>
  591. <xsl:when test="$in.other.chunk != 0">
  592. <xsl:call-template name="count.footnotes.in.this.chunk">
  593. <xsl:with-param name="node" select="$node"/>
  594. <xsl:with-param name="footnotes"
  595. select="$footnotes[position() &gt; 1]"/>
  596. <xsl:with-param name="count" select="$count"/>
  597. </xsl:call-template>
  598. </xsl:when>
  599. <xsl:when test="$footnotes[1]/ancestor::table
  600. |$footnotes[1]/ancestor::informaltable">
  601. <xsl:call-template name="count.footnotes.in.this.chunk">
  602. <xsl:with-param name="node" select="$node"/>
  603. <xsl:with-param name="footnotes"
  604. select="$footnotes[position() &gt; 1]"/>
  605. <xsl:with-param name="count" select="$count"/>
  606. </xsl:call-template>
  607. </xsl:when>
  608. <xsl:otherwise>
  609. <xsl:call-template name="count.footnotes.in.this.chunk">
  610. <xsl:with-param name="node" select="$node"/>
  611. <xsl:with-param name="footnotes"
  612. select="$footnotes[position() &gt; 1]"/>
  613. <xsl:with-param name="count" select="$count + 1"/>
  614. </xsl:call-template>
  615. </xsl:otherwise>
  616. </xsl:choose>
  617. </xsl:otherwise>
  618. </xsl:choose>
  619. </xsl:template>
  620. <xsl:template name="process.footnotes.in.this.chunk">
  621. <xsl:param name="node" select="."/>
  622. <xsl:param name="footnotes" select="$node//footnote"/>
  623. <!--
  624. <xsl:message>process.footnotes.in.this.chunk</xsl:message>
  625. -->
  626. <xsl:variable name="in.other.chunk">
  627. <xsl:call-template name="in.other.chunk">
  628. <xsl:with-param name="chunk" select="$node"/>
  629. <xsl:with-param name="node" select="$footnotes[1]"/>
  630. </xsl:call-template>
  631. </xsl:variable>
  632. <xsl:choose>
  633. <xsl:when test="count($footnotes) = 0">
  634. <!-- nop -->
  635. </xsl:when>
  636. <xsl:otherwise>
  637. <xsl:choose>
  638. <xsl:when test="$in.other.chunk != 0">
  639. <xsl:call-template name="process.footnotes.in.this.chunk">
  640. <xsl:with-param name="node" select="$node"/>
  641. <xsl:with-param name="footnotes"
  642. select="$footnotes[position() &gt; 1]"/>
  643. </xsl:call-template>
  644. </xsl:when>
  645. <xsl:when test="$footnotes[1]/ancestor::table
  646. |$footnotes[1]/ancestor::informaltable">
  647. <xsl:call-template name="process.footnotes.in.this.chunk">
  648. <xsl:with-param name="node" select="$node"/>
  649. <xsl:with-param name="footnotes"
  650. select="$footnotes[position() &gt; 1]"/>
  651. </xsl:call-template>
  652. </xsl:when>
  653. <xsl:otherwise>
  654. <xsl:apply-templates select="$footnotes[1]"
  655. mode="process.footnote.mode"/>
  656. <xsl:call-template name="process.footnotes.in.this.chunk">
  657. <xsl:with-param name="node" select="$node"/>
  658. <xsl:with-param name="footnotes"
  659. select="$footnotes[position() &gt; 1]"/>
  660. </xsl:call-template>
  661. </xsl:otherwise>
  662. </xsl:choose>
  663. </xsl:otherwise>
  664. </xsl:choose>
  665. </xsl:template>
  666. <xsl:template name="process.footnotes">
  667. <xsl:variable name="footnotes" select=".//footnote"/>
  668. <xsl:variable name="fcount">
  669. <xsl:call-template name="count.footnotes.in.this.chunk">
  670. <xsl:with-param name="node" select="."/>
  671. <xsl:with-param name="footnotes" select="$footnotes"/>
  672. </xsl:call-template>
  673. </xsl:variable>
  674. <!--
  675. <xsl:message>
  676. <xsl:value-of select="name(.)"/>
  677. <xsl:text> fcount: </xsl:text>
  678. <xsl:value-of select="$fcount"/>
  679. </xsl:message>
  680. -->
  681. <!-- Only bother to do this if there's at least one non-table footnote -->
  682. <xsl:if test="$fcount &gt; 0">
  683. <div class="footnotes">
  684. <br/>
  685. <hr width="100" align="left"/>
  686. <xsl:call-template name="process.footnotes.in.this.chunk">
  687. <xsl:with-param name="node" select="."/>
  688. <xsl:with-param name="footnotes" select="$footnotes"/>
  689. </xsl:call-template>
  690. </div>
  691. </xsl:if>
  692. </xsl:template>
  693. <xsl:template name="process.chunk.footnotes">
  694. <xsl:variable name="is.chunk">
  695. <xsl:call-template name="chunk"/>
  696. </xsl:variable>
  697. <xsl:if test="$is.chunk = 1">
  698. <xsl:call-template name="process.footnotes"/>
  699. </xsl:if>
  700. </xsl:template>
  701. <!-- ==================================================================== -->
  702. </xsl:stylesheet>