1<?xml version='1.0'?> 2<!DOCTYPE xsl:stylesheet [ 3<!ENTITY % common.entities SYSTEM "../common/entities.ent"> 4%common.entities; 5]> 6<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 7 version='1.0'> 8 9<!-- ******************************************************************** 10 $Id: glossary.xsl 7246 2007-08-16 20:58:06Z bobstayton $ 11 ******************************************************************** 12 13 This file is part of the XSL DocBook Stylesheet distribution. 14 See ../README or http://docbook.sf.net/release/xsl/current/ for 15 copyright and other information. 16 17 ******************************************************************** --> 18 19<!-- ==================================================================== --> 20 21<xsl:template match="glossary"> 22 &setup-language-variable; 23 <xsl:call-template name="id.warning"/> 24 25 <div> 26 <xsl:apply-templates select="." mode="class.attribute"/> 27 <xsl:if test="$generate.id.attributes != 0"> 28 <xsl:attribute name="id"> 29 <xsl:call-template name="object.id"/> 30 </xsl:attribute> 31 </xsl:if> 32 33 <xsl:call-template name="glossary.titlepage"/> 34 35 <xsl:choose> 36 <xsl:when test="glossdiv"> 37 <xsl:apply-templates select="(glossdiv[1]/preceding-sibling::*)"/> 38 </xsl:when> 39 <xsl:when test="glossentry"> 40 <xsl:apply-templates select="(glossentry[1]/preceding-sibling::*)"/> 41 </xsl:when> 42 <xsl:otherwise> 43 <xsl:apply-templates/> 44 </xsl:otherwise> 45 </xsl:choose> 46 47 <xsl:choose> 48 <xsl:when test="glossdiv"> 49 <xsl:apply-templates select="glossdiv"/> 50 </xsl:when> 51 <xsl:when test="glossentry"> 52 <dl> 53 <xsl:choose> 54 <xsl:when test="$glossary.sort != 0"> 55 <xsl:apply-templates select="glossentry"> 56 <xsl:sort lang="{$language}" 57 select="translate(glossterm, $lowercase, 58 $uppercase)"/> 59 </xsl:apply-templates> 60 </xsl:when> 61 <xsl:otherwise> 62 <xsl:apply-templates select="glossentry"/> 63 </xsl:otherwise> 64 </xsl:choose> 65 </dl> 66 </xsl:when> 67 <xsl:otherwise> 68 <!-- empty glossary --> 69 </xsl:otherwise> 70 </xsl:choose> 71 72 <xsl:if test="not(parent::article)"> 73 <xsl:call-template name="process.footnotes"/> 74 </xsl:if> 75 </div> 76</xsl:template> 77 78<xsl:template match="glossary/glossaryinfo"></xsl:template> 79<xsl:template match="glossary/info"></xsl:template> 80<xsl:template match="glossary/title"></xsl:template> 81<xsl:template match="glossary/subtitle"></xsl:template> 82<xsl:template match="glossary/titleabbrev"></xsl:template> 83 84<!-- ==================================================================== --> 85 86<xsl:template match="glosslist"> 87 &setup-language-variable; 88 <div> 89 <xsl:apply-templates select="." mode="class.attribute"/> 90 <xsl:call-template name="anchor"/> 91 <xsl:if test="blockinfo/title|info/title|title"> 92 <xsl:call-template name="formal.object.heading"/> 93 </xsl:if> 94 <dl> 95 <xsl:choose> 96 <xsl:when test="$glossary.sort != 0"> 97 <xsl:apply-templates select="glossentry"> 98 <xsl:sort lang="{$language}" 99 select="translate(glossterm, $lowercase, 100 $uppercase)"/> 101 </xsl:apply-templates> 102 </xsl:when> 103 <xsl:otherwise> 104 <xsl:apply-templates select="glossentry"/> 105 </xsl:otherwise> 106 </xsl:choose> 107 </dl> 108 </div> 109</xsl:template> 110 111<!-- ==================================================================== --> 112 113<xsl:template match="glossdiv"> 114 &setup-language-variable; 115 <xsl:call-template name="id.warning"/> 116 117 <div> 118 <xsl:apply-templates select="." mode="class.attribute"/> 119 <xsl:apply-templates select="(glossentry[1]/preceding-sibling::*)"/> 120 121 <dl> 122 <xsl:choose> 123 <xsl:when test="$glossary.sort != 0"> 124 <xsl:apply-templates select="glossentry"> 125 <xsl:sort lang="{$language}" 126 select="translate(glossterm, $lowercase, 127 $uppercase)"/> 128 </xsl:apply-templates> 129 </xsl:when> 130 <xsl:otherwise> 131 <xsl:apply-templates select="glossentry"/> 132 </xsl:otherwise> 133 </xsl:choose> 134 </dl> 135 </div> 136</xsl:template> 137 138<xsl:template match="glossdiv/title"> 139 <h3> 140 <xsl:apply-templates select="." mode="class.attribute"/> 141 <xsl:apply-templates/> 142 </h3> 143</xsl:template> 144 145<!-- ==================================================================== --> 146 147<!-- 148GlossEntry ::= 149 GlossTerm, Acronym?, Abbrev?, 150 (IndexTerm)*, 151 RevHistory?, 152 (GlossSee | GlossDef+) 153--> 154 155<xsl:template match="glossentry"> 156 <xsl:choose> 157 <xsl:when test="$glossentry.show.acronym = 'primary'"> 158 <dt> 159 <xsl:call-template name="anchor"> 160 <xsl:with-param name="conditional"> 161 <xsl:choose> 162 <xsl:when test="$glossterm.auto.link != 0">0</xsl:when> 163 <xsl:otherwise>1</xsl:otherwise> 164 </xsl:choose> 165 </xsl:with-param> 166 </xsl:call-template> 167 168 <xsl:choose> 169 <xsl:when test="acronym|abbrev"> 170 <xsl:apply-templates select="acronym|abbrev"/> 171 <xsl:text> (</xsl:text> 172 <xsl:apply-templates select="glossterm"/> 173 <xsl:text>)</xsl:text> 174 </xsl:when> 175 <xsl:otherwise> 176 <xsl:apply-templates select="glossterm"/> 177 </xsl:otherwise> 178 </xsl:choose> 179 </dt> 180 </xsl:when> 181 <xsl:when test="$glossentry.show.acronym = 'yes'"> 182 <dt> 183 <xsl:call-template name="anchor"> 184 <xsl:with-param name="conditional"> 185 <xsl:choose> 186 <xsl:when test="$glossterm.auto.link != 0">0</xsl:when> 187 <xsl:otherwise>1</xsl:otherwise> 188 </xsl:choose> 189 </xsl:with-param> 190 </xsl:call-template> 191 192 <xsl:apply-templates select="glossterm"/> 193 194 <xsl:if test="acronym|abbrev"> 195 <xsl:text> (</xsl:text> 196 <xsl:apply-templates select="acronym|abbrev"/> 197 <xsl:text>)</xsl:text> 198 </xsl:if> 199 </dt> 200 </xsl:when> 201 <xsl:otherwise> 202 <dt> 203 <xsl:call-template name="anchor"> 204 <xsl:with-param name="conditional"> 205 <xsl:choose> 206 <xsl:when test="$glossterm.auto.link != 0">0</xsl:when> 207 <xsl:otherwise>1</xsl:otherwise> 208 </xsl:choose> 209 </xsl:with-param> 210 </xsl:call-template> 211 212 <xsl:apply-templates select="glossterm"/> 213 </dt> 214 </xsl:otherwise> 215 </xsl:choose> 216 217 <xsl:apply-templates select="indexterm|revhistory|glosssee|glossdef"/> 218</xsl:template> 219 220<xsl:template match="glossentry/glossterm"> 221 <xsl:apply-templates/> 222 <xsl:if test="following-sibling::glossterm">, </xsl:if> 223</xsl:template> 224 225<xsl:template match="glossentry/acronym"> 226 <xsl:apply-templates/> 227 <xsl:if test="following-sibling::acronym|following-sibling::abbrev">, </xsl:if> 228</xsl:template> 229 230<xsl:template match="glossentry/abbrev"> 231 <xsl:apply-templates/> 232 <xsl:if test="following-sibling::acronym|following-sibling::abbrev">, </xsl:if> 233</xsl:template> 234 235<xsl:template match="glossentry/revhistory"> 236</xsl:template> 237 238<xsl:template match="glossentry/glosssee"> 239 <xsl:variable name="otherterm" select="@otherterm"/> 240 <xsl:variable name="targets" select="key('id', $otherterm)"/> 241 <xsl:variable name="target" select="$targets[1]"/> 242 243 <dd> 244 <p> 245 <xsl:variable name="template"> 246 <xsl:call-template name="gentext.template"> 247 <xsl:with-param name="context" select="'glossary'"/> 248 <xsl:with-param name="name" select="'see'"/> 249 </xsl:call-template> 250 </xsl:variable> 251 252 <xsl:variable name="title"> 253 <xsl:choose> 254 <xsl:when test="$target"> 255 <a> 256 <xsl:apply-templates select="." mode="class.attribute"/> 257 <xsl:attribute name="href"> 258 <xsl:call-template name="href.target"> 259 <xsl:with-param name="object" select="$target"/> 260 </xsl:call-template> 261 </xsl:attribute> 262 <xsl:apply-templates select="$target" mode="xref-to"/> 263 </a> 264 </xsl:when> 265 <xsl:when test="$otherterm != '' and not($target)"> 266 <xsl:message> 267 <xsl:text>Warning: glosssee @otherterm reference not found: </xsl:text> 268 <xsl:value-of select="$otherterm"/> 269 </xsl:message> 270 <xsl:apply-templates/> 271 </xsl:when> 272 <xsl:otherwise> 273 <xsl:apply-templates/> 274 </xsl:otherwise> 275 </xsl:choose> 276 </xsl:variable> 277 278 <xsl:call-template name="substitute-markup"> 279 <xsl:with-param name="template" select="$template"/> 280 <xsl:with-param name="title" select="$title"/> 281 </xsl:call-template> 282 <xsl:text>.</xsl:text> 283 </p> 284 </dd> 285</xsl:template> 286 287<xsl:template match="glossentry/glossdef"> 288 <dd> 289 <xsl:apply-templates select="*[local-name(.) != 'glossseealso']"/> 290 <xsl:if test="glossseealso"> 291 <p> 292 <xsl:variable name="template"> 293 <xsl:call-template name="gentext.template"> 294 <xsl:with-param name="context" select="'glossary'"/> 295 <xsl:with-param name="name" select="'seealso'"/> 296 </xsl:call-template> 297 </xsl:variable> 298 <xsl:variable name="title"> 299 <xsl:apply-templates select="glossseealso"/> 300 </xsl:variable> 301 <xsl:call-template name="substitute-markup"> 302 <xsl:with-param name="template" select="$template"/> 303 <xsl:with-param name="title" select="$title"/> 304 </xsl:call-template> 305 </p> 306 </xsl:if> 307 </dd> 308</xsl:template> 309 310<xsl:template match="glossseealso"> 311 <xsl:variable name="otherterm" select="@otherterm"/> 312 <xsl:variable name="targets" select="key('id', $otherterm)"/> 313 <xsl:variable name="target" select="$targets[1]"/> 314 315 <xsl:choose> 316 <xsl:when test="$target"> 317 <a> 318 <xsl:apply-templates select="." mode="class.attribute"/> 319 <xsl:attribute name="href"> 320 <xsl:call-template name="href.target"> 321 <xsl:with-param name="object" select="$target"/> 322 </xsl:call-template> 323 </xsl:attribute> 324 <xsl:apply-templates select="$target" mode="xref-to"/> 325 </a> 326 </xsl:when> 327 <xsl:when test="$otherterm != '' and not($target)"> 328 <xsl:message> 329 <xsl:text>Warning: glossseealso @otherterm reference not found: </xsl:text> 330 <xsl:value-of select="$otherterm"/> 331 </xsl:message> 332 <xsl:apply-templates/> 333 </xsl:when> 334 <xsl:otherwise> 335 <xsl:apply-templates/> 336 </xsl:otherwise> 337 </xsl:choose> 338 339 <xsl:choose> 340 <xsl:when test="position() = last()"> 341 <xsl:text>.</xsl:text> 342 </xsl:when> 343 <xsl:otherwise> 344 <xsl:text>, </xsl:text> 345 </xsl:otherwise> 346 </xsl:choose> 347</xsl:template> 348 349<!-- ==================================================================== --> 350 351<!-- Glossary collection --> 352 353<xsl:template match="glossary[@role='auto']" priority="2"> 354 &setup-language-variable; 355 <xsl:variable name="terms" 356 select="//glossterm[not(parent::glossdef)]|//firstterm"/> 357 <xsl:variable name="collection" select="document($glossary.collection, .)"/> 358 359 <xsl:call-template name="id.warning"/> 360 361 <xsl:if test="$glossary.collection = ''"> 362 <xsl:message> 363 <xsl:text>Warning: processing automatic glossary </xsl:text> 364 <xsl:text>without a glossary.collection file.</xsl:text> 365 </xsl:message> 366 </xsl:if> 367 368 <xsl:if test="not($collection) and $glossary.collection != ''"> 369 <xsl:message> 370 <xsl:text>Warning: processing automatic glossary but unable to </xsl:text> 371 <xsl:text>open glossary.collection file '</xsl:text> 372 <xsl:value-of select="$glossary.collection"/> 373 <xsl:text>'</xsl:text> 374 </xsl:message> 375 </xsl:if> 376 377 <div> 378 <xsl:apply-templates select="." mode="class.attribute"/> 379 <xsl:if test="$generate.id.attributes != 0"> 380 <xsl:attribute name="id"> 381 <xsl:call-template name="object.id"/> 382 </xsl:attribute> 383 </xsl:if> 384 385 <xsl:call-template name="glossary.titlepage"/> 386 387 <xsl:choose> 388 <xsl:when test="glossdiv and $collection//glossdiv"> 389 <xsl:for-each select="$collection//glossdiv"> 390 <!-- first see if there are any in this div --> 391 <xsl:variable name="exist.test"> 392 <xsl:for-each select="glossentry"> 393 <xsl:variable name="cterm" select="glossterm"/> 394 <xsl:if test="$terms[@baseform = $cterm or . = $cterm]"> 395 <xsl:value-of select="glossterm"/> 396 </xsl:if> 397 </xsl:for-each> 398 </xsl:variable> 399 400 <xsl:if test="$exist.test != ''"> 401 <xsl:apply-templates select="." mode="auto-glossary"> 402 <xsl:with-param name="terms" select="$terms"/> 403 </xsl:apply-templates> 404 </xsl:if> 405 </xsl:for-each> 406 </xsl:when> 407 <xsl:otherwise> 408 <dl> 409 <xsl:choose> 410 <xsl:when test="$glossary.sort != 0"> 411 <xsl:for-each select="$collection//glossentry"> 412 <xsl:sort lang="{$language}" 413 select="translate(glossterm, $lowercase, 414 $uppercase)"/> 415 <xsl:variable name="cterm" select="glossterm"/> 416 <xsl:if test="$terms[@baseform = $cterm or . = $cterm]"> 417 <xsl:apply-templates select="." mode="auto-glossary"/> 418 </xsl:if> 419 </xsl:for-each> 420 </xsl:when> 421 <xsl:otherwise> 422 <xsl:for-each select="$collection//glossentry"> 423 <xsl:variable name="cterm" select="glossterm"/> 424 <xsl:if test="$terms[@baseform = $cterm or . = $cterm]"> 425 <xsl:apply-templates select="." mode="auto-glossary"/> 426 </xsl:if> 427 </xsl:for-each> 428 </xsl:otherwise> 429 </xsl:choose> 430 </dl> 431 </xsl:otherwise> 432 </xsl:choose> 433 434 <xsl:if test="not(parent::article)"> 435 <xsl:call-template name="process.footnotes"/> 436 </xsl:if> 437 </div> 438</xsl:template> 439 440<xsl:template match="*" mode="auto-glossary"> 441 <!-- pop back out to the default mode for most elements --> 442 <xsl:apply-templates select="."/> 443</xsl:template> 444 445<xsl:template match="glossdiv" mode="auto-glossary"> 446 <xsl:param name="terms" select="."/> 447 448 &setup-language-variable; 449 450 <div> 451 <xsl:apply-templates select="." mode="class.attribute"/> 452 <xsl:apply-templates select="(glossentry[1]/preceding-sibling::*)"/> 453 454 <dl> 455 <xsl:choose> 456 <xsl:when test="$glossary.sort != 0"> 457 <xsl:for-each select="glossentry"> 458 <xsl:sort lang="{$language}" 459 select="translate(glossterm, $lowercase, 460 $uppercase)"/> 461 <xsl:variable name="cterm" select="glossterm"/> 462 <xsl:if test="$terms[@baseform = $cterm or . = $cterm]"> 463 <xsl:apply-templates select="." mode="auto-glossary"/> 464 </xsl:if> 465 </xsl:for-each> 466 </xsl:when> 467 <xsl:otherwise> 468 <xsl:for-each select="glossentry"> 469 <xsl:variable name="cterm" select="glossterm"/> 470 <xsl:if test="$terms[@baseform = $cterm or . = $cterm]"> 471 <xsl:apply-templates select="." mode="auto-glossary"/> 472 </xsl:if> 473 </xsl:for-each> 474 </xsl:otherwise> 475 </xsl:choose> 476 </dl> 477 </div> 478</xsl:template> 479 480<!-- ==================================================================== --> 481 482</xsl:stylesheet> 483