metanorma-ribose 2.1.0 → 2.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -777,6 +777,7 @@
777
777
 
778
778
  <xsl:template match="rsd:p" name="paragraph">
779
779
  <xsl:param name="inline" select="'false'"/>
780
+ <xsl:param name="split_keep-within-line"/>
780
781
  <xsl:variable name="previous-element" select="local-name(preceding-sibling::*[1])"/>
781
782
  <xsl:variable name="element-name">
782
783
  <xsl:choose>
@@ -809,7 +810,9 @@
809
810
  </xsl:if>
810
811
 
811
812
  <!-- <xsl:attribute name="line-height">155%</xsl:attribute> -->
812
- <xsl:apply-templates/>
813
+ <xsl:apply-templates>
814
+ <xsl:with-param name="split_keep-within-line" select="$split_keep-within-line"/>
815
+ </xsl:apply-templates>
813
816
  </xsl:element>
814
817
  <xsl:if test="$element-name = 'fo:inline' and not($inline = 'true') and not(local-name(..) = 'admonition')">
815
818
  <fo:block margin-bottom="12pt">
@@ -1209,7 +1212,9 @@
1209
1212
 
1210
1213
 
1211
1214
 
1212
- <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">
1215
+ <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_">
1216
+ false
1217
+ </xsl:variable><xsl:variable name="isGenerateTableIF" select="normalize-space($isGenerateTableIF_)"/><xsl:variable name="lang">
1213
1218
  <xsl:call-template name="getLang"/>
1214
1219
  </xsl:variable><xsl:variable name="pageWidth_">
1215
1220
  215.9
@@ -1684,6 +1689,7 @@
1684
1689
  <xsl:attribute name="font-weight">bold</xsl:attribute>
1685
1690
  <xsl:attribute name="border">solid black 1pt</xsl:attribute>
1686
1691
  <xsl:attribute name="padding-left">1mm</xsl:attribute>
1692
+ <xsl:attribute name="padding-right">1mm</xsl:attribute>
1687
1693
  <xsl:attribute name="display-align">center</xsl:attribute>
1688
1694
 
1689
1695
 
@@ -1705,6 +1711,7 @@
1705
1711
  <xsl:attribute name="display-align">center</xsl:attribute>
1706
1712
  <xsl:attribute name="border">solid black 1pt</xsl:attribute>
1707
1713
  <xsl:attribute name="padding-left">1mm</xsl:attribute>
1714
+ <xsl:attribute name="padding-right">1mm</xsl:attribute>
1708
1715
 
1709
1716
 
1710
1717
 
@@ -1796,7 +1803,8 @@
1796
1803
 
1797
1804
  <xsl:attribute name="min-height">7mm</xsl:attribute>
1798
1805
 
1799
- </xsl:attribute-set><xsl:attribute-set name="dt-style">
1806
+ </xsl:attribute-set><xsl:attribute-set name="dt-cell-style">
1807
+ </xsl:attribute-set><xsl:attribute-set name="dt-block-style">
1800
1808
  <xsl:attribute name="margin-top">6pt</xsl:attribute>
1801
1809
 
1802
1810
 
@@ -1812,6 +1820,8 @@
1812
1820
  <xsl:attribute name="font-weight">bold</xsl:attribute>
1813
1821
  <xsl:attribute name="color"><xsl:value-of select="$color_blue"/></xsl:attribute>
1814
1822
 
1823
+ </xsl:attribute-set><xsl:attribute-set name="dd-cell-style">
1824
+ <xsl:attribute name="padding-left">2mm</xsl:attribute>
1815
1825
  </xsl:attribute-set><xsl:attribute-set name="appendix-style">
1816
1826
 
1817
1827
 
@@ -2710,7 +2720,38 @@
2710
2720
  </xsl:template><xsl:template match="*[local-name()='br']">
2711
2721
  <xsl:value-of select="$linebreak"/>
2712
2722
  </xsl:template><xsl:template match="*[local-name() = 'keep-together_within-line']">
2713
- <fo:inline keep-together.within-line="always"><xsl:apply-templates/></fo:inline>
2723
+ <xsl:param name="split_keep-within-line"/>
2724
+
2725
+ <!-- <fo:inline>split_keep-within-line='<xsl:value-of select="$split_keep-within-line"/>'</fo:inline> -->
2726
+ <xsl:choose>
2727
+
2728
+ <xsl:when test="normalize-space($split_keep-within-line) = 'true'">
2729
+ <xsl:variable name="sep">_</xsl:variable>
2730
+ <xsl:variable name="items">
2731
+ <xsl:call-template name="split">
2732
+ <xsl:with-param name="pText" select="."/>
2733
+ <xsl:with-param name="sep" select="$sep"/>
2734
+ <xsl:with-param name="normalize-space">false</xsl:with-param>
2735
+ <xsl:with-param name="keep_sep">true</xsl:with-param>
2736
+ </xsl:call-template>
2737
+ </xsl:variable>
2738
+ <xsl:for-each select="xalan:nodeset($items)/item">
2739
+ <xsl:choose>
2740
+ <xsl:when test=". = $sep">
2741
+ <xsl:value-of select="$sep"/><xsl:value-of select="$zero_width_space"/>
2742
+ </xsl:when>
2743
+ <xsl:otherwise>
2744
+ <fo:inline keep-together.within-line="always"><xsl:apply-templates/></fo:inline>
2745
+ </xsl:otherwise>
2746
+ </xsl:choose>
2747
+ </xsl:for-each>
2748
+ </xsl:when>
2749
+
2750
+ <xsl:otherwise>
2751
+ <fo:inline keep-together.within-line="always"><xsl:apply-templates/></fo:inline>
2752
+ </xsl:otherwise>
2753
+
2754
+ </xsl:choose>
2714
2755
  </xsl:template><xsl:template match="*[local-name()='copyright-statement']">
2715
2756
  <fo:block xsl:use-attribute-sets="copyright-statement-style">
2716
2757
  <xsl:apply-templates/>
@@ -2807,9 +2848,14 @@
2807
2848
 
2808
2849
  <xsl:variable name="table">
2809
2850
 
2810
- <xsl:variable name="simple-table">
2811
- <xsl:call-template name="getSimpleTable"/>
2851
+ <xsl:variable name="simple-table">
2852
+ <xsl:call-template name="getSimpleTable">
2853
+ <xsl:with-param name="id" select="@id"/>
2854
+ </xsl:call-template>
2812
2855
  </xsl:variable>
2856
+ <!-- <xsl:variable name="simple-table" select="xalan:nodeset($simple-table_)"/> -->
2857
+
2858
+ <!-- simple-table=<xsl:copy-of select="$simple-table"/> -->
2813
2859
 
2814
2860
 
2815
2861
  <!-- Display table's name before table as standalone block -->
@@ -2830,7 +2876,23 @@
2830
2876
  </xsl:call-template>
2831
2877
  </xsl:if>
2832
2878
  </xsl:variable>
2833
- <!-- DEBUG colwidths=<xsl:copy-of select="$colwidths"/> -->
2879
+ <!-- <xsl:variable name="colwidths" select="xalan:nodeset($colwidths_)"/> -->
2880
+
2881
+ <!-- DEBUG -->
2882
+ <xsl:if test="$table_if_debug = 'true'">
2883
+ <fo:block font-size="60%">
2884
+ <xsl:apply-templates select="xalan:nodeset($colwidths)" mode="print_as_xml"/>
2885
+ </fo:block>
2886
+ </xsl:if>
2887
+
2888
+
2889
+ <!-- <xsl:copy-of select="$colwidths"/> -->
2890
+
2891
+ <!-- <xsl:text disable-output-escaping="yes">&lt;!- -</xsl:text>
2892
+ DEBUG
2893
+ colwidths=<xsl:copy-of select="$colwidths"/>
2894
+ <xsl:text disable-output-escaping="yes">- -&gt;</xsl:text> -->
2895
+
2834
2896
 
2835
2897
 
2836
2898
  <xsl:variable name="margin-side">
@@ -2891,9 +2953,17 @@
2891
2953
  </xsl:element>
2892
2954
  </xsl:variable>
2893
2955
 
2956
+ <xsl:if test="$isGenerateTableIF = 'true'">
2957
+ <!-- to determine start of table -->
2958
+ <fo:block id="{concat('table_if_start_',@id)}" keep-with-next="always" font-size="1pt">Start table '<xsl:value-of select="@id"/>'.</fo:block>
2959
+ </xsl:if>
2894
2960
 
2895
2961
  <fo:table id="{@id}">
2896
2962
 
2963
+ <xsl:if test="$isGenerateTableIF = 'true'">
2964
+ <xsl:attribute name="wrap-option">no-wrap</xsl:attribute>
2965
+ </xsl:if>
2966
+
2897
2967
  <xsl:for-each select="xalan:nodeset($table_attributes)/table_attributes/@*">
2898
2968
  <xsl:attribute name="{local-name()}">
2899
2969
  <xsl:value-of select="."/>
@@ -2907,24 +2977,47 @@
2907
2977
 
2908
2978
 
2909
2979
  <xsl:choose>
2910
- <xsl:when test="*[local-name()='colgroup']/*[local-name()='col']">
2911
- <xsl:for-each select="*[local-name()='colgroup']/*[local-name()='col']">
2912
- <fo:table-column column-width="{@width}"/>
2913
- </xsl:for-each>
2980
+ <xsl:when test="$isGenerateTableIF = 'true'">
2981
+ <!-- generate IF for table widths -->
2982
+ <!-- example:
2983
+ <tr>
2984
+ <td valign="top" align="left" id="tab-symdu_1_1">
2985
+ <p>Symbol</p>
2986
+ <word id="tab-symdu_1_1_word_1">Symbol</word>
2987
+ </td>
2988
+ <td valign="top" align="left" id="tab-symdu_1_2">
2989
+ <p>Description</p>
2990
+ <word id="tab-symdu_1_2_word_1">Description</word>
2991
+ </td>
2992
+ </tr>
2993
+ -->
2994
+ <xsl:apply-templates select="xalan:nodeset($simple-table)" mode="process_table-if"/>
2995
+
2914
2996
  </xsl:when>
2915
2997
  <xsl:otherwise>
2916
- <xsl:call-template name="insertTableColumnWidth">
2917
- <xsl:with-param name="colwidths" select="$colwidths"/>
2918
- </xsl:call-template>
2919
- </xsl:otherwise>
2920
- </xsl:choose>
2921
2998
 
2922
- <xsl:choose>
2923
- <xsl:when test="not(*[local-name()='tbody']) and *[local-name()='thead']">
2924
- <xsl:apply-templates select="*[local-name()='thead']" mode="process_tbody"/>
2925
- </xsl:when>
2926
- <xsl:otherwise>
2927
- <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 -->
2999
+ <xsl:choose>
3000
+ <xsl:when test="*[local-name()='colgroup']/*[local-name()='col']">
3001
+ <xsl:for-each select="*[local-name()='colgroup']/*[local-name()='col']">
3002
+ <fo:table-column column-width="{@width}"/>
3003
+ </xsl:for-each>
3004
+ </xsl:when>
3005
+ <xsl:otherwise>
3006
+ <xsl:call-template name="insertTableColumnWidth">
3007
+ <xsl:with-param name="colwidths" select="$colwidths"/>
3008
+ </xsl:call-template>
3009
+ </xsl:otherwise>
3010
+ </xsl:choose>
3011
+
3012
+ <xsl:choose>
3013
+ <xsl:when test="not(*[local-name()='tbody']) and *[local-name()='thead']">
3014
+ <xsl:apply-templates select="*[local-name()='thead']" mode="process_tbody"/>
3015
+ </xsl:when>
3016
+ <xsl:otherwise>
3017
+ <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 -->
3018
+ </xsl:otherwise>
3019
+ </xsl:choose>
3020
+
2928
3021
  </xsl:otherwise>
2929
3022
  </xsl:choose>
2930
3023
 
@@ -3027,11 +3120,22 @@
3027
3120
  <xsl:variable name="columns-with-colspan" select="count($table-row/*[@colspan])"/>
3028
3121
  <xsl:value-of select="$columns-count + $sum-colspans - $columns-with-colspan"/>
3029
3122
  </xsl:template><xsl:template name="calculate-column-widths">
3123
+ <xsl:param name="table"/>
3124
+ <xsl:param name="cols-count"/>
3125
+
3126
+ <xsl:call-template name="calculate-column-widths-proportional">
3127
+ <xsl:with-param name="cols-count" select="$cols-count"/>
3128
+ <xsl:with-param name="table" select="$table"/>
3129
+ </xsl:call-template>
3130
+
3131
+ </xsl:template><xsl:template name="calculate-column-widths-proportional">
3030
3132
  <xsl:param name="table"/>
3031
3133
  <xsl:param name="cols-count"/>
3032
3134
  <xsl:param name="curr-col" select="1"/>
3033
3135
  <xsl:param name="width" select="0"/>
3034
3136
 
3137
+ <!-- table=<xsl:copy-of select="$table"/> -->
3138
+
3035
3139
  <xsl:if test="$curr-col &lt;= $cols-count">
3036
3140
  <xsl:variable name="widths">
3037
3141
  <xsl:choose>
@@ -3069,10 +3173,15 @@
3069
3173
  </xsl:for-each>
3070
3174
  </xsl:when>
3071
3175
  <xsl:otherwise>
3072
- <xsl:for-each select="xalan:nodeset($table)/*/tr">
3176
+ <!-- <curr_col><xsl:value-of select="$curr-col"/></curr_col> -->
3177
+
3178
+ <!-- <table><xsl:copy-of select="$table"/></table>
3179
+ -->
3180
+ <xsl:for-each select="xalan:nodeset($table)/*/*[local-name()='tr']">
3073
3181
  <xsl:variable name="td_text">
3074
3182
  <xsl:apply-templates select="td[$curr-col]" mode="td_text"/>
3075
3183
  </xsl:variable>
3184
+ <!-- <td_text><xsl:value-of select="$td_text"/></td_text> -->
3076
3185
  <xsl:variable name="words">
3077
3186
  <xsl:variable name="string_with_added_zerospaces">
3078
3187
  <xsl:call-template name="add-zero-spaces-java">
@@ -3087,6 +3196,7 @@
3087
3196
  <xsl:with-param name="text" select="normalize-space(translate($string_with_added_zerospaces, '​­', ' '))"/> <!-- replace zero-width-space and soft-hyphen to space -->
3088
3197
  </xsl:call-template>
3089
3198
  </xsl:variable>
3199
+ <!-- words=<xsl:copy-of select="$words"/> -->
3090
3200
  <xsl:variable name="max_length">
3091
3201
  <xsl:call-template name="max_length">
3092
3202
  <xsl:with-param name="words" select="xalan:nodeset($words)"/>
@@ -3111,6 +3221,8 @@
3111
3221
  </xsl:choose>
3112
3222
  </xsl:variable>
3113
3223
 
3224
+ <!-- widths=<xsl:copy-of select="$widths"/> -->
3225
+
3114
3226
  <column>
3115
3227
  <xsl:for-each select="xalan:nodeset($widths)//width">
3116
3228
  <xsl:sort select="." data-type="number" order="descending"/>
@@ -3119,33 +3231,327 @@
3119
3231
  </xsl:if>
3120
3232
  </xsl:for-each>
3121
3233
  </column>
3122
- <xsl:call-template name="calculate-column-widths">
3234
+ <xsl:call-template name="calculate-column-widths-proportional">
3123
3235
  <xsl:with-param name="cols-count" select="$cols-count"/>
3124
3236
  <xsl:with-param name="curr-col" select="$curr-col +1"/>
3125
3237
  <xsl:with-param name="table" select="$table"/>
3126
3238
  </xsl:call-template>
3127
3239
  </xsl:if>
3128
- </xsl:template><xsl:template match="*[@keep-together.within-line]/text()" priority="2" mode="td_text">
3240
+ </xsl:template><xsl:template match="*[@keep-together.within-line or local-name() = 'keep-together_within-line']/text()" priority="2" mode="td_text">
3129
3241
  <!-- <xsl:message>DEBUG t1=<xsl:value-of select="."/></xsl:message>
3130
3242
  <xsl:message>DEBUG t2=<xsl:value-of select="java:replaceAll(java:java.lang.String.new(.),'.','X')"/></xsl:message> -->
3131
3243
  <xsl:value-of select="java:replaceAll(java:java.lang.String.new(.),'.','X')"/>
3244
+
3245
+ <!-- if all capitals english letters or digits -->
3246
+ <xsl:if test="normalize-space(translate(., concat($upper,'0123456789'), '')) = ''">
3247
+ <xsl:call-template name="repeat">
3248
+ <xsl:with-param name="char" select="'X'"/>
3249
+ <xsl:with-param name="count" select="string-length(normalize-space(.)) * 0.5"/>
3250
+ </xsl:call-template>
3251
+ </xsl:if>
3132
3252
  </xsl:template><xsl:template match="text()" mode="td_text">
3133
3253
  <xsl:value-of select="translate(., $zero_width_space, ' ')"/><xsl:text> </xsl:text>
3134
3254
  </xsl:template><xsl:template match="*[local-name()='termsource']" mode="td_text">
3135
3255
  <xsl:value-of select="*[local-name()='origin']/@citeas"/>
3136
3256
  </xsl:template><xsl:template match="*[local-name()='link']" mode="td_text">
3137
3257
  <xsl:value-of select="@target"/>
3138
- </xsl:template><xsl:template match="*[local-name()='math']" mode="td_text">
3139
- <xsl:variable name="mathml">
3140
- <xsl:for-each select="*">
3141
- <xsl:if test="local-name() != 'unit' and local-name() != 'prefix' and local-name() != 'dimension' and local-name() != 'quantity'">
3142
- <xsl:copy-of select="."/>
3258
+ </xsl:template><xsl:template match="*[local-name()='math']" mode="td_text" name="math_length">
3259
+ <xsl:if test="$isGenerateTableIF = 'false'">
3260
+ <xsl:variable name="mathml_">
3261
+ <xsl:for-each select="*">
3262
+ <xsl:if test="local-name() != 'unit' and local-name() != 'prefix' and local-name() != 'dimension' and local-name() != 'quantity'">
3263
+ <xsl:copy-of select="."/>
3264
+ </xsl:if>
3265
+ </xsl:for-each>
3266
+ </xsl:variable>
3267
+ <xsl:variable name="mathml" select="xalan:nodeset($mathml_)"/>
3268
+
3269
+ <xsl:variable name="math_text">
3270
+ <xsl:value-of select="normalize-space($mathml)"/>
3271
+ <xsl:for-each select="$mathml//@open"><xsl:value-of select="."/></xsl:for-each>
3272
+ <xsl:for-each select="$mathml//@close"><xsl:value-of select="."/></xsl:for-each>
3273
+ </xsl:variable>
3274
+ <xsl:value-of select="translate($math_text, ' ', '#')"/><!-- mathml images as one 'word' without spaces -->
3275
+ </xsl:if>
3276
+ </xsl:template><xsl:template name="calculate-column-widths-autolayout-algorithm">
3277
+ <xsl:param name="table"/>
3278
+ <xsl:param name="if">false</xsl:param> <!-- via intermediate format -->
3279
+
3280
+ <!-- The algorithm uses two passes through the table data and scales linearly with the size of the table -->
3281
+
3282
+ <!-- In the first pass, line wrapping is disabled, and the user agent keeps track of the minimum and maximum width of each cell. -->
3283
+
3284
+ <!-- Since line wrap has been disabled, paragraphs are treated as long lines unless broken by BR elements. -->
3285
+
3286
+ <!-- get current table id -->
3287
+ <xsl:variable name="table_id" select="@id"/>
3288
+ <!-- find table by id in the file 'table_widths' -->
3289
+ <xsl:variable name="table-if_" select="$table_widths_from_if//table[@id = $table_id]"/>
3290
+ <xsl:variable name="table-if" select="xalan:nodeset($table-if_)"/>
3291
+
3292
+
3293
+ <!-- table='<xsl:copy-of select="$table"/>' -->
3294
+ <!-- table_id='<xsl:value-of select="$table_id"/>\ -->
3295
+ <!-- table-if='<xsl:copy-of select="$table-if"/>' -->
3296
+ <!-- table_widths_from_if='<xsl:copy-of select="$table_widths_from_if"/>' -->
3297
+
3298
+ <xsl:variable name="table_with_cell_widths_">
3299
+ <xsl:choose>
3300
+ <xsl:when test="$if = 'true' and normalize-space($table-if) != ''"> <!-- if we read column's width from IF and there is table in IF -->
3301
+
3302
+ <!-- Example: <column>10</column>
3303
+ <column>11</column>
3304
+ -->
3305
+ <xsl:apply-templates select="$table-if" mode="determine_cell_widths-if"/>
3306
+ </xsl:when>
3307
+ <xsl:otherwise>
3308
+ <xsl:apply-templates select="xalan:nodeset($table)" mode="determine_cell_widths"/>
3309
+ </xsl:otherwise>
3310
+ </xsl:choose>
3311
+ </xsl:variable>
3312
+ <xsl:variable name="table_with_cell_widths" select="xalan:nodeset($table_with_cell_widths_)"/>
3313
+
3314
+ <xsl:if test="$table_if_debug = 'true'">
3315
+ <xsl:copy-of select="$table_with_cell_widths"/>
3316
+ </xsl:if>
3317
+
3318
+
3319
+ <!-- The minimum and maximum cell widths are then used to determine the corresponding minimum and maximum widths for the columns. -->
3320
+
3321
+ <xsl:variable name="column_widths_">
3322
+ <!-- iteration of columns -->
3323
+ <xsl:for-each select="$table_with_cell_widths//tr[1]/td">
3324
+ <xsl:variable name="pos" select="position()"/>
3325
+ <column>
3326
+ <xsl:attribute name="width_max">
3327
+ <xsl:for-each select="ancestor::tbody//tr/td[$pos]/@width_max">
3328
+ <xsl:sort select="." data-type="number" order="descending"/>
3329
+ <xsl:if test="position() = 1"><xsl:value-of select="."/></xsl:if>
3330
+ </xsl:for-each>
3331
+ </xsl:attribute>
3332
+ <xsl:attribute name="width_min">
3333
+ <xsl:for-each select="ancestor::tbody//tr/td[$pos]/@width_min">
3334
+ <xsl:sort select="." data-type="number" order="descending"/>
3335
+ <xsl:if test="position() = 1"><xsl:value-of select="."/></xsl:if>
3336
+ </xsl:for-each>
3337
+ </xsl:attribute>
3338
+ </column>
3339
+ </xsl:for-each>
3340
+ </xsl:variable>
3341
+ <xsl:variable name="column_widths" select="xalan:nodeset($column_widths_)"/>
3342
+
3343
+ <!-- <column_widths>
3344
+ <xsl:copy-of select="$column_widths"/>
3345
+ </column_widths> -->
3346
+
3347
+ <!-- These in turn, are used to find the minimum and maximum width for the table. -->
3348
+ <xsl:variable name="table_widths_">
3349
+ <table>
3350
+ <xsl:attribute name="width_max">
3351
+ <xsl:value-of select="sum($column_widths/column/@width_max)"/>
3352
+ </xsl:attribute>
3353
+ <xsl:attribute name="width_min">
3354
+ <xsl:value-of select="sum($column_widths/column/@width_min)"/>
3355
+ </xsl:attribute>
3356
+ </table>
3357
+ </xsl:variable>
3358
+ <xsl:variable name="table_widths" select="xalan:nodeset($table_widths_)"/>
3359
+
3360
+ <xsl:variable name="page_width">
3361
+ <xsl:choose>
3362
+ <xsl:when test="$if = 'true'"><xsl:value-of select="$table-if/@page-width"/></xsl:when>
3363
+ <xsl:otherwise>75</xsl:otherwise>
3364
+ </xsl:choose>
3365
+ </xsl:variable>
3366
+
3367
+ <xsl:if test="$table_if_debug = 'true'">
3368
+ <table_width>
3369
+ <xsl:copy-of select="$table_widths"/>
3370
+ </table_width>
3371
+ <!-- <debug>$table_widths/@width_min=<xsl:value-of select="$table_widths/table/@width_min"/></debug>
3372
+ <debug>$table_widths/@width_max=<xsl:value-of select="$table_widths/table/@width_max"/></debug>
3373
+ -->
3374
+ <debug>$page_width=<xsl:value-of select="$page_width"/></debug>
3375
+ </xsl:if>
3376
+
3377
+
3378
+ <!-- There are three cases: -->
3379
+ <xsl:choose>
3380
+ <!-- 1. The minimum table width is equal to or wider than the available space -->
3381
+ <xsl:when test="$table_widths/table/@width_min &gt;= $page_width and 1 = 2"> <!-- this condition isn't working see case 3 below -->
3382
+ <!-- call old algorithm -->
3383
+ <case1/>
3384
+ <xsl:variable name="cols-count" select="count(xalan:nodeset($table)/*/tr[1]/td)"/>
3385
+ <xsl:call-template name="calculate-column-widths-proportional">
3386
+ <xsl:with-param name="cols-count" select="$cols-count"/>
3387
+ <xsl:with-param name="table" select="$table"/>
3388
+ </xsl:call-template>
3389
+ </xsl:when>
3390
+ <!-- 2. The maximum table width fits within the available space. In this case, set the columns to their maximum widths. -->
3391
+ <xsl:when test="$table_widths/table/@width_max &lt;= $page_width">
3392
+ <case2/>
3393
+ <autolayout/>
3394
+ <xsl:for-each select="$column_widths/column/@width_max">
3395
+ <column divider="100"><xsl:value-of select="."/></column>
3396
+ </xsl:for-each>
3397
+ </xsl:when>
3398
+ <!-- 3. The maximum width of the table is greater than the available space, but the minimum table width is smaller.
3399
+ In this case, find the difference between the available space and the minimum table width, lets call it W.
3400
+ Lets also call D the difference between maximum and minimum width of the table.
3401
+ For each column, let d be the difference between maximum and minimum width of that column.
3402
+ Now set the column's width to the minimum width plus d times W over D.
3403
+ This makes columns with large differences between minimum and maximum widths wider than columns with smaller differences. -->
3404
+ <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)">
3405
+ <!-- difference between the available space and the minimum table width -->
3406
+ <xsl:variable name="W" select="$page_width - $table_widths/table/@width_min"/>
3407
+ <W><xsl:value-of select="$W"/></W>
3408
+ <!-- difference between maximum and minimum width of the table -->
3409
+ <xsl:variable name="D" select="$table_widths/table/@width_max - $table_widths/table/@width_min"/>
3410
+ <D><xsl:value-of select="$D"/></D>
3411
+ <case3/>
3412
+ <autolayout/>
3413
+ <xsl:if test="$table_widths/table/@width_min &gt;= $page_width">
3414
+ <split_keep-within-line>true</split_keep-within-line>
3143
3415
  </xsl:if>
3416
+ <xsl:for-each select="$column_widths/column">
3417
+ <!-- difference between maximum and minimum width of that column. -->
3418
+ <xsl:variable name="d" select="@width_max - @width_min"/>
3419
+ <d><xsl:value-of select="$d"/></d>
3420
+ <width_min><xsl:value-of select="@width_min"/></width_min>
3421
+ <e><xsl:value-of select="$d * $W div $D"/></e>
3422
+ <!-- set the column's width to the minimum width plus d times W over D. -->
3423
+ <column divider="100">
3424
+ <xsl:value-of select="round(@width_min + $d * $W div $D)"/> <!-- * 10 -->
3425
+ </column>
3426
+ </xsl:for-each>
3427
+
3428
+ </xsl:when>
3429
+ <xsl:otherwise><unknown_case/></xsl:otherwise>
3430
+ </xsl:choose>
3431
+
3432
+
3433
+ </xsl:template><xsl:template match="@*|node()" mode="determine_cell_widths">
3434
+ <xsl:copy>
3435
+ <xsl:apply-templates select="@*|node()" mode="determine_cell_widths"/>
3436
+ </xsl:copy>
3437
+ </xsl:template><xsl:template match="td | th" mode="determine_cell_widths">
3438
+ <xsl:copy>
3439
+ <xsl:copy-of select="@*"/>
3440
+
3441
+ <!-- The maximum width is given by the widest line. -->
3442
+ <xsl:variable name="widths_max">
3443
+ <xsl:for-each select=".//*[local-name() = 'p']">
3444
+ <xsl:call-template name="add_width"/>
3445
+ </xsl:for-each>
3446
+ <xsl:if test="not(*[local-name() = 'p'])">
3447
+ <xsl:call-template name="add_width"/>
3448
+ </xsl:if>
3449
+ </xsl:variable>
3450
+ <xsl:variable name="width_max">
3451
+ <xsl:for-each select="xalan:nodeset($widths_max)//width">
3452
+ <xsl:sort select="." data-type="number" order="descending"/>
3453
+ <xsl:if test="position() = 1"><xsl:value-of select="."/></xsl:if>
3454
+ </xsl:for-each>
3455
+ </xsl:variable>
3456
+ <xsl:attribute name="width_max">
3457
+ <xsl:value-of select="$width_max"/>
3458
+ </xsl:attribute>
3459
+
3460
+ <!-- The minimum width is given by the widest text element (word, image, etc.) -->
3461
+ <!-- To do: image width -->
3462
+ <xsl:variable name="td_text">
3463
+ <xsl:apply-templates select="." mode="td_text"/>
3464
+ </xsl:variable>
3465
+ <xsl:variable name="words">
3466
+ <xsl:variable name="string_with_added_zerospaces">
3467
+ <xsl:call-template name="add-zero-spaces-java">
3468
+ <xsl:with-param name="text" select="$td_text"/>
3469
+ </xsl:call-template>
3470
+ </xsl:variable>
3471
+ <xsl:call-template name="tokenize">
3472
+ <xsl:with-param name="text" select="normalize-space(translate($string_with_added_zerospaces, '​­', ' '))"/> <!-- replace zero-width-space and soft-hyphen to space -->
3473
+ </xsl:call-template>
3474
+ </xsl:variable>
3475
+
3476
+ <xsl:variable name="max_word_length">
3477
+ <xsl:call-template name="max_length">
3478
+ <xsl:with-param name="words" select="xalan:nodeset($words)"/>
3479
+ </xsl:call-template>
3480
+ </xsl:variable>
3481
+ <xsl:variable name="width_min">
3482
+ <xsl:value-of select="$max_word_length"/>
3483
+ </xsl:variable>
3484
+ <xsl:attribute name="width_min">
3485
+ <xsl:value-of select="$width_min"/>
3486
+ </xsl:attribute>
3487
+ <!-- width_max="1" width_min="1.5"> --> <!-- see 'tokenize' template, multiply 1.5 for all latin capitals -->
3488
+ <xsl:if test="$width_min &gt; $width_max">
3489
+ <xsl:attribute name="width_max">
3490
+ <xsl:value-of select="$width_min"/>
3491
+ </xsl:attribute>
3492
+ </xsl:if>
3493
+ <xsl:if test="$width_min = 0">
3494
+ <xsl:attribute name="width_min">1</xsl:attribute>
3495
+ </xsl:if>
3496
+
3497
+ <xsl:apply-templates select="node()" mode="determine_cell_widths"/>
3498
+
3499
+ </xsl:copy>
3500
+ </xsl:template><xsl:template name="add_width">
3501
+ <xsl:variable name="p_text"><xsl:apply-templates select="." mode="td_text"/></xsl:variable>
3502
+ <xsl:variable name="p_text_len_" select="string-length(normalize-space($p_text))"/>
3503
+
3504
+ <xsl:variable name="p_text_len">
3505
+ <xsl:choose>
3506
+ <xsl:when test="normalize-space(translate($p_text, concat($upper,'0123456789'), '')) = ''"> <!-- english word in CAPITAL letters -->
3507
+ <xsl:value-of select="$p_text_len_ * 1.5"/>
3508
+ </xsl:when>
3509
+ <xsl:otherwise><xsl:value-of select="$p_text_len_"/></xsl:otherwise>
3510
+ </xsl:choose>
3511
+ </xsl:variable>
3512
+
3513
+ <xsl:variable name="math_addon_text">
3514
+ <xsl:for-each select=".//*[local-name() = 'math']">
3515
+ <xsl:apply-templates mode="td_text"/>
3144
3516
  </xsl:for-each>
3145
3517
  </xsl:variable>
3518
+ <xsl:variable name="math_addon_length" select="string-length(normalize-space($math_addon_text)) * 0.2"/> <!-- plus 20% -->
3146
3519
 
3147
- <xsl:variable name="math_text" select="normalize-space(xalan:nodeset($mathml))"/>
3148
- <xsl:value-of select="translate($math_text, ' ', '#')"/><!-- mathml images as one 'word' without spaces -->
3520
+ <width><xsl:value-of select="$p_text_len + $math_addon_length"/></width>
3521
+ </xsl:template><xsl:template match="@*|node()" mode="determine_cell_widths-if">
3522
+ <xsl:copy>
3523
+ <xsl:apply-templates select="@*|node()" mode="determine_cell_widths-if"/>
3524
+ </xsl:copy>
3525
+ </xsl:template><xsl:template match="td | th" mode="determine_cell_widths-if">
3526
+ <xsl:copy>
3527
+ <xsl:copy-of select="@*"/>
3528
+
3529
+ <!-- The maximum width is given by the widest line. -->
3530
+ <xsl:attribute name="width_max">
3531
+ <xsl:for-each select="p_len">
3532
+ <xsl:sort select="." data-type="number" order="descending"/>
3533
+ <xsl:if test="position() = 1"><xsl:value-of select="."/></xsl:if>
3534
+ </xsl:for-each>
3535
+ </xsl:attribute>
3536
+
3537
+ <!-- The minimum width is given by the widest text element (word, image, etc.) -->
3538
+ <xsl:variable name="width_min">
3539
+ <xsl:for-each select="word_len">
3540
+ <xsl:sort select="." data-type="number" order="descending"/>
3541
+ <xsl:if test="position() = 1"><xsl:value-of select="."/></xsl:if>
3542
+ </xsl:for-each>
3543
+ </xsl:variable>
3544
+ <xsl:attribute name="width_min">
3545
+ <xsl:value-of select="$width_min"/>
3546
+ </xsl:attribute>
3547
+
3548
+ <xsl:if test="$width_min = 0">
3549
+ <xsl:attribute name="width_min">1</xsl:attribute>
3550
+ </xsl:if>
3551
+
3552
+ <xsl:apply-templates select="node()" mode="determine_cell_widths-if"/>
3553
+
3554
+ </xsl:copy>
3149
3555
  </xsl:template><xsl:template match="*[local-name()='thead']">
3150
3556
  <xsl:param name="cols-count"/>
3151
3557
  <fo:table-header>
@@ -3230,6 +3636,7 @@
3230
3636
  </xsl:for-each>
3231
3637
  </xsl:when>
3232
3638
  <xsl:otherwise>
3639
+ <!-- $colwidths=<xsl:copy-of select="$colwidths"/> -->
3233
3640
  <xsl:call-template name="insertTableColumnWidth">
3234
3641
  <xsl:with-param name="colwidths" select="$colwidths"/>
3235
3642
  </xsl:call-template>
@@ -3309,6 +3716,52 @@
3309
3716
 
3310
3717
  </fo:table-body>
3311
3718
 
3719
+ </xsl:template><xsl:template match="/" mode="process_table-if">
3720
+ <xsl:param name="table_or_dl">table</xsl:param>
3721
+ <xsl:apply-templates mode="process_table-if">
3722
+ <xsl:with-param name="table_or_dl" select="$table_or_dl"/>
3723
+ </xsl:apply-templates>
3724
+ </xsl:template><xsl:template match="*[local-name()='tbody']" mode="process_table-if">
3725
+ <xsl:param name="table_or_dl">table</xsl:param>
3726
+
3727
+ <fo:table-body>
3728
+ <xsl:for-each select="*[local-name() = 'tr']">
3729
+ <xsl:variable name="col_count" select="count(*)"/>
3730
+
3731
+ <!-- iteration for each tr/td -->
3732
+
3733
+ <xsl:choose>
3734
+ <xsl:when test="$table_or_dl = 'table'">
3735
+ <xsl:for-each select="*[local-name() = 'td' or local-name() = 'th']/*">
3736
+ <fo:table-row number-columns-spanned="{$col_count}">
3737
+ <!-- <test_table><xsl:copy-of select="."/></test_table> -->
3738
+ <xsl:call-template name="td"/>
3739
+ </fo:table-row>
3740
+ </xsl:for-each>
3741
+ </xsl:when>
3742
+ <xsl:otherwise> <!-- $table_or_dl = 'dl' -->
3743
+ <xsl:for-each select="*[local-name() = 'td' or local-name() = 'th']">
3744
+ <xsl:variable name="is_dt" select="position() = 1"/>
3745
+
3746
+ <xsl:for-each select="*">
3747
+ <!-- <test><xsl:copy-of select="."/></test> -->
3748
+ <fo:table-row number-columns-spanned="{$col_count}">
3749
+ <xsl:choose>
3750
+ <xsl:when test="$is_dt">
3751
+ <xsl:call-template name="insert_dt_cell"/>
3752
+ </xsl:when>
3753
+ <xsl:otherwise>
3754
+ <xsl:call-template name="insert_dd_cell"/>
3755
+ </xsl:otherwise>
3756
+ </xsl:choose>
3757
+ </fo:table-row>
3758
+ </xsl:for-each>
3759
+ </xsl:for-each>
3760
+ </xsl:otherwise>
3761
+ </xsl:choose>
3762
+
3763
+ </xsl:for-each>
3764
+ </fo:table-body>
3312
3765
  </xsl:template><xsl:template match="*[local-name()='thead']/*[local-name()='tr']" priority="2">
3313
3766
  <fo:table-row xsl:use-attribute-sets="table-header-row-style">
3314
3767
 
@@ -3400,7 +3853,7 @@
3400
3853
  </xsl:choose>
3401
3854
  </xsl:attribute>
3402
3855
  </xsl:if>
3403
- </xsl:template><xsl:template match="*[local-name()='td']">
3856
+ </xsl:template><xsl:template match="*[local-name()='td']" name="td">
3404
3857
  <fo:table-cell xsl:use-attribute-sets="table-cell-style"> <!-- text-align="{@align}" -->
3405
3858
  <xsl:call-template name="setTextAlignment">
3406
3859
  <xsl:with-param name="default">left</xsl:with-param>
@@ -3434,11 +3887,24 @@
3434
3887
 
3435
3888
  <xsl:call-template name="setTableCellAttributes"/>
3436
3889
 
3890
+ <xsl:if test="$isGenerateTableIF = 'true'">
3891
+ <xsl:attribute name="border">1pt solid black</xsl:attribute> <!-- border is mandatory, to determine page width -->
3892
+ <xsl:attribute name="text-align">left</xsl:attribute>
3893
+ </xsl:if>
3894
+
3437
3895
  <fo:block>
3438
3896
 
3897
+ <xsl:if test="$isGenerateTableIF = 'true'">
3898
+ <xsl:attribute name="id"><xsl:value-of select="@id"/></xsl:attribute>
3899
+ </xsl:if>
3900
+
3901
+
3439
3902
 
3440
3903
 
3441
3904
  <xsl:apply-templates/>
3905
+
3906
+ <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"/> -->
3907
+
3442
3908
  </fo:block>
3443
3909
  </fo:table-cell>
3444
3910
  </xsl:template><xsl:template match="*[local-name()='table']/*[local-name()='note']" priority="2">
@@ -3635,9 +4101,9 @@
3635
4101
  <!-- current hierarchy is 'figure' element -->
3636
4102
  <xsl:variable name="following_dl_colwidths">
3637
4103
  <xsl:if test="*[local-name() = 'dl']"><!-- if there is a 'dl', then set the same columns width as for 'dl' -->
3638
- <xsl:variable name="html-table">
3639
- <xsl:variable name="doc_ns">
3640
-
4104
+ <xsl:variable name="simple-table">
4105
+ <!-- <xsl:variable name="doc_ns">
4106
+ <xsl:if test="$namespace = 'bipm'">bipm</xsl:if>
3641
4107
  </xsl:variable>
3642
4108
  <xsl:variable name="ns">
3643
4109
  <xsl:choose>
@@ -3648,7 +4114,7 @@
3648
4114
  <xsl:value-of select="substring-before(name(/*), '-')"/>
3649
4115
  </xsl:otherwise>
3650
4116
  </xsl:choose>
3651
- </xsl:variable>
4117
+ </xsl:variable> -->
3652
4118
 
3653
4119
  <xsl:for-each select="*[local-name() = 'dl'][1]">
3654
4120
  <tbody>
@@ -3659,7 +4125,7 @@
3659
4125
 
3660
4126
  <xsl:call-template name="calculate-column-widths">
3661
4127
  <xsl:with-param name="cols-count" select="2"/>
3662
- <xsl:with-param name="table" select="$html-table"/>
4128
+ <xsl:with-param name="table" select="$simple-table"/>
3663
4129
  </xsl:call-template>
3664
4130
 
3665
4131
  </xsl:if>
@@ -3842,7 +4308,18 @@
3842
4308
 
3843
4309
 
3844
4310
 
4311
+
4312
+ <xsl:if test="$isGenerateTableIF = 'true'">
4313
+ <!-- to determine start of table -->
4314
+ <fo:block id="{concat('table_if_start_',@id)}" keep-with-next="always" font-size="1pt">Start table '<xsl:value-of select="@id"/>'.</fo:block>
4315
+ </xsl:if>
4316
+
3845
4317
  <fo:table width="95%" table-layout="fixed">
4318
+
4319
+ <xsl:if test="$isGenerateTableIF = 'true'">
4320
+ <xsl:attribute name="wrap-option">no-wrap</xsl:attribute>
4321
+ </xsl:if>
4322
+
3846
4323
 
3847
4324
  <xsl:choose>
3848
4325
  <xsl:when test="normalize-space($key_iso) = 'true' and $parent = 'formula'"/>
@@ -3851,52 +4328,130 @@
3851
4328
 
3852
4329
  </xsl:when>
3853
4330
  </xsl:choose>
3854
- <!-- create virtual html table for dl/[dt and dd] -->
3855
- <xsl:variable name="html-table">
3856
- <xsl:variable name="doc_ns">
4331
+
4332
+
4333
+ <xsl:choose>
4334
+ <xsl:when test="$isGenerateTableIF = 'true'">
4335
+ <!-- generate IF for table widths -->
4336
+ <!-- example:
4337
+ <tr>
4338
+ <td valign="top" align="left" id="tab-symdu_1_1">
4339
+ <p>Symbol</p>
4340
+ <word id="tab-symdu_1_1_word_1">Symbol</word>
4341
+ </td>
4342
+ <td valign="top" align="left" id="tab-symdu_1_2">
4343
+ <p>Description</p>
4344
+ <word id="tab-symdu_1_2_word_1">Description</word>
4345
+ </td>
4346
+ </tr>
4347
+ -->
3857
4348
 
3858
- </xsl:variable>
3859
- <xsl:variable name="ns">
3860
- <xsl:choose>
3861
- <xsl:when test="normalize-space($doc_ns) != ''">
3862
- <xsl:value-of select="normalize-space($doc_ns)"/>
3863
- </xsl:when>
3864
- <xsl:otherwise>
3865
- <xsl:value-of select="substring-before(name(/*), '-')"/>
3866
- </xsl:otherwise>
3867
- </xsl:choose>
3868
- </xsl:variable>
3869
- <tbody>
3870
- <xsl:apply-templates mode="dl"/>
3871
- </tbody>
3872
- </xsl:variable>
3873
- <!-- DEBUG: html-table<xsl:copy-of select="$html-table"/> -->
3874
- <xsl:variable name="colwidths">
3875
- <xsl:call-template name="calculate-column-widths">
3876
- <xsl:with-param name="cols-count" select="2"/>
3877
- <xsl:with-param name="table" select="$html-table"/>
3878
- </xsl:call-template>
3879
- </xsl:variable>
3880
- <!-- DEBUG: colwidths=<xsl:copy-of select="$colwidths"/> -->
3881
- <xsl:variable name="maxlength_dt">
3882
- <xsl:call-template name="getMaxLength_dt"/>
3883
- </xsl:variable>
3884
- <xsl:variable name="isContainsKeepTogetherTag_">
3885
- false
3886
- </xsl:variable>
3887
- <xsl:variable name="isContainsKeepTogetherTag" select="normalize-space($isContainsKeepTogetherTag_)"/>
3888
- <!-- isContainsExpressReference=<xsl:value-of select="$isContainsExpressReference"/> -->
3889
- <xsl:call-template name="setColumnWidth_dl">
3890
- <xsl:with-param name="colwidths" select="$colwidths"/>
3891
- <xsl:with-param name="maxlength_dt" select="$maxlength_dt"/>
3892
- <xsl:with-param name="isContainsKeepTogetherTag" select="$isContainsKeepTogetherTag"/>
3893
- </xsl:call-template>
4349
+ <!-- create virtual html table for dl/[dt and dd] -->
4350
+ <xsl:variable name="simple-table">
4351
+
4352
+ <xsl:variable name="dl_table">
4353
+ <tbody>
4354
+ <xsl:apply-templates mode="dl_if">
4355
+ <xsl:with-param name="id" select="@id"/>
4356
+ </xsl:apply-templates>
4357
+ </tbody>
4358
+ </xsl:variable>
4359
+
4360
+ <!-- dl_table='<xsl:copy-of select="$dl_table"/>' -->
4361
+
4362
+ <!-- Step: replace <br/> to <p>...</p> -->
4363
+ <xsl:variable name="table_without_br">
4364
+ <xsl:apply-templates select="xalan:nodeset($dl_table)" mode="table-without-br"/>
4365
+ </xsl:variable>
4366
+
4367
+ <!-- table_without_br='<xsl:copy-of select="$table_without_br"/>' -->
4368
+
4369
+ <!-- Step: add id to each cell -->
4370
+ <!-- add <word>...</word> for each word, image, math -->
4371
+ <xsl:variable name="simple-table-id">
4372
+ <xsl:apply-templates select="xalan:nodeset($table_without_br)" mode="simple-table-id">
4373
+ <xsl:with-param name="id" select="@id"/>
4374
+ </xsl:apply-templates>
4375
+ </xsl:variable>
4376
+
4377
+ <!-- simple-table-id='<xsl:copy-of select="$simple-table-id"/>' -->
4378
+
4379
+ <xsl:copy-of select="xalan:nodeset($simple-table-id)"/>
4380
+
4381
+ </xsl:variable>
4382
+
4383
+ <!-- DEBUG: simple-table<xsl:copy-of select="$simple-table"/> -->
4384
+
4385
+ <xsl:apply-templates select="xalan:nodeset($simple-table)" mode="process_table-if">
4386
+ <xsl:with-param name="table_or_dl">dl</xsl:with-param>
4387
+ </xsl:apply-templates>
4388
+
4389
+ </xsl:when>
4390
+ <xsl:otherwise>
3894
4391
 
3895
- <fo:table-body>
3896
- <xsl:apply-templates>
3897
- <xsl:with-param name="key_iso" select="normalize-space($key_iso)"/>
3898
- </xsl:apply-templates>
3899
- </fo:table-body>
4392
+ <xsl:variable name="simple-table">
4393
+
4394
+ <xsl:variable name="dl_table">
4395
+ <tbody>
4396
+ <xsl:apply-templates mode="dl">
4397
+ <xsl:with-param name="id" select="@id"/>
4398
+ </xsl:apply-templates>
4399
+ </tbody>
4400
+ </xsl:variable>
4401
+
4402
+ <xsl:copy-of select="$dl_table"/>
4403
+ </xsl:variable>
4404
+
4405
+ <xsl:variable name="colwidths">
4406
+ <xsl:call-template name="calculate-column-widths">
4407
+ <xsl:with-param name="cols-count" select="2"/>
4408
+ <xsl:with-param name="table" select="$simple-table"/>
4409
+ </xsl:call-template>
4410
+ </xsl:variable>
4411
+
4412
+ <!-- <xsl:text disable-output-escaping="yes">&lt;!- -</xsl:text>
4413
+ DEBUG
4414
+ colwidths=<xsl:copy-of select="$colwidths"/>
4415
+ <xsl:text disable-output-escaping="yes">- -&gt;</xsl:text> -->
4416
+
4417
+ <!-- colwidths=<xsl:copy-of select="$colwidths"/> -->
4418
+
4419
+ <xsl:variable name="maxlength_dt">
4420
+ <xsl:call-template name="getMaxLength_dt"/>
4421
+ </xsl:variable>
4422
+
4423
+ <xsl:variable name="isContainsKeepTogetherTag_">
4424
+ false
4425
+ </xsl:variable>
4426
+ <xsl:variable name="isContainsKeepTogetherTag" select="normalize-space($isContainsKeepTogetherTag_)"/>
4427
+ <!-- isContainsExpressReference=<xsl:value-of select="$isContainsExpressReference"/> -->
4428
+
4429
+
4430
+ <xsl:call-template name="setColumnWidth_dl">
4431
+ <xsl:with-param name="colwidths" select="$colwidths"/>
4432
+ <xsl:with-param name="maxlength_dt" select="$maxlength_dt"/>
4433
+ <xsl:with-param name="isContainsKeepTogetherTag" select="$isContainsKeepTogetherTag"/>
4434
+ </xsl:call-template>
4435
+
4436
+ <fo:table-body>
4437
+
4438
+ <!-- DEBUG -->
4439
+ <xsl:if test="$table_if_debug = 'true'">
4440
+ <fo:table-row>
4441
+ <fo:table-cell number-columns-spanned="2" font-size="60%">
4442
+ <xsl:apply-templates select="xalan:nodeset($colwidths)" mode="print_as_xml"/>
4443
+ </fo:table-cell>
4444
+ </fo:table-row>
4445
+ </xsl:if>
4446
+
4447
+ <xsl:apply-templates>
4448
+ <xsl:with-param name="key_iso" select="normalize-space($key_iso)"/>
4449
+ <xsl:with-param name="split_keep-within-line" select="xalan:nodeset($colwidths)/split_keep-within-line"/>
4450
+ </xsl:apply-templates>
4451
+
4452
+ </fo:table-body>
4453
+ </xsl:otherwise>
4454
+ </xsl:choose>
3900
4455
  </fo:table>
3901
4456
  </fo:block>
3902
4457
  </fo:block>
@@ -3907,6 +4462,9 @@
3907
4462
  <xsl:param name="colwidths"/>
3908
4463
  <xsl:param name="maxlength_dt"/>
3909
4464
  <xsl:param name="isContainsKeepTogetherTag"/>
4465
+
4466
+ <!-- <colwidths><xsl:copy-of select="$colwidths"/></colwidths> -->
4467
+
3910
4468
  <xsl:choose>
3911
4469
  <xsl:when test="ancestor::*[local-name()='dl']"><!-- second level, i.e. inlined table -->
3912
4470
  <fo:table-column column-width="50%"/>
@@ -3914,6 +4472,11 @@
3914
4472
  </xsl:when>
3915
4473
  <xsl:otherwise>
3916
4474
  <xsl:choose>
4475
+ <xsl:when test="xalan:nodeset($colwidths)/autolayout">
4476
+ <xsl:call-template name="insertTableColumnWidth">
4477
+ <xsl:with-param name="colwidths" select="$colwidths"/>
4478
+ </xsl:call-template>
4479
+ </xsl:when>
3917
4480
  <xsl:when test="$isContainsKeepTogetherTag">
3918
4481
  <xsl:call-template name="insertTableColumnWidth">
3919
4482
  <xsl:with-param name="colwidths" select="$colwidths"/>
@@ -3958,13 +4521,19 @@
3958
4521
  </xsl:choose>
3959
4522
  </xsl:template><xsl:template name="insertTableColumnWidth">
3960
4523
  <xsl:param name="colwidths"/>
4524
+
3961
4525
  <xsl:for-each select="xalan:nodeset($colwidths)//column">
3962
4526
  <xsl:choose>
3963
4527
  <xsl:when test=". = 1 or . = 0">
3964
4528
  <fo:table-column column-width="proportional-column-width(2)"/>
3965
4529
  </xsl:when>
3966
4530
  <xsl:otherwise>
3967
- <fo:table-column column-width="proportional-column-width({.})"/>
4531
+ <!-- <fo:table-column column-width="proportional-column-width({.})"/> -->
4532
+ <xsl:variable name="divider">
4533
+ <xsl:value-of select="@divider"/>
4534
+ <xsl:if test="not(@divider)">1</xsl:if>
4535
+ </xsl:variable>
4536
+ <fo:table-column column-width="proportional-column-width({round(. div $divider)})"/>
3968
4537
  </xsl:otherwise>
3969
4538
  </xsl:choose>
3970
4539
  </xsl:for-each>
@@ -4026,11 +4595,19 @@
4026
4595
  </fo:table-cell>
4027
4596
  </fo:table-row>
4028
4597
  </xsl:template><xsl:template match="*[local-name()='dt']" mode="dl">
4598
+ <xsl:param name="id"/>
4599
+ <xsl:variable name="row_number" select="count(preceding-sibling::*[local-name()='dt']) + 1"/>
4029
4600
  <tr>
4030
4601
  <td>
4602
+ <xsl:attribute name="id">
4603
+ <xsl:value-of select="concat($id,'_',$row_number,'_1')"/>
4604
+ </xsl:attribute>
4031
4605
  <xsl:apply-templates/>
4032
4606
  </td>
4033
4607
  <td>
4608
+ <xsl:attribute name="id">
4609
+ <xsl:value-of select="concat($id,'_',$row_number,'_2')"/>
4610
+ </xsl:attribute>
4034
4611
 
4035
4612
  <xsl:apply-templates select="following-sibling::*[local-name()='dd'][1]">
4036
4613
  <xsl:with-param name="process">true</xsl:with-param>
@@ -4041,47 +4618,117 @@
4041
4618
 
4042
4619
  </xsl:template><xsl:template match="*[local-name()='dt']">
4043
4620
  <xsl:param name="key_iso"/>
4621
+ <xsl:param name="split_keep-within-line"/>
4044
4622
 
4045
4623
  <fo:table-row xsl:use-attribute-sets="dt-row-style">
4046
- <fo:table-cell>
4624
+ <xsl:call-template name="insert_dt_cell">
4625
+ <xsl:with-param name="key_iso" select="$key_iso"/>
4626
+ <xsl:with-param name="split_keep-within-line" select="$split_keep-within-line"/>
4627
+ </xsl:call-template>
4628
+ <xsl:for-each select="following-sibling::*[local-name()='dd'][1]">
4629
+ <xsl:call-template name="insert_dd_cell">
4630
+ <xsl:with-param name="split_keep-within-line" select="$split_keep-within-line"/>
4631
+ </xsl:call-template>
4632
+ </xsl:for-each>
4633
+ </fo:table-row>
4634
+ </xsl:template><xsl:template name="insert_dt_cell">
4635
+ <xsl:param name="key_iso"/>
4636
+ <xsl:param name="split_keep-within-line"/>
4637
+ <fo:table-cell xsl:use-attribute-sets="dt-cell-style">
4638
+
4639
+ <xsl:if test="$isGenerateTableIF = 'true'">
4640
+ <!-- border is mandatory, to calculate real width -->
4641
+ <xsl:attribute name="border">0.1pt solid black</xsl:attribute>
4642
+ <xsl:attribute name="text-align">left</xsl:attribute>
4643
+ </xsl:if>
4644
+
4645
+
4646
+ <fo:block xsl:use-attribute-sets="dt-block-style">
4647
+ <xsl:copy-of select="@id"/>
4648
+
4649
+ <xsl:if test="normalize-space($key_iso) = 'true'">
4650
+ <xsl:attribute name="margin-top">0</xsl:attribute>
4651
+ </xsl:if>
4652
+
4653
+
4654
+
4655
+ <xsl:apply-templates>
4656
+ <xsl:with-param name="split_keep-within-line" select="$split_keep-within-line"/>
4657
+ </xsl:apply-templates>
4658
+
4659
+ <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"/> -->
4660
+
4661
+ </fo:block>
4662
+ </fo:table-cell>
4663
+ </xsl:template><xsl:template name="insert_dd_cell">
4664
+ <xsl:param name="split_keep-within-line"/>
4665
+ <fo:table-cell xsl:use-attribute-sets="dd-cell-style">
4666
+
4667
+ <xsl:if test="$isGenerateTableIF = 'true'">
4668
+ <!-- border is mandatory, to calculate real width -->
4669
+ <xsl:attribute name="border">0.1pt solid black</xsl:attribute>
4670
+ </xsl:if>
4671
+
4672
+ <fo:block>
4673
+
4674
+ <xsl:if test="$isGenerateTableIF = 'true'">
4675
+ <xsl:attribute name="id"><xsl:value-of select="@id"/></xsl:attribute>
4676
+ </xsl:if>
4677
+
4047
4678
 
4048
- <fo:block xsl:use-attribute-sets="dt-style">
4049
- <xsl:copy-of select="@id"/>
4050
-
4051
- <xsl:if test="normalize-space($key_iso) = 'true'">
4052
- <xsl:attribute name="margin-top">0</xsl:attribute>
4053
- </xsl:if>
4054
-
4055
-
4056
-
4057
- <xsl:apply-templates/>
4058
- </fo:block>
4059
- </fo:table-cell>
4060
- <fo:table-cell>
4061
- <fo:block>
4062
-
4063
4679
 
4064
- <xsl:apply-templates select="following-sibling::*[local-name()='dd'][1]">
4065
- <xsl:with-param name="process">true</xsl:with-param>
4066
- </xsl:apply-templates>
4067
- </fo:block>
4068
- </fo:table-cell>
4069
- </fo:table-row>
4680
+ <xsl:choose>
4681
+ <xsl:when test="$isGenerateTableIF = 'true'">
4682
+ <xsl:apply-templates> <!-- following-sibling::*[local-name()='dd'][1] -->
4683
+ <xsl:with-param name="process">true</xsl:with-param>
4684
+ </xsl:apply-templates>
4685
+ </xsl:when>
4686
+ <xsl:otherwise>
4687
+ <xsl:apply-templates select="."> <!-- following-sibling::*[local-name()='dd'][1] -->
4688
+ <xsl:with-param name="process">true</xsl:with-param>
4689
+ <xsl:with-param name="split_keep-within-line" select="$split_keep-within-line"/>
4690
+ </xsl:apply-templates>
4691
+ </xsl:otherwise>
4692
+
4693
+ </xsl:choose>
4694
+
4695
+ <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"/> -->
4696
+
4697
+ </fo:block>
4698
+ </fo:table-cell>
4070
4699
  </xsl:template><xsl:template match="*[local-name()='dd']" mode="dl"/><xsl:template match="*[local-name()='dd']" mode="dl_process">
4071
4700
  <xsl:apply-templates/>
4072
4701
  </xsl:template><xsl:template match="*[local-name()='dd']">
4073
4702
  <xsl:param name="process">false</xsl:param>
4703
+ <xsl:param name="split_keep-within-line"/>
4074
4704
  <xsl:if test="$process = 'true'">
4075
4705
  <xsl:apply-templates select="@language"/>
4076
- <xsl:apply-templates/>
4706
+ <xsl:apply-templates>
4707
+ <xsl:with-param name="split_keep-within-line" select="$split_keep-within-line"/>
4708
+ </xsl:apply-templates>
4077
4709
  </xsl:if>
4078
4710
  </xsl:template><xsl:template match="*[local-name()='dd']/*[local-name()='p']" mode="inline">
4079
4711
  <fo:inline><xsl:text> </xsl:text><xsl:apply-templates/></fo:inline>
4080
- </xsl:template><xsl:template match="*[local-name()='em']">
4712
+ </xsl:template><xsl:template match="*[local-name()='dt']" mode="dl_if">
4713
+ <xsl:param name="id"/>
4714
+ <xsl:variable name="row_number" select="count(preceding-sibling::*[local-name()='dt']) + 1"/>
4715
+ <tr>
4716
+ <td>
4717
+ <xsl:copy-of select="node()"/>
4718
+ </td>
4719
+ <td>
4720
+
4721
+ <xsl:copy-of select="following-sibling::*[local-name()='dd'][1]/node()"/>
4722
+
4723
+ </td>
4724
+ </tr>
4725
+
4726
+ </xsl:template><xsl:template match="*[local-name()='dd']" mode="dl_if"/><xsl:template match="*[local-name()='em']">
4081
4727
  <fo:inline font-style="italic">
4082
4728
  <xsl:apply-templates/>
4083
4729
  </fo:inline>
4084
4730
  </xsl:template><xsl:template match="*[local-name()='strong'] | *[local-name()='b']">
4731
+ <xsl:param name="split_keep-within-line"/>
4085
4732
  <fo:inline font-weight="bold">
4086
4733
 
4087
4734
  <xsl:if test="not(parent::*[local-name() = 'termsource'])">
@@ -4089,7 +4736,9 @@
4089
4736
  <xsl:attribute name="color">black</xsl:attribute>
4090
4737
  </xsl:if>
4091
4738
 
4092
- <xsl:apply-templates/>
4739
+ <xsl:apply-templates>
4740
+ <xsl:with-param name="split_keep-within-line" select="$split_keep-within-line"/>
4741
+ </xsl:apply-templates>
4093
4742
  </fo:inline>
4094
4743
  </xsl:template><xsl:template match="*[local-name()='padding']">
4095
4744
  <fo:inline padding-right="{@value}"> </fo:inline>
@@ -4295,6 +4944,10 @@
4295
4944
  <xsl:param name="text"/>
4296
4945
  <xsl:param name="separator" select="' '"/>
4297
4946
  <xsl:choose>
4947
+
4948
+ <xsl:when test="$isGenerateTableIF = 'true' and not(contains($text, $separator))">
4949
+ <word><xsl:value-of select="normalize-space($text)"/></word>
4950
+ </xsl:when>
4298
4951
  <xsl:when test="not(contains($text, $separator))">
4299
4952
  <word>
4300
4953
  <xsl:variable name="len_str_tmp" select="string-length(normalize-space($text))"/>
@@ -4339,13 +4992,66 @@
4339
4992
  </xsl:when>
4340
4993
  <xsl:otherwise>
4341
4994
  <word>
4342
- <xsl:value-of select="string-length(normalize-space(substring-before($text, $separator)))"/>
4995
+ <xsl:variable name="word" select="normalize-space(substring-before($text, $separator))"/>
4996
+ <xsl:choose>
4997
+ <xsl:when test="$isGenerateTableIF = 'true'">
4998
+ <xsl:value-of select="$word"/>
4999
+ </xsl:when>
5000
+ <xsl:otherwise>
5001
+ <xsl:value-of select="string-length($word)"/>
5002
+ </xsl:otherwise>
5003
+ </xsl:choose>
4343
5004
  </word>
4344
5005
  <xsl:call-template name="tokenize">
4345
5006
  <xsl:with-param name="text" select="substring-after($text, $separator)"/>
4346
5007
  </xsl:call-template>
4347
5008
  </xsl:otherwise>
4348
5009
  </xsl:choose>
5010
+ </xsl:template><xsl:template name="tokenize_with_tags">
5011
+ <xsl:param name="tags"/>
5012
+ <xsl:param name="text"/>
5013
+ <xsl:param name="separator" select="' '"/>
5014
+ <xsl:choose>
5015
+
5016
+ <xsl:when test="not(contains($text, $separator))">
5017
+ <word>
5018
+ <xsl:call-template name="enclose_text_in_tags">
5019
+ <xsl:with-param name="text" select="normalize-space($text)"/>
5020
+ <xsl:with-param name="tags" select="$tags"/>
5021
+ </xsl:call-template>
5022
+ </word>
5023
+ </xsl:when>
5024
+ <xsl:otherwise>
5025
+ <word>
5026
+ <xsl:call-template name="enclose_text_in_tags">
5027
+ <xsl:with-param name="text" select="normalize-space(substring-before($text, $separator))"/>
5028
+ <xsl:with-param name="tags" select="$tags"/>
5029
+ </xsl:call-template>
5030
+ </word>
5031
+ <xsl:call-template name="tokenize_with_tags">
5032
+ <xsl:with-param name="text" select="substring-after($text, $separator)"/>
5033
+ </xsl:call-template>
5034
+ </xsl:otherwise>
5035
+ </xsl:choose>
5036
+ </xsl:template><xsl:template name="enclose_text_in_tags">
5037
+ <xsl:param name="text"/>
5038
+ <xsl:param name="tags"/>
5039
+ <xsl:param name="num">1</xsl:param> <!-- default (start) value -->
5040
+
5041
+ <xsl:variable name="tag_name" select="normalize-space(xalan:nodeset($tags)//tag[$num])"/>
5042
+
5043
+ <xsl:choose>
5044
+ <xsl:when test="$tag_name = ''"><xsl:value-of select="$text"/></xsl:when>
5045
+ <xsl:otherwise>
5046
+ <xsl:element name="{$tag_name}">
5047
+ <xsl:call-template name="enclose_text_in_tags">
5048
+ <xsl:with-param name="text" select="$text"/>
5049
+ <xsl:with-param name="tags" select="$tags"/>
5050
+ <xsl:with-param name="num" select="$num + 1"/>
5051
+ </xsl:call-template>
5052
+ </xsl:element>
5053
+ </xsl:otherwise>
5054
+ </xsl:choose>
4349
5055
  </xsl:template><xsl:template name="max_length">
4350
5056
  <xsl:param name="words"/>
4351
5057
  <xsl:for-each select="$words//word">
@@ -4446,12 +5152,19 @@
4446
5152
  </xsl:otherwise>
4447
5153
  </xsl:choose>
4448
5154
  </xsl:template><xsl:template name="getSimpleTable">
5155
+ <xsl:param name="id"/>
5156
+
4449
5157
  <xsl:variable name="simple-table">
4450
5158
 
5159
+ <!-- Step 0. replace <br/> to <p>...</p> -->
5160
+ <xsl:variable name="table_without_br">
5161
+ <xsl:apply-templates mode="table-without-br"/>
5162
+ </xsl:variable>
5163
+
4451
5164
  <!-- Step 1. colspan processing -->
4452
5165
  <xsl:variable name="simple-table-colspan">
4453
5166
  <tbody>
4454
- <xsl:apply-templates mode="simple-table-colspan"/>
5167
+ <xsl:apply-templates select="xalan:nodeset($table_without_br)" mode="simple-table-colspan"/>
4455
5168
  </tbody>
4456
5169
  </xsl:variable>
4457
5170
 
@@ -4460,10 +5173,67 @@
4460
5173
  <xsl:apply-templates select="xalan:nodeset($simple-table-colspan)" mode="simple-table-rowspan"/>
4461
5174
  </xsl:variable>
4462
5175
 
4463
- <xsl:copy-of select="xalan:nodeset($simple-table-rowspan)"/>
4464
-
5176
+ <!-- Step 3: add id to each cell -->
5177
+ <!-- add <word>...</word> for each word, image, math -->
5178
+ <xsl:variable name="simple-table-id">
5179
+ <xsl:apply-templates select="xalan:nodeset($simple-table-rowspan)" mode="simple-table-id">
5180
+ <xsl:with-param name="id" select="$id"/>
5181
+ </xsl:apply-templates>
5182
+ </xsl:variable>
5183
+
5184
+ <xsl:copy-of select="xalan:nodeset($simple-table-id)"/>
5185
+
4465
5186
  </xsl:variable>
4466
5187
  <xsl:copy-of select="$simple-table"/>
5188
+ </xsl:template><xsl:template match="@*|node()" mode="table-without-br">
5189
+ <xsl:copy>
5190
+ <xsl:apply-templates select="@*|node()" mode="table-without-br"/>
5191
+ </xsl:copy>
5192
+ </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">
5193
+ <xsl:copy>
5194
+ <xsl:copy-of select="@*"/>
5195
+ <p>
5196
+ <xsl:copy-of select="node()"/>
5197
+ </p>
5198
+ </xsl:copy>
5199
+ </xsl:template><xsl:template match="*[local-name()='th' or local-name()='td'][*[local-name()='br']]" mode="table-without-br">
5200
+ <xsl:copy>
5201
+ <xsl:copy-of select="@*"/>
5202
+ <xsl:for-each select="*[local-name()='br']">
5203
+ <xsl:variable name="current_id" select="generate-id()"/>
5204
+ <p>
5205
+ <xsl:for-each select="preceding-sibling::node()[following-sibling::*[local-name() = 'br'][1][generate-id() = $current_id]][not(local-name() = 'br')]">
5206
+ <xsl:copy-of select="."/>
5207
+ </xsl:for-each>
5208
+ </p>
5209
+ <xsl:if test="not(following-sibling::*[local-name() = 'br'])">
5210
+ <p>
5211
+ <xsl:for-each select="following-sibling::node()">
5212
+ <xsl:copy-of select="."/>
5213
+ </xsl:for-each>
5214
+ </p>
5215
+ </xsl:if>
5216
+ </xsl:for-each>
5217
+ </xsl:copy>
5218
+ </xsl:template><xsl:template match="*[local-name()='th' or local-name()='td']/*[local-name() = 'p'][*[local-name()='br']]" mode="table-without-br">
5219
+ <xsl:for-each select="*[local-name()='br']">
5220
+ <xsl:variable name="current_id" select="generate-id()"/>
5221
+ <p>
5222
+ <xsl:for-each select="preceding-sibling::node()[following-sibling::*[local-name() = 'br'][1][generate-id() = $current_id]][not(local-name() = 'br')]">
5223
+ <xsl:copy-of select="."/>
5224
+ </xsl:for-each>
5225
+ </p>
5226
+ <xsl:if test="not(following-sibling::*[local-name() = 'br'])">
5227
+ <p>
5228
+ <xsl:for-each select="following-sibling::node()">
5229
+ <xsl:copy-of select="."/>
5230
+ </xsl:for-each>
5231
+ </p>
5232
+ </xsl:if>
5233
+ </xsl:for-each>
5234
+ </xsl:template><xsl:template match="text()[not(ancestor::*[local-name() = 'sourcecode'])]" mode="table-without-br">
5235
+ <xsl:variable name="text" select="translate(.,'&#9;&#10;&#13;','')"/>
5236
+ <xsl:value-of select="java:replaceAll(java:java.lang.String.new($text),' {2,}',' ')"/>
4467
5237
  </xsl:template><xsl:template match="*[local-name()='thead'] | *[local-name()='tbody']" mode="simple-table-colspan">
4468
5238
  <xsl:apply-templates mode="simple-table-colspan"/>
4469
5239
  </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">
@@ -4553,6 +5323,126 @@
4553
5323
  <xsl:apply-templates select="following-sibling::tr[1]" mode="simple-table-rowspan">
4554
5324
  <xsl:with-param name="previousRow" select="$newRow"/>
4555
5325
  </xsl:apply-templates>
5326
+ </xsl:template><xsl:template match="/" mode="simple-table-id">
5327
+ <xsl:param name="id"/>
5328
+ <xsl:variable name="id_prefixed" select="concat('table_if_',$id)"/> <!-- table id prefixed by 'table_if_' to simple search in IF -->
5329
+ <xsl:apply-templates select="@*|node()" mode="simple-table-id">
5330
+ <xsl:with-param name="id" select="$id_prefixed"/>
5331
+ </xsl:apply-templates>
5332
+ </xsl:template><xsl:template match="@*|node()" mode="simple-table-id">
5333
+ <xsl:param name="id"/>
5334
+ <xsl:copy>
5335
+ <xsl:apply-templates select="@*|node()" mode="simple-table-id">
5336
+ <xsl:with-param name="id" select="$id"/>
5337
+ </xsl:apply-templates>
5338
+ </xsl:copy>
5339
+ </xsl:template><xsl:template match="*[local-name()='tbody']" mode="simple-table-id">
5340
+ <xsl:param name="id"/>
5341
+ <xsl:copy>
5342
+ <xsl:copy-of select="@*"/>
5343
+ <xsl:attribute name="id"><xsl:value-of select="$id"/></xsl:attribute>
5344
+ <xsl:apply-templates select="node()" mode="simple-table-id">
5345
+ <xsl:with-param name="id" select="$id"/>
5346
+ </xsl:apply-templates>
5347
+ </xsl:copy>
5348
+ </xsl:template><xsl:template match="*[local-name()='th' or local-name()='td']" mode="simple-table-id">
5349
+ <xsl:param name="id"/>
5350
+ <xsl:copy>
5351
+ <xsl:copy-of select="@*"/>
5352
+ <xsl:variable name="row_number" select="count(../preceding-sibling::*) + 1"/>
5353
+ <xsl:variable name="col_number" select="count(preceding-sibling::*) + 1"/>
5354
+ <xsl:attribute name="id">
5355
+ <xsl:value-of select="concat($id,'_',$row_number,'_',$col_number)"/>
5356
+ </xsl:attribute>
5357
+
5358
+ <xsl:for-each select="*[local-name() = 'p']">
5359
+ <xsl:copy>
5360
+ <xsl:copy-of select="@*"/>
5361
+ <xsl:variable name="p_num" select="count(preceding-sibling::*[local-name() = 'p']) + 1"/>
5362
+ <xsl:attribute name="id">
5363
+ <xsl:value-of select="concat($id,'_',$row_number,'_',$col_number,'_p_',$p_num)"/>
5364
+ </xsl:attribute>
5365
+
5366
+ <xsl:copy-of select="node()"/>
5367
+ </xsl:copy>
5368
+ </xsl:for-each>
5369
+
5370
+
5371
+ <xsl:if test="$isGenerateTableIF = 'true'"> <!-- split each paragraph to words, image, math -->
5372
+
5373
+ <xsl:variable name="td_text">
5374
+ <xsl:apply-templates select="." mode="td_text_with_formatting"/>
5375
+ </xsl:variable>
5376
+
5377
+ <!-- td_text='<xsl:copy-of select="$td_text"/>' -->
5378
+
5379
+ <xsl:variable name="words">
5380
+ <xsl:for-each select=".//*[local-name() = 'image' or local-name() = 'stem']">
5381
+ <word>
5382
+ <xsl:copy-of select="."/>
5383
+ </word>
5384
+ </xsl:for-each>
5385
+
5386
+ <xsl:for-each select="xalan:nodeset($td_text)//*[local-name() = 'word'][normalize-space() != '']">
5387
+ <xsl:copy-of select="."/>
5388
+ </xsl:for-each>
5389
+
5390
+ </xsl:variable>
5391
+
5392
+ <xsl:for-each select="xalan:nodeset($words)/word">
5393
+ <xsl:variable name="num" select="count(preceding-sibling::word) + 1"/>
5394
+ <xsl:copy>
5395
+ <xsl:attribute name="id">
5396
+ <xsl:value-of select="concat($id,'_',$row_number,'_',$col_number,'_word_',$num)"/>
5397
+ </xsl:attribute>
5398
+ <xsl:copy-of select="node()"/>
5399
+ </xsl:copy>
5400
+ </xsl:for-each>
5401
+ </xsl:if>
5402
+ </xsl:copy>
5403
+
5404
+ </xsl:template><xsl:template match="@*|node()" mode="td_text_with_formatting">
5405
+ <xsl:copy>
5406
+ <xsl:apply-templates select="@*|node()" mode="td_text_with_formatting"/>
5407
+ </xsl:copy>
5408
+ </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">
5409
+ <xsl:variable name="formatting_tags">
5410
+ <xsl:call-template name="getFormattingTags"/>
5411
+ </xsl:variable>
5412
+ <word>
5413
+ <xsl:call-template name="enclose_text_in_tags">
5414
+ <xsl:with-param name="text" select="normalize-space(.)"/>
5415
+ <xsl:with-param name="tags" select="$formatting_tags"/>
5416
+ </xsl:call-template>
5417
+ </word>
5418
+ </xsl:template><xsl:template match="*[local-name() != 'keep-together_within-line']/text()" mode="td_text_with_formatting">
5419
+
5420
+ <xsl:variable name="td_text" select="."/>
5421
+
5422
+ <xsl:variable name="string_with_added_zerospaces">
5423
+ <xsl:call-template name="add-zero-spaces-java">
5424
+ <xsl:with-param name="text" select="$td_text"/>
5425
+ </xsl:call-template>
5426
+ </xsl:variable>
5427
+
5428
+ <xsl:variable name="formatting_tags">
5429
+ <xsl:call-template name="getFormattingTags"/>
5430
+ </xsl:variable>
5431
+
5432
+ <!-- <word>text</word> -->
5433
+ <xsl:call-template name="tokenize_with_tags">
5434
+ <xsl:with-param name="tags" select="$formatting_tags"/>
5435
+ <xsl:with-param name="text" select="normalize-space(translate($string_with_added_zerospaces, '​­', ' '))"/> <!-- replace zero-width-space and soft-hyphen to space -->
5436
+ </xsl:call-template>
5437
+ </xsl:template><xsl:template name="getFormattingTags">
5438
+ <tags>
5439
+ <xsl:if test="ancestor::*[local-name() = 'strong']"><tag>strong</tag></xsl:if>
5440
+ <xsl:if test="ancestor::*[local-name() = 'em']"><tag>em</tag></xsl:if>
5441
+ <xsl:if test="ancestor::*[local-name() = 'sub']"><tag>sub</tag></xsl:if>
5442
+ <xsl:if test="ancestor::*[local-name() = 'sup']"><tag>sup</tag></xsl:if>
5443
+ <xsl:if test="ancestor::*[local-name() = 'tt']"><tag>tt</tag></xsl:if>
5444
+ <xsl:if test="ancestor::*[local-name() = 'keep-together_within-line']"><tag>keep-together_within-line</tag></xsl:if>
5445
+ </tags>
4556
5446
  </xsl:template><xsl:template name="getLang">
4557
5447
  <xsl:variable name="language_current" select="normalize-space(//*[local-name()='bibdata']//*[local-name()='language'][@current = 'true'])"/>
4558
5448
  <xsl:variable name="language">
@@ -6273,7 +7163,9 @@
6273
7163
  <!-- <xsl:attribute name="border">0.5pt solid black</xsl:attribute> -->
6274
7164
  </xsl:if>
6275
7165
  <xsl:variable name="simple-table">
6276
- <xsl:call-template name="getSimpleTable"/>
7166
+ <xsl:call-template name="getSimpleTable">
7167
+ <xsl:with-param name="id" select="@id"/>
7168
+ </xsl:call-template>
6277
7169
  </xsl:variable>
6278
7170
  <xsl:variable name="cols-count" select="count(xalan:nodeset($simple-table)//tr[1]/td)"/>
6279
7171
  <xsl:if test="$cols-count = 2 and not(ancestor::*[local-name()='table'])">
@@ -7229,7 +8121,7 @@
7229
8121
  <!-- <fo:inline id="{@id}" font-size="1pt"/> -->
7230
8122
  <fo:inline id="{@id}" font-size="1pt"><xsl:value-of select="$hair_space"/></fo:inline>
7231
8123
  <!-- we need to add zero-width space, otherwise this fo:inline is missing in IF xml -->
7232
- <xsl:if test="not(following-sibling::node()[normalize-space() != ''])"> </xsl:if>
8124
+ <xsl:if test="not(following-sibling::node()[normalize-space() != ''])"><fo:inline font-size="1pt"> </fo:inline></xsl:if>
7233
8125
  </xsl:template><xsl:template match="*[local-name() = 'errata']">
7234
8126
  <!-- <row>
7235
8127
  <date>05-07-2013</date>
@@ -8601,4 +9493,40 @@
8601
9493
  <xsl:value-of select="$value"/>
8602
9494
  </xsl:otherwise>
8603
9495
  </xsl:choose>
9496
+ </xsl:template><xsl:template match="*" mode="print_as_xml">
9497
+ <xsl:param name="level">0</xsl:param>
9498
+
9499
+ <fo:block margin-left="{2*$level}mm">
9500
+ <xsl:text>
9501
+ &lt;</xsl:text>
9502
+ <xsl:value-of select="local-name()"/>
9503
+ <xsl:for-each select="@*">
9504
+ <xsl:text> </xsl:text>
9505
+ <xsl:value-of select="local-name()"/>
9506
+ <xsl:text>="</xsl:text>
9507
+ <xsl:value-of select="."/>
9508
+ <xsl:text>"</xsl:text>
9509
+ </xsl:for-each>
9510
+ <xsl:text>&gt;</xsl:text>
9511
+
9512
+ <xsl:if test="not(*)">
9513
+ <fo:inline font-weight="bold"><xsl:value-of select="."/></fo:inline>
9514
+ <xsl:text>&lt;/</xsl:text>
9515
+ <xsl:value-of select="local-name()"/>
9516
+ <xsl:text>&gt;</xsl:text>
9517
+ </xsl:if>
9518
+ </fo:block>
9519
+
9520
+ <xsl:if test="*">
9521
+ <fo:block>
9522
+ <xsl:apply-templates mode="print_as_xml">
9523
+ <xsl:with-param name="level" select="$level + 1"/>
9524
+ </xsl:apply-templates>
9525
+ </fo:block>
9526
+ <fo:block margin-left="{2*$level}mm">
9527
+ <xsl:text>&lt;/</xsl:text>
9528
+ <xsl:value-of select="local-name()"/>
9529
+ <xsl:text>&gt;</xsl:text>
9530
+ </fo:block>
9531
+ </xsl:if>
8604
9532
  </xsl:template></xsl:stylesheet>