10
10
11
11
<!-- Chunk template used to split content among multiple .html files -->
12
12
13
+ <!-- ToDo: Refactor to eliminate duplicate code around href generation for XREF vs. non-XREF <a> elems -->
14
+
13
15
<!-- ToDo: Add "previous" and "next" links as in the docbook-xsl stylesheets? -->
14
16
15
17
<!-- Imports htmlbook.xsl -->
@@ -320,7 +322,7 @@ sect5:s
320
322
321
323
<!-- Custom XREF template in chunk.xsl, because we need to take chunk filename into account, and update hrefs. -->
322
324
<!-- All XREFs must be tagged with a @data-type containing XREF -->
323
- <xsl : template match =" h:a[contains(@data-type, 'xref')]" >
325
+ <xsl : template match =" h:a[contains(@data-type, 'xref')]" name = " process-as-xref " >
324
326
<xsl : param name =" autogenerate-xrefs" select =" $autogenerate-xrefs" />
325
327
<xsl : variable name =" calculated-output-href" >
326
328
<xsl : call-template name =" calculate-output-href" >
@@ -334,9 +336,9 @@ sect5:s
334
336
</xsl : call-template >
335
337
</xsl : variable >
336
338
<xsl : copy >
337
- <xsl : apply-templates select =" @*[not(local- name() = 'href')]" />
339
+ <xsl : apply-templates select =" @*[not(name() = 'href')]" />
338
340
<xsl : choose >
339
- <xsl : when test =" count(key('id', $href-anchor)) > 0 " >
341
+ <xsl : when test =" ( count(key('id', $href-anchor)) > 0) and ($is-xref = 1) " >
340
342
<xsl : variable name =" target" select =" key('id', $href-anchor)[1]" />
341
343
<!-- Regenerate the href here, to ensure it accurately points to correct location, including chunk filename) -->
342
344
<xsl : attribute name =" href" >
@@ -384,6 +386,63 @@ sect5:s
384
386
</xsl : copy >
385
387
</xsl : template >
386
388
389
+ <!-- href and content handling for a elements that are not indexterms, xrefs, or footnoterefs -->
390
+ <xsl : template match =" h:a[not((contains(@data-type, 'xref')) or
391
+ (contains(@data-type, 'footnoteref')) or
392
+ (contains(@data-type, 'indexterm')))][@href]" >
393
+ <!-- If the element is empty, does not have data-type="link", and is a valid XREF, go ahead and treat it like an <a> element with data-type="xref" -->
394
+ <xsl : variable name =" is-xref" >
395
+ <xsl : call-template name =" href-is-xref" >
396
+ <xsl : with-param name =" href-value" select =" @href" />
397
+ </xsl : call-template >
398
+ </xsl : variable >
399
+ <xsl : variable name =" calculated-output-href" >
400
+ <xsl : call-template name =" calculate-output-href" >
401
+ <xsl : with-param name =" source-href-value" select =" @href" />
402
+ </xsl : call-template >
403
+ </xsl : variable >
404
+ <xsl : variable name =" href-anchor" select =" substring-after($calculated-output-href, '#')" />
405
+ <xsl : choose >
406
+ <xsl : when test =" (not(node())) and
407
+ ($is-xref = 1) and
408
+ not(@data-type='link')" >
409
+ <xsl : call-template name =" process-as-xref" />
410
+ </xsl : when >
411
+ <!-- Otherwise just process href and apply-templates for everything else -->
412
+ <xsl : otherwise >
413
+ <xsl : copy >
414
+ <xsl : apply-templates select =" @*[not(name(.) = 'href')]" />
415
+ <xsl : attribute name =" href" >
416
+ <xsl : choose >
417
+ <xsl : when test =" (count(key('id', $href-anchor)) > 0) and ($is-xref = 1)" >
418
+ <xsl : variable name =" target" select =" key('id', $href-anchor)[1]" />
419
+ <!-- Regenerate the href here, to ensure it accurately points to correct location, including chunk filename) -->
420
+ <xsl : call-template name =" href.target" >
421
+ <xsl : with-param name =" object" select =" $target" />
422
+ <xsl : with-param name =" source-link-node" select =" ." />
423
+ </xsl : call-template >
424
+ </xsl : when >
425
+ <xsl : otherwise >
426
+ <xsl : if test =" $is-xref = 1" >
427
+ <xsl : call-template name =" log-message" >
428
+ <xsl : with-param name =" type" select =" 'WARNING'" />
429
+ <xsl : with-param name =" message" >
430
+ <xsl : text >Unable to locate target for a element with @href value:</xsl : text >
431
+ <xsl : value-of select =" @href" />
432
+ </xsl : with-param >
433
+ </xsl : call-template >
434
+ </xsl : if >
435
+ <!-- Oh well, just copy any existing href to output -->
436
+ <xsl : apply-templates select =" @href" />
437
+ </xsl : otherwise >
438
+ </xsl : choose >
439
+ </xsl : attribute >
440
+ <xsl : apply-templates />
441
+ </xsl : copy >
442
+ </xsl : otherwise >
443
+ </xsl : choose >
444
+ </xsl : template >
445
+
387
446
<!-- Generate target @href value pointing to given node, in the appropriate chunk -->
388
447
<!-- Borrowed and adapted from xhtml/html.xsl and xhtml/chunk-common.xsl in docbook-xsl stylesheets -->
389
448
<xsl : template name =" href.target" >
0 commit comments