|
16 | 16 | xmlns:ahf="http://www.antennahouse.com/names/XSLT/Functions/Document"
|
17 | 17 | exclude-result-prefixes="xs ahf"
|
18 | 18 | >
|
19 |
| - <xsl:variable name="cTableGroupingLevelMax" as="xs:integer"> |
20 |
| - <xsl:choose> |
21 |
| - <xsl:when test="$pAddNumberingTitlePrefix"> |
22 |
| - <xsl:sequence select="xs:integer(ahf:getVarValue('Table_Grouping_Level_Max'))"/> |
23 |
| - </xsl:when> |
24 |
| - <xsl:otherwise> |
25 |
| - <!-- if user selects not to add title prefix, the table number will not be grouped. --> |
26 |
| - <xsl:sequence select="0"/> |
27 |
| - </xsl:otherwise> |
28 |
| - </xsl:choose> |
29 |
| - </xsl:variable> |
30 |
| - |
31 |
| - <xsl:variable name="cFigureGroupingLevelMax" as="xs:integer"> |
32 |
| - <xsl:choose> |
33 |
| - <xsl:when test="$pAddNumberingTitlePrefix"> |
34 |
| - <xsl:sequence select="xs:integer(ahf:getVarValue('Figure_Grouping_Level_Max'))"/> |
35 |
| - </xsl:when> |
36 |
| - <xsl:otherwise> |
37 |
| - <!-- if user selects not to add title prefix, the figure number will not be grouped. --> |
38 |
| - <xsl:sequence select="0"/> |
39 |
| - </xsl:otherwise> |
40 |
| - </xsl:choose> |
41 |
| - </xsl:variable> |
42 |
| - |
43 |
| - <xsl:variable name="cFootnoteGroupingLevelMax" as="xs:integer"> |
44 |
| - <xsl:sequence select="xs:integer(ahf:getVarValue('Footnote_Grouping_Level_Max'))"/> |
45 |
| - </xsl:variable> |
| 19 | + <!-- This module defines table/fig/fn numbering map. |
| 20 | + Ususally numbering depends on bookmap hierarchy. |
| 21 | + The ahf:getNumberingGroupLevel function enables customization for many situations. |
| 22 | + --> |
46 | 23 |
|
47 | 24 | <!-- Table Numbering Map -->
|
48 | 25 | <xsl:variable name="tableCountMap" as="document-node()">
|
|
86 | 63 | <xsl:call-template name="makeFootnoteStartCount"/>
|
87 | 64 | </xsl:document>
|
88 | 65 | </xsl:variable>
|
| 66 | + |
| 67 | + <!-- |
| 68 | + function: Define the grouping level accoring to the map hierarchy. |
| 69 | + param: prmElem(table-count, figure-count, footnote-count) |
| 70 | + return: Grouping level |
| 71 | + note: To customize the grouping, override this function. |
| 72 | + $prmElem varies by caller: |
| 73 | + - table-count and figure-count in numbering temporary tree |
| 74 | + - topicref of map |
| 75 | + --> |
89 | 76 |
|
| 77 | + <xsl:function name="ahf:getFigureNumberingGroupLevel" as="xs:integer"> |
| 78 | + <xsl:param name="prmElem" as="element()"/> |
| 79 | + <xsl:sequence select="ahf:getNumberingGroupLevel($prmElem)"/> |
| 80 | + </xsl:function> |
| 81 | + |
| 82 | + <xsl:function name="ahf:getTableNumberingGroupLevel" as="xs:integer"> |
| 83 | + <xsl:param name="prmElem" as="element()"/> |
| 84 | + <xsl:sequence select="ahf:getNumberingGroupLevel($prmElem)"/> |
| 85 | + </xsl:function> |
| 86 | + |
| 87 | + <xsl:function name="ahf:getFootnoteNumberingGroupLevel" as="xs:integer"> |
| 88 | + <xsl:param name="prmElem" as="element()"/> |
| 89 | + <xsl:sequence select="ahf:getNumberingGroupLevel($prmElem)"/> |
| 90 | + </xsl:function> |
| 91 | + |
| 92 | + <xsl:function name="ahf:getNumberingGroupLevel" as="xs:integer"> |
| 93 | + <xsl:param name="prmElem" as="element()"/> |
| 94 | + <xsl:variable name="topElem" as="element()" select="if (root($prmElem)/*[1] is $root) then ($prmElem/ancestor-or-self::* except ($root|$map))[1] else $prmElem/ancestor-or-self::*[position() eq last()]"/> |
| 95 | + <xsl:choose> |
| 96 | + <xsl:when test="not($pAddNumberingTitlePrefix)"> |
| 97 | + <xsl:sequence select="0"/> |
| 98 | + </xsl:when> |
| 99 | + <xsl:when test="$isMap"> |
| 100 | + <xsl:sequence select="1"/> |
| 101 | + </xsl:when> |
| 102 | + <xsl:when test="$topElem[contains(@class,' bookmap/part ')]"> |
| 103 | + <xsl:sequence select="2"/> |
| 104 | + </xsl:when> |
| 105 | + <xsl:when test="$topElem[contains(@class,' bookmap/chapter ')]"> |
| 106 | + <xsl:sequence select="1"/> |
| 107 | + </xsl:when> |
| 108 | + <xsl:when test="$topElem[contains(@class,' bookmap/appendix ')]"> |
| 109 | + <xsl:sequence select="1"/> |
| 110 | + </xsl:when> |
| 111 | + <xsl:when test="$topElem[contains(@class,' bookmap/appendices ')]"> |
| 112 | + <xsl:sequence select="2"/> |
| 113 | + </xsl:when> |
| 114 | + <xsl:when test="$topElem[contains(@class,' bookmap/frontmatter ')]"> |
| 115 | + <xsl:sequence select="1"/> |
| 116 | + </xsl:when> |
| 117 | + <xsl:when test="$topElem[contains(@class,' bookmap/backmatter ')]"> |
| 118 | + <xsl:sequence select="1"/> |
| 119 | + </xsl:when> |
| 120 | + <xsl:otherwise> |
| 121 | + <xsl:sequence select="0"/> |
| 122 | + </xsl:otherwise> |
| 123 | + </xsl:choose> |
| 124 | + </xsl:function> |
| 125 | + |
90 | 126 | <!--
|
91 | 127 | function: make table count map template
|
92 | 128 | param: none
|
|
147 | 183 |
|
148 | 184 | <xsl:template match="table-count" mode="MODE_TABLE_START_COUNT" as="element()">
|
149 | 185 | <xsl:variable name="level" as="xs:integer" select="count(ancestor-or-self::*)"/>
|
150 |
| - <xsl:variable name="countTopElem" as="element()?" select="(ancestor-or-self::*)[position() eq $cTableGroupingLevelMax]"/> |
| 186 | + <xsl:variable name="tableGroupingLevelMax" as="xs:integer" select="ahf:getTableNumberingGroupLevel(.)"/> |
| 187 | + <xsl:variable name="countTopElem" as="element()?" select="(ancestor-or-self::*)[position() eq $tableGroupingLevelMax]"/> |
151 | 188 | <xsl:variable name="prevCount" as="xs:integer">
|
152 | 189 | <xsl:choose>
|
153 |
| - <xsl:when test="$cTableGroupingLevelMax eq 0"> |
| 190 | + <xsl:when test="$tableGroupingLevelMax eq 0"> |
154 | 191 | <!-- Table number is not grouped. -->
|
155 | 192 | <xsl:sequence select="xs:integer(sum(root(current())//*[. << current()]/@count))"/>
|
156 | 193 | </xsl:when>
|
157 |
| - <xsl:when test="$level le $cTableGroupingLevelMax"> |
| 194 | + <xsl:when test="$level le $tableGroupingLevelMax"> |
158 | 195 | <!-- Table number always starts from 1. -->
|
159 | 196 | <xsl:sequence select="0"/>
|
160 | 197 | </xsl:when>
|
|
232 | 269 |
|
233 | 270 | <xsl:template match="figure-count" mode="MODE_FIGURE_START_COUNT" as="element()">
|
234 | 271 | <xsl:variable name="level" as="xs:integer" select="count(ancestor-or-self::*)"/>
|
235 |
| - <xsl:variable name="countTopElem" as="element()?" select="(ancestor-or-self::*)[position() eq $cFigureGroupingLevelMax]"/> |
| 272 | + <xsl:variable name="figureGroupingLevelMax" as="xs:integer" select="ahf:getFigureNumberingGroupLevel(.)"/> |
| 273 | + <xsl:variable name="countTopElem" as="element()?" select="(ancestor-or-self::*)[position() eq $figureGroupingLevelMax]"/> |
236 | 274 | <xsl:variable name="prevCount" as="xs:integer">
|
237 | 275 | <xsl:choose>
|
238 |
| - <xsl:when test="$cFigureGroupingLevelMax eq 0"> |
| 276 | + <xsl:when test="$figureGroupingLevelMax eq 0"> |
239 | 277 | <!-- Figure number is not grouped. -->
|
240 | 278 | <xsl:sequence select="xs:integer(sum(root(current())//*[. << current()]/@count))"/>
|
241 | 279 | </xsl:when>
|
242 |
| - <xsl:when test="$level le $cFigureGroupingLevelMax"> |
| 280 | + <xsl:when test="$level le $figureGroupingLevelMax"> |
243 | 281 | <!-- Figure number always starts from 1. -->
|
244 | 282 | <xsl:sequence select="0"/>
|
245 | 283 | </xsl:when>
|
| 284 | + <xsl:when test="$level eq 1"> |
| 285 | + <!-- Top level always starts from 1. --> |
| 286 | + <xsl:sequence select="0"/> |
| 287 | + </xsl:when> |
246 | 288 | <xsl:otherwise>
|
247 | 289 | <!-- Count figure number with grouping topicref considering $cFigureGroupingLevelMax -->
|
248 | 290 | <xsl:variable name="countTragetElem" as="element()*" select="root(current())//*[. << current()] except root(current())//*[. << $countTopElem]"/>
|
|
317 | 359 |
|
318 | 360 | <xsl:template match="footnote-count" mode="MODE_FOOTNOTE_START_COUNT" as="element()">
|
319 | 361 | <xsl:variable name="level" as="xs:integer" select="count(ancestor-or-self::*)"/>
|
320 |
| - <xsl:variable name="countTopElem" as="element()?" select="(ancestor-or-self::*)[position() eq $cFootnoteGroupingLevelMax]"/> |
| 362 | + <xsl:variable name="footnoteGroupingLevelMax" as="xs:integer" select="ahf:getFootnoteNumberingGroupLevel(.)"/> |
| 363 | + <xsl:variable name="countTopElem" as="element()?" select="(ancestor-or-self::*)[position() eq $footnoteGroupingLevelMax]"/> |
321 | 364 | <xsl:variable name="prevCount" as="xs:integer">
|
322 | 365 | <xsl:choose>
|
323 |
| - <xsl:when test="$cFootnoteGroupingLevelMax eq 0"> |
| 366 | + <xsl:when test="$footnoteGroupingLevelMax eq 0"> |
324 | 367 | <!-- Figure number is not grouped. -->
|
325 | 368 | <xsl:sequence select="xs:integer(sum(root(current())//*[. << current()]/@count))"/>
|
326 | 369 | </xsl:when>
|
327 |
| - <xsl:when test="$level le $cFootnoteGroupingLevelMax"> |
| 370 | + <xsl:when test="$level le $footnoteGroupingLevelMax"> |
328 | 371 | <!-- Figure number always starts from 1. -->
|
329 | 372 | <xsl:sequence select="0"/>
|
330 | 373 | </xsl:when>
|
| 374 | + <xsl:when test="$level eq 1"> |
| 375 | + <!-- Top level always starts from 1. --> |
| 376 | + <xsl:sequence select="0"/> |
| 377 | + </xsl:when> |
331 | 378 | <xsl:otherwise>
|
332 | 379 | <!-- Count figure number with grouping topicref considering $cFigureGroupingLevelMax -->
|
333 | 380 | <xsl:variable name="countTragetElem" as="element()*" select="root(current())//*[. << current()] except root(current())//*[. << $countTopElem]"/>
|
|
0 commit comments