| 1 |
<?xml version='1.0' encoding='UTF-8'?><!-- -*- indent-tabs-mode: nil -*- --> |
| 2 |
<!-- |
| 3 |
This program is free software; you can redistribute it and/or modify it under |
| 4 |
the terms of the GNU Lesser General Public License as published by the Free |
| 5 |
Software Foundation; either version 2 of the License, or (at your option) any |
| 6 |
later version. |
| 7 |
|
| 8 |
This program is distributed in the hope that it will be useful, but WITHOUT |
| 9 |
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 10 |
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
| 11 |
details. |
| 12 |
|
| 13 |
You should have received a copy of the GNU Lesser General Public License |
| 14 |
along with this program; see the file COPYING.LGPL. If not, see <http://www.gnu.org/licenses/>. |
| 15 |
--> |
| 16 |
|
| 17 |
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" |
| 18 |
xmlns:db="http://docbook.org/ns/docbook" |
| 19 |
xmlns:str="http://exslt.org/strings" |
| 20 |
xmlns:msg="http://projects.gnome.org/yelp/gettext/" |
| 21 |
exclude-result-prefixes="db str msg" |
| 22 |
version="1.0"> |
| 23 |
|
| 24 |
<!--!!========================================================================== |
| 25 |
DocBook Common |
| 26 |
|
| 27 |
This stylesheet module provides utility templates for DocBook that are |
| 28 |
independant of the target format. |
| 29 |
--> |
| 30 |
|
| 31 |
|
| 32 |
<!--++========================================================================== |
| 33 |
db.id.key |
| 34 |
Get an element from the `id` attribute. |
| 35 |
@revision[version=3.4 date=2012-01-26 status=final] |
| 36 |
|
| 37 |
This key returns any element based on the `id` attribute, or the `xml:id` |
| 38 |
attribute in DocBook 5. |
| 39 |
--> |
| 40 |
<xsl:key name="db.id.key" match="*" use="@id | @xml:id"/> |
| 41 |
|
| 42 |
|
| 43 |
<!--++========================================================================== |
| 44 |
db.biblio.abbrev.key |
| 45 |
Get a `biblioentry` or `bibliomixed` element from its `abbrev`. |
| 46 |
@revision[version=3.18 date=2015-07-23 status=final] |
| 47 |
|
| 48 |
This key returns `biblioentry` and `bibliomixed` elements based on their child |
| 49 |
`abbrev` elements. The `abbrev` element must be the first child element of the |
| 50 |
`biblioentry` or `bibliomixed` element. This key only returns elements that |
| 51 |
have an `id` attribute for DocBook 4 or an `xml:id` attribute for DocBook 5. |
| 52 |
--> |
| 53 |
<xsl:key name="db.biblio.abbrev.key" |
| 54 |
match="biblioentry[@id and *[1]/self::abbrev] | |
| 55 |
bibliomixed[@id and *[1]/self::abbrev] | |
| 56 |
db:biblioentry[@xml:id and *[1]/self::db:abbrev] | |
| 57 |
db:bibliomixed[@xml:id and *[1]/self::db:abbrev]" |
| 58 |
use="string(*[1])"/> |
| 59 |
|
| 60 |
|
| 61 |
<!--++========================================================================== |
| 62 |
db.biblio.label.key |
| 63 |
Get a `biblioentry` or `bibliomixed` element from its `xreflabel`. |
| 64 |
@revision[version=3.18 date=2015-07-23 status=final] |
| 65 |
|
| 66 |
This key returns `biblioentry` and `bibliomixed` elements based on their |
| 67 |
`xreflabel` attributes. It only returns elements that have an `id` attribute |
| 68 |
for DocBook 4 or an `xml:id` attribute for DocBook 5. |
| 69 |
--> |
| 70 |
<xsl:key name="db.biblio.label.key" |
| 71 |
match="biblioentry[@id and @xreflabel] | |
| 72 |
bibliomixed[@id and @xreflabel] | |
| 73 |
db:biblioentry[@xml:id and @xreflabel] | |
| 74 |
db:bibliomixed[@xml:id and @xreflabel]" |
| 75 |
use="string(@xreflabel)"/> |
| 76 |
|
| 77 |
|
| 78 |
<!--++========================================================================== |
| 79 |
db.biblio.id.key |
| 80 |
Get a `biblioentry` or `bibliomixed` element from its `id`. |
| 81 |
@revision[version=3.18 date=2015-07-23 status=final] |
| 82 |
|
| 83 |
This key returns `biblioentry` and `bibliomixed` elements based on their `id` |
| 84 |
or `xml:id` attributes. The {#id} attribute is used for DocBook 4, and the |
| 85 |
`xml:id` attribute is used for DocBook 5. |
| 86 |
--> |
| 87 |
<xsl:key name="db.biblio.id.key" |
| 88 |
match="biblioentry[@id] | bibliomixed[@id]" |
| 89 |
use="string(@id)"/> |
| 90 |
<xsl:key name="db.biblio.id.key" |
| 91 |
match="db:biblioentry[@xml:id] | db:bibliomixed[@xml:id]" |
| 92 |
use="string(@xml:id)"/> |
| 93 |
|
| 94 |
|
| 95 |
<!--++========================================================================== |
| 96 |
db.glossentry.key |
| 97 |
Get a `glossentry` element from its `glossterm`. |
| 98 |
@revision[version=3.18 date=2015-07-22 status=final] |
| 99 |
|
| 100 |
This key returns `glossentry` elements based on the text in their `glossterm` |
| 101 |
child elements. It only returns `glossentry` elements that have an `id` |
| 102 |
attribute in DocBook 4 or an `xml:id` attribute in DocBook 5. |
| 103 |
--> |
| 104 |
<xsl:key name="db.glossentry.key" |
| 105 |
match="glossentry[@id]" use="string(glossterm)"/> |
| 106 |
<xsl:key name="db.glossentry.key" |
| 107 |
match="db:glossentry[@xml:id]" use="string(db:glossterm)"/> |
| 108 |
|
| 109 |
|
| 110 |
<!--**========================================================================== |
| 111 |
db.copyright |
| 112 |
Outputs copyright information |
| 113 |
$node: The `copyright` element to format |
| 114 |
|
| 115 |
This template outputs copyright information from a `copyright` elements. |
| 116 |
It assembles the `year` and `holder` elements into a simple copyright |
| 117 |
notice, beginning with the copyright symbol "©". |
| 118 |
--> |
| 119 |
<xsl:template name="db.copyright"> |
| 120 |
<xsl:param name="node" select="."/> |
| 121 |
<xsl:call-template name="l10n.gettext"> |
| 122 |
<xsl:with-param name="msgid" select="'copyright.format'"/> |
| 123 |
<xsl:with-param name="node" select="$node"/> |
| 124 |
<xsl:with-param name="format" select="true()"/> |
| 125 |
</xsl:call-template> |
| 126 |
</xsl:template> |
| 127 |
|
| 128 |
<xsl:template mode="l10n.format.mode" match="msg:copyright.years"> |
| 129 |
<xsl:param name="node"/> |
| 130 |
<xsl:for-each select="$node/year | $node/db:year"> |
| 131 |
<xsl:if test="position() != 1"> |
| 132 |
<xsl:call-template name="l10n.gettext"> |
| 133 |
<xsl:with-param name="msgid" select="', '"/> |
| 134 |
</xsl:call-template> |
| 135 |
</xsl:if> |
| 136 |
<xsl:apply-templates select="."/> |
| 137 |
</xsl:for-each> |
| 138 |
</xsl:template> |
| 139 |
|
| 140 |
<xsl:template mode="l10n.format.mode" match="msg:copyright.name"> |
| 141 |
<xsl:param name="node"/> |
| 142 |
<xsl:for-each select="$node/holder | $node/db:holder"> |
| 143 |
<xsl:if test="position() != 1"> |
| 144 |
<xsl:call-template name="l10n.gettext"> |
| 145 |
<xsl:with-param name="msgid" select="', '"/> |
| 146 |
</xsl:call-template> |
| 147 |
</xsl:if> |
| 148 |
<xsl:apply-templates select="."/> |
| 149 |
</xsl:for-each> |
| 150 |
</xsl:template> |
| 151 |
|
| 152 |
|
| 153 |
<!--**========================================================================== |
| 154 |
db.linenumbering.start |
| 155 |
Determines the starting line number for a verbatim element |
| 156 |
$node: The verbatim element to determine the starting line number for |
| 157 |
|
| 158 |
This template determines the starting line number for a verbatim element using |
| 159 |
the `continuation` attribute. The template finds the first preceding element |
| 160 |
of the same name, counts its lines, and handles any `startinglinenumber` or |
| 161 |
`continuation` element it finds on that element. |
| 162 |
--> |
| 163 |
<xsl:template name="db.linenumbering.start"> |
| 164 |
<xsl:param name="node" select="."/> |
| 165 |
<xsl:choose> |
| 166 |
<xsl:when test="$node/@startinglinenumber"> |
| 167 |
<xsl:value-of select="$node/@startinglinenumber"/> |
| 168 |
</xsl:when> |
| 169 |
<xsl:when test="$node/@continuation"> |
| 170 |
<xsl:variable name="prev" select="$node/preceding::*[name(.) = name($node)][1]"/> |
| 171 |
<xsl:choose> |
| 172 |
<xsl:when test="count($prev) = 0">1</xsl:when> |
| 173 |
<xsl:otherwise> |
| 174 |
<xsl:variable name="prevcount"> |
| 175 |
<xsl:value-of select="count(str:split(string($prev), '
'))"/> |
| 176 |
</xsl:variable> |
| 177 |
<xsl:variable name="prevstart"> |
| 178 |
<xsl:call-template name="db.linenumbering.start"> |
| 179 |
<xsl:with-param name="node" select="$prev"/> |
| 180 |
</xsl:call-template> |
| 181 |
</xsl:variable> |
| 182 |
<xsl:value-of select="$prevstart + $prevcount"/> |
| 183 |
</xsl:otherwise> |
| 184 |
</xsl:choose> |
| 185 |
</xsl:when> |
| 186 |
<xsl:otherwise>1</xsl:otherwise> |
| 187 |
</xsl:choose> |
| 188 |
</xsl:template> |
| 189 |
|
| 190 |
|
| 191 |
<!--**========================================================================== |
| 192 |
db.orderedlist.start |
| 193 |
Determine the number to use for the first `listitem` in an `orderedlist`. |
| 194 |
@revision[version=3.10 date=2013-08-12 status=final] |
| 195 |
|
| 196 |
[xsl:params] |
| 197 |
$node: The `orderedlist` element to use. |
| 198 |
$continuation: The value of the `continuation` attribute. |
| 199 |
|
| 200 |
This template determines the starting number for an `orderedlist` element using |
| 201 |
the `continuation` attribute. The template finds the first preceding `orderedlist` |
| 202 |
element and counts its list items. If that element also uses the `continuation` |
| 203 |
attribute, this template calls itself recursively to add that element's starting |
| 204 |
line number to its list item count. |
| 205 |
|
| 206 |
This template uses conditional processing when looking at preceding ordered lists |
| 207 |
and their child list items. |
| 208 |
|
| 209 |
The $continuation parameter is automatically set based on the `continuation` |
| 210 |
attribute of $node. It exists as a parameter to allow this template to force |
| 211 |
continuation when it calls itself recursively for conditional processing. |
| 212 |
--> |
| 213 |
<xsl:template name="db.orderedlist.start"> |
| 214 |
<xsl:param name="node" select="."/> |
| 215 |
<xsl:param name="continuation" select="$node/@continuation"/> |
| 216 |
<xsl:choose> |
| 217 |
<xsl:when test="$continuation != 'continues'">1</xsl:when> |
| 218 |
<xsl:otherwise> |
| 219 |
<xsl:variable name="prevlist" |
| 220 |
select="($node/preceding::orderedlist[1] | $node/preceding::db:orderedlist[1])[last()]"/> |
| 221 |
<xsl:choose> |
| 222 |
<xsl:when test="count($prevlist) = 0">1</xsl:when> |
| 223 |
<xsl:otherwise> |
| 224 |
<xsl:variable name="prevlistif"> |
| 225 |
<xsl:call-template name="db.profile.test"> |
| 226 |
<xsl:with-param name="node" select="$prevlist"/> |
| 227 |
</xsl:call-template> |
| 228 |
</xsl:variable> |
| 229 |
<xsl:choose> |
| 230 |
<xsl:when test="$prevlistif = ''"> |
| 231 |
<xsl:call-template name="db.orderedlist.start"> |
| 232 |
<xsl:with-param name="node" select="$prevlist"/> |
| 233 |
<xsl:with-param name="continuation" select="'continues'"/> |
| 234 |
</xsl:call-template> |
| 235 |
</xsl:when> |
| 236 |
<xsl:otherwise> |
| 237 |
<xsl:variable name="prevlength"> |
| 238 |
<xsl:for-each select="$prevlist/listitem | $prevlist/db:listitem"> |
| 239 |
<xsl:variable name="if"><xsl:call-template name="db.profile.test"/></xsl:variable> |
| 240 |
<xsl:if test="$if != ''"> |
| 241 |
<xsl:text>x</xsl:text> |
| 242 |
</xsl:if> |
| 243 |
</xsl:for-each> |
| 244 |
</xsl:variable> |
| 245 |
<xsl:variable name="prevstart"> |
| 246 |
<xsl:call-template name="db.orderedlist.start"> |
| 247 |
<xsl:with-param name="node" select="$prevlist"/> |
| 248 |
</xsl:call-template> |
| 249 |
</xsl:variable> |
| 250 |
<xsl:value-of select="$prevstart + string-length($prevlength)"/> |
| 251 |
</xsl:otherwise> |
| 252 |
</xsl:choose> |
| 253 |
</xsl:otherwise> |
| 254 |
</xsl:choose> |
| 255 |
</xsl:otherwise> |
| 256 |
</xsl:choose> |
| 257 |
</xsl:template> |
| 258 |
|
| 259 |
|
| 260 |
<!--**========================================================================== |
| 261 |
db.personname |
| 262 |
Outputs the name of a person |
| 263 |
$node: The element containing tags such as `firstname` and `surname` |
| 264 |
|
| 265 |
This template outputs the name of a person as modelled by the `personname` |
| 266 |
element. The `personname` element allows authors to mark up components of |
| 267 |
a person's name, such as the person's first name and surname. This template |
| 268 |
assembles those into a string. |
| 269 |
--> |
| 270 |
<xsl:template name="db.personname"> |
| 271 |
<xsl:param name="node" select="."/> |
| 272 |
<xsl:choose> |
| 273 |
<xsl:when test="$node/personname or $node/db:personname"> |
| 274 |
<xsl:call-template name="db.personname"> |
| 275 |
<xsl:with-param name="node" select="$node/personname | $node/db:personname"/> |
| 276 |
</xsl:call-template> |
| 277 |
</xsl:when> |
| 278 |
<xsl:when test="$node/db:orgname"> |
| 279 |
<xsl:apply-templates select="$node/db:orgname"/> |
| 280 |
</xsl:when> |
| 281 |
<xsl:when test="$node/self::collab or $node/self::db:collab"> |
| 282 |
<xsl:apply-templates select="$node/collabname | |
| 283 |
$node/db:org | $node/db:orgname | $node/db:person | $node/db:personname"/> |
| 284 |
</xsl:when> |
| 285 |
<xsl:when test="$node/self::corpauthor or $node/self::corpcredit"> |
| 286 |
<xsl:apply-templates select="$node"/> |
| 287 |
</xsl:when> |
| 288 |
<xsl:when test="$node/self::db:personname and not($node/db:surname)"> |
| 289 |
<xsl:apply-templates select="$node/node()"/> |
| 290 |
</xsl:when> |
| 291 |
<!-- family-given --> |
| 292 |
<xsl:when test="$node/@role = 'family-given'"> |
| 293 |
<xsl:apply-templates select="($node/surname | $node/db:surname)[1]"/> |
| 294 |
<xsl:if test="$node/surname | $node/db:surname"> |
| 295 |
<xsl:text> </xsl:text> |
| 296 |
</xsl:if> |
| 297 |
<xsl:apply-templates select="($node/firstname | $node/db:firstname)[1]"/> |
| 298 |
</xsl:when> |
| 299 |
<!-- last-first --> |
| 300 |
<xsl:when test="$node/@role = 'last-first'"> |
| 301 |
<xsl:apply-templates select="($node/surname | $node/db:surname)[1]"/> |
| 302 |
<xsl:if test="$node/surname | $node/db:surname"> |
| 303 |
<xsl:text>, </xsl:text> |
| 304 |
</xsl:if> |
| 305 |
<xsl:apply-templates select="($node/firstname | $node/db:firstname)[1]"/> |
| 306 |
</xsl:when> |
| 307 |
<!-- first-last --> |
| 308 |
<xsl:otherwise> |
| 309 |
<xsl:if test="$node/honorific or $node/db:honorific"> |
| 310 |
<xsl:apply-templates select="($node/honorific | $node/db:honorific)[1]"/> |
| 311 |
</xsl:if> |
| 312 |
<xsl:if test="$node/firstname or $node/db:firstname"> |
| 313 |
<xsl:if test="$node/honorific or $node/db:honorific"> |
| 314 |
<xsl:text> </xsl:text> |
| 315 |
</xsl:if> |
| 316 |
<xsl:apply-templates select="$node/firstname[1] | |
| 317 |
$node/db:firstname[1]"/> |
| 318 |
</xsl:if> |
| 319 |
<xsl:if test="$node/othername or $node/db:othername"> |
| 320 |
<xsl:if test="$node/honorific or $node/firstname or |
| 321 |
$node/db:honorific or $node/db:firstname"> |
| 322 |
<xsl:text> </xsl:text> |
| 323 |
</xsl:if> |
| 324 |
<xsl:apply-templates select="$node/othername[1] | |
| 325 |
$node/db:othername[1]"/> |
| 326 |
</xsl:if> |
| 327 |
<xsl:if test="$node/surname or $node/db:surname"> |
| 328 |
<xsl:if test="$node/honorific or $node/firstname or $node/othername or |
| 329 |
$node/db:honorific or $node/db:firstname or |
| 330 |
$node/db:othername"> |
| 331 |
<xsl:text> </xsl:text> |
| 332 |
</xsl:if> |
| 333 |
<xsl:apply-templates select="$node/surname[1] | $node/db:surname[1]"/> |
| 334 |
</xsl:if> |
| 335 |
<xsl:if test="$node/lineage or $node/db:lineage"> |
| 336 |
<xsl:text>, </xsl:text> |
| 337 |
<xsl:apply-templates select="$node/lineage[1] | $node/db:lineage[1]"/> |
| 338 |
</xsl:if> |
| 339 |
</xsl:otherwise> |
| 340 |
</xsl:choose> |
| 341 |
</xsl:template> |
| 342 |
|
| 343 |
|
| 344 |
<!--**========================================================================== |
| 345 |
db.personname.list |
| 346 |
Outputs a list of people's names |
| 347 |
$nodes: The elements containing tags such as `firstname` and `surname` |
| 348 |
|
| 349 |
This template outputs a list of names of people as modelled by the `personname` |
| 350 |
element. The `personname` element allows authors to mark up components of a |
| 351 |
person's name, such as the person's first name and surname. |
| 352 |
--> |
| 353 |
<xsl:template name="db.personname.list"> |
| 354 |
<xsl:param name="nodes"/> |
| 355 |
<xsl:for-each select="$nodes"> |
| 356 |
<xsl:choose> |
| 357 |
<xsl:when test="position() = 1"/> |
| 358 |
<xsl:when test="last() = 2"> |
| 359 |
<xsl:call-template name="l10n.gettext"> |
| 360 |
<xsl:with-param name="msgid" select="' and '"/> |
| 361 |
</xsl:call-template> |
| 362 |
</xsl:when> |
| 363 |
<xsl:when test="position() = last()"> |
| 364 |
<xsl:call-template name="l10n.gettext"> |
| 365 |
<xsl:with-param name="msgid" select="', and '"/> |
| 366 |
</xsl:call-template> |
| 367 |
</xsl:when> |
| 368 |
<xsl:otherwise> |
| 369 |
<xsl:call-template name="l10n.gettext"> |
| 370 |
<xsl:with-param name="msgid" select="', '"/> |
| 371 |
</xsl:call-template> |
| 372 |
</xsl:otherwise> |
| 373 |
</xsl:choose> |
| 374 |
<xsl:call-template name="db.personname"> |
| 375 |
<xsl:with-param name="node" select="."/> |
| 376 |
</xsl:call-template> |
| 377 |
</xsl:for-each> |
| 378 |
</xsl:template> |
| 379 |
|
| 380 |
</xsl:stylesheet> |