Skip to content

Commit 1c30db5

Browse files
committed
Trying to make a custom xref to numbered section headings
1 parent ea19d59 commit 1c30db5

File tree

1 file changed

+34
-18
lines changed

1 file changed

+34
-18
lines changed

theme/pdf/pdf.xsl

+34-18
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
</xsl:template>
5353

5454
<!-- Logic for processing sect2 headings with labels (including section numbers) -->
55-
<xsl:template match="h:section[@data-type='chapter' and not(contains(@class, 'orm:non-recipe'))]/h:section[@data-type='sect1' and not(contains(@class, 'orm:non-recipe'))]/h:section[@data-type='sect2' and not(contains(@class, 'orm:non-recipe'))]/h:h2" mode="process-heading">
55+
<xsl:template match="h:section[@data-type='sect2']/h:h2" mode="process-heading">
5656
<xsl:param name="autogenerate.labels" select="$autogenerate.labels"/>
5757
<!-- Labeled element is typically the parent element of the heading (e.g., <section> or <figure>) -->
5858
<xsl:param name="labeled-element" select="(parent::h:header/parent::*|parent::*[not(self::h:header)])[1]"/>
@@ -72,7 +72,7 @@
7272
</xsl:template>
7373

7474
<!-- Creating the sect1 labels (read: creating the X.X section numbering) -->
75-
<xsl:template match="h:section[@data-type='chapter' and not(contains(@class, 'orm:non-recipe'))]/h:section[@data-type='sect1' and not(contains(@class, 'orm:non-recipe'))]" mode="label.markup">
75+
<xsl:template match="h:section[@data-type='sect1']" mode="label.markup">
7676
<xsl:variable name="current-node" select="."/>
7777
<!-- BEGIN COOKBOOK OVERRIDE -->
7878
<!-- Recipes should always be labeled with ancestor chapter -->
@@ -106,15 +106,15 @@
106106
</xsl:variable>
107107

108108
<xsl:variable name="recipe.level">
109-
<xsl:value-of select="count(preceding-sibling::h:section[@data-type='sect1'][not(@class='orm:non-recipe')]) + (1 - $chap.has.intro - $is.numbered)"/>
109+
<xsl:value-of select="count(preceding-sibling::h:section[@data-type='sect1']) + (1 - $chap.has.intro - $is.numbered)"/>
110110
</xsl:variable>
111111
<xsl:number format="1" value="$recipe.level"/>
112112

113113
<!-- END COOKBOOK OVERRIDE -->
114114
</xsl:template>
115115

116116
<!-- Creating the sect2 labels (read: creating the X.X.X section numbering) -->
117-
<xsl:template match="h:section[@data-type='chapter' and not(contains(@class, 'orm:non-recipe'))]/h:section[@data-type='sect1' and not(contains(@class, 'orm:non-recipe'))]/h:section[@data-type='sect2' and not(contains(@class, 'orm:non-recipe'))]" mode="label.markup">
117+
<xsl:template match="h:section[@data-type='sect2']" mode="label.markup">
118118
<!-- END OVERRIDE -->
119119
<xsl:variable name="current-node" select="."/>
120120
<!-- BEGIN COOKBOOK OVERRIDE -->
@@ -149,7 +149,7 @@
149149
</xsl:variable>
150150

151151
<xsl:variable name="sect1.recipe.level">
152-
<xsl:value-of select="count(../preceding-sibling::h:section[@data-type='sect1'][not(@class='orm:non-recipe')]) + (1 - $chap.has.intro - $is.numbered)"/>
152+
<xsl:value-of select="count(../preceding-sibling::h:section[@data-type='sect1']) + (1 - $chap.has.intro - $is.numbered)"/>
153153
</xsl:variable>
154154
<xsl:number format="1" value="$sect1.recipe.level"/>
155155
<xsl:text>.</xsl:text>
@@ -196,22 +196,38 @@
196196
</xsl:choose>
197197
</xsl:template>
198198

199-
<!-- Custom xref handling -->
199+
<!-- ***************** Custom xref handling ************ -->
200200
<!-- Overrides xrefgen.xsl -->
201201

202202
<!-- Testing selector to make custom xrefs to sections -->
203-
<xsl:template match="h:section[@data-type='sect1']" mode="xref-to">
204-
<!-- Otherwise, throw warning, and print out ??? -->
205-
<xsl:call-template name="log-message">
206-
<xsl:with-param name="type" select="'WARNING'"/>
207-
<xsl:with-param name="message">
208-
<xsl:text>Cannot output gentext for XREF to refentry (id:</xsl:text>
209-
<xsl:value-of select="@id"/>
210-
<xsl:text>) that does not contain an element with class of refname</xsl:text>
211-
</xsl:with-param>
212-
</xsl:call-template>
213-
<xsl:text>???</xsl:text>
214-
</xsl:template>
203+
<xsl:template match="h:section[@data-type='sect1']" mode="xref-to">
204+
<xsl:param name="referrer"/>
205+
<xsl:param name="xrefstyle"/>
206+
<xsl:param name="verbose" select="1"/>
207+
<xsl:choose>
208+
<xsl:when test="h:h1">
209+
<xsl:apply-templates select="." mode="object.xref.markup">
210+
<xsl:with-param name="purpose" select="'xref'"/>
211+
<!-- BEGIN OVERRIDE -->
212+
<xsl:with-param name="xrefstyle" select="'template: %n%t'"/>
213+
<!-- END OVERRIDE -->
214+
<xsl:with-param name="referrer" select="$referrer"/>
215+
<xsl:with-param name="verbose" select="$verbose"/>
216+
</xsl:apply-templates>
217+
</xsl:when>
218+
<xsl:otherwise>
219+
<!-- Otherwise, throw warning, and print out ??? -->
220+
<xsl:call-template name="log-message">
221+
<xsl:with-param name="type" select="'WARNING'"/>
222+
<xsl:with-param name="message">
223+
<xsl:text>Cannot output gentext for XREF to section (id:</xsl:text>
224+
<xsl:value-of select="@id"/>
225+
</xsl:with-param>
226+
</xsl:call-template>
227+
<xsl:text>???</xsl:text>
228+
</xsl:otherwise>
229+
</xsl:choose>
230+
</xsl:template>
215231

216232
<!-- ***************** TOC HANDLING ***************** -->
217233
<!-- ************* Overrides tocgen.xsl ************* -->

0 commit comments

Comments
 (0)