metanorma-cc 2.1.0 → 2.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -455,6 +455,7 @@
455
455
 
456
456
  <xsl:template match="csd:p" name="paragraph">
457
457
  <xsl:param name="inline" select="'false'"/>
458
+ <xsl:param name="split_keep-within-line"/>
458
459
  <xsl:variable name="previous-element" select="local-name(preceding-sibling::*[1])"/>
459
460
  <xsl:variable name="element-name">
460
461
  <xsl:choose>
@@ -480,7 +481,9 @@
480
481
  </xsl:choose>
481
482
  </xsl:attribute>
482
483
  <xsl:attribute name="line-height">115%</xsl:attribute>
483
- <xsl:apply-templates/>
484
+ <xsl:apply-templates>
485
+ <xsl:with-param name="split_keep-within-line" select="$split_keep-within-line"/>
486
+ </xsl:apply-templates>
484
487
  </xsl:element>
485
488
  <xsl:if test="$element-name = 'fo:inline' and not($inline = 'true') and not(local-name(..) = 'admonition')">
486
489
  <fo:block margin-bottom="12pt">
@@ -566,7 +569,9 @@
566
569
  </xsl:template>
567
570
 
568
571
 
569
- <xsl:param name="svg_images"/><xsl:variable name="images" select="document($svg_images)"/><xsl:param name="basepath"/><xsl:param name="external_index"/><xsl:param name="syntax-highlight">false</xsl:param><xsl:param name="add_math_as_text">true</xsl:param><xsl:variable name="lang">
572
+ <xsl:param name="svg_images"/><xsl:variable name="images" select="document($svg_images)"/><xsl:param name="basepath"/><xsl:param name="external_index"/><xsl:param name="syntax-highlight">false</xsl:param><xsl:param name="add_math_as_text">true</xsl:param><xsl:param name="table_if">false</xsl:param><xsl:param name="table_widths"/><xsl:variable name="table_widths_from_if" select="xalan:nodeset($table_widths)"/><xsl:param name="table_if_debug">false</xsl:param><xsl:variable name="isGenerateTableIF_">
573
+ false
574
+ </xsl:variable><xsl:variable name="isGenerateTableIF" select="normalize-space($isGenerateTableIF_)"/><xsl:variable name="lang">
570
575
  <xsl:call-template name="getLang"/>
571
576
  </xsl:variable><xsl:variable name="pageWidth_">
572
577
  210
@@ -1023,6 +1028,7 @@
1023
1028
  <xsl:attribute name="font-weight">bold</xsl:attribute>
1024
1029
  <xsl:attribute name="border">solid black 1pt</xsl:attribute>
1025
1030
  <xsl:attribute name="padding-left">1mm</xsl:attribute>
1031
+ <xsl:attribute name="padding-right">1mm</xsl:attribute>
1026
1032
  <xsl:attribute name="display-align">center</xsl:attribute>
1027
1033
 
1028
1034
 
@@ -1041,6 +1047,7 @@
1041
1047
  <xsl:attribute name="display-align">center</xsl:attribute>
1042
1048
  <xsl:attribute name="border">solid black 1pt</xsl:attribute>
1043
1049
  <xsl:attribute name="padding-left">1mm</xsl:attribute>
1050
+ <xsl:attribute name="padding-right">1mm</xsl:attribute>
1044
1051
 
1045
1052
 
1046
1053
 
@@ -1125,7 +1132,8 @@
1125
1132
  </xsl:attribute-set><xsl:attribute-set name="dt-row-style">
1126
1133
 
1127
1134
 
1128
- </xsl:attribute-set><xsl:attribute-set name="dt-style">
1135
+ </xsl:attribute-set><xsl:attribute-set name="dt-cell-style">
1136
+ </xsl:attribute-set><xsl:attribute-set name="dt-block-style">
1129
1137
  <xsl:attribute name="margin-top">6pt</xsl:attribute>
1130
1138
 
1131
1139
  <xsl:attribute name="margin-left">7mm</xsl:attribute>
@@ -1139,6 +1147,8 @@
1139
1147
 
1140
1148
 
1141
1149
 
1150
+ </xsl:attribute-set><xsl:attribute-set name="dd-cell-style">
1151
+ <xsl:attribute name="padding-left">2mm</xsl:attribute>
1142
1152
  </xsl:attribute-set><xsl:attribute-set name="appendix-style">
1143
1153
 
1144
1154
  <xsl:attribute name="font-size">12pt</xsl:attribute>
@@ -1965,7 +1975,38 @@
1965
1975
  </xsl:template><xsl:template match="*[local-name()='br']">
1966
1976
  <xsl:value-of select="$linebreak"/>
1967
1977
  </xsl:template><xsl:template match="*[local-name() = 'keep-together_within-line']">
1968
- <fo:inline keep-together.within-line="always"><xsl:apply-templates/></fo:inline>
1978
+ <xsl:param name="split_keep-within-line"/>
1979
+
1980
+ <!-- <fo:inline>split_keep-within-line='<xsl:value-of select="$split_keep-within-line"/>'</fo:inline> -->
1981
+ <xsl:choose>
1982
+
1983
+ <xsl:when test="normalize-space($split_keep-within-line) = 'true'">
1984
+ <xsl:variable name="sep">_</xsl:variable>
1985
+ <xsl:variable name="items">
1986
+ <xsl:call-template name="split">
1987
+ <xsl:with-param name="pText" select="."/>
1988
+ <xsl:with-param name="sep" select="$sep"/>
1989
+ <xsl:with-param name="normalize-space">false</xsl:with-param>
1990
+ <xsl:with-param name="keep_sep">true</xsl:with-param>
1991
+ </xsl:call-template>
1992
+ </xsl:variable>
1993
+ <xsl:for-each select="xalan:nodeset($items)/item">
1994
+ <xsl:choose>
1995
+ <xsl:when test=". = $sep">
1996
+ <xsl:value-of select="$sep"/><xsl:value-of select="$zero_width_space"/>
1997
+ </xsl:when>
1998
+ <xsl:otherwise>
1999
+ <fo:inline keep-together.within-line="always"><xsl:apply-templates/></fo:inline>
2000
+ </xsl:otherwise>
2001
+ </xsl:choose>
2002
+ </xsl:for-each>
2003
+ </xsl:when>
2004
+
2005
+ <xsl:otherwise>
2006
+ <fo:inline keep-together.within-line="always"><xsl:apply-templates/></fo:inline>
2007
+ </xsl:otherwise>
2008
+
2009
+ </xsl:choose>
1969
2010
  </xsl:template><xsl:template match="*[local-name()='copyright-statement']">
1970
2011
  <fo:block xsl:use-attribute-sets="copyright-statement-style">
1971
2012
  <xsl:apply-templates/>
@@ -2057,9 +2098,14 @@
2057
2098
 
2058
2099
  <xsl:variable name="table">
2059
2100
 
2060
- <xsl:variable name="simple-table">
2061
- <xsl:call-template name="getSimpleTable"/>
2101
+ <xsl:variable name="simple-table">
2102
+ <xsl:call-template name="getSimpleTable">
2103
+ <xsl:with-param name="id" select="@id"/>
2104
+ </xsl:call-template>
2062
2105
  </xsl:variable>
2106
+ <!-- <xsl:variable name="simple-table" select="xalan:nodeset($simple-table_)"/> -->
2107
+
2108
+ <!-- simple-table=<xsl:copy-of select="$simple-table"/> -->
2063
2109
 
2064
2110
 
2065
2111
  <!-- Display table's name before table as standalone block -->
@@ -2082,7 +2128,23 @@
2082
2128
  </xsl:call-template>
2083
2129
  </xsl:if>
2084
2130
  </xsl:variable>
2085
- <!-- DEBUG colwidths=<xsl:copy-of select="$colwidths"/> -->
2131
+ <!-- <xsl:variable name="colwidths" select="xalan:nodeset($colwidths_)"/> -->
2132
+
2133
+ <!-- DEBUG -->
2134
+ <xsl:if test="$table_if_debug = 'true'">
2135
+ <fo:block font-size="60%">
2136
+ <xsl:apply-templates select="xalan:nodeset($colwidths)" mode="print_as_xml"/>
2137
+ </fo:block>
2138
+ </xsl:if>
2139
+
2140
+
2141
+ <!-- <xsl:copy-of select="$colwidths"/> -->
2142
+
2143
+ <!-- <xsl:text disable-output-escaping="yes">&lt;!- -</xsl:text>
2144
+ DEBUG
2145
+ colwidths=<xsl:copy-of select="$colwidths"/>
2146
+ <xsl:text disable-output-escaping="yes">- -&gt;</xsl:text> -->
2147
+
2086
2148
 
2087
2149
 
2088
2150
  <xsl:variable name="margin-side">
@@ -2149,9 +2211,17 @@
2149
2211
  </xsl:element>
2150
2212
  </xsl:variable>
2151
2213
 
2214
+ <xsl:if test="$isGenerateTableIF = 'true'">
2215
+ <!-- to determine start of table -->
2216
+ <fo:block id="{concat('table_if_start_',@id)}" keep-with-next="always" font-size="1pt">Start table '<xsl:value-of select="@id"/>'.</fo:block>
2217
+ </xsl:if>
2152
2218
 
2153
2219
  <fo:table id="{@id}">
2154
2220
 
2221
+ <xsl:if test="$isGenerateTableIF = 'true'">
2222
+ <xsl:attribute name="wrap-option">no-wrap</xsl:attribute>
2223
+ </xsl:if>
2224
+
2155
2225
  <xsl:for-each select="xalan:nodeset($table_attributes)/table_attributes/@*">
2156
2226
  <xsl:attribute name="{local-name()}">
2157
2227
  <xsl:value-of select="."/>
@@ -2165,24 +2235,47 @@
2165
2235
 
2166
2236
 
2167
2237
  <xsl:choose>
2168
- <xsl:when test="*[local-name()='colgroup']/*[local-name()='col']">
2169
- <xsl:for-each select="*[local-name()='colgroup']/*[local-name()='col']">
2170
- <fo:table-column column-width="{@width}"/>
2171
- </xsl:for-each>
2238
+ <xsl:when test="$isGenerateTableIF = 'true'">
2239
+ <!-- generate IF for table widths -->
2240
+ <!-- example:
2241
+ <tr>
2242
+ <td valign="top" align="left" id="tab-symdu_1_1">
2243
+ <p>Symbol</p>
2244
+ <word id="tab-symdu_1_1_word_1">Symbol</word>
2245
+ </td>
2246
+ <td valign="top" align="left" id="tab-symdu_1_2">
2247
+ <p>Description</p>
2248
+ <word id="tab-symdu_1_2_word_1">Description</word>
2249
+ </td>
2250
+ </tr>
2251
+ -->
2252
+ <xsl:apply-templates select="xalan:nodeset($simple-table)" mode="process_table-if"/>
2253
+
2172
2254
  </xsl:when>
2173
2255
  <xsl:otherwise>
2174
- <xsl:call-template name="insertTableColumnWidth">
2175
- <xsl:with-param name="colwidths" select="$colwidths"/>
2176
- </xsl:call-template>
2177
- </xsl:otherwise>
2178
- </xsl:choose>
2179
2256
 
2180
- <xsl:choose>
2181
- <xsl:when test="not(*[local-name()='tbody']) and *[local-name()='thead']">
2182
- <xsl:apply-templates select="*[local-name()='thead']" mode="process_tbody"/>
2183
- </xsl:when>
2184
- <xsl:otherwise>
2185
- <xsl:apply-templates select="node()[not(local-name() = 'name') and not(local-name() = 'note') and not(local-name() = 'thead') and not(local-name() = 'tfoot')]"/> <!-- process all table' elements, except name, header, footer and note that renders separaterely -->
2257
+ <xsl:choose>
2258
+ <xsl:when test="*[local-name()='colgroup']/*[local-name()='col']">
2259
+ <xsl:for-each select="*[local-name()='colgroup']/*[local-name()='col']">
2260
+ <fo:table-column column-width="{@width}"/>
2261
+ </xsl:for-each>
2262
+ </xsl:when>
2263
+ <xsl:otherwise>
2264
+ <xsl:call-template name="insertTableColumnWidth">
2265
+ <xsl:with-param name="colwidths" select="$colwidths"/>
2266
+ </xsl:call-template>
2267
+ </xsl:otherwise>
2268
+ </xsl:choose>
2269
+
2270
+ <xsl:choose>
2271
+ <xsl:when test="not(*[local-name()='tbody']) and *[local-name()='thead']">
2272
+ <xsl:apply-templates select="*[local-name()='thead']" mode="process_tbody"/>
2273
+ </xsl:when>
2274
+ <xsl:otherwise>
2275
+ <xsl:apply-templates select="node()[not(local-name() = 'name') and not(local-name() = 'note') and not(local-name() = 'thead') and not(local-name() = 'tfoot')]"/> <!-- process all table' elements, except name, header, footer and note that renders separaterely -->
2276
+ </xsl:otherwise>
2277
+ </xsl:choose>
2278
+
2186
2279
  </xsl:otherwise>
2187
2280
  </xsl:choose>
2188
2281
 
@@ -2285,11 +2378,22 @@
2285
2378
  <xsl:variable name="columns-with-colspan" select="count($table-row/*[@colspan])"/>
2286
2379
  <xsl:value-of select="$columns-count + $sum-colspans - $columns-with-colspan"/>
2287
2380
  </xsl:template><xsl:template name="calculate-column-widths">
2381
+ <xsl:param name="table"/>
2382
+ <xsl:param name="cols-count"/>
2383
+
2384
+ <xsl:call-template name="calculate-column-widths-proportional">
2385
+ <xsl:with-param name="cols-count" select="$cols-count"/>
2386
+ <xsl:with-param name="table" select="$table"/>
2387
+ </xsl:call-template>
2388
+
2389
+ </xsl:template><xsl:template name="calculate-column-widths-proportional">
2288
2390
  <xsl:param name="table"/>
2289
2391
  <xsl:param name="cols-count"/>
2290
2392
  <xsl:param name="curr-col" select="1"/>
2291
2393
  <xsl:param name="width" select="0"/>
2292
2394
 
2395
+ <!-- table=<xsl:copy-of select="$table"/> -->
2396
+
2293
2397
  <xsl:if test="$curr-col &lt;= $cols-count">
2294
2398
  <xsl:variable name="widths">
2295
2399
  <xsl:choose>
@@ -2327,10 +2431,15 @@
2327
2431
  </xsl:for-each>
2328
2432
  </xsl:when>
2329
2433
  <xsl:otherwise>
2330
- <xsl:for-each select="xalan:nodeset($table)/*/tr">
2434
+ <!-- <curr_col><xsl:value-of select="$curr-col"/></curr_col> -->
2435
+
2436
+ <!-- <table><xsl:copy-of select="$table"/></table>
2437
+ -->
2438
+ <xsl:for-each select="xalan:nodeset($table)/*/*[local-name()='tr']">
2331
2439
  <xsl:variable name="td_text">
2332
2440
  <xsl:apply-templates select="td[$curr-col]" mode="td_text"/>
2333
2441
  </xsl:variable>
2442
+ <!-- <td_text><xsl:value-of select="$td_text"/></td_text> -->
2334
2443
  <xsl:variable name="words">
2335
2444
  <xsl:variable name="string_with_added_zerospaces">
2336
2445
  <xsl:call-template name="add-zero-spaces-java">
@@ -2345,6 +2454,7 @@
2345
2454
  <xsl:with-param name="text" select="normalize-space(translate($string_with_added_zerospaces, '​­', ' '))"/> <!-- replace zero-width-space and soft-hyphen to space -->
2346
2455
  </xsl:call-template>
2347
2456
  </xsl:variable>
2457
+ <!-- words=<xsl:copy-of select="$words"/> -->
2348
2458
  <xsl:variable name="max_length">
2349
2459
  <xsl:call-template name="max_length">
2350
2460
  <xsl:with-param name="words" select="xalan:nodeset($words)"/>
@@ -2369,6 +2479,8 @@
2369
2479
  </xsl:choose>
2370
2480
  </xsl:variable>
2371
2481
 
2482
+ <!-- widths=<xsl:copy-of select="$widths"/> -->
2483
+
2372
2484
  <column>
2373
2485
  <xsl:for-each select="xalan:nodeset($widths)//width">
2374
2486
  <xsl:sort select="." data-type="number" order="descending"/>
@@ -2377,33 +2489,327 @@
2377
2489
  </xsl:if>
2378
2490
  </xsl:for-each>
2379
2491
  </column>
2380
- <xsl:call-template name="calculate-column-widths">
2492
+ <xsl:call-template name="calculate-column-widths-proportional">
2381
2493
  <xsl:with-param name="cols-count" select="$cols-count"/>
2382
2494
  <xsl:with-param name="curr-col" select="$curr-col +1"/>
2383
2495
  <xsl:with-param name="table" select="$table"/>
2384
2496
  </xsl:call-template>
2385
2497
  </xsl:if>
2386
- </xsl:template><xsl:template match="*[@keep-together.within-line]/text()" priority="2" mode="td_text">
2498
+ </xsl:template><xsl:template match="*[@keep-together.within-line or local-name() = 'keep-together_within-line']/text()" priority="2" mode="td_text">
2387
2499
  <!-- <xsl:message>DEBUG t1=<xsl:value-of select="."/></xsl:message>
2388
2500
  <xsl:message>DEBUG t2=<xsl:value-of select="java:replaceAll(java:java.lang.String.new(.),'.','X')"/></xsl:message> -->
2389
2501
  <xsl:value-of select="java:replaceAll(java:java.lang.String.new(.),'.','X')"/>
2502
+
2503
+ <!-- if all capitals english letters or digits -->
2504
+ <xsl:if test="normalize-space(translate(., concat($upper,'0123456789'), '')) = ''">
2505
+ <xsl:call-template name="repeat">
2506
+ <xsl:with-param name="char" select="'X'"/>
2507
+ <xsl:with-param name="count" select="string-length(normalize-space(.)) * 0.5"/>
2508
+ </xsl:call-template>
2509
+ </xsl:if>
2390
2510
  </xsl:template><xsl:template match="text()" mode="td_text">
2391
2511
  <xsl:value-of select="translate(., $zero_width_space, ' ')"/><xsl:text> </xsl:text>
2392
2512
  </xsl:template><xsl:template match="*[local-name()='termsource']" mode="td_text">
2393
2513
  <xsl:value-of select="*[local-name()='origin']/@citeas"/>
2394
2514
  </xsl:template><xsl:template match="*[local-name()='link']" mode="td_text">
2395
2515
  <xsl:value-of select="@target"/>
2396
- </xsl:template><xsl:template match="*[local-name()='math']" mode="td_text">
2397
- <xsl:variable name="mathml">
2398
- <xsl:for-each select="*">
2399
- <xsl:if test="local-name() != 'unit' and local-name() != 'prefix' and local-name() != 'dimension' and local-name() != 'quantity'">
2400
- <xsl:copy-of select="."/>
2516
+ </xsl:template><xsl:template match="*[local-name()='math']" mode="td_text" name="math_length">
2517
+ <xsl:if test="$isGenerateTableIF = 'false'">
2518
+ <xsl:variable name="mathml_">
2519
+ <xsl:for-each select="*">
2520
+ <xsl:if test="local-name() != 'unit' and local-name() != 'prefix' and local-name() != 'dimension' and local-name() != 'quantity'">
2521
+ <xsl:copy-of select="."/>
2522
+ </xsl:if>
2523
+ </xsl:for-each>
2524
+ </xsl:variable>
2525
+ <xsl:variable name="mathml" select="xalan:nodeset($mathml_)"/>
2526
+
2527
+ <xsl:variable name="math_text">
2528
+ <xsl:value-of select="normalize-space($mathml)"/>
2529
+ <xsl:for-each select="$mathml//@open"><xsl:value-of select="."/></xsl:for-each>
2530
+ <xsl:for-each select="$mathml//@close"><xsl:value-of select="."/></xsl:for-each>
2531
+ </xsl:variable>
2532
+ <xsl:value-of select="translate($math_text, ' ', '#')"/><!-- mathml images as one 'word' without spaces -->
2533
+ </xsl:if>
2534
+ </xsl:template><xsl:template name="calculate-column-widths-autolayout-algorithm">
2535
+ <xsl:param name="table"/>
2536
+ <xsl:param name="if">false</xsl:param> <!-- via intermediate format -->
2537
+
2538
+ <!-- The algorithm uses two passes through the table data and scales linearly with the size of the table -->
2539
+
2540
+ <!-- In the first pass, line wrapping is disabled, and the user agent keeps track of the minimum and maximum width of each cell. -->
2541
+
2542
+ <!-- Since line wrap has been disabled, paragraphs are treated as long lines unless broken by BR elements. -->
2543
+
2544
+ <!-- get current table id -->
2545
+ <xsl:variable name="table_id" select="@id"/>
2546
+ <!-- find table by id in the file 'table_widths' -->
2547
+ <xsl:variable name="table-if_" select="$table_widths_from_if//table[@id = $table_id]"/>
2548
+ <xsl:variable name="table-if" select="xalan:nodeset($table-if_)"/>
2549
+
2550
+
2551
+ <!-- table='<xsl:copy-of select="$table"/>' -->
2552
+ <!-- table_id='<xsl:value-of select="$table_id"/>\ -->
2553
+ <!-- table-if='<xsl:copy-of select="$table-if"/>' -->
2554
+ <!-- table_widths_from_if='<xsl:copy-of select="$table_widths_from_if"/>' -->
2555
+
2556
+ <xsl:variable name="table_with_cell_widths_">
2557
+ <xsl:choose>
2558
+ <xsl:when test="$if = 'true' and normalize-space($table-if) != ''"> <!-- if we read column's width from IF and there is table in IF -->
2559
+
2560
+ <!-- Example: <column>10</column>
2561
+ <column>11</column>
2562
+ -->
2563
+ <xsl:apply-templates select="$table-if" mode="determine_cell_widths-if"/>
2564
+ </xsl:when>
2565
+ <xsl:otherwise>
2566
+ <xsl:apply-templates select="xalan:nodeset($table)" mode="determine_cell_widths"/>
2567
+ </xsl:otherwise>
2568
+ </xsl:choose>
2569
+ </xsl:variable>
2570
+ <xsl:variable name="table_with_cell_widths" select="xalan:nodeset($table_with_cell_widths_)"/>
2571
+
2572
+ <xsl:if test="$table_if_debug = 'true'">
2573
+ <xsl:copy-of select="$table_with_cell_widths"/>
2574
+ </xsl:if>
2575
+
2576
+
2577
+ <!-- The minimum and maximum cell widths are then used to determine the corresponding minimum and maximum widths for the columns. -->
2578
+
2579
+ <xsl:variable name="column_widths_">
2580
+ <!-- iteration of columns -->
2581
+ <xsl:for-each select="$table_with_cell_widths//tr[1]/td">
2582
+ <xsl:variable name="pos" select="position()"/>
2583
+ <column>
2584
+ <xsl:attribute name="width_max">
2585
+ <xsl:for-each select="ancestor::tbody//tr/td[$pos]/@width_max">
2586
+ <xsl:sort select="." data-type="number" order="descending"/>
2587
+ <xsl:if test="position() = 1"><xsl:value-of select="."/></xsl:if>
2588
+ </xsl:for-each>
2589
+ </xsl:attribute>
2590
+ <xsl:attribute name="width_min">
2591
+ <xsl:for-each select="ancestor::tbody//tr/td[$pos]/@width_min">
2592
+ <xsl:sort select="." data-type="number" order="descending"/>
2593
+ <xsl:if test="position() = 1"><xsl:value-of select="."/></xsl:if>
2594
+ </xsl:for-each>
2595
+ </xsl:attribute>
2596
+ </column>
2597
+ </xsl:for-each>
2598
+ </xsl:variable>
2599
+ <xsl:variable name="column_widths" select="xalan:nodeset($column_widths_)"/>
2600
+
2601
+ <!-- <column_widths>
2602
+ <xsl:copy-of select="$column_widths"/>
2603
+ </column_widths> -->
2604
+
2605
+ <!-- These in turn, are used to find the minimum and maximum width for the table. -->
2606
+ <xsl:variable name="table_widths_">
2607
+ <table>
2608
+ <xsl:attribute name="width_max">
2609
+ <xsl:value-of select="sum($column_widths/column/@width_max)"/>
2610
+ </xsl:attribute>
2611
+ <xsl:attribute name="width_min">
2612
+ <xsl:value-of select="sum($column_widths/column/@width_min)"/>
2613
+ </xsl:attribute>
2614
+ </table>
2615
+ </xsl:variable>
2616
+ <xsl:variable name="table_widths" select="xalan:nodeset($table_widths_)"/>
2617
+
2618
+ <xsl:variable name="page_width">
2619
+ <xsl:choose>
2620
+ <xsl:when test="$if = 'true'"><xsl:value-of select="$table-if/@page-width"/></xsl:when>
2621
+ <xsl:otherwise>75</xsl:otherwise>
2622
+ </xsl:choose>
2623
+ </xsl:variable>
2624
+
2625
+ <xsl:if test="$table_if_debug = 'true'">
2626
+ <table_width>
2627
+ <xsl:copy-of select="$table_widths"/>
2628
+ </table_width>
2629
+ <!-- <debug>$table_widths/@width_min=<xsl:value-of select="$table_widths/table/@width_min"/></debug>
2630
+ <debug>$table_widths/@width_max=<xsl:value-of select="$table_widths/table/@width_max"/></debug>
2631
+ -->
2632
+ <debug>$page_width=<xsl:value-of select="$page_width"/></debug>
2633
+ </xsl:if>
2634
+
2635
+
2636
+ <!-- There are three cases: -->
2637
+ <xsl:choose>
2638
+ <!-- 1. The minimum table width is equal to or wider than the available space -->
2639
+ <xsl:when test="$table_widths/table/@width_min &gt;= $page_width and 1 = 2"> <!-- this condition isn't working see case 3 below -->
2640
+ <!-- call old algorithm -->
2641
+ <case1/>
2642
+ <xsl:variable name="cols-count" select="count(xalan:nodeset($table)/*/tr[1]/td)"/>
2643
+ <xsl:call-template name="calculate-column-widths-proportional">
2644
+ <xsl:with-param name="cols-count" select="$cols-count"/>
2645
+ <xsl:with-param name="table" select="$table"/>
2646
+ </xsl:call-template>
2647
+ </xsl:when>
2648
+ <!-- 2. The maximum table width fits within the available space. In this case, set the columns to their maximum widths. -->
2649
+ <xsl:when test="$table_widths/table/@width_max &lt;= $page_width">
2650
+ <case2/>
2651
+ <autolayout/>
2652
+ <xsl:for-each select="$column_widths/column/@width_max">
2653
+ <column divider="100"><xsl:value-of select="."/></column>
2654
+ </xsl:for-each>
2655
+ </xsl:when>
2656
+ <!-- 3. The maximum width of the table is greater than the available space, but the minimum table width is smaller.
2657
+ In this case, find the difference between the available space and the minimum table width, lets call it W.
2658
+ Lets also call D the difference between maximum and minimum width of the table.
2659
+ For each column, let d be the difference between maximum and minimum width of that column.
2660
+ Now set the column's width to the minimum width plus d times W over D.
2661
+ This makes columns with large differences between minimum and maximum widths wider than columns with smaller differences. -->
2662
+ <xsl:when test="($table_widths/table/@width_max &gt; $page_width and $table_widths/table/@width_min &lt; $page_width) or ($table_widths/table/@width_min &gt;= $page_width)">
2663
+ <!-- difference between the available space and the minimum table width -->
2664
+ <xsl:variable name="W" select="$page_width - $table_widths/table/@width_min"/>
2665
+ <W><xsl:value-of select="$W"/></W>
2666
+ <!-- difference between maximum and minimum width of the table -->
2667
+ <xsl:variable name="D" select="$table_widths/table/@width_max - $table_widths/table/@width_min"/>
2668
+ <D><xsl:value-of select="$D"/></D>
2669
+ <case3/>
2670
+ <autolayout/>
2671
+ <xsl:if test="$table_widths/table/@width_min &gt;= $page_width">
2672
+ <split_keep-within-line>true</split_keep-within-line>
2401
2673
  </xsl:if>
2674
+ <xsl:for-each select="$column_widths/column">
2675
+ <!-- difference between maximum and minimum width of that column. -->
2676
+ <xsl:variable name="d" select="@width_max - @width_min"/>
2677
+ <d><xsl:value-of select="$d"/></d>
2678
+ <width_min><xsl:value-of select="@width_min"/></width_min>
2679
+ <e><xsl:value-of select="$d * $W div $D"/></e>
2680
+ <!-- set the column's width to the minimum width plus d times W over D. -->
2681
+ <column divider="100">
2682
+ <xsl:value-of select="round(@width_min + $d * $W div $D)"/> <!-- * 10 -->
2683
+ </column>
2684
+ </xsl:for-each>
2685
+
2686
+ </xsl:when>
2687
+ <xsl:otherwise><unknown_case/></xsl:otherwise>
2688
+ </xsl:choose>
2689
+
2690
+
2691
+ </xsl:template><xsl:template match="@*|node()" mode="determine_cell_widths">
2692
+ <xsl:copy>
2693
+ <xsl:apply-templates select="@*|node()" mode="determine_cell_widths"/>
2694
+ </xsl:copy>
2695
+ </xsl:template><xsl:template match="td | th" mode="determine_cell_widths">
2696
+ <xsl:copy>
2697
+ <xsl:copy-of select="@*"/>
2698
+
2699
+ <!-- The maximum width is given by the widest line. -->
2700
+ <xsl:variable name="widths_max">
2701
+ <xsl:for-each select=".//*[local-name() = 'p']">
2702
+ <xsl:call-template name="add_width"/>
2703
+ </xsl:for-each>
2704
+ <xsl:if test="not(*[local-name() = 'p'])">
2705
+ <xsl:call-template name="add_width"/>
2706
+ </xsl:if>
2707
+ </xsl:variable>
2708
+ <xsl:variable name="width_max">
2709
+ <xsl:for-each select="xalan:nodeset($widths_max)//width">
2710
+ <xsl:sort select="." data-type="number" order="descending"/>
2711
+ <xsl:if test="position() = 1"><xsl:value-of select="."/></xsl:if>
2712
+ </xsl:for-each>
2713
+ </xsl:variable>
2714
+ <xsl:attribute name="width_max">
2715
+ <xsl:value-of select="$width_max"/>
2716
+ </xsl:attribute>
2717
+
2718
+ <!-- The minimum width is given by the widest text element (word, image, etc.) -->
2719
+ <!-- To do: image width -->
2720
+ <xsl:variable name="td_text">
2721
+ <xsl:apply-templates select="." mode="td_text"/>
2722
+ </xsl:variable>
2723
+ <xsl:variable name="words">
2724
+ <xsl:variable name="string_with_added_zerospaces">
2725
+ <xsl:call-template name="add-zero-spaces-java">
2726
+ <xsl:with-param name="text" select="$td_text"/>
2727
+ </xsl:call-template>
2728
+ </xsl:variable>
2729
+ <xsl:call-template name="tokenize">
2730
+ <xsl:with-param name="text" select="normalize-space(translate($string_with_added_zerospaces, '​­', ' '))"/> <!-- replace zero-width-space and soft-hyphen to space -->
2731
+ </xsl:call-template>
2732
+ </xsl:variable>
2733
+
2734
+ <xsl:variable name="max_word_length">
2735
+ <xsl:call-template name="max_length">
2736
+ <xsl:with-param name="words" select="xalan:nodeset($words)"/>
2737
+ </xsl:call-template>
2738
+ </xsl:variable>
2739
+ <xsl:variable name="width_min">
2740
+ <xsl:value-of select="$max_word_length"/>
2741
+ </xsl:variable>
2742
+ <xsl:attribute name="width_min">
2743
+ <xsl:value-of select="$width_min"/>
2744
+ </xsl:attribute>
2745
+ <!-- width_max="1" width_min="1.5"> --> <!-- see 'tokenize' template, multiply 1.5 for all latin capitals -->
2746
+ <xsl:if test="$width_min &gt; $width_max">
2747
+ <xsl:attribute name="width_max">
2748
+ <xsl:value-of select="$width_min"/>
2749
+ </xsl:attribute>
2750
+ </xsl:if>
2751
+ <xsl:if test="$width_min = 0">
2752
+ <xsl:attribute name="width_min">1</xsl:attribute>
2753
+ </xsl:if>
2754
+
2755
+ <xsl:apply-templates select="node()" mode="determine_cell_widths"/>
2756
+
2757
+ </xsl:copy>
2758
+ </xsl:template><xsl:template name="add_width">
2759
+ <xsl:variable name="p_text"><xsl:apply-templates select="." mode="td_text"/></xsl:variable>
2760
+ <xsl:variable name="p_text_len_" select="string-length(normalize-space($p_text))"/>
2761
+
2762
+ <xsl:variable name="p_text_len">
2763
+ <xsl:choose>
2764
+ <xsl:when test="normalize-space(translate($p_text, concat($upper,'0123456789'), '')) = ''"> <!-- english word in CAPITAL letters -->
2765
+ <xsl:value-of select="$p_text_len_ * 1.5"/>
2766
+ </xsl:when>
2767
+ <xsl:otherwise><xsl:value-of select="$p_text_len_"/></xsl:otherwise>
2768
+ </xsl:choose>
2769
+ </xsl:variable>
2770
+
2771
+ <xsl:variable name="math_addon_text">
2772
+ <xsl:for-each select=".//*[local-name() = 'math']">
2773
+ <xsl:apply-templates mode="td_text"/>
2402
2774
  </xsl:for-each>
2403
2775
  </xsl:variable>
2776
+ <xsl:variable name="math_addon_length" select="string-length(normalize-space($math_addon_text)) * 0.2"/> <!-- plus 20% -->
2404
2777
 
2405
- <xsl:variable name="math_text" select="normalize-space(xalan:nodeset($mathml))"/>
2406
- <xsl:value-of select="translate($math_text, ' ', '#')"/><!-- mathml images as one 'word' without spaces -->
2778
+ <width><xsl:value-of select="$p_text_len + $math_addon_length"/></width>
2779
+ </xsl:template><xsl:template match="@*|node()" mode="determine_cell_widths-if">
2780
+ <xsl:copy>
2781
+ <xsl:apply-templates select="@*|node()" mode="determine_cell_widths-if"/>
2782
+ </xsl:copy>
2783
+ </xsl:template><xsl:template match="td | th" mode="determine_cell_widths-if">
2784
+ <xsl:copy>
2785
+ <xsl:copy-of select="@*"/>
2786
+
2787
+ <!-- The maximum width is given by the widest line. -->
2788
+ <xsl:attribute name="width_max">
2789
+ <xsl:for-each select="p_len">
2790
+ <xsl:sort select="." data-type="number" order="descending"/>
2791
+ <xsl:if test="position() = 1"><xsl:value-of select="."/></xsl:if>
2792
+ </xsl:for-each>
2793
+ </xsl:attribute>
2794
+
2795
+ <!-- The minimum width is given by the widest text element (word, image, etc.) -->
2796
+ <xsl:variable name="width_min">
2797
+ <xsl:for-each select="word_len">
2798
+ <xsl:sort select="." data-type="number" order="descending"/>
2799
+ <xsl:if test="position() = 1"><xsl:value-of select="."/></xsl:if>
2800
+ </xsl:for-each>
2801
+ </xsl:variable>
2802
+ <xsl:attribute name="width_min">
2803
+ <xsl:value-of select="$width_min"/>
2804
+ </xsl:attribute>
2805
+
2806
+ <xsl:if test="$width_min = 0">
2807
+ <xsl:attribute name="width_min">1</xsl:attribute>
2808
+ </xsl:if>
2809
+
2810
+ <xsl:apply-templates select="node()" mode="determine_cell_widths-if"/>
2811
+
2812
+ </xsl:copy>
2407
2813
  </xsl:template><xsl:template match="*[local-name()='thead']">
2408
2814
  <xsl:param name="cols-count"/>
2409
2815
  <fo:table-header>
@@ -2488,6 +2894,7 @@
2488
2894
  </xsl:for-each>
2489
2895
  </xsl:when>
2490
2896
  <xsl:otherwise>
2897
+ <!-- $colwidths=<xsl:copy-of select="$colwidths"/> -->
2491
2898
  <xsl:call-template name="insertTableColumnWidth">
2492
2899
  <xsl:with-param name="colwidths" select="$colwidths"/>
2493
2900
  </xsl:call-template>
@@ -2567,6 +2974,52 @@
2567
2974
 
2568
2975
  </fo:table-body>
2569
2976
 
2977
+ </xsl:template><xsl:template match="/" mode="process_table-if">
2978
+ <xsl:param name="table_or_dl">table</xsl:param>
2979
+ <xsl:apply-templates mode="process_table-if">
2980
+ <xsl:with-param name="table_or_dl" select="$table_or_dl"/>
2981
+ </xsl:apply-templates>
2982
+ </xsl:template><xsl:template match="*[local-name()='tbody']" mode="process_table-if">
2983
+ <xsl:param name="table_or_dl">table</xsl:param>
2984
+
2985
+ <fo:table-body>
2986
+ <xsl:for-each select="*[local-name() = 'tr']">
2987
+ <xsl:variable name="col_count" select="count(*)"/>
2988
+
2989
+ <!-- iteration for each tr/td -->
2990
+
2991
+ <xsl:choose>
2992
+ <xsl:when test="$table_or_dl = 'table'">
2993
+ <xsl:for-each select="*[local-name() = 'td' or local-name() = 'th']/*">
2994
+ <fo:table-row number-columns-spanned="{$col_count}">
2995
+ <!-- <test_table><xsl:copy-of select="."/></test_table> -->
2996
+ <xsl:call-template name="td"/>
2997
+ </fo:table-row>
2998
+ </xsl:for-each>
2999
+ </xsl:when>
3000
+ <xsl:otherwise> <!-- $table_or_dl = 'dl' -->
3001
+ <xsl:for-each select="*[local-name() = 'td' or local-name() = 'th']">
3002
+ <xsl:variable name="is_dt" select="position() = 1"/>
3003
+
3004
+ <xsl:for-each select="*">
3005
+ <!-- <test><xsl:copy-of select="."/></test> -->
3006
+ <fo:table-row number-columns-spanned="{$col_count}">
3007
+ <xsl:choose>
3008
+ <xsl:when test="$is_dt">
3009
+ <xsl:call-template name="insert_dt_cell"/>
3010
+ </xsl:when>
3011
+ <xsl:otherwise>
3012
+ <xsl:call-template name="insert_dd_cell"/>
3013
+ </xsl:otherwise>
3014
+ </xsl:choose>
3015
+ </fo:table-row>
3016
+ </xsl:for-each>
3017
+ </xsl:for-each>
3018
+ </xsl:otherwise>
3019
+ </xsl:choose>
3020
+
3021
+ </xsl:for-each>
3022
+ </fo:table-body>
2570
3023
  </xsl:template><xsl:template match="*[local-name()='thead']/*[local-name()='tr']" priority="2">
2571
3024
  <fo:table-row xsl:use-attribute-sets="table-header-row-style">
2572
3025
 
@@ -2653,7 +3106,7 @@
2653
3106
  </xsl:choose>
2654
3107
  </xsl:attribute>
2655
3108
  </xsl:if>
2656
- </xsl:template><xsl:template match="*[local-name()='td']">
3109
+ </xsl:template><xsl:template match="*[local-name()='td']" name="td">
2657
3110
  <fo:table-cell xsl:use-attribute-sets="table-cell-style"> <!-- text-align="{@align}" -->
2658
3111
  <xsl:call-template name="setTextAlignment">
2659
3112
  <xsl:with-param name="default">left</xsl:with-param>
@@ -2687,11 +3140,24 @@
2687
3140
 
2688
3141
  <xsl:call-template name="setTableCellAttributes"/>
2689
3142
 
3143
+ <xsl:if test="$isGenerateTableIF = 'true'">
3144
+ <xsl:attribute name="border">1pt solid black</xsl:attribute> <!-- border is mandatory, to determine page width -->
3145
+ <xsl:attribute name="text-align">left</xsl:attribute>
3146
+ </xsl:if>
3147
+
2690
3148
  <fo:block>
2691
3149
 
3150
+ <xsl:if test="$isGenerateTableIF = 'true'">
3151
+ <xsl:attribute name="id"><xsl:value-of select="@id"/></xsl:attribute>
3152
+ </xsl:if>
3153
+
3154
+
2692
3155
 
2693
3156
 
2694
3157
  <xsl:apply-templates/>
3158
+
3159
+ <xsl:if test="$isGenerateTableIF = 'true'"><fo:inline id="{@id}_end">end</fo:inline></xsl:if> <!-- to determine width of text --> <!-- <xsl:value-of select="$hair_space"/> -->
3160
+
2695
3161
  </fo:block>
2696
3162
  </fo:table-cell>
2697
3163
  </xsl:template><xsl:template match="*[local-name()='table']/*[local-name()='note']" priority="2">
@@ -2888,9 +3354,9 @@
2888
3354
  <!-- current hierarchy is 'figure' element -->
2889
3355
  <xsl:variable name="following_dl_colwidths">
2890
3356
  <xsl:if test="*[local-name() = 'dl']"><!-- if there is a 'dl', then set the same columns width as for 'dl' -->
2891
- <xsl:variable name="html-table">
2892
- <xsl:variable name="doc_ns">
2893
-
3357
+ <xsl:variable name="simple-table">
3358
+ <!-- <xsl:variable name="doc_ns">
3359
+ <xsl:if test="$namespace = 'bipm'">bipm</xsl:if>
2894
3360
  </xsl:variable>
2895
3361
  <xsl:variable name="ns">
2896
3362
  <xsl:choose>
@@ -2901,7 +3367,7 @@
2901
3367
  <xsl:value-of select="substring-before(name(/*), '-')"/>
2902
3368
  </xsl:otherwise>
2903
3369
  </xsl:choose>
2904
- </xsl:variable>
3370
+ </xsl:variable> -->
2905
3371
 
2906
3372
  <xsl:for-each select="*[local-name() = 'dl'][1]">
2907
3373
  <tbody>
@@ -2912,7 +3378,7 @@
2912
3378
 
2913
3379
  <xsl:call-template name="calculate-column-widths">
2914
3380
  <xsl:with-param name="cols-count" select="2"/>
2915
- <xsl:with-param name="table" select="$html-table"/>
3381
+ <xsl:with-param name="table" select="$simple-table"/>
2916
3382
  </xsl:call-template>
2917
3383
 
2918
3384
  </xsl:if>
@@ -3092,7 +3558,18 @@
3092
3558
 
3093
3559
 
3094
3560
 
3561
+
3562
+ <xsl:if test="$isGenerateTableIF = 'true'">
3563
+ <!-- to determine start of table -->
3564
+ <fo:block id="{concat('table_if_start_',@id)}" keep-with-next="always" font-size="1pt">Start table '<xsl:value-of select="@id"/>'.</fo:block>
3565
+ </xsl:if>
3566
+
3095
3567
  <fo:table width="95%" table-layout="fixed">
3568
+
3569
+ <xsl:if test="$isGenerateTableIF = 'true'">
3570
+ <xsl:attribute name="wrap-option">no-wrap</xsl:attribute>
3571
+ </xsl:if>
3572
+
3096
3573
 
3097
3574
  <xsl:choose>
3098
3575
  <xsl:when test="normalize-space($key_iso) = 'true' and $parent = 'formula'"/>
@@ -3101,52 +3578,130 @@
3101
3578
 
3102
3579
  </xsl:when>
3103
3580
  </xsl:choose>
3104
- <!-- create virtual html table for dl/[dt and dd] -->
3105
- <xsl:variable name="html-table">
3106
- <xsl:variable name="doc_ns">
3581
+
3582
+
3583
+ <xsl:choose>
3584
+ <xsl:when test="$isGenerateTableIF = 'true'">
3585
+ <!-- generate IF for table widths -->
3586
+ <!-- example:
3587
+ <tr>
3588
+ <td valign="top" align="left" id="tab-symdu_1_1">
3589
+ <p>Symbol</p>
3590
+ <word id="tab-symdu_1_1_word_1">Symbol</word>
3591
+ </td>
3592
+ <td valign="top" align="left" id="tab-symdu_1_2">
3593
+ <p>Description</p>
3594
+ <word id="tab-symdu_1_2_word_1">Description</word>
3595
+ </td>
3596
+ </tr>
3597
+ -->
3107
3598
 
3108
- </xsl:variable>
3109
- <xsl:variable name="ns">
3110
- <xsl:choose>
3111
- <xsl:when test="normalize-space($doc_ns) != ''">
3112
- <xsl:value-of select="normalize-space($doc_ns)"/>
3113
- </xsl:when>
3114
- <xsl:otherwise>
3115
- <xsl:value-of select="substring-before(name(/*), '-')"/>
3116
- </xsl:otherwise>
3117
- </xsl:choose>
3118
- </xsl:variable>
3119
- <tbody>
3120
- <xsl:apply-templates mode="dl"/>
3121
- </tbody>
3122
- </xsl:variable>
3123
- <!-- DEBUG: html-table<xsl:copy-of select="$html-table"/> -->
3124
- <xsl:variable name="colwidths">
3125
- <xsl:call-template name="calculate-column-widths">
3126
- <xsl:with-param name="cols-count" select="2"/>
3127
- <xsl:with-param name="table" select="$html-table"/>
3128
- </xsl:call-template>
3129
- </xsl:variable>
3130
- <!-- DEBUG: colwidths=<xsl:copy-of select="$colwidths"/> -->
3131
- <xsl:variable name="maxlength_dt">
3132
- <xsl:call-template name="getMaxLength_dt"/>
3133
- </xsl:variable>
3134
- <xsl:variable name="isContainsKeepTogetherTag_">
3135
- false
3136
- </xsl:variable>
3137
- <xsl:variable name="isContainsKeepTogetherTag" select="normalize-space($isContainsKeepTogetherTag_)"/>
3138
- <!-- isContainsExpressReference=<xsl:value-of select="$isContainsExpressReference"/> -->
3139
- <xsl:call-template name="setColumnWidth_dl">
3140
- <xsl:with-param name="colwidths" select="$colwidths"/>
3141
- <xsl:with-param name="maxlength_dt" select="$maxlength_dt"/>
3142
- <xsl:with-param name="isContainsKeepTogetherTag" select="$isContainsKeepTogetherTag"/>
3143
- </xsl:call-template>
3599
+ <!-- create virtual html table for dl/[dt and dd] -->
3600
+ <xsl:variable name="simple-table">
3601
+
3602
+ <xsl:variable name="dl_table">
3603
+ <tbody>
3604
+ <xsl:apply-templates mode="dl_if">
3605
+ <xsl:with-param name="id" select="@id"/>
3606
+ </xsl:apply-templates>
3607
+ </tbody>
3608
+ </xsl:variable>
3609
+
3610
+ <!-- dl_table='<xsl:copy-of select="$dl_table"/>' -->
3611
+
3612
+ <!-- Step: replace <br/> to <p>...</p> -->
3613
+ <xsl:variable name="table_without_br">
3614
+ <xsl:apply-templates select="xalan:nodeset($dl_table)" mode="table-without-br"/>
3615
+ </xsl:variable>
3616
+
3617
+ <!-- table_without_br='<xsl:copy-of select="$table_without_br"/>' -->
3618
+
3619
+ <!-- Step: add id to each cell -->
3620
+ <!-- add <word>...</word> for each word, image, math -->
3621
+ <xsl:variable name="simple-table-id">
3622
+ <xsl:apply-templates select="xalan:nodeset($table_without_br)" mode="simple-table-id">
3623
+ <xsl:with-param name="id" select="@id"/>
3624
+ </xsl:apply-templates>
3625
+ </xsl:variable>
3626
+
3627
+ <!-- simple-table-id='<xsl:copy-of select="$simple-table-id"/>' -->
3628
+
3629
+ <xsl:copy-of select="xalan:nodeset($simple-table-id)"/>
3630
+
3631
+ </xsl:variable>
3632
+
3633
+ <!-- DEBUG: simple-table<xsl:copy-of select="$simple-table"/> -->
3634
+
3635
+ <xsl:apply-templates select="xalan:nodeset($simple-table)" mode="process_table-if">
3636
+ <xsl:with-param name="table_or_dl">dl</xsl:with-param>
3637
+ </xsl:apply-templates>
3638
+
3639
+ </xsl:when>
3640
+ <xsl:otherwise>
3144
3641
 
3145
- <fo:table-body>
3146
- <xsl:apply-templates>
3147
- <xsl:with-param name="key_iso" select="normalize-space($key_iso)"/>
3148
- </xsl:apply-templates>
3149
- </fo:table-body>
3642
+ <xsl:variable name="simple-table">
3643
+
3644
+ <xsl:variable name="dl_table">
3645
+ <tbody>
3646
+ <xsl:apply-templates mode="dl">
3647
+ <xsl:with-param name="id" select="@id"/>
3648
+ </xsl:apply-templates>
3649
+ </tbody>
3650
+ </xsl:variable>
3651
+
3652
+ <xsl:copy-of select="$dl_table"/>
3653
+ </xsl:variable>
3654
+
3655
+ <xsl:variable name="colwidths">
3656
+ <xsl:call-template name="calculate-column-widths">
3657
+ <xsl:with-param name="cols-count" select="2"/>
3658
+ <xsl:with-param name="table" select="$simple-table"/>
3659
+ </xsl:call-template>
3660
+ </xsl:variable>
3661
+
3662
+ <!-- <xsl:text disable-output-escaping="yes">&lt;!- -</xsl:text>
3663
+ DEBUG
3664
+ colwidths=<xsl:copy-of select="$colwidths"/>
3665
+ <xsl:text disable-output-escaping="yes">- -&gt;</xsl:text> -->
3666
+
3667
+ <!-- colwidths=<xsl:copy-of select="$colwidths"/> -->
3668
+
3669
+ <xsl:variable name="maxlength_dt">
3670
+ <xsl:call-template name="getMaxLength_dt"/>
3671
+ </xsl:variable>
3672
+
3673
+ <xsl:variable name="isContainsKeepTogetherTag_">
3674
+ false
3675
+ </xsl:variable>
3676
+ <xsl:variable name="isContainsKeepTogetherTag" select="normalize-space($isContainsKeepTogetherTag_)"/>
3677
+ <!-- isContainsExpressReference=<xsl:value-of select="$isContainsExpressReference"/> -->
3678
+
3679
+
3680
+ <xsl:call-template name="setColumnWidth_dl">
3681
+ <xsl:with-param name="colwidths" select="$colwidths"/>
3682
+ <xsl:with-param name="maxlength_dt" select="$maxlength_dt"/>
3683
+ <xsl:with-param name="isContainsKeepTogetherTag" select="$isContainsKeepTogetherTag"/>
3684
+ </xsl:call-template>
3685
+
3686
+ <fo:table-body>
3687
+
3688
+ <!-- DEBUG -->
3689
+ <xsl:if test="$table_if_debug = 'true'">
3690
+ <fo:table-row>
3691
+ <fo:table-cell number-columns-spanned="2" font-size="60%">
3692
+ <xsl:apply-templates select="xalan:nodeset($colwidths)" mode="print_as_xml"/>
3693
+ </fo:table-cell>
3694
+ </fo:table-row>
3695
+ </xsl:if>
3696
+
3697
+ <xsl:apply-templates>
3698
+ <xsl:with-param name="key_iso" select="normalize-space($key_iso)"/>
3699
+ <xsl:with-param name="split_keep-within-line" select="xalan:nodeset($colwidths)/split_keep-within-line"/>
3700
+ </xsl:apply-templates>
3701
+
3702
+ </fo:table-body>
3703
+ </xsl:otherwise>
3704
+ </xsl:choose>
3150
3705
  </fo:table>
3151
3706
  </fo:block>
3152
3707
  </fo:block>
@@ -3157,6 +3712,9 @@
3157
3712
  <xsl:param name="colwidths"/>
3158
3713
  <xsl:param name="maxlength_dt"/>
3159
3714
  <xsl:param name="isContainsKeepTogetherTag"/>
3715
+
3716
+ <!-- <colwidths><xsl:copy-of select="$colwidths"/></colwidths> -->
3717
+
3160
3718
  <xsl:choose>
3161
3719
  <xsl:when test="ancestor::*[local-name()='dl']"><!-- second level, i.e. inlined table -->
3162
3720
  <fo:table-column column-width="50%"/>
@@ -3164,6 +3722,11 @@
3164
3722
  </xsl:when>
3165
3723
  <xsl:otherwise>
3166
3724
  <xsl:choose>
3725
+ <xsl:when test="xalan:nodeset($colwidths)/autolayout">
3726
+ <xsl:call-template name="insertTableColumnWidth">
3727
+ <xsl:with-param name="colwidths" select="$colwidths"/>
3728
+ </xsl:call-template>
3729
+ </xsl:when>
3167
3730
  <xsl:when test="$isContainsKeepTogetherTag">
3168
3731
  <xsl:call-template name="insertTableColumnWidth">
3169
3732
  <xsl:with-param name="colwidths" select="$colwidths"/>
@@ -3208,13 +3771,19 @@
3208
3771
  </xsl:choose>
3209
3772
  </xsl:template><xsl:template name="insertTableColumnWidth">
3210
3773
  <xsl:param name="colwidths"/>
3774
+
3211
3775
  <xsl:for-each select="xalan:nodeset($colwidths)//column">
3212
3776
  <xsl:choose>
3213
3777
  <xsl:when test=". = 1 or . = 0">
3214
3778
  <fo:table-column column-width="proportional-column-width(2)"/>
3215
3779
  </xsl:when>
3216
3780
  <xsl:otherwise>
3217
- <fo:table-column column-width="proportional-column-width({.})"/>
3781
+ <!-- <fo:table-column column-width="proportional-column-width({.})"/> -->
3782
+ <xsl:variable name="divider">
3783
+ <xsl:value-of select="@divider"/>
3784
+ <xsl:if test="not(@divider)">1</xsl:if>
3785
+ </xsl:variable>
3786
+ <fo:table-column column-width="proportional-column-width({round(. div $divider)})"/>
3218
3787
  </xsl:otherwise>
3219
3788
  </xsl:choose>
3220
3789
  </xsl:for-each>
@@ -3276,11 +3845,19 @@
3276
3845
  </fo:table-cell>
3277
3846
  </fo:table-row>
3278
3847
  </xsl:template><xsl:template match="*[local-name()='dt']" mode="dl">
3848
+ <xsl:param name="id"/>
3849
+ <xsl:variable name="row_number" select="count(preceding-sibling::*[local-name()='dt']) + 1"/>
3279
3850
  <tr>
3280
3851
  <td>
3852
+ <xsl:attribute name="id">
3853
+ <xsl:value-of select="concat($id,'_',$row_number,'_1')"/>
3854
+ </xsl:attribute>
3281
3855
  <xsl:apply-templates/>
3282
3856
  </td>
3283
3857
  <td>
3858
+ <xsl:attribute name="id">
3859
+ <xsl:value-of select="concat($id,'_',$row_number,'_2')"/>
3860
+ </xsl:attribute>
3284
3861
 
3285
3862
  <xsl:apply-templates select="following-sibling::*[local-name()='dd'][1]">
3286
3863
  <xsl:with-param name="process">true</xsl:with-param>
@@ -3291,50 +3868,122 @@
3291
3868
 
3292
3869
  </xsl:template><xsl:template match="*[local-name()='dt']">
3293
3870
  <xsl:param name="key_iso"/>
3871
+ <xsl:param name="split_keep-within-line"/>
3294
3872
 
3295
3873
  <fo:table-row xsl:use-attribute-sets="dt-row-style">
3296
- <fo:table-cell>
3874
+ <xsl:call-template name="insert_dt_cell">
3875
+ <xsl:with-param name="key_iso" select="$key_iso"/>
3876
+ <xsl:with-param name="split_keep-within-line" select="$split_keep-within-line"/>
3877
+ </xsl:call-template>
3878
+ <xsl:for-each select="following-sibling::*[local-name()='dd'][1]">
3879
+ <xsl:call-template name="insert_dd_cell">
3880
+ <xsl:with-param name="split_keep-within-line" select="$split_keep-within-line"/>
3881
+ </xsl:call-template>
3882
+ </xsl:for-each>
3883
+ </fo:table-row>
3884
+ </xsl:template><xsl:template name="insert_dt_cell">
3885
+ <xsl:param name="key_iso"/>
3886
+ <xsl:param name="split_keep-within-line"/>
3887
+ <fo:table-cell xsl:use-attribute-sets="dt-cell-style">
3888
+
3889
+ <xsl:if test="$isGenerateTableIF = 'true'">
3890
+ <!-- border is mandatory, to calculate real width -->
3891
+ <xsl:attribute name="border">0.1pt solid black</xsl:attribute>
3892
+ <xsl:attribute name="text-align">left</xsl:attribute>
3893
+ </xsl:if>
3894
+
3895
+
3896
+ <fo:block xsl:use-attribute-sets="dt-block-style">
3897
+ <xsl:copy-of select="@id"/>
3898
+
3899
+ <xsl:if test="normalize-space($key_iso) = 'true'">
3900
+ <xsl:attribute name="margin-top">0</xsl:attribute>
3901
+ </xsl:if>
3902
+
3903
+
3904
+
3905
+ <xsl:apply-templates>
3906
+ <xsl:with-param name="split_keep-within-line" select="$split_keep-within-line"/>
3907
+ </xsl:apply-templates>
3908
+
3909
+ <xsl:if test="$isGenerateTableIF = 'true'"><fo:inline id="{@id}_end">end</fo:inline></xsl:if> <!-- to determine width of text --> <!-- <xsl:value-of select="$hair_space"/> -->
3910
+
3911
+ </fo:block>
3912
+ </fo:table-cell>
3913
+ </xsl:template><xsl:template name="insert_dd_cell">
3914
+ <xsl:param name="split_keep-within-line"/>
3915
+ <fo:table-cell xsl:use-attribute-sets="dd-cell-style">
3916
+
3917
+ <xsl:if test="$isGenerateTableIF = 'true'">
3918
+ <!-- border is mandatory, to calculate real width -->
3919
+ <xsl:attribute name="border">0.1pt solid black</xsl:attribute>
3920
+ </xsl:if>
3921
+
3922
+ <fo:block>
3923
+
3924
+ <xsl:if test="$isGenerateTableIF = 'true'">
3925
+ <xsl:attribute name="id"><xsl:value-of select="@id"/></xsl:attribute>
3926
+ </xsl:if>
3927
+
3297
3928
 
3298
- <fo:block xsl:use-attribute-sets="dt-style">
3299
- <xsl:copy-of select="@id"/>
3300
-
3301
- <xsl:if test="normalize-space($key_iso) = 'true'">
3302
- <xsl:attribute name="margin-top">0</xsl:attribute>
3303
- </xsl:if>
3304
-
3305
-
3306
-
3307
- <xsl:apply-templates/>
3308
- </fo:block>
3309
- </fo:table-cell>
3310
- <fo:table-cell>
3311
- <fo:block>
3312
-
3313
3929
 
3314
- <xsl:apply-templates select="following-sibling::*[local-name()='dd'][1]">
3315
- <xsl:with-param name="process">true</xsl:with-param>
3316
- </xsl:apply-templates>
3317
- </fo:block>
3318
- </fo:table-cell>
3319
- </fo:table-row>
3930
+ <xsl:choose>
3931
+ <xsl:when test="$isGenerateTableIF = 'true'">
3932
+ <xsl:apply-templates> <!-- following-sibling::*[local-name()='dd'][1] -->
3933
+ <xsl:with-param name="process">true</xsl:with-param>
3934
+ </xsl:apply-templates>
3935
+ </xsl:when>
3936
+ <xsl:otherwise>
3937
+ <xsl:apply-templates select="."> <!-- following-sibling::*[local-name()='dd'][1] -->
3938
+ <xsl:with-param name="process">true</xsl:with-param>
3939
+ <xsl:with-param name="split_keep-within-line" select="$split_keep-within-line"/>
3940
+ </xsl:apply-templates>
3941
+ </xsl:otherwise>
3942
+
3943
+ </xsl:choose>
3944
+
3945
+ <xsl:if test="$isGenerateTableIF = 'true'"><fo:inline id="{@id}_end">end</fo:inline></xsl:if> <!-- to determine width of text --> <!-- <xsl:value-of select="$hair_space"/> -->
3946
+
3947
+ </fo:block>
3948
+ </fo:table-cell>
3320
3949
  </xsl:template><xsl:template match="*[local-name()='dd']" mode="dl"/><xsl:template match="*[local-name()='dd']" mode="dl_process">
3321
3950
  <xsl:apply-templates/>
3322
3951
  </xsl:template><xsl:template match="*[local-name()='dd']">
3323
3952
  <xsl:param name="process">false</xsl:param>
3953
+ <xsl:param name="split_keep-within-line"/>
3324
3954
  <xsl:if test="$process = 'true'">
3325
3955
  <xsl:apply-templates select="@language"/>
3326
- <xsl:apply-templates/>
3956
+ <xsl:apply-templates>
3957
+ <xsl:with-param name="split_keep-within-line" select="$split_keep-within-line"/>
3958
+ </xsl:apply-templates>
3327
3959
  </xsl:if>
3328
3960
  </xsl:template><xsl:template match="*[local-name()='dd']/*[local-name()='p']" mode="inline">
3329
3961
  <fo:inline><xsl:text> </xsl:text><xsl:apply-templates/></fo:inline>
3330
- </xsl:template><xsl:template match="*[local-name()='em']">
3962
+ </xsl:template><xsl:template match="*[local-name()='dt']" mode="dl_if">
3963
+ <xsl:param name="id"/>
3964
+ <xsl:variable name="row_number" select="count(preceding-sibling::*[local-name()='dt']) + 1"/>
3965
+ <tr>
3966
+ <td>
3967
+ <xsl:copy-of select="node()"/>
3968
+ </td>
3969
+ <td>
3970
+
3971
+ <xsl:copy-of select="following-sibling::*[local-name()='dd'][1]/node()"/>
3972
+
3973
+ </td>
3974
+ </tr>
3975
+
3976
+ </xsl:template><xsl:template match="*[local-name()='dd']" mode="dl_if"/><xsl:template match="*[local-name()='em']">
3331
3977
  <fo:inline font-style="italic">
3332
3978
  <xsl:apply-templates/>
3333
3979
  </fo:inline>
3334
3980
  </xsl:template><xsl:template match="*[local-name()='strong'] | *[local-name()='b']">
3981
+ <xsl:param name="split_keep-within-line"/>
3335
3982
  <fo:inline font-weight="bold">
3336
3983
 
3337
- <xsl:apply-templates/>
3984
+ <xsl:apply-templates>
3985
+ <xsl:with-param name="split_keep-within-line" select="$split_keep-within-line"/>
3986
+ </xsl:apply-templates>
3338
3987
  </fo:inline>
3339
3988
  </xsl:template><xsl:template match="*[local-name()='padding']">
3340
3989
  <fo:inline padding-right="{@value}"> </fo:inline>
@@ -3535,6 +4184,10 @@
3535
4184
  <xsl:param name="text"/>
3536
4185
  <xsl:param name="separator" select="' '"/>
3537
4186
  <xsl:choose>
4187
+
4188
+ <xsl:when test="$isGenerateTableIF = 'true' and not(contains($text, $separator))">
4189
+ <word><xsl:value-of select="normalize-space($text)"/></word>
4190
+ </xsl:when>
3538
4191
  <xsl:when test="not(contains($text, $separator))">
3539
4192
  <word>
3540
4193
  <xsl:variable name="len_str_tmp" select="string-length(normalize-space($text))"/>
@@ -3579,13 +4232,66 @@
3579
4232
  </xsl:when>
3580
4233
  <xsl:otherwise>
3581
4234
  <word>
3582
- <xsl:value-of select="string-length(normalize-space(substring-before($text, $separator)))"/>
4235
+ <xsl:variable name="word" select="normalize-space(substring-before($text, $separator))"/>
4236
+ <xsl:choose>
4237
+ <xsl:when test="$isGenerateTableIF = 'true'">
4238
+ <xsl:value-of select="$word"/>
4239
+ </xsl:when>
4240
+ <xsl:otherwise>
4241
+ <xsl:value-of select="string-length($word)"/>
4242
+ </xsl:otherwise>
4243
+ </xsl:choose>
3583
4244
  </word>
3584
4245
  <xsl:call-template name="tokenize">
3585
4246
  <xsl:with-param name="text" select="substring-after($text, $separator)"/>
3586
4247
  </xsl:call-template>
3587
4248
  </xsl:otherwise>
3588
4249
  </xsl:choose>
4250
+ </xsl:template><xsl:template name="tokenize_with_tags">
4251
+ <xsl:param name="tags"/>
4252
+ <xsl:param name="text"/>
4253
+ <xsl:param name="separator" select="' '"/>
4254
+ <xsl:choose>
4255
+
4256
+ <xsl:when test="not(contains($text, $separator))">
4257
+ <word>
4258
+ <xsl:call-template name="enclose_text_in_tags">
4259
+ <xsl:with-param name="text" select="normalize-space($text)"/>
4260
+ <xsl:with-param name="tags" select="$tags"/>
4261
+ </xsl:call-template>
4262
+ </word>
4263
+ </xsl:when>
4264
+ <xsl:otherwise>
4265
+ <word>
4266
+ <xsl:call-template name="enclose_text_in_tags">
4267
+ <xsl:with-param name="text" select="normalize-space(substring-before($text, $separator))"/>
4268
+ <xsl:with-param name="tags" select="$tags"/>
4269
+ </xsl:call-template>
4270
+ </word>
4271
+ <xsl:call-template name="tokenize_with_tags">
4272
+ <xsl:with-param name="text" select="substring-after($text, $separator)"/>
4273
+ </xsl:call-template>
4274
+ </xsl:otherwise>
4275
+ </xsl:choose>
4276
+ </xsl:template><xsl:template name="enclose_text_in_tags">
4277
+ <xsl:param name="text"/>
4278
+ <xsl:param name="tags"/>
4279
+ <xsl:param name="num">1</xsl:param> <!-- default (start) value -->
4280
+
4281
+ <xsl:variable name="tag_name" select="normalize-space(xalan:nodeset($tags)//tag[$num])"/>
4282
+
4283
+ <xsl:choose>
4284
+ <xsl:when test="$tag_name = ''"><xsl:value-of select="$text"/></xsl:when>
4285
+ <xsl:otherwise>
4286
+ <xsl:element name="{$tag_name}">
4287
+ <xsl:call-template name="enclose_text_in_tags">
4288
+ <xsl:with-param name="text" select="$text"/>
4289
+ <xsl:with-param name="tags" select="$tags"/>
4290
+ <xsl:with-param name="num" select="$num + 1"/>
4291
+ </xsl:call-template>
4292
+ </xsl:element>
4293
+ </xsl:otherwise>
4294
+ </xsl:choose>
3589
4295
  </xsl:template><xsl:template name="max_length">
3590
4296
  <xsl:param name="words"/>
3591
4297
  <xsl:for-each select="$words//word">
@@ -3686,12 +4392,19 @@
3686
4392
  </xsl:otherwise>
3687
4393
  </xsl:choose>
3688
4394
  </xsl:template><xsl:template name="getSimpleTable">
4395
+ <xsl:param name="id"/>
4396
+
3689
4397
  <xsl:variable name="simple-table">
3690
4398
 
4399
+ <!-- Step 0. replace <br/> to <p>...</p> -->
4400
+ <xsl:variable name="table_without_br">
4401
+ <xsl:apply-templates mode="table-without-br"/>
4402
+ </xsl:variable>
4403
+
3691
4404
  <!-- Step 1. colspan processing -->
3692
4405
  <xsl:variable name="simple-table-colspan">
3693
4406
  <tbody>
3694
- <xsl:apply-templates mode="simple-table-colspan"/>
4407
+ <xsl:apply-templates select="xalan:nodeset($table_without_br)" mode="simple-table-colspan"/>
3695
4408
  </tbody>
3696
4409
  </xsl:variable>
3697
4410
 
@@ -3700,10 +4413,67 @@
3700
4413
  <xsl:apply-templates select="xalan:nodeset($simple-table-colspan)" mode="simple-table-rowspan"/>
3701
4414
  </xsl:variable>
3702
4415
 
3703
- <xsl:copy-of select="xalan:nodeset($simple-table-rowspan)"/>
3704
-
4416
+ <!-- Step 3: add id to each cell -->
4417
+ <!-- add <word>...</word> for each word, image, math -->
4418
+ <xsl:variable name="simple-table-id">
4419
+ <xsl:apply-templates select="xalan:nodeset($simple-table-rowspan)" mode="simple-table-id">
4420
+ <xsl:with-param name="id" select="$id"/>
4421
+ </xsl:apply-templates>
4422
+ </xsl:variable>
4423
+
4424
+ <xsl:copy-of select="xalan:nodeset($simple-table-id)"/>
4425
+
3705
4426
  </xsl:variable>
3706
4427
  <xsl:copy-of select="$simple-table"/>
4428
+ </xsl:template><xsl:template match="@*|node()" mode="table-without-br">
4429
+ <xsl:copy>
4430
+ <xsl:apply-templates select="@*|node()" mode="table-without-br"/>
4431
+ </xsl:copy>
4432
+ </xsl:template><xsl:template match="*[local-name()='th' or local-name() = 'td'][not(*[local-name()='br']) and not(*[local-name()='p'])]" mode="table-without-br">
4433
+ <xsl:copy>
4434
+ <xsl:copy-of select="@*"/>
4435
+ <p>
4436
+ <xsl:copy-of select="node()"/>
4437
+ </p>
4438
+ </xsl:copy>
4439
+ </xsl:template><xsl:template match="*[local-name()='th' or local-name()='td'][*[local-name()='br']]" mode="table-without-br">
4440
+ <xsl:copy>
4441
+ <xsl:copy-of select="@*"/>
4442
+ <xsl:for-each select="*[local-name()='br']">
4443
+ <xsl:variable name="current_id" select="generate-id()"/>
4444
+ <p>
4445
+ <xsl:for-each select="preceding-sibling::node()[following-sibling::*[local-name() = 'br'][1][generate-id() = $current_id]][not(local-name() = 'br')]">
4446
+ <xsl:copy-of select="."/>
4447
+ </xsl:for-each>
4448
+ </p>
4449
+ <xsl:if test="not(following-sibling::*[local-name() = 'br'])">
4450
+ <p>
4451
+ <xsl:for-each select="following-sibling::node()">
4452
+ <xsl:copy-of select="."/>
4453
+ </xsl:for-each>
4454
+ </p>
4455
+ </xsl:if>
4456
+ </xsl:for-each>
4457
+ </xsl:copy>
4458
+ </xsl:template><xsl:template match="*[local-name()='th' or local-name()='td']/*[local-name() = 'p'][*[local-name()='br']]" mode="table-without-br">
4459
+ <xsl:for-each select="*[local-name()='br']">
4460
+ <xsl:variable name="current_id" select="generate-id()"/>
4461
+ <p>
4462
+ <xsl:for-each select="preceding-sibling::node()[following-sibling::*[local-name() = 'br'][1][generate-id() = $current_id]][not(local-name() = 'br')]">
4463
+ <xsl:copy-of select="."/>
4464
+ </xsl:for-each>
4465
+ </p>
4466
+ <xsl:if test="not(following-sibling::*[local-name() = 'br'])">
4467
+ <p>
4468
+ <xsl:for-each select="following-sibling::node()">
4469
+ <xsl:copy-of select="."/>
4470
+ </xsl:for-each>
4471
+ </p>
4472
+ </xsl:if>
4473
+ </xsl:for-each>
4474
+ </xsl:template><xsl:template match="text()[not(ancestor::*[local-name() = 'sourcecode'])]" mode="table-without-br">
4475
+ <xsl:variable name="text" select="translate(.,'&#9;&#10;&#13;','')"/>
4476
+ <xsl:value-of select="java:replaceAll(java:java.lang.String.new($text),' {2,}',' ')"/>
3707
4477
  </xsl:template><xsl:template match="*[local-name()='thead'] | *[local-name()='tbody']" mode="simple-table-colspan">
3708
4478
  <xsl:apply-templates mode="simple-table-colspan"/>
3709
4479
  </xsl:template><xsl:template match="*[local-name()='fn']" mode="simple-table-colspan"/><xsl:template match="*[local-name()='th'] | *[local-name()='td']" mode="simple-table-colspan">
@@ -3793,6 +4563,126 @@
3793
4563
  <xsl:apply-templates select="following-sibling::tr[1]" mode="simple-table-rowspan">
3794
4564
  <xsl:with-param name="previousRow" select="$newRow"/>
3795
4565
  </xsl:apply-templates>
4566
+ </xsl:template><xsl:template match="/" mode="simple-table-id">
4567
+ <xsl:param name="id"/>
4568
+ <xsl:variable name="id_prefixed" select="concat('table_if_',$id)"/> <!-- table id prefixed by 'table_if_' to simple search in IF -->
4569
+ <xsl:apply-templates select="@*|node()" mode="simple-table-id">
4570
+ <xsl:with-param name="id" select="$id_prefixed"/>
4571
+ </xsl:apply-templates>
4572
+ </xsl:template><xsl:template match="@*|node()" mode="simple-table-id">
4573
+ <xsl:param name="id"/>
4574
+ <xsl:copy>
4575
+ <xsl:apply-templates select="@*|node()" mode="simple-table-id">
4576
+ <xsl:with-param name="id" select="$id"/>
4577
+ </xsl:apply-templates>
4578
+ </xsl:copy>
4579
+ </xsl:template><xsl:template match="*[local-name()='tbody']" mode="simple-table-id">
4580
+ <xsl:param name="id"/>
4581
+ <xsl:copy>
4582
+ <xsl:copy-of select="@*"/>
4583
+ <xsl:attribute name="id"><xsl:value-of select="$id"/></xsl:attribute>
4584
+ <xsl:apply-templates select="node()" mode="simple-table-id">
4585
+ <xsl:with-param name="id" select="$id"/>
4586
+ </xsl:apply-templates>
4587
+ </xsl:copy>
4588
+ </xsl:template><xsl:template match="*[local-name()='th' or local-name()='td']" mode="simple-table-id">
4589
+ <xsl:param name="id"/>
4590
+ <xsl:copy>
4591
+ <xsl:copy-of select="@*"/>
4592
+ <xsl:variable name="row_number" select="count(../preceding-sibling::*) + 1"/>
4593
+ <xsl:variable name="col_number" select="count(preceding-sibling::*) + 1"/>
4594
+ <xsl:attribute name="id">
4595
+ <xsl:value-of select="concat($id,'_',$row_number,'_',$col_number)"/>
4596
+ </xsl:attribute>
4597
+
4598
+ <xsl:for-each select="*[local-name() = 'p']">
4599
+ <xsl:copy>
4600
+ <xsl:copy-of select="@*"/>
4601
+ <xsl:variable name="p_num" select="count(preceding-sibling::*[local-name() = 'p']) + 1"/>
4602
+ <xsl:attribute name="id">
4603
+ <xsl:value-of select="concat($id,'_',$row_number,'_',$col_number,'_p_',$p_num)"/>
4604
+ </xsl:attribute>
4605
+
4606
+ <xsl:copy-of select="node()"/>
4607
+ </xsl:copy>
4608
+ </xsl:for-each>
4609
+
4610
+
4611
+ <xsl:if test="$isGenerateTableIF = 'true'"> <!-- split each paragraph to words, image, math -->
4612
+
4613
+ <xsl:variable name="td_text">
4614
+ <xsl:apply-templates select="." mode="td_text_with_formatting"/>
4615
+ </xsl:variable>
4616
+
4617
+ <!-- td_text='<xsl:copy-of select="$td_text"/>' -->
4618
+
4619
+ <xsl:variable name="words">
4620
+ <xsl:for-each select=".//*[local-name() = 'image' or local-name() = 'stem']">
4621
+ <word>
4622
+ <xsl:copy-of select="."/>
4623
+ </word>
4624
+ </xsl:for-each>
4625
+
4626
+ <xsl:for-each select="xalan:nodeset($td_text)//*[local-name() = 'word'][normalize-space() != '']">
4627
+ <xsl:copy-of select="."/>
4628
+ </xsl:for-each>
4629
+
4630
+ </xsl:variable>
4631
+
4632
+ <xsl:for-each select="xalan:nodeset($words)/word">
4633
+ <xsl:variable name="num" select="count(preceding-sibling::word) + 1"/>
4634
+ <xsl:copy>
4635
+ <xsl:attribute name="id">
4636
+ <xsl:value-of select="concat($id,'_',$row_number,'_',$col_number,'_word_',$num)"/>
4637
+ </xsl:attribute>
4638
+ <xsl:copy-of select="node()"/>
4639
+ </xsl:copy>
4640
+ </xsl:for-each>
4641
+ </xsl:if>
4642
+ </xsl:copy>
4643
+
4644
+ </xsl:template><xsl:template match="@*|node()" mode="td_text_with_formatting">
4645
+ <xsl:copy>
4646
+ <xsl:apply-templates select="@*|node()" mode="td_text_with_formatting"/>
4647
+ </xsl:copy>
4648
+ </xsl:template><xsl:template match="*[local-name() = 'stem' or local-name() = 'image']" mode="td_text_with_formatting"/><xsl:template match="*[local-name() = 'keep-together_within-line']/text()" mode="td_text_with_formatting">
4649
+ <xsl:variable name="formatting_tags">
4650
+ <xsl:call-template name="getFormattingTags"/>
4651
+ </xsl:variable>
4652
+ <word>
4653
+ <xsl:call-template name="enclose_text_in_tags">
4654
+ <xsl:with-param name="text" select="normalize-space(.)"/>
4655
+ <xsl:with-param name="tags" select="$formatting_tags"/>
4656
+ </xsl:call-template>
4657
+ </word>
4658
+ </xsl:template><xsl:template match="*[local-name() != 'keep-together_within-line']/text()" mode="td_text_with_formatting">
4659
+
4660
+ <xsl:variable name="td_text" select="."/>
4661
+
4662
+ <xsl:variable name="string_with_added_zerospaces">
4663
+ <xsl:call-template name="add-zero-spaces-java">
4664
+ <xsl:with-param name="text" select="$td_text"/>
4665
+ </xsl:call-template>
4666
+ </xsl:variable>
4667
+
4668
+ <xsl:variable name="formatting_tags">
4669
+ <xsl:call-template name="getFormattingTags"/>
4670
+ </xsl:variable>
4671
+
4672
+ <!-- <word>text</word> -->
4673
+ <xsl:call-template name="tokenize_with_tags">
4674
+ <xsl:with-param name="tags" select="$formatting_tags"/>
4675
+ <xsl:with-param name="text" select="normalize-space(translate($string_with_added_zerospaces, '​­', ' '))"/> <!-- replace zero-width-space and soft-hyphen to space -->
4676
+ </xsl:call-template>
4677
+ </xsl:template><xsl:template name="getFormattingTags">
4678
+ <tags>
4679
+ <xsl:if test="ancestor::*[local-name() = 'strong']"><tag>strong</tag></xsl:if>
4680
+ <xsl:if test="ancestor::*[local-name() = 'em']"><tag>em</tag></xsl:if>
4681
+ <xsl:if test="ancestor::*[local-name() = 'sub']"><tag>sub</tag></xsl:if>
4682
+ <xsl:if test="ancestor::*[local-name() = 'sup']"><tag>sup</tag></xsl:if>
4683
+ <xsl:if test="ancestor::*[local-name() = 'tt']"><tag>tt</tag></xsl:if>
4684
+ <xsl:if test="ancestor::*[local-name() = 'keep-together_within-line']"><tag>keep-together_within-line</tag></xsl:if>
4685
+ </tags>
3796
4686
  </xsl:template><xsl:template name="getLang">
3797
4687
  <xsl:variable name="language_current" select="normalize-space(//*[local-name()='bibdata']//*[local-name()='language'][@current = 'true'])"/>
3798
4688
  <xsl:variable name="language">
@@ -5480,7 +6370,9 @@
5480
6370
  <!-- <xsl:attribute name="border">0.5pt solid black</xsl:attribute> -->
5481
6371
  </xsl:if>
5482
6372
  <xsl:variable name="simple-table">
5483
- <xsl:call-template name="getSimpleTable"/>
6373
+ <xsl:call-template name="getSimpleTable">
6374
+ <xsl:with-param name="id" select="@id"/>
6375
+ </xsl:call-template>
5484
6376
  </xsl:variable>
5485
6377
  <xsl:variable name="cols-count" select="count(xalan:nodeset($simple-table)//tr[1]/td)"/>
5486
6378
  <xsl:if test="$cols-count = 2 and not(ancestor::*[local-name()='table'])">
@@ -6442,7 +7334,7 @@
6442
7334
  <!-- <fo:inline id="{@id}" font-size="1pt"/> -->
6443
7335
  <fo:inline id="{@id}" font-size="1pt"><xsl:value-of select="$hair_space"/></fo:inline>
6444
7336
  <!-- we need to add zero-width space, otherwise this fo:inline is missing in IF xml -->
6445
- <xsl:if test="not(following-sibling::node()[normalize-space() != ''])"> </xsl:if>
7337
+ <xsl:if test="not(following-sibling::node()[normalize-space() != ''])"><fo:inline font-size="1pt"> </fo:inline></xsl:if>
6446
7338
  </xsl:template><xsl:template match="*[local-name() = 'errata']">
6447
7339
  <!-- <row>
6448
7340
  <date>05-07-2013</date>
@@ -7789,4 +8681,40 @@
7789
8681
  <xsl:value-of select="$value"/>
7790
8682
  </xsl:otherwise>
7791
8683
  </xsl:choose>
8684
+ </xsl:template><xsl:template match="*" mode="print_as_xml">
8685
+ <xsl:param name="level">0</xsl:param>
8686
+
8687
+ <fo:block margin-left="{2*$level}mm">
8688
+ <xsl:text>
8689
+ &lt;</xsl:text>
8690
+ <xsl:value-of select="local-name()"/>
8691
+ <xsl:for-each select="@*">
8692
+ <xsl:text> </xsl:text>
8693
+ <xsl:value-of select="local-name()"/>
8694
+ <xsl:text>="</xsl:text>
8695
+ <xsl:value-of select="."/>
8696
+ <xsl:text>"</xsl:text>
8697
+ </xsl:for-each>
8698
+ <xsl:text>&gt;</xsl:text>
8699
+
8700
+ <xsl:if test="not(*)">
8701
+ <fo:inline font-weight="bold"><xsl:value-of select="."/></fo:inline>
8702
+ <xsl:text>&lt;/</xsl:text>
8703
+ <xsl:value-of select="local-name()"/>
8704
+ <xsl:text>&gt;</xsl:text>
8705
+ </xsl:if>
8706
+ </fo:block>
8707
+
8708
+ <xsl:if test="*">
8709
+ <fo:block>
8710
+ <xsl:apply-templates mode="print_as_xml">
8711
+ <xsl:with-param name="level" select="$level + 1"/>
8712
+ </xsl:apply-templates>
8713
+ </fo:block>
8714
+ <fo:block margin-left="{2*$level}mm">
8715
+ <xsl:text>&lt;/</xsl:text>
8716
+ <xsl:value-of select="local-name()"/>
8717
+ <xsl:text>&gt;</xsl:text>
8718
+ </fo:block>
8719
+ </xsl:if>
7792
8720
  </xsl:template></xsl:stylesheet>