|
24 | 24 | <!-- WARNING: If you need additional handling for these elements for other functionality,
|
25 | 25 | and you override this template elsewhere, make sure you add in id-decoration functionality -->
|
26 | 26 | <xsl:template match="h:section|h:div[contains(@data-type, 'part')]|h:aside|h:a[contains(@data-type, 'indexterm')]">
|
| 27 | + <xsl:param name="html4.structural.elements" select="$html4.structural.elements"/> |
27 | 28 | <xsl:variable name="output-element-name">
|
28 |
| - <xsl:call-template name="html.output.element"/> |
| 29 | + <xsl:call-template name="html.output.element"> |
| 30 | + <xsl:with-param name="html4.structural.elements" select="$html4.structural.elements"/> |
| 31 | + </xsl:call-template> |
29 | 32 | </xsl:variable>
|
30 |
| - <xsl:element name="{$output-element-name}" namespace="http://www.w3.org/1999/xhtml"> |
| 33 | + <xsl:copy> |
31 | 34 | <xsl:apply-templates select="@*[not(local-name() = 'id')]"/>
|
32 |
| - <xsl:attribute name="id"> |
33 |
| - <xsl:call-template name="object.id"/> |
34 |
| - </xsl:attribute> |
35 | 35 | <xsl:apply-templates select="." mode="pdf-bookmark"/>
|
36 |
| - <xsl:apply-templates/> |
37 |
| - <xsl:if test="$process.footnotes = 1"> |
38 |
| - <xsl:call-template name="generate-footnotes"/> |
39 |
| - </xsl:if> |
40 |
| - </xsl:element> |
| 36 | + <xsl:choose> |
| 37 | + <!-- If output element name matches local name (i.e., HTML4 fallback elements disabled), copy element as is and process descendant content --> |
| 38 | + <!-- ToDo: Refactor duplicate code in when/otherwise; perhaps do an apply-templates select="." with a process-section mode --> |
| 39 | + <xsl:when test="$output-element-name = local-name()"> |
| 40 | + <xsl:attribute name="id"> |
| 41 | + <xsl:call-template name="object.id"/> |
| 42 | + </xsl:attribute> |
| 43 | + <xsl:apply-templates/> |
| 44 | + <xsl:if test="$process.footnotes = 1"> |
| 45 | + <xsl:call-template name="generate-footnotes"/> |
| 46 | + </xsl:if> |
| 47 | + </xsl:when> |
| 48 | + <!-- If output element name does not match local name (i.e., HTML4 fallback elements enabled), copy element, but add an HTML4 |
| 49 | + fallback child wrapper to include descendant content --> |
| 50 | + <xsl:otherwise> |
| 51 | + <xsl:element name="{$output-element-name}" namespace="http://www.w3.org/1999/xhtml"> |
| 52 | + <!-- Put a class on it with the proper semantic name --> |
| 53 | + <xsl:attribute name="class"> |
| 54 | + <xsl:call-template name="semantic-name"/> |
| 55 | + </xsl:attribute> |
| 56 | + <xsl:attribute name="id"> |
| 57 | + <xsl:call-template name="object.id"/> |
| 58 | + </xsl:attribute> |
| 59 | + <xsl:apply-templates/> |
| 60 | + <xsl:if test="$process.footnotes = 1"> |
| 61 | + <xsl:call-template name="generate-footnotes"/> |
| 62 | + </xsl:if> |
| 63 | + </xsl:element> |
| 64 | + </xsl:otherwise> |
| 65 | + </xsl:choose> |
| 66 | + </xsl:copy> |
41 | 67 | </xsl:template>
|
42 | 68 |
|
43 | 69 | <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]|
|
|
51 | 77 | </xsl:template>
|
52 | 78 |
|
53 | 79 | <xsl:template match="h:figure">
|
| 80 | + <xsl:param name="html4.structural.elements" select="$html4.structural.elements"/> |
| 81 | + <xsl:param name="figure.border.div" select="$figure.border.div"/> |
54 | 82 | <xsl:variable name="output-element-name">
|
55 |
| - <xsl:call-template name="html.output.element"/> |
| 83 | + <xsl:call-template name="html.output.element"> |
| 84 | + <xsl:with-param name="html4.structural.elements" select="$html4.structural.elements"/> |
| 85 | + </xsl:call-template> |
56 | 86 | </xsl:variable>
|
57 |
| - <xsl:element name="{$output-element-name}" namespace="http://www.w3.org/1999/xhtml"> |
58 |
| - <xsl:apply-templates select="@*"/> |
59 |
| - <!-- If there's no data-type already and $html4.structural.elements is enabled, plop in a data type of "figure" --> |
60 |
| - <xsl:if test="not(@data-type) and $html4.structural.elements = 1"> |
61 |
| - <xsl:attribute name="data-type">figure</xsl:attribute> |
62 |
| - </xsl:if> |
63 |
| - <!-- If the parameter $figure.border.div is enabled, and there is a figure caption, add a child div and put everything but the caption in it --> |
| 87 | + <xsl:copy> |
| 88 | + <xsl:apply-templates select="@*[not(local-name() = 'id')]"/> |
64 | 89 | <xsl:choose>
|
65 |
| - <xsl:when test="$figure.border.div = 1 and h:figcaption"> |
| 90 | + <!-- If output element name matches local name (i.e., HTML4 fallback elements disabled), copy element as is and process descendant content --> |
| 91 | + <xsl:when test="$output-element-name = local-name()"> |
| 92 | + <xsl:apply-templates select="@id"/> |
| 93 | + <xsl:call-template name="process-figure-contents"> |
| 94 | + <xsl:with-param name="figure.border.div" select="$figure.border.div"/> |
| 95 | + </xsl:call-template> |
| 96 | + </xsl:when> |
| 97 | + <!-- If output element name does not match local name (i.e., HTML4 fallback elements enabled), copy element, but add an HTML4 |
| 98 | + fallback child wrapper to include descendant content --> |
| 99 | + <xsl:otherwise> |
| 100 | + <xsl:element name="{$output-element-name}" namespace="http://www.w3.org/1999/xhtml"> |
| 101 | + <xsl:apply-templates select="@id"/> |
| 102 | + <xsl:attribute name="class"> |
| 103 | + <xsl:call-template name="semantic-name"/> |
| 104 | + </xsl:attribute> |
| 105 | + <xsl:call-template name="process-figure-contents"> |
| 106 | + <xsl:with-param name="figure.border.div" select="$figure.border.div"/> |
| 107 | + </xsl:call-template> |
| 108 | + </xsl:element> |
| 109 | + </xsl:otherwise> |
| 110 | + </xsl:choose> |
| 111 | + </xsl:copy> |
| 112 | + </xsl:template> |
| 113 | + |
| 114 | + <xsl:template name="process-figure-contents"> |
| 115 | + <xsl:param name="node" select="."/> |
| 116 | + <xsl:param name="figure.border.div" select="$figure.border.div"/> |
| 117 | + <!-- If the parameter $figure.border.div is enabled, and there is a figure caption, add a child div and put everything but the caption in it --> |
| 118 | + <!-- Switch to the appropriate context node --> |
| 119 | + <xsl:for-each select="$node[1]"> |
| 120 | + <xsl:choose> |
| 121 | + <xsl:when test="$figure.border.div = 1 and h:figcaption[text()]"> |
66 | 122 | <!-- figcaption must be first or last; handle accordingly -->
|
67 | 123 | <xsl:choose>
|
| 124 | + <!-- Only do border box when you've got a nonempty fig caption --> |
68 | 125 | <xsl:when test="*[1][self::h:figcaption]">
|
69 | 126 | <xsl:apply-templates select="h:figcaption"/>
|
70 | 127 | <div class="border-box">
|
|
82 | 139 | <xsl:call-template name="log-message">
|
83 | 140 | <xsl:with-param name="type" select="'WARNING'"/>
|
84 | 141 | <xsl:with-param name="message">
|
85 |
| - <xsl:text>Error: figcaption for figure </xsl:text> |
| 142 | + <xsl:text>Warning: figcaption for figure </xsl:text> |
86 | 143 | <xsl:value-of select="@id"/>
|
87 |
| - <xsl:text> not at beginning or end of figure. Unable to add border box</xsl:text> |
| 144 | + <xsl:text>not at beginning or end of figure. Unable to add border box</xsl:text> |
88 | 145 | </xsl:with-param>
|
89 | 146 | </xsl:call-template>
|
90 | 147 | <xsl:apply-templates/>
|
|
95 | 152 | <xsl:apply-templates/>
|
96 | 153 | </xsl:otherwise>
|
97 | 154 | </xsl:choose>
|
98 |
| - </xsl:element> |
| 155 | + </xsl:for-each> |
99 | 156 | </xsl:template>
|
100 | 157 |
|
101 | 158 | <xsl:template match="h:caption">
|
|
105 | 162 | </xsl:template>
|
106 | 163 |
|
107 | 164 | <xsl:template match="h:figcaption">
|
| 165 | + <xsl:param name="html4.structural.elements" select="$html4.structural.elements"/> |
108 | 166 | <xsl:apply-templates select="." mode="process-heading">
|
109 | 167 | <xsl:with-param name="labeled-element-semantic-name" select="'figure'"/>
|
110 | 168 | <xsl:with-param name="output-element-name">
|
111 |
| - <xsl:call-template name="html.output.element"/> |
| 169 | + <xsl:call-template name="html.output.element"> |
| 170 | + <xsl:with-param name="html4.structural.elements" select="$html4.structural.elements"/> |
| 171 | + </xsl:call-template> |
112 | 172 | </xsl:with-param>
|
113 | 173 | </xsl:apply-templates>
|
114 | 174 | </xsl:template>
|
115 | 175 |
|
| 176 | + <!-- Admonition handling --> |
| 177 | + <xsl:template match="h:div[@data-type='note' or |
| 178 | + @data-type='tip' or |
| 179 | + @data-type='warning' or |
| 180 | + @data-type='caution' or |
| 181 | + @data-type='important']"> |
| 182 | + <xsl:param name="add.title.heading.for.admonitions" select="$add.title.heading.for.admonitions"/> |
| 183 | + <xsl:copy> |
| 184 | + <xsl:apply-templates select="@*"/> |
| 185 | + <!-- Add admonition heading title if $add.title.heading.for.admonitions is enabled AND there is not a heading first child already --> |
| 186 | + <xsl:if test="($add.title.heading.for.admonitions = 1) and |
| 187 | + not(*[1][self::h:h1|self::h:h2|self::h:h3|self::h:h4|self::h:h5|self::h:h6])"> |
| 188 | + <h6> |
| 189 | + <!-- For title, use proper admonition title gentext, based on localization --> |
| 190 | + <xsl:variable name="admon-semantic-name"> |
| 191 | + <xsl:call-template name="semantic-name"> |
| 192 | + <xsl:with-param name="node" select="."/> |
| 193 | + </xsl:call-template> |
| 194 | + </xsl:variable> |
| 195 | + <xsl:call-template name="get-localization-value"> |
| 196 | + <xsl:with-param name="gentext-key" select="$admon-semantic-name"/> |
| 197 | + </xsl:call-template> |
| 198 | + </h6> |
| 199 | + </xsl:if> |
| 200 | + <xsl:apply-templates/> |
| 201 | + </xsl:copy> |
| 202 | + </xsl:template> |
| 203 | + |
116 | 204 | <!-- Footnote handling -->
|
117 | 205 | <xsl:template match="h:span[@data-type='footnote']">
|
118 | 206 | <xsl:choose>
|
|
0 commit comments