Skip to content

Commit 84f12f2

Browse files
author
Sanders Kleinfeld
committed
Handling to exclude "informal" figures and tables from count when labeling fig/table captions.
1 parent 6fd3ebe commit 84f12f2

File tree

2 files changed

+113
-4
lines changed

2 files changed

+113
-4
lines changed

htmlbook-xsl/common.xsl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@
120120
contains(@data-type, 'toc')]|
121121
ancestor::h:div[@data-type = 'part'])[last()]" mode="label.markup"/>
122122
<xsl:apply-templates select="." mode="intralabel.punctuation"/>
123-
<xsl:number count="h:table" from="h:section[contains(@data-type, 'acknowledgments') or
123+
<xsl:number count="h:table[h:caption[. != '']]" from="h:section[contains(@data-type, 'acknowledgments') or
124124
contains(@data-type, 'afterword') or
125125
contains(@data-type, 'appendix') or
126126
contains(@data-type, 'bibliography') or
@@ -140,7 +140,7 @@
140140
h:div[contains(@data-type, 'part')]" level="any" format="1"/>
141141
</xsl:when>
142142
<xsl:otherwise>
143-
<xsl:number count="h:table" level="any" format="1"/>
143+
<xsl:number count="h:table[h:caption[. != '']]" level="any" format="1"/>
144144
</xsl:otherwise>
145145
</xsl:choose>
146146
</xsl:template>
@@ -168,7 +168,7 @@
168168
contains(@data-type, 'toc')]|
169169
ancestor::h:div[@data-type = 'part'])[last()]" mode="label.markup"/>
170170
<xsl:apply-templates select="." mode="intralabel.punctuation"/>
171-
<xsl:number count="h:figure[not(contains(@data-type, 'cover'))]" from="h:section[contains(@data-type, 'acknowledgments') or
171+
<xsl:number count="h:figure[not(contains(@data-type, 'cover'))][h:figcaption[. != '']]" from="h:section[contains(@data-type, 'acknowledgments') or
172172
contains(@data-type, 'afterword') or
173173
contains(@data-type, 'appendix') or
174174
contains(@data-type, 'bibliography') or
@@ -188,7 +188,7 @@
188188
h:div[contains(@data-type, 'part')]" level="any" format="1"/>
189189
</xsl:when>
190190
<xsl:otherwise>
191-
<xsl:number count="h:figure[not(contains(@data-type, 'cover'))]" level="any" format="1"/>
191+
<xsl:number count="h:figure[not(contains(@data-type, 'cover'))][h:figcaption[. != '']]" level="any" format="1"/>
192192
</xsl:otherwise>
193193
</xsl:choose>
194194
</xsl:template>

htmlbook-xsl/xspec/common.xspec

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,115 @@ sect5:none
582582
</x:scenario>
583583
</x:scenario>
584584

585+
<x:scenario label="When generating a label for a table">
586+
<x:context select="(//h:section//h:table)[3]" mode="label.markup">
587+
<section data-type="chapter">
588+
<h1>This is a chapter heading</h1>
589+
<p>Running out of amusing things to say</p>
590+
<table>
591+
<!-- No caption -->
592+
<tbody>
593+
<tr>
594+
<td>Python</td>
595+
<td>Java</td>
596+
</tr>
597+
<tr>
598+
<td>Ruby</td>
599+
<td>Perl</td>
600+
</tr>
601+
</tbody>
602+
</table>
603+
<table>
604+
<!-- Empty caption -->
605+
<caption/>
606+
<tbody>
607+
<tr>
608+
<td>pencil</td>
609+
</tr>
610+
<tr>
611+
<td>paper</td>
612+
</tr>
613+
</tbody>
614+
</table>
615+
<table>
616+
<caption>Our favorite colors</caption>
617+
<thead>
618+
<tr>
619+
<th>Name</th>
620+
<th>Color</th>
621+
</tr>
622+
</thead>
623+
<tbody>
624+
<tr>
625+
<td>Tom</td>
626+
<td>vermilion</td>
627+
</tr>
628+
<tr>
629+
<td>Richard</td>
630+
<td>fuchsia</td>
631+
</tr>
632+
<tr>
633+
<td>Harry</td>
634+
<td>cerulean</td>
635+
</tr>
636+
</tbody>
637+
</table>
638+
</section>
639+
</x:context>
640+
641+
<x:scenario label="With label.formal.with.ancestor disabled">
642+
<x:context>
643+
<x:param name="label.formal.with.ancestor" select="0"/>
644+
</x:context>
645+
<x:expect label="Ignore 'informal' (uncaptioned or empty-captioned) tables in the count">1</x:expect>
646+
</x:scenario>
647+
648+
<x:scenario label="With label.formal.with.ancestor enabled">
649+
<x:context>
650+
<x:param name="label.formal.with.ancestor" select="1"/>
651+
</x:context>
652+
<x:expect label="Ignore 'informal' (uncaptioned or empty-captioned) tables in the count">1-1</x:expect>
653+
</x:scenario>
654+
</x:scenario>
655+
656+
657+
<x:scenario label="When generating a label for a figure">
658+
<x:context select="(//h:section//h:figure)[3]" mode="label.markup">
659+
<section data-type="chapter">
660+
<h1>This is a chapter heading</h1>
661+
<p>Running out of amusing things to say</p>
662+
<figure>
663+
<!-- No caption (technically shouldn't be a <figure> element here in this case) -->
664+
<img src="tegucigalpa.png"/>
665+
</figure>
666+
<figure>
667+
<!-- Empty caption -->
668+
<figcaption/>
669+
<img src="paramaribo.png"/>
670+
</figure>
671+
<figure>
672+
<figcaption>Image of the Ouagadougou skyline</figcaption>
673+
<img src="ouagadougou.png"/>
674+
</figure>
675+
</section>
676+
</x:context>
677+
678+
<x:scenario label="With label.formal.with.ancestor disabled">
679+
<x:context>
680+
<x:param name="label.formal.with.ancestor" select="0"/>
681+
</x:context>
682+
<x:expect label="Ignore 'informal' (uncaptioned or empty-captioned) figures in the count">1</x:expect>
683+
</x:scenario>
684+
685+
<x:scenario label="With label.formal.with.ancestor enabled">
686+
<x:context>
687+
<x:param name="label.formal.with.ancestor" select="1"/>
688+
</x:context>
689+
<x:expect label="Ignore 'informal' (uncaptioned or empty-captioned) figures in the count">1-1</x:expect>
690+
</x:scenario>
691+
</x:scenario>
692+
693+
585694
<x:pending>
586695

587696
<x:scenario label="When generating a label for a part div with label.section.with.ancestors enabled">

0 commit comments

Comments
 (0)