Skip to content

Commit 87e59b3

Browse files
author
Sanders Kleinfeld
committed
Merge pull request #126 from oreillymedia/schema
Updated specifications for subtitle handling
2 parents 2e1e563 + 43556f6 commit 87e59b3

File tree

14 files changed

+760
-83
lines changed

14 files changed

+760
-83
lines changed

htmlbook-xsl/chunk.xsl

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@
2626
<!-- Nodeset of all chunks in this document -->
2727
<xsl:variable name="chunks" select="key('chunks', '1')"/> <!-- All chunks have an is-chunk() value of 1 -->
2828

29-
<!-- Specify a number from 0 to 5, where 0 means chunk at top-level sections (part, chapter, appendix), and 1-5 means chunk at the corresponding sect level (sect1 - sect5) -->
30-
<xsl:param name="chunk.level" select="0"/>
31-
3229
<!-- Specify whether to generate a root chunk -->
3330
<xsl:param name="generate.root.chunk" select="0"/>
3431

@@ -77,7 +74,7 @@ sect5:s
7774
</xsl:template>
7875

7976
<xsl:template match="h:section|h:div[contains(@data-type, 'part')]|h:nav[contains(@data-type, 'toc')]">
80-
<xsl:variable name="is.chunk" select="htmlbook:is-chunk(., $chunk.level)"/>
77+
<xsl:variable name="is.chunk" select="htmlbook:is-chunk(.)"/>
8178
<!-- <xsl:message>Element name: <xsl:value-of select="local-name()"/>, data-type name: <xsl:value-of select="@data-type"/>, Is chunk: <xsl:value-of select="$is.chunk"/></xsl:message> -->
8279
<xsl:choose>
8380
<xsl:when test="$is.chunk = 1">
@@ -139,7 +136,7 @@ sect5:s
139136
<!-- Root Chunk! Needs $outputdir in full file path-->
140137
<xsl:value-of select="concat($outputdir, $chars-to-append-to-outputdir)"/>
141138
</xsl:when>
142-
<xsl:when test="$outputdir != '' and not($generate.root.chunk = 1) and not($chunk[ancestor::*[htmlbook:is-chunk(., $chunk.level) = 1]])">
139+
<xsl:when test="$outputdir != '' and not($generate.root.chunk = 1) and not($chunk[ancestor::*[htmlbook:is-chunk(.) = 1]])">
143140
<!-- $outputdir is specified and *is not* absolute filepath,
144141
and generate.root.chunk is not specified (if it is, then previous "when" will set the outputdir properly),
145142
and chunk *is not* a nested chunk -->
@@ -287,7 +284,7 @@ sect5:s
287284

288285
<!-- Check to see if parent is also chunk, in which case, call template recursively -->
289286
<xsl:variable name="parent-node" select="parent::*"/>
290-
<xsl:variable name="parent-is-chunk" select="htmlbook:is-chunk($parent-node, $chunk.level)"/>
287+
<xsl:variable name="parent-is-chunk" select="htmlbook:is-chunk($parent-node)"/>
291288
<xsl:if test="$parent-is-chunk = '1'">
292289
<xsl:call-template name="output-filename-for-chunk">
293290
<xsl:with-param name="node" select="$parent-node"/>
@@ -534,7 +531,7 @@ sect5:s
534531
<xsl:template name="generate-footnotes">
535532

536533
<!-- Only generate footnotes if the current node is a chunk -->
537-
<xsl:if test="htmlbook:is-chunk(., $chunk.level)">
534+
<xsl:if test="htmlbook:is-chunk(.)">
538535

539536
<xsl:variable name="all-footnotes" select="//h:span[@data-type='footnote']"/>
540537

htmlbook-xsl/common.xsl

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -343,13 +343,14 @@
343343
<!-- Logic for generating titles; default handling is to grab the first <h1>-<h6> content -->
344344
<xsl:template match="*" mode="title.markup">
345345
<xsl:choose>
346-
<xsl:when test="self::h:section[@data-type='index' and not(h:h1|h:h2|h:h3|h:h4|h:h5|h:h6)]">
346+
<xsl:when test="self::h:section[@data-type='index' and not(h:h1|h:h2|h:h3|h:h4|h:h5|h:h6|h:header/h:h1|h:header/h:h2|h:header/h:h3|h:header/h:h4|h:header/h:h5|h:header/h:h6)]">
347347
<xsl:call-template name="get-localization-value">
348348
<xsl:with-param name="gentext-key" select="'index'"/>
349349
</xsl:call-template>
350350
</xsl:when>
351351
<xsl:otherwise>
352-
<xsl:apply-templates select="(h:h1|h:h2|h:h3|h:h4|h:h5|h:h6)[1]/node()"/>
352+
<xsl:apply-templates select="(h:h1|h:h2|h:h3|h:h4|h:h5|h:h6|
353+
h:header/h:h1|h:header/h:h2|h:header/h:h3|h:header/h:h4|h:header/h:h5|h:header/h:h6)[1]/node()"/>
353354
</xsl:otherwise>
354355
</xsl:choose>
355356
</xsl:template>
@@ -358,9 +359,9 @@
358359
<xsl:template match="*" mode="process-heading">
359360
<xsl:param name="autogenerate.labels" select="$autogenerate.labels"/>
360361
<!-- Labeled element is typically the parent element of the heading (e.g., <section> or <figure>) -->
361-
<xsl:param name="labeled-element" select=".."/>
362+
<xsl:param name="labeled-element" select="(parent::h:header/parent::*|parent::*[not(self::h:header)])[1]"/>
362363
<!-- Labeled element semantic name is typically the parent element of the heading's @data-type -->
363-
<xsl:param name="labeled-element-semantic-name" select="../@data-type"/>
364+
<xsl:param name="labeled-element-semantic-name" select="(parent::h:header/parent::*|parent::*[not(self::h:header)])[1]/@data-type"/>
364365
<!-- Name for output heading element; same as current node name by default -->
365366
<xsl:param name="output-element-name" select="local-name(.)"/>
366367
<xsl:element name="{$output-element-name}" namespace="http://www.w3.org/1999/xhtml">
@@ -488,9 +489,9 @@
488489
<xsl:when test="@data-pdf-bookmark">
489490
<xsl:attribute name="data-pdf-bookmark" select="@data-pdf-bookmark"/>
490491
</xsl:when>
491-
<xsl:when test="h:h1">
492+
<xsl:when test="h:h1 or h:header/h:h1">
492493
<xsl:variable name="processed-heading">
493-
<xsl:apply-templates select="h:h1[1]" mode="process-heading">
494+
<xsl:apply-templates select="(h:h1|h:header/h:h1)[1]" mode="process-heading">
494495
<xsl:with-param name="autogenerate.labels" select="$autogenerate.pdf.bookmark.labels"/>
495496
</xsl:apply-templates>
496497
</xsl:variable>
@@ -506,9 +507,9 @@
506507
<xsl:when test="@data-pdf-bookmark">
507508
<xsl:attribute name="data-pdf-bookmark" select="@data-pdf-bookmark"/>
508509
</xsl:when>
509-
<xsl:when test="h:h2">
510+
<xsl:when test="h:h2 or h:header/h:h2">
510511
<xsl:variable name="processed-heading">
511-
<xsl:apply-templates select="h:h2[1]" mode="process-heading">
512+
<xsl:apply-templates select="(h:h2|h:header/h:h2)[1]" mode="process-heading">
512513
<xsl:with-param name="autogenerate.labels" select="$autogenerate.pdf.bookmark.labels"/>
513514
</xsl:apply-templates>
514515
</xsl:variable>
@@ -524,9 +525,9 @@
524525
<xsl:when test="@data-pdf-bookmark">
525526
<xsl:attribute name="data-pdf-bookmark" select="@data-pdf-bookmark"/>
526527
</xsl:when>
527-
<xsl:when test="h:h3">
528+
<xsl:when test="h:h3 or h:header/h:h3">
528529
<xsl:variable name="processed-heading">
529-
<xsl:apply-templates select="h:h3[1]" mode="process-heading">
530+
<xsl:apply-templates select="(h:h3|h:header/h:h3)[1]" mode="process-heading">
530531
<xsl:with-param name="autogenerate.labels" select="$autogenerate.pdf.bookmark.labels"/>
531532
</xsl:apply-templates>
532533
</xsl:variable>
@@ -542,9 +543,9 @@
542543
<xsl:when test="@data-pdf-bookmark">
543544
<xsl:attribute name="data-pdf-bookmark" select="@data-pdf-bookmark"/>
544545
</xsl:when>
545-
<xsl:when test="h:h4">
546+
<xsl:when test="h:h4 or h:header/h:h4">
546547
<xsl:variable name="processed-heading">
547-
<xsl:apply-templates select="h:h4[1]" mode="process-heading">
548+
<xsl:apply-templates select="(h:h4|h:header/h:h4)[1]" mode="process-heading">
548549
<xsl:with-param name="autogenerate.labels" select="$autogenerate.pdf.bookmark.labels"/>
549550
</xsl:apply-templates>
550551
</xsl:variable>
@@ -560,9 +561,9 @@
560561
<xsl:when test="@data-pdf-bookmark">
561562
<xsl:attribute name="data-pdf-bookmark" select="@data-pdf-bookmark"/>
562563
</xsl:when>
563-
<xsl:when test="h:h5">
564+
<xsl:when test="h:h5 or h:header/h:h5">
564565
<xsl:variable name="processed-heading">
565-
<xsl:apply-templates select="h:h5[1]" mode="process-heading">
566+
<xsl:apply-templates select="(h:h5|h:header/h:h5)[1]" mode="process-heading">
566567
<xsl:with-param name="autogenerate.labels" select="$autogenerate.pdf.bookmark.labels"/>
567568
</xsl:apply-templates>
568569
</xsl:variable>
@@ -578,9 +579,9 @@
578579
<xsl:when test="@data-pdf-bookmark">
579580
<xsl:attribute name="data-pdf-bookmark" select="@data-pdf-bookmark"/>
580581
</xsl:when>
581-
<xsl:when test="h:h1">
582+
<xsl:when test="h:h1 or h:header/h:h1">
582583
<xsl:variable name="processed-heading">
583-
<xsl:apply-templates select="h:h1[1]" mode="process-heading">
584+
<xsl:apply-templates select="(h:h1|h:header/h:h1)[1]" mode="process-heading">
584585
<xsl:with-param name="autogenerate.labels" select="$autogenerate.pdf.bookmark.labels"/>
585586
</xsl:apply-templates>
586587
</xsl:variable>

htmlbook-xsl/elements.xsl

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,13 @@
4141
</xsl:template>
4242

4343
<xsl:template match="h:section[@data-type]/*[self::h:h1 or self::h:h2 or self::h:h3 or self::h:h4 or self::h:h5 or self::h:h6]|
44-
h:div[@data-type = 'part' or @data-type = 'example' or @data-type = 'equation']/*[self::h:h1 or self::h:h2 or self::h:h3 or self::h:h4 or self::h:h5 or self::h:h6]">
45-
<xsl:apply-templates select="." mode="process-heading"/>
44+
h:section[@data-type]/h:header/*[self::h:h1 or self::h:h2 or self::h:h3 or self::h:h4 or self::h:h5 or self::h:h6]|
45+
h:div[@data-type = 'part' or @data-type = 'example' or @data-type = 'equation']/*[self::h:h1 or self::h:h2 or self::h:h3 or self::h:h4 or self::h:h5 or self::h:h6]|
46+
h:div[@data-type = 'part']/h:header/*[self::h:h1 or self::h:h2 or self::h:h3 or self::h:h4 or self::h:h5 or self::h:h6]">
47+
<xsl:param name="autogenerate.labels" select="$autogenerate.labels"/>
48+
<xsl:apply-templates select="." mode="process-heading">
49+
<xsl:with-param name="autogenerate.labels" select="$autogenerate.labels"/>
50+
</xsl:apply-templates>
4651
</xsl:template>
4752

4853
<xsl:template match="h:figure">

htmlbook-xsl/epub.xsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262

6363
<xsl:param name="metadata.title">
6464
<!-- Look for title first in head, then as child of body -->
65-
<xsl:value-of select="(//h:head/h:title|//h:body/h:h1)[1]"/>
65+
<xsl:value-of select="(//h:head/h:title|//h:body/h:h1|//h:body/h:header/h:h1)[1]"/>
6666
</xsl:param>
6767

6868
<xsl:param name="metadata.language">

htmlbook-xsl/functions-exsl.xsl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
<func:function name="htmlbook:is-chunk">
1313
<xsl:param name="node"/>
14-
<xsl:param name="chunk.level" select="$chunk.level"/>
1514
<xsl:choose>
1615
<xsl:when test="$node[self::h:div[contains(@data-type, 'part')]]">
1716
<func:result>1</func:result>

htmlbook-xsl/functions-xslt2.xsl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
<xsl:function name="htmlbook:is-chunk">
1212
<xsl:param name="node"/>
13-
<xsl:param name="chunk.level"/>
1413
<xsl:choose>
1514
<xsl:when test="$node[self::h:div[contains(@data-type, 'part')]]">1</xsl:when>
1615
<xsl:when test="$node[self::h:section[contains(@data-type, 'acknowledgments') or

htmlbook-xsl/ncx.xsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
<navLabel>
6060
<text>
6161
<!-- Look for title first in head, then as child of body -->
62-
<xsl:value-of select="(//h:head/h:title|//h:body/h:h1)[1]"/>
62+
<xsl:value-of select="(//h:head/h:title|//h:body/h:h1|//h:body/h:header/h:h1)[1]"/>
6363
</text>
6464
</navLabel>
6565
<content src="{$root.chunk.filename}"/>

htmlbook-xsl/opf.xsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,7 @@
604604
<xsl:for-each select="$element-descendants[1]">
605605
<xsl:choose>
606606
<!-- Check if the element's nearest chunk ancestor is the chunk in question... -->
607-
<xsl:when test="ancestor::*[htmlbook:is-chunk(., $chunk.level) = 1 and not(descendant::*[htmlbook:is-chunk(., $chunk.level) = 1][descendant::*[generate-id() = generate-id($element-descendants[1])]])][generate-id() = $chunk-id]">
607+
<xsl:when test="ancestor::*[htmlbook:is-chunk(.) = 1 and not(descendant::*[htmlbook:is-chunk(.) = 1][descendant::*[generate-id() = generate-id($element-descendants[1])]])][generate-id() = $chunk-id]">
608608
<!--...It is: We have $element-name in this chunk! -->
609609
<xsl:text>1</xsl:text>
610610
</xsl:when>

htmlbook-xsl/param.xsl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@
4343
</xsl:choose>
4444
</xsl:param>
4545

46+
<!-- For chunking templates: specify a number from 0 to 5, where 0 means chunk at top-level sections (part, chapter, appendix), and 1-5 means chunk at the corresponding sect level (sect1 - sect5) -->
47+
<xsl:param name="chunk.level" select="0"/>
48+
4649
<!-- Titling and labeling params -->
4750

4851
<!-- Specify whether to autogenerate labels on sectioning and formal elements in HTML output (as opposed to labeling with CSS); default is to not include labels (0) -->

htmlbook-xsl/xspec/common.xspec

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,19 @@ sect5:none
4343
<x:expect label="Copy the child content of the first h1-h6 as is">XPath <em>is</em> <strong>the bestest</strong></x:expect>
4444
</x:scenario>
4545

46+
<x:scenario label="When generating a title for a section that has heading info captured in a header element">
47+
<x:context mode="title.markup">
48+
<section data-type="chapter">
49+
<header>
50+
<h1>Get this heading!</h1>
51+
<p data-type="subtitle">Ignore the second headling!</p>
52+
</header>
53+
<p>This is some boilerplate text</p>
54+
</section>
55+
</x:context>
56+
<x:expect label="Copy the first h1 in the header element">Get this heading!</x:expect>
57+
</x:scenario>
58+
4659
<!-- Label markup tests -->
4760
<!-- This section's tests based on values in label.numeration.by.data-type global param -->
4861
<x:scenario label="When generating a label for a section (chapter)">

0 commit comments

Comments
 (0)