metanorma-mpfa 0.9.0 → 0.9.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -422,6 +422,7 @@
422
422
 
423
423
  <xsl:template match="mpfd:p" name="paragraph">
424
424
  <xsl:param name="inline" select="'false'"/>
425
+ <xsl:param name="split_keep-within-line"/>
425
426
  <xsl:variable name="previous-element" select="local-name(preceding-sibling::*[1])"/>
426
427
  <xsl:variable name="element-name">
427
428
  <xsl:choose>
@@ -446,7 +447,9 @@
446
447
  <xsl:attribute name="margin-bottom">0pt</xsl:attribute>
447
448
  </xsl:if>
448
449
  <xsl:attribute name="line-height">115%</xsl:attribute>
449
- <xsl:apply-templates/>
450
+ <xsl:apply-templates>
451
+ <xsl:with-param name="split_keep-within-line" select="$split_keep-within-line"/>
452
+ </xsl:apply-templates>
450
453
  </xsl:element>
451
454
  <xsl:if test="$element-name = 'fo:inline' and not($inline = 'true') and not(local-name(..) = 'admonition')">
452
455
  <xsl:choose>
@@ -583,7 +586,9 @@
583
586
  </xsl:template>
584
587
 
585
588
 
586
- <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">
589
+ <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_">
590
+ false
591
+ </xsl:variable><xsl:variable name="isGenerateTableIF" select="normalize-space($isGenerateTableIF_)"/><xsl:variable name="lang">
587
592
  <xsl:call-template name="getLang"/>
588
593
  </xsl:variable><xsl:variable name="pageWidth_">
589
594
  210
@@ -1033,6 +1038,7 @@
1033
1038
  <xsl:attribute name="font-weight">bold</xsl:attribute>
1034
1039
  <xsl:attribute name="border">solid black 1pt</xsl:attribute>
1035
1040
  <xsl:attribute name="padding-left">1mm</xsl:attribute>
1041
+ <xsl:attribute name="padding-right">1mm</xsl:attribute>
1036
1042
  <xsl:attribute name="display-align">center</xsl:attribute>
1037
1043
 
1038
1044
 
@@ -1054,6 +1060,7 @@
1054
1060
  <xsl:attribute name="display-align">center</xsl:attribute>
1055
1061
  <xsl:attribute name="border">solid black 1pt</xsl:attribute>
1056
1062
  <xsl:attribute name="padding-left">1mm</xsl:attribute>
1063
+ <xsl:attribute name="padding-right">1mm</xsl:attribute>
1057
1064
 
1058
1065
 
1059
1066
 
@@ -1136,7 +1143,8 @@
1136
1143
  </xsl:attribute-set><xsl:attribute-set name="dt-row-style">
1137
1144
 
1138
1145
 
1139
- </xsl:attribute-set><xsl:attribute-set name="dt-style">
1146
+ </xsl:attribute-set><xsl:attribute-set name="dt-cell-style">
1147
+ </xsl:attribute-set><xsl:attribute-set name="dt-block-style">
1140
1148
  <xsl:attribute name="margin-top">6pt</xsl:attribute>
1141
1149
 
1142
1150
 
@@ -1148,6 +1156,8 @@
1148
1156
 
1149
1157
 
1150
1158
 
1159
+ </xsl:attribute-set><xsl:attribute-set name="dd-cell-style">
1160
+ <xsl:attribute name="padding-left">2mm</xsl:attribute>
1151
1161
  </xsl:attribute-set><xsl:attribute-set name="appendix-style">
1152
1162
 
1153
1163
 
@@ -1955,7 +1965,38 @@
1955
1965
  </xsl:template><xsl:template match="*[local-name()='br']">
1956
1966
  <xsl:value-of select="$linebreak"/>
1957
1967
  </xsl:template><xsl:template match="*[local-name() = 'keep-together_within-line']">
1958
- <fo:inline keep-together.within-line="always"><xsl:apply-templates/></fo:inline>
1968
+ <xsl:param name="split_keep-within-line"/>
1969
+
1970
+ <!-- <fo:inline>split_keep-within-line='<xsl:value-of select="$split_keep-within-line"/>'</fo:inline> -->
1971
+ <xsl:choose>
1972
+
1973
+ <xsl:when test="normalize-space($split_keep-within-line) = 'true'">
1974
+ <xsl:variable name="sep">_</xsl:variable>
1975
+ <xsl:variable name="items">
1976
+ <xsl:call-template name="split">
1977
+ <xsl:with-param name="pText" select="."/>
1978
+ <xsl:with-param name="sep" select="$sep"/>
1979
+ <xsl:with-param name="normalize-space">false</xsl:with-param>
1980
+ <xsl:with-param name="keep_sep">true</xsl:with-param>
1981
+ </xsl:call-template>
1982
+ </xsl:variable>
1983
+ <xsl:for-each select="xalan:nodeset($items)/item">
1984
+ <xsl:choose>
1985
+ <xsl:when test=". = $sep">
1986
+ <xsl:value-of select="$sep"/><xsl:value-of select="$zero_width_space"/>
1987
+ </xsl:when>
1988
+ <xsl:otherwise>
1989
+ <fo:inline keep-together.within-line="always"><xsl:apply-templates/></fo:inline>
1990
+ </xsl:otherwise>
1991
+ </xsl:choose>
1992
+ </xsl:for-each>
1993
+ </xsl:when>
1994
+
1995
+ <xsl:otherwise>
1996
+ <fo:inline keep-together.within-line="always"><xsl:apply-templates/></fo:inline>
1997
+ </xsl:otherwise>
1998
+
1999
+ </xsl:choose>
1959
2000
  </xsl:template><xsl:template match="*[local-name()='copyright-statement']">
1960
2001
  <fo:block xsl:use-attribute-sets="copyright-statement-style">
1961
2002
  <xsl:apply-templates/>
@@ -2047,9 +2088,14 @@
2047
2088
 
2048
2089
  <xsl:variable name="table">
2049
2090
 
2050
- <xsl:variable name="simple-table">
2051
- <xsl:call-template name="getSimpleTable"/>
2091
+ <xsl:variable name="simple-table">
2092
+ <xsl:call-template name="getSimpleTable">
2093
+ <xsl:with-param name="id" select="@id"/>
2094
+ </xsl:call-template>
2052
2095
  </xsl:variable>
2096
+ <!-- <xsl:variable name="simple-table" select="xalan:nodeset($simple-table_)"/> -->
2097
+
2098
+ <!-- simple-table=<xsl:copy-of select="$simple-table"/> -->
2053
2099
 
2054
2100
 
2055
2101
  <!-- Display table's name before table as standalone block -->
@@ -2072,7 +2118,23 @@
2072
2118
  </xsl:call-template>
2073
2119
  </xsl:if>
2074
2120
  </xsl:variable>
2075
- <!-- DEBUG colwidths=<xsl:copy-of select="$colwidths"/> -->
2121
+ <!-- <xsl:variable name="colwidths" select="xalan:nodeset($colwidths_)"/> -->
2122
+
2123
+ <!-- DEBUG -->
2124
+ <xsl:if test="$table_if_debug = 'true'">
2125
+ <fo:block font-size="60%">
2126
+ <xsl:apply-templates select="xalan:nodeset($colwidths)" mode="print_as_xml"/>
2127
+ </fo:block>
2128
+ </xsl:if>
2129
+
2130
+
2131
+ <!-- <xsl:copy-of select="$colwidths"/> -->
2132
+
2133
+ <!-- <xsl:text disable-output-escaping="yes">&lt;!- -</xsl:text>
2134
+ DEBUG
2135
+ colwidths=<xsl:copy-of select="$colwidths"/>
2136
+ <xsl:text disable-output-escaping="yes">- -&gt;</xsl:text> -->
2137
+
2076
2138
 
2077
2139
 
2078
2140
  <xsl:variable name="margin-side">
@@ -2133,9 +2195,17 @@
2133
2195
  </xsl:element>
2134
2196
  </xsl:variable>
2135
2197
 
2198
+ <xsl:if test="$isGenerateTableIF = 'true'">
2199
+ <!-- to determine start of table -->
2200
+ <fo:block id="{concat('table_if_start_',@id)}" keep-with-next="always" font-size="1pt">Start table '<xsl:value-of select="@id"/>'.</fo:block>
2201
+ </xsl:if>
2136
2202
 
2137
2203
  <fo:table id="{@id}">
2138
2204
 
2205
+ <xsl:if test="$isGenerateTableIF = 'true'">
2206
+ <xsl:attribute name="wrap-option">no-wrap</xsl:attribute>
2207
+ </xsl:if>
2208
+
2139
2209
  <xsl:for-each select="xalan:nodeset($table_attributes)/table_attributes/@*">
2140
2210
  <xsl:attribute name="{local-name()}">
2141
2211
  <xsl:value-of select="."/>
@@ -2149,24 +2219,47 @@
2149
2219
 
2150
2220
 
2151
2221
  <xsl:choose>
2152
- <xsl:when test="*[local-name()='colgroup']/*[local-name()='col']">
2153
- <xsl:for-each select="*[local-name()='colgroup']/*[local-name()='col']">
2154
- <fo:table-column column-width="{@width}"/>
2155
- </xsl:for-each>
2222
+ <xsl:when test="$isGenerateTableIF = 'true'">
2223
+ <!-- generate IF for table widths -->
2224
+ <!-- example:
2225
+ <tr>
2226
+ <td valign="top" align="left" id="tab-symdu_1_1">
2227
+ <p>Symbol</p>
2228
+ <word id="tab-symdu_1_1_word_1">Symbol</word>
2229
+ </td>
2230
+ <td valign="top" align="left" id="tab-symdu_1_2">
2231
+ <p>Description</p>
2232
+ <word id="tab-symdu_1_2_word_1">Description</word>
2233
+ </td>
2234
+ </tr>
2235
+ -->
2236
+ <xsl:apply-templates select="xalan:nodeset($simple-table)" mode="process_table-if"/>
2237
+
2156
2238
  </xsl:when>
2157
2239
  <xsl:otherwise>
2158
- <xsl:call-template name="insertTableColumnWidth">
2159
- <xsl:with-param name="colwidths" select="$colwidths"/>
2160
- </xsl:call-template>
2161
- </xsl:otherwise>
2162
- </xsl:choose>
2163
2240
 
2164
- <xsl:choose>
2165
- <xsl:when test="not(*[local-name()='tbody']) and *[local-name()='thead']">
2166
- <xsl:apply-templates select="*[local-name()='thead']" mode="process_tbody"/>
2167
- </xsl:when>
2168
- <xsl:otherwise>
2169
- <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 -->
2241
+ <xsl:choose>
2242
+ <xsl:when test="*[local-name()='colgroup']/*[local-name()='col']">
2243
+ <xsl:for-each select="*[local-name()='colgroup']/*[local-name()='col']">
2244
+ <fo:table-column column-width="{@width}"/>
2245
+ </xsl:for-each>
2246
+ </xsl:when>
2247
+ <xsl:otherwise>
2248
+ <xsl:call-template name="insertTableColumnWidth">
2249
+ <xsl:with-param name="colwidths" select="$colwidths"/>
2250
+ </xsl:call-template>
2251
+ </xsl:otherwise>
2252
+ </xsl:choose>
2253
+
2254
+ <xsl:choose>
2255
+ <xsl:when test="not(*[local-name()='tbody']) and *[local-name()='thead']">
2256
+ <xsl:apply-templates select="*[local-name()='thead']" mode="process_tbody"/>
2257
+ </xsl:when>
2258
+ <xsl:otherwise>
2259
+ <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 -->
2260
+ </xsl:otherwise>
2261
+ </xsl:choose>
2262
+
2170
2263
  </xsl:otherwise>
2171
2264
  </xsl:choose>
2172
2265
 
@@ -2269,11 +2362,22 @@
2269
2362
  <xsl:variable name="columns-with-colspan" select="count($table-row/*[@colspan])"/>
2270
2363
  <xsl:value-of select="$columns-count + $sum-colspans - $columns-with-colspan"/>
2271
2364
  </xsl:template><xsl:template name="calculate-column-widths">
2365
+ <xsl:param name="table"/>
2366
+ <xsl:param name="cols-count"/>
2367
+
2368
+ <xsl:call-template name="calculate-column-widths-proportional">
2369
+ <xsl:with-param name="cols-count" select="$cols-count"/>
2370
+ <xsl:with-param name="table" select="$table"/>
2371
+ </xsl:call-template>
2372
+
2373
+ </xsl:template><xsl:template name="calculate-column-widths-proportional">
2272
2374
  <xsl:param name="table"/>
2273
2375
  <xsl:param name="cols-count"/>
2274
2376
  <xsl:param name="curr-col" select="1"/>
2275
2377
  <xsl:param name="width" select="0"/>
2276
2378
 
2379
+ <!-- table=<xsl:copy-of select="$table"/> -->
2380
+
2277
2381
  <xsl:if test="$curr-col &lt;= $cols-count">
2278
2382
  <xsl:variable name="widths">
2279
2383
  <xsl:choose>
@@ -2311,10 +2415,15 @@
2311
2415
  </xsl:for-each>
2312
2416
  </xsl:when>
2313
2417
  <xsl:otherwise>
2314
- <xsl:for-each select="xalan:nodeset($table)/*/tr">
2418
+ <!-- <curr_col><xsl:value-of select="$curr-col"/></curr_col> -->
2419
+
2420
+ <!-- <table><xsl:copy-of select="$table"/></table>
2421
+ -->
2422
+ <xsl:for-each select="xalan:nodeset($table)/*/*[local-name()='tr']">
2315
2423
  <xsl:variable name="td_text">
2316
2424
  <xsl:apply-templates select="td[$curr-col]" mode="td_text"/>
2317
2425
  </xsl:variable>
2426
+ <!-- <td_text><xsl:value-of select="$td_text"/></td_text> -->
2318
2427
  <xsl:variable name="words">
2319
2428
  <xsl:variable name="string_with_added_zerospaces">
2320
2429
  <xsl:call-template name="add-zero-spaces-java">
@@ -2329,6 +2438,7 @@
2329
2438
  <xsl:with-param name="text" select="normalize-space(translate($string_with_added_zerospaces, '​­', ' '))"/> <!-- replace zero-width-space and soft-hyphen to space -->
2330
2439
  </xsl:call-template>
2331
2440
  </xsl:variable>
2441
+ <!-- words=<xsl:copy-of select="$words"/> -->
2332
2442
  <xsl:variable name="max_length">
2333
2443
  <xsl:call-template name="max_length">
2334
2444
  <xsl:with-param name="words" select="xalan:nodeset($words)"/>
@@ -2353,6 +2463,8 @@
2353
2463
  </xsl:choose>
2354
2464
  </xsl:variable>
2355
2465
 
2466
+ <!-- widths=<xsl:copy-of select="$widths"/> -->
2467
+
2356
2468
  <column>
2357
2469
  <xsl:for-each select="xalan:nodeset($widths)//width">
2358
2470
  <xsl:sort select="." data-type="number" order="descending"/>
@@ -2361,33 +2473,327 @@
2361
2473
  </xsl:if>
2362
2474
  </xsl:for-each>
2363
2475
  </column>
2364
- <xsl:call-template name="calculate-column-widths">
2476
+ <xsl:call-template name="calculate-column-widths-proportional">
2365
2477
  <xsl:with-param name="cols-count" select="$cols-count"/>
2366
2478
  <xsl:with-param name="curr-col" select="$curr-col +1"/>
2367
2479
  <xsl:with-param name="table" select="$table"/>
2368
2480
  </xsl:call-template>
2369
2481
  </xsl:if>
2370
- </xsl:template><xsl:template match="*[@keep-together.within-line]/text()" priority="2" mode="td_text">
2482
+ </xsl:template><xsl:template match="*[@keep-together.within-line or local-name() = 'keep-together_within-line']/text()" priority="2" mode="td_text">
2371
2483
  <!-- <xsl:message>DEBUG t1=<xsl:value-of select="."/></xsl:message>
2372
2484
  <xsl:message>DEBUG t2=<xsl:value-of select="java:replaceAll(java:java.lang.String.new(.),'.','X')"/></xsl:message> -->
2373
2485
  <xsl:value-of select="java:replaceAll(java:java.lang.String.new(.),'.','X')"/>
2486
+
2487
+ <!-- if all capitals english letters or digits -->
2488
+ <xsl:if test="normalize-space(translate(., concat($upper,'0123456789'), '')) = ''">
2489
+ <xsl:call-template name="repeat">
2490
+ <xsl:with-param name="char" select="'X'"/>
2491
+ <xsl:with-param name="count" select="string-length(normalize-space(.)) * 0.5"/>
2492
+ </xsl:call-template>
2493
+ </xsl:if>
2374
2494
  </xsl:template><xsl:template match="text()" mode="td_text">
2375
2495
  <xsl:value-of select="translate(., $zero_width_space, ' ')"/><xsl:text> </xsl:text>
2376
2496
  </xsl:template><xsl:template match="*[local-name()='termsource']" mode="td_text">
2377
2497
  <xsl:value-of select="*[local-name()='origin']/@citeas"/>
2378
2498
  </xsl:template><xsl:template match="*[local-name()='link']" mode="td_text">
2379
2499
  <xsl:value-of select="@target"/>
2380
- </xsl:template><xsl:template match="*[local-name()='math']" mode="td_text">
2381
- <xsl:variable name="mathml">
2382
- <xsl:for-each select="*">
2383
- <xsl:if test="local-name() != 'unit' and local-name() != 'prefix' and local-name() != 'dimension' and local-name() != 'quantity'">
2384
- <xsl:copy-of select="."/>
2500
+ </xsl:template><xsl:template match="*[local-name()='math']" mode="td_text" name="math_length">
2501
+ <xsl:if test="$isGenerateTableIF = 'false'">
2502
+ <xsl:variable name="mathml_">
2503
+ <xsl:for-each select="*">
2504
+ <xsl:if test="local-name() != 'unit' and local-name() != 'prefix' and local-name() != 'dimension' and local-name() != 'quantity'">
2505
+ <xsl:copy-of select="."/>
2506
+ </xsl:if>
2507
+ </xsl:for-each>
2508
+ </xsl:variable>
2509
+ <xsl:variable name="mathml" select="xalan:nodeset($mathml_)"/>
2510
+
2511
+ <xsl:variable name="math_text">
2512
+ <xsl:value-of select="normalize-space($mathml)"/>
2513
+ <xsl:for-each select="$mathml//@open"><xsl:value-of select="."/></xsl:for-each>
2514
+ <xsl:for-each select="$mathml//@close"><xsl:value-of select="."/></xsl:for-each>
2515
+ </xsl:variable>
2516
+ <xsl:value-of select="translate($math_text, ' ', '#')"/><!-- mathml images as one 'word' without spaces -->
2517
+ </xsl:if>
2518
+ </xsl:template><xsl:template name="calculate-column-widths-autolayout-algorithm">
2519
+ <xsl:param name="table"/>
2520
+ <xsl:param name="if">false</xsl:param> <!-- via intermediate format -->
2521
+
2522
+ <!-- The algorithm uses two passes through the table data and scales linearly with the size of the table -->
2523
+
2524
+ <!-- In the first pass, line wrapping is disabled, and the user agent keeps track of the minimum and maximum width of each cell. -->
2525
+
2526
+ <!-- Since line wrap has been disabled, paragraphs are treated as long lines unless broken by BR elements. -->
2527
+
2528
+ <!-- get current table id -->
2529
+ <xsl:variable name="table_id" select="@id"/>
2530
+ <!-- find table by id in the file 'table_widths' -->
2531
+ <xsl:variable name="table-if_" select="$table_widths_from_if//table[@id = $table_id]"/>
2532
+ <xsl:variable name="table-if" select="xalan:nodeset($table-if_)"/>
2533
+
2534
+
2535
+ <!-- table='<xsl:copy-of select="$table"/>' -->
2536
+ <!-- table_id='<xsl:value-of select="$table_id"/>\ -->
2537
+ <!-- table-if='<xsl:copy-of select="$table-if"/>' -->
2538
+ <!-- table_widths_from_if='<xsl:copy-of select="$table_widths_from_if"/>' -->
2539
+
2540
+ <xsl:variable name="table_with_cell_widths_">
2541
+ <xsl:choose>
2542
+ <xsl:when test="$if = 'true' and normalize-space($table-if) != ''"> <!-- if we read column's width from IF and there is table in IF -->
2543
+
2544
+ <!-- Example: <column>10</column>
2545
+ <column>11</column>
2546
+ -->
2547
+ <xsl:apply-templates select="$table-if" mode="determine_cell_widths-if"/>
2548
+ </xsl:when>
2549
+ <xsl:otherwise>
2550
+ <xsl:apply-templates select="xalan:nodeset($table)" mode="determine_cell_widths"/>
2551
+ </xsl:otherwise>
2552
+ </xsl:choose>
2553
+ </xsl:variable>
2554
+ <xsl:variable name="table_with_cell_widths" select="xalan:nodeset($table_with_cell_widths_)"/>
2555
+
2556
+ <xsl:if test="$table_if_debug = 'true'">
2557
+ <xsl:copy-of select="$table_with_cell_widths"/>
2558
+ </xsl:if>
2559
+
2560
+
2561
+ <!-- The minimum and maximum cell widths are then used to determine the corresponding minimum and maximum widths for the columns. -->
2562
+
2563
+ <xsl:variable name="column_widths_">
2564
+ <!-- iteration of columns -->
2565
+ <xsl:for-each select="$table_with_cell_widths//tr[1]/td">
2566
+ <xsl:variable name="pos" select="position()"/>
2567
+ <column>
2568
+ <xsl:attribute name="width_max">
2569
+ <xsl:for-each select="ancestor::tbody//tr/td[$pos]/@width_max">
2570
+ <xsl:sort select="." data-type="number" order="descending"/>
2571
+ <xsl:if test="position() = 1"><xsl:value-of select="."/></xsl:if>
2572
+ </xsl:for-each>
2573
+ </xsl:attribute>
2574
+ <xsl:attribute name="width_min">
2575
+ <xsl:for-each select="ancestor::tbody//tr/td[$pos]/@width_min">
2576
+ <xsl:sort select="." data-type="number" order="descending"/>
2577
+ <xsl:if test="position() = 1"><xsl:value-of select="."/></xsl:if>
2578
+ </xsl:for-each>
2579
+ </xsl:attribute>
2580
+ </column>
2581
+ </xsl:for-each>
2582
+ </xsl:variable>
2583
+ <xsl:variable name="column_widths" select="xalan:nodeset($column_widths_)"/>
2584
+
2585
+ <!-- <column_widths>
2586
+ <xsl:copy-of select="$column_widths"/>
2587
+ </column_widths> -->
2588
+
2589
+ <!-- These in turn, are used to find the minimum and maximum width for the table. -->
2590
+ <xsl:variable name="table_widths_">
2591
+ <table>
2592
+ <xsl:attribute name="width_max">
2593
+ <xsl:value-of select="sum($column_widths/column/@width_max)"/>
2594
+ </xsl:attribute>
2595
+ <xsl:attribute name="width_min">
2596
+ <xsl:value-of select="sum($column_widths/column/@width_min)"/>
2597
+ </xsl:attribute>
2598
+ </table>
2599
+ </xsl:variable>
2600
+ <xsl:variable name="table_widths" select="xalan:nodeset($table_widths_)"/>
2601
+
2602
+ <xsl:variable name="page_width">
2603
+ <xsl:choose>
2604
+ <xsl:when test="$if = 'true'"><xsl:value-of select="$table-if/@page-width"/></xsl:when>
2605
+ <xsl:otherwise>75</xsl:otherwise>
2606
+ </xsl:choose>
2607
+ </xsl:variable>
2608
+
2609
+ <xsl:if test="$table_if_debug = 'true'">
2610
+ <table_width>
2611
+ <xsl:copy-of select="$table_widths"/>
2612
+ </table_width>
2613
+ <!-- <debug>$table_widths/@width_min=<xsl:value-of select="$table_widths/table/@width_min"/></debug>
2614
+ <debug>$table_widths/@width_max=<xsl:value-of select="$table_widths/table/@width_max"/></debug>
2615
+ -->
2616
+ <debug>$page_width=<xsl:value-of select="$page_width"/></debug>
2617
+ </xsl:if>
2618
+
2619
+
2620
+ <!-- There are three cases: -->
2621
+ <xsl:choose>
2622
+ <!-- 1. The minimum table width is equal to or wider than the available space -->
2623
+ <xsl:when test="$table_widths/table/@width_min &gt;= $page_width and 1 = 2"> <!-- this condition isn't working see case 3 below -->
2624
+ <!-- call old algorithm -->
2625
+ <case1/>
2626
+ <xsl:variable name="cols-count" select="count(xalan:nodeset($table)/*/tr[1]/td)"/>
2627
+ <xsl:call-template name="calculate-column-widths-proportional">
2628
+ <xsl:with-param name="cols-count" select="$cols-count"/>
2629
+ <xsl:with-param name="table" select="$table"/>
2630
+ </xsl:call-template>
2631
+ </xsl:when>
2632
+ <!-- 2. The maximum table width fits within the available space. In this case, set the columns to their maximum widths. -->
2633
+ <xsl:when test="$table_widths/table/@width_max &lt;= $page_width">
2634
+ <case2/>
2635
+ <autolayout/>
2636
+ <xsl:for-each select="$column_widths/column/@width_max">
2637
+ <column divider="100"><xsl:value-of select="."/></column>
2638
+ </xsl:for-each>
2639
+ </xsl:when>
2640
+ <!-- 3. The maximum width of the table is greater than the available space, but the minimum table width is smaller.
2641
+ In this case, find the difference between the available space and the minimum table width, lets call it W.
2642
+ Lets also call D the difference between maximum and minimum width of the table.
2643
+ For each column, let d be the difference between maximum and minimum width of that column.
2644
+ Now set the column's width to the minimum width plus d times W over D.
2645
+ This makes columns with large differences between minimum and maximum widths wider than columns with smaller differences. -->
2646
+ <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)">
2647
+ <!-- difference between the available space and the minimum table width -->
2648
+ <xsl:variable name="W" select="$page_width - $table_widths/table/@width_min"/>
2649
+ <W><xsl:value-of select="$W"/></W>
2650
+ <!-- difference between maximum and minimum width of the table -->
2651
+ <xsl:variable name="D" select="$table_widths/table/@width_max - $table_widths/table/@width_min"/>
2652
+ <D><xsl:value-of select="$D"/></D>
2653
+ <case3/>
2654
+ <autolayout/>
2655
+ <xsl:if test="$table_widths/table/@width_min &gt;= $page_width">
2656
+ <split_keep-within-line>true</split_keep-within-line>
2385
2657
  </xsl:if>
2658
+ <xsl:for-each select="$column_widths/column">
2659
+ <!-- difference between maximum and minimum width of that column. -->
2660
+ <xsl:variable name="d" select="@width_max - @width_min"/>
2661
+ <d><xsl:value-of select="$d"/></d>
2662
+ <width_min><xsl:value-of select="@width_min"/></width_min>
2663
+ <e><xsl:value-of select="$d * $W div $D"/></e>
2664
+ <!-- set the column's width to the minimum width plus d times W over D. -->
2665
+ <column divider="100">
2666
+ <xsl:value-of select="round(@width_min + $d * $W div $D)"/> <!-- * 10 -->
2667
+ </column>
2668
+ </xsl:for-each>
2669
+
2670
+ </xsl:when>
2671
+ <xsl:otherwise><unknown_case/></xsl:otherwise>
2672
+ </xsl:choose>
2673
+
2674
+
2675
+ </xsl:template><xsl:template match="@*|node()" mode="determine_cell_widths">
2676
+ <xsl:copy>
2677
+ <xsl:apply-templates select="@*|node()" mode="determine_cell_widths"/>
2678
+ </xsl:copy>
2679
+ </xsl:template><xsl:template match="td | th" mode="determine_cell_widths">
2680
+ <xsl:copy>
2681
+ <xsl:copy-of select="@*"/>
2682
+
2683
+ <!-- The maximum width is given by the widest line. -->
2684
+ <xsl:variable name="widths_max">
2685
+ <xsl:for-each select=".//*[local-name() = 'p']">
2686
+ <xsl:call-template name="add_width"/>
2687
+ </xsl:for-each>
2688
+ <xsl:if test="not(*[local-name() = 'p'])">
2689
+ <xsl:call-template name="add_width"/>
2690
+ </xsl:if>
2691
+ </xsl:variable>
2692
+ <xsl:variable name="width_max">
2693
+ <xsl:for-each select="xalan:nodeset($widths_max)//width">
2694
+ <xsl:sort select="." data-type="number" order="descending"/>
2695
+ <xsl:if test="position() = 1"><xsl:value-of select="."/></xsl:if>
2696
+ </xsl:for-each>
2697
+ </xsl:variable>
2698
+ <xsl:attribute name="width_max">
2699
+ <xsl:value-of select="$width_max"/>
2700
+ </xsl:attribute>
2701
+
2702
+ <!-- The minimum width is given by the widest text element (word, image, etc.) -->
2703
+ <!-- To do: image width -->
2704
+ <xsl:variable name="td_text">
2705
+ <xsl:apply-templates select="." mode="td_text"/>
2706
+ </xsl:variable>
2707
+ <xsl:variable name="words">
2708
+ <xsl:variable name="string_with_added_zerospaces">
2709
+ <xsl:call-template name="add-zero-spaces-java">
2710
+ <xsl:with-param name="text" select="$td_text"/>
2711
+ </xsl:call-template>
2712
+ </xsl:variable>
2713
+ <xsl:call-template name="tokenize">
2714
+ <xsl:with-param name="text" select="normalize-space(translate($string_with_added_zerospaces, '​­', ' '))"/> <!-- replace zero-width-space and soft-hyphen to space -->
2715
+ </xsl:call-template>
2716
+ </xsl:variable>
2717
+
2718
+ <xsl:variable name="max_word_length">
2719
+ <xsl:call-template name="max_length">
2720
+ <xsl:with-param name="words" select="xalan:nodeset($words)"/>
2721
+ </xsl:call-template>
2722
+ </xsl:variable>
2723
+ <xsl:variable name="width_min">
2724
+ <xsl:value-of select="$max_word_length"/>
2725
+ </xsl:variable>
2726
+ <xsl:attribute name="width_min">
2727
+ <xsl:value-of select="$width_min"/>
2728
+ </xsl:attribute>
2729
+ <!-- width_max="1" width_min="1.5"> --> <!-- see 'tokenize' template, multiply 1.5 for all latin capitals -->
2730
+ <xsl:if test="$width_min &gt; $width_max">
2731
+ <xsl:attribute name="width_max">
2732
+ <xsl:value-of select="$width_min"/>
2733
+ </xsl:attribute>
2734
+ </xsl:if>
2735
+ <xsl:if test="$width_min = 0">
2736
+ <xsl:attribute name="width_min">1</xsl:attribute>
2737
+ </xsl:if>
2738
+
2739
+ <xsl:apply-templates select="node()" mode="determine_cell_widths"/>
2740
+
2741
+ </xsl:copy>
2742
+ </xsl:template><xsl:template name="add_width">
2743
+ <xsl:variable name="p_text"><xsl:apply-templates select="." mode="td_text"/></xsl:variable>
2744
+ <xsl:variable name="p_text_len_" select="string-length(normalize-space($p_text))"/>
2745
+
2746
+ <xsl:variable name="p_text_len">
2747
+ <xsl:choose>
2748
+ <xsl:when test="normalize-space(translate($p_text, concat($upper,'0123456789'), '')) = ''"> <!-- english word in CAPITAL letters -->
2749
+ <xsl:value-of select="$p_text_len_ * 1.5"/>
2750
+ </xsl:when>
2751
+ <xsl:otherwise><xsl:value-of select="$p_text_len_"/></xsl:otherwise>
2752
+ </xsl:choose>
2753
+ </xsl:variable>
2754
+
2755
+ <xsl:variable name="math_addon_text">
2756
+ <xsl:for-each select=".//*[local-name() = 'math']">
2757
+ <xsl:apply-templates mode="td_text"/>
2386
2758
  </xsl:for-each>
2387
2759
  </xsl:variable>
2760
+ <xsl:variable name="math_addon_length" select="string-length(normalize-space($math_addon_text)) * 0.2"/> <!-- plus 20% -->
2388
2761
 
2389
- <xsl:variable name="math_text" select="normalize-space(xalan:nodeset($mathml))"/>
2390
- <xsl:value-of select="translate($math_text, ' ', '#')"/><!-- mathml images as one 'word' without spaces -->
2762
+ <width><xsl:value-of select="$p_text_len + $math_addon_length"/></width>
2763
+ </xsl:template><xsl:template match="@*|node()" mode="determine_cell_widths-if">
2764
+ <xsl:copy>
2765
+ <xsl:apply-templates select="@*|node()" mode="determine_cell_widths-if"/>
2766
+ </xsl:copy>
2767
+ </xsl:template><xsl:template match="td | th" mode="determine_cell_widths-if">
2768
+ <xsl:copy>
2769
+ <xsl:copy-of select="@*"/>
2770
+
2771
+ <!-- The maximum width is given by the widest line. -->
2772
+ <xsl:attribute name="width_max">
2773
+ <xsl:for-each select="p_len">
2774
+ <xsl:sort select="." data-type="number" order="descending"/>
2775
+ <xsl:if test="position() = 1"><xsl:value-of select="."/></xsl:if>
2776
+ </xsl:for-each>
2777
+ </xsl:attribute>
2778
+
2779
+ <!-- The minimum width is given by the widest text element (word, image, etc.) -->
2780
+ <xsl:variable name="width_min">
2781
+ <xsl:for-each select="word_len">
2782
+ <xsl:sort select="." data-type="number" order="descending"/>
2783
+ <xsl:if test="position() = 1"><xsl:value-of select="."/></xsl:if>
2784
+ </xsl:for-each>
2785
+ </xsl:variable>
2786
+ <xsl:attribute name="width_min">
2787
+ <xsl:value-of select="$width_min"/>
2788
+ </xsl:attribute>
2789
+
2790
+ <xsl:if test="$width_min = 0">
2791
+ <xsl:attribute name="width_min">1</xsl:attribute>
2792
+ </xsl:if>
2793
+
2794
+ <xsl:apply-templates select="node()" mode="determine_cell_widths-if"/>
2795
+
2796
+ </xsl:copy>
2391
2797
  </xsl:template><xsl:template match="*[local-name()='thead']">
2392
2798
  <xsl:param name="cols-count"/>
2393
2799
  <fo:table-header>
@@ -2472,6 +2878,7 @@
2472
2878
  </xsl:for-each>
2473
2879
  </xsl:when>
2474
2880
  <xsl:otherwise>
2881
+ <!-- $colwidths=<xsl:copy-of select="$colwidths"/> -->
2475
2882
  <xsl:call-template name="insertTableColumnWidth">
2476
2883
  <xsl:with-param name="colwidths" select="$colwidths"/>
2477
2884
  </xsl:call-template>
@@ -2551,6 +2958,52 @@
2551
2958
 
2552
2959
  </fo:table-body>
2553
2960
 
2961
+ </xsl:template><xsl:template match="/" mode="process_table-if">
2962
+ <xsl:param name="table_or_dl">table</xsl:param>
2963
+ <xsl:apply-templates mode="process_table-if">
2964
+ <xsl:with-param name="table_or_dl" select="$table_or_dl"/>
2965
+ </xsl:apply-templates>
2966
+ </xsl:template><xsl:template match="*[local-name()='tbody']" mode="process_table-if">
2967
+ <xsl:param name="table_or_dl">table</xsl:param>
2968
+
2969
+ <fo:table-body>
2970
+ <xsl:for-each select="*[local-name() = 'tr']">
2971
+ <xsl:variable name="col_count" select="count(*)"/>
2972
+
2973
+ <!-- iteration for each tr/td -->
2974
+
2975
+ <xsl:choose>
2976
+ <xsl:when test="$table_or_dl = 'table'">
2977
+ <xsl:for-each select="*[local-name() = 'td' or local-name() = 'th']/*">
2978
+ <fo:table-row number-columns-spanned="{$col_count}">
2979
+ <!-- <test_table><xsl:copy-of select="."/></test_table> -->
2980
+ <xsl:call-template name="td"/>
2981
+ </fo:table-row>
2982
+ </xsl:for-each>
2983
+ </xsl:when>
2984
+ <xsl:otherwise> <!-- $table_or_dl = 'dl' -->
2985
+ <xsl:for-each select="*[local-name() = 'td' or local-name() = 'th']">
2986
+ <xsl:variable name="is_dt" select="position() = 1"/>
2987
+
2988
+ <xsl:for-each select="*">
2989
+ <!-- <test><xsl:copy-of select="."/></test> -->
2990
+ <fo:table-row number-columns-spanned="{$col_count}">
2991
+ <xsl:choose>
2992
+ <xsl:when test="$is_dt">
2993
+ <xsl:call-template name="insert_dt_cell"/>
2994
+ </xsl:when>
2995
+ <xsl:otherwise>
2996
+ <xsl:call-template name="insert_dd_cell"/>
2997
+ </xsl:otherwise>
2998
+ </xsl:choose>
2999
+ </fo:table-row>
3000
+ </xsl:for-each>
3001
+ </xsl:for-each>
3002
+ </xsl:otherwise>
3003
+ </xsl:choose>
3004
+
3005
+ </xsl:for-each>
3006
+ </fo:table-body>
2554
3007
  </xsl:template><xsl:template match="*[local-name()='thead']/*[local-name()='tr']" priority="2">
2555
3008
  <fo:table-row xsl:use-attribute-sets="table-header-row-style">
2556
3009
 
@@ -2637,7 +3090,7 @@
2637
3090
  </xsl:choose>
2638
3091
  </xsl:attribute>
2639
3092
  </xsl:if>
2640
- </xsl:template><xsl:template match="*[local-name()='td']">
3093
+ </xsl:template><xsl:template match="*[local-name()='td']" name="td">
2641
3094
  <fo:table-cell xsl:use-attribute-sets="table-cell-style"> <!-- text-align="{@align}" -->
2642
3095
  <xsl:call-template name="setTextAlignment">
2643
3096
  <xsl:with-param name="default">left</xsl:with-param>
@@ -2671,11 +3124,24 @@
2671
3124
 
2672
3125
  <xsl:call-template name="setTableCellAttributes"/>
2673
3126
 
3127
+ <xsl:if test="$isGenerateTableIF = 'true'">
3128
+ <xsl:attribute name="border">1pt solid black</xsl:attribute> <!-- border is mandatory, to determine page width -->
3129
+ <xsl:attribute name="text-align">left</xsl:attribute>
3130
+ </xsl:if>
3131
+
2674
3132
  <fo:block>
2675
3133
 
3134
+ <xsl:if test="$isGenerateTableIF = 'true'">
3135
+ <xsl:attribute name="id"><xsl:value-of select="@id"/></xsl:attribute>
3136
+ </xsl:if>
3137
+
3138
+
2676
3139
 
2677
3140
 
2678
3141
  <xsl:apply-templates/>
3142
+
3143
+ <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"/> -->
3144
+
2679
3145
  </fo:block>
2680
3146
  </fo:table-cell>
2681
3147
  </xsl:template><xsl:template match="*[local-name()='table']/*[local-name()='note']" priority="2">
@@ -2872,9 +3338,9 @@
2872
3338
  <!-- current hierarchy is 'figure' element -->
2873
3339
  <xsl:variable name="following_dl_colwidths">
2874
3340
  <xsl:if test="*[local-name() = 'dl']"><!-- if there is a 'dl', then set the same columns width as for 'dl' -->
2875
- <xsl:variable name="html-table">
2876
- <xsl:variable name="doc_ns">
2877
-
3341
+ <xsl:variable name="simple-table">
3342
+ <!-- <xsl:variable name="doc_ns">
3343
+ <xsl:if test="$namespace = 'bipm'">bipm</xsl:if>
2878
3344
  </xsl:variable>
2879
3345
  <xsl:variable name="ns">
2880
3346
  <xsl:choose>
@@ -2885,7 +3351,7 @@
2885
3351
  <xsl:value-of select="substring-before(name(/*), '-')"/>
2886
3352
  </xsl:otherwise>
2887
3353
  </xsl:choose>
2888
- </xsl:variable>
3354
+ </xsl:variable> -->
2889
3355
 
2890
3356
  <xsl:for-each select="*[local-name() = 'dl'][1]">
2891
3357
  <tbody>
@@ -2896,7 +3362,7 @@
2896
3362
 
2897
3363
  <xsl:call-template name="calculate-column-widths">
2898
3364
  <xsl:with-param name="cols-count" select="2"/>
2899
- <xsl:with-param name="table" select="$html-table"/>
3365
+ <xsl:with-param name="table" select="$simple-table"/>
2900
3366
  </xsl:call-template>
2901
3367
 
2902
3368
  </xsl:if>
@@ -3076,7 +3542,18 @@
3076
3542
 
3077
3543
 
3078
3544
 
3545
+
3546
+ <xsl:if test="$isGenerateTableIF = 'true'">
3547
+ <!-- to determine start of table -->
3548
+ <fo:block id="{concat('table_if_start_',@id)}" keep-with-next="always" font-size="1pt">Start table '<xsl:value-of select="@id"/>'.</fo:block>
3549
+ </xsl:if>
3550
+
3079
3551
  <fo:table width="95%" table-layout="fixed">
3552
+
3553
+ <xsl:if test="$isGenerateTableIF = 'true'">
3554
+ <xsl:attribute name="wrap-option">no-wrap</xsl:attribute>
3555
+ </xsl:if>
3556
+
3080
3557
 
3081
3558
  <xsl:choose>
3082
3559
  <xsl:when test="normalize-space($key_iso) = 'true' and $parent = 'formula'"/>
@@ -3085,52 +3562,130 @@
3085
3562
 
3086
3563
  </xsl:when>
3087
3564
  </xsl:choose>
3088
- <!-- create virtual html table for dl/[dt and dd] -->
3089
- <xsl:variable name="html-table">
3090
- <xsl:variable name="doc_ns">
3565
+
3566
+
3567
+ <xsl:choose>
3568
+ <xsl:when test="$isGenerateTableIF = 'true'">
3569
+ <!-- generate IF for table widths -->
3570
+ <!-- example:
3571
+ <tr>
3572
+ <td valign="top" align="left" id="tab-symdu_1_1">
3573
+ <p>Symbol</p>
3574
+ <word id="tab-symdu_1_1_word_1">Symbol</word>
3575
+ </td>
3576
+ <td valign="top" align="left" id="tab-symdu_1_2">
3577
+ <p>Description</p>
3578
+ <word id="tab-symdu_1_2_word_1">Description</word>
3579
+ </td>
3580
+ </tr>
3581
+ -->
3091
3582
 
3092
- </xsl:variable>
3093
- <xsl:variable name="ns">
3094
- <xsl:choose>
3095
- <xsl:when test="normalize-space($doc_ns) != ''">
3096
- <xsl:value-of select="normalize-space($doc_ns)"/>
3097
- </xsl:when>
3098
- <xsl:otherwise>
3099
- <xsl:value-of select="substring-before(name(/*), '-')"/>
3100
- </xsl:otherwise>
3101
- </xsl:choose>
3102
- </xsl:variable>
3103
- <tbody>
3104
- <xsl:apply-templates mode="dl"/>
3105
- </tbody>
3106
- </xsl:variable>
3107
- <!-- DEBUG: html-table<xsl:copy-of select="$html-table"/> -->
3108
- <xsl:variable name="colwidths">
3109
- <xsl:call-template name="calculate-column-widths">
3110
- <xsl:with-param name="cols-count" select="2"/>
3111
- <xsl:with-param name="table" select="$html-table"/>
3112
- </xsl:call-template>
3113
- </xsl:variable>
3114
- <!-- DEBUG: colwidths=<xsl:copy-of select="$colwidths"/> -->
3115
- <xsl:variable name="maxlength_dt">
3116
- <xsl:call-template name="getMaxLength_dt"/>
3117
- </xsl:variable>
3118
- <xsl:variable name="isContainsKeepTogetherTag_">
3119
- false
3120
- </xsl:variable>
3121
- <xsl:variable name="isContainsKeepTogetherTag" select="normalize-space($isContainsKeepTogetherTag_)"/>
3122
- <!-- isContainsExpressReference=<xsl:value-of select="$isContainsExpressReference"/> -->
3123
- <xsl:call-template name="setColumnWidth_dl">
3124
- <xsl:with-param name="colwidths" select="$colwidths"/>
3125
- <xsl:with-param name="maxlength_dt" select="$maxlength_dt"/>
3126
- <xsl:with-param name="isContainsKeepTogetherTag" select="$isContainsKeepTogetherTag"/>
3127
- </xsl:call-template>
3583
+ <!-- create virtual html table for dl/[dt and dd] -->
3584
+ <xsl:variable name="simple-table">
3585
+
3586
+ <xsl:variable name="dl_table">
3587
+ <tbody>
3588
+ <xsl:apply-templates mode="dl_if">
3589
+ <xsl:with-param name="id" select="@id"/>
3590
+ </xsl:apply-templates>
3591
+ </tbody>
3592
+ </xsl:variable>
3593
+
3594
+ <!-- dl_table='<xsl:copy-of select="$dl_table"/>' -->
3595
+
3596
+ <!-- Step: replace <br/> to <p>...</p> -->
3597
+ <xsl:variable name="table_without_br">
3598
+ <xsl:apply-templates select="xalan:nodeset($dl_table)" mode="table-without-br"/>
3599
+ </xsl:variable>
3600
+
3601
+ <!-- table_without_br='<xsl:copy-of select="$table_without_br"/>' -->
3602
+
3603
+ <!-- Step: add id to each cell -->
3604
+ <!-- add <word>...</word> for each word, image, math -->
3605
+ <xsl:variable name="simple-table-id">
3606
+ <xsl:apply-templates select="xalan:nodeset($table_without_br)" mode="simple-table-id">
3607
+ <xsl:with-param name="id" select="@id"/>
3608
+ </xsl:apply-templates>
3609
+ </xsl:variable>
3610
+
3611
+ <!-- simple-table-id='<xsl:copy-of select="$simple-table-id"/>' -->
3612
+
3613
+ <xsl:copy-of select="xalan:nodeset($simple-table-id)"/>
3614
+
3615
+ </xsl:variable>
3616
+
3617
+ <!-- DEBUG: simple-table<xsl:copy-of select="$simple-table"/> -->
3618
+
3619
+ <xsl:apply-templates select="xalan:nodeset($simple-table)" mode="process_table-if">
3620
+ <xsl:with-param name="table_or_dl">dl</xsl:with-param>
3621
+ </xsl:apply-templates>
3622
+
3623
+ </xsl:when>
3624
+ <xsl:otherwise>
3128
3625
 
3129
- <fo:table-body>
3130
- <xsl:apply-templates>
3131
- <xsl:with-param name="key_iso" select="normalize-space($key_iso)"/>
3132
- </xsl:apply-templates>
3133
- </fo:table-body>
3626
+ <xsl:variable name="simple-table">
3627
+
3628
+ <xsl:variable name="dl_table">
3629
+ <tbody>
3630
+ <xsl:apply-templates mode="dl">
3631
+ <xsl:with-param name="id" select="@id"/>
3632
+ </xsl:apply-templates>
3633
+ </tbody>
3634
+ </xsl:variable>
3635
+
3636
+ <xsl:copy-of select="$dl_table"/>
3637
+ </xsl:variable>
3638
+
3639
+ <xsl:variable name="colwidths">
3640
+ <xsl:call-template name="calculate-column-widths">
3641
+ <xsl:with-param name="cols-count" select="2"/>
3642
+ <xsl:with-param name="table" select="$simple-table"/>
3643
+ </xsl:call-template>
3644
+ </xsl:variable>
3645
+
3646
+ <!-- <xsl:text disable-output-escaping="yes">&lt;!- -</xsl:text>
3647
+ DEBUG
3648
+ colwidths=<xsl:copy-of select="$colwidths"/>
3649
+ <xsl:text disable-output-escaping="yes">- -&gt;</xsl:text> -->
3650
+
3651
+ <!-- colwidths=<xsl:copy-of select="$colwidths"/> -->
3652
+
3653
+ <xsl:variable name="maxlength_dt">
3654
+ <xsl:call-template name="getMaxLength_dt"/>
3655
+ </xsl:variable>
3656
+
3657
+ <xsl:variable name="isContainsKeepTogetherTag_">
3658
+ false
3659
+ </xsl:variable>
3660
+ <xsl:variable name="isContainsKeepTogetherTag" select="normalize-space($isContainsKeepTogetherTag_)"/>
3661
+ <!-- isContainsExpressReference=<xsl:value-of select="$isContainsExpressReference"/> -->
3662
+
3663
+
3664
+ <xsl:call-template name="setColumnWidth_dl">
3665
+ <xsl:with-param name="colwidths" select="$colwidths"/>
3666
+ <xsl:with-param name="maxlength_dt" select="$maxlength_dt"/>
3667
+ <xsl:with-param name="isContainsKeepTogetherTag" select="$isContainsKeepTogetherTag"/>
3668
+ </xsl:call-template>
3669
+
3670
+ <fo:table-body>
3671
+
3672
+ <!-- DEBUG -->
3673
+ <xsl:if test="$table_if_debug = 'true'">
3674
+ <fo:table-row>
3675
+ <fo:table-cell number-columns-spanned="2" font-size="60%">
3676
+ <xsl:apply-templates select="xalan:nodeset($colwidths)" mode="print_as_xml"/>
3677
+ </fo:table-cell>
3678
+ </fo:table-row>
3679
+ </xsl:if>
3680
+
3681
+ <xsl:apply-templates>
3682
+ <xsl:with-param name="key_iso" select="normalize-space($key_iso)"/>
3683
+ <xsl:with-param name="split_keep-within-line" select="xalan:nodeset($colwidths)/split_keep-within-line"/>
3684
+ </xsl:apply-templates>
3685
+
3686
+ </fo:table-body>
3687
+ </xsl:otherwise>
3688
+ </xsl:choose>
3134
3689
  </fo:table>
3135
3690
  </fo:block>
3136
3691
  </fo:block>
@@ -3141,6 +3696,9 @@
3141
3696
  <xsl:param name="colwidths"/>
3142
3697
  <xsl:param name="maxlength_dt"/>
3143
3698
  <xsl:param name="isContainsKeepTogetherTag"/>
3699
+
3700
+ <!-- <colwidths><xsl:copy-of select="$colwidths"/></colwidths> -->
3701
+
3144
3702
  <xsl:choose>
3145
3703
  <xsl:when test="ancestor::*[local-name()='dl']"><!-- second level, i.e. inlined table -->
3146
3704
  <fo:table-column column-width="50%"/>
@@ -3148,6 +3706,11 @@
3148
3706
  </xsl:when>
3149
3707
  <xsl:otherwise>
3150
3708
  <xsl:choose>
3709
+ <xsl:when test="xalan:nodeset($colwidths)/autolayout">
3710
+ <xsl:call-template name="insertTableColumnWidth">
3711
+ <xsl:with-param name="colwidths" select="$colwidths"/>
3712
+ </xsl:call-template>
3713
+ </xsl:when>
3151
3714
  <xsl:when test="$isContainsKeepTogetherTag">
3152
3715
  <xsl:call-template name="insertTableColumnWidth">
3153
3716
  <xsl:with-param name="colwidths" select="$colwidths"/>
@@ -3192,13 +3755,19 @@
3192
3755
  </xsl:choose>
3193
3756
  </xsl:template><xsl:template name="insertTableColumnWidth">
3194
3757
  <xsl:param name="colwidths"/>
3758
+
3195
3759
  <xsl:for-each select="xalan:nodeset($colwidths)//column">
3196
3760
  <xsl:choose>
3197
3761
  <xsl:when test=". = 1 or . = 0">
3198
3762
  <fo:table-column column-width="proportional-column-width(2)"/>
3199
3763
  </xsl:when>
3200
3764
  <xsl:otherwise>
3201
- <fo:table-column column-width="proportional-column-width({.})"/>
3765
+ <!-- <fo:table-column column-width="proportional-column-width({.})"/> -->
3766
+ <xsl:variable name="divider">
3767
+ <xsl:value-of select="@divider"/>
3768
+ <xsl:if test="not(@divider)">1</xsl:if>
3769
+ </xsl:variable>
3770
+ <fo:table-column column-width="proportional-column-width({round(. div $divider)})"/>
3202
3771
  </xsl:otherwise>
3203
3772
  </xsl:choose>
3204
3773
  </xsl:for-each>
@@ -3260,11 +3829,19 @@
3260
3829
  </fo:table-cell>
3261
3830
  </fo:table-row>
3262
3831
  </xsl:template><xsl:template match="*[local-name()='dt']" mode="dl">
3832
+ <xsl:param name="id"/>
3833
+ <xsl:variable name="row_number" select="count(preceding-sibling::*[local-name()='dt']) + 1"/>
3263
3834
  <tr>
3264
3835
  <td>
3836
+ <xsl:attribute name="id">
3837
+ <xsl:value-of select="concat($id,'_',$row_number,'_1')"/>
3838
+ </xsl:attribute>
3265
3839
  <xsl:apply-templates/>
3266
3840
  </td>
3267
3841
  <td>
3842
+ <xsl:attribute name="id">
3843
+ <xsl:value-of select="concat($id,'_',$row_number,'_2')"/>
3844
+ </xsl:attribute>
3268
3845
 
3269
3846
  <xsl:apply-templates select="following-sibling::*[local-name()='dd'][1]">
3270
3847
  <xsl:with-param name="process">true</xsl:with-param>
@@ -3275,50 +3852,122 @@
3275
3852
 
3276
3853
  </xsl:template><xsl:template match="*[local-name()='dt']">
3277
3854
  <xsl:param name="key_iso"/>
3855
+ <xsl:param name="split_keep-within-line"/>
3278
3856
 
3279
3857
  <fo:table-row xsl:use-attribute-sets="dt-row-style">
3280
- <fo:table-cell>
3858
+ <xsl:call-template name="insert_dt_cell">
3859
+ <xsl:with-param name="key_iso" select="$key_iso"/>
3860
+ <xsl:with-param name="split_keep-within-line" select="$split_keep-within-line"/>
3861
+ </xsl:call-template>
3862
+ <xsl:for-each select="following-sibling::*[local-name()='dd'][1]">
3863
+ <xsl:call-template name="insert_dd_cell">
3864
+ <xsl:with-param name="split_keep-within-line" select="$split_keep-within-line"/>
3865
+ </xsl:call-template>
3866
+ </xsl:for-each>
3867
+ </fo:table-row>
3868
+ </xsl:template><xsl:template name="insert_dt_cell">
3869
+ <xsl:param name="key_iso"/>
3870
+ <xsl:param name="split_keep-within-line"/>
3871
+ <fo:table-cell xsl:use-attribute-sets="dt-cell-style">
3872
+
3873
+ <xsl:if test="$isGenerateTableIF = 'true'">
3874
+ <!-- border is mandatory, to calculate real width -->
3875
+ <xsl:attribute name="border">0.1pt solid black</xsl:attribute>
3876
+ <xsl:attribute name="text-align">left</xsl:attribute>
3877
+ </xsl:if>
3878
+
3879
+
3880
+ <fo:block xsl:use-attribute-sets="dt-block-style">
3881
+ <xsl:copy-of select="@id"/>
3882
+
3883
+ <xsl:if test="normalize-space($key_iso) = 'true'">
3884
+ <xsl:attribute name="margin-top">0</xsl:attribute>
3885
+ </xsl:if>
3886
+
3887
+
3888
+
3889
+ <xsl:apply-templates>
3890
+ <xsl:with-param name="split_keep-within-line" select="$split_keep-within-line"/>
3891
+ </xsl:apply-templates>
3892
+
3893
+ <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"/> -->
3894
+
3895
+ </fo:block>
3896
+ </fo:table-cell>
3897
+ </xsl:template><xsl:template name="insert_dd_cell">
3898
+ <xsl:param name="split_keep-within-line"/>
3899
+ <fo:table-cell xsl:use-attribute-sets="dd-cell-style">
3900
+
3901
+ <xsl:if test="$isGenerateTableIF = 'true'">
3902
+ <!-- border is mandatory, to calculate real width -->
3903
+ <xsl:attribute name="border">0.1pt solid black</xsl:attribute>
3904
+ </xsl:if>
3905
+
3906
+ <fo:block>
3907
+
3908
+ <xsl:if test="$isGenerateTableIF = 'true'">
3909
+ <xsl:attribute name="id"><xsl:value-of select="@id"/></xsl:attribute>
3910
+ </xsl:if>
3911
+
3281
3912
 
3282
- <fo:block xsl:use-attribute-sets="dt-style">
3283
- <xsl:copy-of select="@id"/>
3284
-
3285
- <xsl:if test="normalize-space($key_iso) = 'true'">
3286
- <xsl:attribute name="margin-top">0</xsl:attribute>
3287
- </xsl:if>
3288
-
3289
-
3290
-
3291
- <xsl:apply-templates/>
3292
- </fo:block>
3293
- </fo:table-cell>
3294
- <fo:table-cell>
3295
- <fo:block>
3296
-
3297
3913
 
3298
- <xsl:apply-templates select="following-sibling::*[local-name()='dd'][1]">
3299
- <xsl:with-param name="process">true</xsl:with-param>
3300
- </xsl:apply-templates>
3301
- </fo:block>
3302
- </fo:table-cell>
3303
- </fo:table-row>
3914
+ <xsl:choose>
3915
+ <xsl:when test="$isGenerateTableIF = 'true'">
3916
+ <xsl:apply-templates> <!-- following-sibling::*[local-name()='dd'][1] -->
3917
+ <xsl:with-param name="process">true</xsl:with-param>
3918
+ </xsl:apply-templates>
3919
+ </xsl:when>
3920
+ <xsl:otherwise>
3921
+ <xsl:apply-templates select="."> <!-- following-sibling::*[local-name()='dd'][1] -->
3922
+ <xsl:with-param name="process">true</xsl:with-param>
3923
+ <xsl:with-param name="split_keep-within-line" select="$split_keep-within-line"/>
3924
+ </xsl:apply-templates>
3925
+ </xsl:otherwise>
3926
+
3927
+ </xsl:choose>
3928
+
3929
+ <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"/> -->
3930
+
3931
+ </fo:block>
3932
+ </fo:table-cell>
3304
3933
  </xsl:template><xsl:template match="*[local-name()='dd']" mode="dl"/><xsl:template match="*[local-name()='dd']" mode="dl_process">
3305
3934
  <xsl:apply-templates/>
3306
3935
  </xsl:template><xsl:template match="*[local-name()='dd']">
3307
3936
  <xsl:param name="process">false</xsl:param>
3937
+ <xsl:param name="split_keep-within-line"/>
3308
3938
  <xsl:if test="$process = 'true'">
3309
3939
  <xsl:apply-templates select="@language"/>
3310
- <xsl:apply-templates/>
3940
+ <xsl:apply-templates>
3941
+ <xsl:with-param name="split_keep-within-line" select="$split_keep-within-line"/>
3942
+ </xsl:apply-templates>
3311
3943
  </xsl:if>
3312
3944
  </xsl:template><xsl:template match="*[local-name()='dd']/*[local-name()='p']" mode="inline">
3313
3945
  <fo:inline><xsl:text> </xsl:text><xsl:apply-templates/></fo:inline>
3314
- </xsl:template><xsl:template match="*[local-name()='em']">
3946
+ </xsl:template><xsl:template match="*[local-name()='dt']" mode="dl_if">
3947
+ <xsl:param name="id"/>
3948
+ <xsl:variable name="row_number" select="count(preceding-sibling::*[local-name()='dt']) + 1"/>
3949
+ <tr>
3950
+ <td>
3951
+ <xsl:copy-of select="node()"/>
3952
+ </td>
3953
+ <td>
3954
+
3955
+ <xsl:copy-of select="following-sibling::*[local-name()='dd'][1]/node()"/>
3956
+
3957
+ </td>
3958
+ </tr>
3959
+
3960
+ </xsl:template><xsl:template match="*[local-name()='dd']" mode="dl_if"/><xsl:template match="*[local-name()='em']">
3315
3961
  <fo:inline font-style="italic">
3316
3962
  <xsl:apply-templates/>
3317
3963
  </fo:inline>
3318
3964
  </xsl:template><xsl:template match="*[local-name()='strong'] | *[local-name()='b']">
3965
+ <xsl:param name="split_keep-within-line"/>
3319
3966
  <fo:inline font-weight="bold">
3320
3967
 
3321
- <xsl:apply-templates/>
3968
+ <xsl:apply-templates>
3969
+ <xsl:with-param name="split_keep-within-line" select="$split_keep-within-line"/>
3970
+ </xsl:apply-templates>
3322
3971
  </fo:inline>
3323
3972
  </xsl:template><xsl:template match="*[local-name()='padding']">
3324
3973
  <fo:inline padding-right="{@value}"> </fo:inline>
@@ -3519,6 +4168,10 @@
3519
4168
  <xsl:param name="text"/>
3520
4169
  <xsl:param name="separator" select="' '"/>
3521
4170
  <xsl:choose>
4171
+
4172
+ <xsl:when test="$isGenerateTableIF = 'true' and not(contains($text, $separator))">
4173
+ <word><xsl:value-of select="normalize-space($text)"/></word>
4174
+ </xsl:when>
3522
4175
  <xsl:when test="not(contains($text, $separator))">
3523
4176
  <word>
3524
4177
  <xsl:variable name="len_str_tmp" select="string-length(normalize-space($text))"/>
@@ -3563,13 +4216,66 @@
3563
4216
  </xsl:when>
3564
4217
  <xsl:otherwise>
3565
4218
  <word>
3566
- <xsl:value-of select="string-length(normalize-space(substring-before($text, $separator)))"/>
4219
+ <xsl:variable name="word" select="normalize-space(substring-before($text, $separator))"/>
4220
+ <xsl:choose>
4221
+ <xsl:when test="$isGenerateTableIF = 'true'">
4222
+ <xsl:value-of select="$word"/>
4223
+ </xsl:when>
4224
+ <xsl:otherwise>
4225
+ <xsl:value-of select="string-length($word)"/>
4226
+ </xsl:otherwise>
4227
+ </xsl:choose>
3567
4228
  </word>
3568
4229
  <xsl:call-template name="tokenize">
3569
4230
  <xsl:with-param name="text" select="substring-after($text, $separator)"/>
3570
4231
  </xsl:call-template>
3571
4232
  </xsl:otherwise>
3572
4233
  </xsl:choose>
4234
+ </xsl:template><xsl:template name="tokenize_with_tags">
4235
+ <xsl:param name="tags"/>
4236
+ <xsl:param name="text"/>
4237
+ <xsl:param name="separator" select="' '"/>
4238
+ <xsl:choose>
4239
+
4240
+ <xsl:when test="not(contains($text, $separator))">
4241
+ <word>
4242
+ <xsl:call-template name="enclose_text_in_tags">
4243
+ <xsl:with-param name="text" select="normalize-space($text)"/>
4244
+ <xsl:with-param name="tags" select="$tags"/>
4245
+ </xsl:call-template>
4246
+ </word>
4247
+ </xsl:when>
4248
+ <xsl:otherwise>
4249
+ <word>
4250
+ <xsl:call-template name="enclose_text_in_tags">
4251
+ <xsl:with-param name="text" select="normalize-space(substring-before($text, $separator))"/>
4252
+ <xsl:with-param name="tags" select="$tags"/>
4253
+ </xsl:call-template>
4254
+ </word>
4255
+ <xsl:call-template name="tokenize_with_tags">
4256
+ <xsl:with-param name="text" select="substring-after($text, $separator)"/>
4257
+ </xsl:call-template>
4258
+ </xsl:otherwise>
4259
+ </xsl:choose>
4260
+ </xsl:template><xsl:template name="enclose_text_in_tags">
4261
+ <xsl:param name="text"/>
4262
+ <xsl:param name="tags"/>
4263
+ <xsl:param name="num">1</xsl:param> <!-- default (start) value -->
4264
+
4265
+ <xsl:variable name="tag_name" select="normalize-space(xalan:nodeset($tags)//tag[$num])"/>
4266
+
4267
+ <xsl:choose>
4268
+ <xsl:when test="$tag_name = ''"><xsl:value-of select="$text"/></xsl:when>
4269
+ <xsl:otherwise>
4270
+ <xsl:element name="{$tag_name}">
4271
+ <xsl:call-template name="enclose_text_in_tags">
4272
+ <xsl:with-param name="text" select="$text"/>
4273
+ <xsl:with-param name="tags" select="$tags"/>
4274
+ <xsl:with-param name="num" select="$num + 1"/>
4275
+ </xsl:call-template>
4276
+ </xsl:element>
4277
+ </xsl:otherwise>
4278
+ </xsl:choose>
3573
4279
  </xsl:template><xsl:template name="max_length">
3574
4280
  <xsl:param name="words"/>
3575
4281
  <xsl:for-each select="$words//word">
@@ -3670,12 +4376,19 @@
3670
4376
  </xsl:otherwise>
3671
4377
  </xsl:choose>
3672
4378
  </xsl:template><xsl:template name="getSimpleTable">
4379
+ <xsl:param name="id"/>
4380
+
3673
4381
  <xsl:variable name="simple-table">
3674
4382
 
4383
+ <!-- Step 0. replace <br/> to <p>...</p> -->
4384
+ <xsl:variable name="table_without_br">
4385
+ <xsl:apply-templates mode="table-without-br"/>
4386
+ </xsl:variable>
4387
+
3675
4388
  <!-- Step 1. colspan processing -->
3676
4389
  <xsl:variable name="simple-table-colspan">
3677
4390
  <tbody>
3678
- <xsl:apply-templates mode="simple-table-colspan"/>
4391
+ <xsl:apply-templates select="xalan:nodeset($table_without_br)" mode="simple-table-colspan"/>
3679
4392
  </tbody>
3680
4393
  </xsl:variable>
3681
4394
 
@@ -3684,10 +4397,67 @@
3684
4397
  <xsl:apply-templates select="xalan:nodeset($simple-table-colspan)" mode="simple-table-rowspan"/>
3685
4398
  </xsl:variable>
3686
4399
 
3687
- <xsl:copy-of select="xalan:nodeset($simple-table-rowspan)"/>
3688
-
4400
+ <!-- Step 3: add id to each cell -->
4401
+ <!-- add <word>...</word> for each word, image, math -->
4402
+ <xsl:variable name="simple-table-id">
4403
+ <xsl:apply-templates select="xalan:nodeset($simple-table-rowspan)" mode="simple-table-id">
4404
+ <xsl:with-param name="id" select="$id"/>
4405
+ </xsl:apply-templates>
4406
+ </xsl:variable>
4407
+
4408
+ <xsl:copy-of select="xalan:nodeset($simple-table-id)"/>
4409
+
3689
4410
  </xsl:variable>
3690
4411
  <xsl:copy-of select="$simple-table"/>
4412
+ </xsl:template><xsl:template match="@*|node()" mode="table-without-br">
4413
+ <xsl:copy>
4414
+ <xsl:apply-templates select="@*|node()" mode="table-without-br"/>
4415
+ </xsl:copy>
4416
+ </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">
4417
+ <xsl:copy>
4418
+ <xsl:copy-of select="@*"/>
4419
+ <p>
4420
+ <xsl:copy-of select="node()"/>
4421
+ </p>
4422
+ </xsl:copy>
4423
+ </xsl:template><xsl:template match="*[local-name()='th' or local-name()='td'][*[local-name()='br']]" mode="table-without-br">
4424
+ <xsl:copy>
4425
+ <xsl:copy-of select="@*"/>
4426
+ <xsl:for-each select="*[local-name()='br']">
4427
+ <xsl:variable name="current_id" select="generate-id()"/>
4428
+ <p>
4429
+ <xsl:for-each select="preceding-sibling::node()[following-sibling::*[local-name() = 'br'][1][generate-id() = $current_id]][not(local-name() = 'br')]">
4430
+ <xsl:copy-of select="."/>
4431
+ </xsl:for-each>
4432
+ </p>
4433
+ <xsl:if test="not(following-sibling::*[local-name() = 'br'])">
4434
+ <p>
4435
+ <xsl:for-each select="following-sibling::node()">
4436
+ <xsl:copy-of select="."/>
4437
+ </xsl:for-each>
4438
+ </p>
4439
+ </xsl:if>
4440
+ </xsl:for-each>
4441
+ </xsl:copy>
4442
+ </xsl:template><xsl:template match="*[local-name()='th' or local-name()='td']/*[local-name() = 'p'][*[local-name()='br']]" mode="table-without-br">
4443
+ <xsl:for-each select="*[local-name()='br']">
4444
+ <xsl:variable name="current_id" select="generate-id()"/>
4445
+ <p>
4446
+ <xsl:for-each select="preceding-sibling::node()[following-sibling::*[local-name() = 'br'][1][generate-id() = $current_id]][not(local-name() = 'br')]">
4447
+ <xsl:copy-of select="."/>
4448
+ </xsl:for-each>
4449
+ </p>
4450
+ <xsl:if test="not(following-sibling::*[local-name() = 'br'])">
4451
+ <p>
4452
+ <xsl:for-each select="following-sibling::node()">
4453
+ <xsl:copy-of select="."/>
4454
+ </xsl:for-each>
4455
+ </p>
4456
+ </xsl:if>
4457
+ </xsl:for-each>
4458
+ </xsl:template><xsl:template match="text()[not(ancestor::*[local-name() = 'sourcecode'])]" mode="table-without-br">
4459
+ <xsl:variable name="text" select="translate(.,'&#9;&#10;&#13;','')"/>
4460
+ <xsl:value-of select="java:replaceAll(java:java.lang.String.new($text),' {2,}',' ')"/>
3691
4461
  </xsl:template><xsl:template match="*[local-name()='thead'] | *[local-name()='tbody']" mode="simple-table-colspan">
3692
4462
  <xsl:apply-templates mode="simple-table-colspan"/>
3693
4463
  </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">
@@ -3777,6 +4547,126 @@
3777
4547
  <xsl:apply-templates select="following-sibling::tr[1]" mode="simple-table-rowspan">
3778
4548
  <xsl:with-param name="previousRow" select="$newRow"/>
3779
4549
  </xsl:apply-templates>
4550
+ </xsl:template><xsl:template match="/" mode="simple-table-id">
4551
+ <xsl:param name="id"/>
4552
+ <xsl:variable name="id_prefixed" select="concat('table_if_',$id)"/> <!-- table id prefixed by 'table_if_' to simple search in IF -->
4553
+ <xsl:apply-templates select="@*|node()" mode="simple-table-id">
4554
+ <xsl:with-param name="id" select="$id_prefixed"/>
4555
+ </xsl:apply-templates>
4556
+ </xsl:template><xsl:template match="@*|node()" mode="simple-table-id">
4557
+ <xsl:param name="id"/>
4558
+ <xsl:copy>
4559
+ <xsl:apply-templates select="@*|node()" mode="simple-table-id">
4560
+ <xsl:with-param name="id" select="$id"/>
4561
+ </xsl:apply-templates>
4562
+ </xsl:copy>
4563
+ </xsl:template><xsl:template match="*[local-name()='tbody']" mode="simple-table-id">
4564
+ <xsl:param name="id"/>
4565
+ <xsl:copy>
4566
+ <xsl:copy-of select="@*"/>
4567
+ <xsl:attribute name="id"><xsl:value-of select="$id"/></xsl:attribute>
4568
+ <xsl:apply-templates select="node()" mode="simple-table-id">
4569
+ <xsl:with-param name="id" select="$id"/>
4570
+ </xsl:apply-templates>
4571
+ </xsl:copy>
4572
+ </xsl:template><xsl:template match="*[local-name()='th' or local-name()='td']" mode="simple-table-id">
4573
+ <xsl:param name="id"/>
4574
+ <xsl:copy>
4575
+ <xsl:copy-of select="@*"/>
4576
+ <xsl:variable name="row_number" select="count(../preceding-sibling::*) + 1"/>
4577
+ <xsl:variable name="col_number" select="count(preceding-sibling::*) + 1"/>
4578
+ <xsl:attribute name="id">
4579
+ <xsl:value-of select="concat($id,'_',$row_number,'_',$col_number)"/>
4580
+ </xsl:attribute>
4581
+
4582
+ <xsl:for-each select="*[local-name() = 'p']">
4583
+ <xsl:copy>
4584
+ <xsl:copy-of select="@*"/>
4585
+ <xsl:variable name="p_num" select="count(preceding-sibling::*[local-name() = 'p']) + 1"/>
4586
+ <xsl:attribute name="id">
4587
+ <xsl:value-of select="concat($id,'_',$row_number,'_',$col_number,'_p_',$p_num)"/>
4588
+ </xsl:attribute>
4589
+
4590
+ <xsl:copy-of select="node()"/>
4591
+ </xsl:copy>
4592
+ </xsl:for-each>
4593
+
4594
+
4595
+ <xsl:if test="$isGenerateTableIF = 'true'"> <!-- split each paragraph to words, image, math -->
4596
+
4597
+ <xsl:variable name="td_text">
4598
+ <xsl:apply-templates select="." mode="td_text_with_formatting"/>
4599
+ </xsl:variable>
4600
+
4601
+ <!-- td_text='<xsl:copy-of select="$td_text"/>' -->
4602
+
4603
+ <xsl:variable name="words">
4604
+ <xsl:for-each select=".//*[local-name() = 'image' or local-name() = 'stem']">
4605
+ <word>
4606
+ <xsl:copy-of select="."/>
4607
+ </word>
4608
+ </xsl:for-each>
4609
+
4610
+ <xsl:for-each select="xalan:nodeset($td_text)//*[local-name() = 'word'][normalize-space() != '']">
4611
+ <xsl:copy-of select="."/>
4612
+ </xsl:for-each>
4613
+
4614
+ </xsl:variable>
4615
+
4616
+ <xsl:for-each select="xalan:nodeset($words)/word">
4617
+ <xsl:variable name="num" select="count(preceding-sibling::word) + 1"/>
4618
+ <xsl:copy>
4619
+ <xsl:attribute name="id">
4620
+ <xsl:value-of select="concat($id,'_',$row_number,'_',$col_number,'_word_',$num)"/>
4621
+ </xsl:attribute>
4622
+ <xsl:copy-of select="node()"/>
4623
+ </xsl:copy>
4624
+ </xsl:for-each>
4625
+ </xsl:if>
4626
+ </xsl:copy>
4627
+
4628
+ </xsl:template><xsl:template match="@*|node()" mode="td_text_with_formatting">
4629
+ <xsl:copy>
4630
+ <xsl:apply-templates select="@*|node()" mode="td_text_with_formatting"/>
4631
+ </xsl:copy>
4632
+ </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">
4633
+ <xsl:variable name="formatting_tags">
4634
+ <xsl:call-template name="getFormattingTags"/>
4635
+ </xsl:variable>
4636
+ <word>
4637
+ <xsl:call-template name="enclose_text_in_tags">
4638
+ <xsl:with-param name="text" select="normalize-space(.)"/>
4639
+ <xsl:with-param name="tags" select="$formatting_tags"/>
4640
+ </xsl:call-template>
4641
+ </word>
4642
+ </xsl:template><xsl:template match="*[local-name() != 'keep-together_within-line']/text()" mode="td_text_with_formatting">
4643
+
4644
+ <xsl:variable name="td_text" select="."/>
4645
+
4646
+ <xsl:variable name="string_with_added_zerospaces">
4647
+ <xsl:call-template name="add-zero-spaces-java">
4648
+ <xsl:with-param name="text" select="$td_text"/>
4649
+ </xsl:call-template>
4650
+ </xsl:variable>
4651
+
4652
+ <xsl:variable name="formatting_tags">
4653
+ <xsl:call-template name="getFormattingTags"/>
4654
+ </xsl:variable>
4655
+
4656
+ <!-- <word>text</word> -->
4657
+ <xsl:call-template name="tokenize_with_tags">
4658
+ <xsl:with-param name="tags" select="$formatting_tags"/>
4659
+ <xsl:with-param name="text" select="normalize-space(translate($string_with_added_zerospaces, '​­', ' '))"/> <!-- replace zero-width-space and soft-hyphen to space -->
4660
+ </xsl:call-template>
4661
+ </xsl:template><xsl:template name="getFormattingTags">
4662
+ <tags>
4663
+ <xsl:if test="ancestor::*[local-name() = 'strong']"><tag>strong</tag></xsl:if>
4664
+ <xsl:if test="ancestor::*[local-name() = 'em']"><tag>em</tag></xsl:if>
4665
+ <xsl:if test="ancestor::*[local-name() = 'sub']"><tag>sub</tag></xsl:if>
4666
+ <xsl:if test="ancestor::*[local-name() = 'sup']"><tag>sup</tag></xsl:if>
4667
+ <xsl:if test="ancestor::*[local-name() = 'tt']"><tag>tt</tag></xsl:if>
4668
+ <xsl:if test="ancestor::*[local-name() = 'keep-together_within-line']"><tag>keep-together_within-line</tag></xsl:if>
4669
+ </tags>
3780
4670
  </xsl:template><xsl:template name="getLang">
3781
4671
  <xsl:variable name="language_current" select="normalize-space(//*[local-name()='bibdata']//*[local-name()='language'][@current = 'true'])"/>
3782
4672
  <xsl:variable name="language">
@@ -5464,7 +6354,9 @@
5464
6354
  <!-- <xsl:attribute name="border">0.5pt solid black</xsl:attribute> -->
5465
6355
  </xsl:if>
5466
6356
  <xsl:variable name="simple-table">
5467
- <xsl:call-template name="getSimpleTable"/>
6357
+ <xsl:call-template name="getSimpleTable">
6358
+ <xsl:with-param name="id" select="@id"/>
6359
+ </xsl:call-template>
5468
6360
  </xsl:variable>
5469
6361
  <xsl:variable name="cols-count" select="count(xalan:nodeset($simple-table)//tr[1]/td)"/>
5470
6362
  <xsl:if test="$cols-count = 2 and not(ancestor::*[local-name()='table'])">
@@ -6410,7 +7302,7 @@
6410
7302
  <!-- <fo:inline id="{@id}" font-size="1pt"/> -->
6411
7303
  <fo:inline id="{@id}" font-size="1pt"><xsl:value-of select="$hair_space"/></fo:inline>
6412
7304
  <!-- we need to add zero-width space, otherwise this fo:inline is missing in IF xml -->
6413
- <xsl:if test="not(following-sibling::node()[normalize-space() != ''])"> </xsl:if>
7305
+ <xsl:if test="not(following-sibling::node()[normalize-space() != ''])"><fo:inline font-size="1pt"> </fo:inline></xsl:if>
6414
7306
  </xsl:template><xsl:template match="*[local-name() = 'errata']">
6415
7307
  <!-- <row>
6416
7308
  <date>05-07-2013</date>
@@ -7751,4 +8643,40 @@
7751
8643
  <xsl:value-of select="$value"/>
7752
8644
  </xsl:otherwise>
7753
8645
  </xsl:choose>
8646
+ </xsl:template><xsl:template match="*" mode="print_as_xml">
8647
+ <xsl:param name="level">0</xsl:param>
8648
+
8649
+ <fo:block margin-left="{2*$level}mm">
8650
+ <xsl:text>
8651
+ &lt;</xsl:text>
8652
+ <xsl:value-of select="local-name()"/>
8653
+ <xsl:for-each select="@*">
8654
+ <xsl:text> </xsl:text>
8655
+ <xsl:value-of select="local-name()"/>
8656
+ <xsl:text>="</xsl:text>
8657
+ <xsl:value-of select="."/>
8658
+ <xsl:text>"</xsl:text>
8659
+ </xsl:for-each>
8660
+ <xsl:text>&gt;</xsl:text>
8661
+
8662
+ <xsl:if test="not(*)">
8663
+ <fo:inline font-weight="bold"><xsl:value-of select="."/></fo:inline>
8664
+ <xsl:text>&lt;/</xsl:text>
8665
+ <xsl:value-of select="local-name()"/>
8666
+ <xsl:text>&gt;</xsl:text>
8667
+ </xsl:if>
8668
+ </fo:block>
8669
+
8670
+ <xsl:if test="*">
8671
+ <fo:block>
8672
+ <xsl:apply-templates mode="print_as_xml">
8673
+ <xsl:with-param name="level" select="$level + 1"/>
8674
+ </xsl:apply-templates>
8675
+ </fo:block>
8676
+ <fo:block margin-left="{2*$level}mm">
8677
+ <xsl:text>&lt;/</xsl:text>
8678
+ <xsl:value-of select="local-name()"/>
8679
+ <xsl:text>&gt;</xsl:text>
8680
+ </fo:block>
8681
+ </xsl:if>
7754
8682
  </xsl:template></xsl:stylesheet>