metanorma-ogc 2.1.0 → 2.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -488,6 +488,7 @@
488
488
 
489
489
  <xsl:template match="ogc:p" name="paragraph">
490
490
  <xsl:param name="inline" select="'false'"/>
491
+ <xsl:param name="split_keep-within-line"/>
491
492
  <xsl:variable name="previous-element" select="local-name(preceding-sibling::*[1])"/>
492
493
  <xsl:variable name="element-name">
493
494
  <xsl:choose>
@@ -518,7 +519,9 @@
518
519
  <xsl:attribute name="margin-bottom">6pt</xsl:attribute>
519
520
  </xsl:if>
520
521
  <xsl:attribute name="line-height">115%</xsl:attribute>
521
- <xsl:apply-templates/>
522
+ <xsl:apply-templates>
523
+ <xsl:with-param name="split_keep-within-line" select="$split_keep-within-line"/>
524
+ </xsl:apply-templates>
522
525
  </xsl:element>
523
526
  <xsl:if test="$element-name = 'fo:inline' and not($inline = 'true') and not(local-name(..) = 'admonition')">
524
527
  <fo:block margin-bottom="12pt">
@@ -640,7 +643,9 @@
640
643
  </xsl:choose>
641
644
  </xsl:template>
642
645
 
643
- <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">
646
+ <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_">
647
+ false
648
+ </xsl:variable><xsl:variable name="isGenerateTableIF" select="normalize-space($isGenerateTableIF_)"/><xsl:variable name="lang">
644
649
  <xsl:call-template name="getLang"/>
645
650
  </xsl:variable><xsl:variable name="pageWidth_">
646
651
  215.9
@@ -1167,6 +1172,7 @@
1167
1172
  <xsl:attribute name="font-weight">bold</xsl:attribute>
1168
1173
  <xsl:attribute name="border">solid black 1pt</xsl:attribute>
1169
1174
  <xsl:attribute name="padding-left">1mm</xsl:attribute>
1175
+ <xsl:attribute name="padding-right">1mm</xsl:attribute>
1170
1176
  <xsl:attribute name="display-align">center</xsl:attribute>
1171
1177
 
1172
1178
 
@@ -1191,6 +1197,7 @@
1191
1197
  <xsl:attribute name="display-align">center</xsl:attribute>
1192
1198
  <xsl:attribute name="border">solid black 1pt</xsl:attribute>
1193
1199
  <xsl:attribute name="padding-left">1mm</xsl:attribute>
1200
+ <xsl:attribute name="padding-right">1mm</xsl:attribute>
1194
1201
 
1195
1202
 
1196
1203
 
@@ -1279,7 +1286,8 @@
1279
1286
  </xsl:attribute-set><xsl:attribute-set name="dt-row-style">
1280
1287
 
1281
1288
 
1282
- </xsl:attribute-set><xsl:attribute-set name="dt-style">
1289
+ </xsl:attribute-set><xsl:attribute-set name="dt-cell-style">
1290
+ </xsl:attribute-set><xsl:attribute-set name="dt-block-style">
1283
1291
  <xsl:attribute name="margin-top">6pt</xsl:attribute>
1284
1292
 
1285
1293
 
@@ -1294,6 +1302,8 @@
1294
1302
  <xsl:attribute name="margin-bottom">6pt</xsl:attribute>
1295
1303
 
1296
1304
 
1305
+ </xsl:attribute-set><xsl:attribute-set name="dd-cell-style">
1306
+ <xsl:attribute name="padding-left">2mm</xsl:attribute>
1297
1307
  </xsl:attribute-set><xsl:attribute-set name="appendix-style">
1298
1308
 
1299
1309
  <xsl:attribute name="font-size">12pt</xsl:attribute>
@@ -2171,7 +2181,38 @@
2171
2181
  </xsl:template><xsl:template match="*[local-name()='br']">
2172
2182
  <xsl:value-of select="$linebreak"/>
2173
2183
  </xsl:template><xsl:template match="*[local-name() = 'keep-together_within-line']">
2174
- <fo:inline keep-together.within-line="always"><xsl:apply-templates/></fo:inline>
2184
+ <xsl:param name="split_keep-within-line"/>
2185
+
2186
+ <!-- <fo:inline>split_keep-within-line='<xsl:value-of select="$split_keep-within-line"/>'</fo:inline> -->
2187
+ <xsl:choose>
2188
+
2189
+ <xsl:when test="normalize-space($split_keep-within-line) = 'true'">
2190
+ <xsl:variable name="sep">_</xsl:variable>
2191
+ <xsl:variable name="items">
2192
+ <xsl:call-template name="split">
2193
+ <xsl:with-param name="pText" select="."/>
2194
+ <xsl:with-param name="sep" select="$sep"/>
2195
+ <xsl:with-param name="normalize-space">false</xsl:with-param>
2196
+ <xsl:with-param name="keep_sep">true</xsl:with-param>
2197
+ </xsl:call-template>
2198
+ </xsl:variable>
2199
+ <xsl:for-each select="xalan:nodeset($items)/item">
2200
+ <xsl:choose>
2201
+ <xsl:when test=". = $sep">
2202
+ <xsl:value-of select="$sep"/><xsl:value-of select="$zero_width_space"/>
2203
+ </xsl:when>
2204
+ <xsl:otherwise>
2205
+ <fo:inline keep-together.within-line="always"><xsl:apply-templates/></fo:inline>
2206
+ </xsl:otherwise>
2207
+ </xsl:choose>
2208
+ </xsl:for-each>
2209
+ </xsl:when>
2210
+
2211
+ <xsl:otherwise>
2212
+ <fo:inline keep-together.within-line="always"><xsl:apply-templates/></fo:inline>
2213
+ </xsl:otherwise>
2214
+
2215
+ </xsl:choose>
2175
2216
  </xsl:template><xsl:template match="*[local-name()='copyright-statement']">
2176
2217
  <fo:block xsl:use-attribute-sets="copyright-statement-style">
2177
2218
  <xsl:apply-templates/>
@@ -2306,9 +2347,14 @@
2306
2347
 
2307
2348
  <xsl:variable name="table">
2308
2349
 
2309
- <xsl:variable name="simple-table">
2310
- <xsl:call-template name="getSimpleTable"/>
2350
+ <xsl:variable name="simple-table">
2351
+ <xsl:call-template name="getSimpleTable">
2352
+ <xsl:with-param name="id" select="@id"/>
2353
+ </xsl:call-template>
2311
2354
  </xsl:variable>
2355
+ <!-- <xsl:variable name="simple-table" select="xalan:nodeset($simple-table_)"/> -->
2356
+
2357
+ <!-- simple-table=<xsl:copy-of select="$simple-table"/> -->
2312
2358
 
2313
2359
 
2314
2360
  <!-- Display table's name before table as standalone block -->
@@ -2329,7 +2375,23 @@
2329
2375
  </xsl:call-template>
2330
2376
  </xsl:if>
2331
2377
  </xsl:variable>
2332
- <!-- DEBUG colwidths=<xsl:copy-of select="$colwidths"/> -->
2378
+ <!-- <xsl:variable name="colwidths" select="xalan:nodeset($colwidths_)"/> -->
2379
+
2380
+ <!-- DEBUG -->
2381
+ <xsl:if test="$table_if_debug = 'true'">
2382
+ <fo:block font-size="60%">
2383
+ <xsl:apply-templates select="xalan:nodeset($colwidths)" mode="print_as_xml"/>
2384
+ </fo:block>
2385
+ </xsl:if>
2386
+
2387
+
2388
+ <!-- <xsl:copy-of select="$colwidths"/> -->
2389
+
2390
+ <!-- <xsl:text disable-output-escaping="yes">&lt;!- -</xsl:text>
2391
+ DEBUG
2392
+ colwidths=<xsl:copy-of select="$colwidths"/>
2393
+ <xsl:text disable-output-escaping="yes">- -&gt;</xsl:text> -->
2394
+
2333
2395
 
2334
2396
 
2335
2397
  <xsl:variable name="margin-side">
@@ -2395,9 +2457,17 @@
2395
2457
  </xsl:element>
2396
2458
  </xsl:variable>
2397
2459
 
2460
+ <xsl:if test="$isGenerateTableIF = 'true'">
2461
+ <!-- to determine start of table -->
2462
+ <fo:block id="{concat('table_if_start_',@id)}" keep-with-next="always" font-size="1pt">Start table '<xsl:value-of select="@id"/>'.</fo:block>
2463
+ </xsl:if>
2398
2464
 
2399
2465
  <fo:table id="{@id}">
2400
2466
 
2467
+ <xsl:if test="$isGenerateTableIF = 'true'">
2468
+ <xsl:attribute name="wrap-option">no-wrap</xsl:attribute>
2469
+ </xsl:if>
2470
+
2401
2471
  <xsl:for-each select="xalan:nodeset($table_attributes)/table_attributes/@*">
2402
2472
  <xsl:attribute name="{local-name()}">
2403
2473
  <xsl:value-of select="."/>
@@ -2411,24 +2481,47 @@
2411
2481
 
2412
2482
 
2413
2483
  <xsl:choose>
2414
- <xsl:when test="*[local-name()='colgroup']/*[local-name()='col']">
2415
- <xsl:for-each select="*[local-name()='colgroup']/*[local-name()='col']">
2416
- <fo:table-column column-width="{@width}"/>
2417
- </xsl:for-each>
2484
+ <xsl:when test="$isGenerateTableIF = 'true'">
2485
+ <!-- generate IF for table widths -->
2486
+ <!-- example:
2487
+ <tr>
2488
+ <td valign="top" align="left" id="tab-symdu_1_1">
2489
+ <p>Symbol</p>
2490
+ <word id="tab-symdu_1_1_word_1">Symbol</word>
2491
+ </td>
2492
+ <td valign="top" align="left" id="tab-symdu_1_2">
2493
+ <p>Description</p>
2494
+ <word id="tab-symdu_1_2_word_1">Description</word>
2495
+ </td>
2496
+ </tr>
2497
+ -->
2498
+ <xsl:apply-templates select="xalan:nodeset($simple-table)" mode="process_table-if"/>
2499
+
2418
2500
  </xsl:when>
2419
2501
  <xsl:otherwise>
2420
- <xsl:call-template name="insertTableColumnWidth">
2421
- <xsl:with-param name="colwidths" select="$colwidths"/>
2422
- </xsl:call-template>
2423
- </xsl:otherwise>
2424
- </xsl:choose>
2425
2502
 
2426
- <xsl:choose>
2427
- <xsl:when test="not(*[local-name()='tbody']) and *[local-name()='thead']">
2428
- <xsl:apply-templates select="*[local-name()='thead']" mode="process_tbody"/>
2429
- </xsl:when>
2430
- <xsl:otherwise>
2431
- <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 -->
2503
+ <xsl:choose>
2504
+ <xsl:when test="*[local-name()='colgroup']/*[local-name()='col']">
2505
+ <xsl:for-each select="*[local-name()='colgroup']/*[local-name()='col']">
2506
+ <fo:table-column column-width="{@width}"/>
2507
+ </xsl:for-each>
2508
+ </xsl:when>
2509
+ <xsl:otherwise>
2510
+ <xsl:call-template name="insertTableColumnWidth">
2511
+ <xsl:with-param name="colwidths" select="$colwidths"/>
2512
+ </xsl:call-template>
2513
+ </xsl:otherwise>
2514
+ </xsl:choose>
2515
+
2516
+ <xsl:choose>
2517
+ <xsl:when test="not(*[local-name()='tbody']) and *[local-name()='thead']">
2518
+ <xsl:apply-templates select="*[local-name()='thead']" mode="process_tbody"/>
2519
+ </xsl:when>
2520
+ <xsl:otherwise>
2521
+ <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 -->
2522
+ </xsl:otherwise>
2523
+ </xsl:choose>
2524
+
2432
2525
  </xsl:otherwise>
2433
2526
  </xsl:choose>
2434
2527
 
@@ -2530,11 +2623,22 @@
2530
2623
  <xsl:variable name="columns-with-colspan" select="count($table-row/*[@colspan])"/>
2531
2624
  <xsl:value-of select="$columns-count + $sum-colspans - $columns-with-colspan"/>
2532
2625
  </xsl:template><xsl:template name="calculate-column-widths">
2626
+ <xsl:param name="table"/>
2627
+ <xsl:param name="cols-count"/>
2628
+
2629
+ <xsl:call-template name="calculate-column-widths-proportional">
2630
+ <xsl:with-param name="cols-count" select="$cols-count"/>
2631
+ <xsl:with-param name="table" select="$table"/>
2632
+ </xsl:call-template>
2633
+
2634
+ </xsl:template><xsl:template name="calculate-column-widths-proportional">
2533
2635
  <xsl:param name="table"/>
2534
2636
  <xsl:param name="cols-count"/>
2535
2637
  <xsl:param name="curr-col" select="1"/>
2536
2638
  <xsl:param name="width" select="0"/>
2537
2639
 
2640
+ <!-- table=<xsl:copy-of select="$table"/> -->
2641
+
2538
2642
  <xsl:if test="$curr-col &lt;= $cols-count">
2539
2643
  <xsl:variable name="widths">
2540
2644
  <xsl:choose>
@@ -2572,10 +2676,15 @@
2572
2676
  </xsl:for-each>
2573
2677
  </xsl:when>
2574
2678
  <xsl:otherwise>
2575
- <xsl:for-each select="xalan:nodeset($table)/*/tr">
2679
+ <!-- <curr_col><xsl:value-of select="$curr-col"/></curr_col> -->
2680
+
2681
+ <!-- <table><xsl:copy-of select="$table"/></table>
2682
+ -->
2683
+ <xsl:for-each select="xalan:nodeset($table)/*/*[local-name()='tr']">
2576
2684
  <xsl:variable name="td_text">
2577
2685
  <xsl:apply-templates select="td[$curr-col]" mode="td_text"/>
2578
2686
  </xsl:variable>
2687
+ <!-- <td_text><xsl:value-of select="$td_text"/></td_text> -->
2579
2688
  <xsl:variable name="words">
2580
2689
  <xsl:variable name="string_with_added_zerospaces">
2581
2690
  <xsl:call-template name="add-zero-spaces-java">
@@ -2590,6 +2699,7 @@
2590
2699
  <xsl:with-param name="text" select="normalize-space(translate($string_with_added_zerospaces, '​­', ' '))"/> <!-- replace zero-width-space and soft-hyphen to space -->
2591
2700
  </xsl:call-template>
2592
2701
  </xsl:variable>
2702
+ <!-- words=<xsl:copy-of select="$words"/> -->
2593
2703
  <xsl:variable name="max_length">
2594
2704
  <xsl:call-template name="max_length">
2595
2705
  <xsl:with-param name="words" select="xalan:nodeset($words)"/>
@@ -2614,6 +2724,8 @@
2614
2724
  </xsl:choose>
2615
2725
  </xsl:variable>
2616
2726
 
2727
+ <!-- widths=<xsl:copy-of select="$widths"/> -->
2728
+
2617
2729
  <column>
2618
2730
  <xsl:for-each select="xalan:nodeset($widths)//width">
2619
2731
  <xsl:sort select="." data-type="number" order="descending"/>
@@ -2622,33 +2734,327 @@
2622
2734
  </xsl:if>
2623
2735
  </xsl:for-each>
2624
2736
  </column>
2625
- <xsl:call-template name="calculate-column-widths">
2737
+ <xsl:call-template name="calculate-column-widths-proportional">
2626
2738
  <xsl:with-param name="cols-count" select="$cols-count"/>
2627
2739
  <xsl:with-param name="curr-col" select="$curr-col +1"/>
2628
2740
  <xsl:with-param name="table" select="$table"/>
2629
2741
  </xsl:call-template>
2630
2742
  </xsl:if>
2631
- </xsl:template><xsl:template match="*[@keep-together.within-line]/text()" priority="2" mode="td_text">
2743
+ </xsl:template><xsl:template match="*[@keep-together.within-line or local-name() = 'keep-together_within-line']/text()" priority="2" mode="td_text">
2632
2744
  <!-- <xsl:message>DEBUG t1=<xsl:value-of select="."/></xsl:message>
2633
2745
  <xsl:message>DEBUG t2=<xsl:value-of select="java:replaceAll(java:java.lang.String.new(.),'.','X')"/></xsl:message> -->
2634
2746
  <xsl:value-of select="java:replaceAll(java:java.lang.String.new(.),'.','X')"/>
2747
+
2748
+ <!-- if all capitals english letters or digits -->
2749
+ <xsl:if test="normalize-space(translate(., concat($upper,'0123456789'), '')) = ''">
2750
+ <xsl:call-template name="repeat">
2751
+ <xsl:with-param name="char" select="'X'"/>
2752
+ <xsl:with-param name="count" select="string-length(normalize-space(.)) * 0.5"/>
2753
+ </xsl:call-template>
2754
+ </xsl:if>
2635
2755
  </xsl:template><xsl:template match="text()" mode="td_text">
2636
2756
  <xsl:value-of select="translate(., $zero_width_space, ' ')"/><xsl:text> </xsl:text>
2637
2757
  </xsl:template><xsl:template match="*[local-name()='termsource']" mode="td_text">
2638
2758
  <xsl:value-of select="*[local-name()='origin']/@citeas"/>
2639
2759
  </xsl:template><xsl:template match="*[local-name()='link']" mode="td_text">
2640
2760
  <xsl:value-of select="@target"/>
2641
- </xsl:template><xsl:template match="*[local-name()='math']" mode="td_text">
2642
- <xsl:variable name="mathml">
2643
- <xsl:for-each select="*">
2644
- <xsl:if test="local-name() != 'unit' and local-name() != 'prefix' and local-name() != 'dimension' and local-name() != 'quantity'">
2645
- <xsl:copy-of select="."/>
2761
+ </xsl:template><xsl:template match="*[local-name()='math']" mode="td_text" name="math_length">
2762
+ <xsl:if test="$isGenerateTableIF = 'false'">
2763
+ <xsl:variable name="mathml_">
2764
+ <xsl:for-each select="*">
2765
+ <xsl:if test="local-name() != 'unit' and local-name() != 'prefix' and local-name() != 'dimension' and local-name() != 'quantity'">
2766
+ <xsl:copy-of select="."/>
2767
+ </xsl:if>
2768
+ </xsl:for-each>
2769
+ </xsl:variable>
2770
+ <xsl:variable name="mathml" select="xalan:nodeset($mathml_)"/>
2771
+
2772
+ <xsl:variable name="math_text">
2773
+ <xsl:value-of select="normalize-space($mathml)"/>
2774
+ <xsl:for-each select="$mathml//@open"><xsl:value-of select="."/></xsl:for-each>
2775
+ <xsl:for-each select="$mathml//@close"><xsl:value-of select="."/></xsl:for-each>
2776
+ </xsl:variable>
2777
+ <xsl:value-of select="translate($math_text, ' ', '#')"/><!-- mathml images as one 'word' without spaces -->
2778
+ </xsl:if>
2779
+ </xsl:template><xsl:template name="calculate-column-widths-autolayout-algorithm">
2780
+ <xsl:param name="table"/>
2781
+ <xsl:param name="if">false</xsl:param> <!-- via intermediate format -->
2782
+
2783
+ <!-- The algorithm uses two passes through the table data and scales linearly with the size of the table -->
2784
+
2785
+ <!-- In the first pass, line wrapping is disabled, and the user agent keeps track of the minimum and maximum width of each cell. -->
2786
+
2787
+ <!-- Since line wrap has been disabled, paragraphs are treated as long lines unless broken by BR elements. -->
2788
+
2789
+ <!-- get current table id -->
2790
+ <xsl:variable name="table_id" select="@id"/>
2791
+ <!-- find table by id in the file 'table_widths' -->
2792
+ <xsl:variable name="table-if_" select="$table_widths_from_if//table[@id = $table_id]"/>
2793
+ <xsl:variable name="table-if" select="xalan:nodeset($table-if_)"/>
2794
+
2795
+
2796
+ <!-- table='<xsl:copy-of select="$table"/>' -->
2797
+ <!-- table_id='<xsl:value-of select="$table_id"/>\ -->
2798
+ <!-- table-if='<xsl:copy-of select="$table-if"/>' -->
2799
+ <!-- table_widths_from_if='<xsl:copy-of select="$table_widths_from_if"/>' -->
2800
+
2801
+ <xsl:variable name="table_with_cell_widths_">
2802
+ <xsl:choose>
2803
+ <xsl:when test="$if = 'true' and normalize-space($table-if) != ''"> <!-- if we read column's width from IF and there is table in IF -->
2804
+
2805
+ <!-- Example: <column>10</column>
2806
+ <column>11</column>
2807
+ -->
2808
+ <xsl:apply-templates select="$table-if" mode="determine_cell_widths-if"/>
2809
+ </xsl:when>
2810
+ <xsl:otherwise>
2811
+ <xsl:apply-templates select="xalan:nodeset($table)" mode="determine_cell_widths"/>
2812
+ </xsl:otherwise>
2813
+ </xsl:choose>
2814
+ </xsl:variable>
2815
+ <xsl:variable name="table_with_cell_widths" select="xalan:nodeset($table_with_cell_widths_)"/>
2816
+
2817
+ <xsl:if test="$table_if_debug = 'true'">
2818
+ <xsl:copy-of select="$table_with_cell_widths"/>
2819
+ </xsl:if>
2820
+
2821
+
2822
+ <!-- The minimum and maximum cell widths are then used to determine the corresponding minimum and maximum widths for the columns. -->
2823
+
2824
+ <xsl:variable name="column_widths_">
2825
+ <!-- iteration of columns -->
2826
+ <xsl:for-each select="$table_with_cell_widths//tr[1]/td">
2827
+ <xsl:variable name="pos" select="position()"/>
2828
+ <column>
2829
+ <xsl:attribute name="width_max">
2830
+ <xsl:for-each select="ancestor::tbody//tr/td[$pos]/@width_max">
2831
+ <xsl:sort select="." data-type="number" order="descending"/>
2832
+ <xsl:if test="position() = 1"><xsl:value-of select="."/></xsl:if>
2833
+ </xsl:for-each>
2834
+ </xsl:attribute>
2835
+ <xsl:attribute name="width_min">
2836
+ <xsl:for-each select="ancestor::tbody//tr/td[$pos]/@width_min">
2837
+ <xsl:sort select="." data-type="number" order="descending"/>
2838
+ <xsl:if test="position() = 1"><xsl:value-of select="."/></xsl:if>
2839
+ </xsl:for-each>
2840
+ </xsl:attribute>
2841
+ </column>
2842
+ </xsl:for-each>
2843
+ </xsl:variable>
2844
+ <xsl:variable name="column_widths" select="xalan:nodeset($column_widths_)"/>
2845
+
2846
+ <!-- <column_widths>
2847
+ <xsl:copy-of select="$column_widths"/>
2848
+ </column_widths> -->
2849
+
2850
+ <!-- These in turn, are used to find the minimum and maximum width for the table. -->
2851
+ <xsl:variable name="table_widths_">
2852
+ <table>
2853
+ <xsl:attribute name="width_max">
2854
+ <xsl:value-of select="sum($column_widths/column/@width_max)"/>
2855
+ </xsl:attribute>
2856
+ <xsl:attribute name="width_min">
2857
+ <xsl:value-of select="sum($column_widths/column/@width_min)"/>
2858
+ </xsl:attribute>
2859
+ </table>
2860
+ </xsl:variable>
2861
+ <xsl:variable name="table_widths" select="xalan:nodeset($table_widths_)"/>
2862
+
2863
+ <xsl:variable name="page_width">
2864
+ <xsl:choose>
2865
+ <xsl:when test="$if = 'true'"><xsl:value-of select="$table-if/@page-width"/></xsl:when>
2866
+ <xsl:otherwise>75</xsl:otherwise>
2867
+ </xsl:choose>
2868
+ </xsl:variable>
2869
+
2870
+ <xsl:if test="$table_if_debug = 'true'">
2871
+ <table_width>
2872
+ <xsl:copy-of select="$table_widths"/>
2873
+ </table_width>
2874
+ <!-- <debug>$table_widths/@width_min=<xsl:value-of select="$table_widths/table/@width_min"/></debug>
2875
+ <debug>$table_widths/@width_max=<xsl:value-of select="$table_widths/table/@width_max"/></debug>
2876
+ -->
2877
+ <debug>$page_width=<xsl:value-of select="$page_width"/></debug>
2878
+ </xsl:if>
2879
+
2880
+
2881
+ <!-- There are three cases: -->
2882
+ <xsl:choose>
2883
+ <!-- 1. The minimum table width is equal to or wider than the available space -->
2884
+ <xsl:when test="$table_widths/table/@width_min &gt;= $page_width and 1 = 2"> <!-- this condition isn't working see case 3 below -->
2885
+ <!-- call old algorithm -->
2886
+ <case1/>
2887
+ <xsl:variable name="cols-count" select="count(xalan:nodeset($table)/*/tr[1]/td)"/>
2888
+ <xsl:call-template name="calculate-column-widths-proportional">
2889
+ <xsl:with-param name="cols-count" select="$cols-count"/>
2890
+ <xsl:with-param name="table" select="$table"/>
2891
+ </xsl:call-template>
2892
+ </xsl:when>
2893
+ <!-- 2. The maximum table width fits within the available space. In this case, set the columns to their maximum widths. -->
2894
+ <xsl:when test="$table_widths/table/@width_max &lt;= $page_width">
2895
+ <case2/>
2896
+ <autolayout/>
2897
+ <xsl:for-each select="$column_widths/column/@width_max">
2898
+ <column divider="100"><xsl:value-of select="."/></column>
2899
+ </xsl:for-each>
2900
+ </xsl:when>
2901
+ <!-- 3. The maximum width of the table is greater than the available space, but the minimum table width is smaller.
2902
+ In this case, find the difference between the available space and the minimum table width, lets call it W.
2903
+ Lets also call D the difference between maximum and minimum width of the table.
2904
+ For each column, let d be the difference between maximum and minimum width of that column.
2905
+ Now set the column's width to the minimum width plus d times W over D.
2906
+ This makes columns with large differences between minimum and maximum widths wider than columns with smaller differences. -->
2907
+ <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)">
2908
+ <!-- difference between the available space and the minimum table width -->
2909
+ <xsl:variable name="W" select="$page_width - $table_widths/table/@width_min"/>
2910
+ <W><xsl:value-of select="$W"/></W>
2911
+ <!-- difference between maximum and minimum width of the table -->
2912
+ <xsl:variable name="D" select="$table_widths/table/@width_max - $table_widths/table/@width_min"/>
2913
+ <D><xsl:value-of select="$D"/></D>
2914
+ <case3/>
2915
+ <autolayout/>
2916
+ <xsl:if test="$table_widths/table/@width_min &gt;= $page_width">
2917
+ <split_keep-within-line>true</split_keep-within-line>
2646
2918
  </xsl:if>
2919
+ <xsl:for-each select="$column_widths/column">
2920
+ <!-- difference between maximum and minimum width of that column. -->
2921
+ <xsl:variable name="d" select="@width_max - @width_min"/>
2922
+ <d><xsl:value-of select="$d"/></d>
2923
+ <width_min><xsl:value-of select="@width_min"/></width_min>
2924
+ <e><xsl:value-of select="$d * $W div $D"/></e>
2925
+ <!-- set the column's width to the minimum width plus d times W over D. -->
2926
+ <column divider="100">
2927
+ <xsl:value-of select="round(@width_min + $d * $W div $D)"/> <!-- * 10 -->
2928
+ </column>
2929
+ </xsl:for-each>
2930
+
2931
+ </xsl:when>
2932
+ <xsl:otherwise><unknown_case/></xsl:otherwise>
2933
+ </xsl:choose>
2934
+
2935
+
2936
+ </xsl:template><xsl:template match="@*|node()" mode="determine_cell_widths">
2937
+ <xsl:copy>
2938
+ <xsl:apply-templates select="@*|node()" mode="determine_cell_widths"/>
2939
+ </xsl:copy>
2940
+ </xsl:template><xsl:template match="td | th" mode="determine_cell_widths">
2941
+ <xsl:copy>
2942
+ <xsl:copy-of select="@*"/>
2943
+
2944
+ <!-- The maximum width is given by the widest line. -->
2945
+ <xsl:variable name="widths_max">
2946
+ <xsl:for-each select=".//*[local-name() = 'p']">
2947
+ <xsl:call-template name="add_width"/>
2948
+ </xsl:for-each>
2949
+ <xsl:if test="not(*[local-name() = 'p'])">
2950
+ <xsl:call-template name="add_width"/>
2951
+ </xsl:if>
2952
+ </xsl:variable>
2953
+ <xsl:variable name="width_max">
2954
+ <xsl:for-each select="xalan:nodeset($widths_max)//width">
2955
+ <xsl:sort select="." data-type="number" order="descending"/>
2956
+ <xsl:if test="position() = 1"><xsl:value-of select="."/></xsl:if>
2957
+ </xsl:for-each>
2958
+ </xsl:variable>
2959
+ <xsl:attribute name="width_max">
2960
+ <xsl:value-of select="$width_max"/>
2961
+ </xsl:attribute>
2962
+
2963
+ <!-- The minimum width is given by the widest text element (word, image, etc.) -->
2964
+ <!-- To do: image width -->
2965
+ <xsl:variable name="td_text">
2966
+ <xsl:apply-templates select="." mode="td_text"/>
2967
+ </xsl:variable>
2968
+ <xsl:variable name="words">
2969
+ <xsl:variable name="string_with_added_zerospaces">
2970
+ <xsl:call-template name="add-zero-spaces-java">
2971
+ <xsl:with-param name="text" select="$td_text"/>
2972
+ </xsl:call-template>
2973
+ </xsl:variable>
2974
+ <xsl:call-template name="tokenize">
2975
+ <xsl:with-param name="text" select="normalize-space(translate($string_with_added_zerospaces, '​­', ' '))"/> <!-- replace zero-width-space and soft-hyphen to space -->
2976
+ </xsl:call-template>
2977
+ </xsl:variable>
2978
+
2979
+ <xsl:variable name="max_word_length">
2980
+ <xsl:call-template name="max_length">
2981
+ <xsl:with-param name="words" select="xalan:nodeset($words)"/>
2982
+ </xsl:call-template>
2983
+ </xsl:variable>
2984
+ <xsl:variable name="width_min">
2985
+ <xsl:value-of select="$max_word_length"/>
2986
+ </xsl:variable>
2987
+ <xsl:attribute name="width_min">
2988
+ <xsl:value-of select="$width_min"/>
2989
+ </xsl:attribute>
2990
+ <!-- width_max="1" width_min="1.5"> --> <!-- see 'tokenize' template, multiply 1.5 for all latin capitals -->
2991
+ <xsl:if test="$width_min &gt; $width_max">
2992
+ <xsl:attribute name="width_max">
2993
+ <xsl:value-of select="$width_min"/>
2994
+ </xsl:attribute>
2995
+ </xsl:if>
2996
+ <xsl:if test="$width_min = 0">
2997
+ <xsl:attribute name="width_min">1</xsl:attribute>
2998
+ </xsl:if>
2999
+
3000
+ <xsl:apply-templates select="node()" mode="determine_cell_widths"/>
3001
+
3002
+ </xsl:copy>
3003
+ </xsl:template><xsl:template name="add_width">
3004
+ <xsl:variable name="p_text"><xsl:apply-templates select="." mode="td_text"/></xsl:variable>
3005
+ <xsl:variable name="p_text_len_" select="string-length(normalize-space($p_text))"/>
3006
+
3007
+ <xsl:variable name="p_text_len">
3008
+ <xsl:choose>
3009
+ <xsl:when test="normalize-space(translate($p_text, concat($upper,'0123456789'), '')) = ''"> <!-- english word in CAPITAL letters -->
3010
+ <xsl:value-of select="$p_text_len_ * 1.5"/>
3011
+ </xsl:when>
3012
+ <xsl:otherwise><xsl:value-of select="$p_text_len_"/></xsl:otherwise>
3013
+ </xsl:choose>
3014
+ </xsl:variable>
3015
+
3016
+ <xsl:variable name="math_addon_text">
3017
+ <xsl:for-each select=".//*[local-name() = 'math']">
3018
+ <xsl:apply-templates mode="td_text"/>
2647
3019
  </xsl:for-each>
2648
3020
  </xsl:variable>
3021
+ <xsl:variable name="math_addon_length" select="string-length(normalize-space($math_addon_text)) * 0.2"/> <!-- plus 20% -->
2649
3022
 
2650
- <xsl:variable name="math_text" select="normalize-space(xalan:nodeset($mathml))"/>
2651
- <xsl:value-of select="translate($math_text, ' ', '#')"/><!-- mathml images as one 'word' without spaces -->
3023
+ <width><xsl:value-of select="$p_text_len + $math_addon_length"/></width>
3024
+ </xsl:template><xsl:template match="@*|node()" mode="determine_cell_widths-if">
3025
+ <xsl:copy>
3026
+ <xsl:apply-templates select="@*|node()" mode="determine_cell_widths-if"/>
3027
+ </xsl:copy>
3028
+ </xsl:template><xsl:template match="td | th" mode="determine_cell_widths-if">
3029
+ <xsl:copy>
3030
+ <xsl:copy-of select="@*"/>
3031
+
3032
+ <!-- The maximum width is given by the widest line. -->
3033
+ <xsl:attribute name="width_max">
3034
+ <xsl:for-each select="p_len">
3035
+ <xsl:sort select="." data-type="number" order="descending"/>
3036
+ <xsl:if test="position() = 1"><xsl:value-of select="."/></xsl:if>
3037
+ </xsl:for-each>
3038
+ </xsl:attribute>
3039
+
3040
+ <!-- The minimum width is given by the widest text element (word, image, etc.) -->
3041
+ <xsl:variable name="width_min">
3042
+ <xsl:for-each select="word_len">
3043
+ <xsl:sort select="." data-type="number" order="descending"/>
3044
+ <xsl:if test="position() = 1"><xsl:value-of select="."/></xsl:if>
3045
+ </xsl:for-each>
3046
+ </xsl:variable>
3047
+ <xsl:attribute name="width_min">
3048
+ <xsl:value-of select="$width_min"/>
3049
+ </xsl:attribute>
3050
+
3051
+ <xsl:if test="$width_min = 0">
3052
+ <xsl:attribute name="width_min">1</xsl:attribute>
3053
+ </xsl:if>
3054
+
3055
+ <xsl:apply-templates select="node()" mode="determine_cell_widths-if"/>
3056
+
3057
+ </xsl:copy>
2652
3058
  </xsl:template><xsl:template match="*[local-name()='thead']">
2653
3059
  <xsl:param name="cols-count"/>
2654
3060
  <fo:table-header>
@@ -2733,6 +3139,7 @@
2733
3139
  </xsl:for-each>
2734
3140
  </xsl:when>
2735
3141
  <xsl:otherwise>
3142
+ <!-- $colwidths=<xsl:copy-of select="$colwidths"/> -->
2736
3143
  <xsl:call-template name="insertTableColumnWidth">
2737
3144
  <xsl:with-param name="colwidths" select="$colwidths"/>
2738
3145
  </xsl:call-template>
@@ -2812,6 +3219,52 @@
2812
3219
 
2813
3220
  </fo:table-body>
2814
3221
 
3222
+ </xsl:template><xsl:template match="/" mode="process_table-if">
3223
+ <xsl:param name="table_or_dl">table</xsl:param>
3224
+ <xsl:apply-templates mode="process_table-if">
3225
+ <xsl:with-param name="table_or_dl" select="$table_or_dl"/>
3226
+ </xsl:apply-templates>
3227
+ </xsl:template><xsl:template match="*[local-name()='tbody']" mode="process_table-if">
3228
+ <xsl:param name="table_or_dl">table</xsl:param>
3229
+
3230
+ <fo:table-body>
3231
+ <xsl:for-each select="*[local-name() = 'tr']">
3232
+ <xsl:variable name="col_count" select="count(*)"/>
3233
+
3234
+ <!-- iteration for each tr/td -->
3235
+
3236
+ <xsl:choose>
3237
+ <xsl:when test="$table_or_dl = 'table'">
3238
+ <xsl:for-each select="*[local-name() = 'td' or local-name() = 'th']/*">
3239
+ <fo:table-row number-columns-spanned="{$col_count}">
3240
+ <!-- <test_table><xsl:copy-of select="."/></test_table> -->
3241
+ <xsl:call-template name="td"/>
3242
+ </fo:table-row>
3243
+ </xsl:for-each>
3244
+ </xsl:when>
3245
+ <xsl:otherwise> <!-- $table_or_dl = 'dl' -->
3246
+ <xsl:for-each select="*[local-name() = 'td' or local-name() = 'th']">
3247
+ <xsl:variable name="is_dt" select="position() = 1"/>
3248
+
3249
+ <xsl:for-each select="*">
3250
+ <!-- <test><xsl:copy-of select="."/></test> -->
3251
+ <fo:table-row number-columns-spanned="{$col_count}">
3252
+ <xsl:choose>
3253
+ <xsl:when test="$is_dt">
3254
+ <xsl:call-template name="insert_dt_cell"/>
3255
+ </xsl:when>
3256
+ <xsl:otherwise>
3257
+ <xsl:call-template name="insert_dd_cell"/>
3258
+ </xsl:otherwise>
3259
+ </xsl:choose>
3260
+ </fo:table-row>
3261
+ </xsl:for-each>
3262
+ </xsl:for-each>
3263
+ </xsl:otherwise>
3264
+ </xsl:choose>
3265
+
3266
+ </xsl:for-each>
3267
+ </fo:table-body>
2815
3268
  </xsl:template><xsl:template match="*[local-name()='thead']/*[local-name()='tr']" priority="2">
2816
3269
  <fo:table-row xsl:use-attribute-sets="table-header-row-style">
2817
3270
 
@@ -2898,7 +3351,7 @@
2898
3351
  </xsl:choose>
2899
3352
  </xsl:attribute>
2900
3353
  </xsl:if>
2901
- </xsl:template><xsl:template match="*[local-name()='td']">
3354
+ </xsl:template><xsl:template match="*[local-name()='td']" name="td">
2902
3355
  <fo:table-cell xsl:use-attribute-sets="table-cell-style"> <!-- text-align="{@align}" -->
2903
3356
  <xsl:call-template name="setTextAlignment">
2904
3357
  <xsl:with-param name="default">left</xsl:with-param>
@@ -2932,11 +3385,24 @@
2932
3385
 
2933
3386
  <xsl:call-template name="setTableCellAttributes"/>
2934
3387
 
3388
+ <xsl:if test="$isGenerateTableIF = 'true'">
3389
+ <xsl:attribute name="border">1pt solid black</xsl:attribute> <!-- border is mandatory, to determine page width -->
3390
+ <xsl:attribute name="text-align">left</xsl:attribute>
3391
+ </xsl:if>
3392
+
2935
3393
  <fo:block>
2936
3394
 
3395
+ <xsl:if test="$isGenerateTableIF = 'true'">
3396
+ <xsl:attribute name="id"><xsl:value-of select="@id"/></xsl:attribute>
3397
+ </xsl:if>
3398
+
3399
+
2937
3400
 
2938
3401
 
2939
3402
  <xsl:apply-templates/>
3403
+
3404
+ <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"/> -->
3405
+
2940
3406
  </fo:block>
2941
3407
  </fo:table-cell>
2942
3408
  </xsl:template><xsl:template match="*[local-name()='table']/*[local-name()='note']" priority="2">
@@ -3139,9 +3605,9 @@
3139
3605
  <!-- current hierarchy is 'figure' element -->
3140
3606
  <xsl:variable name="following_dl_colwidths">
3141
3607
  <xsl:if test="*[local-name() = 'dl']"><!-- if there is a 'dl', then set the same columns width as for 'dl' -->
3142
- <xsl:variable name="html-table">
3143
- <xsl:variable name="doc_ns">
3144
-
3608
+ <xsl:variable name="simple-table">
3609
+ <!-- <xsl:variable name="doc_ns">
3610
+ <xsl:if test="$namespace = 'bipm'">bipm</xsl:if>
3145
3611
  </xsl:variable>
3146
3612
  <xsl:variable name="ns">
3147
3613
  <xsl:choose>
@@ -3152,7 +3618,7 @@
3152
3618
  <xsl:value-of select="substring-before(name(/*), '-')"/>
3153
3619
  </xsl:otherwise>
3154
3620
  </xsl:choose>
3155
- </xsl:variable>
3621
+ </xsl:variable> -->
3156
3622
 
3157
3623
  <xsl:for-each select="*[local-name() = 'dl'][1]">
3158
3624
  <tbody>
@@ -3163,7 +3629,7 @@
3163
3629
 
3164
3630
  <xsl:call-template name="calculate-column-widths">
3165
3631
  <xsl:with-param name="cols-count" select="2"/>
3166
- <xsl:with-param name="table" select="$html-table"/>
3632
+ <xsl:with-param name="table" select="$simple-table"/>
3167
3633
  </xsl:call-template>
3168
3634
 
3169
3635
  </xsl:if>
@@ -3348,7 +3814,18 @@
3348
3814
 
3349
3815
 
3350
3816
 
3817
+
3818
+ <xsl:if test="$isGenerateTableIF = 'true'">
3819
+ <!-- to determine start of table -->
3820
+ <fo:block id="{concat('table_if_start_',@id)}" keep-with-next="always" font-size="1pt">Start table '<xsl:value-of select="@id"/>'.</fo:block>
3821
+ </xsl:if>
3822
+
3351
3823
  <fo:table width="95%" table-layout="fixed">
3824
+
3825
+ <xsl:if test="$isGenerateTableIF = 'true'">
3826
+ <xsl:attribute name="wrap-option">no-wrap</xsl:attribute>
3827
+ </xsl:if>
3828
+
3352
3829
 
3353
3830
  <xsl:choose>
3354
3831
  <xsl:when test="normalize-space($key_iso) = 'true' and $parent = 'formula'"/>
@@ -3357,52 +3834,130 @@
3357
3834
 
3358
3835
  </xsl:when>
3359
3836
  </xsl:choose>
3360
- <!-- create virtual html table for dl/[dt and dd] -->
3361
- <xsl:variable name="html-table">
3362
- <xsl:variable name="doc_ns">
3837
+
3838
+
3839
+ <xsl:choose>
3840
+ <xsl:when test="$isGenerateTableIF = 'true'">
3841
+ <!-- generate IF for table widths -->
3842
+ <!-- example:
3843
+ <tr>
3844
+ <td valign="top" align="left" id="tab-symdu_1_1">
3845
+ <p>Symbol</p>
3846
+ <word id="tab-symdu_1_1_word_1">Symbol</word>
3847
+ </td>
3848
+ <td valign="top" align="left" id="tab-symdu_1_2">
3849
+ <p>Description</p>
3850
+ <word id="tab-symdu_1_2_word_1">Description</word>
3851
+ </td>
3852
+ </tr>
3853
+ -->
3363
3854
 
3364
- </xsl:variable>
3365
- <xsl:variable name="ns">
3366
- <xsl:choose>
3367
- <xsl:when test="normalize-space($doc_ns) != ''">
3368
- <xsl:value-of select="normalize-space($doc_ns)"/>
3369
- </xsl:when>
3370
- <xsl:otherwise>
3371
- <xsl:value-of select="substring-before(name(/*), '-')"/>
3372
- </xsl:otherwise>
3373
- </xsl:choose>
3374
- </xsl:variable>
3375
- <tbody>
3376
- <xsl:apply-templates mode="dl"/>
3377
- </tbody>
3378
- </xsl:variable>
3379
- <!-- DEBUG: html-table<xsl:copy-of select="$html-table"/> -->
3380
- <xsl:variable name="colwidths">
3381
- <xsl:call-template name="calculate-column-widths">
3382
- <xsl:with-param name="cols-count" select="2"/>
3383
- <xsl:with-param name="table" select="$html-table"/>
3384
- </xsl:call-template>
3385
- </xsl:variable>
3386
- <!-- DEBUG: colwidths=<xsl:copy-of select="$colwidths"/> -->
3387
- <xsl:variable name="maxlength_dt">
3388
- <xsl:call-template name="getMaxLength_dt"/>
3389
- </xsl:variable>
3390
- <xsl:variable name="isContainsKeepTogetherTag_">
3391
- false
3392
- </xsl:variable>
3393
- <xsl:variable name="isContainsKeepTogetherTag" select="normalize-space($isContainsKeepTogetherTag_)"/>
3394
- <!-- isContainsExpressReference=<xsl:value-of select="$isContainsExpressReference"/> -->
3395
- <xsl:call-template name="setColumnWidth_dl">
3396
- <xsl:with-param name="colwidths" select="$colwidths"/>
3397
- <xsl:with-param name="maxlength_dt" select="$maxlength_dt"/>
3398
- <xsl:with-param name="isContainsKeepTogetherTag" select="$isContainsKeepTogetherTag"/>
3399
- </xsl:call-template>
3855
+ <!-- create virtual html table for dl/[dt and dd] -->
3856
+ <xsl:variable name="simple-table">
3857
+
3858
+ <xsl:variable name="dl_table">
3859
+ <tbody>
3860
+ <xsl:apply-templates mode="dl_if">
3861
+ <xsl:with-param name="id" select="@id"/>
3862
+ </xsl:apply-templates>
3863
+ </tbody>
3864
+ </xsl:variable>
3865
+
3866
+ <!-- dl_table='<xsl:copy-of select="$dl_table"/>' -->
3867
+
3868
+ <!-- Step: replace <br/> to <p>...</p> -->
3869
+ <xsl:variable name="table_without_br">
3870
+ <xsl:apply-templates select="xalan:nodeset($dl_table)" mode="table-without-br"/>
3871
+ </xsl:variable>
3872
+
3873
+ <!-- table_without_br='<xsl:copy-of select="$table_without_br"/>' -->
3874
+
3875
+ <!-- Step: add id to each cell -->
3876
+ <!-- add <word>...</word> for each word, image, math -->
3877
+ <xsl:variable name="simple-table-id">
3878
+ <xsl:apply-templates select="xalan:nodeset($table_without_br)" mode="simple-table-id">
3879
+ <xsl:with-param name="id" select="@id"/>
3880
+ </xsl:apply-templates>
3881
+ </xsl:variable>
3882
+
3883
+ <!-- simple-table-id='<xsl:copy-of select="$simple-table-id"/>' -->
3884
+
3885
+ <xsl:copy-of select="xalan:nodeset($simple-table-id)"/>
3886
+
3887
+ </xsl:variable>
3888
+
3889
+ <!-- DEBUG: simple-table<xsl:copy-of select="$simple-table"/> -->
3890
+
3891
+ <xsl:apply-templates select="xalan:nodeset($simple-table)" mode="process_table-if">
3892
+ <xsl:with-param name="table_or_dl">dl</xsl:with-param>
3893
+ </xsl:apply-templates>
3894
+
3895
+ </xsl:when>
3896
+ <xsl:otherwise>
3400
3897
 
3401
- <fo:table-body>
3402
- <xsl:apply-templates>
3403
- <xsl:with-param name="key_iso" select="normalize-space($key_iso)"/>
3404
- </xsl:apply-templates>
3405
- </fo:table-body>
3898
+ <xsl:variable name="simple-table">
3899
+
3900
+ <xsl:variable name="dl_table">
3901
+ <tbody>
3902
+ <xsl:apply-templates mode="dl">
3903
+ <xsl:with-param name="id" select="@id"/>
3904
+ </xsl:apply-templates>
3905
+ </tbody>
3906
+ </xsl:variable>
3907
+
3908
+ <xsl:copy-of select="$dl_table"/>
3909
+ </xsl:variable>
3910
+
3911
+ <xsl:variable name="colwidths">
3912
+ <xsl:call-template name="calculate-column-widths">
3913
+ <xsl:with-param name="cols-count" select="2"/>
3914
+ <xsl:with-param name="table" select="$simple-table"/>
3915
+ </xsl:call-template>
3916
+ </xsl:variable>
3917
+
3918
+ <!-- <xsl:text disable-output-escaping="yes">&lt;!- -</xsl:text>
3919
+ DEBUG
3920
+ colwidths=<xsl:copy-of select="$colwidths"/>
3921
+ <xsl:text disable-output-escaping="yes">- -&gt;</xsl:text> -->
3922
+
3923
+ <!-- colwidths=<xsl:copy-of select="$colwidths"/> -->
3924
+
3925
+ <xsl:variable name="maxlength_dt">
3926
+ <xsl:call-template name="getMaxLength_dt"/>
3927
+ </xsl:variable>
3928
+
3929
+ <xsl:variable name="isContainsKeepTogetherTag_">
3930
+ false
3931
+ </xsl:variable>
3932
+ <xsl:variable name="isContainsKeepTogetherTag" select="normalize-space($isContainsKeepTogetherTag_)"/>
3933
+ <!-- isContainsExpressReference=<xsl:value-of select="$isContainsExpressReference"/> -->
3934
+
3935
+
3936
+ <xsl:call-template name="setColumnWidth_dl">
3937
+ <xsl:with-param name="colwidths" select="$colwidths"/>
3938
+ <xsl:with-param name="maxlength_dt" select="$maxlength_dt"/>
3939
+ <xsl:with-param name="isContainsKeepTogetherTag" select="$isContainsKeepTogetherTag"/>
3940
+ </xsl:call-template>
3941
+
3942
+ <fo:table-body>
3943
+
3944
+ <!-- DEBUG -->
3945
+ <xsl:if test="$table_if_debug = 'true'">
3946
+ <fo:table-row>
3947
+ <fo:table-cell number-columns-spanned="2" font-size="60%">
3948
+ <xsl:apply-templates select="xalan:nodeset($colwidths)" mode="print_as_xml"/>
3949
+ </fo:table-cell>
3950
+ </fo:table-row>
3951
+ </xsl:if>
3952
+
3953
+ <xsl:apply-templates>
3954
+ <xsl:with-param name="key_iso" select="normalize-space($key_iso)"/>
3955
+ <xsl:with-param name="split_keep-within-line" select="xalan:nodeset($colwidths)/split_keep-within-line"/>
3956
+ </xsl:apply-templates>
3957
+
3958
+ </fo:table-body>
3959
+ </xsl:otherwise>
3960
+ </xsl:choose>
3406
3961
  </fo:table>
3407
3962
  </fo:block>
3408
3963
  </fo:block>
@@ -3413,6 +3968,9 @@
3413
3968
  <xsl:param name="colwidths"/>
3414
3969
  <xsl:param name="maxlength_dt"/>
3415
3970
  <xsl:param name="isContainsKeepTogetherTag"/>
3971
+
3972
+ <!-- <colwidths><xsl:copy-of select="$colwidths"/></colwidths> -->
3973
+
3416
3974
  <xsl:choose>
3417
3975
  <xsl:when test="ancestor::*[local-name()='dl']"><!-- second level, i.e. inlined table -->
3418
3976
  <fo:table-column column-width="50%"/>
@@ -3420,6 +3978,11 @@
3420
3978
  </xsl:when>
3421
3979
  <xsl:otherwise>
3422
3980
  <xsl:choose>
3981
+ <xsl:when test="xalan:nodeset($colwidths)/autolayout">
3982
+ <xsl:call-template name="insertTableColumnWidth">
3983
+ <xsl:with-param name="colwidths" select="$colwidths"/>
3984
+ </xsl:call-template>
3985
+ </xsl:when>
3423
3986
  <xsl:when test="$isContainsKeepTogetherTag">
3424
3987
  <xsl:call-template name="insertTableColumnWidth">
3425
3988
  <xsl:with-param name="colwidths" select="$colwidths"/>
@@ -3464,13 +4027,19 @@
3464
4027
  </xsl:choose>
3465
4028
  </xsl:template><xsl:template name="insertTableColumnWidth">
3466
4029
  <xsl:param name="colwidths"/>
4030
+
3467
4031
  <xsl:for-each select="xalan:nodeset($colwidths)//column">
3468
4032
  <xsl:choose>
3469
4033
  <xsl:when test=". = 1 or . = 0">
3470
4034
  <fo:table-column column-width="proportional-column-width(2)"/>
3471
4035
  </xsl:when>
3472
4036
  <xsl:otherwise>
3473
- <fo:table-column column-width="proportional-column-width({.})"/>
4037
+ <!-- <fo:table-column column-width="proportional-column-width({.})"/> -->
4038
+ <xsl:variable name="divider">
4039
+ <xsl:value-of select="@divider"/>
4040
+ <xsl:if test="not(@divider)">1</xsl:if>
4041
+ </xsl:variable>
4042
+ <fo:table-column column-width="proportional-column-width({round(. div $divider)})"/>
3474
4043
  </xsl:otherwise>
3475
4044
  </xsl:choose>
3476
4045
  </xsl:for-each>
@@ -3532,11 +4101,19 @@
3532
4101
  </fo:table-cell>
3533
4102
  </fo:table-row>
3534
4103
  </xsl:template><xsl:template match="*[local-name()='dt']" mode="dl">
4104
+ <xsl:param name="id"/>
4105
+ <xsl:variable name="row_number" select="count(preceding-sibling::*[local-name()='dt']) + 1"/>
3535
4106
  <tr>
3536
4107
  <td>
4108
+ <xsl:attribute name="id">
4109
+ <xsl:value-of select="concat($id,'_',$row_number,'_1')"/>
4110
+ </xsl:attribute>
3537
4111
  <xsl:apply-templates/>
3538
4112
  </td>
3539
4113
  <td>
4114
+ <xsl:attribute name="id">
4115
+ <xsl:value-of select="concat($id,'_',$row_number,'_2')"/>
4116
+ </xsl:attribute>
3540
4117
 
3541
4118
  <xsl:apply-templates select="following-sibling::*[local-name()='dd'][1]">
3542
4119
  <xsl:with-param name="process">true</xsl:with-param>
@@ -3547,50 +4124,122 @@
3547
4124
 
3548
4125
  </xsl:template><xsl:template match="*[local-name()='dt']">
3549
4126
  <xsl:param name="key_iso"/>
4127
+ <xsl:param name="split_keep-within-line"/>
3550
4128
 
3551
4129
  <fo:table-row xsl:use-attribute-sets="dt-row-style">
3552
- <fo:table-cell>
4130
+ <xsl:call-template name="insert_dt_cell">
4131
+ <xsl:with-param name="key_iso" select="$key_iso"/>
4132
+ <xsl:with-param name="split_keep-within-line" select="$split_keep-within-line"/>
4133
+ </xsl:call-template>
4134
+ <xsl:for-each select="following-sibling::*[local-name()='dd'][1]">
4135
+ <xsl:call-template name="insert_dd_cell">
4136
+ <xsl:with-param name="split_keep-within-line" select="$split_keep-within-line"/>
4137
+ </xsl:call-template>
4138
+ </xsl:for-each>
4139
+ </fo:table-row>
4140
+ </xsl:template><xsl:template name="insert_dt_cell">
4141
+ <xsl:param name="key_iso"/>
4142
+ <xsl:param name="split_keep-within-line"/>
4143
+ <fo:table-cell xsl:use-attribute-sets="dt-cell-style">
4144
+
4145
+ <xsl:if test="$isGenerateTableIF = 'true'">
4146
+ <!-- border is mandatory, to calculate real width -->
4147
+ <xsl:attribute name="border">0.1pt solid black</xsl:attribute>
4148
+ <xsl:attribute name="text-align">left</xsl:attribute>
4149
+ </xsl:if>
4150
+
4151
+
4152
+ <fo:block xsl:use-attribute-sets="dt-block-style">
4153
+ <xsl:copy-of select="@id"/>
4154
+
4155
+ <xsl:if test="normalize-space($key_iso) = 'true'">
4156
+ <xsl:attribute name="margin-top">0</xsl:attribute>
4157
+ </xsl:if>
4158
+
4159
+
4160
+
4161
+ <xsl:apply-templates>
4162
+ <xsl:with-param name="split_keep-within-line" select="$split_keep-within-line"/>
4163
+ </xsl:apply-templates>
4164
+
4165
+ <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"/> -->
4166
+
4167
+ </fo:block>
4168
+ </fo:table-cell>
4169
+ </xsl:template><xsl:template name="insert_dd_cell">
4170
+ <xsl:param name="split_keep-within-line"/>
4171
+ <fo:table-cell xsl:use-attribute-sets="dd-cell-style">
4172
+
4173
+ <xsl:if test="$isGenerateTableIF = 'true'">
4174
+ <!-- border is mandatory, to calculate real width -->
4175
+ <xsl:attribute name="border">0.1pt solid black</xsl:attribute>
4176
+ </xsl:if>
4177
+
4178
+ <fo:block>
4179
+
4180
+ <xsl:if test="$isGenerateTableIF = 'true'">
4181
+ <xsl:attribute name="id"><xsl:value-of select="@id"/></xsl:attribute>
4182
+ </xsl:if>
4183
+
3553
4184
 
3554
- <fo:block xsl:use-attribute-sets="dt-style">
3555
- <xsl:copy-of select="@id"/>
3556
-
3557
- <xsl:if test="normalize-space($key_iso) = 'true'">
3558
- <xsl:attribute name="margin-top">0</xsl:attribute>
3559
- </xsl:if>
3560
-
3561
-
3562
-
3563
- <xsl:apply-templates/>
3564
- </fo:block>
3565
- </fo:table-cell>
3566
- <fo:table-cell>
3567
- <fo:block>
3568
-
3569
4185
 
3570
- <xsl:apply-templates select="following-sibling::*[local-name()='dd'][1]">
3571
- <xsl:with-param name="process">true</xsl:with-param>
3572
- </xsl:apply-templates>
3573
- </fo:block>
3574
- </fo:table-cell>
3575
- </fo:table-row>
4186
+ <xsl:choose>
4187
+ <xsl:when test="$isGenerateTableIF = 'true'">
4188
+ <xsl:apply-templates> <!-- following-sibling::*[local-name()='dd'][1] -->
4189
+ <xsl:with-param name="process">true</xsl:with-param>
4190
+ </xsl:apply-templates>
4191
+ </xsl:when>
4192
+ <xsl:otherwise>
4193
+ <xsl:apply-templates select="."> <!-- following-sibling::*[local-name()='dd'][1] -->
4194
+ <xsl:with-param name="process">true</xsl:with-param>
4195
+ <xsl:with-param name="split_keep-within-line" select="$split_keep-within-line"/>
4196
+ </xsl:apply-templates>
4197
+ </xsl:otherwise>
4198
+
4199
+ </xsl:choose>
4200
+
4201
+ <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"/> -->
4202
+
4203
+ </fo:block>
4204
+ </fo:table-cell>
3576
4205
  </xsl:template><xsl:template match="*[local-name()='dd']" mode="dl"/><xsl:template match="*[local-name()='dd']" mode="dl_process">
3577
4206
  <xsl:apply-templates/>
3578
4207
  </xsl:template><xsl:template match="*[local-name()='dd']">
3579
4208
  <xsl:param name="process">false</xsl:param>
4209
+ <xsl:param name="split_keep-within-line"/>
3580
4210
  <xsl:if test="$process = 'true'">
3581
4211
  <xsl:apply-templates select="@language"/>
3582
- <xsl:apply-templates/>
4212
+ <xsl:apply-templates>
4213
+ <xsl:with-param name="split_keep-within-line" select="$split_keep-within-line"/>
4214
+ </xsl:apply-templates>
3583
4215
  </xsl:if>
3584
4216
  </xsl:template><xsl:template match="*[local-name()='dd']/*[local-name()='p']" mode="inline">
3585
4217
  <fo:inline><xsl:text> </xsl:text><xsl:apply-templates/></fo:inline>
3586
- </xsl:template><xsl:template match="*[local-name()='em']">
4218
+ </xsl:template><xsl:template match="*[local-name()='dt']" mode="dl_if">
4219
+ <xsl:param name="id"/>
4220
+ <xsl:variable name="row_number" select="count(preceding-sibling::*[local-name()='dt']) + 1"/>
4221
+ <tr>
4222
+ <td>
4223
+ <xsl:copy-of select="node()"/>
4224
+ </td>
4225
+ <td>
4226
+
4227
+ <xsl:copy-of select="following-sibling::*[local-name()='dd'][1]/node()"/>
4228
+
4229
+ </td>
4230
+ </tr>
4231
+
4232
+ </xsl:template><xsl:template match="*[local-name()='dd']" mode="dl_if"/><xsl:template match="*[local-name()='em']">
3587
4233
  <fo:inline font-style="italic">
3588
4234
  <xsl:apply-templates/>
3589
4235
  </fo:inline>
3590
4236
  </xsl:template><xsl:template match="*[local-name()='strong'] | *[local-name()='b']">
4237
+ <xsl:param name="split_keep-within-line"/>
3591
4238
  <fo:inline font-weight="bold">
3592
4239
 
3593
- <xsl:apply-templates/>
4240
+ <xsl:apply-templates>
4241
+ <xsl:with-param name="split_keep-within-line" select="$split_keep-within-line"/>
4242
+ </xsl:apply-templates>
3594
4243
  </fo:inline>
3595
4244
  </xsl:template><xsl:template match="*[local-name()='padding']">
3596
4245
  <fo:inline padding-right="{@value}"> </fo:inline>
@@ -3791,6 +4440,10 @@
3791
4440
  <xsl:param name="text"/>
3792
4441
  <xsl:param name="separator" select="' '"/>
3793
4442
  <xsl:choose>
4443
+
4444
+ <xsl:when test="$isGenerateTableIF = 'true' and not(contains($text, $separator))">
4445
+ <word><xsl:value-of select="normalize-space($text)"/></word>
4446
+ </xsl:when>
3794
4447
  <xsl:when test="not(contains($text, $separator))">
3795
4448
  <word>
3796
4449
  <xsl:variable name="len_str_tmp" select="string-length(normalize-space($text))"/>
@@ -3835,13 +4488,66 @@
3835
4488
  </xsl:when>
3836
4489
  <xsl:otherwise>
3837
4490
  <word>
3838
- <xsl:value-of select="string-length(normalize-space(substring-before($text, $separator)))"/>
4491
+ <xsl:variable name="word" select="normalize-space(substring-before($text, $separator))"/>
4492
+ <xsl:choose>
4493
+ <xsl:when test="$isGenerateTableIF = 'true'">
4494
+ <xsl:value-of select="$word"/>
4495
+ </xsl:when>
4496
+ <xsl:otherwise>
4497
+ <xsl:value-of select="string-length($word)"/>
4498
+ </xsl:otherwise>
4499
+ </xsl:choose>
3839
4500
  </word>
3840
4501
  <xsl:call-template name="tokenize">
3841
4502
  <xsl:with-param name="text" select="substring-after($text, $separator)"/>
3842
4503
  </xsl:call-template>
3843
4504
  </xsl:otherwise>
3844
4505
  </xsl:choose>
4506
+ </xsl:template><xsl:template name="tokenize_with_tags">
4507
+ <xsl:param name="tags"/>
4508
+ <xsl:param name="text"/>
4509
+ <xsl:param name="separator" select="' '"/>
4510
+ <xsl:choose>
4511
+
4512
+ <xsl:when test="not(contains($text, $separator))">
4513
+ <word>
4514
+ <xsl:call-template name="enclose_text_in_tags">
4515
+ <xsl:with-param name="text" select="normalize-space($text)"/>
4516
+ <xsl:with-param name="tags" select="$tags"/>
4517
+ </xsl:call-template>
4518
+ </word>
4519
+ </xsl:when>
4520
+ <xsl:otherwise>
4521
+ <word>
4522
+ <xsl:call-template name="enclose_text_in_tags">
4523
+ <xsl:with-param name="text" select="normalize-space(substring-before($text, $separator))"/>
4524
+ <xsl:with-param name="tags" select="$tags"/>
4525
+ </xsl:call-template>
4526
+ </word>
4527
+ <xsl:call-template name="tokenize_with_tags">
4528
+ <xsl:with-param name="text" select="substring-after($text, $separator)"/>
4529
+ </xsl:call-template>
4530
+ </xsl:otherwise>
4531
+ </xsl:choose>
4532
+ </xsl:template><xsl:template name="enclose_text_in_tags">
4533
+ <xsl:param name="text"/>
4534
+ <xsl:param name="tags"/>
4535
+ <xsl:param name="num">1</xsl:param> <!-- default (start) value -->
4536
+
4537
+ <xsl:variable name="tag_name" select="normalize-space(xalan:nodeset($tags)//tag[$num])"/>
4538
+
4539
+ <xsl:choose>
4540
+ <xsl:when test="$tag_name = ''"><xsl:value-of select="$text"/></xsl:when>
4541
+ <xsl:otherwise>
4542
+ <xsl:element name="{$tag_name}">
4543
+ <xsl:call-template name="enclose_text_in_tags">
4544
+ <xsl:with-param name="text" select="$text"/>
4545
+ <xsl:with-param name="tags" select="$tags"/>
4546
+ <xsl:with-param name="num" select="$num + 1"/>
4547
+ </xsl:call-template>
4548
+ </xsl:element>
4549
+ </xsl:otherwise>
4550
+ </xsl:choose>
3845
4551
  </xsl:template><xsl:template name="max_length">
3846
4552
  <xsl:param name="words"/>
3847
4553
  <xsl:for-each select="$words//word">
@@ -3942,12 +4648,19 @@
3942
4648
  </xsl:otherwise>
3943
4649
  </xsl:choose>
3944
4650
  </xsl:template><xsl:template name="getSimpleTable">
4651
+ <xsl:param name="id"/>
4652
+
3945
4653
  <xsl:variable name="simple-table">
3946
4654
 
4655
+ <!-- Step 0. replace <br/> to <p>...</p> -->
4656
+ <xsl:variable name="table_without_br">
4657
+ <xsl:apply-templates mode="table-without-br"/>
4658
+ </xsl:variable>
4659
+
3947
4660
  <!-- Step 1. colspan processing -->
3948
4661
  <xsl:variable name="simple-table-colspan">
3949
4662
  <tbody>
3950
- <xsl:apply-templates mode="simple-table-colspan"/>
4663
+ <xsl:apply-templates select="xalan:nodeset($table_without_br)" mode="simple-table-colspan"/>
3951
4664
  </tbody>
3952
4665
  </xsl:variable>
3953
4666
 
@@ -3956,10 +4669,67 @@
3956
4669
  <xsl:apply-templates select="xalan:nodeset($simple-table-colspan)" mode="simple-table-rowspan"/>
3957
4670
  </xsl:variable>
3958
4671
 
3959
- <xsl:copy-of select="xalan:nodeset($simple-table-rowspan)"/>
3960
-
4672
+ <!-- Step 3: add id to each cell -->
4673
+ <!-- add <word>...</word> for each word, image, math -->
4674
+ <xsl:variable name="simple-table-id">
4675
+ <xsl:apply-templates select="xalan:nodeset($simple-table-rowspan)" mode="simple-table-id">
4676
+ <xsl:with-param name="id" select="$id"/>
4677
+ </xsl:apply-templates>
4678
+ </xsl:variable>
4679
+
4680
+ <xsl:copy-of select="xalan:nodeset($simple-table-id)"/>
4681
+
3961
4682
  </xsl:variable>
3962
4683
  <xsl:copy-of select="$simple-table"/>
4684
+ </xsl:template><xsl:template match="@*|node()" mode="table-without-br">
4685
+ <xsl:copy>
4686
+ <xsl:apply-templates select="@*|node()" mode="table-without-br"/>
4687
+ </xsl:copy>
4688
+ </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">
4689
+ <xsl:copy>
4690
+ <xsl:copy-of select="@*"/>
4691
+ <p>
4692
+ <xsl:copy-of select="node()"/>
4693
+ </p>
4694
+ </xsl:copy>
4695
+ </xsl:template><xsl:template match="*[local-name()='th' or local-name()='td'][*[local-name()='br']]" mode="table-without-br">
4696
+ <xsl:copy>
4697
+ <xsl:copy-of select="@*"/>
4698
+ <xsl:for-each select="*[local-name()='br']">
4699
+ <xsl:variable name="current_id" select="generate-id()"/>
4700
+ <p>
4701
+ <xsl:for-each select="preceding-sibling::node()[following-sibling::*[local-name() = 'br'][1][generate-id() = $current_id]][not(local-name() = 'br')]">
4702
+ <xsl:copy-of select="."/>
4703
+ </xsl:for-each>
4704
+ </p>
4705
+ <xsl:if test="not(following-sibling::*[local-name() = 'br'])">
4706
+ <p>
4707
+ <xsl:for-each select="following-sibling::node()">
4708
+ <xsl:copy-of select="."/>
4709
+ </xsl:for-each>
4710
+ </p>
4711
+ </xsl:if>
4712
+ </xsl:for-each>
4713
+ </xsl:copy>
4714
+ </xsl:template><xsl:template match="*[local-name()='th' or local-name()='td']/*[local-name() = 'p'][*[local-name()='br']]" mode="table-without-br">
4715
+ <xsl:for-each select="*[local-name()='br']">
4716
+ <xsl:variable name="current_id" select="generate-id()"/>
4717
+ <p>
4718
+ <xsl:for-each select="preceding-sibling::node()[following-sibling::*[local-name() = 'br'][1][generate-id() = $current_id]][not(local-name() = 'br')]">
4719
+ <xsl:copy-of select="."/>
4720
+ </xsl:for-each>
4721
+ </p>
4722
+ <xsl:if test="not(following-sibling::*[local-name() = 'br'])">
4723
+ <p>
4724
+ <xsl:for-each select="following-sibling::node()">
4725
+ <xsl:copy-of select="."/>
4726
+ </xsl:for-each>
4727
+ </p>
4728
+ </xsl:if>
4729
+ </xsl:for-each>
4730
+ </xsl:template><xsl:template match="text()[not(ancestor::*[local-name() = 'sourcecode'])]" mode="table-without-br">
4731
+ <xsl:variable name="text" select="translate(.,'&#9;&#10;&#13;','')"/>
4732
+ <xsl:value-of select="java:replaceAll(java:java.lang.String.new($text),' {2,}',' ')"/>
3963
4733
  </xsl:template><xsl:template match="*[local-name()='thead'] | *[local-name()='tbody']" mode="simple-table-colspan">
3964
4734
  <xsl:apply-templates mode="simple-table-colspan"/>
3965
4735
  </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">
@@ -4049,6 +4819,126 @@
4049
4819
  <xsl:apply-templates select="following-sibling::tr[1]" mode="simple-table-rowspan">
4050
4820
  <xsl:with-param name="previousRow" select="$newRow"/>
4051
4821
  </xsl:apply-templates>
4822
+ </xsl:template><xsl:template match="/" mode="simple-table-id">
4823
+ <xsl:param name="id"/>
4824
+ <xsl:variable name="id_prefixed" select="concat('table_if_',$id)"/> <!-- table id prefixed by 'table_if_' to simple search in IF -->
4825
+ <xsl:apply-templates select="@*|node()" mode="simple-table-id">
4826
+ <xsl:with-param name="id" select="$id_prefixed"/>
4827
+ </xsl:apply-templates>
4828
+ </xsl:template><xsl:template match="@*|node()" mode="simple-table-id">
4829
+ <xsl:param name="id"/>
4830
+ <xsl:copy>
4831
+ <xsl:apply-templates select="@*|node()" mode="simple-table-id">
4832
+ <xsl:with-param name="id" select="$id"/>
4833
+ </xsl:apply-templates>
4834
+ </xsl:copy>
4835
+ </xsl:template><xsl:template match="*[local-name()='tbody']" mode="simple-table-id">
4836
+ <xsl:param name="id"/>
4837
+ <xsl:copy>
4838
+ <xsl:copy-of select="@*"/>
4839
+ <xsl:attribute name="id"><xsl:value-of select="$id"/></xsl:attribute>
4840
+ <xsl:apply-templates select="node()" mode="simple-table-id">
4841
+ <xsl:with-param name="id" select="$id"/>
4842
+ </xsl:apply-templates>
4843
+ </xsl:copy>
4844
+ </xsl:template><xsl:template match="*[local-name()='th' or local-name()='td']" mode="simple-table-id">
4845
+ <xsl:param name="id"/>
4846
+ <xsl:copy>
4847
+ <xsl:copy-of select="@*"/>
4848
+ <xsl:variable name="row_number" select="count(../preceding-sibling::*) + 1"/>
4849
+ <xsl:variable name="col_number" select="count(preceding-sibling::*) + 1"/>
4850
+ <xsl:attribute name="id">
4851
+ <xsl:value-of select="concat($id,'_',$row_number,'_',$col_number)"/>
4852
+ </xsl:attribute>
4853
+
4854
+ <xsl:for-each select="*[local-name() = 'p']">
4855
+ <xsl:copy>
4856
+ <xsl:copy-of select="@*"/>
4857
+ <xsl:variable name="p_num" select="count(preceding-sibling::*[local-name() = 'p']) + 1"/>
4858
+ <xsl:attribute name="id">
4859
+ <xsl:value-of select="concat($id,'_',$row_number,'_',$col_number,'_p_',$p_num)"/>
4860
+ </xsl:attribute>
4861
+
4862
+ <xsl:copy-of select="node()"/>
4863
+ </xsl:copy>
4864
+ </xsl:for-each>
4865
+
4866
+
4867
+ <xsl:if test="$isGenerateTableIF = 'true'"> <!-- split each paragraph to words, image, math -->
4868
+
4869
+ <xsl:variable name="td_text">
4870
+ <xsl:apply-templates select="." mode="td_text_with_formatting"/>
4871
+ </xsl:variable>
4872
+
4873
+ <!-- td_text='<xsl:copy-of select="$td_text"/>' -->
4874
+
4875
+ <xsl:variable name="words">
4876
+ <xsl:for-each select=".//*[local-name() = 'image' or local-name() = 'stem']">
4877
+ <word>
4878
+ <xsl:copy-of select="."/>
4879
+ </word>
4880
+ </xsl:for-each>
4881
+
4882
+ <xsl:for-each select="xalan:nodeset($td_text)//*[local-name() = 'word'][normalize-space() != '']">
4883
+ <xsl:copy-of select="."/>
4884
+ </xsl:for-each>
4885
+
4886
+ </xsl:variable>
4887
+
4888
+ <xsl:for-each select="xalan:nodeset($words)/word">
4889
+ <xsl:variable name="num" select="count(preceding-sibling::word) + 1"/>
4890
+ <xsl:copy>
4891
+ <xsl:attribute name="id">
4892
+ <xsl:value-of select="concat($id,'_',$row_number,'_',$col_number,'_word_',$num)"/>
4893
+ </xsl:attribute>
4894
+ <xsl:copy-of select="node()"/>
4895
+ </xsl:copy>
4896
+ </xsl:for-each>
4897
+ </xsl:if>
4898
+ </xsl:copy>
4899
+
4900
+ </xsl:template><xsl:template match="@*|node()" mode="td_text_with_formatting">
4901
+ <xsl:copy>
4902
+ <xsl:apply-templates select="@*|node()" mode="td_text_with_formatting"/>
4903
+ </xsl:copy>
4904
+ </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">
4905
+ <xsl:variable name="formatting_tags">
4906
+ <xsl:call-template name="getFormattingTags"/>
4907
+ </xsl:variable>
4908
+ <word>
4909
+ <xsl:call-template name="enclose_text_in_tags">
4910
+ <xsl:with-param name="text" select="normalize-space(.)"/>
4911
+ <xsl:with-param name="tags" select="$formatting_tags"/>
4912
+ </xsl:call-template>
4913
+ </word>
4914
+ </xsl:template><xsl:template match="*[local-name() != 'keep-together_within-line']/text()" mode="td_text_with_formatting">
4915
+
4916
+ <xsl:variable name="td_text" select="."/>
4917
+
4918
+ <xsl:variable name="string_with_added_zerospaces">
4919
+ <xsl:call-template name="add-zero-spaces-java">
4920
+ <xsl:with-param name="text" select="$td_text"/>
4921
+ </xsl:call-template>
4922
+ </xsl:variable>
4923
+
4924
+ <xsl:variable name="formatting_tags">
4925
+ <xsl:call-template name="getFormattingTags"/>
4926
+ </xsl:variable>
4927
+
4928
+ <!-- <word>text</word> -->
4929
+ <xsl:call-template name="tokenize_with_tags">
4930
+ <xsl:with-param name="tags" select="$formatting_tags"/>
4931
+ <xsl:with-param name="text" select="normalize-space(translate($string_with_added_zerospaces, '​­', ' '))"/> <!-- replace zero-width-space and soft-hyphen to space -->
4932
+ </xsl:call-template>
4933
+ </xsl:template><xsl:template name="getFormattingTags">
4934
+ <tags>
4935
+ <xsl:if test="ancestor::*[local-name() = 'strong']"><tag>strong</tag></xsl:if>
4936
+ <xsl:if test="ancestor::*[local-name() = 'em']"><tag>em</tag></xsl:if>
4937
+ <xsl:if test="ancestor::*[local-name() = 'sub']"><tag>sub</tag></xsl:if>
4938
+ <xsl:if test="ancestor::*[local-name() = 'sup']"><tag>sup</tag></xsl:if>
4939
+ <xsl:if test="ancestor::*[local-name() = 'tt']"><tag>tt</tag></xsl:if>
4940
+ <xsl:if test="ancestor::*[local-name() = 'keep-together_within-line']"><tag>keep-together_within-line</tag></xsl:if>
4941
+ </tags>
4052
4942
  </xsl:template><xsl:template name="getLang">
4053
4943
  <xsl:variable name="language_current" select="normalize-space(//*[local-name()='bibdata']//*[local-name()='language'][@current = 'true'])"/>
4054
4944
  <xsl:variable name="language">
@@ -5739,7 +6629,9 @@
5739
6629
  <!-- <xsl:attribute name="border">0.5pt solid black</xsl:attribute> -->
5740
6630
  </xsl:if>
5741
6631
  <xsl:variable name="simple-table">
5742
- <xsl:call-template name="getSimpleTable"/>
6632
+ <xsl:call-template name="getSimpleTable">
6633
+ <xsl:with-param name="id" select="@id"/>
6634
+ </xsl:call-template>
5743
6635
  </xsl:variable>
5744
6636
  <xsl:variable name="cols-count" select="count(xalan:nodeset($simple-table)//tr[1]/td)"/>
5745
6637
  <xsl:if test="$cols-count = 2 and not(ancestor::*[local-name()='table'])">
@@ -6702,7 +7594,7 @@
6702
7594
  <!-- <fo:inline id="{@id}" font-size="1pt"/> -->
6703
7595
  <fo:inline id="{@id}" font-size="1pt"><xsl:value-of select="$hair_space"/></fo:inline>
6704
7596
  <!-- we need to add zero-width space, otherwise this fo:inline is missing in IF xml -->
6705
- <xsl:if test="not(following-sibling::node()[normalize-space() != ''])"> </xsl:if>
7597
+ <xsl:if test="not(following-sibling::node()[normalize-space() != ''])"><fo:inline font-size="1pt"> </fo:inline></xsl:if>
6706
7598
  </xsl:template><xsl:template match="*[local-name() = 'errata']">
6707
7599
  <!-- <row>
6708
7600
  <date>05-07-2013</date>
@@ -8171,4 +9063,40 @@
8171
9063
  <xsl:value-of select="$value"/>
8172
9064
  </xsl:otherwise>
8173
9065
  </xsl:choose>
9066
+ </xsl:template><xsl:template match="*" mode="print_as_xml">
9067
+ <xsl:param name="level">0</xsl:param>
9068
+
9069
+ <fo:block margin-left="{2*$level}mm">
9070
+ <xsl:text>
9071
+ &lt;</xsl:text>
9072
+ <xsl:value-of select="local-name()"/>
9073
+ <xsl:for-each select="@*">
9074
+ <xsl:text> </xsl:text>
9075
+ <xsl:value-of select="local-name()"/>
9076
+ <xsl:text>="</xsl:text>
9077
+ <xsl:value-of select="."/>
9078
+ <xsl:text>"</xsl:text>
9079
+ </xsl:for-each>
9080
+ <xsl:text>&gt;</xsl:text>
9081
+
9082
+ <xsl:if test="not(*)">
9083
+ <fo:inline font-weight="bold"><xsl:value-of select="."/></fo:inline>
9084
+ <xsl:text>&lt;/</xsl:text>
9085
+ <xsl:value-of select="local-name()"/>
9086
+ <xsl:text>&gt;</xsl:text>
9087
+ </xsl:if>
9088
+ </fo:block>
9089
+
9090
+ <xsl:if test="*">
9091
+ <fo:block>
9092
+ <xsl:apply-templates mode="print_as_xml">
9093
+ <xsl:with-param name="level" select="$level + 1"/>
9094
+ </xsl:apply-templates>
9095
+ </fo:block>
9096
+ <fo:block margin-left="{2*$level}mm">
9097
+ <xsl:text>&lt;/</xsl:text>
9098
+ <xsl:value-of select="local-name()"/>
9099
+ <xsl:text>&gt;</xsl:text>
9100
+ </fo:block>
9101
+ </xsl:if>
8174
9102
  </xsl:template></xsl:stylesheet>