Skip to content

Commit 859486b

Browse files
author
Sanders Kleinfeld
committed
Merge pull request #116 from oreillymedia/sarah
Adding level="any" to xsl:number elements to fix label handling of chapters within parts
2 parents dc5b41d + c768f56 commit 859486b

File tree

2 files changed

+202
-6
lines changed

2 files changed

+202
-6
lines changed

htmlbook-xsl/common.xsl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -292,22 +292,22 @@
292292
<xsl:choose>
293293
<!-- I wish XSL allowed variables in @format attribute -->
294294
<xsl:when test="$calculated-numeration-format = '1'">
295-
<xsl:number count="*[@data-type = $data-type]" format="1"/>
295+
<xsl:number count="*[@data-type = $data-type]" format="1" level="any"/>
296296
</xsl:when>
297297
<xsl:when test="$calculated-numeration-format = '01'">
298-
<xsl:number count="*[@data-type = $data-type]" format="01"/>
298+
<xsl:number count="*[@data-type = $data-type]" format="01" level="any"/>
299299
</xsl:when>
300300
<xsl:when test="$calculated-numeration-format = 'a'">
301-
<xsl:number count="*[@data-type = $data-type]" format="a"/>
301+
<xsl:number count="*[@data-type = $data-type]" format="a" level="any"/>
302302
</xsl:when>
303303
<xsl:when test="$calculated-numeration-format = 'A'">
304-
<xsl:number count="*[@data-type = $data-type]" format="A"/>
304+
<xsl:number count="*[@data-type = $data-type]" format="A" level="any"/>
305305
</xsl:when>
306306
<xsl:when test="$calculated-numeration-format = 'i'">
307-
<xsl:number count="*[@data-type = $data-type]" format="i"/>
307+
<xsl:number count="*[@data-type = $data-type]" format="i" level="any"/>
308308
</xsl:when>
309309
<xsl:when test="$calculated-numeration-format = 'I'">
310-
<xsl:number count="*[@data-type = $data-type]" format="I"/>
310+
<xsl:number count="*[@data-type = $data-type]" format="I" level="any"/>
311311
</xsl:when>
312312
<xsl:when test="$calculated-numeration-format = 'none'"/>
313313
<xsl:otherwise>

htmlbook-xsl/xspec/common.xspec

Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,17 @@
66
xmlns:h="http://www.w3.org/1999/xhtml"
77
stylesheet="../htmlbook.xsl">
88

9+
<x:param name="label.numeration.by.data-type">
10+
appendix:A
11+
chapter:1
12+
part:I
13+
sect1:a
14+
sect2:none
15+
sect3:none
16+
sect4:none
17+
sect5:none
18+
</x:param>
19+
920
<!-- Test suite for common.xsl -->
1021

1122
<!-- Title markup tests -->
@@ -32,6 +43,191 @@
3243
<x:expect label="Copy the child content of the first h1-h6 as is">XPath <em>is</em> <strong>the bestest</strong></x:expect>
3344
</x:scenario>
3445

46+
<!-- Label markup tests -->
47+
<!-- This section's tests based on values in label.numeration.by.data-type global param -->
48+
<x:scenario label="When generating a label for a section (chapter)">
49+
<x:context mode="label.markup" select="/h:body/h:section[@data-type='chapter'][2]">
50+
<body>
51+
<section data-type="chapter">
52+
<h1>First one!</h1>
53+
<p>Yup!</p>
54+
</section>
55+
<section data-type="chapter">
56+
<h1>Second one!</h1>
57+
<p>Yeah!</p>
58+
</section>
59+
<section data-type="appendix">
60+
<h1>Appendix, yo!</h1>
61+
<p>You betcha!</p>
62+
</section>
63+
</body>
64+
</x:context>
65+
<!-- check the result -->
66+
<x:expect label="The appropriate numeration value should be generated">2</x:expect>
67+
</x:scenario>
68+
69+
<x:scenario label="When generating a label for a part div">
70+
<x:context mode="label.markup" select="/h:body/h:div[@data-type='part'][3]">
71+
<body>
72+
<div data-type="part">
73+
<h1>Prefaces!</h1>
74+
<section data-type="preface">
75+
<h1>First one!</h1>
76+
<p>Yup!</p>
77+
</section>
78+
</div>
79+
<div data-type="part">
80+
<h1>Chapters!</h1>
81+
<section data-type="chapter">
82+
<h1>Love this sample markup!</h1>
83+
<p>Oh yeah!</p>
84+
</section>
85+
</div>
86+
<div data-type="part">
87+
<h1>Appendixes</h1>
88+
<section data-type="appendix">
89+
<h1>Why plural? There's only one here!</h1>
90+
<p>D'oh!</p>
91+
</section>
92+
</div>
93+
</body>
94+
</x:context>
95+
<!-- check the result -->
96+
<x:expect label="The appropriate numeration value should be generated">III</x:expect>
97+
</x:scenario>
98+
99+
<x:scenario label="When generating a label for a lower-level section">
100+
<x:context mode="label.markup" select="/h:section[@data-type='chapter']/h:section[@data-type='sect1'][1]">
101+
<section data-type="chapter">
102+
<h1>Lots of sect1s in this one</h1>
103+
<section data-type="sect1">
104+
<h1>First subheading</h1>
105+
<p>Un!</p>
106+
</section>
107+
<section data-type="sect1">
108+
<h1>Second subheading</h1>
109+
<p>Deux!</p>
110+
</section>
111+
<section data-type="sect1">
112+
<h1>Third subheading</h1>
113+
<p>Trois!</p>
114+
</section>
115+
</section>
116+
</x:context>
117+
<!-- check the result -->
118+
<x:expect label="The appropriate numeration value should be generated">a</x:expect>
119+
</x:scenario>
120+
121+
<x:scenario label="When generating a label for a section with no label specified in params">
122+
<x:context mode="label.markup" select="/h:section[@data-type='chapter']/h:section[@data-type='sect1'][2]/h:section[@data-type='sect2'][1]">
123+
<section data-type="chapter">
124+
<h1>Lots of sect1s in this one</h1>
125+
<section data-type="sect1">
126+
<h1>First subheading</h1>
127+
<p>Un!</p>
128+
</section>
129+
<section data-type="sect1">
130+
<h1>Second subheading</h1>
131+
<p>Deux!</p>
132+
<section data-type="sect2">
133+
<h2>Sub-subheading</h2>
134+
<p>Woohoo!</p>
135+
</section>
136+
</section>
137+
<section data-type="sect1">
138+
<h1>Third subheading</h1>
139+
<p>Trois!</p>
140+
</section>
141+
</section>
142+
</x:context>
143+
<!-- check the result -->
144+
<x:expect label="The appropriate numeration value should be generated" select="()"/>
145+
</x:scenario>
146+
147+
<x:scenario label="When generating a label for a section (chapter) in a part">
148+
<x:context mode="label.markup" select="/h:body/h:div[@data-type='part'][2]/h:section[@data-type='chapter'][1]">
149+
<body>
150+
<div data-type="part">
151+
<h1>First set o chapters!</h1>
152+
<section data-type="chapter">
153+
<h1>First one!</h1>
154+
<p>Yup!</p>
155+
</section>
156+
<section data-type="chapter">
157+
<h1>Second one!</h1>
158+
<p>Oh yeah!</p>
159+
</section>
160+
</div>
161+
<div data-type="part">
162+
<h1>Second set o chapters</h1>
163+
<section data-type="chapter">
164+
<h1>Third one!</h1>
165+
<p>Hooray!</p>
166+
</section>
167+
</div>
168+
</body>
169+
</x:context>
170+
<x:expect label="The appropriate numeration value should be generated (absolute, not relative to part)">3</x:expect>
171+
</x:scenario>
172+
173+
<x:pending>
174+
175+
<x:scenario label="When generating a label for a part div with label.section.with.ancestors enabled">
176+
<x:context>
177+
</x:context>
178+
<x:expect label="The appropriate numeration value should be generated"/>
179+
</x:scenario>
180+
181+
<x:scenario label="When generating a label for a section (chapter) with label.section.with.ancestors enabled">
182+
<x:context>
183+
</x:context>
184+
<x:expect label="The appropriate numeration value should be generated"/>
185+
</x:scenario>
186+
187+
<x:scenario label="When generating a label for a section (subsection) with label.section.with.ancestors enabled">
188+
<x:context>
189+
</x:context>
190+
<x:expect label="The appropriate numeration value should be generated"/>
191+
</x:scenario>
192+
193+
<x:scenario label="When generating a label for a figure">
194+
<x:context>
195+
</x:context>
196+
<x:expect label="The appropriate numeration value should be generated"/>
197+
</x:scenario>
198+
199+
<x:scenario label="When generating a label for a figure (label.formal.with.ancestor = false)">
200+
<x:context>
201+
</x:context>
202+
<x:expect label="The appropriate numeration value should be generated"/>
203+
</x:scenario>
204+
205+
<x:scenario label="When generating a label for a table">
206+
<x:context>
207+
</x:context>
208+
<x:expect label="The appropriate numeration value should be generated"/>
209+
</x:scenario>
210+
211+
<x:scenario label="When generating a label for a table (label.formal.with.ancestor = false)">
212+
<x:context>
213+
</x:context>
214+
<x:expect label="The appropriate numeration value should be generated"/>
215+
</x:scenario>
216+
217+
<x:scenario label="When generating a label for an example">
218+
<x:context>
219+
</x:context>
220+
<x:expect label="The appropriate numeration value should be generated"/>
221+
</x:scenario>
222+
223+
<x:scenario label="When generating a label for an example (label.formal.with.ancestor = false)">
224+
<x:context>
225+
</x:context>
226+
<x:expect label="The appropriate numeration value should be generated"/>
227+
</x:scenario>
228+
229+
</x:pending>
230+
35231
<!-- Heading processing templates -->
36232
<x:scenario label="When process-headings is run on a section heading with $autogenerate.labels turned off">
37233
<x:context mode="process-heading" select="/h:section/h:h1">

0 commit comments

Comments
 (0)