| 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:mal="http://projectmallard.org/1.0/" |
| 19 |
xmlns:cache="http://projectmallard.org/cache/1.0/" |
| 20 |
xmlns:exsl="http://exslt.org/common" |
| 21 |
xmlns:str="http://exslt.org/strings" |
| 22 |
exclude-result-prefixes="mal cache exsl str" |
| 23 |
version="1.0"> |
| 24 |
|
| 25 |
<!--!!========================================================================== |
| 26 |
Mallard Links |
| 27 |
Common linking utilities for Mallard documents. |
| 28 |
@revision[version=3.4 date=2012-01-17 status=final] |
| 29 |
|
| 30 |
This stylesheet contains various utilities for handling links in Mallard |
| 31 |
documents. The templates in this stylesheet make it easier to handle the |
| 32 |
different linking mechanisms in Mallard, including the dynamic automatic |
| 33 |
linking systems. |
| 34 |
--> |
| 35 |
|
| 36 |
|
| 37 |
<!--@@========================================================================== |
| 38 |
mal.cache.file |
| 39 |
The location of the cache file. |
| 40 |
@revision[version=3.0 date=2010-01-02 status=final] |
| 41 |
|
| 42 |
In order to locate and process links between pages, this stylesheet requires |
| 43 |
a Mallard cache file. Use this parameter to pass the path to a valid cache |
| 44 |
file. |
| 45 |
--> |
| 46 |
<xsl:param name="mal.cache.file"/> |
| 47 |
|
| 48 |
|
| 49 |
<!--@@========================================================================== |
| 50 |
mal.cache |
| 51 |
The cache document as a node set. |
| 52 |
@revision[version=3.0 date=2010-01-02 status=final] |
| 53 |
|
| 54 |
This parameter points to the root `cache:cache` element of a Mallard cache |
| 55 |
document. By default, it selects the root element from the file provided in |
| 56 |
{mal.cache.file}. |
| 57 |
|
| 58 |
Some processing tools may create a Mallard cache document without outputting |
| 59 |
it to a file. Those tools can use this parameter directly. |
| 60 |
--> |
| 61 |
<xsl:param name="mal.cache" select="document($mal.cache.file, /)/cache:cache"/> |
| 62 |
|
| 63 |
|
| 64 |
<!--++========================================================================== |
| 65 |
mal.cache.key |
| 66 |
Get a page or section from the `id` attribute. |
| 67 |
@revision[version=3.4 date=2012-01-25 status=final] |
| 68 |
|
| 69 |
This key returns a `page` or `section` element from a Mallard cache file from |
| 70 |
the `id` attribute. In cache files, the `id` attribute of `section` elements |
| 71 |
is set to a qualified ID by prefixing it with the containing page ID and the |
| 72 |
hash character. |
| 73 |
|
| 74 |
The context node must be in the document {mal.cache} when this key is called. |
| 75 |
--> |
| 76 |
<xsl:key name="mal.cache.key" match="cache:cache//*" use="@id"/> |
| 77 |
|
| 78 |
|
| 79 |
<!--++========================================================================== |
| 80 |
mal.cache.link.key |
| 81 |
Get `link` elements from a link type and `xref` attribute. |
| 82 |
@revision[version=3.4 date=2012-01-25 status=final] |
| 83 |
|
| 84 |
This key returns all `link` elements from a Mallard cache file from the `type` |
| 85 |
and `xref` attributes. They key is the concatenation of the `type` attribute, |
| 86 |
the colon character, and the `xref` attribute. Only `link` elements with both |
| 87 |
a `type` and `xref` attribute are supported. |
| 88 |
|
| 89 |
The context node must be in the document {mal.cache} when this key is called. |
| 90 |
--> |
| 91 |
<xsl:key name="mal.cache.link.key" |
| 92 |
match="mal:info/mal:link[@type][@xref]" |
| 93 |
use="concat(@type, ':', @xref)"/> |
| 94 |
|
| 95 |
|
| 96 |
<!--@@========================================================================== |
| 97 |
mal.link.prefix |
| 98 |
A prefix for link targets. |
| 99 |
@revision[version=3.4 date=2012-01-17 status=final] |
| 100 |
|
| 101 |
When link targets are constructed by {mal.link.target} from `xref` attributes, |
| 102 |
this string is prepended. This can be used, for example, to specify absolute |
| 103 |
directories or URLs. |
| 104 |
--> |
| 105 |
<xsl:param name="mal.link.prefix"/> |
| 106 |
|
| 107 |
|
| 108 |
<!--@@========================================================================== |
| 109 |
mal.link.extension |
| 110 |
The filename extension for output files. |
| 111 |
@revision[version=3.4 date=2012-01-17 status=final] |
| 112 |
|
| 113 |
When link targets are constructed by {mal.link.target} from `xref` attributes, |
| 114 |
this string is appended. This is used to specify the file extension when creating |
| 115 |
output files from Mallard pages. |
| 116 |
--> |
| 117 |
<xsl:param name="mal.link.extension"/> |
| 118 |
|
| 119 |
|
| 120 |
<!--@@========================================================================== |
| 121 |
mal.link.default_root |
| 122 |
The default root ID. |
| 123 |
@revision[version=3.4 date=2012-01-17 status=final] |
| 124 |
|
| 125 |
This parameter provides the default ID for the page that is taken to be the |
| 126 |
root of the document. By default, `'index'` is used. This should not be |
| 127 |
changed for normal Mallard documents. It may be necessary to change it for |
| 128 |
some Mallard extension formats. |
| 129 |
--> |
| 130 |
<xsl:param name="mal.link.default_root" select="'index'"/> |
| 131 |
|
| 132 |
|
| 133 |
<!--**========================================================================== |
| 134 |
mal.link.linkid |
| 135 |
Output the fully qualified link ID for a page or section. |
| 136 |
@revision[version=3.0 date=2010-01-02 status=final] |
| 137 |
|
| 138 |
[xsl:params] |
| 139 |
$node: The `page` or `section` element to generate a link ID for. |
| 140 |
|
| 141 |
This template outputs the fully qualified link ID for a page or section. For |
| 142 |
`page` elements, the link ID is identical to the ID. For `section` elements, |
| 143 |
however, the link ID is the containing page ID and the section ID, joined with |
| 144 |
the `#` character. |
| 145 |
|
| 146 |
The link ID is used in Mallard cache files to ensure all `id` attributes are |
| 147 |
unique. All of the templates in this stylesheet that use a link ID use this |
| 148 |
template or {mal.link.xref.linkid}. |
| 149 |
--> |
| 150 |
<xsl:template name="mal.link.linkid"> |
| 151 |
<xsl:param name="node" select="."/> |
| 152 |
<xsl:choose> |
| 153 |
<xsl:when test="contains($node/@id, '#')"> |
| 154 |
<xsl:value-of select="$node/@id"/> |
| 155 |
</xsl:when> |
| 156 |
<xsl:when test="$node/self::mal:section"> |
| 157 |
<xsl:value-of select="concat($node/ancestor::mal:page[1]/@id, '#', $node/@id)"/> |
| 158 |
</xsl:when> |
| 159 |
<xsl:otherwise> |
| 160 |
<xsl:value-of select="$node/@id"/> |
| 161 |
</xsl:otherwise> |
| 162 |
</xsl:choose> |
| 163 |
</xsl:template> |
| 164 |
|
| 165 |
|
| 166 |
<!--**========================================================================== |
| 167 |
mal.link.xref.linkid |
| 168 |
Output the fully qualified link ID for an `xref` attribute. |
| 169 |
@revision[version=3.0 date=2010-01-02 status=final] |
| 170 |
|
| 171 |
[xsl:params] |
| 172 |
$node: The element containing an `xref` attribute. |
| 173 |
$xref: The `xref` value to generate a link ID from. |
| 174 |
|
| 175 |
This template outputs the fully qualified link ID for an `xref` attribute. |
| 176 |
This may simply be $xref, but if $xref starts with the `#` character, it |
| 177 |
is prefixed with the ID of the page that contains $node. |
| 178 |
|
| 179 |
See {mal.link.linkid} for more on link IDs. |
| 180 |
--> |
| 181 |
<xsl:template name="mal.link.xref.linkid"> |
| 182 |
<xsl:param name="node" select="."/> |
| 183 |
<xsl:param name="xref" select="$node/@xref"/> |
| 184 |
<xsl:if test="starts-with($xref, '#')"> |
| 185 |
<xsl:value-of select="$node/ancestor-or-self::mal:page/@id"/> |
| 186 |
</xsl:if> |
| 187 |
<xsl:value-of select="$xref"/> |
| 188 |
</xsl:template> |
| 189 |
|
| 190 |
|
| 191 |
<!--**========================================================================== |
| 192 |
mal.link.content |
| 193 |
Output the content for a `link` element. |
| 194 |
@revision[version=3.18 date=2015-06-06 status=final] |
| 195 |
|
| 196 |
[xsl:params] |
| 197 |
$node: The `link` or other element creating the link. |
| 198 |
$action: The `action` attribute of $node. |
| 199 |
$xref: The `xref` attribute of $node. |
| 200 |
$href: The `href` attribute of $node. |
| 201 |
$role: A space-separated list of link roles, used to select the appropriate title. |
| 202 |
$info: An `info` element that overrides the info found in a target node. |
| 203 |
|
| 204 |
This template outputs the automatic text content for a link. It should only |
| 205 |
be used for links that do not have specified content. If $xref points to a |
| 206 |
valid page or section, the appropriate link title from that page or section |
| 207 |
will be selected, based on the list of roles in $role. The first role for |
| 208 |
which a matching link title is found will be used. Otherwise, the link title |
| 209 |
without a role is used, or the primary title. The {mal.link.content.mode} |
| 210 |
mode is applied to the contents of that title. Stylesheets using this template |
| 211 |
should map that mode to inline processing. |
| 212 |
|
| 213 |
For inline links, $node should be the `link` element. For links from a |
| 214 |
`links` element, $node should be that `links` element, or the containing |
| 215 |
element when the `links` element is implicit. |
| 216 |
|
| 217 |
This template first calls {mal.link.content.custom} with the same arguments. |
| 218 |
If that template returns a non-empty result, it is used as the return value, |
| 219 |
overriding any other behavior of this template. |
| 220 |
|
| 221 |
If only $href is provided, that URL is used as the text content. If a target |
| 222 |
page or section cannot be found, $xref is used as the text content. |
| 223 |
|
| 224 |
Normally, this template automatically looks up information from a targret node |
| 225 |
according to the $xref parameter. However, if the $info parameter is given, |
| 226 |
information in that node set is used instead. This is useful for external info |
| 227 |
links, where the target information is provided as child elements to the `link` |
| 228 |
element. |
| 229 |
--> |
| 230 |
<xsl:template name="mal.link.content"> |
| 231 |
<xsl:param name="node" select="."/> |
| 232 |
<xsl:param name="action" select="$node/@action"/> |
| 233 |
<xsl:param name="xref" select="$node/@xref"/> |
| 234 |
<xsl:param name="href" select="$node/@href"/> |
| 235 |
<xsl:param name="role" select="''"/> |
| 236 |
<xsl:param name="info" select="/false"/> |
| 237 |
<xsl:variable name="custom"> |
| 238 |
<xsl:call-template name="mal.link.content.custom"> |
| 239 |
<xsl:with-param name="node" select="$node"/> |
| 240 |
<xsl:with-param name="action" select="$action"/> |
| 241 |
<xsl:with-param name="xref" select="$xref"/> |
| 242 |
<xsl:with-param name="href" select="$href"/> |
| 243 |
<xsl:with-param name="role" select="$role"/> |
| 244 |
<xsl:with-param name="info" select="$info"/> |
| 245 |
</xsl:call-template> |
| 246 |
</xsl:variable> |
| 247 |
<xsl:choose> |
| 248 |
<xsl:when test="exsl:node-set($custom)/node()"> |
| 249 |
<xsl:copy-of select="$custom"/> |
| 250 |
</xsl:when> |
| 251 |
<xsl:otherwise> |
| 252 |
<xsl:variable name="linkid"> |
| 253 |
<xsl:call-template name="mal.link.xref.linkid"> |
| 254 |
<xsl:with-param name="node" select="$node"/> |
| 255 |
<xsl:with-param name="xref" select="$xref"/> |
| 256 |
</xsl:call-template> |
| 257 |
</xsl:variable> |
| 258 |
<xsl:for-each select="$mal.cache"> |
| 259 |
<xsl:variable name="target" select="key('mal.cache.key', $linkid)"/> |
| 260 |
<xsl:choose> |
| 261 |
<xsl:when test="$target or $info"> |
| 262 |
<xsl:variable name="infos" select="$target/mal:info | $info"/> |
| 263 |
<xsl:variable name="titles" select="$infos/mal:title[@type = 'link']"/> |
| 264 |
<xsl:variable name="realrole"> |
| 265 |
<xsl:for-each select="str:split($role)"> |
| 266 |
<xsl:variable name="thisrole" select="string(.)"/> |
| 267 |
<xsl:if test="$titles[@role=$thisrole]"> |
| 268 |
<xsl:value-of select="concat($thisrole, ' ')"/> |
| 269 |
</xsl:if> |
| 270 |
</xsl:for-each> |
| 271 |
</xsl:variable> |
| 272 |
<xsl:choose> |
| 273 |
<xsl:when test="$realrole != ''"> |
| 274 |
<xsl:apply-templates mode="mal.link.content.mode" |
| 275 |
select="$titles[@role = substring-before($realrole, ' ')][1]/node()"/> |
| 276 |
</xsl:when> |
| 277 |
<xsl:when test="$titles[not(@role)]"> |
| 278 |
<xsl:apply-templates mode="mal.link.content.mode" |
| 279 |
select="$titles[not(@role)][1]/node()"/> |
| 280 |
</xsl:when> |
| 281 |
<xsl:when test="$info/mal:title[not(@type)]"> |
| 282 |
<xsl:apply-templates mode="mal.link.content.mode" |
| 283 |
select="$info/mal:title[not(@type)][1]/node()"/> |
| 284 |
</xsl:when> |
| 285 |
<xsl:otherwise> |
| 286 |
<xsl:apply-templates mode="mal.link.content.mode" |
| 287 |
select="$target/mal:title[1]/node()"/> |
| 288 |
</xsl:otherwise> |
| 289 |
</xsl:choose> |
| 290 |
</xsl:when> |
| 291 |
<xsl:otherwise> |
| 292 |
<xsl:choose> |
| 293 |
<xsl:when test="$href"> |
| 294 |
<xsl:value-of select="$href"/> |
| 295 |
</xsl:when> |
| 296 |
<xsl:when test="$xref"> |
| 297 |
<xsl:value-of select="$xref"/> |
| 298 |
</xsl:when> |
| 299 |
<xsl:when test="$action"> |
| 300 |
<xsl:value-of select="$action"/> |
| 301 |
</xsl:when> |
| 302 |
</xsl:choose> |
| 303 |
</xsl:otherwise> |
| 304 |
</xsl:choose> |
| 305 |
</xsl:for-each> |
| 306 |
</xsl:otherwise> |
| 307 |
</xsl:choose> |
| 308 |
</xsl:template> |
| 309 |
|
| 310 |
|
| 311 |
<!--**========================================================================== |
| 312 |
mal.link.content.custom |
| 313 |
Output the content for a custom `link` element. |
| 314 |
:Stub: true |
| 315 |
@revision[version=3.18 date=2015-06-06 status=final] |
| 316 |
|
| 317 |
[xsl:params] |
| 318 |
$node: The `link` or other element creating the link. |
| 319 |
$action: The `action` attribute of $node. |
| 320 |
$xref: The `xref` attribute of $node. |
| 321 |
$href: The `href` attribute of $node. |
| 322 |
$role: A space-separated list of link roles, used to select the appropriate title. |
| 323 |
$info: An `info` element that overrides the info found in a target node. |
| 324 |
|
| 325 |
This template is called by {mal.link.content} to create content for custom |
| 326 |
links. Use this template to support the `action` attribute or extended `xref` |
| 327 |
attributes containing slash or colon characters. |
| 328 |
--> |
| 329 |
<xsl:template name="mal.link.content.custom"> |
| 330 |
<xsl:param name="node" select="."/> |
| 331 |
<xsl:param name="action" select="$node/@action"/> |
| 332 |
<xsl:param name="xref" select="$node/@xref"/> |
| 333 |
<xsl:param name="href" select="$node/@href"/> |
| 334 |
<xsl:param name="role" select="''"/> |
| 335 |
<xsl:param name="info" select="/false"/> |
| 336 |
</xsl:template> |
| 337 |
|
| 338 |
|
| 339 |
<!--%%========================================================================== |
| 340 |
mal.link.content.mode |
| 341 |
Output the content for a link from the contents of a `title` element. |
| 342 |
@revision[version=3.0 date=2010-01-02 status=final] |
| 343 |
|
| 344 |
This mode is applied to the contents of a `title` element by {mal.link.content}. |
| 345 |
By default, it returns the string value of its input. Stylesheets that use |
| 346 |
{mal.link.content} should map this mode to inline processing. |
| 347 |
--> |
| 348 |
<xsl:template mode="mal.link.content.mode" match="* | text()"> |
| 349 |
<xsl:value-of select="."/> |
| 350 |
</xsl:template> |
| 351 |
|
| 352 |
|
| 353 |
<!--**========================================================================== |
| 354 |
mal.link.desc |
| 355 |
Output the desc content for a `link` element. |
| 356 |
@revision[version=3.18 date=2015-06-06 status=final] |
| 357 |
|
| 358 |
[xsl:params] |
| 359 |
$node: The `link` or other element creating the link. |
| 360 |
$action: The `action` attribute of $node. |
| 361 |
$xref: The `xref` attribute of $node. |
| 362 |
$href: The `href` attribute of $node. |
| 363 |
$role: A space-separated list of link roles, used to select the appropriate desc. |
| 364 |
$info: An `info` element that overrides the info found in a target node. |
| 365 |
|
| 366 |
This template outputs the secondary desc text content for a link. If $xref |
| 367 |
points to a valid page or section, the desc from that page or section will be |
| 368 |
used. The {mal.link.content.mode} mode is applied to the contents of that |
| 369 |
desc. Stylesheets using this template should map that mode to inline processing. |
| 370 |
|
| 371 |
For inline links, $node should be the `link` element. For links from a |
| 372 |
`links` element, $node should be that `links` element, or the containing |
| 373 |
element when the `links` element is implicit. |
| 374 |
|
| 375 |
This template first calls {mal.link.desc.custom} with the same arguments. |
| 376 |
If that template returns a non-empty result, it is used as the return value, |
| 377 |
overriding any other behavior of this template. |
| 378 |
|
| 379 |
Normally, this template automatically looks up information from a targret node |
| 380 |
according to the $xref parameter. However, if the $info parameter is given, |
| 381 |
information in that node set is used instead. This is useful for external info |
| 382 |
links, where the target information is provided as child elements to the `link` |
| 383 |
element. |
| 384 |
--> |
| 385 |
<xsl:template name="mal.link.desc"> |
| 386 |
<xsl:param name="node" select="."/> |
| 387 |
<xsl:param name="action" select="$node/@action"/> |
| 388 |
<xsl:param name="xref" select="$node/@xref"/> |
| 389 |
<xsl:param name="href" select="$node/@href"/> |
| 390 |
<xsl:param name="role" select="''"/> |
| 391 |
<xsl:param name="info" select="/false"/> |
| 392 |
<xsl:variable name="custom"> |
| 393 |
<xsl:call-template name="mal.link.desc.custom"> |
| 394 |
<xsl:with-param name="node" select="$node"/> |
| 395 |
<xsl:with-param name="action" select="$action"/> |
| 396 |
<xsl:with-param name="xref" select="$xref"/> |
| 397 |
<xsl:with-param name="href" select="$href"/> |
| 398 |
<xsl:with-param name="role" select="$role"/> |
| 399 |
<xsl:with-param name="info" select="$info"/> |
| 400 |
</xsl:call-template> |
| 401 |
</xsl:variable> |
| 402 |
<xsl:choose> |
| 403 |
<xsl:when test="exsl:node-set($custom)/node()"> |
| 404 |
<xsl:copy-of select="$custom"/> |
| 405 |
</xsl:when> |
| 406 |
<xsl:otherwise> |
| 407 |
<xsl:variable name="linkid"> |
| 408 |
<xsl:call-template name="mal.link.xref.linkid"> |
| 409 |
<xsl:with-param name="node" select="$node"/> |
| 410 |
<xsl:with-param name="xref" select="$xref"/> |
| 411 |
</xsl:call-template> |
| 412 |
</xsl:variable> |
| 413 |
<xsl:for-each select="$mal.cache"> |
| 414 |
<xsl:variable name="target" select="key('mal.cache.key', $linkid)"/> |
| 415 |
<xsl:choose> |
| 416 |
<xsl:when test="$target or $info"> |
| 417 |
<xsl:variable name="infos" select="$target/mal:info | $info"/> |
| 418 |
<xsl:variable name="typedescs" select="$infos/mal:desc[@type = 'link']"/> |
| 419 |
<xsl:variable name="notypedescs" select="$infos/mal:desc[not(@type)]"/> |
| 420 |
<xsl:variable name="typerole"> |
| 421 |
<xsl:for-each select="str:split($role)"> |
| 422 |
<xsl:variable name="thisrole" select="string(.)"/> |
| 423 |
<xsl:if test="$typedescs[@role=$thisrole]"> |
| 424 |
<xsl:value-of select="concat($thisrole, ' ')"/> |
| 425 |
</xsl:if> |
| 426 |
</xsl:for-each> |
| 427 |
</xsl:variable> |
| 428 |
<xsl:variable name="notyperole"> |
| 429 |
<xsl:for-each select="str:split($role)"> |
| 430 |
<xsl:variable name="thisrole" select="string(.)"/> |
| 431 |
<xsl:if test="$notypedescs[@role=$thisrole]"> |
| 432 |
<xsl:value-of select="concat($thisrole, ' ')"/> |
| 433 |
</xsl:if> |
| 434 |
</xsl:for-each> |
| 435 |
</xsl:variable> |
| 436 |
<xsl:choose> |
| 437 |
<xsl:when test="$typerole != ''"> |
| 438 |
<xsl:apply-templates mode="mal.link.content.mode" |
| 439 |
select="$typedescs[@role = substring-before($typerole, ' ')][1]/node()"/> |
| 440 |
</xsl:when> |
| 441 |
<xsl:when test="$notyperole != ''"> |
| 442 |
<xsl:apply-templates mode="mal.link.content.mode" |
| 443 |
select="$notypedescs[@role = substring-before($notyperole, ' ')][1]/node()"/> |
| 444 |
</xsl:when> |
| 445 |
<xsl:when test="$typedescs[not(@role)]"> |
| 446 |
<xsl:apply-templates mode="mal.link.content.mode" |
| 447 |
select="$typedescs[not(@role)][1]/node()"/> |
| 448 |
</xsl:when> |
| 449 |
<xsl:when test="$notypedescs[not(@role)]"> |
| 450 |
<xsl:apply-templates mode="mal.link.content.mode" |
| 451 |
select="$notypedescs[not(@role)][1]/node()"/> |
| 452 |
</xsl:when> |
| 453 |
</xsl:choose> |
| 454 |
</xsl:when> |
| 455 |
</xsl:choose> |
| 456 |
</xsl:for-each> |
| 457 |
</xsl:otherwise> |
| 458 |
</xsl:choose> |
| 459 |
</xsl:template> |
| 460 |
|
| 461 |
|
| 462 |
<!--**========================================================================== |
| 463 |
mal.link.desc.custom |
| 464 |
Output the desc content for a custom `link` element. |
| 465 |
:Stub: true |
| 466 |
@revision[version=3.18 date=2015-06-06 status=final] |
| 467 |
|
| 468 |
[xsl:params] |
| 469 |
$node: The `link` or other element creating the link. |
| 470 |
$action: The `action` attribute of $node. |
| 471 |
$xref: The `xref` attribute of $node. |
| 472 |
$href: The `href` attribute of $node. |
| 473 |
$role: A space-separated list of link roles, used to select the appropriate title. |
| 474 |
$info: An `info` element that overrides the info found in a target node. |
| 475 |
|
| 476 |
This template is called by {mal.link.desc} to create content for custom links. |
| 477 |
Use this template to support the `action` attribute or extended `xref` |
| 478 |
attributes containing slash or colon characters. |
| 479 |
--> |
| 480 |
<xsl:template name="mal.link.desc.custom"> |
| 481 |
<xsl:param name="node" select="."/> |
| 482 |
<xsl:param name="action" select="$node/@action"/> |
| 483 |
<xsl:param name="xref" select="$node/@xref"/> |
| 484 |
<xsl:param name="href" select="$node/@href"/> |
| 485 |
<xsl:param name="role" select="''"/> |
| 486 |
<xsl:param name="info" select="/false"/> |
| 487 |
</xsl:template> |
| 488 |
|
| 489 |
|
| 490 |
<!--**========================================================================== |
| 491 |
mal.link.tooltip |
| 492 |
Output a tooltip for a `link` element. |
| 493 |
@revision[version=3.18 date=2015-06-06 status=final] |
| 494 |
|
| 495 |
[xsl:params] |
| 496 |
$node: The `link` or other element creating the link. |
| 497 |
$action: The `action` attribute of $node. |
| 498 |
$xref: The `xref` attribute of $node. |
| 499 |
$href: The `href` attribute of $node. |
| 500 |
$role: A space-separated list of link roles, used to select the appropriate title. |
| 501 |
$info: An `info` element that overrides the info found in a target node. |
| 502 |
|
| 503 |
This template outputs a text-only tooltip for a link. If $xref points to a |
| 504 |
valid page or section, the text title from that page or section will be used. |
| 505 |
If the target does not specify a text title, the primary title is used. |
| 506 |
|
| 507 |
For inline links, $node should be the `link` element. For links from a |
| 508 |
`links` element, $node should be that `links` element, or the containing |
| 509 |
element when the `links` element is implicit. |
| 510 |
|
| 511 |
This template first calls {mal.link.tooltip.custom} with the same arguments. |
| 512 |
If that template returns a non-empty string, it is used as the return value, |
| 513 |
overriding any other behavior of this template. |
| 514 |
|
| 515 |
If only $href is provided, that URL is used as the tooltip. If a target |
| 516 |
page or section cannot be found, $xref is used as the text content. Special |
| 517 |
tooltips may be provided for certain URI schemes. |
| 518 |
|
| 519 |
Normally, this template automatically looks up information from a targret node |
| 520 |
according to the $xref parameter. However, if the $info parameter is given, |
| 521 |
information in that node set is used instead. This is useful for external info |
| 522 |
links, where the target information is provided as child elements to the `link` |
| 523 |
element. |
| 524 |
--> |
| 525 |
<xsl:template name="mal.link.tooltip"> |
| 526 |
<xsl:param name="node" select="."/> |
| 527 |
<xsl:param name="action" select="$node/@action"/> |
| 528 |
<xsl:param name="xref" select="$node/@xref"/> |
| 529 |
<xsl:param name="href" select="$node/@href"/> |
| 530 |
<xsl:param name="role" select="''"/> |
| 531 |
<xsl:param name="info" select="/false"/> |
| 532 |
<xsl:variable name="custom"> |
| 533 |
<xsl:call-template name="mal.link.tooltip.custom"> |
| 534 |
<xsl:with-param name="node" select="$node"/> |
| 535 |
<xsl:with-param name="action" select="$action"/> |
| 536 |
<xsl:with-param name="xref" select="$xref"/> |
| 537 |
<xsl:with-param name="href" select="$href"/> |
| 538 |
<xsl:with-param name="role" select="$role"/> |
| 539 |
<xsl:with-param name="info" select="$info"/> |
| 540 |
</xsl:call-template> |
| 541 |
</xsl:variable> |
| 542 |
<xsl:choose> |
| 543 |
<xsl:when test="$custom != ''"> |
| 544 |
<xsl:value-of select="$custom"/> |
| 545 |
</xsl:when> |
| 546 |
<xsl:otherwise> |
| 547 |
<xsl:variable name="linkid"> |
| 548 |
<xsl:call-template name="mal.link.xref.linkid"> |
| 549 |
<xsl:with-param name="node" select="$node"/> |
| 550 |
<xsl:with-param name="xref" select="$xref"/> |
| 551 |
</xsl:call-template> |
| 552 |
</xsl:variable> |
| 553 |
<xsl:for-each select="$mal.cache"> |
| 554 |
<xsl:variable name="target" select="key('mal.cache.key', $linkid)"/> |
| 555 |
<xsl:variable name="infos" select="$target/mal:info | $info"/> |
| 556 |
<xsl:choose> |
| 557 |
<xsl:when test="$infos/mal:title[@type = 'text']"> |
| 558 |
<xsl:value-of select="normalize-space($infos/mal:title[@type = 'text'][1])"/> |
| 559 |
</xsl:when> |
| 560 |
<xsl:when test="$info/mal:title[not(@type)]"> |
| 561 |
<xsl:value-of select="normalize-space($info/mal:title[not(@type)])"/> |
| 562 |
</xsl:when> |
| 563 |
<xsl:when test="$target/mal:title"> |
| 564 |
<xsl:value-of select="normalize-space($target/mal:title[1])"/> |
| 565 |
</xsl:when> |
| 566 |
<xsl:when test="starts-with($href, 'mailto:')"> |
| 567 |
<xsl:call-template name="l10n.gettext"> |
| 568 |
<xsl:with-param name="msgid" select="'email.tooltip'"/> |
| 569 |
<xsl:with-param name="string"> |
| 570 |
<xsl:call-template name="utils.email_address"> |
| 571 |
<xsl:with-param name="url" select="$href"/> |
| 572 |
</xsl:call-template> |
| 573 |
</xsl:with-param> |
| 574 |
<xsl:with-param name="format" select="true()"/> |
| 575 |
</xsl:call-template> |
| 576 |
</xsl:when> |
| 577 |
<xsl:when test="$href"> |
| 578 |
<xsl:value-of select="$href"/> |
| 579 |
</xsl:when> |
| 580 |
<xsl:otherwise> |
| 581 |
<xsl:value-of select="$xref"/> |
| 582 |
</xsl:otherwise> |
| 583 |
</xsl:choose> |
| 584 |
</xsl:for-each> |
| 585 |
</xsl:otherwise> |
| 586 |
</xsl:choose> |
| 587 |
</xsl:template> |
| 588 |
|
| 589 |
|
| 590 |
<!--**========================================================================== |
| 591 |
mal.link.tooltip.custom |
| 592 |
Output a tooltip for a custom `link` element. |
| 593 |
:Stub: true |
| 594 |
@revision[version=3.18 date=2015-06-06 status=final] |
| 595 |
|
| 596 |
[xsl:params] |
| 597 |
$node: The `link` or other element creating the link. |
| 598 |
$action: The `action` attribute of $node. |
| 599 |
$xref: The `xref` attribute of $node. |
| 600 |
$href: The `href` attribute of $node. |
| 601 |
$role: A space-separated list of link roles, used to select the appropriate title. |
| 602 |
$info: An `info` element that overrides the info found in a target node. |
| 603 |
|
| 604 |
This template is called by {mal.link.tooltip} to create tooltips for custom |
| 605 |
links. Use this template to support the `action` attribute or extended `xref` |
| 606 |
attributes containing slash or colon characters. |
| 607 |
--> |
| 608 |
<xsl:template name="mal.link.tooltip.custom"> |
| 609 |
<xsl:param name="node" select="."/> |
| 610 |
<xsl:param name="action" select="$node/@action"/> |
| 611 |
<xsl:param name="xref" select="$node/@xref"/> |
| 612 |
<xsl:param name="href" select="$node/@href"/> |
| 613 |
<xsl:param name="role" select="''"/> |
| 614 |
<xsl:param name="info" select="/false"/> |
| 615 |
</xsl:template> |
| 616 |
|
| 617 |
|
| 618 |
<!--**========================================================================== |
| 619 |
mal.link.target |
| 620 |
Output the target URL for a `link` or other linking element. |
| 621 |
@revision[version=3.28 date=2017-08-11 status=final] |
| 622 |
|
| 623 |
[xsl:params] |
| 624 |
$node: The `link` or other element creating the link. |
| 625 |
$action: The `action` attribute of $node. |
| 626 |
$xref: The `xref` attribute of $node. |
| 627 |
$href: The `href` attribute of $node. |
| 628 |
|
| 629 |
This template outputs a URL for a `link` element or another element using |
| 630 |
linking attributes. If $xref points to a valid page or section, it uses |
| 631 |
a file name based on the ID of the target page plus {mal.link.extension}. |
| 632 |
Otherwise, the link will point to $href. |
| 633 |
|
| 634 |
For inline links, $node should be the `link` element. For links from a |
| 635 |
`links` element, $node should be that `links` element, or the containing |
| 636 |
element when the `links` element is implicit. |
| 637 |
|
| 638 |
This template first calls {mal.link.target.custom} with the same arguments. |
| 639 |
If that template returns a non-empty string, it is used as the return value, |
| 640 |
overriding any other behavior of this template. |
| 641 |
|
| 642 |
If $xref contains a `/` or `:` character, this template calls |
| 643 |
{mal.link.target.extended}, which by default just uses $href instead. |
| 644 |
Override that template to provide extended xref behavior. |
| 645 |
--> |
| 646 |
<xsl:template name="mal.link.target"> |
| 647 |
<xsl:param name="node" select="."/> |
| 648 |
<xsl:param name="action" select="$node/@action"/> |
| 649 |
<xsl:param name="xref" select="$node/@xref"/> |
| 650 |
<xsl:param name="href" select="$node/@href"/> |
| 651 |
<xsl:variable name="custom"> |
| 652 |
<xsl:call-template name="mal.link.target.custom"> |
| 653 |
<xsl:with-param name="node" select="$node"/> |
| 654 |
<xsl:with-param name="action" select="$action"/> |
| 655 |
<xsl:with-param name="xref" select="$xref"/> |
| 656 |
<xsl:with-param name="href" select="$href"/> |
| 657 |
</xsl:call-template> |
| 658 |
</xsl:variable> |
| 659 |
<xsl:choose> |
| 660 |
<xsl:when test="$custom != ''"> |
| 661 |
<xsl:value-of select="$custom"/> |
| 662 |
</xsl:when> |
| 663 |
<xsl:otherwise> |
| 664 |
<xsl:call-template name="_mal.link.target.default"> |
| 665 |
<xsl:with-param name="node" select="$node"/> |
| 666 |
<xsl:with-param name="action" select="$action"/> |
| 667 |
<xsl:with-param name="xref" select="$xref"/> |
| 668 |
<xsl:with-param name="href" select="$href"/> |
| 669 |
</xsl:call-template> |
| 670 |
</xsl:otherwise> |
| 671 |
</xsl:choose> |
| 672 |
</xsl:template> |
| 673 |
|
| 674 |
|
| 675 |
<!--#* _mal.link.target.default --> |
| 676 |
<!-- |
| 677 |
Note sure yet if I want to make this public API. If so, we should |
| 678 |
do it to all the mal.link.* templates. This allows you, if you |
| 679 |
really want, to override mal.link.target completely, but still |
| 680 |
fallback to the built-in behavior. |
| 681 |
--> |
| 682 |
<xsl:template name="_mal.link.target.default"> |
| 683 |
<xsl:param name="node" select="."/> |
| 684 |
<xsl:param name="action" select="$node/@action"/> |
| 685 |
<xsl:param name="xref" select="$node/@xref"/> |
| 686 |
<xsl:param name="href" select="$node/@href"/> |
| 687 |
<xsl:choose> |
| 688 |
<xsl:when test="string($xref) = ''"> |
| 689 |
<xsl:value-of select="$href"/> |
| 690 |
</xsl:when> |
| 691 |
<xsl:when test="contains($xref, '/') or contains($xref, ':')"> |
| 692 |
<xsl:call-template name="mal.link.target.extended"> |
| 693 |
<xsl:with-param name="node" select="$node"/> |
| 694 |
<xsl:with-param name="action" select="$action"/> |
| 695 |
<xsl:with-param name="xref" select="$xref"/> |
| 696 |
<xsl:with-param name="href" select="$href"/> |
| 697 |
</xsl:call-template> |
| 698 |
</xsl:when> |
| 699 |
<xsl:when test="contains($xref, '#')"> |
| 700 |
<xsl:variable name="pageid" select="substring-before($xref, '#')"/> |
| 701 |
<xsl:variable name="sectionid" select="substring-after($xref, '#')"/> |
| 702 |
<xsl:if test="$pageid != ''"> |
| 703 |
<xsl:value-of select="concat($mal.link.prefix, $pageid, $mal.link.extension)"/> |
| 704 |
</xsl:if> |
| 705 |
<xsl:value-of select="concat('#', $sectionid)"/> |
| 706 |
</xsl:when> |
| 707 |
<xsl:otherwise> |
| 708 |
<xsl:value-of select="concat($mal.link.prefix, $xref, $mal.link.extension)"/> |
| 709 |
</xsl:otherwise> |
| 710 |
</xsl:choose> |
| 711 |
</xsl:template> |
| 712 |
|
| 713 |
|
| 714 |
<!--**========================================================================== |
| 715 |
mal.link.target.extended |
| 716 |
Output the target URL for an element with an extended `xref` attribute. |
| 717 |
:Stub: true |
| 718 |
@revision[version=3.28 date=2017-08-11 status=final] |
| 719 |
|
| 720 |
[xsl:params] |
| 721 |
$node: The `link` or other element creating the link. |
| 722 |
$action: The `action` attribute of $node. |
| 723 |
$xref: The `xref` attribute of $node. |
| 724 |
$href: The `href` attribute of $node. |
| 725 |
|
| 726 |
This template is called by {mal.link.target} to create URLs for links with |
| 727 |
a `/` or `:` in the `xref` attribute. By default, it just outputs the |
| 728 |
value of $href. Override this template to provide behavior for extended |
| 729 |
`xref` attributes. |
| 730 |
--> |
| 731 |
<xsl:template name="mal.link.target.extended"> |
| 732 |
<xsl:param name="node" select="."/> |
| 733 |
<xsl:param name="action" select="$node/@action"/> |
| 734 |
<xsl:param name="xref" select="$node/@xref"/> |
| 735 |
<xsl:param name="href" select="$node/@href"/> |
| 736 |
<xsl:value-of select="$href"/> |
| 737 |
</xsl:template> |
| 738 |
|
| 739 |
|
| 740 |
<!--**========================================================================== |
| 741 |
mal.link.target.custom |
| 742 |
Output the target URL for an element with `action` or extended `xref` attributes. |
| 743 |
:Stub: true |
| 744 |
@revision[version=3.4 date=2012-01-17 status=final] |
| 745 |
|
| 746 |
[xsl:params] |
| 747 |
$node: The `link` or other element creating the link. |
| 748 |
$action: The `action` attribute of $node. |
| 749 |
$xref: The `xref` attribute of $node. |
| 750 |
$href: The `href` attribute of $node. |
| 751 |
|
| 752 |
This template is called by {mal.link.target} to create URLs for custom links. |
| 753 |
Use this template to support the `action` attribute or extended `xref` |
| 754 |
attributes containing slash or colon characters. |
| 755 |
--> |
| 756 |
<xsl:template name="mal.link.target.custom"> |
| 757 |
<xsl:param name="node" select="."/> |
| 758 |
<xsl:param name="action" select="$node/@action"/> |
| 759 |
<xsl:param name="xref" select="$node/@xref"/> |
| 760 |
<xsl:param name="href" select="$node/@href"/> |
| 761 |
</xsl:template> |
| 762 |
|
| 763 |
|
| 764 |
<!--**========================================================================== |
| 765 |
mal.link.guidelinks |
| 766 |
Output the guide links for a page or section. |
| 767 |
@revision[version=3.18 date=2015-06-07 status=final] |
| 768 |
|
| 769 |
[xsl:params] |
| 770 |
$node: The `page` or `section` element to generate links for. |
| 771 |
$role: A space-separated list of link roles, used to select the appropriate title, default `"guide"`. |
| 772 |
|
| 773 |
This template outputs all the guide links for a page or section, whether |
| 774 |
declared as guide links in the page or section or as topic links from another |
| 775 |
guide page. It outputs each of the links as a `link` element within the |
| 776 |
Mallard namespace. Each `link` element has an `xref` attribute pointing |
| 777 |
to the target page or section. Or, in the case of external links, the `link` |
| 778 |
element has an `href` attribute pointing to the external resource. |
| 779 |
|
| 780 |
Each `link` element contains a `title` with `type="sort"` providing the |
| 781 |
sort title of the target page or section. The $role attribute is used to |
| 782 |
select a link title to sort on when a sort title is not present. The results |
| 783 |
are not sorted when returned from this template. Use `xsl:sort` on the sort |
| 784 |
titles to sort the results. |
| 785 |
|
| 786 |
When a link comes from a guide link on $node that has an `href` |
| 787 |
attribute but not an `xref` attribute, it is taken to be an external |
| 788 |
link. In that case, the output link has an `href` attribute instead of |
| 789 |
an `xref` attribute, and it has an `info` child element. This element |
| 790 |
has a copy of all the child elements of the source `link` element. |
| 791 |
|
| 792 |
The output is a result tree fragment. To use these results, call |
| 793 |
`exsl:node-set` on them. |
| 794 |
--> |
| 795 |
<xsl:template name="mal.link.guidelinks"> |
| 796 |
<xsl:param name="node" select="."/> |
| 797 |
<xsl:param name="role" select="'guide'"/> |
| 798 |
<xsl:variable name="linkid"> |
| 799 |
<xsl:call-template name="mal.link.linkid"> |
| 800 |
<xsl:with-param name="node" select="$node"/> |
| 801 |
</xsl:call-template> |
| 802 |
</xsl:variable> |
| 803 |
<xsl:variable name="links"> |
| 804 |
<xsl:for-each select="$node/mal:info/mal:link[@type = 'guide']"> |
| 805 |
<xsl:variable name="link" select="."/> |
| 806 |
<xsl:choose> |
| 807 |
<xsl:when test="$link[@xref]"> |
| 808 |
<xsl:variable name="linklinkid"> |
| 809 |
<xsl:call-template name="mal.link.xref.linkid"/> |
| 810 |
</xsl:variable> |
| 811 |
<xsl:for-each select="$mal.cache"> |
| 812 |
<xsl:variable name="linklinknode" select="key('mal.cache.key', $linklinkid)"/> |
| 813 |
<xsl:if test="count($linklinknode) > 0"> |
| 814 |
<mal:link xref="{$linklinkid}"> |
| 815 |
<mal:title type="sort"> |
| 816 |
<xsl:call-template name="mal.link.sorttitle"> |
| 817 |
<xsl:with-param name="node" select="$linklinknode"/> |
| 818 |
<xsl:with-param name="role" select="$role"/> |
| 819 |
</xsl:call-template> |
| 820 |
</mal:title> |
| 821 |
</mal:link> |
| 822 |
</xsl:if> |
| 823 |
</xsl:for-each> |
| 824 |
</xsl:when> |
| 825 |
<xsl:when test="$link[@href]"> |
| 826 |
<mal:link href="{$link/@href}"> |
| 827 |
<mal:title type="sort"> |
| 828 |
<xsl:choose> |
| 829 |
<xsl:when test="mal:title[@type = 'sort']"> |
| 830 |
<xsl:value-of select="normalize-space(mal:title[@type = 'sort'][1])"/> |
| 831 |
</xsl:when> |
| 832 |
<xsl:otherwise> |
| 833 |
<xsl:value-of select="normalize-space(mal:title[not(@type)][1])"/> |
| 834 |
</xsl:otherwise> |
| 835 |
</xsl:choose> |
| 836 |
</mal:title> |
| 837 |
<mal:info> |
| 838 |
<xsl:copy-of select="$link/*"/> |
| 839 |
</mal:info> |
| 840 |
</mal:link> |
| 841 |
</xsl:when> |
| 842 |
</xsl:choose> |
| 843 |
</xsl:for-each> |
| 844 |
</xsl:variable> |
| 845 |
<xsl:copy-of select="$links"/> |
| 846 |
<xsl:variable name="linknodes" select="exsl:node-set($links)/*"/> |
| 847 |
<xsl:for-each select="$mal.cache"> |
| 848 |
<xsl:for-each select="key('mal.cache.link.key', concat('topic:', $linkid))/../.."> |
| 849 |
<xsl:variable name="linklinkid"> |
| 850 |
<xsl:call-template name="mal.link.linkid"/> |
| 851 |
</xsl:variable> |
| 852 |
<xsl:if test="$linklinkid != '' and not($linknodes[@xref = $linklinkid])"> |
| 853 |
<mal:link xref="{$linklinkid}"> |
| 854 |
<mal:title type="sort"> |
| 855 |
<xsl:call-template name="mal.link.sorttitle"> |
| 856 |
<xsl:with-param name="node" select="."/> |
| 857 |
<xsl:with-param name="role" select="$role"/> |
| 858 |
</xsl:call-template> |
| 859 |
</mal:title> |
| 860 |
</mal:link> |
| 861 |
</xsl:if> |
| 862 |
</xsl:for-each> |
| 863 |
</xsl:for-each> |
| 864 |
</xsl:template> |
| 865 |
|
| 866 |
|
| 867 |
<!--**========================================================================== |
| 868 |
mal.link.topiclinks |
| 869 |
Output the topic links for a page or section. |
| 870 |
@revision[version=3.18 date=2015-06-06 status=final] |
| 871 |
|
| 872 |
[xsl:params] |
| 873 |
$node: The `page` or `section` element to generate links for. |
| 874 |
$groups: The list of all valid link groups for $node. |
| 875 |
$role: A space-separated list of link roles, used to select the appropriate title, default `"topic"`. |
| 876 |
|
| 877 |
This template outputs all the topic links for a guide page or section, whether |
| 878 |
declared as topic links in the page or section or as guide links from another |
| 879 |
page or section. It outputs each of the links as a `link` element within the |
| 880 |
Mallard namespace. Each `link` element has an `xref` attribute pointing |
| 881 |
to the target page or section. Or, in the case of external links, the `link` |
| 882 |
element has an `href` attribute pointing to the external resource. |
| 883 |
|
| 884 |
Each `link` element contains a `title` with `type="sort"` providing the |
| 885 |
sort title of the target page or section. The $role attribute is used to |
| 886 |
select a link title to sort on when a sort title is not present. The results |
| 887 |
are not sorted when returned from this template. Use `xsl:sort` on the sort |
| 888 |
titles to sort the results. |
| 889 |
|
| 890 |
Each `link` element also contains a `group` attribute. The `group` |
| 891 |
attribute is normalized. It will either point to a link group declared |
| 892 |
in $groups, or it will be set to `#default`. Each `link` element also |
| 893 |
contains a `groupsort` attribute giving the numerical position of the |
| 894 |
`group` attribute in the normalized group list for $node. |
| 895 |
|
| 896 |
The $groups parameter can be calculated automatically from $node. |
| 897 |
|
| 898 |
When a link comes from a topic link on $node that has an `href` |
| 899 |
attribute but not an `xref` attribute, it is taken to be an external |
| 900 |
link. In that case, the output link has an `href` attribute instead of |
| 901 |
an `xref` attribute, and it has an `info` child element. This element |
| 902 |
has a copy of all the child elements of the source `link` element. |
| 903 |
|
| 904 |
The output is a result tree fragment. To use these results, call |
| 905 |
`exsl:node-set` on them. |
| 906 |
--> |
| 907 |
<xsl:template name="mal.link.topiclinks"> |
| 908 |
<xsl:param name="node" select="."/> |
| 909 |
<xsl:param name="groups"> |
| 910 |
<xsl:variable name="_groups"> |
| 911 |
<xsl:choose> |
| 912 |
<xsl:when test="$node/mal:links[@type = 'topic']"> |
| 913 |
<xsl:text> </xsl:text> |
| 914 |
<xsl:for-each select="$node/mal:links[@type = 'topic']"> |
| 915 |
<xsl:choose> |
| 916 |
<xsl:when test="@groups"> |
| 917 |
<xsl:value-of select="@groups"/> |
| 918 |
</xsl:when> |
| 919 |
<xsl:otherwise> |
| 920 |
<xsl:text>#default</xsl:text> |
| 921 |
</xsl:otherwise> |
| 922 |
</xsl:choose> |
| 923 |
<xsl:text> </xsl:text> |
| 924 |
</xsl:for-each> |
| 925 |
</xsl:when> |
| 926 |
<xsl:otherwise> |
| 927 |
<xsl:value-of select="concat(' ', $node/@groups, ' ')"/> |
| 928 |
</xsl:otherwise> |
| 929 |
</xsl:choose> |
| 930 |
</xsl:variable> |
| 931 |
<xsl:if test="not(contains($_groups, ' #first '))"> |
| 932 |
<xsl:text>#first</xsl:text> |
| 933 |
</xsl:if> |
| 934 |
<xsl:value-of select="$_groups"/> |
| 935 |
<xsl:if test="not(contains($_groups, ' #default '))"> |
| 936 |
<xsl:text>#default </xsl:text> |
| 937 |
</xsl:if> |
| 938 |
<xsl:if test="not(contains($_groups, ' #last '))"> |
| 939 |
<xsl:text>#last </xsl:text> |
| 940 |
</xsl:if> |
| 941 |
</xsl:param> |
| 942 |
<xsl:param name="role" select="'topic'"/> |
| 943 |
<xsl:variable name="groupslist" select="str:split($groups)"/> |
| 944 |
<xsl:variable name="defaultpos"> |
| 945 |
<xsl:for-each select="$groupslist"> |
| 946 |
<xsl:if test="string(.) = '#default'"> |
| 947 |
<xsl:value-of select="position()"/> |
| 948 |
</xsl:if> |
| 949 |
</xsl:for-each> |
| 950 |
</xsl:variable> |
| 951 |
<xsl:variable name="linkid"> |
| 952 |
<xsl:call-template name="mal.link.linkid"> |
| 953 |
<xsl:with-param name="node" select="$node"/> |
| 954 |
</xsl:call-template> |
| 955 |
</xsl:variable> |
| 956 |
<xsl:variable name="links"> |
| 957 |
<xsl:for-each select="$node/mal:info/mal:link[@type = 'topic']"> |
| 958 |
<xsl:variable name="link" select="."/> |
| 959 |
<xsl:variable name="grouppos"> |
| 960 |
<xsl:if test="$link/@group"> |
| 961 |
<xsl:for-each select="$groupslist"> |
| 962 |
<xsl:if test="string(.) = $link/@group"> |
| 963 |
<xsl:value-of select="position()"/> |
| 964 |
<xsl:text> </xsl:text> |
| 965 |
</xsl:if> |
| 966 |
</xsl:for-each> |
| 967 |
</xsl:if> |
| 968 |
</xsl:variable> |
| 969 |
<xsl:variable name="groupsort"> |
| 970 |
<xsl:value-of select="substring-before($grouppos, ' ')"/> |
| 971 |
<xsl:if test="string($grouppos) = ''"> |
| 972 |
<xsl:value-of select="$defaultpos"/> |
| 973 |
</xsl:if> |
| 974 |
</xsl:variable> |
| 975 |
<xsl:variable name="groupattrs"> |
| 976 |
<xsl:attribute name="group"> |
| 977 |
<xsl:value-of select="$groupslist[number($groupsort)]"/> |
| 978 |
</xsl:attribute> |
| 979 |
<xsl:attribute name="groupsort"> |
| 980 |
<xsl:value-of select="$groupsort"/> |
| 981 |
</xsl:attribute> |
| 982 |
</xsl:variable> |
| 983 |
<xsl:choose> |
| 984 |
<xsl:when test="$link[@xref]"> |
| 985 |
<xsl:variable name="linklinkid"> |
| 986 |
<xsl:call-template name="mal.link.xref.linkid"/> |
| 987 |
</xsl:variable> |
| 988 |
<xsl:for-each select="$mal.cache"> |
| 989 |
<xsl:variable name="linklinknode" |
| 990 |
select="key('mal.cache.key', $linklinkid)"/> |
| 991 |
<xsl:if test="count($linklinknode) > 0"> |
| 992 |
<mal:link xref="{$linklinkid}"> |
| 993 |
<xsl:attribute name="group"> |
| 994 |
<xsl:value-of select="$groupslist[number($groupsort)]"/> |
| 995 |
</xsl:attribute> |
| 996 |
<xsl:attribute name="groupsort"> |
| 997 |
<xsl:value-of select="$groupsort"/> |
| 998 |
</xsl:attribute> |
| 999 |
<mal:title type="sort"> |
| 1000 |
<xsl:call-template name="mal.link.sorttitle"> |
| 1001 |
<xsl:with-param name="node" select="$linklinknode"/> |
| 1002 |
<xsl:with-param name="role" select="$role"/> |
| 1003 |
</xsl:call-template> |
| 1004 |
</mal:title> |
| 1005 |
</mal:link> |
| 1006 |
</xsl:if> |
| 1007 |
</xsl:for-each> |
| 1008 |
</xsl:when> |
| 1009 |
<xsl:when test="$link[@href]"> |
| 1010 |
<mal:link href="{$link/@href}"> |
| 1011 |
<xsl:attribute name="group"> |
| 1012 |
<xsl:value-of select="$groupslist[number($groupsort)]"/> |
| 1013 |
</xsl:attribute> |
| 1014 |
<xsl:attribute name="groupsort"> |
| 1015 |
<xsl:value-of select="$groupsort"/> |
| 1016 |
</xsl:attribute> |
| 1017 |
<mal:title type="sort"> |
| 1018 |
<xsl:choose> |
| 1019 |
<xsl:when test="mal:title[@type = 'sort']"> |
| 1020 |
<xsl:value-of select="normalize-space(mal:title[@type = 'sort'][1])"/> |
| 1021 |
</xsl:when> |
| 1022 |
<xsl:otherwise> |
| 1023 |
<xsl:value-of select="normalize-space(mal:title[not(@type)][1])"/> |
| 1024 |
</xsl:otherwise> |
| 1025 |
</xsl:choose> |
| 1026 |
</mal:title> |
| 1027 |
<mal:info> |
| 1028 |
<xsl:copy-of select="$link/*"/> |
| 1029 |
</mal:info> |
| 1030 |
</mal:link> |
| 1031 |
</xsl:when> |
| 1032 |
</xsl:choose> |
| 1033 |
</xsl:for-each> |
| 1034 |
</xsl:variable> |
| 1035 |
<xsl:copy-of select="$links"/> |
| 1036 |
<xsl:variable name="linknodes" select="exsl:node-set($links)/*"/> |
| 1037 |
<xsl:for-each select="$mal.cache"> |
| 1038 |
<xsl:for-each select="key('mal.cache.link.key', concat('guide:', $linkid))"> |
| 1039 |
<xsl:variable name="source" select="../.."/> |
| 1040 |
<xsl:variable name="linklinkid"> |
| 1041 |
<xsl:call-template name="mal.link.xref.linkid"> |
| 1042 |
<xsl:with-param name="node" select="$source"/> |
| 1043 |
<xsl:with-param name="xref" select="$source/@id"/> |
| 1044 |
</xsl:call-template> |
| 1045 |
</xsl:variable> |
| 1046 |
<xsl:if test="$linklinkid != '' and not($linknodes[@xref = $linklinkid])"> |
| 1047 |
<xsl:variable name="link" select="."/> |
| 1048 |
<xsl:variable name="grouppos"> |
| 1049 |
<xsl:if test="$link/@group"> |
| 1050 |
<xsl:for-each select="$groupslist"> |
| 1051 |
<xsl:if test="string(.) = $link/@group"> |
| 1052 |
<xsl:value-of select="position()"/> |
| 1053 |
<xsl:text> </xsl:text> |
| 1054 |
</xsl:if> |
| 1055 |
</xsl:for-each> |
| 1056 |
</xsl:if> |
| 1057 |
</xsl:variable> |
| 1058 |
<xsl:variable name="groupsort"> |
| 1059 |
<xsl:value-of select="substring-before($grouppos, ' ')"/> |
| 1060 |
<xsl:if test="string($grouppos) = ''"> |
| 1061 |
<xsl:value-of select="$defaultpos"/> |
| 1062 |
</xsl:if> |
| 1063 |
</xsl:variable> |
| 1064 |
<mal:link xref="{$linklinkid}"> |
| 1065 |
<xsl:attribute name="group"> |
| 1066 |
<xsl:value-of select="$groupslist[number($groupsort)]"/> |
| 1067 |
</xsl:attribute> |
| 1068 |
<xsl:attribute name="groupsort"> |
| 1069 |
<xsl:value-of select="$groupsort"/> |
| 1070 |
</xsl:attribute> |
| 1071 |
<mal:title type="sort"> |
| 1072 |
<xsl:call-template name="mal.link.sorttitle"> |
| 1073 |
<xsl:with-param name="node" select="$source"/> |
| 1074 |
<xsl:with-param name="role" select="$role"/> |
| 1075 |
</xsl:call-template> |
| 1076 |
</mal:title> |
| 1077 |
</mal:link> |
| 1078 |
</xsl:if> |
| 1079 |
</xsl:for-each> |
| 1080 |
</xsl:for-each> |
| 1081 |
</xsl:template> |
| 1082 |
|
| 1083 |
|
| 1084 |
<!--**========================================================================== |
| 1085 |
mal.link.seealsolinks |
| 1086 |
Output the see-also links for a page or section. |
| 1087 |
@revision[version=3.18 date=2015-06-07 status=final] |
| 1088 |
|
| 1089 |
[xsl:params] |
| 1090 |
$node: The `page` or `section` element to generate links for. |
| 1091 |
$role: A space-separated list of link roles, used to select the appropriate title, default `"seealso"`. |
| 1092 |
|
| 1093 |
This template outputs all the see-also links for a page or section, whether |
| 1094 |
declared in the page or section or in another page or section. It outputs |
| 1095 |
each of the links as a `link` element within the Mallard namespace. Each |
| 1096 |
`link` element has an `xref` attribute pointing to the target page or section. |
| 1097 |
Or, in the case of external links, the `link` element has an `href` attribute |
| 1098 |
pointing to the external resource. |
| 1099 |
|
| 1100 |
Each `link` element contains a `title` with `type="sort"` providing the |
| 1101 |
sort title of the target page or section. The $role attribute is used to |
| 1102 |
select a link title to sort on when a sort title is not present. The results |
| 1103 |
are not sorted when returned from this template. Use `xsl:sort` on the sort |
| 1104 |
titles to sort the results. |
| 1105 |
|
| 1106 |
When a link comes from a topic link on $node that has an `href` |
| 1107 |
attribute but not an `xref` attribute, it is taken to be an external |
| 1108 |
link. In that case, the output link has an `href` attribute instead of |
| 1109 |
an `xref` attribute, and it has an `info` child element. This element |
| 1110 |
has a copy of all the child elements of the source `link` element. |
| 1111 |
|
| 1112 |
The output is a result tree fragment. To use these results, call |
| 1113 |
`exsl:node-set` on them. |
| 1114 |
--> |
| 1115 |
<xsl:template name="mal.link.seealsolinks"> |
| 1116 |
<xsl:param name="node" select="."/> |
| 1117 |
<xsl:param name="role" select="'seealso'"/> |
| 1118 |
<xsl:variable name="linkid"> |
| 1119 |
<xsl:call-template name="mal.link.linkid"> |
| 1120 |
<xsl:with-param name="node" select="$node"/> |
| 1121 |
</xsl:call-template> |
| 1122 |
</xsl:variable> |
| 1123 |
<xsl:variable name="links"> |
| 1124 |
<xsl:for-each select="$node/mal:info/mal:link[@type = 'seealso']"> |
| 1125 |
<xsl:variable name="link" select="."/> |
| 1126 |
<xsl:choose> |
| 1127 |
<xsl:when test="$link[@xref]"> |
| 1128 |
<xsl:variable name="linklinkid"> |
| 1129 |
<xsl:call-template name="mal.link.xref.linkid"/> |
| 1130 |
</xsl:variable> |
| 1131 |
<xsl:for-each select="$mal.cache"> |
| 1132 |
<xsl:variable name="linklinknode" select="key('mal.cache.key', $linklinkid)"/> |
| 1133 |
<xsl:if test="count($linklinknode) > 0"> |
| 1134 |
<mal:link xref="{$linklinkid}"> |
| 1135 |
<mal:title type="sort"> |
| 1136 |
<xsl:call-template name="mal.link.sorttitle"> |
| 1137 |
<xsl:with-param name="node" select="$linklinknode"/> |
| 1138 |
<xsl:with-param name="role" select="$role"/> |
| 1139 |
</xsl:call-template> |
| 1140 |
</mal:title> |
| 1141 |
</mal:link> |
| 1142 |
</xsl:if> |
| 1143 |
</xsl:for-each> |
| 1144 |
</xsl:when> |
| 1145 |
<xsl:when test="$link[@href]"> |
| 1146 |
<mal:link href="{$link/@href}"> |
| 1147 |
<mal:title type="sort"> |
| 1148 |
<xsl:choose> |
| 1149 |
<xsl:when test="mal:title[@type = 'sort']"> |
| 1150 |
<xsl:value-of select="normalize-space(mal:title[@type = 'sort'][1])"/> |
| 1151 |
</xsl:when> |
| 1152 |
<xsl:otherwise> |
| 1153 |
<xsl:value-of select="normalize-space(mal:title[not(@type)][1])"/> |
| 1154 |
</xsl:otherwise> |
| 1155 |
</xsl:choose> |
| 1156 |
</mal:title> |
| 1157 |
<mal:info> |
| 1158 |
<xsl:copy-of select="$link/*"/> |
| 1159 |
</mal:info> |
| 1160 |
</mal:link> |
| 1161 |
</xsl:when> |
| 1162 |
</xsl:choose> |
| 1163 |
</xsl:for-each> |
| 1164 |
</xsl:variable> |
| 1165 |
<xsl:copy-of select="$links"/> |
| 1166 |
<xsl:variable name="linknodes" select="exsl:node-set($links)/*"/> |
| 1167 |
<xsl:for-each select="$mal.cache"> |
| 1168 |
<xsl:for-each select="key('mal.cache.link.key', concat('seealso:', $linkid))/../.."> |
| 1169 |
<xsl:variable name="linklinkid"> |
| 1170 |
<xsl:call-template name="mal.link.linkid"/> |
| 1171 |
</xsl:variable> |
| 1172 |
<xsl:if test="$linklinkid != '' and not($linknodes[@xref = $linklinkid])"> |
| 1173 |
<mal:link xref="{$linklinkid}"> |
| 1174 |
<mal:title type="sort"> |
| 1175 |
<xsl:call-template name="mal.link.sorttitle"> |
| 1176 |
<xsl:with-param name="node" select="."/> |
| 1177 |
<xsl:with-param name="role" select="$role"/> |
| 1178 |
</xsl:call-template> |
| 1179 |
</mal:title> |
| 1180 |
</mal:link> |
| 1181 |
</xsl:if> |
| 1182 |
</xsl:for-each> |
| 1183 |
</xsl:for-each> |
| 1184 |
</xsl:template> |
| 1185 |
|
| 1186 |
|
| 1187 |
<!--**========================================================================== |
| 1188 |
mal.link.linktrails |
| 1189 |
Output link trails for a page or section. |
| 1190 |
@revision[version=3.4 date=2012-01-18 status=final] |
| 1191 |
|
| 1192 |
[xsl:params] |
| 1193 |
$node: The `page` or `section` element to generate links for. |
| 1194 |
$trail: The link trail leading to $node. |
| 1195 |
$root: The ID of the root page. |
| 1196 |
|
| 1197 |
This template outputs lists of links, where each list is a path of topic links |
| 1198 |
that leads to $node. Each link list is output as a `link` element in the |
| 1199 |
Mallard namespace with an `xref` attribute pointing to the target page or |
| 1200 |
section. Each `link` has a `title` element with `type="sort"` providing |
| 1201 |
the sort title of the target page or section. |
| 1202 |
|
| 1203 |
Each `link` element may also contain another `link` element providing the |
| 1204 |
next link in the trail. Each of these links also contains a sort titles and |
| 1205 |
may also contain another link. |
| 1206 |
|
| 1207 |
The results are not sorted when returned from this template. Use `xsl:sort` |
| 1208 |
on the nested sort titles to sort the results. The output is a result tree |
| 1209 |
fragment. To use these results, call `exsl:node-set` on them. |
| 1210 |
|
| 1211 |
This template calls itself recursively. It finds the guide links for $node |
| 1212 |
using {mal.link.guidelinks}. It then calls {mal.link.linktrails} on each |
| 1213 |
guide, wrapping $trail with a link to the guide as the new $trail parameter. |
| 1214 |
|
| 1215 |
If there are no guide links for $node and $node is a `section` element, |
| 1216 |
this template calls itself on the containing page, wrapping $trails with a |
| 1217 |
link to that page. This `link` element has the attribute `child="section"` |
| 1218 |
to indicate the link from it to its child is not a topic link. |
| 1219 |
|
| 1220 |
Recursion stops when the ID of $node is $root. Link trails are only |
| 1221 |
output if they reach $root, which is {mal.link.default_root} by default. |
| 1222 |
--> |
| 1223 |
<!-- |
| 1224 |
FIXME: |
| 1225 |
* Terminate at $root |
| 1226 |
* Only output if we reach $root |
| 1227 |
* Cycle detection |
| 1228 |
--> |
| 1229 |
<xsl:template name="mal.link.linktrails"> |
| 1230 |
<xsl:param name="node" select="."/> |
| 1231 |
<xsl:param name="trail" select="/false"/> |
| 1232 |
<xsl:param name="root" select="$mal.link.default_root"/> |
| 1233 |
<xsl:variable name="guidelinks"> |
| 1234 |
<xsl:call-template name="mal.link.guidelinks"> |
| 1235 |
<xsl:with-param name="node" select="$node"/> |
| 1236 |
<xsl:with-param name="role" select="'trail'"/> |
| 1237 |
</xsl:call-template> |
| 1238 |
</xsl:variable> |
| 1239 |
<xsl:variable name="guidenodes" select="exsl:node-set($guidelinks)/*"/> |
| 1240 |
<xsl:choose> |
| 1241 |
<xsl:when test="count($guidenodes) = 0"> |
| 1242 |
<xsl:choose> |
| 1243 |
<xsl:when test="$node/self::mal:section"> |
| 1244 |
<xsl:variable name="page" select="$node/ancestor::mal:page"/> |
| 1245 |
<xsl:call-template name="mal.link.linktrails"> |
| 1246 |
<xsl:with-param name="node" select="$page"/> |
| 1247 |
<xsl:with-param name="trail"> |
| 1248 |
<mal:link xref="{$page/@id}" child="section"> |
| 1249 |
<xsl:copy-of select="$page/mal:info/mal:title[@type='sort']"/> |
| 1250 |
<xsl:copy-of select="$trail"/> |
| 1251 |
</mal:link> |
| 1252 |
</xsl:with-param> |
| 1253 |
<xsl:with-param name="root" select="$root"/> |
| 1254 |
</xsl:call-template> |
| 1255 |
</xsl:when> |
| 1256 |
<xsl:otherwise> |
| 1257 |
<xsl:copy-of select="$trail"/> |
| 1258 |
</xsl:otherwise> |
| 1259 |
</xsl:choose> |
| 1260 |
</xsl:when> |
| 1261 |
<xsl:when test="$guidenodes[@xref = $root]"> |
| 1262 |
<mal:link xref="{$root}"> |
| 1263 |
<xsl:copy-of select="$guidenodes[@xref = $root][1]/mal:title"/> |
| 1264 |
<xsl:copy-of select="$trail"/> |
| 1265 |
</mal:link> |
| 1266 |
</xsl:when> |
| 1267 |
<xsl:otherwise> |
| 1268 |
<xsl:for-each select="$guidenodes"> |
| 1269 |
<xsl:variable name="self" select="."/> |
| 1270 |
<xsl:choose> |
| 1271 |
<xsl:when test="$self/@xref = $root"> |
| 1272 |
<mal:link xref="{$self/@xref}"> |
| 1273 |
<xsl:copy-of select="$self/mal:title"/> |
| 1274 |
<xsl:copy-of select="$trail"/> |
| 1275 |
</mal:link> |
| 1276 |
</xsl:when> |
| 1277 |
<xsl:otherwise> |
| 1278 |
<xsl:for-each select="$mal.cache"> |
| 1279 |
<xsl:call-template name="mal.link.linktrails"> |
| 1280 |
<xsl:with-param name="node" select="key('mal.cache.key', $self/@xref)"/> |
| 1281 |
<xsl:with-param name="trail"> |
| 1282 |
<mal:link xref="{$self/@xref}"> |
| 1283 |
<xsl:copy-of select="$self/mal:title"/> |
| 1284 |
<xsl:copy-of select="$trail"/> |
| 1285 |
</mal:link> |
| 1286 |
</xsl:with-param> |
| 1287 |
<xsl:with-param name="root" select="$root"/> |
| 1288 |
</xsl:call-template> |
| 1289 |
</xsl:for-each> |
| 1290 |
</xsl:otherwise> |
| 1291 |
</xsl:choose> |
| 1292 |
</xsl:for-each> |
| 1293 |
</xsl:otherwise> |
| 1294 |
</xsl:choose> |
| 1295 |
</xsl:template> |
| 1296 |
|
| 1297 |
|
| 1298 |
<!--**========================================================================== |
| 1299 |
mal.link.sorttitle |
| 1300 |
Output the sort title for a page or section. |
| 1301 |
@revision[version=3.10 date=2013-07-30 status=final] |
| 1302 |
|
| 1303 |
[xsl:params] |
| 1304 |
$node: The `page` or `section` element to output a sort title for. |
| 1305 |
$role: A space-separated list of link roles, used to select the appropriate title. |
| 1306 |
|
| 1307 |
This template returns a sort title for a page or section as a normalized string. |
| 1308 |
If $node defines a sort title in its `info` element, the value of that title |
| 1309 |
is always used first. Otherwise, if $role is defined and $node has a link |
| 1310 |
title with a matching role, that title is used. Otherwise, if $node has a link |
| 1311 |
title with no role, that title is used. Otherwise, the primary title is used. |
| 1312 |
--> |
| 1313 |
<xsl:template name="mal.link.sorttitle"> |
| 1314 |
<xsl:param name="node" select="."/> |
| 1315 |
<xsl:param name="role" select="''"/> |
| 1316 |
<xsl:choose> |
| 1317 |
<xsl:when test="$node/mal:info/mal:title[@type = 'sort']"> |
| 1318 |
<xsl:value-of select="normalize-space($node/mal:info/mal:title[@type = 'sort'][1])"/> |
| 1319 |
</xsl:when> |
| 1320 |
<xsl:when test="$role != '' and $node/mal:info/mal:title[@type = 'link'][@role = $role]"> |
| 1321 |
<xsl:value-of select="normalize-space($node/mal:info/mal:title[@type = 'link'][@role = $role][1])"/> |
| 1322 |
</xsl:when> |
| 1323 |
<xsl:when test="$node/mal:info/mal:title[@type = 'link'][not(@role)]"> |
| 1324 |
<xsl:value-of select="normalize-space($node/mal:info/mal:title[@type = 'link'][not(@role)][1])"/> |
| 1325 |
</xsl:when> |
| 1326 |
<xsl:otherwise> |
| 1327 |
<xsl:value-of select="normalize-space($node/mal:title[1])"/> |
| 1328 |
</xsl:otherwise> |
| 1329 |
</xsl:choose> |
| 1330 |
</xsl:template> |
| 1331 |
|
| 1332 |
</xsl:stylesheet> |