1<?xml version='1.0'?> 2<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 3 xmlns:doc="http://nwalsh.com/xsl/documentation/1.0" 4 exclude-result-prefixes="doc" 5 version='1.0'> 6 7<!-- ============================================================ --> 8<!-- label markup --> 9 10<doc:mode mode="label.markup" xmlns=""> 11<refpurpose>Provides access to element labels</refpurpose> 12<refdescription> 13<para>Processing an element in the 14<literal role="mode">label.markup</literal> mode produces the 15element label.</para> 16<para>Trailing punctuation is not added to the label. 17</para> 18</refdescription> 19</doc:mode> 20 21<xsl:template match="*" mode="intralabel.punctuation"> 22 <xsl:text>.</xsl:text> 23</xsl:template> 24 25<xsl:template match="*" mode="label.markup"> 26 <xsl:message> 27 <xsl:text>Request for label of unexpected element: </xsl:text> 28 <xsl:value-of select="name(.)"/> 29 </xsl:message> 30</xsl:template> 31 32<xsl:template match="set|book" mode="label.markup"> 33 <xsl:if test="@label"> 34 <xsl:value-of select="@label"/> 35 </xsl:if> 36</xsl:template> 37 38<xsl:template match="part" mode="label.markup"> 39 <xsl:choose> 40 <xsl:when test="@label"> 41 <xsl:value-of select="@label"/> 42 </xsl:when> 43 <xsl:when test="$part.autolabel != 0"> 44 <xsl:number from="book" count="part" format="I"/> 45 </xsl:when> 46 </xsl:choose> 47</xsl:template> 48 49<xsl:template match="preface" mode="label.markup"> 50 <xsl:choose> 51 <xsl:when test="@label"> 52 <xsl:value-of select="@label"/> 53 </xsl:when> 54 <xsl:when test="$preface.autolabel != 0"> 55 <xsl:choose> 56 <xsl:when test="$label.from.part != 0 and ancestor::part"> 57 <xsl:number from="part" count="preface" format="1" level="any"/> 58 </xsl:when> 59 <xsl:otherwise> 60 <xsl:number from="book" count="preface" format="1" level="any"/> 61 </xsl:otherwise> 62 </xsl:choose> 63 </xsl:when> 64 </xsl:choose> 65</xsl:template> 66 67<xsl:template match="chapter" mode="label.markup"> 68 <xsl:choose> 69 <xsl:when test="@label"> 70 <xsl:value-of select="@label"/> 71 </xsl:when> 72 <xsl:when test="$chapter.autolabel != 0"> 73 <xsl:choose> 74 <xsl:when test="$label.from.part != 0 and ancestor::part"> 75 <xsl:number from="part" count="chapter" format="1" level="any"/> 76 </xsl:when> 77 <xsl:otherwise> 78 <xsl:number from="book" count="chapter" format="1" level="any"/> 79 </xsl:otherwise> 80 </xsl:choose> 81 </xsl:when> 82 </xsl:choose> 83</xsl:template> 84 85<xsl:template match="appendix" mode="label.markup"> 86 <xsl:choose> 87 <xsl:when test="@label"> 88 <xsl:value-of select="@label"/> 89 </xsl:when> 90 <xsl:when test="$appendix.autolabel != 0"> 91 <xsl:choose> 92 <xsl:when test="$label.from.part != 0 and ancestor::part"> 93 <xsl:number from="part" count="appendix" format="A" level="any"/> 94 </xsl:when> 95 <xsl:otherwise> 96 <xsl:number from="book|article" 97 count="appendix" format="A" level="any"/> 98 </xsl:otherwise> 99 </xsl:choose> 100 </xsl:when> 101 </xsl:choose> 102</xsl:template> 103 104<xsl:template match="article" mode="label.markup"> 105 <xsl:if test="@label"> 106 <xsl:value-of select="@label"/> 107 </xsl:if> 108</xsl:template> 109 110<xsl:template match="dedication|colophon" mode="label.markup"> 111 <xsl:if test="@label"> 112 <xsl:value-of select="@label"/> 113 </xsl:if> 114</xsl:template> 115 116<xsl:template match="reference" mode="label.markup"> 117 <xsl:choose> 118 <xsl:when test="@label"> 119 <xsl:value-of select="@label"/> 120 </xsl:when> 121 <xsl:when test="$part.autolabel != 0"> 122 <xsl:number from="book" count="reference" format="I" level="any"/> 123 </xsl:when> 124 </xsl:choose> 125</xsl:template> 126 127<xsl:template match="refentry" mode="label.markup"> 128 <xsl:if test="@label"> 129 <xsl:value-of select="@label"/> 130 </xsl:if> 131</xsl:template> 132 133<xsl:template match="section" mode="label.markup"> 134 <!-- if this is a nested section, label the parent --> 135 <xsl:if test="local-name(..) = 'section'"> 136 <xsl:variable name="parent.section.label"> 137 <xsl:apply-templates select=".." mode="label.markup"/> 138 </xsl:variable> 139 <xsl:if test="$parent.section.label != ''"> 140 <xsl:apply-templates select=".." mode="label.markup"/> 141 <xsl:apply-templates select=".." mode="intralabel.punctuation"/> 142 </xsl:if> 143 </xsl:if> 144 145 <!-- if the parent is a component, maybe label that too --> 146 <xsl:variable name="parent.is.component"> 147 <xsl:call-template name="is.component"> 148 <xsl:with-param name="node" select=".."/> 149 </xsl:call-template> 150 </xsl:variable> 151 152 <!-- does this section get labelled? --> 153 <xsl:variable name="label"> 154 <xsl:call-template name="label.this.section"> 155 <xsl:with-param name="section" select="."/> 156 </xsl:call-template> 157 </xsl:variable> 158 159 <xsl:if test="($section.label.includes.component.label != 0 160 or /article) 161 and $parent.is.component != 0"> 162 <xsl:variable name="parent.label"> 163 <xsl:apply-templates select=".." mode="label.markup"/> 164 </xsl:variable> 165 <xsl:if test="$parent.label != ''"> 166 <xsl:apply-templates select=".." mode="label.markup"/> 167 <xsl:apply-templates select=".." mode="intralabel.punctuation"/> 168 </xsl:if> 169 </xsl:if> 170 171<!-- 172 <xsl:message> 173 <xsl:value-of select="$label"/>, <xsl:number count="section"/> 174 </xsl:message> 175--> 176 177 <xsl:choose> 178 <xsl:when test="@label"> 179 <xsl:value-of select="@label"/> 180 </xsl:when> 181 <xsl:when test="$label != 0"> 182 <xsl:number count="section"/> 183 </xsl:when> 184 </xsl:choose> 185</xsl:template> 186 187<xsl:template match="sect1" mode="label.markup"> 188 <!-- if the parent is a component, maybe label that too --> 189 <xsl:variable name="parent.is.component"> 190 <xsl:call-template name="is.component"> 191 <xsl:with-param name="node" select=".."/> 192 </xsl:call-template> 193 </xsl:variable> 194 195 <xsl:if test="$section.label.includes.component.label != 0 196 and $parent.is.component"> 197 <xsl:variable name="parent.label"> 198 <xsl:apply-templates select=".." mode="label.markup"/> 199 </xsl:variable> 200 <xsl:if test="$parent.label != ''"> 201 <xsl:apply-templates select=".." mode="label.markup"/> 202 <xsl:apply-templates select=".." mode="intralabel.punctuation"/> 203 </xsl:if> 204 </xsl:if> 205 206 <xsl:choose> 207 <xsl:when test="@label"> 208 <xsl:value-of select="@label"/> 209 </xsl:when> 210 <xsl:when test="$section.autolabel != 0"> 211 <xsl:number count="sect1"/> 212 </xsl:when> 213 </xsl:choose> 214</xsl:template> 215 216<xsl:template match="sect2|sect3|sect4|sect5" mode="label.markup"> 217 <!-- label the parent --> 218 <xsl:variable name="parent.label"> 219 <xsl:apply-templates select=".." mode="label.markup"/> 220 </xsl:variable> 221 <xsl:if test="$parent.label != ''"> 222 <xsl:apply-templates select=".." mode="label.markup"/> 223 <xsl:apply-templates select=".." mode="intralabel.punctuation"/> 224 </xsl:if> 225 226 <xsl:choose> 227 <xsl:when test="@label"> 228 <xsl:value-of select="@label"/> 229 </xsl:when> 230 <xsl:when test="$section.autolabel != 0"> 231 <xsl:choose> 232 <xsl:when test="local-name(.) = 'sect2'"> 233 <xsl:number count="sect2"/> 234 </xsl:when> 235 <xsl:when test="local-name(.) = 'sect3'"> 236 <xsl:number count="sect3"/> 237 </xsl:when> 238 <xsl:when test="local-name(.) = 'sect4'"> 239 <xsl:number count="sect4"/> 240 </xsl:when> 241 <xsl:when test="local-name(.) = 'sect5'"> 242 <xsl:number count="sect5"/> 243 </xsl:when> 244 <xsl:otherwise> 245 <xsl:message>label.markup: this can't happen!</xsl:message> 246 </xsl:otherwise> 247 </xsl:choose> 248 </xsl:when> 249 </xsl:choose> 250</xsl:template> 251 252<xsl:template match="refsect1" mode="label.markup"> 253 <xsl:choose> 254 <xsl:when test="@label"> 255 <xsl:value-of select="@label"/> 256 </xsl:when> 257 <xsl:when test="$section.autolabel != 0"> 258 <xsl:number count="refsect1"/> 259 </xsl:when> 260 </xsl:choose> 261</xsl:template> 262 263<xsl:template match="refsect2|refsect3" mode="label.markup"> 264 <!-- label the parent --> 265 <xsl:variable name="parent.label"> 266 <xsl:apply-templates select=".." mode="label.markup"/> 267 </xsl:variable> 268 <xsl:if test="$parent.label != ''"> 269 <xsl:apply-templates select=".." mode="label.markup"/> 270 <xsl:apply-templates select=".." mode="intralabel.punctuation"/> 271 </xsl:if> 272 273 <xsl:choose> 274 <xsl:when test="@label"> 275 <xsl:value-of select="@label"/> 276 </xsl:when> 277 <xsl:when test="$section.autolabel != 0"> 278 <xsl:choose> 279 <xsl:when test="local-name(.) = 'refsect2'"> 280 <xsl:number count="refsect2"/> 281 </xsl:when> 282 <xsl:otherwise> 283 <xsl:number count="refsect3"/> 284 </xsl:otherwise> 285 </xsl:choose> 286 </xsl:when> 287 </xsl:choose> 288</xsl:template> 289 290<xsl:template match="simplesect" mode="label.markup"> 291 <!-- if this is a nested section, label the parent --> 292 <xsl:if test="local-name(..) = 'section' 293 or local-name(..) = 'sect1' 294 or local-name(..) = 'sect2' 295 or local-name(..) = 'sect3' 296 or local-name(..) = 'sect4' 297 or local-name(..) = 'sect5'"> 298 <xsl:variable name="parent.section.label"> 299 <xsl:apply-templates select=".." mode="label.markup"/> 300 </xsl:variable> 301 <xsl:if test="$parent.section.label != ''"> 302 <xsl:apply-templates select=".." mode="label.markup"/> 303 <xsl:apply-templates select=".." mode="intralabel.punctuation"/> 304 </xsl:if> 305 </xsl:if> 306 307 <!-- if the parent is a component, maybe label that too --> 308 <xsl:variable name="parent.is.component"> 309 <xsl:call-template name="is.component"> 310 <xsl:with-param name="node" select=".."/> 311 </xsl:call-template> 312 </xsl:variable> 313 314 <!-- does this section get labelled? --> 315 <xsl:variable name="label"> 316 <xsl:call-template name="label.this.section"> 317 <xsl:with-param name="section" select="."/> 318 </xsl:call-template> 319 </xsl:variable> 320 321 <xsl:if test="$section.label.includes.component.label != 0 322 and $parent.is.component != 0"> 323 <xsl:variable name="parent.label"> 324 <xsl:apply-templates select=".." mode="label.markup"/> 325 </xsl:variable> 326 <xsl:if test="$parent.label != ''"> 327 <xsl:apply-templates select=".." mode="label.markup"/> 328 <xsl:apply-templates select=".." mode="intralabel.punctuation"/> 329 </xsl:if> 330 </xsl:if> 331 332 <xsl:choose> 333 <xsl:when test="@label"> 334 <xsl:value-of select="@label"/> 335 </xsl:when> 336 <xsl:when test="$label != 0"> 337 <xsl:number count="simplesect"/> 338 </xsl:when> 339 </xsl:choose> 340</xsl:template> 341 342<xsl:template match="qandadiv" mode="label.markup"> 343 <xsl:variable name="lparent" select="(ancestor::set 344 |ancestor::book 345 |ancestor::chapter 346 |ancestor::appendix 347 |ancestor::preface 348 |ancestor::section 349 |ancestor::simplesect 350 |ancestor::sect1 351 |ancestor::sect2 352 |ancestor::sect3 353 |ancestor::sect4 354 |ancestor::sect5 355 |ancestor::refsect1 356 |ancestor::refsect2 357 |ancestor::refsect3)[last()]"/> 358 359 <xsl:variable name="lparent.prefix"> 360 <xsl:apply-templates select="$lparent" mode="label.markup"/> 361 </xsl:variable> 362 363 <xsl:variable name="prefix"> 364 <xsl:if test="$qanda.inherit.numeration != 0"> 365 <xsl:if test="$lparent.prefix != ''"> 366 <xsl:apply-templates select="$lparent" mode="label.markup"/> 367 <xsl:apply-templates select="$lparent" mode="intralabel.punctuation"/> 368 </xsl:if> 369 </xsl:if> 370 </xsl:variable> 371 372 <xsl:choose> 373 <xsl:when test="@label"> 374 <xsl:value-of select="$prefix"/> 375 <xsl:value-of select="@label"/> 376 </xsl:when> 377 <xsl:when test="$qandadiv.autolabel != 0"> 378 <xsl:value-of select="$prefix"/> 379 <xsl:number level="multiple" count="qandadiv" format="1"/> 380 </xsl:when> 381 </xsl:choose> 382</xsl:template> 383 384<xsl:template match="question|answer" mode="label.markup"> 385 <xsl:variable name="lparent" select="(ancestor::set 386 |ancestor::book 387 |ancestor::chapter 388 |ancestor::appendix 389 |ancestor::preface 390 |ancestor::section 391 |ancestor::simplesect 392 |ancestor::sect1 393 |ancestor::sect2 394 |ancestor::sect3 395 |ancestor::sect4 396 |ancestor::sect5 397 |ancestor::refsect1 398 |ancestor::refsect2 399 |ancestor::refsect3)[last()]"/> 400 401 <xsl:variable name="lparent.prefix"> 402 <xsl:apply-templates select="$lparent" mode="label.markup"/> 403 </xsl:variable> 404 405 <xsl:variable name="prefix"> 406 <xsl:if test="$qanda.inherit.numeration != 0"> 407 <xsl:if test="$lparent.prefix != ''"> 408 <xsl:apply-templates select="$lparent" mode="label.markup"/> 409 <xsl:apply-templates select="$lparent" mode="intralabel.punctuation"/> 410 </xsl:if> 411 </xsl:if> 412 </xsl:variable> 413 414 <xsl:variable name="inhlabel" 415 select="ancestor-or-self::qandaset/@defaultlabel[1]"/> 416 417 <xsl:variable name="deflabel"> 418 <xsl:choose> 419 <xsl:when test="$inhlabel != ''"> 420 <xsl:value-of select="$inhlabel"/> 421 </xsl:when> 422 <xsl:otherwise> 423 <xsl:value-of select="$qanda.defaultlabel"/> 424 </xsl:otherwise> 425 </xsl:choose> 426 </xsl:variable> 427 428 <xsl:variable name="label" select="label"/> 429 430 <xsl:choose> 431 <xsl:when test="count($label)>0"> 432 <xsl:value-of select="$prefix"/> 433 <xsl:apply-templates select="$label"/> 434 </xsl:when> 435 436 <xsl:when test="$deflabel = 'qanda' and local-name(.) = 'question'"> 437 <xsl:call-template name="gentext"> 438 <xsl:with-param name="key" select="'Question'"/> 439 </xsl:call-template> 440 </xsl:when> 441 442 <xsl:when test="$deflabel = 'qanda' and local-name(.) = 'answer'"> 443 <xsl:call-template name="gentext"> 444 <xsl:with-param name="key" select="'Answer'"/> 445 </xsl:call-template> 446 </xsl:when> 447 448 <xsl:when test="$deflabel = 'number'"> 449 <xsl:if test="name(.) = 'question'"> 450 <xsl:value-of select="$prefix"/> 451 <xsl:number level="multiple" count="qandaentry" format="1"/> 452 </xsl:if> 453 </xsl:when> 454 </xsl:choose> 455</xsl:template> 456 457<xsl:template match="bibliography|glossary|index" mode="label.markup"> 458 <xsl:if test="@label"> 459 <xsl:value-of select="@label"/> 460 </xsl:if> 461</xsl:template> 462 463<xsl:template match="figure|table|example|equation" mode="label.markup"> 464 <xsl:variable name="pchap" 465 select="ancestor::chapter|ancestor::appendix"/> 466 467 <xsl:variable name="prefix"> 468 <xsl:if test="count($pchap) > 0"> 469 <xsl:apply-templates select="$pchap" mode="label.markup"/> 470 </xsl:if> 471 </xsl:variable> 472 473 <xsl:choose> 474 <xsl:when test="@label"> 475 <xsl:value-of select="@label"/> 476 </xsl:when> 477 <xsl:otherwise> 478 <xsl:choose> 479 <xsl:when test="count($pchap)>0"> 480 <xsl:if test="$prefix != ''"> 481 <xsl:apply-templates select="$pchap" mode="label.markup"/> 482 <xsl:apply-templates select="$pchap" mode="intralabel.punctuation"/> 483 </xsl:if> 484 <xsl:number format="1" from="chapter|appendix" level="any"/> 485 </xsl:when> 486 <xsl:otherwise> 487 <xsl:number format="1" from="book|article" level="any"/> 488 </xsl:otherwise> 489 </xsl:choose> 490 </xsl:otherwise> 491 </xsl:choose> 492</xsl:template> 493 494<xsl:template match="abstract" mode="label.markup"> 495 <!-- nop --> 496</xsl:template> 497 498<!-- ============================================================ --> 499 500<xsl:template name="label.this.section"> 501 <xsl:param name="section" select="."/> 502 <xsl:value-of select="$section.autolabel"/> 503</xsl:template> 504 505<doc:template name="label.this.section" xmlns=""> 506<refpurpose>Returns true if $section should be labelled</refpurpose> 507<refdescription> 508<para>Returns true if the specified section should be labelled. 509By default, this template simply returns $section.autolabel, but 510custom stylesheets may override it to get more selective behavior.</para> 511</refdescription> 512</doc:template> 513 514<!-- ============================================================ --> 515 516</xsl:stylesheet> 517