Skip to content

Commit 1fba0b6

Browse files
author
Sanders Kleinfeld
committed
Proper labeling for figures nested in Parts.
1 parent 73534ce commit 1fba0b6

File tree

2 files changed

+67
-13
lines changed

2 files changed

+67
-13
lines changed

htmlbook-xsl/common.xsl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,10 @@
143143
</xsl:template>
144144

145145
<xsl:template match="h:figure" mode="label.markup">
146+
<xsl:param name="label.formal.with.ancestor" select="$label.formal.with.ancestor"/>
146147
<xsl:choose>
147148
<xsl:when test="$label.formal.with.ancestor != 0">
148-
<xsl:apply-templates select="ancestor::h:section[contains(@data-type, 'acknowledgments') or
149+
<xsl:apply-templates select="(ancestor::h:section[contains(@data-type, 'acknowledgments') or
149150
contains(@data-type, 'afterword') or
150151
contains(@data-type, 'appendix') or
151152
contains(@data-type, 'bibliography') or
@@ -161,7 +162,8 @@
161162
contains(@data-type, 'introduction') or
162163
contains(@data-type, 'preface') or
163164
contains(@data-type, 'titlepage') or
164-
contains(@data-type, 'toc')][last()]" mode="label.markup"/>
165+
contains(@data-type, 'toc')]|
166+
ancestor::h:div[@data-type = 'part'])[last()]" mode="label.markup"/>
165167
<xsl:apply-templates select="." mode="intralabel.punctuation"/>
166168
<xsl:number count="h:figure[not(contains(@data-type, 'cover'))]" from="h:section[contains(@data-type, 'acknowledgments') or
167169
contains(@data-type, 'afterword') or

htmlbook-xsl/xspec/common.xspec

Lines changed: 63 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -183,33 +183,85 @@ sect5:none
183183
<x:expect label="The appropriate numeration value should be generated (absolute, not relative to part)">3</x:expect>
184184
</x:scenario>
185185

186-
<x:pending>
187-
188-
<x:scenario label="When generating a label for a part div with label.section.with.ancestors enabled">
189-
<x:context>
186+
<x:scenario label="When generating a label for a figure in a chapter-level division">
187+
<x:context select="(//h:section//h:figure)[2]" mode="label.markup">
188+
<section data-type="chapter">
189+
<h1>This is a chapter heading</h1>
190+
<p>Running out of amusing things to say</p>
191+
<figure>
192+
<img src="tokyo.png"/>
193+
<figcaption>A picture of the Tokyo skyline</figcaption>
194+
</figure>
195+
196+
<figure>
197+
<img src="paris.png"/>
198+
<figcaption>A picture of the Paris skyline</figcaption>
199+
</figure>
200+
</section>
190201
</x:context>
191-
<x:expect label="The appropriate numeration value should be generated"/>
202+
203+
<x:scenario label="With label.formal.with.ancestor disabled">
204+
<x:context>
205+
<x:param name="label.formal.with.ancestor" select="0"/>
206+
</x:context>
207+
<x:expect label="The appropriate numeration value should be generated">2</x:expect>
208+
</x:scenario>
209+
210+
<x:scenario label="With label.formal.with.ancestor enabled">
211+
<x:context>
212+
<x:param name="label.formal.with.ancestor" select="1"/>
213+
</x:context>
214+
<x:expect label="The appropriate numeration value should be generated">1-2</x:expect>
215+
</x:scenario>
192216
</x:scenario>
193217

194-
<x:scenario label="When generating a label for a section (chapter) with label.section.with.ancestors enabled">
195-
<x:context>
218+
<x:scenario label="When generating a label for a figure in a Part">
219+
<x:context select="(//h:div[@data-type='part']//h:figure)[2]" mode="label.markup">
220+
<div data-type="part">
221+
<h1>This is a Part heading</h1>
222+
<p>More text here</p>
223+
<figure>
224+
<img src="barcelona.png"/>
225+
<figcaption>A picture of the Barcelona skyline</figcaption>
226+
</figure>
227+
228+
<figure>
229+
<img src="quito.png"/>
230+
<figcaption>A picture of the Quito skyline</figcaption>
231+
</figure>
232+
</div>
196233
</x:context>
197-
<x:expect label="The appropriate numeration value should be generated"/>
234+
235+
<x:scenario label="With label.formal.with.ancestor disabled">
236+
<x:context>
237+
<x:param name="label.formal.with.ancestor" select="0"/>
238+
</x:context>
239+
<x:expect label="The appropriate numeration value should be generated">2</x:expect>
240+
</x:scenario>
241+
242+
<x:scenario label="With label.formal.with.ancestor enabled">
243+
<x:context>
244+
<x:param name="label.formal.with.ancestor" select="1"/>
245+
</x:context>
246+
<x:expect label="The appropriate numeration value should be generated">I-2</x:expect>
247+
</x:scenario>
198248
</x:scenario>
199249

200-
<x:scenario label="When generating a label for a section (subsection) with label.section.with.ancestors enabled">
250+
<x:pending>
251+
252+
<x:scenario label="When generating a label for a part div with label.section.with.ancestors enabled">
201253
<x:context>
202254
</x:context>
203255
<x:expect label="The appropriate numeration value should be generated"/>
204256
</x:scenario>
205257

206-
<x:scenario label="When generating a label for a figure">
258+
<x:scenario label="When generating a label for a section (chapter) with label.section.with.ancestors enabled">
207259
<x:context>
208260
</x:context>
209261
<x:expect label="The appropriate numeration value should be generated"/>
210262
</x:scenario>
211263

212-
<x:scenario label="When generating a label for a figure (label.formal.with.ancestor = false)">
264+
<x:scenario label="When generating a label for a section (subsection) with label.section.with.ancestors enabled">
213265
<x:context>
214266
</x:context>
215267
<x:expect label="The appropriate numeration value should be generated"/>

0 commit comments

Comments
 (0)