1<?xml version='1.0'?> 2<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 3 version='1.0' 4 xmlns="http://www.w3.org/TR/xhtml1/transitional" 5 exclude-result-prefixes="#default"> 6 7<!-- ***************************Chunking***********************--> 8 9<!-- ***************************Variables**********************--> 10<xsl:param name="local.l10n.xml" select="document('l10n.xml')"/> 11 12<!-- ***************************Templates**********************--> 13 14<xsl:template name="chunk"> 15 <xsl:param name="node" select="."/> 16 <!-- returns 1 if $node is a chunk --> 17 18 <!-- ==================================================================== --> 19 <!-- What's a chunk? 20 21 The root element 22 appendix 23 article 24 bibliography in article or part or book 25 book 26 chapter 27 colophon 28 glossary in article or part or book 29 index in article or part or book 30 part 31 preface 32 refentry 33 reference 34 sect{1,2,3,4,5} if position()>1 && depth < chunk.section.depth 35 section if position()>1 && depth < chunk.section.depth 36 set 37 setindex 38 --> 39 <!-- ==================================================================== --> 40 41<!-- 42 <xsl:message> 43 <xsl:text>chunk: </xsl:text> 44 <xsl:value-of select="name($node)"/> 45 <xsl:text>(</xsl:text> 46 <xsl:value-of select="$node/@id"/> 47 <xsl:text>)</xsl:text> 48 <xsl:text> csd: </xsl:text> 49 <xsl:value-of select="$chunk.section.depth"/> 50 <xsl:text> cfs: </xsl:text> 51 <xsl:value-of select="$chunk.first.sections"/> 52 <xsl:text> ps: </xsl:text> 53 <xsl:value-of select="count($node/parent::section)"/> 54 <xsl:text> prs: </xsl:text> 55 <xsl:value-of select="count($node/preceding-sibling::section)"/> 56 </xsl:message> 57--> 58 59 <xsl:choose> 60 <xsl:when test="$node/parent::*/processing-instruction('dbhtml')[normalize-space(.) = 'stop-chunking']">0</xsl:when> 61 <xsl:when test="not($node/parent::*)">1</xsl:when> 62 63 <xsl:when test="local-name($node) = 'sect1' 64 and $chunk.section.depth >= 1 65 and ($chunk.first.sections != 0 66 or count($node/preceding-sibling::sect1) > 0)"> 67 <xsl:text>1</xsl:text> 68 </xsl:when> 69 <xsl:when test="local-name($node) = 'sect2' 70 and $chunk.section.depth >= 2 71 and ($chunk.first.sections != 0 72 or count($node/preceding-sibling::sect2) > 0)"> 73 <xsl:call-template name="chunk"> 74 <xsl:with-param name="node" select="$node/parent::*"/> 75 </xsl:call-template> 76 </xsl:when> 77 <xsl:when test="local-name($node) = 'sect3' 78 and $chunk.section.depth >= 3 79 and ($chunk.first.sections != 0 80 or count($node/preceding-sibling::sect3) > 0)"> 81 <xsl:call-template name="chunk"> 82 <xsl:with-param name="node" select="$node/parent::*"/> 83 </xsl:call-template> 84 </xsl:when> 85 <xsl:when test="local-name($node) = 'sect4' 86 and $chunk.section.depth >= 4 87 and ($chunk.first.sections != 0 88 or count($node/preceding-sibling::sect4) > 0)"> 89 <xsl:call-template name="chunk"> 90 <xsl:with-param name="node" select="$node/parent::*"/> 91 </xsl:call-template> 92 </xsl:when> 93 <xsl:when test="local-name($node) = 'sect5' 94 and $chunk.section.depth >= 5 95 and ($chunk.first.sections != 0 96 or count($node/preceding-sibling::sect5) > 0)"> 97 <xsl:call-template name="chunk"> 98 <xsl:with-param name="node" select="$node/parent::*"/> 99 </xsl:call-template> 100 </xsl:when> 101 <xsl:when test="local-name($node) = 'section' 102 and $chunk.section.depth >= count($node/ancestor::section)+1 103 and ($chunk.first.sections != 0 104 or count($node/preceding-sibling::section) > 0)"> 105 <xsl:call-template name="chunk"> 106 <xsl:with-param name="node" select="$node/parent::*"/> 107 </xsl:call-template> 108 </xsl:when> 109 110 <xsl:when test="local-name($node)='preface'">1</xsl:when> 111 <xsl:when test="local-name($node)='chapter'">1</xsl:when> 112 <xsl:when test="local-name($node)='appendix'">1</xsl:when> 113 <xsl:when test="local-name($node)='article'">1</xsl:when> 114 <xsl:when test="local-name($node)='part'">1</xsl:when> 115 <xsl:when test="local-name($node)='reference'">1</xsl:when> 116 <xsl:when test="local-name($node)='refentry'">1</xsl:when> 117 <xsl:when test="local-name($node)='index' and ($generate.index != 0 or count($node/*) > 0) 118 and (local-name($node/parent::*) = 'article' 119 or local-name($node/parent::*) = 'book' 120 or local-name($node/parent::*) = 'part' 121 )">1</xsl:when> 122 <xsl:when test="local-name($node)='bibliography' 123 and (local-name($node/parent::*) = 'article' 124 or local-name($node/parent::*) = 'book' 125 or local-name($node/parent::*) = 'part' 126 )">1</xsl:when> 127 <xsl:when test="local-name($node)='glossary' 128 and (local-name($node/parent::*) = 'article' 129 or local-name($node/parent::*) = 'book' 130 or local-name($node/parent::*) = 'part' 131 )">1</xsl:when> 132 <xsl:when test="local-name($node)='colophon'">1</xsl:when> 133 <xsl:when test="local-name($node)='book'">1</xsl:when> 134 <xsl:when test="local-name($node)='set'">1</xsl:when> 135 <xsl:when test="local-name($node)='setindex'">1</xsl:when> 136 <xsl:when test="local-name($node)='legalnotice' 137 and $generate.legalnotice.link != 0">1</xsl:when> 138 <xsl:when test="name($node)='bookinfo'">1</xsl:when> 139 <xsl:when test="name($node)='articleinfo'">1</xsl:when> 140 <xsl:otherwise>0</xsl:otherwise> 141 </xsl:choose> 142</xsl:template> 143 144<xsl:template name="chunk-all-top-level-sections"> 145 <xsl:variable name="prev" 146 select="(articleinfo[1] 147 |bookinfo[1] 148 |preceding::book[1] 149 |preceding::preface[1] 150 |preceding::chapter[1] 151 |preceding::appendix[1] 152 |preceding::part[1] 153 |preceding::reference[1] 154 |preceding::refentry[1] 155 |preceding::colophon[1] 156 |preceding::sect1[1] 157 |preceding::section[name(parent::*) != 'section'][1] 158 |preceding::article[1] 159 |preceding::bibliography[1] 160 |preceding::glossary[1] 161 |preceding::index[1] 162 |preceding::setindex[1] 163 |ancestor::set 164 |ancestor::book[1] 165 |ancestor::preface[1] 166 |ancestor::chapter[1] 167 |ancestor::appendix[1] 168 |ancestor::part[1] 169 |ancestor::reference[1] 170 |ancestor::article[1])[last()]"/> 171 172 <xsl:variable name="next" 173 select="(following::book[1] 174 |following::preface[1] 175 |following::chapter[1] 176 |following::appendix[1] 177 |following::part[1] 178 |following::reference[1] 179 |following::refentry[1] 180 |following::colophon[1] 181 |following::sect1[1] 182 |following::section[name(parent::*) != 'section'][1] 183 |following::bibliography[1] 184 |following::glossary[1] 185 |following::index[1] 186 |following::article[1] 187 |following::setindex[1] 188 |descendant::book[1] 189 |descendant::preface[1] 190 |descendant::chapter[1] 191 |descendant::appendix[1] 192 |descendant::article[1] 193 |descendant::bibliography[1] 194 |descendant::glossary[1] 195 |descendant::index[1] 196 |descendant::colophon[1] 197 |descendant::setindex[1] 198 |descendant::part[1] 199 |descendant::reference[1] 200 |descendant::refentry[1] 201 |descendant::sect1[1] 202 |descendant::section[name(parent::*) != 'section'][1])[1]"/> 203 204 <xsl:call-template name="process-chunk"> 205 <xsl:with-param name="prev" select="$prev"/> 206 <xsl:with-param name="next" select="$next"/> 207 </xsl:call-template> 208</xsl:template> 209 210<xsl:template match="*" mode="chunk-filename"> 211 <xsl:param name="recursive" select="false()"/> 212 213 <!-- returns the filename of a chunk --> 214 <xsl:variable name="ischunk"> 215 <xsl:call-template name="chunk"/> 216 </xsl:variable> 217 218 <xsl:variable name="dbhtml_filename"> 219 <xsl:call-template name="pi.dbhtml_filename"/> 220 </xsl:variable> 221 222 <xsl:variable name="filename"> 223 <xsl:choose> 224 <xsl:when test="$dbhtml_filename != ''"> 225 <xsl:value-of select="$dbhtml_filename"/> 226 </xsl:when> 227 <!-- if there's no dbhtml filename, and if we're to use IDs as --> 228 <!-- filenames, then use the ID to generate the filename. --> 229 <xsl:when test="@id and $use.id.as.filename != 0"> 230 <xsl:value-of select="@id"/> 231 <xsl:value-of select="$html.ext"/> 232 </xsl:when> 233 <!-- if this is the root element, use the root.filename --> 234 <xsl:when test="not(parent::*)"> 235 <xsl:value-of select="$root.filename"/> 236 <xsl:value-of select="$html.ext"/> 237 </xsl:when> 238 <xsl:otherwise></xsl:otherwise> 239 </xsl:choose> 240 </xsl:variable> 241 242 <xsl:variable name="dir"> 243 <xsl:call-template name="pi.dbhtml_dir"/> 244 </xsl:variable> 245 246 <xsl:choose> 247 <xsl:when test="$ischunk='0'"> 248 <!-- if called on something that isn't a chunk, walk up... --> 249 <xsl:choose> 250 <xsl:when test="count(parent::*)>0"> 251 <xsl:apply-templates mode="chunk-filename" select="parent::*"> 252 <xsl:with-param name="recursive" select="$recursive"/> 253 </xsl:apply-templates> 254 </xsl:when> 255 <!-- unless there is no up, in which case return "" --> 256 <xsl:otherwise></xsl:otherwise> 257 </xsl:choose> 258 </xsl:when> 259 260 <xsl:when test="not($recursive) and $filename != ''"> 261 <!-- if this chunk has an explicit name, use it --> 262 <xsl:if test="$dir != ''"> 263 <xsl:value-of select="$dir"/> 264 <xsl:text>/</xsl:text> 265 </xsl:if> 266 <xsl:value-of select="$filename"/> 267 </xsl:when> 268 269 <xsl:when test="name(.)='set'"> 270 <xsl:value-of select="$root.filename"/> 271 <xsl:if test="not($recursive)"> 272 <xsl:value-of select="$html.ext"/> 273 </xsl:if> 274 </xsl:when> 275 276 <xsl:when test="name(.)='bookinfo'"> 277 <xsl:text>titlepage</xsl:text> 278 <xsl:if test="not($recursive)"> 279 <xsl:value-of select="$html.ext"/> 280 </xsl:if> 281 </xsl:when> 282 283 <xsl:when test="name(.)='articleinfo'"> 284 <xsl:text>titlepage</xsl:text> 285 <xsl:if test="not($recursive)"> 286 <xsl:value-of select="$html.ext"/> 287 </xsl:if> 288 </xsl:when> 289 290 <xsl:when test="name(.)='book'"> 291 <xsl:text>bk</xsl:text> 292 <xsl:number level="any" format="01"/> 293 <xsl:if test="not($recursive)"> 294 <xsl:value-of select="$html.ext"/> 295 </xsl:if> 296 </xsl:when> 297 298 <xsl:when test="name(.)='article'"> 299 <xsl:if test="/set"> 300 <!-- in a set, make sure we inherit the right book info... --> 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>ar</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(.)='preface'"> 313 <xsl:if test="/set"> 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>pr</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(.)='chapter'"> 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>ch</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(.)='appendix'"> 339 <xsl:if test="/set"> 340 <xsl:apply-templates mode="chunk-filename" select="parent::*"> 341 <xsl:with-param name="recursive" select="true()"/> 342 </xsl:apply-templates> 343 </xsl:if> 344 <xsl:text>ap</xsl:text> 345 <xsl:number level="any" format="a" from="book"/> 346 <xsl:if test="not($recursive)"> 347 <xsl:value-of select="$html.ext"/> 348 </xsl:if> 349 </xsl:when> 350 351 <xsl:when test="name(.)='part'"> 352 <xsl:if test="/set"> 353 <xsl:apply-templates mode="chunk-filename" select="parent::*"> 354 <xsl:with-param name="recursive" select="true()"/> 355 </xsl:apply-templates> 356 </xsl:if> 357 <xsl:text>pt</xsl:text> 358 <xsl:number level="any" format="01" from="book"/> 359 <xsl:if test="not($recursive)"> 360 <xsl:value-of select="$html.ext"/> 361 </xsl:if> 362 </xsl:when> 363 364 <xsl:when test="name(.)='reference'"> 365 <xsl:if test="/set"> 366 <xsl:apply-templates mode="chunk-filename" select="parent::*"> 367 <xsl:with-param name="recursive" select="true()"/> 368 </xsl:apply-templates> 369 </xsl:if> 370 <xsl:text>rn</xsl:text> 371 <xsl:number level="any" format="01" from="book"/> 372 <xsl:if test="not($recursive)"> 373 <xsl:value-of select="$html.ext"/> 374 </xsl:if> 375 </xsl:when> 376 377 <xsl:when test="name(.)='refentry'"> 378 <xsl:if test="parent::reference"> 379 <xsl:apply-templates mode="chunk-filename" select="parent::*"> 380 <xsl:with-param name="recursive" select="true()"/> 381 </xsl:apply-templates> 382 </xsl:if> 383 <xsl:text>re</xsl:text> 384 <xsl:number level="any" format="01" from="book"/> 385 <xsl:if test="not($recursive)"> 386 <xsl:value-of select="$html.ext"/> 387 </xsl:if> 388 </xsl:when> 389 390 <xsl:when test="name(.)='colophon'"> 391 <xsl:if test="/set"> 392 <xsl:apply-templates mode="chunk-filename" select="parent::*"> 393 <xsl:with-param name="recursive" select="true()"/> 394 </xsl:apply-templates> 395 </xsl:if> 396 <xsl:text>co</xsl:text> 397 <xsl:number level="any" format="01" from="book"/> 398 <xsl:if test="not($recursive)"> 399 <xsl:value-of select="$html.ext"/> 400 </xsl:if> 401 </xsl:when> 402 403 <xsl:when test="name(.)='sect1' or name(.)='section'"> 404 <xsl:apply-templates mode="chunk-filename" select="parent::*"> 405 <xsl:with-param name="recursive" select="true()"/> 406 </xsl:apply-templates> 407 <xsl:text>s</xsl:text> 408 <xsl:number level="any" format="01" from="preface|chapter|appendix"/> 409 <xsl:if test="not($recursive)"> 410 <xsl:value-of select="$html.ext"/> 411 </xsl:if> 412 </xsl:when> 413 414 <xsl:when test="name(.)='bibliography'"> 415 <xsl:if test="/set"> 416 <xsl:apply-templates mode="chunk-filename" select="parent::*"> 417 <xsl:with-param name="recursive" select="true()"/> 418 </xsl:apply-templates> 419 </xsl:if> 420 <xsl:text>bi</xsl:text> 421 <xsl:number level="any" format="01" from="book"/> 422 <xsl:if test="not($recursive)"> 423 <xsl:value-of select="$html.ext"/> 424 </xsl:if> 425 </xsl:when> 426 427 <xsl:when test="name(.)='glossary'"> 428 <xsl:if test="/set"> 429 <xsl:apply-templates mode="chunk-filename" select="parent::*"> 430 <xsl:with-param name="recursive" select="true()"/> 431 </xsl:apply-templates> 432 </xsl:if> 433 <xsl:text>go</xsl:text> 434 <xsl:number level="any" format="01" from="book"/> 435 <xsl:if test="not($recursive)"> 436 <xsl:value-of select="$html.ext"/> 437 </xsl:if> 438 </xsl:when> 439 440 <xsl:when test="name(.)='index'"> 441 <xsl:if test="/set"> 442 <xsl:apply-templates mode="chunk-filename" select="parent::*"> 443 <xsl:with-param name="recursive" select="true()"/> 444 </xsl:apply-templates> 445 </xsl:if> 446 <xsl:text>ix</xsl:text> 447 <xsl:number level="any" format="01" from="book"/> 448 <xsl:if test="not($recursive)"> 449 <xsl:value-of select="$html.ext"/> 450 </xsl:if> 451 </xsl:when> 452 453 <xsl:when test="name(.)='setindex'"> 454 <xsl:text>si</xsl:text> 455 <xsl:number level="any" format="01" from="set"/> 456 <xsl:if test="not($recursive)"> 457 <xsl:value-of select="$html.ext"/> 458 </xsl:if> 459 </xsl:when> 460 461 <xsl:otherwise> 462 <xsl:text>chunk-filename-error-</xsl:text> 463 <xsl:value-of select="name(.)"/> 464 <xsl:number level="any" format="01" from="set"/> 465 <xsl:if test="not($recursive)"> 466 <xsl:value-of select="$html.ext"/> 467 </xsl:if> 468 </xsl:otherwise> 469 </xsl:choose> 470</xsl:template> 471 472 473 474 475 476</xsl:stylesheet> 477