metanorma-iec 2.1.0 → 2.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1641,6 +1641,7 @@
1641
1641
 
1642
1642
  <xsl:template match="iec:p" name="paragraph">
1643
1643
  <xsl:param name="inline" select="'false'"/>
1644
+ <xsl:param name="split_keep-within-line"/>
1644
1645
  <xsl:variable name="previous-element" select="local-name(preceding-sibling::*[1])"/>
1645
1646
  <xsl:variable name="element-name">
1646
1647
  <xsl:choose>
@@ -1683,11 +1684,15 @@
1683
1684
  </xsl:if>
1684
1685
 
1685
1686
  <xsl:apply-templates select="@language"/>
1686
- <xsl:apply-templates/>
1687
+ <xsl:apply-templates>
1688
+ <xsl:with-param name="split_keep-within-line" select="$split_keep-within-line"/>
1689
+ </xsl:apply-templates>
1687
1690
  </xsl:element>
1688
1691
  </xsl:when>
1689
1692
  <xsl:otherwise>
1690
- <xsl:apply-templates/>
1693
+ <xsl:apply-templates>
1694
+ <xsl:with-param name="split_keep-within-line" select="$split_keep-within-line"/>
1695
+ </xsl:apply-templates>
1691
1696
  </xsl:otherwise>
1692
1697
  </xsl:choose>
1693
1698
 
@@ -1930,7 +1935,9 @@
1930
1935
  </xsl:copy>
1931
1936
  </xsl:template> -->
1932
1937
 
1933
- <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">
1938
+ <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_">
1939
+ false
1940
+ </xsl:variable><xsl:variable name="isGenerateTableIF" select="normalize-space($isGenerateTableIF_)"/><xsl:variable name="lang">
1934
1941
  <xsl:call-template name="getLang"/>
1935
1942
  </xsl:variable><xsl:variable name="pageWidth_">
1936
1943
  210
@@ -2400,6 +2407,7 @@
2400
2407
  <xsl:attribute name="font-weight">bold</xsl:attribute>
2401
2408
  <xsl:attribute name="border">solid black 1pt</xsl:attribute>
2402
2409
  <xsl:attribute name="padding-left">1mm</xsl:attribute>
2410
+ <xsl:attribute name="padding-right">1mm</xsl:attribute>
2403
2411
  <xsl:attribute name="display-align">center</xsl:attribute>
2404
2412
 
2405
2413
 
@@ -2422,6 +2430,7 @@
2422
2430
  <xsl:attribute name="display-align">center</xsl:attribute>
2423
2431
  <xsl:attribute name="border">solid black 1pt</xsl:attribute>
2424
2432
  <xsl:attribute name="padding-left">1mm</xsl:attribute>
2433
+ <xsl:attribute name="padding-right">1mm</xsl:attribute>
2425
2434
 
2426
2435
 
2427
2436
 
@@ -2525,7 +2534,8 @@
2525
2534
  </xsl:attribute-set><xsl:attribute-set name="dt-row-style">
2526
2535
 
2527
2536
 
2528
- </xsl:attribute-set><xsl:attribute-set name="dt-style">
2537
+ </xsl:attribute-set><xsl:attribute-set name="dt-cell-style">
2538
+ </xsl:attribute-set><xsl:attribute-set name="dt-block-style">
2529
2539
  <xsl:attribute name="margin-top">6pt</xsl:attribute>
2530
2540
 
2531
2541
 
@@ -2539,6 +2549,8 @@
2539
2549
 
2540
2550
 
2541
2551
 
2552
+ </xsl:attribute-set><xsl:attribute-set name="dd-cell-style">
2553
+ <xsl:attribute name="padding-left">2mm</xsl:attribute>
2542
2554
  </xsl:attribute-set><xsl:attribute-set name="appendix-style">
2543
2555
 
2544
2556
 
@@ -3395,7 +3407,38 @@
3395
3407
  </xsl:template><xsl:template match="*[local-name()='br']">
3396
3408
  <xsl:value-of select="$linebreak"/>
3397
3409
  </xsl:template><xsl:template match="*[local-name() = 'keep-together_within-line']">
3398
- <fo:inline keep-together.within-line="always"><xsl:apply-templates/></fo:inline>
3410
+ <xsl:param name="split_keep-within-line"/>
3411
+
3412
+ <!-- <fo:inline>split_keep-within-line='<xsl:value-of select="$split_keep-within-line"/>'</fo:inline> -->
3413
+ <xsl:choose>
3414
+
3415
+ <xsl:when test="normalize-space($split_keep-within-line) = 'true'">
3416
+ <xsl:variable name="sep">_</xsl:variable>
3417
+ <xsl:variable name="items">
3418
+ <xsl:call-template name="split">
3419
+ <xsl:with-param name="pText" select="."/>
3420
+ <xsl:with-param name="sep" select="$sep"/>
3421
+ <xsl:with-param name="normalize-space">false</xsl:with-param>
3422
+ <xsl:with-param name="keep_sep">true</xsl:with-param>
3423
+ </xsl:call-template>
3424
+ </xsl:variable>
3425
+ <xsl:for-each select="xalan:nodeset($items)/item">
3426
+ <xsl:choose>
3427
+ <xsl:when test=". = $sep">
3428
+ <xsl:value-of select="$sep"/><xsl:value-of select="$zero_width_space"/>
3429
+ </xsl:when>
3430
+ <xsl:otherwise>
3431
+ <fo:inline keep-together.within-line="always"><xsl:apply-templates/></fo:inline>
3432
+ </xsl:otherwise>
3433
+ </xsl:choose>
3434
+ </xsl:for-each>
3435
+ </xsl:when>
3436
+
3437
+ <xsl:otherwise>
3438
+ <fo:inline keep-together.within-line="always"><xsl:apply-templates/></fo:inline>
3439
+ </xsl:otherwise>
3440
+
3441
+ </xsl:choose>
3399
3442
  </xsl:template><xsl:template match="*[local-name()='copyright-statement']">
3400
3443
  <fo:block xsl:use-attribute-sets="copyright-statement-style">
3401
3444
  <xsl:apply-templates/>
@@ -3490,9 +3533,14 @@
3490
3533
 
3491
3534
  <xsl:variable name="table">
3492
3535
 
3493
- <xsl:variable name="simple-table">
3494
- <xsl:call-template name="getSimpleTable"/>
3536
+ <xsl:variable name="simple-table">
3537
+ <xsl:call-template name="getSimpleTable">
3538
+ <xsl:with-param name="id" select="@id"/>
3539
+ </xsl:call-template>
3495
3540
  </xsl:variable>
3541
+ <!-- <xsl:variable name="simple-table" select="xalan:nodeset($simple-table_)"/> -->
3542
+
3543
+ <!-- simple-table=<xsl:copy-of select="$simple-table"/> -->
3496
3544
 
3497
3545
 
3498
3546
  <!-- Display table's name before table as standalone block -->
@@ -3515,7 +3563,23 @@
3515
3563
  </xsl:call-template>
3516
3564
  </xsl:if>
3517
3565
  </xsl:variable>
3518
- <!-- DEBUG colwidths=<xsl:copy-of select="$colwidths"/> -->
3566
+ <!-- <xsl:variable name="colwidths" select="xalan:nodeset($colwidths_)"/> -->
3567
+
3568
+ <!-- DEBUG -->
3569
+ <xsl:if test="$table_if_debug = 'true'">
3570
+ <fo:block font-size="60%">
3571
+ <xsl:apply-templates select="xalan:nodeset($colwidths)" mode="print_as_xml"/>
3572
+ </fo:block>
3573
+ </xsl:if>
3574
+
3575
+
3576
+ <!-- <xsl:copy-of select="$colwidths"/> -->
3577
+
3578
+ <!-- <xsl:text disable-output-escaping="yes">&lt;!- -</xsl:text>
3579
+ DEBUG
3580
+ colwidths=<xsl:copy-of select="$colwidths"/>
3581
+ <xsl:text disable-output-escaping="yes">- -&gt;</xsl:text> -->
3582
+
3519
3583
 
3520
3584
 
3521
3585
  <xsl:variable name="margin-side">
@@ -3586,9 +3650,17 @@
3586
3650
  </xsl:element>
3587
3651
  </xsl:variable>
3588
3652
 
3653
+ <xsl:if test="$isGenerateTableIF = 'true'">
3654
+ <!-- to determine start of table -->
3655
+ <fo:block id="{concat('table_if_start_',@id)}" keep-with-next="always" font-size="1pt">Start table '<xsl:value-of select="@id"/>'.</fo:block>
3656
+ </xsl:if>
3589
3657
 
3590
3658
  <fo:table id="{@id}">
3591
3659
 
3660
+ <xsl:if test="$isGenerateTableIF = 'true'">
3661
+ <xsl:attribute name="wrap-option">no-wrap</xsl:attribute>
3662
+ </xsl:if>
3663
+
3592
3664
  <xsl:for-each select="xalan:nodeset($table_attributes)/table_attributes/@*">
3593
3665
  <xsl:attribute name="{local-name()}">
3594
3666
  <xsl:value-of select="."/>
@@ -3602,24 +3674,47 @@
3602
3674
 
3603
3675
 
3604
3676
  <xsl:choose>
3605
- <xsl:when test="*[local-name()='colgroup']/*[local-name()='col']">
3606
- <xsl:for-each select="*[local-name()='colgroup']/*[local-name()='col']">
3607
- <fo:table-column column-width="{@width}"/>
3608
- </xsl:for-each>
3677
+ <xsl:when test="$isGenerateTableIF = 'true'">
3678
+ <!-- generate IF for table widths -->
3679
+ <!-- example:
3680
+ <tr>
3681
+ <td valign="top" align="left" id="tab-symdu_1_1">
3682
+ <p>Symbol</p>
3683
+ <word id="tab-symdu_1_1_word_1">Symbol</word>
3684
+ </td>
3685
+ <td valign="top" align="left" id="tab-symdu_1_2">
3686
+ <p>Description</p>
3687
+ <word id="tab-symdu_1_2_word_1">Description</word>
3688
+ </td>
3689
+ </tr>
3690
+ -->
3691
+ <xsl:apply-templates select="xalan:nodeset($simple-table)" mode="process_table-if"/>
3692
+
3609
3693
  </xsl:when>
3610
3694
  <xsl:otherwise>
3611
- <xsl:call-template name="insertTableColumnWidth">
3612
- <xsl:with-param name="colwidths" select="$colwidths"/>
3613
- </xsl:call-template>
3614
- </xsl:otherwise>
3615
- </xsl:choose>
3616
3695
 
3617
- <xsl:choose>
3618
- <xsl:when test="not(*[local-name()='tbody']) and *[local-name()='thead']">
3619
- <xsl:apply-templates select="*[local-name()='thead']" mode="process_tbody"/>
3620
- </xsl:when>
3621
- <xsl:otherwise>
3622
- <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 -->
3696
+ <xsl:choose>
3697
+ <xsl:when test="*[local-name()='colgroup']/*[local-name()='col']">
3698
+ <xsl:for-each select="*[local-name()='colgroup']/*[local-name()='col']">
3699
+ <fo:table-column column-width="{@width}"/>
3700
+ </xsl:for-each>
3701
+ </xsl:when>
3702
+ <xsl:otherwise>
3703
+ <xsl:call-template name="insertTableColumnWidth">
3704
+ <xsl:with-param name="colwidths" select="$colwidths"/>
3705
+ </xsl:call-template>
3706
+ </xsl:otherwise>
3707
+ </xsl:choose>
3708
+
3709
+ <xsl:choose>
3710
+ <xsl:when test="not(*[local-name()='tbody']) and *[local-name()='thead']">
3711
+ <xsl:apply-templates select="*[local-name()='thead']" mode="process_tbody"/>
3712
+ </xsl:when>
3713
+ <xsl:otherwise>
3714
+ <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 -->
3715
+ </xsl:otherwise>
3716
+ </xsl:choose>
3717
+
3623
3718
  </xsl:otherwise>
3624
3719
  </xsl:choose>
3625
3720
 
@@ -3722,11 +3817,22 @@
3722
3817
  <xsl:variable name="columns-with-colspan" select="count($table-row/*[@colspan])"/>
3723
3818
  <xsl:value-of select="$columns-count + $sum-colspans - $columns-with-colspan"/>
3724
3819
  </xsl:template><xsl:template name="calculate-column-widths">
3820
+ <xsl:param name="table"/>
3821
+ <xsl:param name="cols-count"/>
3822
+
3823
+ <xsl:call-template name="calculate-column-widths-proportional">
3824
+ <xsl:with-param name="cols-count" select="$cols-count"/>
3825
+ <xsl:with-param name="table" select="$table"/>
3826
+ </xsl:call-template>
3827
+
3828
+ </xsl:template><xsl:template name="calculate-column-widths-proportional">
3725
3829
  <xsl:param name="table"/>
3726
3830
  <xsl:param name="cols-count"/>
3727
3831
  <xsl:param name="curr-col" select="1"/>
3728
3832
  <xsl:param name="width" select="0"/>
3729
3833
 
3834
+ <!-- table=<xsl:copy-of select="$table"/> -->
3835
+
3730
3836
  <xsl:if test="$curr-col &lt;= $cols-count">
3731
3837
  <xsl:variable name="widths">
3732
3838
  <xsl:choose>
@@ -3764,10 +3870,15 @@
3764
3870
  </xsl:for-each>
3765
3871
  </xsl:when>
3766
3872
  <xsl:otherwise>
3767
- <xsl:for-each select="xalan:nodeset($table)/*/tr">
3873
+ <!-- <curr_col><xsl:value-of select="$curr-col"/></curr_col> -->
3874
+
3875
+ <!-- <table><xsl:copy-of select="$table"/></table>
3876
+ -->
3877
+ <xsl:for-each select="xalan:nodeset($table)/*/*[local-name()='tr']">
3768
3878
  <xsl:variable name="td_text">
3769
3879
  <xsl:apply-templates select="td[$curr-col]" mode="td_text"/>
3770
3880
  </xsl:variable>
3881
+ <!-- <td_text><xsl:value-of select="$td_text"/></td_text> -->
3771
3882
  <xsl:variable name="words">
3772
3883
  <xsl:variable name="string_with_added_zerospaces">
3773
3884
  <xsl:call-template name="add-zero-spaces-java">
@@ -3782,6 +3893,7 @@
3782
3893
  <xsl:with-param name="text" select="normalize-space(translate($string_with_added_zerospaces, '​­', ' '))"/> <!-- replace zero-width-space and soft-hyphen to space -->
3783
3894
  </xsl:call-template>
3784
3895
  </xsl:variable>
3896
+ <!-- words=<xsl:copy-of select="$words"/> -->
3785
3897
  <xsl:variable name="max_length">
3786
3898
  <xsl:call-template name="max_length">
3787
3899
  <xsl:with-param name="words" select="xalan:nodeset($words)"/>
@@ -3806,6 +3918,8 @@
3806
3918
  </xsl:choose>
3807
3919
  </xsl:variable>
3808
3920
 
3921
+ <!-- widths=<xsl:copy-of select="$widths"/> -->
3922
+
3809
3923
  <column>
3810
3924
  <xsl:for-each select="xalan:nodeset($widths)//width">
3811
3925
  <xsl:sort select="." data-type="number" order="descending"/>
@@ -3814,33 +3928,327 @@
3814
3928
  </xsl:if>
3815
3929
  </xsl:for-each>
3816
3930
  </column>
3817
- <xsl:call-template name="calculate-column-widths">
3931
+ <xsl:call-template name="calculate-column-widths-proportional">
3818
3932
  <xsl:with-param name="cols-count" select="$cols-count"/>
3819
3933
  <xsl:with-param name="curr-col" select="$curr-col +1"/>
3820
3934
  <xsl:with-param name="table" select="$table"/>
3821
3935
  </xsl:call-template>
3822
3936
  </xsl:if>
3823
- </xsl:template><xsl:template match="*[@keep-together.within-line]/text()" priority="2" mode="td_text">
3937
+ </xsl:template><xsl:template match="*[@keep-together.within-line or local-name() = 'keep-together_within-line']/text()" priority="2" mode="td_text">
3824
3938
  <!-- <xsl:message>DEBUG t1=<xsl:value-of select="."/></xsl:message>
3825
3939
  <xsl:message>DEBUG t2=<xsl:value-of select="java:replaceAll(java:java.lang.String.new(.),'.','X')"/></xsl:message> -->
3826
3940
  <xsl:value-of select="java:replaceAll(java:java.lang.String.new(.),'.','X')"/>
3941
+
3942
+ <!-- if all capitals english letters or digits -->
3943
+ <xsl:if test="normalize-space(translate(., concat($upper,'0123456789'), '')) = ''">
3944
+ <xsl:call-template name="repeat">
3945
+ <xsl:with-param name="char" select="'X'"/>
3946
+ <xsl:with-param name="count" select="string-length(normalize-space(.)) * 0.5"/>
3947
+ </xsl:call-template>
3948
+ </xsl:if>
3827
3949
  </xsl:template><xsl:template match="text()" mode="td_text">
3828
3950
  <xsl:value-of select="translate(., $zero_width_space, ' ')"/><xsl:text> </xsl:text>
3829
3951
  </xsl:template><xsl:template match="*[local-name()='termsource']" mode="td_text">
3830
3952
  <xsl:value-of select="*[local-name()='origin']/@citeas"/>
3831
3953
  </xsl:template><xsl:template match="*[local-name()='link']" mode="td_text">
3832
3954
  <xsl:value-of select="@target"/>
3833
- </xsl:template><xsl:template match="*[local-name()='math']" mode="td_text">
3834
- <xsl:variable name="mathml">
3835
- <xsl:for-each select="*">
3836
- <xsl:if test="local-name() != 'unit' and local-name() != 'prefix' and local-name() != 'dimension' and local-name() != 'quantity'">
3837
- <xsl:copy-of select="."/>
3955
+ </xsl:template><xsl:template match="*[local-name()='math']" mode="td_text" name="math_length">
3956
+ <xsl:if test="$isGenerateTableIF = 'false'">
3957
+ <xsl:variable name="mathml_">
3958
+ <xsl:for-each select="*">
3959
+ <xsl:if test="local-name() != 'unit' and local-name() != 'prefix' and local-name() != 'dimension' and local-name() != 'quantity'">
3960
+ <xsl:copy-of select="."/>
3961
+ </xsl:if>
3962
+ </xsl:for-each>
3963
+ </xsl:variable>
3964
+ <xsl:variable name="mathml" select="xalan:nodeset($mathml_)"/>
3965
+
3966
+ <xsl:variable name="math_text">
3967
+ <xsl:value-of select="normalize-space($mathml)"/>
3968
+ <xsl:for-each select="$mathml//@open"><xsl:value-of select="."/></xsl:for-each>
3969
+ <xsl:for-each select="$mathml//@close"><xsl:value-of select="."/></xsl:for-each>
3970
+ </xsl:variable>
3971
+ <xsl:value-of select="translate($math_text, ' ', '#')"/><!-- mathml images as one 'word' without spaces -->
3972
+ </xsl:if>
3973
+ </xsl:template><xsl:template name="calculate-column-widths-autolayout-algorithm">
3974
+ <xsl:param name="table"/>
3975
+ <xsl:param name="if">false</xsl:param> <!-- via intermediate format -->
3976
+
3977
+ <!-- The algorithm uses two passes through the table data and scales linearly with the size of the table -->
3978
+
3979
+ <!-- In the first pass, line wrapping is disabled, and the user agent keeps track of the minimum and maximum width of each cell. -->
3980
+
3981
+ <!-- Since line wrap has been disabled, paragraphs are treated as long lines unless broken by BR elements. -->
3982
+
3983
+ <!-- get current table id -->
3984
+ <xsl:variable name="table_id" select="@id"/>
3985
+ <!-- find table by id in the file 'table_widths' -->
3986
+ <xsl:variable name="table-if_" select="$table_widths_from_if//table[@id = $table_id]"/>
3987
+ <xsl:variable name="table-if" select="xalan:nodeset($table-if_)"/>
3988
+
3989
+
3990
+ <!-- table='<xsl:copy-of select="$table"/>' -->
3991
+ <!-- table_id='<xsl:value-of select="$table_id"/>\ -->
3992
+ <!-- table-if='<xsl:copy-of select="$table-if"/>' -->
3993
+ <!-- table_widths_from_if='<xsl:copy-of select="$table_widths_from_if"/>' -->
3994
+
3995
+ <xsl:variable name="table_with_cell_widths_">
3996
+ <xsl:choose>
3997
+ <xsl:when test="$if = 'true' and normalize-space($table-if) != ''"> <!-- if we read column's width from IF and there is table in IF -->
3998
+
3999
+ <!-- Example: <column>10</column>
4000
+ <column>11</column>
4001
+ -->
4002
+ <xsl:apply-templates select="$table-if" mode="determine_cell_widths-if"/>
4003
+ </xsl:when>
4004
+ <xsl:otherwise>
4005
+ <xsl:apply-templates select="xalan:nodeset($table)" mode="determine_cell_widths"/>
4006
+ </xsl:otherwise>
4007
+ </xsl:choose>
4008
+ </xsl:variable>
4009
+ <xsl:variable name="table_with_cell_widths" select="xalan:nodeset($table_with_cell_widths_)"/>
4010
+
4011
+ <xsl:if test="$table_if_debug = 'true'">
4012
+ <xsl:copy-of select="$table_with_cell_widths"/>
4013
+ </xsl:if>
4014
+
4015
+
4016
+ <!-- The minimum and maximum cell widths are then used to determine the corresponding minimum and maximum widths for the columns. -->
4017
+
4018
+ <xsl:variable name="column_widths_">
4019
+ <!-- iteration of columns -->
4020
+ <xsl:for-each select="$table_with_cell_widths//tr[1]/td">
4021
+ <xsl:variable name="pos" select="position()"/>
4022
+ <column>
4023
+ <xsl:attribute name="width_max">
4024
+ <xsl:for-each select="ancestor::tbody//tr/td[$pos]/@width_max">
4025
+ <xsl:sort select="." data-type="number" order="descending"/>
4026
+ <xsl:if test="position() = 1"><xsl:value-of select="."/></xsl:if>
4027
+ </xsl:for-each>
4028
+ </xsl:attribute>
4029
+ <xsl:attribute name="width_min">
4030
+ <xsl:for-each select="ancestor::tbody//tr/td[$pos]/@width_min">
4031
+ <xsl:sort select="." data-type="number" order="descending"/>
4032
+ <xsl:if test="position() = 1"><xsl:value-of select="."/></xsl:if>
4033
+ </xsl:for-each>
4034
+ </xsl:attribute>
4035
+ </column>
4036
+ </xsl:for-each>
4037
+ </xsl:variable>
4038
+ <xsl:variable name="column_widths" select="xalan:nodeset($column_widths_)"/>
4039
+
4040
+ <!-- <column_widths>
4041
+ <xsl:copy-of select="$column_widths"/>
4042
+ </column_widths> -->
4043
+
4044
+ <!-- These in turn, are used to find the minimum and maximum width for the table. -->
4045
+ <xsl:variable name="table_widths_">
4046
+ <table>
4047
+ <xsl:attribute name="width_max">
4048
+ <xsl:value-of select="sum($column_widths/column/@width_max)"/>
4049
+ </xsl:attribute>
4050
+ <xsl:attribute name="width_min">
4051
+ <xsl:value-of select="sum($column_widths/column/@width_min)"/>
4052
+ </xsl:attribute>
4053
+ </table>
4054
+ </xsl:variable>
4055
+ <xsl:variable name="table_widths" select="xalan:nodeset($table_widths_)"/>
4056
+
4057
+ <xsl:variable name="page_width">
4058
+ <xsl:choose>
4059
+ <xsl:when test="$if = 'true'"><xsl:value-of select="$table-if/@page-width"/></xsl:when>
4060
+ <xsl:otherwise>75</xsl:otherwise>
4061
+ </xsl:choose>
4062
+ </xsl:variable>
4063
+
4064
+ <xsl:if test="$table_if_debug = 'true'">
4065
+ <table_width>
4066
+ <xsl:copy-of select="$table_widths"/>
4067
+ </table_width>
4068
+ <!-- <debug>$table_widths/@width_min=<xsl:value-of select="$table_widths/table/@width_min"/></debug>
4069
+ <debug>$table_widths/@width_max=<xsl:value-of select="$table_widths/table/@width_max"/></debug>
4070
+ -->
4071
+ <debug>$page_width=<xsl:value-of select="$page_width"/></debug>
4072
+ </xsl:if>
4073
+
4074
+
4075
+ <!-- There are three cases: -->
4076
+ <xsl:choose>
4077
+ <!-- 1. The minimum table width is equal to or wider than the available space -->
4078
+ <xsl:when test="$table_widths/table/@width_min &gt;= $page_width and 1 = 2"> <!-- this condition isn't working see case 3 below -->
4079
+ <!-- call old algorithm -->
4080
+ <case1/>
4081
+ <xsl:variable name="cols-count" select="count(xalan:nodeset($table)/*/tr[1]/td)"/>
4082
+ <xsl:call-template name="calculate-column-widths-proportional">
4083
+ <xsl:with-param name="cols-count" select="$cols-count"/>
4084
+ <xsl:with-param name="table" select="$table"/>
4085
+ </xsl:call-template>
4086
+ </xsl:when>
4087
+ <!-- 2. The maximum table width fits within the available space. In this case, set the columns to their maximum widths. -->
4088
+ <xsl:when test="$table_widths/table/@width_max &lt;= $page_width">
4089
+ <case2/>
4090
+ <autolayout/>
4091
+ <xsl:for-each select="$column_widths/column/@width_max">
4092
+ <column divider="100"><xsl:value-of select="."/></column>
4093
+ </xsl:for-each>
4094
+ </xsl:when>
4095
+ <!-- 3. The maximum width of the table is greater than the available space, but the minimum table width is smaller.
4096
+ In this case, find the difference between the available space and the minimum table width, lets call it W.
4097
+ Lets also call D the difference between maximum and minimum width of the table.
4098
+ For each column, let d be the difference between maximum and minimum width of that column.
4099
+ Now set the column's width to the minimum width plus d times W over D.
4100
+ This makes columns with large differences between minimum and maximum widths wider than columns with smaller differences. -->
4101
+ <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)">
4102
+ <!-- difference between the available space and the minimum table width -->
4103
+ <xsl:variable name="W" select="$page_width - $table_widths/table/@width_min"/>
4104
+ <W><xsl:value-of select="$W"/></W>
4105
+ <!-- difference between maximum and minimum width of the table -->
4106
+ <xsl:variable name="D" select="$table_widths/table/@width_max - $table_widths/table/@width_min"/>
4107
+ <D><xsl:value-of select="$D"/></D>
4108
+ <case3/>
4109
+ <autolayout/>
4110
+ <xsl:if test="$table_widths/table/@width_min &gt;= $page_width">
4111
+ <split_keep-within-line>true</split_keep-within-line>
3838
4112
  </xsl:if>
4113
+ <xsl:for-each select="$column_widths/column">
4114
+ <!-- difference between maximum and minimum width of that column. -->
4115
+ <xsl:variable name="d" select="@width_max - @width_min"/>
4116
+ <d><xsl:value-of select="$d"/></d>
4117
+ <width_min><xsl:value-of select="@width_min"/></width_min>
4118
+ <e><xsl:value-of select="$d * $W div $D"/></e>
4119
+ <!-- set the column's width to the minimum width plus d times W over D. -->
4120
+ <column divider="100">
4121
+ <xsl:value-of select="round(@width_min + $d * $W div $D)"/> <!-- * 10 -->
4122
+ </column>
4123
+ </xsl:for-each>
4124
+
4125
+ </xsl:when>
4126
+ <xsl:otherwise><unknown_case/></xsl:otherwise>
4127
+ </xsl:choose>
4128
+
4129
+
4130
+ </xsl:template><xsl:template match="@*|node()" mode="determine_cell_widths">
4131
+ <xsl:copy>
4132
+ <xsl:apply-templates select="@*|node()" mode="determine_cell_widths"/>
4133
+ </xsl:copy>
4134
+ </xsl:template><xsl:template match="td | th" mode="determine_cell_widths">
4135
+ <xsl:copy>
4136
+ <xsl:copy-of select="@*"/>
4137
+
4138
+ <!-- The maximum width is given by the widest line. -->
4139
+ <xsl:variable name="widths_max">
4140
+ <xsl:for-each select=".//*[local-name() = 'p']">
4141
+ <xsl:call-template name="add_width"/>
4142
+ </xsl:for-each>
4143
+ <xsl:if test="not(*[local-name() = 'p'])">
4144
+ <xsl:call-template name="add_width"/>
4145
+ </xsl:if>
4146
+ </xsl:variable>
4147
+ <xsl:variable name="width_max">
4148
+ <xsl:for-each select="xalan:nodeset($widths_max)//width">
4149
+ <xsl:sort select="." data-type="number" order="descending"/>
4150
+ <xsl:if test="position() = 1"><xsl:value-of select="."/></xsl:if>
4151
+ </xsl:for-each>
4152
+ </xsl:variable>
4153
+ <xsl:attribute name="width_max">
4154
+ <xsl:value-of select="$width_max"/>
4155
+ </xsl:attribute>
4156
+
4157
+ <!-- The minimum width is given by the widest text element (word, image, etc.) -->
4158
+ <!-- To do: image width -->
4159
+ <xsl:variable name="td_text">
4160
+ <xsl:apply-templates select="." mode="td_text"/>
4161
+ </xsl:variable>
4162
+ <xsl:variable name="words">
4163
+ <xsl:variable name="string_with_added_zerospaces">
4164
+ <xsl:call-template name="add-zero-spaces-java">
4165
+ <xsl:with-param name="text" select="$td_text"/>
4166
+ </xsl:call-template>
4167
+ </xsl:variable>
4168
+ <xsl:call-template name="tokenize">
4169
+ <xsl:with-param name="text" select="normalize-space(translate($string_with_added_zerospaces, '​­', ' '))"/> <!-- replace zero-width-space and soft-hyphen to space -->
4170
+ </xsl:call-template>
4171
+ </xsl:variable>
4172
+
4173
+ <xsl:variable name="max_word_length">
4174
+ <xsl:call-template name="max_length">
4175
+ <xsl:with-param name="words" select="xalan:nodeset($words)"/>
4176
+ </xsl:call-template>
4177
+ </xsl:variable>
4178
+ <xsl:variable name="width_min">
4179
+ <xsl:value-of select="$max_word_length"/>
4180
+ </xsl:variable>
4181
+ <xsl:attribute name="width_min">
4182
+ <xsl:value-of select="$width_min"/>
4183
+ </xsl:attribute>
4184
+ <!-- width_max="1" width_min="1.5"> --> <!-- see 'tokenize' template, multiply 1.5 for all latin capitals -->
4185
+ <xsl:if test="$width_min &gt; $width_max">
4186
+ <xsl:attribute name="width_max">
4187
+ <xsl:value-of select="$width_min"/>
4188
+ </xsl:attribute>
4189
+ </xsl:if>
4190
+ <xsl:if test="$width_min = 0">
4191
+ <xsl:attribute name="width_min">1</xsl:attribute>
4192
+ </xsl:if>
4193
+
4194
+ <xsl:apply-templates select="node()" mode="determine_cell_widths"/>
4195
+
4196
+ </xsl:copy>
4197
+ </xsl:template><xsl:template name="add_width">
4198
+ <xsl:variable name="p_text"><xsl:apply-templates select="." mode="td_text"/></xsl:variable>
4199
+ <xsl:variable name="p_text_len_" select="string-length(normalize-space($p_text))"/>
4200
+
4201
+ <xsl:variable name="p_text_len">
4202
+ <xsl:choose>
4203
+ <xsl:when test="normalize-space(translate($p_text, concat($upper,'0123456789'), '')) = ''"> <!-- english word in CAPITAL letters -->
4204
+ <xsl:value-of select="$p_text_len_ * 1.5"/>
4205
+ </xsl:when>
4206
+ <xsl:otherwise><xsl:value-of select="$p_text_len_"/></xsl:otherwise>
4207
+ </xsl:choose>
4208
+ </xsl:variable>
4209
+
4210
+ <xsl:variable name="math_addon_text">
4211
+ <xsl:for-each select=".//*[local-name() = 'math']">
4212
+ <xsl:apply-templates mode="td_text"/>
3839
4213
  </xsl:for-each>
3840
4214
  </xsl:variable>
4215
+ <xsl:variable name="math_addon_length" select="string-length(normalize-space($math_addon_text)) * 0.2"/> <!-- plus 20% -->
3841
4216
 
3842
- <xsl:variable name="math_text" select="normalize-space(xalan:nodeset($mathml))"/>
3843
- <xsl:value-of select="translate($math_text, ' ', '#')"/><!-- mathml images as one 'word' without spaces -->
4217
+ <width><xsl:value-of select="$p_text_len + $math_addon_length"/></width>
4218
+ </xsl:template><xsl:template match="@*|node()" mode="determine_cell_widths-if">
4219
+ <xsl:copy>
4220
+ <xsl:apply-templates select="@*|node()" mode="determine_cell_widths-if"/>
4221
+ </xsl:copy>
4222
+ </xsl:template><xsl:template match="td | th" mode="determine_cell_widths-if">
4223
+ <xsl:copy>
4224
+ <xsl:copy-of select="@*"/>
4225
+
4226
+ <!-- The maximum width is given by the widest line. -->
4227
+ <xsl:attribute name="width_max">
4228
+ <xsl:for-each select="p_len">
4229
+ <xsl:sort select="." data-type="number" order="descending"/>
4230
+ <xsl:if test="position() = 1"><xsl:value-of select="."/></xsl:if>
4231
+ </xsl:for-each>
4232
+ </xsl:attribute>
4233
+
4234
+ <!-- The minimum width is given by the widest text element (word, image, etc.) -->
4235
+ <xsl:variable name="width_min">
4236
+ <xsl:for-each select="word_len">
4237
+ <xsl:sort select="." data-type="number" order="descending"/>
4238
+ <xsl:if test="position() = 1"><xsl:value-of select="."/></xsl:if>
4239
+ </xsl:for-each>
4240
+ </xsl:variable>
4241
+ <xsl:attribute name="width_min">
4242
+ <xsl:value-of select="$width_min"/>
4243
+ </xsl:attribute>
4244
+
4245
+ <xsl:if test="$width_min = 0">
4246
+ <xsl:attribute name="width_min">1</xsl:attribute>
4247
+ </xsl:if>
4248
+
4249
+ <xsl:apply-templates select="node()" mode="determine_cell_widths-if"/>
4250
+
4251
+ </xsl:copy>
3844
4252
  </xsl:template><xsl:template match="*[local-name()='thead']">
3845
4253
  <xsl:param name="cols-count"/>
3846
4254
  <fo:table-header>
@@ -3925,6 +4333,7 @@
3925
4333
  </xsl:for-each>
3926
4334
  </xsl:when>
3927
4335
  <xsl:otherwise>
4336
+ <!-- $colwidths=<xsl:copy-of select="$colwidths"/> -->
3928
4337
  <xsl:call-template name="insertTableColumnWidth">
3929
4338
  <xsl:with-param name="colwidths" select="$colwidths"/>
3930
4339
  </xsl:call-template>
@@ -4014,6 +4423,52 @@
4014
4423
 
4015
4424
  </fo:table-body>
4016
4425
 
4426
+ </xsl:template><xsl:template match="/" mode="process_table-if">
4427
+ <xsl:param name="table_or_dl">table</xsl:param>
4428
+ <xsl:apply-templates mode="process_table-if">
4429
+ <xsl:with-param name="table_or_dl" select="$table_or_dl"/>
4430
+ </xsl:apply-templates>
4431
+ </xsl:template><xsl:template match="*[local-name()='tbody']" mode="process_table-if">
4432
+ <xsl:param name="table_or_dl">table</xsl:param>
4433
+
4434
+ <fo:table-body>
4435
+ <xsl:for-each select="*[local-name() = 'tr']">
4436
+ <xsl:variable name="col_count" select="count(*)"/>
4437
+
4438
+ <!-- iteration for each tr/td -->
4439
+
4440
+ <xsl:choose>
4441
+ <xsl:when test="$table_or_dl = 'table'">
4442
+ <xsl:for-each select="*[local-name() = 'td' or local-name() = 'th']/*">
4443
+ <fo:table-row number-columns-spanned="{$col_count}">
4444
+ <!-- <test_table><xsl:copy-of select="."/></test_table> -->
4445
+ <xsl:call-template name="td"/>
4446
+ </fo:table-row>
4447
+ </xsl:for-each>
4448
+ </xsl:when>
4449
+ <xsl:otherwise> <!-- $table_or_dl = 'dl' -->
4450
+ <xsl:for-each select="*[local-name() = 'td' or local-name() = 'th']">
4451
+ <xsl:variable name="is_dt" select="position() = 1"/>
4452
+
4453
+ <xsl:for-each select="*">
4454
+ <!-- <test><xsl:copy-of select="."/></test> -->
4455
+ <fo:table-row number-columns-spanned="{$col_count}">
4456
+ <xsl:choose>
4457
+ <xsl:when test="$is_dt">
4458
+ <xsl:call-template name="insert_dt_cell"/>
4459
+ </xsl:when>
4460
+ <xsl:otherwise>
4461
+ <xsl:call-template name="insert_dd_cell"/>
4462
+ </xsl:otherwise>
4463
+ </xsl:choose>
4464
+ </fo:table-row>
4465
+ </xsl:for-each>
4466
+ </xsl:for-each>
4467
+ </xsl:otherwise>
4468
+ </xsl:choose>
4469
+
4470
+ </xsl:for-each>
4471
+ </fo:table-body>
4017
4472
  </xsl:template><xsl:template match="*[local-name()='thead']/*[local-name()='tr']" priority="2">
4018
4473
  <fo:table-row xsl:use-attribute-sets="table-header-row-style">
4019
4474
 
@@ -4105,7 +4560,7 @@
4105
4560
  </xsl:choose>
4106
4561
  </xsl:attribute>
4107
4562
  </xsl:if>
4108
- </xsl:template><xsl:template match="*[local-name()='td']">
4563
+ </xsl:template><xsl:template match="*[local-name()='td']" name="td">
4109
4564
  <fo:table-cell xsl:use-attribute-sets="table-cell-style"> <!-- text-align="{@align}" -->
4110
4565
  <xsl:call-template name="setTextAlignment">
4111
4566
  <xsl:with-param name="default">left</xsl:with-param>
@@ -4143,11 +4598,24 @@
4143
4598
 
4144
4599
  <xsl:call-template name="setTableCellAttributes"/>
4145
4600
 
4601
+ <xsl:if test="$isGenerateTableIF = 'true'">
4602
+ <xsl:attribute name="border">1pt solid black</xsl:attribute> <!-- border is mandatory, to determine page width -->
4603
+ <xsl:attribute name="text-align">left</xsl:attribute>
4604
+ </xsl:if>
4605
+
4146
4606
  <fo:block>
4147
4607
 
4608
+ <xsl:if test="$isGenerateTableIF = 'true'">
4609
+ <xsl:attribute name="id"><xsl:value-of select="@id"/></xsl:attribute>
4610
+ </xsl:if>
4611
+
4612
+
4148
4613
 
4149
4614
 
4150
4615
  <xsl:apply-templates/>
4616
+
4617
+ <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"/> -->
4618
+
4151
4619
  </fo:block>
4152
4620
  </fo:table-cell>
4153
4621
  </xsl:template><xsl:template match="*[local-name()='table']/*[local-name()='note']" priority="2">
@@ -4344,9 +4812,9 @@
4344
4812
  <!-- current hierarchy is 'figure' element -->
4345
4813
  <xsl:variable name="following_dl_colwidths">
4346
4814
  <xsl:if test="*[local-name() = 'dl']"><!-- if there is a 'dl', then set the same columns width as for 'dl' -->
4347
- <xsl:variable name="html-table">
4348
- <xsl:variable name="doc_ns">
4349
-
4815
+ <xsl:variable name="simple-table">
4816
+ <!-- <xsl:variable name="doc_ns">
4817
+ <xsl:if test="$namespace = 'bipm'">bipm</xsl:if>
4350
4818
  </xsl:variable>
4351
4819
  <xsl:variable name="ns">
4352
4820
  <xsl:choose>
@@ -4357,7 +4825,7 @@
4357
4825
  <xsl:value-of select="substring-before(name(/*), '-')"/>
4358
4826
  </xsl:otherwise>
4359
4827
  </xsl:choose>
4360
- </xsl:variable>
4828
+ </xsl:variable> -->
4361
4829
 
4362
4830
  <xsl:for-each select="*[local-name() = 'dl'][1]">
4363
4831
  <tbody>
@@ -4368,7 +4836,7 @@
4368
4836
 
4369
4837
  <xsl:call-template name="calculate-column-widths">
4370
4838
  <xsl:with-param name="cols-count" select="2"/>
4371
- <xsl:with-param name="table" select="$html-table"/>
4839
+ <xsl:with-param name="table" select="$simple-table"/>
4372
4840
  </xsl:call-template>
4373
4841
 
4374
4842
  </xsl:if>
@@ -4567,7 +5035,18 @@
4567
5035
 
4568
5036
 
4569
5037
 
5038
+
5039
+ <xsl:if test="$isGenerateTableIF = 'true'">
5040
+ <!-- to determine start of table -->
5041
+ <fo:block id="{concat('table_if_start_',@id)}" keep-with-next="always" font-size="1pt">Start table '<xsl:value-of select="@id"/>'.</fo:block>
5042
+ </xsl:if>
5043
+
4570
5044
  <fo:table width="95%" table-layout="fixed">
5045
+
5046
+ <xsl:if test="$isGenerateTableIF = 'true'">
5047
+ <xsl:attribute name="wrap-option">no-wrap</xsl:attribute>
5048
+ </xsl:if>
5049
+
4571
5050
 
4572
5051
  <xsl:choose>
4573
5052
  <xsl:when test="normalize-space($key_iso) = 'true' and $parent = 'formula'"/>
@@ -4578,52 +5057,130 @@
4578
5057
 
4579
5058
  </xsl:when>
4580
5059
  </xsl:choose>
4581
- <!-- create virtual html table for dl/[dt and dd] -->
4582
- <xsl:variable name="html-table">
4583
- <xsl:variable name="doc_ns">
5060
+
5061
+
5062
+ <xsl:choose>
5063
+ <xsl:when test="$isGenerateTableIF = 'true'">
5064
+ <!-- generate IF for table widths -->
5065
+ <!-- example:
5066
+ <tr>
5067
+ <td valign="top" align="left" id="tab-symdu_1_1">
5068
+ <p>Symbol</p>
5069
+ <word id="tab-symdu_1_1_word_1">Symbol</word>
5070
+ </td>
5071
+ <td valign="top" align="left" id="tab-symdu_1_2">
5072
+ <p>Description</p>
5073
+ <word id="tab-symdu_1_2_word_1">Description</word>
5074
+ </td>
5075
+ </tr>
5076
+ -->
4584
5077
 
4585
- </xsl:variable>
4586
- <xsl:variable name="ns">
4587
- <xsl:choose>
4588
- <xsl:when test="normalize-space($doc_ns) != ''">
4589
- <xsl:value-of select="normalize-space($doc_ns)"/>
4590
- </xsl:when>
4591
- <xsl:otherwise>
4592
- <xsl:value-of select="substring-before(name(/*), '-')"/>
4593
- </xsl:otherwise>
4594
- </xsl:choose>
4595
- </xsl:variable>
4596
- <tbody>
4597
- <xsl:apply-templates mode="dl"/>
4598
- </tbody>
4599
- </xsl:variable>
4600
- <!-- DEBUG: html-table<xsl:copy-of select="$html-table"/> -->
4601
- <xsl:variable name="colwidths">
4602
- <xsl:call-template name="calculate-column-widths">
4603
- <xsl:with-param name="cols-count" select="2"/>
4604
- <xsl:with-param name="table" select="$html-table"/>
4605
- </xsl:call-template>
4606
- </xsl:variable>
4607
- <!-- DEBUG: colwidths=<xsl:copy-of select="$colwidths"/> -->
4608
- <xsl:variable name="maxlength_dt">
4609
- <xsl:call-template name="getMaxLength_dt"/>
4610
- </xsl:variable>
4611
- <xsl:variable name="isContainsKeepTogetherTag_">
4612
- false
4613
- </xsl:variable>
4614
- <xsl:variable name="isContainsKeepTogetherTag" select="normalize-space($isContainsKeepTogetherTag_)"/>
4615
- <!-- isContainsExpressReference=<xsl:value-of select="$isContainsExpressReference"/> -->
4616
- <xsl:call-template name="setColumnWidth_dl">
4617
- <xsl:with-param name="colwidths" select="$colwidths"/>
4618
- <xsl:with-param name="maxlength_dt" select="$maxlength_dt"/>
4619
- <xsl:with-param name="isContainsKeepTogetherTag" select="$isContainsKeepTogetherTag"/>
4620
- </xsl:call-template>
5078
+ <!-- create virtual html table for dl/[dt and dd] -->
5079
+ <xsl:variable name="simple-table">
5080
+
5081
+ <xsl:variable name="dl_table">
5082
+ <tbody>
5083
+ <xsl:apply-templates mode="dl_if">
5084
+ <xsl:with-param name="id" select="@id"/>
5085
+ </xsl:apply-templates>
5086
+ </tbody>
5087
+ </xsl:variable>
5088
+
5089
+ <!-- dl_table='<xsl:copy-of select="$dl_table"/>' -->
5090
+
5091
+ <!-- Step: replace <br/> to <p>...</p> -->
5092
+ <xsl:variable name="table_without_br">
5093
+ <xsl:apply-templates select="xalan:nodeset($dl_table)" mode="table-without-br"/>
5094
+ </xsl:variable>
5095
+
5096
+ <!-- table_without_br='<xsl:copy-of select="$table_without_br"/>' -->
5097
+
5098
+ <!-- Step: add id to each cell -->
5099
+ <!-- add <word>...</word> for each word, image, math -->
5100
+ <xsl:variable name="simple-table-id">
5101
+ <xsl:apply-templates select="xalan:nodeset($table_without_br)" mode="simple-table-id">
5102
+ <xsl:with-param name="id" select="@id"/>
5103
+ </xsl:apply-templates>
5104
+ </xsl:variable>
5105
+
5106
+ <!-- simple-table-id='<xsl:copy-of select="$simple-table-id"/>' -->
5107
+
5108
+ <xsl:copy-of select="xalan:nodeset($simple-table-id)"/>
5109
+
5110
+ </xsl:variable>
5111
+
5112
+ <!-- DEBUG: simple-table<xsl:copy-of select="$simple-table"/> -->
5113
+
5114
+ <xsl:apply-templates select="xalan:nodeset($simple-table)" mode="process_table-if">
5115
+ <xsl:with-param name="table_or_dl">dl</xsl:with-param>
5116
+ </xsl:apply-templates>
5117
+
5118
+ </xsl:when>
5119
+ <xsl:otherwise>
4621
5120
 
4622
- <fo:table-body>
4623
- <xsl:apply-templates>
4624
- <xsl:with-param name="key_iso" select="normalize-space($key_iso)"/>
4625
- </xsl:apply-templates>
4626
- </fo:table-body>
5121
+ <xsl:variable name="simple-table">
5122
+
5123
+ <xsl:variable name="dl_table">
5124
+ <tbody>
5125
+ <xsl:apply-templates mode="dl">
5126
+ <xsl:with-param name="id" select="@id"/>
5127
+ </xsl:apply-templates>
5128
+ </tbody>
5129
+ </xsl:variable>
5130
+
5131
+ <xsl:copy-of select="$dl_table"/>
5132
+ </xsl:variable>
5133
+
5134
+ <xsl:variable name="colwidths">
5135
+ <xsl:call-template name="calculate-column-widths">
5136
+ <xsl:with-param name="cols-count" select="2"/>
5137
+ <xsl:with-param name="table" select="$simple-table"/>
5138
+ </xsl:call-template>
5139
+ </xsl:variable>
5140
+
5141
+ <!-- <xsl:text disable-output-escaping="yes">&lt;!- -</xsl:text>
5142
+ DEBUG
5143
+ colwidths=<xsl:copy-of select="$colwidths"/>
5144
+ <xsl:text disable-output-escaping="yes">- -&gt;</xsl:text> -->
5145
+
5146
+ <!-- colwidths=<xsl:copy-of select="$colwidths"/> -->
5147
+
5148
+ <xsl:variable name="maxlength_dt">
5149
+ <xsl:call-template name="getMaxLength_dt"/>
5150
+ </xsl:variable>
5151
+
5152
+ <xsl:variable name="isContainsKeepTogetherTag_">
5153
+ false
5154
+ </xsl:variable>
5155
+ <xsl:variable name="isContainsKeepTogetherTag" select="normalize-space($isContainsKeepTogetherTag_)"/>
5156
+ <!-- isContainsExpressReference=<xsl:value-of select="$isContainsExpressReference"/> -->
5157
+
5158
+
5159
+ <xsl:call-template name="setColumnWidth_dl">
5160
+ <xsl:with-param name="colwidths" select="$colwidths"/>
5161
+ <xsl:with-param name="maxlength_dt" select="$maxlength_dt"/>
5162
+ <xsl:with-param name="isContainsKeepTogetherTag" select="$isContainsKeepTogetherTag"/>
5163
+ </xsl:call-template>
5164
+
5165
+ <fo:table-body>
5166
+
5167
+ <!-- DEBUG -->
5168
+ <xsl:if test="$table_if_debug = 'true'">
5169
+ <fo:table-row>
5170
+ <fo:table-cell number-columns-spanned="2" font-size="60%">
5171
+ <xsl:apply-templates select="xalan:nodeset($colwidths)" mode="print_as_xml"/>
5172
+ </fo:table-cell>
5173
+ </fo:table-row>
5174
+ </xsl:if>
5175
+
5176
+ <xsl:apply-templates>
5177
+ <xsl:with-param name="key_iso" select="normalize-space($key_iso)"/>
5178
+ <xsl:with-param name="split_keep-within-line" select="xalan:nodeset($colwidths)/split_keep-within-line"/>
5179
+ </xsl:apply-templates>
5180
+
5181
+ </fo:table-body>
5182
+ </xsl:otherwise>
5183
+ </xsl:choose>
4627
5184
  </fo:table>
4628
5185
  </fo:block>
4629
5186
  </fo:block>
@@ -4634,6 +5191,9 @@
4634
5191
  <xsl:param name="colwidths"/>
4635
5192
  <xsl:param name="maxlength_dt"/>
4636
5193
  <xsl:param name="isContainsKeepTogetherTag"/>
5194
+
5195
+ <!-- <colwidths><xsl:copy-of select="$colwidths"/></colwidths> -->
5196
+
4637
5197
  <xsl:choose>
4638
5198
  <xsl:when test="ancestor::*[local-name()='dl']"><!-- second level, i.e. inlined table -->
4639
5199
  <fo:table-column column-width="50%"/>
@@ -4641,6 +5201,11 @@
4641
5201
  </xsl:when>
4642
5202
  <xsl:otherwise>
4643
5203
  <xsl:choose>
5204
+ <xsl:when test="xalan:nodeset($colwidths)/autolayout">
5205
+ <xsl:call-template name="insertTableColumnWidth">
5206
+ <xsl:with-param name="colwidths" select="$colwidths"/>
5207
+ </xsl:call-template>
5208
+ </xsl:when>
4644
5209
  <xsl:when test="$isContainsKeepTogetherTag">
4645
5210
  <xsl:call-template name="insertTableColumnWidth">
4646
5211
  <xsl:with-param name="colwidths" select="$colwidths"/>
@@ -4685,13 +5250,19 @@
4685
5250
  </xsl:choose>
4686
5251
  </xsl:template><xsl:template name="insertTableColumnWidth">
4687
5252
  <xsl:param name="colwidths"/>
5253
+
4688
5254
  <xsl:for-each select="xalan:nodeset($colwidths)//column">
4689
5255
  <xsl:choose>
4690
5256
  <xsl:when test=". = 1 or . = 0">
4691
5257
  <fo:table-column column-width="proportional-column-width(2)"/>
4692
5258
  </xsl:when>
4693
5259
  <xsl:otherwise>
4694
- <fo:table-column column-width="proportional-column-width({.})"/>
5260
+ <!-- <fo:table-column column-width="proportional-column-width({.})"/> -->
5261
+ <xsl:variable name="divider">
5262
+ <xsl:value-of select="@divider"/>
5263
+ <xsl:if test="not(@divider)">1</xsl:if>
5264
+ </xsl:variable>
5265
+ <fo:table-column column-width="proportional-column-width({round(. div $divider)})"/>
4695
5266
  </xsl:otherwise>
4696
5267
  </xsl:choose>
4697
5268
  </xsl:for-each>
@@ -4753,11 +5324,19 @@
4753
5324
  </fo:table-cell>
4754
5325
  </fo:table-row>
4755
5326
  </xsl:template><xsl:template match="*[local-name()='dt']" mode="dl">
5327
+ <xsl:param name="id"/>
5328
+ <xsl:variable name="row_number" select="count(preceding-sibling::*[local-name()='dt']) + 1"/>
4756
5329
  <tr>
4757
5330
  <td>
5331
+ <xsl:attribute name="id">
5332
+ <xsl:value-of select="concat($id,'_',$row_number,'_1')"/>
5333
+ </xsl:attribute>
4758
5334
  <xsl:apply-templates/>
4759
5335
  </td>
4760
5336
  <td>
5337
+ <xsl:attribute name="id">
5338
+ <xsl:value-of select="concat($id,'_',$row_number,'_2')"/>
5339
+ </xsl:attribute>
4761
5340
 
4762
5341
  <xsl:apply-templates select="following-sibling::*[local-name()='dd'][1]">
4763
5342
  <xsl:with-param name="process">true</xsl:with-param>
@@ -4768,50 +5347,122 @@
4768
5347
 
4769
5348
  </xsl:template><xsl:template match="*[local-name()='dt']">
4770
5349
  <xsl:param name="key_iso"/>
5350
+ <xsl:param name="split_keep-within-line"/>
4771
5351
 
4772
5352
  <fo:table-row xsl:use-attribute-sets="dt-row-style">
4773
- <fo:table-cell>
5353
+ <xsl:call-template name="insert_dt_cell">
5354
+ <xsl:with-param name="key_iso" select="$key_iso"/>
5355
+ <xsl:with-param name="split_keep-within-line" select="$split_keep-within-line"/>
5356
+ </xsl:call-template>
5357
+ <xsl:for-each select="following-sibling::*[local-name()='dd'][1]">
5358
+ <xsl:call-template name="insert_dd_cell">
5359
+ <xsl:with-param name="split_keep-within-line" select="$split_keep-within-line"/>
5360
+ </xsl:call-template>
5361
+ </xsl:for-each>
5362
+ </fo:table-row>
5363
+ </xsl:template><xsl:template name="insert_dt_cell">
5364
+ <xsl:param name="key_iso"/>
5365
+ <xsl:param name="split_keep-within-line"/>
5366
+ <fo:table-cell xsl:use-attribute-sets="dt-cell-style">
5367
+
5368
+ <xsl:if test="$isGenerateTableIF = 'true'">
5369
+ <!-- border is mandatory, to calculate real width -->
5370
+ <xsl:attribute name="border">0.1pt solid black</xsl:attribute>
5371
+ <xsl:attribute name="text-align">left</xsl:attribute>
5372
+ </xsl:if>
5373
+
5374
+
5375
+ <fo:block xsl:use-attribute-sets="dt-block-style">
5376
+ <xsl:copy-of select="@id"/>
5377
+
5378
+ <xsl:if test="normalize-space($key_iso) = 'true'">
5379
+ <xsl:attribute name="margin-top">0</xsl:attribute>
5380
+ </xsl:if>
5381
+
5382
+
5383
+
5384
+ <xsl:apply-templates>
5385
+ <xsl:with-param name="split_keep-within-line" select="$split_keep-within-line"/>
5386
+ </xsl:apply-templates>
5387
+
5388
+ <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"/> -->
5389
+
5390
+ </fo:block>
5391
+ </fo:table-cell>
5392
+ </xsl:template><xsl:template name="insert_dd_cell">
5393
+ <xsl:param name="split_keep-within-line"/>
5394
+ <fo:table-cell xsl:use-attribute-sets="dd-cell-style">
5395
+
5396
+ <xsl:if test="$isGenerateTableIF = 'true'">
5397
+ <!-- border is mandatory, to calculate real width -->
5398
+ <xsl:attribute name="border">0.1pt solid black</xsl:attribute>
5399
+ </xsl:if>
5400
+
5401
+ <fo:block>
5402
+
5403
+ <xsl:if test="$isGenerateTableIF = 'true'">
5404
+ <xsl:attribute name="id"><xsl:value-of select="@id"/></xsl:attribute>
5405
+ </xsl:if>
5406
+
4774
5407
 
4775
- <fo:block xsl:use-attribute-sets="dt-style">
4776
- <xsl:copy-of select="@id"/>
4777
-
4778
- <xsl:if test="normalize-space($key_iso) = 'true'">
4779
- <xsl:attribute name="margin-top">0</xsl:attribute>
4780
- </xsl:if>
4781
-
4782
-
4783
-
4784
- <xsl:apply-templates/>
4785
- </fo:block>
4786
- </fo:table-cell>
4787
- <fo:table-cell>
4788
- <fo:block>
4789
-
4790
5408
 
4791
- <xsl:apply-templates select="following-sibling::*[local-name()='dd'][1]">
4792
- <xsl:with-param name="process">true</xsl:with-param>
4793
- </xsl:apply-templates>
4794
- </fo:block>
4795
- </fo:table-cell>
4796
- </fo:table-row>
5409
+ <xsl:choose>
5410
+ <xsl:when test="$isGenerateTableIF = 'true'">
5411
+ <xsl:apply-templates> <!-- following-sibling::*[local-name()='dd'][1] -->
5412
+ <xsl:with-param name="process">true</xsl:with-param>
5413
+ </xsl:apply-templates>
5414
+ </xsl:when>
5415
+ <xsl:otherwise>
5416
+ <xsl:apply-templates select="."> <!-- following-sibling::*[local-name()='dd'][1] -->
5417
+ <xsl:with-param name="process">true</xsl:with-param>
5418
+ <xsl:with-param name="split_keep-within-line" select="$split_keep-within-line"/>
5419
+ </xsl:apply-templates>
5420
+ </xsl:otherwise>
5421
+
5422
+ </xsl:choose>
5423
+
5424
+ <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"/> -->
5425
+
5426
+ </fo:block>
5427
+ </fo:table-cell>
4797
5428
  </xsl:template><xsl:template match="*[local-name()='dd']" mode="dl"/><xsl:template match="*[local-name()='dd']" mode="dl_process">
4798
5429
  <xsl:apply-templates/>
4799
5430
  </xsl:template><xsl:template match="*[local-name()='dd']">
4800
5431
  <xsl:param name="process">false</xsl:param>
5432
+ <xsl:param name="split_keep-within-line"/>
4801
5433
  <xsl:if test="$process = 'true'">
4802
5434
  <xsl:apply-templates select="@language"/>
4803
- <xsl:apply-templates/>
5435
+ <xsl:apply-templates>
5436
+ <xsl:with-param name="split_keep-within-line" select="$split_keep-within-line"/>
5437
+ </xsl:apply-templates>
4804
5438
  </xsl:if>
4805
5439
  </xsl:template><xsl:template match="*[local-name()='dd']/*[local-name()='p']" mode="inline">
4806
5440
  <fo:inline><xsl:text> </xsl:text><xsl:apply-templates/></fo:inline>
4807
- </xsl:template><xsl:template match="*[local-name()='em']">
5441
+ </xsl:template><xsl:template match="*[local-name()='dt']" mode="dl_if">
5442
+ <xsl:param name="id"/>
5443
+ <xsl:variable name="row_number" select="count(preceding-sibling::*[local-name()='dt']) + 1"/>
5444
+ <tr>
5445
+ <td>
5446
+ <xsl:copy-of select="node()"/>
5447
+ </td>
5448
+ <td>
5449
+
5450
+ <xsl:copy-of select="following-sibling::*[local-name()='dd'][1]/node()"/>
5451
+
5452
+ </td>
5453
+ </tr>
5454
+
5455
+ </xsl:template><xsl:template match="*[local-name()='dd']" mode="dl_if"/><xsl:template match="*[local-name()='em']">
4808
5456
  <fo:inline font-style="italic">
4809
5457
  <xsl:apply-templates/>
4810
5458
  </fo:inline>
4811
5459
  </xsl:template><xsl:template match="*[local-name()='strong'] | *[local-name()='b']">
5460
+ <xsl:param name="split_keep-within-line"/>
4812
5461
  <fo:inline font-weight="bold">
4813
5462
 
4814
- <xsl:apply-templates/>
5463
+ <xsl:apply-templates>
5464
+ <xsl:with-param name="split_keep-within-line" select="$split_keep-within-line"/>
5465
+ </xsl:apply-templates>
4815
5466
  </fo:inline>
4816
5467
  </xsl:template><xsl:template match="*[local-name()='padding']">
4817
5468
  <fo:inline padding-right="{@value}"> </fo:inline>
@@ -5012,6 +5663,10 @@
5012
5663
  <xsl:param name="text"/>
5013
5664
  <xsl:param name="separator" select="' '"/>
5014
5665
  <xsl:choose>
5666
+
5667
+ <xsl:when test="$isGenerateTableIF = 'true' and not(contains($text, $separator))">
5668
+ <word><xsl:value-of select="normalize-space($text)"/></word>
5669
+ </xsl:when>
5015
5670
  <xsl:when test="not(contains($text, $separator))">
5016
5671
  <word>
5017
5672
  <xsl:variable name="len_str_tmp" select="string-length(normalize-space($text))"/>
@@ -5056,13 +5711,66 @@
5056
5711
  </xsl:when>
5057
5712
  <xsl:otherwise>
5058
5713
  <word>
5059
- <xsl:value-of select="string-length(normalize-space(substring-before($text, $separator)))"/>
5714
+ <xsl:variable name="word" select="normalize-space(substring-before($text, $separator))"/>
5715
+ <xsl:choose>
5716
+ <xsl:when test="$isGenerateTableIF = 'true'">
5717
+ <xsl:value-of select="$word"/>
5718
+ </xsl:when>
5719
+ <xsl:otherwise>
5720
+ <xsl:value-of select="string-length($word)"/>
5721
+ </xsl:otherwise>
5722
+ </xsl:choose>
5060
5723
  </word>
5061
5724
  <xsl:call-template name="tokenize">
5062
5725
  <xsl:with-param name="text" select="substring-after($text, $separator)"/>
5063
5726
  </xsl:call-template>
5064
5727
  </xsl:otherwise>
5065
5728
  </xsl:choose>
5729
+ </xsl:template><xsl:template name="tokenize_with_tags">
5730
+ <xsl:param name="tags"/>
5731
+ <xsl:param name="text"/>
5732
+ <xsl:param name="separator" select="' '"/>
5733
+ <xsl:choose>
5734
+
5735
+ <xsl:when test="not(contains($text, $separator))">
5736
+ <word>
5737
+ <xsl:call-template name="enclose_text_in_tags">
5738
+ <xsl:with-param name="text" select="normalize-space($text)"/>
5739
+ <xsl:with-param name="tags" select="$tags"/>
5740
+ </xsl:call-template>
5741
+ </word>
5742
+ </xsl:when>
5743
+ <xsl:otherwise>
5744
+ <word>
5745
+ <xsl:call-template name="enclose_text_in_tags">
5746
+ <xsl:with-param name="text" select="normalize-space(substring-before($text, $separator))"/>
5747
+ <xsl:with-param name="tags" select="$tags"/>
5748
+ </xsl:call-template>
5749
+ </word>
5750
+ <xsl:call-template name="tokenize_with_tags">
5751
+ <xsl:with-param name="text" select="substring-after($text, $separator)"/>
5752
+ </xsl:call-template>
5753
+ </xsl:otherwise>
5754
+ </xsl:choose>
5755
+ </xsl:template><xsl:template name="enclose_text_in_tags">
5756
+ <xsl:param name="text"/>
5757
+ <xsl:param name="tags"/>
5758
+ <xsl:param name="num">1</xsl:param> <!-- default (start) value -->
5759
+
5760
+ <xsl:variable name="tag_name" select="normalize-space(xalan:nodeset($tags)//tag[$num])"/>
5761
+
5762
+ <xsl:choose>
5763
+ <xsl:when test="$tag_name = ''"><xsl:value-of select="$text"/></xsl:when>
5764
+ <xsl:otherwise>
5765
+ <xsl:element name="{$tag_name}">
5766
+ <xsl:call-template name="enclose_text_in_tags">
5767
+ <xsl:with-param name="text" select="$text"/>
5768
+ <xsl:with-param name="tags" select="$tags"/>
5769
+ <xsl:with-param name="num" select="$num + 1"/>
5770
+ </xsl:call-template>
5771
+ </xsl:element>
5772
+ </xsl:otherwise>
5773
+ </xsl:choose>
5066
5774
  </xsl:template><xsl:template name="max_length">
5067
5775
  <xsl:param name="words"/>
5068
5776
  <xsl:for-each select="$words//word">
@@ -5163,12 +5871,19 @@
5163
5871
  </xsl:otherwise>
5164
5872
  </xsl:choose>
5165
5873
  </xsl:template><xsl:template name="getSimpleTable">
5874
+ <xsl:param name="id"/>
5875
+
5166
5876
  <xsl:variable name="simple-table">
5167
5877
 
5878
+ <!-- Step 0. replace <br/> to <p>...</p> -->
5879
+ <xsl:variable name="table_without_br">
5880
+ <xsl:apply-templates mode="table-without-br"/>
5881
+ </xsl:variable>
5882
+
5168
5883
  <!-- Step 1. colspan processing -->
5169
5884
  <xsl:variable name="simple-table-colspan">
5170
5885
  <tbody>
5171
- <xsl:apply-templates mode="simple-table-colspan"/>
5886
+ <xsl:apply-templates select="xalan:nodeset($table_without_br)" mode="simple-table-colspan"/>
5172
5887
  </tbody>
5173
5888
  </xsl:variable>
5174
5889
 
@@ -5177,10 +5892,67 @@
5177
5892
  <xsl:apply-templates select="xalan:nodeset($simple-table-colspan)" mode="simple-table-rowspan"/>
5178
5893
  </xsl:variable>
5179
5894
 
5180
- <xsl:copy-of select="xalan:nodeset($simple-table-rowspan)"/>
5181
-
5895
+ <!-- Step 3: add id to each cell -->
5896
+ <!-- add <word>...</word> for each word, image, math -->
5897
+ <xsl:variable name="simple-table-id">
5898
+ <xsl:apply-templates select="xalan:nodeset($simple-table-rowspan)" mode="simple-table-id">
5899
+ <xsl:with-param name="id" select="$id"/>
5900
+ </xsl:apply-templates>
5901
+ </xsl:variable>
5902
+
5903
+ <xsl:copy-of select="xalan:nodeset($simple-table-id)"/>
5904
+
5182
5905
  </xsl:variable>
5183
5906
  <xsl:copy-of select="$simple-table"/>
5907
+ </xsl:template><xsl:template match="@*|node()" mode="table-without-br">
5908
+ <xsl:copy>
5909
+ <xsl:apply-templates select="@*|node()" mode="table-without-br"/>
5910
+ </xsl:copy>
5911
+ </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">
5912
+ <xsl:copy>
5913
+ <xsl:copy-of select="@*"/>
5914
+ <p>
5915
+ <xsl:copy-of select="node()"/>
5916
+ </p>
5917
+ </xsl:copy>
5918
+ </xsl:template><xsl:template match="*[local-name()='th' or local-name()='td'][*[local-name()='br']]" mode="table-without-br">
5919
+ <xsl:copy>
5920
+ <xsl:copy-of select="@*"/>
5921
+ <xsl:for-each select="*[local-name()='br']">
5922
+ <xsl:variable name="current_id" select="generate-id()"/>
5923
+ <p>
5924
+ <xsl:for-each select="preceding-sibling::node()[following-sibling::*[local-name() = 'br'][1][generate-id() = $current_id]][not(local-name() = 'br')]">
5925
+ <xsl:copy-of select="."/>
5926
+ </xsl:for-each>
5927
+ </p>
5928
+ <xsl:if test="not(following-sibling::*[local-name() = 'br'])">
5929
+ <p>
5930
+ <xsl:for-each select="following-sibling::node()">
5931
+ <xsl:copy-of select="."/>
5932
+ </xsl:for-each>
5933
+ </p>
5934
+ </xsl:if>
5935
+ </xsl:for-each>
5936
+ </xsl:copy>
5937
+ </xsl:template><xsl:template match="*[local-name()='th' or local-name()='td']/*[local-name() = 'p'][*[local-name()='br']]" mode="table-without-br">
5938
+ <xsl:for-each select="*[local-name()='br']">
5939
+ <xsl:variable name="current_id" select="generate-id()"/>
5940
+ <p>
5941
+ <xsl:for-each select="preceding-sibling::node()[following-sibling::*[local-name() = 'br'][1][generate-id() = $current_id]][not(local-name() = 'br')]">
5942
+ <xsl:copy-of select="."/>
5943
+ </xsl:for-each>
5944
+ </p>
5945
+ <xsl:if test="not(following-sibling::*[local-name() = 'br'])">
5946
+ <p>
5947
+ <xsl:for-each select="following-sibling::node()">
5948
+ <xsl:copy-of select="."/>
5949
+ </xsl:for-each>
5950
+ </p>
5951
+ </xsl:if>
5952
+ </xsl:for-each>
5953
+ </xsl:template><xsl:template match="text()[not(ancestor::*[local-name() = 'sourcecode'])]" mode="table-without-br">
5954
+ <xsl:variable name="text" select="translate(.,'&#9;&#10;&#13;','')"/>
5955
+ <xsl:value-of select="java:replaceAll(java:java.lang.String.new($text),' {2,}',' ')"/>
5184
5956
  </xsl:template><xsl:template match="*[local-name()='thead'] | *[local-name()='tbody']" mode="simple-table-colspan">
5185
5957
  <xsl:apply-templates mode="simple-table-colspan"/>
5186
5958
  </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">
@@ -5270,6 +6042,126 @@
5270
6042
  <xsl:apply-templates select="following-sibling::tr[1]" mode="simple-table-rowspan">
5271
6043
  <xsl:with-param name="previousRow" select="$newRow"/>
5272
6044
  </xsl:apply-templates>
6045
+ </xsl:template><xsl:template match="/" mode="simple-table-id">
6046
+ <xsl:param name="id"/>
6047
+ <xsl:variable name="id_prefixed" select="concat('table_if_',$id)"/> <!-- table id prefixed by 'table_if_' to simple search in IF -->
6048
+ <xsl:apply-templates select="@*|node()" mode="simple-table-id">
6049
+ <xsl:with-param name="id" select="$id_prefixed"/>
6050
+ </xsl:apply-templates>
6051
+ </xsl:template><xsl:template match="@*|node()" mode="simple-table-id">
6052
+ <xsl:param name="id"/>
6053
+ <xsl:copy>
6054
+ <xsl:apply-templates select="@*|node()" mode="simple-table-id">
6055
+ <xsl:with-param name="id" select="$id"/>
6056
+ </xsl:apply-templates>
6057
+ </xsl:copy>
6058
+ </xsl:template><xsl:template match="*[local-name()='tbody']" mode="simple-table-id">
6059
+ <xsl:param name="id"/>
6060
+ <xsl:copy>
6061
+ <xsl:copy-of select="@*"/>
6062
+ <xsl:attribute name="id"><xsl:value-of select="$id"/></xsl:attribute>
6063
+ <xsl:apply-templates select="node()" mode="simple-table-id">
6064
+ <xsl:with-param name="id" select="$id"/>
6065
+ </xsl:apply-templates>
6066
+ </xsl:copy>
6067
+ </xsl:template><xsl:template match="*[local-name()='th' or local-name()='td']" mode="simple-table-id">
6068
+ <xsl:param name="id"/>
6069
+ <xsl:copy>
6070
+ <xsl:copy-of select="@*"/>
6071
+ <xsl:variable name="row_number" select="count(../preceding-sibling::*) + 1"/>
6072
+ <xsl:variable name="col_number" select="count(preceding-sibling::*) + 1"/>
6073
+ <xsl:attribute name="id">
6074
+ <xsl:value-of select="concat($id,'_',$row_number,'_',$col_number)"/>
6075
+ </xsl:attribute>
6076
+
6077
+ <xsl:for-each select="*[local-name() = 'p']">
6078
+ <xsl:copy>
6079
+ <xsl:copy-of select="@*"/>
6080
+ <xsl:variable name="p_num" select="count(preceding-sibling::*[local-name() = 'p']) + 1"/>
6081
+ <xsl:attribute name="id">
6082
+ <xsl:value-of select="concat($id,'_',$row_number,'_',$col_number,'_p_',$p_num)"/>
6083
+ </xsl:attribute>
6084
+
6085
+ <xsl:copy-of select="node()"/>
6086
+ </xsl:copy>
6087
+ </xsl:for-each>
6088
+
6089
+
6090
+ <xsl:if test="$isGenerateTableIF = 'true'"> <!-- split each paragraph to words, image, math -->
6091
+
6092
+ <xsl:variable name="td_text">
6093
+ <xsl:apply-templates select="." mode="td_text_with_formatting"/>
6094
+ </xsl:variable>
6095
+
6096
+ <!-- td_text='<xsl:copy-of select="$td_text"/>' -->
6097
+
6098
+ <xsl:variable name="words">
6099
+ <xsl:for-each select=".//*[local-name() = 'image' or local-name() = 'stem']">
6100
+ <word>
6101
+ <xsl:copy-of select="."/>
6102
+ </word>
6103
+ </xsl:for-each>
6104
+
6105
+ <xsl:for-each select="xalan:nodeset($td_text)//*[local-name() = 'word'][normalize-space() != '']">
6106
+ <xsl:copy-of select="."/>
6107
+ </xsl:for-each>
6108
+
6109
+ </xsl:variable>
6110
+
6111
+ <xsl:for-each select="xalan:nodeset($words)/word">
6112
+ <xsl:variable name="num" select="count(preceding-sibling::word) + 1"/>
6113
+ <xsl:copy>
6114
+ <xsl:attribute name="id">
6115
+ <xsl:value-of select="concat($id,'_',$row_number,'_',$col_number,'_word_',$num)"/>
6116
+ </xsl:attribute>
6117
+ <xsl:copy-of select="node()"/>
6118
+ </xsl:copy>
6119
+ </xsl:for-each>
6120
+ </xsl:if>
6121
+ </xsl:copy>
6122
+
6123
+ </xsl:template><xsl:template match="@*|node()" mode="td_text_with_formatting">
6124
+ <xsl:copy>
6125
+ <xsl:apply-templates select="@*|node()" mode="td_text_with_formatting"/>
6126
+ </xsl:copy>
6127
+ </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">
6128
+ <xsl:variable name="formatting_tags">
6129
+ <xsl:call-template name="getFormattingTags"/>
6130
+ </xsl:variable>
6131
+ <word>
6132
+ <xsl:call-template name="enclose_text_in_tags">
6133
+ <xsl:with-param name="text" select="normalize-space(.)"/>
6134
+ <xsl:with-param name="tags" select="$formatting_tags"/>
6135
+ </xsl:call-template>
6136
+ </word>
6137
+ </xsl:template><xsl:template match="*[local-name() != 'keep-together_within-line']/text()" mode="td_text_with_formatting">
6138
+
6139
+ <xsl:variable name="td_text" select="."/>
6140
+
6141
+ <xsl:variable name="string_with_added_zerospaces">
6142
+ <xsl:call-template name="add-zero-spaces-java">
6143
+ <xsl:with-param name="text" select="$td_text"/>
6144
+ </xsl:call-template>
6145
+ </xsl:variable>
6146
+
6147
+ <xsl:variable name="formatting_tags">
6148
+ <xsl:call-template name="getFormattingTags"/>
6149
+ </xsl:variable>
6150
+
6151
+ <!-- <word>text</word> -->
6152
+ <xsl:call-template name="tokenize_with_tags">
6153
+ <xsl:with-param name="tags" select="$formatting_tags"/>
6154
+ <xsl:with-param name="text" select="normalize-space(translate($string_with_added_zerospaces, '​­', ' '))"/> <!-- replace zero-width-space and soft-hyphen to space -->
6155
+ </xsl:call-template>
6156
+ </xsl:template><xsl:template name="getFormattingTags">
6157
+ <tags>
6158
+ <xsl:if test="ancestor::*[local-name() = 'strong']"><tag>strong</tag></xsl:if>
6159
+ <xsl:if test="ancestor::*[local-name() = 'em']"><tag>em</tag></xsl:if>
6160
+ <xsl:if test="ancestor::*[local-name() = 'sub']"><tag>sub</tag></xsl:if>
6161
+ <xsl:if test="ancestor::*[local-name() = 'sup']"><tag>sup</tag></xsl:if>
6162
+ <xsl:if test="ancestor::*[local-name() = 'tt']"><tag>tt</tag></xsl:if>
6163
+ <xsl:if test="ancestor::*[local-name() = 'keep-together_within-line']"><tag>keep-together_within-line</tag></xsl:if>
6164
+ </tags>
5273
6165
  </xsl:template><xsl:template name="getLang">
5274
6166
  <xsl:variable name="language_current" select="normalize-space(//*[local-name()='bibdata']//*[local-name()='language'][@current = 'true'])"/>
5275
6167
  <xsl:variable name="language">
@@ -6972,7 +7864,9 @@
6972
7864
  <!-- <xsl:attribute name="border">0.5pt solid black</xsl:attribute> -->
6973
7865
  </xsl:if>
6974
7866
  <xsl:variable name="simple-table">
6975
- <xsl:call-template name="getSimpleTable"/>
7867
+ <xsl:call-template name="getSimpleTable">
7868
+ <xsl:with-param name="id" select="@id"/>
7869
+ </xsl:call-template>
6976
7870
  </xsl:variable>
6977
7871
  <xsl:variable name="cols-count" select="count(xalan:nodeset($simple-table)//tr[1]/td)"/>
6978
7872
  <xsl:if test="$cols-count = 2 and not(ancestor::*[local-name()='table'])">
@@ -7937,7 +8831,7 @@
7937
8831
  <!-- <fo:inline id="{@id}" font-size="1pt"/> -->
7938
8832
  <fo:inline id="{@id}" font-size="1pt"><xsl:value-of select="$hair_space"/></fo:inline>
7939
8833
  <!-- we need to add zero-width space, otherwise this fo:inline is missing in IF xml -->
7940
- <xsl:if test="not(following-sibling::node()[normalize-space() != ''])"> </xsl:if>
8834
+ <xsl:if test="not(following-sibling::node()[normalize-space() != ''])"><fo:inline font-size="1pt"> </fo:inline></xsl:if>
7941
8835
  </xsl:template><xsl:template match="*[local-name() = 'errata']">
7942
8836
  <!-- <row>
7943
8837
  <date>05-07-2013</date>
@@ -9284,4 +10178,40 @@
9284
10178
  <xsl:value-of select="$value"/>
9285
10179
  </xsl:otherwise>
9286
10180
  </xsl:choose>
10181
+ </xsl:template><xsl:template match="*" mode="print_as_xml">
10182
+ <xsl:param name="level">0</xsl:param>
10183
+
10184
+ <fo:block margin-left="{2*$level}mm">
10185
+ <xsl:text>
10186
+ &lt;</xsl:text>
10187
+ <xsl:value-of select="local-name()"/>
10188
+ <xsl:for-each select="@*">
10189
+ <xsl:text> </xsl:text>
10190
+ <xsl:value-of select="local-name()"/>
10191
+ <xsl:text>="</xsl:text>
10192
+ <xsl:value-of select="."/>
10193
+ <xsl:text>"</xsl:text>
10194
+ </xsl:for-each>
10195
+ <xsl:text>&gt;</xsl:text>
10196
+
10197
+ <xsl:if test="not(*)">
10198
+ <fo:inline font-weight="bold"><xsl:value-of select="."/></fo:inline>
10199
+ <xsl:text>&lt;/</xsl:text>
10200
+ <xsl:value-of select="local-name()"/>
10201
+ <xsl:text>&gt;</xsl:text>
10202
+ </xsl:if>
10203
+ </fo:block>
10204
+
10205
+ <xsl:if test="*">
10206
+ <fo:block>
10207
+ <xsl:apply-templates mode="print_as_xml">
10208
+ <xsl:with-param name="level" select="$level + 1"/>
10209
+ </xsl:apply-templates>
10210
+ </fo:block>
10211
+ <fo:block margin-left="{2*$level}mm">
10212
+ <xsl:text>&lt;/</xsl:text>
10213
+ <xsl:value-of select="local-name()"/>
10214
+ <xsl:text>&gt;</xsl:text>
10215
+ </fo:block>
10216
+ </xsl:if>
9287
10217
  </xsl:template></xsl:stylesheet>