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 6<xsl:output method="html" 7 encoding="ISO-8859-1" 8 indent="no"/> 9 10<xsl:param name="html.ext" select="'.html'"/> 11<doc:param name="html.ext" xmlns=""> 12<refpurpose>Extension for chunked files</refpurpose> 13<refdescription> 14<para>The extension identified by <parameter>html.ext</parameter> will 15be used as the filename extension for chunks created by this stylesheet. 16</para> 17</refdescription> 18</doc:param> 19 20<xsl:param name="root.filename" select="'index'"/> 21<doc:param name="root.filename" xmlns=""> 22<refpurpose>Filename for the root chunk</refpurpose> 23<refdescription> 24<para>The <parameter>root.filename</parameter> is the base filename for 25the chunk created for the root of each document processed. 26</para> 27</refdescription> 28</doc:param> 29 30<xsl:param name="base.dir" select="''"/> 31<doc:param name="base.dir" xmlns=""> 32<refpurpose>Output directory for chunks</refpurpose> 33<refdescription> 34<para>If specified, the <literal>base.dir</literal> identifies 35the output directory for chunks. (If not specified, the output directory 36is system dependent.)</para> 37</refdescription> 38</doc:param> 39 40<xsl:param name="chunk.sections" select="'1'"/> 41<doc:param name="chunk.sections" xmlns=""> 42<refpurpose>Create chunks for top-level sections in components?</refpurpose> 43<refdescription> 44<para>If non-zero, chunks will be created for top-level 45<sgmltag>sect1</sgmltag> and <sgmltag>section</sgmltag> elements in 46each component. 47</para> 48</refdescription> 49</doc:param> 50 51<xsl:param name="chunk.first.sections" select="'0'"/> 52<doc:param name="chunk.first.sections" xmlns=""> 53<refpurpose>Create a chunk for the first top-level section in each component?</refpurpose> 54<refdescription> 55<para>If non-zero, a chunk will be created for the first top-level 56<sgmltag>sect1</sgmltag> or <sgmltag>section</sgmltag> elements in 57each component. Otherwise, that section will be part of the chunk for 58its parent. 59</para> 60</refdescription> 61</doc:param> 62 63<!-- ==================================================================== --> 64<!-- What's a chunk? 65 66 appendix 67 article 68 bibliography in article or book 69 book 70 chapter 71 colophon 72 glossary in article or book 73 index in article or book 74 part 75 preface 76 refentry 77 reference 78 sect1 if position()>1 79 section if position()>1 && parent != section 80 set 81 setindex 82 --> 83<!-- ==================================================================== --> 84 85<xsl:template name="chunk"> 86 <xsl:param name="node" select="."/> 87 <!-- returns 1 if $node is a chunk --> 88 89<!-- 90 <xsl:message> 91 <xsl:text>chunk: </xsl:text> 92 <xsl:value-of select="name($node)"/> 93 <xsl:text>(</xsl:text> 94 <xsl:value-of select="$node/@id"/> 95 <xsl:text>)</xsl:text> 96 <xsl:text> cs: </xsl:text> 97 <xsl:value-of select="$chunk.sections"/> 98 <xsl:text> cfs: </xsl:text> 99 <xsl:value-of select="$chunk.first.sections"/> 100 <xsl:text> ps: </xsl:text> 101 <xsl:value-of select="count($node/parent::section)"/> 102 <xsl:text> prs: </xsl:text> 103 <xsl:value-of select="count($node/preceding-sibling::section)"/> 104 </xsl:message> 105--> 106 107 <xsl:choose> 108 <xsl:when test="$chunk.sections != 0 109 and name($node)='sect1' 110 and ($chunk.first.sections != 0 111 or count($node/preceding-sibling::sect1) > 0)"> 112 <xsl:text>1</xsl:text> 113 </xsl:when> 114 <xsl:when test="$chunk.sections != 0 115 and name($node)='section' 116 and ($chunk.first.sections != 0 117 or (count($node/parent::section) = 0 118 and count($node/preceding-sibling::section)))>0"> 119 <xsl:text>1</xsl:text> 120 </xsl:when> 121 <xsl:when test="name($node)='preface'">1</xsl:when> 122 <xsl:when test="name($node)='chapter'">1</xsl:when> 123 <xsl:when test="name($node)='appendix'">1</xsl:when> 124 <xsl:when test="name($node)='article'">1</xsl:when> 125 <xsl:when test="name($node)='part'">1</xsl:when> 126 <xsl:when test="name($node)='reference'">1</xsl:when> 127 <xsl:when test="name($node)='refentry'">1</xsl:when> 128 <xsl:when test="name($node)='index' 129 and (name($node/parent::*) = 'article' 130 or name($node/parent::*) = 'book')">1</xsl:when> 131 <xsl:when test="name($node)='bibliography' 132 and (name($node/parent::*) = 'article' 133 or name($node/parent::*) = 'book')">1</xsl:when> 134 <xsl:when test="name($node)='glossary' 135 and (name($node/parent::*) = 'article' 136 or name($node/parent::*) = 'book')">1</xsl:when> 137 <xsl:when test="name($node)='colophon'">1</xsl:when> 138 <xsl:when test="name($node)='book'">1</xsl:when> 139 <xsl:when test="name($node)='set'">1</xsl:when> 140 <xsl:when test="name($node)='setindex'">1</xsl:when> 141 <xsl:otherwise>0</xsl:otherwise> 142 </xsl:choose> 143</xsl:template> 144 145<!-- ==================================================================== --> 146 147<xsl:template match="*" mode="chunk-filename"> 148 <xsl:param name="recursive" select="false()"/> 149 150 <!-- returns the filename of a chunk --> 151 <xsl:variable name="ischunk"> 152 <xsl:call-template name="chunk"/> 153 </xsl:variable> 154 155 <xsl:variable name="dbhtml-filename"> 156 <xsl:call-template name="dbhtml-filename"/> 157 </xsl:variable> 158 159 <xsl:variable name="filename"> 160 <xsl:choose> 161 <xsl:when test="$dbhtml-filename != ''"> 162 <xsl:value-of select="$dbhtml-filename"/> 163 </xsl:when> 164 <!-- if there's no dbhtml filename, and if we're to use IDs as --> 165 <!-- filenames, *and* this isn't the root node, then use the ID --> 166 <!-- to generate the filename. --> 167 <xsl:when test="@id and $use.id.as.filename != 0 168 and . != /*"> 169 <xsl:value-of select="@id"/> 170 <xsl:value-of select="$html.ext"/> 171 </xsl:when> 172 <xsl:otherwise></xsl:otherwise> 173 </xsl:choose> 174 </xsl:variable> 175 176 <xsl:variable name="dir"> 177 <xsl:call-template name="dbhtml-dir"/> 178 </xsl:variable> 179 180 <xsl:choose> 181 <xsl:when test="$ischunk='0'"> 182 <!-- if called on something that isn't a chunk, walk up... --> 183 <xsl:choose> 184 <xsl:when test="count(parent::*)>0"> 185 <xsl:apply-templates mode="chunk-filename" select="parent::*"> 186 <xsl:with-param name="recursive" select="$recursive"/> 187 </xsl:apply-templates> 188 </xsl:when> 189 <!-- unless there is no up, in which case return "" --> 190 <xsl:otherwise></xsl:otherwise> 191 </xsl:choose> 192 </xsl:when> 193 194 <xsl:when test="not($recursive) and $filename != ''"> 195 <!-- if this chunk has an explicit name, use it --> 196 <xsl:if test="$dir != ''"> 197 <xsl:value-of select="$dir"/> 198 <xsl:text>/</xsl:text> 199 </xsl:if> 200 <xsl:value-of select="$filename"/> 201 </xsl:when> 202 203 <xsl:when test="name(.)='set'"> 204 <xsl:value-of select="$root.filename"/> 205 <xsl:if test="not($recursive)"> 206 <xsl:value-of select="$html.ext"/> 207 </xsl:if> 208 </xsl:when> 209 210 <xsl:when test="name(.)='book'"> 211 <xsl:choose> 212 <xsl:when test="count(parent::*)>0"> 213 <xsl:text>bk</xsl:text> 214 <xsl:number level="any" format="01"/> 215 </xsl:when> 216 <xsl:otherwise> 217 <xsl:value-of select="$root.filename"/> 218 </xsl:otherwise> 219 </xsl:choose> 220 <xsl:if test="not($recursive)"> 221 <xsl:value-of select="$html.ext"/> 222 </xsl:if> 223 </xsl:when> 224 225 <xsl:when test="name(.)='article'"> 226 <xsl:if test="/set"> 227 <!-- in a set, make sure we inherit the right book info... --> 228 <xsl:apply-templates mode="chunk-filename" select="parent::*"> 229 <xsl:with-param name="recursive" select="true()"/> 230 </xsl:apply-templates> 231 </xsl:if> 232 <xsl:choose> 233 <xsl:when test="count(parent::*)>0"> 234 <!-- if we aren't the root, name them numerically ... --> 235 <xsl:text>ar</xsl:text> 236 <xsl:number level="any" format="01" from="book"/> 237 </xsl:when> 238 <xsl:otherwise> 239 <xsl:value-of select="$root.filename"/> 240 </xsl:otherwise> 241 </xsl:choose> 242 <xsl:if test="not($recursive)"> 243 <xsl:value-of select="$html.ext"/> 244 </xsl:if> 245 </xsl:when> 246 247 <xsl:when test="name(.)='preface'"> 248 <xsl:if test="/set"> 249 <xsl:apply-templates mode="chunk-filename" select="parent::*"> 250 <xsl:with-param name="recursive" select="true()"/> 251 </xsl:apply-templates> 252 </xsl:if> 253 <xsl:text>pr</xsl:text> 254 <xsl:number level="any" format="01" from="book"/> 255 <xsl:if test="not($recursive)"> 256 <xsl:value-of select="$html.ext"/> 257 </xsl:if> 258 </xsl:when> 259 260 <xsl:when test="name(.)='chapter'"> 261 <xsl:if test="/set"> 262 <xsl:apply-templates mode="chunk-filename" select="parent::*"> 263 <xsl:with-param name="recursive" select="true()"/> 264 </xsl:apply-templates> 265 </xsl:if> 266 <xsl:text>ch</xsl:text> 267 <xsl:number level="any" format="01" from="book"/> 268 <xsl:if test="not($recursive)"> 269 <xsl:value-of select="$html.ext"/> 270 </xsl:if> 271 </xsl:when> 272 273 <xsl:when test="name(.)='appendix'"> 274 <xsl:if test="/set"> 275 <xsl:apply-templates mode="chunk-filename" select="parent::*"> 276 <xsl:with-param name="recursive" select="true()"/> 277 </xsl:apply-templates> 278 </xsl:if> 279 <xsl:text>ap</xsl:text> 280 <xsl:number level="any" format="a" from="book"/> 281 <xsl:if test="not($recursive)"> 282 <xsl:value-of select="$html.ext"/> 283 </xsl:if> 284 </xsl:when> 285 286 <xsl:when test="name(.)='part'"> 287 <xsl:if test="/set"> 288 <xsl:apply-templates mode="chunk-filename" select="parent::*"> 289 <xsl:with-param name="recursive" select="true()"/> 290 </xsl:apply-templates> 291 </xsl:if> 292 <xsl:text>pt</xsl:text> 293 <xsl:number level="any" format="01" from="book"/> 294 <xsl:if test="not($recursive)"> 295 <xsl:value-of select="$html.ext"/> 296 </xsl:if> 297 </xsl:when> 298 299 <xsl:when test="name(.)='reference'"> 300 <xsl:if test="/set"> 301 <xsl:apply-templates mode="chunk-filename" select="parent::*"> 302 <xsl:with-param name="recursive" select="true()"/> 303 </xsl:apply-templates> 304 </xsl:if> 305 <xsl:text>rn</xsl:text> 306 <xsl:number level="any" format="01" from="book"/> 307 <xsl:if test="not($recursive)"> 308 <xsl:value-of select="$html.ext"/> 309 </xsl:if> 310 </xsl:when> 311 312 <xsl:when test="name(.)='refentry'"> 313 <xsl:if test="parent::reference"> 314 <xsl:apply-templates mode="chunk-filename" select="parent::*"> 315 <xsl:with-param name="recursive" select="true()"/> 316 </xsl:apply-templates> 317 </xsl:if> 318 <xsl:text>re</xsl:text> 319 <xsl:number level="any" format="01" from="book"/> 320 <xsl:if test="not($recursive)"> 321 <xsl:value-of select="$html.ext"/> 322 </xsl:if> 323 </xsl:when> 324 325 <xsl:when test="name(.)='colophon'"> 326 <xsl:if test="/set"> 327 <xsl:apply-templates mode="chunk-filename" select="parent::*"> 328 <xsl:with-param name="recursive" select="true()"/> 329 </xsl:apply-templates> 330 </xsl:if> 331 <xsl:text>co</xsl:text> 332 <xsl:number level="any" format="01" from="book"/> 333 <xsl:if test="not($recursive)"> 334 <xsl:value-of select="$html.ext"/> 335 </xsl:if> 336 </xsl:when> 337 338 <xsl:when test="name(.)='sect1' or name(.)='section'"> 339 <xsl:apply-templates mode="chunk-filename" select="parent::*"> 340 <xsl:with-param name="recursive" select="true()"/> 341 </xsl:apply-templates> 342 <xsl:text>s</xsl:text> 343 <xsl:number level="any" format="01" from="preface|chapter|appendix"/> 344 <xsl:if test="not($recursive)"> 345 <xsl:value-of select="$html.ext"/> 346 </xsl:if> 347 </xsl:when> 348 349 <xsl:when test="name(.)='bibliography'"> 350 <xsl:if test="/set"> 351 <xsl:apply-templates mode="chunk-filename" select="parent::*"> 352 <xsl:with-param name="recursive" select="true()"/> 353 </xsl:apply-templates> 354 </xsl:if> 355 <xsl:text>bi</xsl:text> 356 <xsl:number level="any" format="01" from="book"/> 357 <xsl:if test="not($recursive)"> 358 <xsl:value-of select="$html.ext"/> 359 </xsl:if> 360 </xsl:when> 361 362 <xsl:when test="name(.)='glossary'"> 363 <xsl:if test="/set"> 364 <xsl:apply-templates mode="chunk-filename" select="parent::*"> 365 <xsl:with-param name="recursive" select="true()"/> 366 </xsl:apply-templates> 367 </xsl:if> 368 <xsl:text>go</xsl:text> 369 <xsl:number level="any" format="01" from="book"/> 370 <xsl:if test="not($recursive)"> 371 <xsl:value-of select="$html.ext"/> 372 </xsl:if> 373 </xsl:when> 374 375 <xsl:when test="name(.)='index'"> 376 <xsl:if test="/set"> 377 <xsl:apply-templates mode="chunk-filename" select="parent::*"> 378 <xsl:with-param name="recursive" select="true()"/> 379 </xsl:apply-templates> 380 </xsl:if> 381 <xsl:text>ix</xsl:text> 382 <xsl:number level="any" format="01" from="book"/> 383 <xsl:if test="not($recursive)"> 384 <xsl:value-of select="$html.ext"/> 385 </xsl:if> 386 </xsl:when> 387 388 <xsl:when test="name(.)='setindex'"> 389 <xsl:text>si</xsl:text> 390 <xsl:number level="any" format="01" from="set"/> 391 <xsl:if test="not($recursive)"> 392 <xsl:value-of select="$html.ext"/> 393 </xsl:if> 394 </xsl:when> 395 396 <xsl:otherwise> 397 <xsl:text>chunk-filename-error-</xsl:text> 398 <xsl:value-of select="name(.)"/> 399 <xsl:number level="any" format="01" from="set"/> 400 <xsl:if test="not($recursive)"> 401 <xsl:value-of select="$html.ext"/> 402 </xsl:if> 403 </xsl:otherwise> 404 </xsl:choose> 405</xsl:template> 406 407<!-- ==================================================================== --> 408 409<xsl:template name="href.target"> 410 <xsl:param name="object" select="."/> 411 <xsl:variable name="ischunk"> 412 <xsl:call-template name="chunk"> 413 <xsl:with-param name="node" select="$object"/> 414 </xsl:call-template> 415 </xsl:variable> 416 417 <xsl:apply-templates mode="chunk-filename" select="$object"/> 418 419 <xsl:if test="$ischunk='0'"> 420 <xsl:text>#</xsl:text> 421 <xsl:call-template name="object.id"> 422 <xsl:with-param name="object" select="$object"/> 423 </xsl:call-template> 424 </xsl:if> 425</xsl:template> 426 427<!-- ==================================================================== --> 428 429<xsl:template name="html.head"> 430 <xsl:param name="prev" select="/foo"/> 431 <xsl:param name="next" select="/foo"/> 432 <xsl:variable name="home" select="/*[1]"/> 433 <xsl:variable name="up" select="parent::*"/> 434 435 <head> 436 <xsl:call-template name="head.content"/> 437 <xsl:call-template name="user.head.content"/> 438 439 <xsl:if test="$home"> 440 <link rel="home"> 441 <xsl:attribute name="href"> 442 <xsl:call-template name="href.target"> 443 <xsl:with-param name="object" select="$home"/> 444 </xsl:call-template> 445 </xsl:attribute> 446 <xsl:attribute name="title"> 447 <xsl:apply-templates select="$home" 448 mode="object.title.markup.textonly"/> 449 </xsl:attribute> 450 </link> 451 </xsl:if> 452 453 <xsl:if test="$up"> 454 <link rel="up"> 455 <xsl:attribute name="href"> 456 <xsl:call-template name="href.target"> 457 <xsl:with-param name="object" select="$up"/> 458 </xsl:call-template> 459 </xsl:attribute> 460 <xsl:attribute name="title"> 461 <xsl:apply-templates select="$up" mode="object.title.markup.textonly"/> 462 </xsl:attribute> 463 </link> 464 </xsl:if> 465 466 <xsl:if test="$prev"> 467 <link rel="previous"> 468 <xsl:attribute name="href"> 469 <xsl:call-template name="href.target"> 470 <xsl:with-param name="object" select="$prev"/> 471 </xsl:call-template> 472 </xsl:attribute> 473 <xsl:attribute name="title"> 474 <xsl:apply-templates select="$prev" mode="object.title.markup.textonly"/> 475 </xsl:attribute> 476 </link> 477 </xsl:if> 478 479 <xsl:if test="$next"> 480 <link rel="next"> 481 <xsl:attribute name="href"> 482 <xsl:call-template name="href.target"> 483 <xsl:with-param name="object" select="$next"/> 484 </xsl:call-template> 485 </xsl:attribute> 486 <xsl:attribute name="title"> 487 <xsl:apply-templates select="$next" mode="object.title.markup.textonly"/> 488 </xsl:attribute> 489 </link> 490 </xsl:if> 491 </head> 492</xsl:template> 493 494<!-- ==================================================================== --> 495 496<xsl:template name="header.navigation"> 497 <xsl:param name="prev" select="/foo"/> 498 <xsl:param name="next" select="/foo"/> 499 <xsl:variable name="home" select="/*[1]"/> 500 <xsl:variable name="up" select="parent::*"/> 501 502 <xsl:if test="$suppress.navigation = '0'"> 503 <div class="navheader"> 504 <table width="100%" summary="Navigation header"> 505 <tr> 506 <th colspan="3" align="center"> 507 <xsl:apply-templates select="." mode="object.title.markup"/> 508 </th> 509 </tr> 510 <tr> 511 <td width="20%" align="left"> 512 <xsl:if test="count($prev)>0"> 513 <a> 514 <xsl:attribute name="href"> 515 <xsl:call-template name="href.target"> 516 <xsl:with-param name="object" select="$prev"/> 517 </xsl:call-template> 518 </xsl:attribute> 519 <xsl:call-template name="gentext"> 520 <xsl:with-param name="key">nav-prev</xsl:with-param> 521 </xsl:call-template> 522 </a> 523 </xsl:if> 524 <xsl:text> </xsl:text> 525 </td> 526 <th width="60%" align="center"> 527 <xsl:choose> 528 <xsl:when test="count($up) > 0 and $up != $home"> 529 <xsl:apply-templates select="$up" mode="object.title.markup"/> 530 </xsl:when> 531 <xsl:otherwise> </xsl:otherwise> 532 </xsl:choose> 533 </th> 534 <td width="20%" align="right"> 535 <xsl:text> </xsl:text> 536 <xsl:if test="count($next)>0"> 537 <a> 538 <xsl:attribute name="href"> 539 <xsl:call-template name="href.target"> 540 <xsl:with-param name="object" select="$next"/> 541 </xsl:call-template> 542 </xsl:attribute> 543 <xsl:call-template name="gentext"> 544 <xsl:with-param name="key">nav-next</xsl:with-param> 545 </xsl:call-template> 546 </a> 547 </xsl:if> 548 </td> 549 </tr> 550 </table> 551 <hr/> 552 </div> 553 </xsl:if> 554</xsl:template> 555 556<!-- ==================================================================== --> 557 558<xsl:template name="footer.navigation"> 559 <xsl:param name="prev" select="/foo"/> 560 <xsl:param name="next" select="/foo"/> 561 <xsl:variable name="home" select="/*[1]"/> 562 <xsl:variable name="up" select="parent::*"/> 563 564 <xsl:if test="$suppress.navigation = '0'"> 565 <div class="navfooter"> 566 <hr/> 567 <table width="100%" summary="Navigation footer"> 568 <tr> 569 <td width="40%" align="left"> 570 <xsl:if test="count($prev)>0"> 571 <a> 572 <xsl:attribute name="href"> 573 <xsl:call-template name="href.target"> 574 <xsl:with-param name="object" select="$prev"/> 575 </xsl:call-template> 576 </xsl:attribute> 577 <xsl:call-template name="gentext"> 578 <xsl:with-param name="key">nav-prev</xsl:with-param> 579 </xsl:call-template> 580 </a> 581 </xsl:if> 582 <xsl:text> </xsl:text> 583 </td> 584 <td width="20%" align="center"> 585 <xsl:choose> 586 <xsl:when test="$home != ."> 587 <a> 588 <xsl:attribute name="href"> 589 <xsl:call-template name="href.target"> 590 <xsl:with-param name="object" select="$home"/> 591 </xsl:call-template> 592 </xsl:attribute> 593 <xsl:call-template name="gentext"> 594 <xsl:with-param name="key">nav-home</xsl:with-param> 595 </xsl:call-template> 596 </a> 597 </xsl:when> 598 <xsl:otherwise> </xsl:otherwise> 599 </xsl:choose> 600 </td> 601 <td width="40%" align="right"> 602 <xsl:text> </xsl:text> 603 <xsl:if test="count($next)>0"> 604 <a> 605 <xsl:attribute name="href"> 606 <xsl:call-template name="href.target"> 607 <xsl:with-param name="object" select="$next"/> 608 </xsl:call-template> 609 </xsl:attribute> 610 <xsl:call-template name="gentext"> 611 <xsl:with-param name="key">nav-next</xsl:with-param> 612 </xsl:call-template> 613 </a> 614 </xsl:if> 615 </td> 616 </tr> 617 618 <tr> 619 <td width="40%" align="left"> 620 <xsl:apply-templates select="$prev" mode="object.title.markup"/> 621 <xsl:text> </xsl:text> 622 </td> 623 <td width="20%" align="center"> 624 <xsl:choose> 625 <xsl:when test="count($up)>0"> 626 <a> 627 <xsl:attribute name="href"> 628 <xsl:call-template name="href.target"> 629 <xsl:with-param name="object" select="$up"/> 630 </xsl:call-template> 631 </xsl:attribute> 632 <xsl:call-template name="gentext"> 633 <xsl:with-param name="key">nav-up</xsl:with-param> 634 </xsl:call-template> 635 </a> 636 </xsl:when> 637 <xsl:otherwise> </xsl:otherwise> 638 </xsl:choose> 639 </td> 640 <td width="40%" align="right"> 641 <xsl:text> </xsl:text> 642 <xsl:apply-templates select="$next" mode="object.title.markup"/> 643 </td> 644 </tr> 645 </table> 646 </div> 647 </xsl:if> 648</xsl:template> 649 650<!-- ==================================================================== --> 651 652<xsl:template match="processing-instruction('dbhtml')"> 653 <!-- nop --> 654</xsl:template> 655 656<!-- ==================================================================== --> 657 658<xsl:template name="process-chunk-element"> 659 <xsl:choose> 660 <xsl:when test="$chunk.sections = 0"> 661 <xsl:call-template name="chunk-no-sections"/> 662 </xsl:when> 663 <xsl:when test="$chunk.first.sections = 0"> 664 <xsl:call-template name="chunk-first-section-with-parent"/> 665 </xsl:when> 666 <xsl:otherwise> 667 <xsl:call-template name="chunk-all-top-level-sections"/> 668 </xsl:otherwise> 669 </xsl:choose> 670</xsl:template> 671 672<xsl:template name="process-chunk"> 673 <xsl:param name="prev" select="."/> 674 <xsl:param name="next" select="."/> 675 676 <xsl:variable name="ischunk"> 677 <xsl:call-template name="chunk"/> 678 </xsl:variable> 679 680 <xsl:variable name="chunkfn"> 681 <xsl:if test="$ischunk='1'"> 682 <xsl:apply-templates mode="chunk-filename" select="."/> 683 </xsl:if> 684 </xsl:variable> 685 686 <xsl:if test="$ischunk='0'"> 687 <xsl:message> 688 <xsl:text>Error </xsl:text> 689 <xsl:value-of select="name(.)"/> 690 <xsl:text> is not a chunk!</xsl:text> 691 </xsl:message> 692 </xsl:if> 693 694 <xsl:variable name="filename"> 695 <xsl:call-template name="make-relative-filename"> 696 <xsl:with-param name="base.dir" select="$base.dir"/> 697 <xsl:with-param name="base.name" select="$chunkfn"/> 698 </xsl:call-template> 699 </xsl:variable> 700 701 <xsl:call-template name="write.chunk"> 702 <xsl:with-param name="filename" select="$filename"/> 703 <xsl:with-param name="content"> 704 <xsl:call-template name="chunk-element-content"> 705 <xsl:with-param name="prev" select="$prev"/> 706 <xsl:with-param name="next" select="$next"/> 707 </xsl:call-template> 708 </xsl:with-param> 709 </xsl:call-template> 710</xsl:template> 711 712<xsl:template name="chunk-first-section-with-parent"> 713 <xsl:variable name="prev" 714 select="(preceding::book[1] 715 |preceding::preface[1] 716 |preceding::chapter[1] 717 |preceding::appendix[1] 718 |preceding::part[1] 719 |preceding::reference[1] 720 |preceding::refentry[1] 721 |preceding::colophon[1] 722 |preceding::sect1[name(preceding-sibling::*[1]) = 'sect1'][1] 723 |preceding::section[name(preceding-sibling::*[1]) = 'section' 724 and name(parent::*) != 'section'][1] 725 |preceding::article[1] 726 |preceding::bibliography[1] 727 |preceding::glossary[1] 728 |preceding::index[1] 729 |preceding::setindex[1] 730 |ancestor::set 731 |ancestor::book[1] 732 |ancestor::preface[1] 733 |ancestor::chapter[1] 734 |ancestor::appendix[1] 735 |ancestor::part[1] 736 |ancestor::reference[1] 737 |ancestor::article[1])[last()]"/> 738 739 <xsl:variable name="next" 740 select="(following::book[1] 741 |following::preface[1] 742 |following::chapter[1] 743 |following::appendix[1] 744 |following::part[1] 745 |following::reference[1] 746 |following::refentry[1] 747 |following::colophon[1] 748 |following::sect1[1] 749 |following::section[name(parent::*) != 'section'][1] 750 |following::bibliography[1] 751 |following::glossary[1] 752 |following::index[1] 753 |following::article[1] 754 |following::setindex[1] 755 |descendant::book[1] 756 |descendant::preface[1] 757 |descendant::chapter[1] 758 |descendant::appendix[1] 759 |descendant::article[1] 760 |descendant::bibliography[1] 761 |descendant::glossary[1] 762 |descendant::index[1] 763 |descendant::colophon[1] 764 |descendant::setindex[1] 765 |descendant::part[1] 766 |descendant::reference[1] 767 |descendant::refentry[1] 768 |descendant::sect1[2] 769 |descendant::section[name(parent::*) != 'section'][2])[1]"/> 770 771 <xsl:call-template name="process-chunk"> 772 <xsl:with-param name="prev" select="$prev"/> 773 <xsl:with-param name="next" select="$next"/> 774 </xsl:call-template> 775</xsl:template> 776 777<xsl:template name="chunk-all-top-level-sections"> 778 <xsl:variable name="prev" 779 select="(preceding::book[1] 780 |preceding::preface[1] 781 |preceding::chapter[1] 782 |preceding::appendix[1] 783 |preceding::part[1] 784 |preceding::reference[1] 785 |preceding::refentry[1] 786 |preceding::colophon[1] 787 |preceding::sect1[1] 788 |preceding::section[name(parent::*) != 'section'][1] 789 |preceding::article[1] 790 |preceding::bibliography[1] 791 |preceding::glossary[1] 792 |preceding::index[1] 793 |preceding::setindex[1] 794 |ancestor::set 795 |ancestor::book[1] 796 |ancestor::preface[1] 797 |ancestor::chapter[1] 798 |ancestor::appendix[1] 799 |ancestor::part[1] 800 |ancestor::reference[1] 801 |ancestor::article[1])[last()]"/> 802 803 <xsl:variable name="next" 804 select="(following::book[1] 805 |following::preface[1] 806 |following::chapter[1] 807 |following::appendix[1] 808 |following::part[1] 809 |following::reference[1] 810 |following::refentry[1] 811 |following::colophon[1] 812 |following::sect1[1] 813 |following::section[name(parent::*) != 'section'][1] 814 |following::bibliography[1] 815 |following::glossary[1] 816 |following::index[1] 817 |following::article[1] 818 |following::setindex[1] 819 |descendant::book[1] 820 |descendant::preface[1] 821 |descendant::chapter[1] 822 |descendant::appendix[1] 823 |descendant::article[1] 824 |descendant::bibliography[1] 825 |descendant::glossary[1] 826 |descendant::index[1] 827 |descendant::colophon[1] 828 |descendant::setindex[1] 829 |descendant::part[1] 830 |descendant::reference[1] 831 |descendant::refentry[1] 832 |descendant::sect1[1] 833 |descendant::section[name(parent::*) != 'section'][1])[1]"/> 834 835 <xsl:call-template name="process-chunk"> 836 <xsl:with-param name="prev" select="$prev"/> 837 <xsl:with-param name="next" select="$next"/> 838 </xsl:call-template> 839</xsl:template> 840 841<xsl:template name="chunk-no-sections"> 842 <xsl:variable name="prev" 843 select="(preceding::book[1] 844 |preceding::preface[1] 845 |preceding::chapter[1] 846 |preceding::appendix[1] 847 |preceding::part[1] 848 |preceding::reference[1] 849 |preceding::refentry[1] 850 |preceding::colophon[1] 851 |preceding::article[1] 852 |preceding::bibliography[1] 853 |preceding::glossary[1] 854 |preceding::index[1] 855 |preceding::setindex[1] 856 |ancestor::set 857 |ancestor::book[1] 858 |ancestor::preface[1] 859 |ancestor::chapter[1] 860 |ancestor::appendix[1] 861 |ancestor::part[1] 862 |ancestor::reference[1] 863 |ancestor::article[1])[last()]"/> 864 865 <xsl:variable name="next" 866 select="(following::book[1] 867 |following::preface[1] 868 |following::chapter[1] 869 |following::appendix[1] 870 |following::part[1] 871 |following::reference[1] 872 |following::refentry[1] 873 |following::colophon[1] 874 |following::bibliography[1] 875 |following::glossary[1] 876 |following::index[1] 877 |following::article[1] 878 |following::setindex[1] 879 |descendant::book[1] 880 |descendant::preface[1] 881 |descendant::chapter[1] 882 |descendant::appendix[1] 883 |descendant::article[1] 884 |descendant::bibliography[1] 885 |descendant::glossary[1] 886 |descendant::index[1] 887 |descendant::colophon[1] 888 |descendant::setindex[1] 889 |descendant::part[1] 890 |descendant::reference[1] 891 |descendant::refentry[1])[1]"/> 892 893 <xsl:call-template name="process-chunk"> 894 <xsl:with-param name="prev" select="$prev"/> 895 <xsl:with-param name="next" select="$next"/> 896 </xsl:call-template> 897</xsl:template> 898 899<!-- ==================================================================== --> 900 901<xsl:template name="chunk-element-content"> 902 <xsl:param name="prev"></xsl:param> 903 <xsl:param name="next"></xsl:param> 904 905 <html> 906 <xsl:call-template name="html.head"> 907 <xsl:with-param name="prev" select="$prev"/> 908 <xsl:with-param name="next" select="$next"/> 909 </xsl:call-template> 910 911 <body xsl:use-attribute-sets="body.attrs"> 912 <xsl:call-template name="user.header.navigation"/> 913 914 <xsl:call-template name="header.navigation"> 915 <xsl:with-param name="prev" select="$prev"/> 916 <xsl:with-param name="next" select="$next"/> 917 </xsl:call-template> 918 919 <xsl:call-template name="user.header.content"/> 920 921 <xsl:apply-imports/> 922 923 <xsl:call-template name="user.footer.content"/> 924 925 <xsl:call-template name="footer.navigation"> 926 <xsl:with-param name="prev" select="$prev"/> 927 <xsl:with-param name="next" select="$next"/> 928 </xsl:call-template> 929 930 <xsl:call-template name="user.footer.navigation"/> 931 </body> 932 </html> 933</xsl:template> 934 935<!-- ==================================================================== --> 936 937<xsl:template match="/"> 938 <xsl:choose> 939 <xsl:when test="$rootid != ''"> 940 <xsl:choose> 941 <xsl:when test="count(id($rootid)) = 0"> 942 <xsl:message terminate="yes"> 943 <xsl:text>ID '</xsl:text> 944 <xsl:value-of select="$rootid"/> 945 <xsl:text>' not found in document.</xsl:text> 946 </xsl:message> 947 </xsl:when> 948 <xsl:otherwise> 949 <xsl:apply-templates select="id($rootid)"/> 950 </xsl:otherwise> 951 </xsl:choose> 952 </xsl:when> 953 <xsl:otherwise> 954 <xsl:apply-templates select="/" mode="process.root"/> 955 </xsl:otherwise> 956 </xsl:choose> 957</xsl:template> 958 959<xsl:template match="*" mode="process.root"> 960 <xsl:apply-templates select="."/> 961</xsl:template> 962 963<xsl:template match="set|book|part|preface|chapter|appendix 964 |article 965 |reference|refentry 966 |book/glossary|article/glossary 967 |book/bibliography|article/bibliography 968 |colophon"> 969 <xsl:call-template name="process-chunk-element"/> 970</xsl:template> 971 972<xsl:template match="sect1|section[local-name(parent::*) != 'section']"> 973<!-- 974 <xsl:message> 975 <xsl:text>cs: </xsl:text> 976 <xsl:value-of select="$chunk.sections"/> 977 <xsl:text> cfs: </xsl:text> 978 <xsl:value-of select="$chunk.first.sections"/> 979 <xsl:text> pos: </xsl:text> 980 <xsl:value-of select="position()"/> 981 </xsl:message> 982--> 983 984 <xsl:choose> 985 <xsl:when test="$chunk.sections = 0"> 986 <xsl:apply-imports/> 987 </xsl:when> 988 <xsl:when test="$chunk.first.sections = 0"> 989 <xsl:choose> 990 <xsl:when test="count(preceding-sibling::section) > 0 991 or count(preceding-sibling::sect1) > 0"> 992 <xsl:call-template name="process-chunk-element"/> 993 </xsl:when> 994 <xsl:otherwise> 995 <xsl:apply-imports/> 996 </xsl:otherwise> 997 </xsl:choose> 998 </xsl:when> 999 <xsl:otherwise> 1000 <xsl:call-template name="process-chunk-element"/> 1001 </xsl:otherwise> 1002 </xsl:choose> 1003</xsl:template> 1004 1005<xsl:template match="setindex 1006 |book/index 1007 |article/index"> 1008 <!-- some implementations use completely empty index tags to indicate --> 1009 <!-- where an automatically generated index should be inserted. so --> 1010 <!-- if the index is completely empty, skip it. --> 1011 <xsl:if test="count(*)>0 or $generate.index != '0'"> 1012 <xsl:call-template name="process-chunk-element"/> 1013 </xsl:if> 1014</xsl:template> 1015 1016<!-- ==================================================================== --> 1017 1018<xsl:template name="in.other.chunk"> 1019 <xsl:param name="chunk" select="."/> 1020 <xsl:param name="node" select="."/> 1021 1022 <xsl:variable name="is.chunk"> 1023 <xsl:call-template name="chunk"> 1024 <xsl:with-param name="node" select="$node"/> 1025 </xsl:call-template> 1026 </xsl:variable> 1027 1028<!-- 1029 <xsl:message> 1030 <xsl:text>in.other.chunk: </xsl:text> 1031 <xsl:value-of select="name($chunk)"/> 1032 <xsl:text> </xsl:text> 1033 <xsl:value-of select="name($node)"/> 1034 <xsl:text> </xsl:text> 1035 <xsl:value-of select="$chunk = $node"/> 1036 <xsl:text> </xsl:text> 1037 <xsl:value-of select="$is.chunk"/> 1038 </xsl:message> 1039--> 1040 1041 <xsl:choose> 1042 <xsl:when test="$chunk = $node">0</xsl:when> 1043 <xsl:when test="$is.chunk = 1">1</xsl:when> 1044 <xsl:when test="count($node) = 0">0</xsl:when> 1045 <xsl:otherwise> 1046 <xsl:call-template name="in.other.chunk"> 1047 <xsl:with-param name="chunk" select="$chunk"/> 1048 <xsl:with-param name="node" select="$node/parent::*"/> 1049 </xsl:call-template> 1050 </xsl:otherwise> 1051 </xsl:choose> 1052</xsl:template> 1053 1054<xsl:template name="count.footnotes.in.this.chunk"> 1055 <xsl:param name="node" select="."/> 1056 <xsl:param name="footnotes" select="$node//footnote"/> 1057 <xsl:param name="count" select="0"/> 1058 1059<!-- 1060 <xsl:message> 1061 <xsl:text>count.footnotes.in.this.chunk: </xsl:text> 1062 <xsl:value-of select="name($node)"/> 1063 </xsl:message> 1064--> 1065 1066 <xsl:variable name="in.other.chunk"> 1067 <xsl:call-template name="in.other.chunk"> 1068 <xsl:with-param name="chunk" select="$node"/> 1069 <xsl:with-param name="node" select="$footnotes[1]"/> 1070 </xsl:call-template> 1071 </xsl:variable> 1072 1073 <xsl:choose> 1074 <xsl:when test="count($footnotes) = 0"> 1075 <xsl:value-of select="$count"/> 1076 </xsl:when> 1077 <xsl:otherwise> 1078 <xsl:choose> 1079 <xsl:when test="$in.other.chunk != 0"> 1080 <xsl:call-template name="count.footnotes.in.this.chunk"> 1081 <xsl:with-param name="node" select="$node"/> 1082 <xsl:with-param name="footnotes" 1083 select="$footnotes[position() > 1]"/> 1084 <xsl:with-param name="count" select="$count"/> 1085 </xsl:call-template> 1086 </xsl:when> 1087 <xsl:when test="$footnotes[1]/ancestor::table 1088 |$footnotes[1]/ancestor::informaltable"> 1089 <xsl:call-template name="count.footnotes.in.this.chunk"> 1090 <xsl:with-param name="node" select="$node"/> 1091 <xsl:with-param name="footnotes" 1092 select="$footnotes[position() > 1]"/> 1093 <xsl:with-param name="count" select="$count"/> 1094 </xsl:call-template> 1095 </xsl:when> 1096 <xsl:otherwise> 1097 <xsl:call-template name="count.footnotes.in.this.chunk"> 1098 <xsl:with-param name="node" select="$node"/> 1099 <xsl:with-param name="footnotes" 1100 select="$footnotes[position() > 1]"/> 1101 <xsl:with-param name="count" select="$count + 1"/> 1102 </xsl:call-template> 1103 </xsl:otherwise> 1104 </xsl:choose> 1105 </xsl:otherwise> 1106 </xsl:choose> 1107</xsl:template> 1108 1109<xsl:template name="process.footnotes.in.this.chunk"> 1110 <xsl:param name="node" select="."/> 1111 <xsl:param name="footnotes" select="$node//footnote"/> 1112 1113<!-- 1114 <xsl:message>process.footnotes.in.this.chunk</xsl:message> 1115--> 1116 1117 <xsl:variable name="in.other.chunk"> 1118 <xsl:call-template name="in.other.chunk"> 1119 <xsl:with-param name="chunk" select="$node"/> 1120 <xsl:with-param name="node" select="$footnotes[1]"/> 1121 </xsl:call-template> 1122 </xsl:variable> 1123 1124 <xsl:choose> 1125 <xsl:when test="count($footnotes) = 0"> 1126 <!-- nop --> 1127 </xsl:when> 1128 <xsl:otherwise> 1129 <xsl:choose> 1130 <xsl:when test="$in.other.chunk != 0"> 1131 <xsl:call-template name="process.footnotes.in.this.chunk"> 1132 <xsl:with-param name="node" select="$node"/> 1133 <xsl:with-param name="footnotes" 1134 select="$footnotes[position() > 1]"/> 1135 </xsl:call-template> 1136 </xsl:when> 1137 <xsl:when test="$footnotes[1]/ancestor::table 1138 |$footnotes[1]/ancestor::informaltable"> 1139 <xsl:call-template name="process.footnotes.in.this.chunk"> 1140 <xsl:with-param name="node" select="$node"/> 1141 <xsl:with-param name="footnotes" 1142 select="$footnotes[position() > 1]"/> 1143 </xsl:call-template> 1144 </xsl:when> 1145 <xsl:otherwise> 1146 <xsl:apply-templates select="$footnotes[1]" 1147 mode="process.footnote.mode"/> 1148 <xsl:call-template name="process.footnotes.in.this.chunk"> 1149 <xsl:with-param name="node" select="$node"/> 1150 <xsl:with-param name="footnotes" 1151 select="$footnotes[position() > 1]"/> 1152 </xsl:call-template> 1153 </xsl:otherwise> 1154 </xsl:choose> 1155 </xsl:otherwise> 1156 </xsl:choose> 1157</xsl:template> 1158 1159<xsl:template name="process.footnotes"> 1160 <xsl:variable name="footnotes" select=".//footnote"/> 1161 <xsl:variable name="fcount"> 1162 <xsl:call-template name="count.footnotes.in.this.chunk"> 1163 <xsl:with-param name="node" select="."/> 1164 <xsl:with-param name="footnotes" select="$footnotes"/> 1165 </xsl:call-template> 1166 </xsl:variable> 1167 1168<!-- 1169 <xsl:message> 1170 <xsl:value-of select="name(.)"/> 1171 <xsl:text> fcount: </xsl:text> 1172 <xsl:value-of select="$fcount"/> 1173 </xsl:message> 1174--> 1175 1176 <!-- Only bother to do this if there's at least one non-table footnote --> 1177 <xsl:if test="$fcount > 0"> 1178 <div class="footnotes"> 1179 <br/> 1180 <hr width="100" align="left"/> 1181 <xsl:call-template name="process.footnotes.in.this.chunk"> 1182 <xsl:with-param name="node" select="."/> 1183 <xsl:with-param name="footnotes" select="$footnotes"/> 1184 </xsl:call-template> 1185 </div> 1186 </xsl:if> 1187</xsl:template> 1188 1189<xsl:template name="process.chunk.footnotes"> 1190 <xsl:variable name="is.chunk"> 1191 <xsl:call-template name="chunk"/> 1192 </xsl:variable> 1193 <xsl:if test="$is.chunk = 1"> 1194 <xsl:call-template name="process.footnotes"/> 1195 </xsl:if> 1196</xsl:template> 1197 1198<!-- ==================================================================== --> 1199 1200</xsl:stylesheet> 1201