metanorma-ogc 2.1.0 → 2.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -969,6 +969,7 @@
969
969
 
970
970
  <xsl:template match="ogc:p" name="paragraph">
971
971
  <xsl:param name="inline" select="'false'"/>
972
+ <xsl:param name="split_keep-within-line"/>
972
973
  <xsl:variable name="previous-element" select="local-name(preceding-sibling::*[1])"/>
973
974
  <xsl:variable name="element-name">
974
975
  <xsl:choose>
@@ -999,7 +1000,9 @@
999
1000
  <xsl:attribute name="margin-bottom">4pt</xsl:attribute>
1000
1001
  </xsl:if>
1001
1002
 
1002
- <xsl:apply-templates/>
1003
+ <xsl:apply-templates>
1004
+ <xsl:with-param name="split_keep-within-line" select="$split_keep-within-line"/>
1005
+ </xsl:apply-templates>
1003
1006
  </xsl:element>
1004
1007
  <xsl:if test="$element-name = 'fo:inline' and not($inline = 'true') and not(local-name(..) = 'admonition')">
1005
1008
  <fo:block margin-bottom="12pt">
@@ -1461,7 +1464,9 @@
1461
1464
  </fo:static-content>
1462
1465
  </xsl:template>
1463
1466
 
1464
- <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">
1467
+ <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_">
1468
+ false
1469
+ </xsl:variable><xsl:variable name="isGenerateTableIF" select="normalize-space($isGenerateTableIF_)"/><xsl:variable name="lang">
1465
1470
  <xsl:call-template name="getLang"/>
1466
1471
  </xsl:variable><xsl:variable name="pageWidth_">
1467
1472
  215.9
@@ -1985,6 +1990,7 @@
1985
1990
  <xsl:attribute name="font-weight">bold</xsl:attribute>
1986
1991
  <xsl:attribute name="border">solid black 1pt</xsl:attribute>
1987
1992
  <xsl:attribute name="padding-left">1mm</xsl:attribute>
1993
+ <xsl:attribute name="padding-right">1mm</xsl:attribute>
1988
1994
  <xsl:attribute name="display-align">center</xsl:attribute>
1989
1995
 
1990
1996
 
@@ -2005,6 +2011,7 @@
2005
2011
  <xsl:attribute name="display-align">center</xsl:attribute>
2006
2012
  <xsl:attribute name="border">solid black 1pt</xsl:attribute>
2007
2013
  <xsl:attribute name="padding-left">1mm</xsl:attribute>
2014
+ <xsl:attribute name="padding-right">1mm</xsl:attribute>
2008
2015
 
2009
2016
 
2010
2017
 
@@ -2097,7 +2104,8 @@
2097
2104
  <xsl:attribute name="min-height">8.5mm</xsl:attribute>
2098
2105
 
2099
2106
 
2100
- </xsl:attribute-set><xsl:attribute-set name="dt-style">
2107
+ </xsl:attribute-set><xsl:attribute-set name="dt-cell-style">
2108
+ </xsl:attribute-set><xsl:attribute-set name="dt-block-style">
2101
2109
  <xsl:attribute name="margin-top">6pt</xsl:attribute>
2102
2110
 
2103
2111
 
@@ -2112,6 +2120,8 @@
2112
2120
  <xsl:attribute name="margin-bottom">6pt</xsl:attribute>
2113
2121
 
2114
2122
 
2123
+ </xsl:attribute-set><xsl:attribute-set name="dd-cell-style">
2124
+ <xsl:attribute name="padding-left">2mm</xsl:attribute>
2115
2125
  </xsl:attribute-set><xsl:attribute-set name="appendix-style">
2116
2126
 
2117
2127
  <xsl:attribute name="font-size">12pt</xsl:attribute>
@@ -2984,7 +2994,38 @@
2984
2994
  </xsl:template><xsl:template match="*[local-name()='br']">
2985
2995
  <xsl:value-of select="$linebreak"/>
2986
2996
  </xsl:template><xsl:template match="*[local-name() = 'keep-together_within-line']">
2987
- <fo:inline keep-together.within-line="always"><xsl:apply-templates/></fo:inline>
2997
+ <xsl:param name="split_keep-within-line"/>
2998
+
2999
+ <!-- <fo:inline>split_keep-within-line='<xsl:value-of select="$split_keep-within-line"/>'</fo:inline> -->
3000
+ <xsl:choose>
3001
+
3002
+ <xsl:when test="normalize-space($split_keep-within-line) = 'true'">
3003
+ <xsl:variable name="sep">_</xsl:variable>
3004
+ <xsl:variable name="items">
3005
+ <xsl:call-template name="split">
3006
+ <xsl:with-param name="pText" select="."/>
3007
+ <xsl:with-param name="sep" select="$sep"/>
3008
+ <xsl:with-param name="normalize-space">false</xsl:with-param>
3009
+ <xsl:with-param name="keep_sep">true</xsl:with-param>
3010
+ </xsl:call-template>
3011
+ </xsl:variable>
3012
+ <xsl:for-each select="xalan:nodeset($items)/item">
3013
+ <xsl:choose>
3014
+ <xsl:when test=". = $sep">
3015
+ <xsl:value-of select="$sep"/><xsl:value-of select="$zero_width_space"/>
3016
+ </xsl:when>
3017
+ <xsl:otherwise>
3018
+ <fo:inline keep-together.within-line="always"><xsl:apply-templates/></fo:inline>
3019
+ </xsl:otherwise>
3020
+ </xsl:choose>
3021
+ </xsl:for-each>
3022
+ </xsl:when>
3023
+
3024
+ <xsl:otherwise>
3025
+ <fo:inline keep-together.within-line="always"><xsl:apply-templates/></fo:inline>
3026
+ </xsl:otherwise>
3027
+
3028
+ </xsl:choose>
2988
3029
  </xsl:template><xsl:template match="*[local-name()='copyright-statement']">
2989
3030
  <fo:block xsl:use-attribute-sets="copyright-statement-style">
2990
3031
  <xsl:apply-templates/>
@@ -3098,9 +3139,14 @@
3098
3139
 
3099
3140
  <xsl:variable name="table">
3100
3141
 
3101
- <xsl:variable name="simple-table">
3102
- <xsl:call-template name="getSimpleTable"/>
3142
+ <xsl:variable name="simple-table">
3143
+ <xsl:call-template name="getSimpleTable">
3144
+ <xsl:with-param name="id" select="@id"/>
3145
+ </xsl:call-template>
3103
3146
  </xsl:variable>
3147
+ <!-- <xsl:variable name="simple-table" select="xalan:nodeset($simple-table_)"/> -->
3148
+
3149
+ <!-- simple-table=<xsl:copy-of select="$simple-table"/> -->
3104
3150
 
3105
3151
 
3106
3152
  <!-- Display table's name before table as standalone block -->
@@ -3123,7 +3169,23 @@
3123
3169
  </xsl:call-template>
3124
3170
  </xsl:if>
3125
3171
  </xsl:variable>
3126
- <!-- DEBUG colwidths=<xsl:copy-of select="$colwidths"/> -->
3172
+ <!-- <xsl:variable name="colwidths" select="xalan:nodeset($colwidths_)"/> -->
3173
+
3174
+ <!-- DEBUG -->
3175
+ <xsl:if test="$table_if_debug = 'true'">
3176
+ <fo:block font-size="60%">
3177
+ <xsl:apply-templates select="xalan:nodeset($colwidths)" mode="print_as_xml"/>
3178
+ </fo:block>
3179
+ </xsl:if>
3180
+
3181
+
3182
+ <!-- <xsl:copy-of select="$colwidths"/> -->
3183
+
3184
+ <!-- <xsl:text disable-output-escaping="yes">&lt;!- -</xsl:text>
3185
+ DEBUG
3186
+ colwidths=<xsl:copy-of select="$colwidths"/>
3187
+ <xsl:text disable-output-escaping="yes">- -&gt;</xsl:text> -->
3188
+
3127
3189
 
3128
3190
 
3129
3191
  <xsl:variable name="margin-side">
@@ -3193,9 +3255,17 @@
3193
3255
  </xsl:element>
3194
3256
  </xsl:variable>
3195
3257
 
3258
+ <xsl:if test="$isGenerateTableIF = 'true'">
3259
+ <!-- to determine start of table -->
3260
+ <fo:block id="{concat('table_if_start_',@id)}" keep-with-next="always" font-size="1pt">Start table '<xsl:value-of select="@id"/>'.</fo:block>
3261
+ </xsl:if>
3196
3262
 
3197
3263
  <fo:table id="{@id}">
3198
3264
 
3265
+ <xsl:if test="$isGenerateTableIF = 'true'">
3266
+ <xsl:attribute name="wrap-option">no-wrap</xsl:attribute>
3267
+ </xsl:if>
3268
+
3199
3269
  <xsl:for-each select="xalan:nodeset($table_attributes)/table_attributes/@*">
3200
3270
  <xsl:attribute name="{local-name()}">
3201
3271
  <xsl:value-of select="."/>
@@ -3209,24 +3279,47 @@
3209
3279
 
3210
3280
 
3211
3281
  <xsl:choose>
3212
- <xsl:when test="*[local-name()='colgroup']/*[local-name()='col']">
3213
- <xsl:for-each select="*[local-name()='colgroup']/*[local-name()='col']">
3214
- <fo:table-column column-width="{@width}"/>
3215
- </xsl:for-each>
3282
+ <xsl:when test="$isGenerateTableIF = 'true'">
3283
+ <!-- generate IF for table widths -->
3284
+ <!-- example:
3285
+ <tr>
3286
+ <td valign="top" align="left" id="tab-symdu_1_1">
3287
+ <p>Symbol</p>
3288
+ <word id="tab-symdu_1_1_word_1">Symbol</word>
3289
+ </td>
3290
+ <td valign="top" align="left" id="tab-symdu_1_2">
3291
+ <p>Description</p>
3292
+ <word id="tab-symdu_1_2_word_1">Description</word>
3293
+ </td>
3294
+ </tr>
3295
+ -->
3296
+ <xsl:apply-templates select="xalan:nodeset($simple-table)" mode="process_table-if"/>
3297
+
3216
3298
  </xsl:when>
3217
3299
  <xsl:otherwise>
3218
- <xsl:call-template name="insertTableColumnWidth">
3219
- <xsl:with-param name="colwidths" select="$colwidths"/>
3220
- </xsl:call-template>
3221
- </xsl:otherwise>
3222
- </xsl:choose>
3223
3300
 
3224
- <xsl:choose>
3225
- <xsl:when test="not(*[local-name()='tbody']) and *[local-name()='thead']">
3226
- <xsl:apply-templates select="*[local-name()='thead']" mode="process_tbody"/>
3227
- </xsl:when>
3228
- <xsl:otherwise>
3229
- <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 -->
3301
+ <xsl:choose>
3302
+ <xsl:when test="*[local-name()='colgroup']/*[local-name()='col']">
3303
+ <xsl:for-each select="*[local-name()='colgroup']/*[local-name()='col']">
3304
+ <fo:table-column column-width="{@width}"/>
3305
+ </xsl:for-each>
3306
+ </xsl:when>
3307
+ <xsl:otherwise>
3308
+ <xsl:call-template name="insertTableColumnWidth">
3309
+ <xsl:with-param name="colwidths" select="$colwidths"/>
3310
+ </xsl:call-template>
3311
+ </xsl:otherwise>
3312
+ </xsl:choose>
3313
+
3314
+ <xsl:choose>
3315
+ <xsl:when test="not(*[local-name()='tbody']) and *[local-name()='thead']">
3316
+ <xsl:apply-templates select="*[local-name()='thead']" mode="process_tbody"/>
3317
+ </xsl:when>
3318
+ <xsl:otherwise>
3319
+ <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 -->
3320
+ </xsl:otherwise>
3321
+ </xsl:choose>
3322
+
3230
3323
  </xsl:otherwise>
3231
3324
  </xsl:choose>
3232
3325
 
@@ -3326,11 +3419,22 @@
3326
3419
  <xsl:variable name="columns-with-colspan" select="count($table-row/*[@colspan])"/>
3327
3420
  <xsl:value-of select="$columns-count + $sum-colspans - $columns-with-colspan"/>
3328
3421
  </xsl:template><xsl:template name="calculate-column-widths">
3422
+ <xsl:param name="table"/>
3423
+ <xsl:param name="cols-count"/>
3424
+
3425
+ <xsl:call-template name="calculate-column-widths-proportional">
3426
+ <xsl:with-param name="cols-count" select="$cols-count"/>
3427
+ <xsl:with-param name="table" select="$table"/>
3428
+ </xsl:call-template>
3429
+
3430
+ </xsl:template><xsl:template name="calculate-column-widths-proportional">
3329
3431
  <xsl:param name="table"/>
3330
3432
  <xsl:param name="cols-count"/>
3331
3433
  <xsl:param name="curr-col" select="1"/>
3332
3434
  <xsl:param name="width" select="0"/>
3333
3435
 
3436
+ <!-- table=<xsl:copy-of select="$table"/> -->
3437
+
3334
3438
  <xsl:if test="$curr-col &lt;= $cols-count">
3335
3439
  <xsl:variable name="widths">
3336
3440
  <xsl:choose>
@@ -3368,10 +3472,15 @@
3368
3472
  </xsl:for-each>
3369
3473
  </xsl:when>
3370
3474
  <xsl:otherwise>
3371
- <xsl:for-each select="xalan:nodeset($table)/*/tr">
3475
+ <!-- <curr_col><xsl:value-of select="$curr-col"/></curr_col> -->
3476
+
3477
+ <!-- <table><xsl:copy-of select="$table"/></table>
3478
+ -->
3479
+ <xsl:for-each select="xalan:nodeset($table)/*/*[local-name()='tr']">
3372
3480
  <xsl:variable name="td_text">
3373
3481
  <xsl:apply-templates select="td[$curr-col]" mode="td_text"/>
3374
3482
  </xsl:variable>
3483
+ <!-- <td_text><xsl:value-of select="$td_text"/></td_text> -->
3375
3484
  <xsl:variable name="words">
3376
3485
  <xsl:variable name="string_with_added_zerospaces">
3377
3486
  <xsl:call-template name="add-zero-spaces-java">
@@ -3386,6 +3495,7 @@
3386
3495
  <xsl:with-param name="text" select="normalize-space(translate($string_with_added_zerospaces, '​­', ' '))"/> <!-- replace zero-width-space and soft-hyphen to space -->
3387
3496
  </xsl:call-template>
3388
3497
  </xsl:variable>
3498
+ <!-- words=<xsl:copy-of select="$words"/> -->
3389
3499
  <xsl:variable name="max_length">
3390
3500
  <xsl:call-template name="max_length">
3391
3501
  <xsl:with-param name="words" select="xalan:nodeset($words)"/>
@@ -3410,6 +3520,8 @@
3410
3520
  </xsl:choose>
3411
3521
  </xsl:variable>
3412
3522
 
3523
+ <!-- widths=<xsl:copy-of select="$widths"/> -->
3524
+
3413
3525
  <column>
3414
3526
  <xsl:for-each select="xalan:nodeset($widths)//width">
3415
3527
  <xsl:sort select="." data-type="number" order="descending"/>
@@ -3418,33 +3530,327 @@
3418
3530
  </xsl:if>
3419
3531
  </xsl:for-each>
3420
3532
  </column>
3421
- <xsl:call-template name="calculate-column-widths">
3533
+ <xsl:call-template name="calculate-column-widths-proportional">
3422
3534
  <xsl:with-param name="cols-count" select="$cols-count"/>
3423
3535
  <xsl:with-param name="curr-col" select="$curr-col +1"/>
3424
3536
  <xsl:with-param name="table" select="$table"/>
3425
3537
  </xsl:call-template>
3426
3538
  </xsl:if>
3427
- </xsl:template><xsl:template match="*[@keep-together.within-line]/text()" priority="2" mode="td_text">
3539
+ </xsl:template><xsl:template match="*[@keep-together.within-line or local-name() = 'keep-together_within-line']/text()" priority="2" mode="td_text">
3428
3540
  <!-- <xsl:message>DEBUG t1=<xsl:value-of select="."/></xsl:message>
3429
3541
  <xsl:message>DEBUG t2=<xsl:value-of select="java:replaceAll(java:java.lang.String.new(.),'.','X')"/></xsl:message> -->
3430
3542
  <xsl:value-of select="java:replaceAll(java:java.lang.String.new(.),'.','X')"/>
3543
+
3544
+ <!-- if all capitals english letters or digits -->
3545
+ <xsl:if test="normalize-space(translate(., concat($upper,'0123456789'), '')) = ''">
3546
+ <xsl:call-template name="repeat">
3547
+ <xsl:with-param name="char" select="'X'"/>
3548
+ <xsl:with-param name="count" select="string-length(normalize-space(.)) * 0.5"/>
3549
+ </xsl:call-template>
3550
+ </xsl:if>
3431
3551
  </xsl:template><xsl:template match="text()" mode="td_text">
3432
3552
  <xsl:value-of select="translate(., $zero_width_space, ' ')"/><xsl:text> </xsl:text>
3433
3553
  </xsl:template><xsl:template match="*[local-name()='termsource']" mode="td_text">
3434
3554
  <xsl:value-of select="*[local-name()='origin']/@citeas"/>
3435
3555
  </xsl:template><xsl:template match="*[local-name()='link']" mode="td_text">
3436
3556
  <xsl:value-of select="@target"/>
3437
- </xsl:template><xsl:template match="*[local-name()='math']" mode="td_text">
3438
- <xsl:variable name="mathml">
3439
- <xsl:for-each select="*">
3440
- <xsl:if test="local-name() != 'unit' and local-name() != 'prefix' and local-name() != 'dimension' and local-name() != 'quantity'">
3441
- <xsl:copy-of select="."/>
3557
+ </xsl:template><xsl:template match="*[local-name()='math']" mode="td_text" name="math_length">
3558
+ <xsl:if test="$isGenerateTableIF = 'false'">
3559
+ <xsl:variable name="mathml_">
3560
+ <xsl:for-each select="*">
3561
+ <xsl:if test="local-name() != 'unit' and local-name() != 'prefix' and local-name() != 'dimension' and local-name() != 'quantity'">
3562
+ <xsl:copy-of select="."/>
3563
+ </xsl:if>
3564
+ </xsl:for-each>
3565
+ </xsl:variable>
3566
+ <xsl:variable name="mathml" select="xalan:nodeset($mathml_)"/>
3567
+
3568
+ <xsl:variable name="math_text">
3569
+ <xsl:value-of select="normalize-space($mathml)"/>
3570
+ <xsl:for-each select="$mathml//@open"><xsl:value-of select="."/></xsl:for-each>
3571
+ <xsl:for-each select="$mathml//@close"><xsl:value-of select="."/></xsl:for-each>
3572
+ </xsl:variable>
3573
+ <xsl:value-of select="translate($math_text, ' ', '#')"/><!-- mathml images as one 'word' without spaces -->
3574
+ </xsl:if>
3575
+ </xsl:template><xsl:template name="calculate-column-widths-autolayout-algorithm">
3576
+ <xsl:param name="table"/>
3577
+ <xsl:param name="if">false</xsl:param> <!-- via intermediate format -->
3578
+
3579
+ <!-- The algorithm uses two passes through the table data and scales linearly with the size of the table -->
3580
+
3581
+ <!-- In the first pass, line wrapping is disabled, and the user agent keeps track of the minimum and maximum width of each cell. -->
3582
+
3583
+ <!-- Since line wrap has been disabled, paragraphs are treated as long lines unless broken by BR elements. -->
3584
+
3585
+ <!-- get current table id -->
3586
+ <xsl:variable name="table_id" select="@id"/>
3587
+ <!-- find table by id in the file 'table_widths' -->
3588
+ <xsl:variable name="table-if_" select="$table_widths_from_if//table[@id = $table_id]"/>
3589
+ <xsl:variable name="table-if" select="xalan:nodeset($table-if_)"/>
3590
+
3591
+
3592
+ <!-- table='<xsl:copy-of select="$table"/>' -->
3593
+ <!-- table_id='<xsl:value-of select="$table_id"/>\ -->
3594
+ <!-- table-if='<xsl:copy-of select="$table-if"/>' -->
3595
+ <!-- table_widths_from_if='<xsl:copy-of select="$table_widths_from_if"/>' -->
3596
+
3597
+ <xsl:variable name="table_with_cell_widths_">
3598
+ <xsl:choose>
3599
+ <xsl:when test="$if = 'true' and normalize-space($table-if) != ''"> <!-- if we read column's width from IF and there is table in IF -->
3600
+
3601
+ <!-- Example: <column>10</column>
3602
+ <column>11</column>
3603
+ -->
3604
+ <xsl:apply-templates select="$table-if" mode="determine_cell_widths-if"/>
3605
+ </xsl:when>
3606
+ <xsl:otherwise>
3607
+ <xsl:apply-templates select="xalan:nodeset($table)" mode="determine_cell_widths"/>
3608
+ </xsl:otherwise>
3609
+ </xsl:choose>
3610
+ </xsl:variable>
3611
+ <xsl:variable name="table_with_cell_widths" select="xalan:nodeset($table_with_cell_widths_)"/>
3612
+
3613
+ <xsl:if test="$table_if_debug = 'true'">
3614
+ <xsl:copy-of select="$table_with_cell_widths"/>
3615
+ </xsl:if>
3616
+
3617
+
3618
+ <!-- The minimum and maximum cell widths are then used to determine the corresponding minimum and maximum widths for the columns. -->
3619
+
3620
+ <xsl:variable name="column_widths_">
3621
+ <!-- iteration of columns -->
3622
+ <xsl:for-each select="$table_with_cell_widths//tr[1]/td">
3623
+ <xsl:variable name="pos" select="position()"/>
3624
+ <column>
3625
+ <xsl:attribute name="width_max">
3626
+ <xsl:for-each select="ancestor::tbody//tr/td[$pos]/@width_max">
3627
+ <xsl:sort select="." data-type="number" order="descending"/>
3628
+ <xsl:if test="position() = 1"><xsl:value-of select="."/></xsl:if>
3629
+ </xsl:for-each>
3630
+ </xsl:attribute>
3631
+ <xsl:attribute name="width_min">
3632
+ <xsl:for-each select="ancestor::tbody//tr/td[$pos]/@width_min">
3633
+ <xsl:sort select="." data-type="number" order="descending"/>
3634
+ <xsl:if test="position() = 1"><xsl:value-of select="."/></xsl:if>
3635
+ </xsl:for-each>
3636
+ </xsl:attribute>
3637
+ </column>
3638
+ </xsl:for-each>
3639
+ </xsl:variable>
3640
+ <xsl:variable name="column_widths" select="xalan:nodeset($column_widths_)"/>
3641
+
3642
+ <!-- <column_widths>
3643
+ <xsl:copy-of select="$column_widths"/>
3644
+ </column_widths> -->
3645
+
3646
+ <!-- These in turn, are used to find the minimum and maximum width for the table. -->
3647
+ <xsl:variable name="table_widths_">
3648
+ <table>
3649
+ <xsl:attribute name="width_max">
3650
+ <xsl:value-of select="sum($column_widths/column/@width_max)"/>
3651
+ </xsl:attribute>
3652
+ <xsl:attribute name="width_min">
3653
+ <xsl:value-of select="sum($column_widths/column/@width_min)"/>
3654
+ </xsl:attribute>
3655
+ </table>
3656
+ </xsl:variable>
3657
+ <xsl:variable name="table_widths" select="xalan:nodeset($table_widths_)"/>
3658
+
3659
+ <xsl:variable name="page_width">
3660
+ <xsl:choose>
3661
+ <xsl:when test="$if = 'true'"><xsl:value-of select="$table-if/@page-width"/></xsl:when>
3662
+ <xsl:otherwise>75</xsl:otherwise>
3663
+ </xsl:choose>
3664
+ </xsl:variable>
3665
+
3666
+ <xsl:if test="$table_if_debug = 'true'">
3667
+ <table_width>
3668
+ <xsl:copy-of select="$table_widths"/>
3669
+ </table_width>
3670
+ <!-- <debug>$table_widths/@width_min=<xsl:value-of select="$table_widths/table/@width_min"/></debug>
3671
+ <debug>$table_widths/@width_max=<xsl:value-of select="$table_widths/table/@width_max"/></debug>
3672
+ -->
3673
+ <debug>$page_width=<xsl:value-of select="$page_width"/></debug>
3674
+ </xsl:if>
3675
+
3676
+
3677
+ <!-- There are three cases: -->
3678
+ <xsl:choose>
3679
+ <!-- 1. The minimum table width is equal to or wider than the available space -->
3680
+ <xsl:when test="$table_widths/table/@width_min &gt;= $page_width and 1 = 2"> <!-- this condition isn't working see case 3 below -->
3681
+ <!-- call old algorithm -->
3682
+ <case1/>
3683
+ <xsl:variable name="cols-count" select="count(xalan:nodeset($table)/*/tr[1]/td)"/>
3684
+ <xsl:call-template name="calculate-column-widths-proportional">
3685
+ <xsl:with-param name="cols-count" select="$cols-count"/>
3686
+ <xsl:with-param name="table" select="$table"/>
3687
+ </xsl:call-template>
3688
+ </xsl:when>
3689
+ <!-- 2. The maximum table width fits within the available space. In this case, set the columns to their maximum widths. -->
3690
+ <xsl:when test="$table_widths/table/@width_max &lt;= $page_width">
3691
+ <case2/>
3692
+ <autolayout/>
3693
+ <xsl:for-each select="$column_widths/column/@width_max">
3694
+ <column divider="100"><xsl:value-of select="."/></column>
3695
+ </xsl:for-each>
3696
+ </xsl:when>
3697
+ <!-- 3. The maximum width of the table is greater than the available space, but the minimum table width is smaller.
3698
+ In this case, find the difference between the available space and the minimum table width, lets call it W.
3699
+ Lets also call D the difference between maximum and minimum width of the table.
3700
+ For each column, let d be the difference between maximum and minimum width of that column.
3701
+ Now set the column's width to the minimum width plus d times W over D.
3702
+ This makes columns with large differences between minimum and maximum widths wider than columns with smaller differences. -->
3703
+ <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)">
3704
+ <!-- difference between the available space and the minimum table width -->
3705
+ <xsl:variable name="W" select="$page_width - $table_widths/table/@width_min"/>
3706
+ <W><xsl:value-of select="$W"/></W>
3707
+ <!-- difference between maximum and minimum width of the table -->
3708
+ <xsl:variable name="D" select="$table_widths/table/@width_max - $table_widths/table/@width_min"/>
3709
+ <D><xsl:value-of select="$D"/></D>
3710
+ <case3/>
3711
+ <autolayout/>
3712
+ <xsl:if test="$table_widths/table/@width_min &gt;= $page_width">
3713
+ <split_keep-within-line>true</split_keep-within-line>
3442
3714
  </xsl:if>
3715
+ <xsl:for-each select="$column_widths/column">
3716
+ <!-- difference between maximum and minimum width of that column. -->
3717
+ <xsl:variable name="d" select="@width_max - @width_min"/>
3718
+ <d><xsl:value-of select="$d"/></d>
3719
+ <width_min><xsl:value-of select="@width_min"/></width_min>
3720
+ <e><xsl:value-of select="$d * $W div $D"/></e>
3721
+ <!-- set the column's width to the minimum width plus d times W over D. -->
3722
+ <column divider="100">
3723
+ <xsl:value-of select="round(@width_min + $d * $W div $D)"/> <!-- * 10 -->
3724
+ </column>
3725
+ </xsl:for-each>
3726
+
3727
+ </xsl:when>
3728
+ <xsl:otherwise><unknown_case/></xsl:otherwise>
3729
+ </xsl:choose>
3730
+
3731
+
3732
+ </xsl:template><xsl:template match="@*|node()" mode="determine_cell_widths">
3733
+ <xsl:copy>
3734
+ <xsl:apply-templates select="@*|node()" mode="determine_cell_widths"/>
3735
+ </xsl:copy>
3736
+ </xsl:template><xsl:template match="td | th" mode="determine_cell_widths">
3737
+ <xsl:copy>
3738
+ <xsl:copy-of select="@*"/>
3739
+
3740
+ <!-- The maximum width is given by the widest line. -->
3741
+ <xsl:variable name="widths_max">
3742
+ <xsl:for-each select=".//*[local-name() = 'p']">
3743
+ <xsl:call-template name="add_width"/>
3744
+ </xsl:for-each>
3745
+ <xsl:if test="not(*[local-name() = 'p'])">
3746
+ <xsl:call-template name="add_width"/>
3747
+ </xsl:if>
3748
+ </xsl:variable>
3749
+ <xsl:variable name="width_max">
3750
+ <xsl:for-each select="xalan:nodeset($widths_max)//width">
3751
+ <xsl:sort select="." data-type="number" order="descending"/>
3752
+ <xsl:if test="position() = 1"><xsl:value-of select="."/></xsl:if>
3753
+ </xsl:for-each>
3754
+ </xsl:variable>
3755
+ <xsl:attribute name="width_max">
3756
+ <xsl:value-of select="$width_max"/>
3757
+ </xsl:attribute>
3758
+
3759
+ <!-- The minimum width is given by the widest text element (word, image, etc.) -->
3760
+ <!-- To do: image width -->
3761
+ <xsl:variable name="td_text">
3762
+ <xsl:apply-templates select="." mode="td_text"/>
3763
+ </xsl:variable>
3764
+ <xsl:variable name="words">
3765
+ <xsl:variable name="string_with_added_zerospaces">
3766
+ <xsl:call-template name="add-zero-spaces-java">
3767
+ <xsl:with-param name="text" select="$td_text"/>
3768
+ </xsl:call-template>
3769
+ </xsl:variable>
3770
+ <xsl:call-template name="tokenize">
3771
+ <xsl:with-param name="text" select="normalize-space(translate($string_with_added_zerospaces, '​­', ' '))"/> <!-- replace zero-width-space and soft-hyphen to space -->
3772
+ </xsl:call-template>
3773
+ </xsl:variable>
3774
+
3775
+ <xsl:variable name="max_word_length">
3776
+ <xsl:call-template name="max_length">
3777
+ <xsl:with-param name="words" select="xalan:nodeset($words)"/>
3778
+ </xsl:call-template>
3779
+ </xsl:variable>
3780
+ <xsl:variable name="width_min">
3781
+ <xsl:value-of select="$max_word_length"/>
3782
+ </xsl:variable>
3783
+ <xsl:attribute name="width_min">
3784
+ <xsl:value-of select="$width_min"/>
3785
+ </xsl:attribute>
3786
+ <!-- width_max="1" width_min="1.5"> --> <!-- see 'tokenize' template, multiply 1.5 for all latin capitals -->
3787
+ <xsl:if test="$width_min &gt; $width_max">
3788
+ <xsl:attribute name="width_max">
3789
+ <xsl:value-of select="$width_min"/>
3790
+ </xsl:attribute>
3791
+ </xsl:if>
3792
+ <xsl:if test="$width_min = 0">
3793
+ <xsl:attribute name="width_min">1</xsl:attribute>
3794
+ </xsl:if>
3795
+
3796
+ <xsl:apply-templates select="node()" mode="determine_cell_widths"/>
3797
+
3798
+ </xsl:copy>
3799
+ </xsl:template><xsl:template name="add_width">
3800
+ <xsl:variable name="p_text"><xsl:apply-templates select="." mode="td_text"/></xsl:variable>
3801
+ <xsl:variable name="p_text_len_" select="string-length(normalize-space($p_text))"/>
3802
+
3803
+ <xsl:variable name="p_text_len">
3804
+ <xsl:choose>
3805
+ <xsl:when test="normalize-space(translate($p_text, concat($upper,'0123456789'), '')) = ''"> <!-- english word in CAPITAL letters -->
3806
+ <xsl:value-of select="$p_text_len_ * 1.5"/>
3807
+ </xsl:when>
3808
+ <xsl:otherwise><xsl:value-of select="$p_text_len_"/></xsl:otherwise>
3809
+ </xsl:choose>
3810
+ </xsl:variable>
3811
+
3812
+ <xsl:variable name="math_addon_text">
3813
+ <xsl:for-each select=".//*[local-name() = 'math']">
3814
+ <xsl:apply-templates mode="td_text"/>
3443
3815
  </xsl:for-each>
3444
3816
  </xsl:variable>
3817
+ <xsl:variable name="math_addon_length" select="string-length(normalize-space($math_addon_text)) * 0.2"/> <!-- plus 20% -->
3445
3818
 
3446
- <xsl:variable name="math_text" select="normalize-space(xalan:nodeset($mathml))"/>
3447
- <xsl:value-of select="translate($math_text, ' ', '#')"/><!-- mathml images as one 'word' without spaces -->
3819
+ <width><xsl:value-of select="$p_text_len + $math_addon_length"/></width>
3820
+ </xsl:template><xsl:template match="@*|node()" mode="determine_cell_widths-if">
3821
+ <xsl:copy>
3822
+ <xsl:apply-templates select="@*|node()" mode="determine_cell_widths-if"/>
3823
+ </xsl:copy>
3824
+ </xsl:template><xsl:template match="td | th" mode="determine_cell_widths-if">
3825
+ <xsl:copy>
3826
+ <xsl:copy-of select="@*"/>
3827
+
3828
+ <!-- The maximum width is given by the widest line. -->
3829
+ <xsl:attribute name="width_max">
3830
+ <xsl:for-each select="p_len">
3831
+ <xsl:sort select="." data-type="number" order="descending"/>
3832
+ <xsl:if test="position() = 1"><xsl:value-of select="."/></xsl:if>
3833
+ </xsl:for-each>
3834
+ </xsl:attribute>
3835
+
3836
+ <!-- The minimum width is given by the widest text element (word, image, etc.) -->
3837
+ <xsl:variable name="width_min">
3838
+ <xsl:for-each select="word_len">
3839
+ <xsl:sort select="." data-type="number" order="descending"/>
3840
+ <xsl:if test="position() = 1"><xsl:value-of select="."/></xsl:if>
3841
+ </xsl:for-each>
3842
+ </xsl:variable>
3843
+ <xsl:attribute name="width_min">
3844
+ <xsl:value-of select="$width_min"/>
3845
+ </xsl:attribute>
3846
+
3847
+ <xsl:if test="$width_min = 0">
3848
+ <xsl:attribute name="width_min">1</xsl:attribute>
3849
+ </xsl:if>
3850
+
3851
+ <xsl:apply-templates select="node()" mode="determine_cell_widths-if"/>
3852
+
3853
+ </xsl:copy>
3448
3854
  </xsl:template><xsl:template match="*[local-name()='thead']">
3449
3855
  <xsl:param name="cols-count"/>
3450
3856
  <fo:table-header>
@@ -3529,6 +3935,7 @@
3529
3935
  </xsl:for-each>
3530
3936
  </xsl:when>
3531
3937
  <xsl:otherwise>
3938
+ <!-- $colwidths=<xsl:copy-of select="$colwidths"/> -->
3532
3939
  <xsl:call-template name="insertTableColumnWidth">
3533
3940
  <xsl:with-param name="colwidths" select="$colwidths"/>
3534
3941
  </xsl:call-template>
@@ -3608,6 +4015,52 @@
3608
4015
 
3609
4016
  </fo:table-body>
3610
4017
 
4018
+ </xsl:template><xsl:template match="/" mode="process_table-if">
4019
+ <xsl:param name="table_or_dl">table</xsl:param>
4020
+ <xsl:apply-templates mode="process_table-if">
4021
+ <xsl:with-param name="table_or_dl" select="$table_or_dl"/>
4022
+ </xsl:apply-templates>
4023
+ </xsl:template><xsl:template match="*[local-name()='tbody']" mode="process_table-if">
4024
+ <xsl:param name="table_or_dl">table</xsl:param>
4025
+
4026
+ <fo:table-body>
4027
+ <xsl:for-each select="*[local-name() = 'tr']">
4028
+ <xsl:variable name="col_count" select="count(*)"/>
4029
+
4030
+ <!-- iteration for each tr/td -->
4031
+
4032
+ <xsl:choose>
4033
+ <xsl:when test="$table_or_dl = 'table'">
4034
+ <xsl:for-each select="*[local-name() = 'td' or local-name() = 'th']/*">
4035
+ <fo:table-row number-columns-spanned="{$col_count}">
4036
+ <!-- <test_table><xsl:copy-of select="."/></test_table> -->
4037
+ <xsl:call-template name="td"/>
4038
+ </fo:table-row>
4039
+ </xsl:for-each>
4040
+ </xsl:when>
4041
+ <xsl:otherwise> <!-- $table_or_dl = 'dl' -->
4042
+ <xsl:for-each select="*[local-name() = 'td' or local-name() = 'th']">
4043
+ <xsl:variable name="is_dt" select="position() = 1"/>
4044
+
4045
+ <xsl:for-each select="*">
4046
+ <!-- <test><xsl:copy-of select="."/></test> -->
4047
+ <fo:table-row number-columns-spanned="{$col_count}">
4048
+ <xsl:choose>
4049
+ <xsl:when test="$is_dt">
4050
+ <xsl:call-template name="insert_dt_cell"/>
4051
+ </xsl:when>
4052
+ <xsl:otherwise>
4053
+ <xsl:call-template name="insert_dd_cell"/>
4054
+ </xsl:otherwise>
4055
+ </xsl:choose>
4056
+ </fo:table-row>
4057
+ </xsl:for-each>
4058
+ </xsl:for-each>
4059
+ </xsl:otherwise>
4060
+ </xsl:choose>
4061
+
4062
+ </xsl:for-each>
4063
+ </fo:table-body>
3611
4064
  </xsl:template><xsl:template match="*[local-name()='thead']/*[local-name()='tr']" priority="2">
3612
4065
  <fo:table-row xsl:use-attribute-sets="table-header-row-style">
3613
4066
 
@@ -3699,7 +4152,7 @@
3699
4152
  </xsl:choose>
3700
4153
  </xsl:attribute>
3701
4154
  </xsl:if>
3702
- </xsl:template><xsl:template match="*[local-name()='td']">
4155
+ </xsl:template><xsl:template match="*[local-name()='td']" name="td">
3703
4156
  <fo:table-cell xsl:use-attribute-sets="table-cell-style"> <!-- text-align="{@align}" -->
3704
4157
  <xsl:call-template name="setTextAlignment">
3705
4158
  <xsl:with-param name="default">left</xsl:with-param>
@@ -3733,11 +4186,24 @@
3733
4186
 
3734
4187
  <xsl:call-template name="setTableCellAttributes"/>
3735
4188
 
4189
+ <xsl:if test="$isGenerateTableIF = 'true'">
4190
+ <xsl:attribute name="border">1pt solid black</xsl:attribute> <!-- border is mandatory, to determine page width -->
4191
+ <xsl:attribute name="text-align">left</xsl:attribute>
4192
+ </xsl:if>
4193
+
3736
4194
  <fo:block>
3737
4195
 
4196
+ <xsl:if test="$isGenerateTableIF = 'true'">
4197
+ <xsl:attribute name="id"><xsl:value-of select="@id"/></xsl:attribute>
4198
+ </xsl:if>
4199
+
4200
+
3738
4201
 
3739
4202
 
3740
4203
  <xsl:apply-templates/>
4204
+
4205
+ <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"/> -->
4206
+
3741
4207
  </fo:block>
3742
4208
  </fo:table-cell>
3743
4209
  </xsl:template><xsl:template match="*[local-name()='table']/*[local-name()='note']" priority="2">
@@ -3940,9 +4406,9 @@
3940
4406
  <!-- current hierarchy is 'figure' element -->
3941
4407
  <xsl:variable name="following_dl_colwidths">
3942
4408
  <xsl:if test="*[local-name() = 'dl']"><!-- if there is a 'dl', then set the same columns width as for 'dl' -->
3943
- <xsl:variable name="html-table">
3944
- <xsl:variable name="doc_ns">
3945
-
4409
+ <xsl:variable name="simple-table">
4410
+ <!-- <xsl:variable name="doc_ns">
4411
+ <xsl:if test="$namespace = 'bipm'">bipm</xsl:if>
3946
4412
  </xsl:variable>
3947
4413
  <xsl:variable name="ns">
3948
4414
  <xsl:choose>
@@ -3953,7 +4419,7 @@
3953
4419
  <xsl:value-of select="substring-before(name(/*), '-')"/>
3954
4420
  </xsl:otherwise>
3955
4421
  </xsl:choose>
3956
- </xsl:variable>
4422
+ </xsl:variable> -->
3957
4423
 
3958
4424
  <xsl:for-each select="*[local-name() = 'dl'][1]">
3959
4425
  <tbody>
@@ -3964,7 +4430,7 @@
3964
4430
 
3965
4431
  <xsl:call-template name="calculate-column-widths">
3966
4432
  <xsl:with-param name="cols-count" select="2"/>
3967
- <xsl:with-param name="table" select="$html-table"/>
4433
+ <xsl:with-param name="table" select="$simple-table"/>
3968
4434
  </xsl:call-template>
3969
4435
 
3970
4436
  </xsl:if>
@@ -4149,7 +4615,18 @@
4149
4615
 
4150
4616
 
4151
4617
 
4618
+
4619
+ <xsl:if test="$isGenerateTableIF = 'true'">
4620
+ <!-- to determine start of table -->
4621
+ <fo:block id="{concat('table_if_start_',@id)}" keep-with-next="always" font-size="1pt">Start table '<xsl:value-of select="@id"/>'.</fo:block>
4622
+ </xsl:if>
4623
+
4152
4624
  <fo:table width="95%" table-layout="fixed">
4625
+
4626
+ <xsl:if test="$isGenerateTableIF = 'true'">
4627
+ <xsl:attribute name="wrap-option">no-wrap</xsl:attribute>
4628
+ </xsl:if>
4629
+
4153
4630
 
4154
4631
  <xsl:choose>
4155
4632
  <xsl:when test="normalize-space($key_iso) = 'true' and $parent = 'formula'"/>
@@ -4158,52 +4635,130 @@
4158
4635
 
4159
4636
  </xsl:when>
4160
4637
  </xsl:choose>
4161
- <!-- create virtual html table for dl/[dt and dd] -->
4162
- <xsl:variable name="html-table">
4163
- <xsl:variable name="doc_ns">
4638
+
4639
+
4640
+ <xsl:choose>
4641
+ <xsl:when test="$isGenerateTableIF = 'true'">
4642
+ <!-- generate IF for table widths -->
4643
+ <!-- example:
4644
+ <tr>
4645
+ <td valign="top" align="left" id="tab-symdu_1_1">
4646
+ <p>Symbol</p>
4647
+ <word id="tab-symdu_1_1_word_1">Symbol</word>
4648
+ </td>
4649
+ <td valign="top" align="left" id="tab-symdu_1_2">
4650
+ <p>Description</p>
4651
+ <word id="tab-symdu_1_2_word_1">Description</word>
4652
+ </td>
4653
+ </tr>
4654
+ -->
4164
4655
 
4165
- </xsl:variable>
4166
- <xsl:variable name="ns">
4167
- <xsl:choose>
4168
- <xsl:when test="normalize-space($doc_ns) != ''">
4169
- <xsl:value-of select="normalize-space($doc_ns)"/>
4170
- </xsl:when>
4171
- <xsl:otherwise>
4172
- <xsl:value-of select="substring-before(name(/*), '-')"/>
4173
- </xsl:otherwise>
4174
- </xsl:choose>
4175
- </xsl:variable>
4176
- <tbody>
4177
- <xsl:apply-templates mode="dl"/>
4178
- </tbody>
4179
- </xsl:variable>
4180
- <!-- DEBUG: html-table<xsl:copy-of select="$html-table"/> -->
4181
- <xsl:variable name="colwidths">
4182
- <xsl:call-template name="calculate-column-widths">
4183
- <xsl:with-param name="cols-count" select="2"/>
4184
- <xsl:with-param name="table" select="$html-table"/>
4185
- </xsl:call-template>
4186
- </xsl:variable>
4187
- <!-- DEBUG: colwidths=<xsl:copy-of select="$colwidths"/> -->
4188
- <xsl:variable name="maxlength_dt">
4189
- <xsl:call-template name="getMaxLength_dt"/>
4190
- </xsl:variable>
4191
- <xsl:variable name="isContainsKeepTogetherTag_">
4192
- false
4193
- </xsl:variable>
4194
- <xsl:variable name="isContainsKeepTogetherTag" select="normalize-space($isContainsKeepTogetherTag_)"/>
4195
- <!-- isContainsExpressReference=<xsl:value-of select="$isContainsExpressReference"/> -->
4196
- <xsl:call-template name="setColumnWidth_dl">
4197
- <xsl:with-param name="colwidths" select="$colwidths"/>
4198
- <xsl:with-param name="maxlength_dt" select="$maxlength_dt"/>
4199
- <xsl:with-param name="isContainsKeepTogetherTag" select="$isContainsKeepTogetherTag"/>
4200
- </xsl:call-template>
4656
+ <!-- create virtual html table for dl/[dt and dd] -->
4657
+ <xsl:variable name="simple-table">
4658
+
4659
+ <xsl:variable name="dl_table">
4660
+ <tbody>
4661
+ <xsl:apply-templates mode="dl_if">
4662
+ <xsl:with-param name="id" select="@id"/>
4663
+ </xsl:apply-templates>
4664
+ </tbody>
4665
+ </xsl:variable>
4666
+
4667
+ <!-- dl_table='<xsl:copy-of select="$dl_table"/>' -->
4668
+
4669
+ <!-- Step: replace <br/> to <p>...</p> -->
4670
+ <xsl:variable name="table_without_br">
4671
+ <xsl:apply-templates select="xalan:nodeset($dl_table)" mode="table-without-br"/>
4672
+ </xsl:variable>
4673
+
4674
+ <!-- table_without_br='<xsl:copy-of select="$table_without_br"/>' -->
4675
+
4676
+ <!-- Step: add id to each cell -->
4677
+ <!-- add <word>...</word> for each word, image, math -->
4678
+ <xsl:variable name="simple-table-id">
4679
+ <xsl:apply-templates select="xalan:nodeset($table_without_br)" mode="simple-table-id">
4680
+ <xsl:with-param name="id" select="@id"/>
4681
+ </xsl:apply-templates>
4682
+ </xsl:variable>
4683
+
4684
+ <!-- simple-table-id='<xsl:copy-of select="$simple-table-id"/>' -->
4685
+
4686
+ <xsl:copy-of select="xalan:nodeset($simple-table-id)"/>
4687
+
4688
+ </xsl:variable>
4689
+
4690
+ <!-- DEBUG: simple-table<xsl:copy-of select="$simple-table"/> -->
4691
+
4692
+ <xsl:apply-templates select="xalan:nodeset($simple-table)" mode="process_table-if">
4693
+ <xsl:with-param name="table_or_dl">dl</xsl:with-param>
4694
+ </xsl:apply-templates>
4695
+
4696
+ </xsl:when>
4697
+ <xsl:otherwise>
4201
4698
 
4202
- <fo:table-body>
4203
- <xsl:apply-templates>
4204
- <xsl:with-param name="key_iso" select="normalize-space($key_iso)"/>
4205
- </xsl:apply-templates>
4206
- </fo:table-body>
4699
+ <xsl:variable name="simple-table">
4700
+
4701
+ <xsl:variable name="dl_table">
4702
+ <tbody>
4703
+ <xsl:apply-templates mode="dl">
4704
+ <xsl:with-param name="id" select="@id"/>
4705
+ </xsl:apply-templates>
4706
+ </tbody>
4707
+ </xsl:variable>
4708
+
4709
+ <xsl:copy-of select="$dl_table"/>
4710
+ </xsl:variable>
4711
+
4712
+ <xsl:variable name="colwidths">
4713
+ <xsl:call-template name="calculate-column-widths">
4714
+ <xsl:with-param name="cols-count" select="2"/>
4715
+ <xsl:with-param name="table" select="$simple-table"/>
4716
+ </xsl:call-template>
4717
+ </xsl:variable>
4718
+
4719
+ <!-- <xsl:text disable-output-escaping="yes">&lt;!- -</xsl:text>
4720
+ DEBUG
4721
+ colwidths=<xsl:copy-of select="$colwidths"/>
4722
+ <xsl:text disable-output-escaping="yes">- -&gt;</xsl:text> -->
4723
+
4724
+ <!-- colwidths=<xsl:copy-of select="$colwidths"/> -->
4725
+
4726
+ <xsl:variable name="maxlength_dt">
4727
+ <xsl:call-template name="getMaxLength_dt"/>
4728
+ </xsl:variable>
4729
+
4730
+ <xsl:variable name="isContainsKeepTogetherTag_">
4731
+ false
4732
+ </xsl:variable>
4733
+ <xsl:variable name="isContainsKeepTogetherTag" select="normalize-space($isContainsKeepTogetherTag_)"/>
4734
+ <!-- isContainsExpressReference=<xsl:value-of select="$isContainsExpressReference"/> -->
4735
+
4736
+
4737
+ <xsl:call-template name="setColumnWidth_dl">
4738
+ <xsl:with-param name="colwidths" select="$colwidths"/>
4739
+ <xsl:with-param name="maxlength_dt" select="$maxlength_dt"/>
4740
+ <xsl:with-param name="isContainsKeepTogetherTag" select="$isContainsKeepTogetherTag"/>
4741
+ </xsl:call-template>
4742
+
4743
+ <fo:table-body>
4744
+
4745
+ <!-- DEBUG -->
4746
+ <xsl:if test="$table_if_debug = 'true'">
4747
+ <fo:table-row>
4748
+ <fo:table-cell number-columns-spanned="2" font-size="60%">
4749
+ <xsl:apply-templates select="xalan:nodeset($colwidths)" mode="print_as_xml"/>
4750
+ </fo:table-cell>
4751
+ </fo:table-row>
4752
+ </xsl:if>
4753
+
4754
+ <xsl:apply-templates>
4755
+ <xsl:with-param name="key_iso" select="normalize-space($key_iso)"/>
4756
+ <xsl:with-param name="split_keep-within-line" select="xalan:nodeset($colwidths)/split_keep-within-line"/>
4757
+ </xsl:apply-templates>
4758
+
4759
+ </fo:table-body>
4760
+ </xsl:otherwise>
4761
+ </xsl:choose>
4207
4762
  </fo:table>
4208
4763
  </fo:block>
4209
4764
  </fo:block>
@@ -4214,6 +4769,9 @@
4214
4769
  <xsl:param name="colwidths"/>
4215
4770
  <xsl:param name="maxlength_dt"/>
4216
4771
  <xsl:param name="isContainsKeepTogetherTag"/>
4772
+
4773
+ <!-- <colwidths><xsl:copy-of select="$colwidths"/></colwidths> -->
4774
+
4217
4775
  <xsl:choose>
4218
4776
  <xsl:when test="ancestor::*[local-name()='dl']"><!-- second level, i.e. inlined table -->
4219
4777
  <fo:table-column column-width="50%"/>
@@ -4221,6 +4779,11 @@
4221
4779
  </xsl:when>
4222
4780
  <xsl:otherwise>
4223
4781
  <xsl:choose>
4782
+ <xsl:when test="xalan:nodeset($colwidths)/autolayout">
4783
+ <xsl:call-template name="insertTableColumnWidth">
4784
+ <xsl:with-param name="colwidths" select="$colwidths"/>
4785
+ </xsl:call-template>
4786
+ </xsl:when>
4224
4787
  <xsl:when test="$isContainsKeepTogetherTag">
4225
4788
  <xsl:call-template name="insertTableColumnWidth">
4226
4789
  <xsl:with-param name="colwidths" select="$colwidths"/>
@@ -4265,13 +4828,19 @@
4265
4828
  </xsl:choose>
4266
4829
  </xsl:template><xsl:template name="insertTableColumnWidth">
4267
4830
  <xsl:param name="colwidths"/>
4831
+
4268
4832
  <xsl:for-each select="xalan:nodeset($colwidths)//column">
4269
4833
  <xsl:choose>
4270
4834
  <xsl:when test=". = 1 or . = 0">
4271
4835
  <fo:table-column column-width="proportional-column-width(2)"/>
4272
4836
  </xsl:when>
4273
4837
  <xsl:otherwise>
4274
- <fo:table-column column-width="proportional-column-width({.})"/>
4838
+ <!-- <fo:table-column column-width="proportional-column-width({.})"/> -->
4839
+ <xsl:variable name="divider">
4840
+ <xsl:value-of select="@divider"/>
4841
+ <xsl:if test="not(@divider)">1</xsl:if>
4842
+ </xsl:variable>
4843
+ <fo:table-column column-width="proportional-column-width({round(. div $divider)})"/>
4275
4844
  </xsl:otherwise>
4276
4845
  </xsl:choose>
4277
4846
  </xsl:for-each>
@@ -4333,11 +4902,19 @@
4333
4902
  </fo:table-cell>
4334
4903
  </fo:table-row>
4335
4904
  </xsl:template><xsl:template match="*[local-name()='dt']" mode="dl">
4905
+ <xsl:param name="id"/>
4906
+ <xsl:variable name="row_number" select="count(preceding-sibling::*[local-name()='dt']) + 1"/>
4336
4907
  <tr>
4337
4908
  <td>
4909
+ <xsl:attribute name="id">
4910
+ <xsl:value-of select="concat($id,'_',$row_number,'_1')"/>
4911
+ </xsl:attribute>
4338
4912
  <xsl:apply-templates/>
4339
4913
  </td>
4340
4914
  <td>
4915
+ <xsl:attribute name="id">
4916
+ <xsl:value-of select="concat($id,'_',$row_number,'_2')"/>
4917
+ </xsl:attribute>
4341
4918
 
4342
4919
  <xsl:apply-templates select="following-sibling::*[local-name()='dd'][1]">
4343
4920
  <xsl:with-param name="process">true</xsl:with-param>
@@ -4348,50 +4925,122 @@
4348
4925
 
4349
4926
  </xsl:template><xsl:template match="*[local-name()='dt']">
4350
4927
  <xsl:param name="key_iso"/>
4928
+ <xsl:param name="split_keep-within-line"/>
4351
4929
 
4352
4930
  <fo:table-row xsl:use-attribute-sets="dt-row-style">
4353
- <fo:table-cell>
4931
+ <xsl:call-template name="insert_dt_cell">
4932
+ <xsl:with-param name="key_iso" select="$key_iso"/>
4933
+ <xsl:with-param name="split_keep-within-line" select="$split_keep-within-line"/>
4934
+ </xsl:call-template>
4935
+ <xsl:for-each select="following-sibling::*[local-name()='dd'][1]">
4936
+ <xsl:call-template name="insert_dd_cell">
4937
+ <xsl:with-param name="split_keep-within-line" select="$split_keep-within-line"/>
4938
+ </xsl:call-template>
4939
+ </xsl:for-each>
4940
+ </fo:table-row>
4941
+ </xsl:template><xsl:template name="insert_dt_cell">
4942
+ <xsl:param name="key_iso"/>
4943
+ <xsl:param name="split_keep-within-line"/>
4944
+ <fo:table-cell xsl:use-attribute-sets="dt-cell-style">
4945
+
4946
+ <xsl:if test="$isGenerateTableIF = 'true'">
4947
+ <!-- border is mandatory, to calculate real width -->
4948
+ <xsl:attribute name="border">0.1pt solid black</xsl:attribute>
4949
+ <xsl:attribute name="text-align">left</xsl:attribute>
4950
+ </xsl:if>
4951
+
4952
+
4953
+ <fo:block xsl:use-attribute-sets="dt-block-style">
4954
+ <xsl:copy-of select="@id"/>
4955
+
4956
+ <xsl:if test="normalize-space($key_iso) = 'true'">
4957
+ <xsl:attribute name="margin-top">0</xsl:attribute>
4958
+ </xsl:if>
4959
+
4960
+
4961
+
4962
+ <xsl:apply-templates>
4963
+ <xsl:with-param name="split_keep-within-line" select="$split_keep-within-line"/>
4964
+ </xsl:apply-templates>
4965
+
4966
+ <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"/> -->
4967
+
4968
+ </fo:block>
4969
+ </fo:table-cell>
4970
+ </xsl:template><xsl:template name="insert_dd_cell">
4971
+ <xsl:param name="split_keep-within-line"/>
4972
+ <fo:table-cell xsl:use-attribute-sets="dd-cell-style">
4973
+
4974
+ <xsl:if test="$isGenerateTableIF = 'true'">
4975
+ <!-- border is mandatory, to calculate real width -->
4976
+ <xsl:attribute name="border">0.1pt solid black</xsl:attribute>
4977
+ </xsl:if>
4978
+
4979
+ <fo:block>
4980
+
4981
+ <xsl:if test="$isGenerateTableIF = 'true'">
4982
+ <xsl:attribute name="id"><xsl:value-of select="@id"/></xsl:attribute>
4983
+ </xsl:if>
4984
+
4354
4985
 
4355
- <fo:block xsl:use-attribute-sets="dt-style">
4356
- <xsl:copy-of select="@id"/>
4357
-
4358
- <xsl:if test="normalize-space($key_iso) = 'true'">
4359
- <xsl:attribute name="margin-top">0</xsl:attribute>
4360
- </xsl:if>
4361
-
4362
-
4363
-
4364
- <xsl:apply-templates/>
4365
- </fo:block>
4366
- </fo:table-cell>
4367
- <fo:table-cell>
4368
- <fo:block>
4369
-
4370
4986
 
4371
- <xsl:apply-templates select="following-sibling::*[local-name()='dd'][1]">
4372
- <xsl:with-param name="process">true</xsl:with-param>
4373
- </xsl:apply-templates>
4374
- </fo:block>
4375
- </fo:table-cell>
4376
- </fo:table-row>
4987
+ <xsl:choose>
4988
+ <xsl:when test="$isGenerateTableIF = 'true'">
4989
+ <xsl:apply-templates> <!-- following-sibling::*[local-name()='dd'][1] -->
4990
+ <xsl:with-param name="process">true</xsl:with-param>
4991
+ </xsl:apply-templates>
4992
+ </xsl:when>
4993
+ <xsl:otherwise>
4994
+ <xsl:apply-templates select="."> <!-- following-sibling::*[local-name()='dd'][1] -->
4995
+ <xsl:with-param name="process">true</xsl:with-param>
4996
+ <xsl:with-param name="split_keep-within-line" select="$split_keep-within-line"/>
4997
+ </xsl:apply-templates>
4998
+ </xsl:otherwise>
4999
+
5000
+ </xsl:choose>
5001
+
5002
+ <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"/> -->
5003
+
5004
+ </fo:block>
5005
+ </fo:table-cell>
4377
5006
  </xsl:template><xsl:template match="*[local-name()='dd']" mode="dl"/><xsl:template match="*[local-name()='dd']" mode="dl_process">
4378
5007
  <xsl:apply-templates/>
4379
5008
  </xsl:template><xsl:template match="*[local-name()='dd']">
4380
5009
  <xsl:param name="process">false</xsl:param>
5010
+ <xsl:param name="split_keep-within-line"/>
4381
5011
  <xsl:if test="$process = 'true'">
4382
5012
  <xsl:apply-templates select="@language"/>
4383
- <xsl:apply-templates/>
5013
+ <xsl:apply-templates>
5014
+ <xsl:with-param name="split_keep-within-line" select="$split_keep-within-line"/>
5015
+ </xsl:apply-templates>
4384
5016
  </xsl:if>
4385
5017
  </xsl:template><xsl:template match="*[local-name()='dd']/*[local-name()='p']" mode="inline">
4386
5018
  <fo:inline><xsl:text> </xsl:text><xsl:apply-templates/></fo:inline>
4387
- </xsl:template><xsl:template match="*[local-name()='em']">
5019
+ </xsl:template><xsl:template match="*[local-name()='dt']" mode="dl_if">
5020
+ <xsl:param name="id"/>
5021
+ <xsl:variable name="row_number" select="count(preceding-sibling::*[local-name()='dt']) + 1"/>
5022
+ <tr>
5023
+ <td>
5024
+ <xsl:copy-of select="node()"/>
5025
+ </td>
5026
+ <td>
5027
+
5028
+ <xsl:copy-of select="following-sibling::*[local-name()='dd'][1]/node()"/>
5029
+
5030
+ </td>
5031
+ </tr>
5032
+
5033
+ </xsl:template><xsl:template match="*[local-name()='dd']" mode="dl_if"/><xsl:template match="*[local-name()='em']">
4388
5034
  <fo:inline font-style="italic">
4389
5035
  <xsl:apply-templates/>
4390
5036
  </fo:inline>
4391
5037
  </xsl:template><xsl:template match="*[local-name()='strong'] | *[local-name()='b']">
5038
+ <xsl:param name="split_keep-within-line"/>
4392
5039
  <fo:inline font-weight="bold">
4393
5040
 
4394
- <xsl:apply-templates/>
5041
+ <xsl:apply-templates>
5042
+ <xsl:with-param name="split_keep-within-line" select="$split_keep-within-line"/>
5043
+ </xsl:apply-templates>
4395
5044
  </fo:inline>
4396
5045
  </xsl:template><xsl:template match="*[local-name()='padding']">
4397
5046
  <fo:inline padding-right="{@value}"> </fo:inline>
@@ -4592,6 +5241,10 @@
4592
5241
  <xsl:param name="text"/>
4593
5242
  <xsl:param name="separator" select="' '"/>
4594
5243
  <xsl:choose>
5244
+
5245
+ <xsl:when test="$isGenerateTableIF = 'true' and not(contains($text, $separator))">
5246
+ <word><xsl:value-of select="normalize-space($text)"/></word>
5247
+ </xsl:when>
4595
5248
  <xsl:when test="not(contains($text, $separator))">
4596
5249
  <word>
4597
5250
  <xsl:variable name="len_str_tmp" select="string-length(normalize-space($text))"/>
@@ -4636,13 +5289,66 @@
4636
5289
  </xsl:when>
4637
5290
  <xsl:otherwise>
4638
5291
  <word>
4639
- <xsl:value-of select="string-length(normalize-space(substring-before($text, $separator)))"/>
5292
+ <xsl:variable name="word" select="normalize-space(substring-before($text, $separator))"/>
5293
+ <xsl:choose>
5294
+ <xsl:when test="$isGenerateTableIF = 'true'">
5295
+ <xsl:value-of select="$word"/>
5296
+ </xsl:when>
5297
+ <xsl:otherwise>
5298
+ <xsl:value-of select="string-length($word)"/>
5299
+ </xsl:otherwise>
5300
+ </xsl:choose>
4640
5301
  </word>
4641
5302
  <xsl:call-template name="tokenize">
4642
5303
  <xsl:with-param name="text" select="substring-after($text, $separator)"/>
4643
5304
  </xsl:call-template>
4644
5305
  </xsl:otherwise>
4645
5306
  </xsl:choose>
5307
+ </xsl:template><xsl:template name="tokenize_with_tags">
5308
+ <xsl:param name="tags"/>
5309
+ <xsl:param name="text"/>
5310
+ <xsl:param name="separator" select="' '"/>
5311
+ <xsl:choose>
5312
+
5313
+ <xsl:when test="not(contains($text, $separator))">
5314
+ <word>
5315
+ <xsl:call-template name="enclose_text_in_tags">
5316
+ <xsl:with-param name="text" select="normalize-space($text)"/>
5317
+ <xsl:with-param name="tags" select="$tags"/>
5318
+ </xsl:call-template>
5319
+ </word>
5320
+ </xsl:when>
5321
+ <xsl:otherwise>
5322
+ <word>
5323
+ <xsl:call-template name="enclose_text_in_tags">
5324
+ <xsl:with-param name="text" select="normalize-space(substring-before($text, $separator))"/>
5325
+ <xsl:with-param name="tags" select="$tags"/>
5326
+ </xsl:call-template>
5327
+ </word>
5328
+ <xsl:call-template name="tokenize_with_tags">
5329
+ <xsl:with-param name="text" select="substring-after($text, $separator)"/>
5330
+ </xsl:call-template>
5331
+ </xsl:otherwise>
5332
+ </xsl:choose>
5333
+ </xsl:template><xsl:template name="enclose_text_in_tags">
5334
+ <xsl:param name="text"/>
5335
+ <xsl:param name="tags"/>
5336
+ <xsl:param name="num">1</xsl:param> <!-- default (start) value -->
5337
+
5338
+ <xsl:variable name="tag_name" select="normalize-space(xalan:nodeset($tags)//tag[$num])"/>
5339
+
5340
+ <xsl:choose>
5341
+ <xsl:when test="$tag_name = ''"><xsl:value-of select="$text"/></xsl:when>
5342
+ <xsl:otherwise>
5343
+ <xsl:element name="{$tag_name}">
5344
+ <xsl:call-template name="enclose_text_in_tags">
5345
+ <xsl:with-param name="text" select="$text"/>
5346
+ <xsl:with-param name="tags" select="$tags"/>
5347
+ <xsl:with-param name="num" select="$num + 1"/>
5348
+ </xsl:call-template>
5349
+ </xsl:element>
5350
+ </xsl:otherwise>
5351
+ </xsl:choose>
4646
5352
  </xsl:template><xsl:template name="max_length">
4647
5353
  <xsl:param name="words"/>
4648
5354
  <xsl:for-each select="$words//word">
@@ -4743,12 +5449,19 @@
4743
5449
  </xsl:otherwise>
4744
5450
  </xsl:choose>
4745
5451
  </xsl:template><xsl:template name="getSimpleTable">
5452
+ <xsl:param name="id"/>
5453
+
4746
5454
  <xsl:variable name="simple-table">
4747
5455
 
5456
+ <!-- Step 0. replace <br/> to <p>...</p> -->
5457
+ <xsl:variable name="table_without_br">
5458
+ <xsl:apply-templates mode="table-without-br"/>
5459
+ </xsl:variable>
5460
+
4748
5461
  <!-- Step 1. colspan processing -->
4749
5462
  <xsl:variable name="simple-table-colspan">
4750
5463
  <tbody>
4751
- <xsl:apply-templates mode="simple-table-colspan"/>
5464
+ <xsl:apply-templates select="xalan:nodeset($table_without_br)" mode="simple-table-colspan"/>
4752
5465
  </tbody>
4753
5466
  </xsl:variable>
4754
5467
 
@@ -4757,10 +5470,67 @@
4757
5470
  <xsl:apply-templates select="xalan:nodeset($simple-table-colspan)" mode="simple-table-rowspan"/>
4758
5471
  </xsl:variable>
4759
5472
 
4760
- <xsl:copy-of select="xalan:nodeset($simple-table-rowspan)"/>
4761
-
5473
+ <!-- Step 3: add id to each cell -->
5474
+ <!-- add <word>...</word> for each word, image, math -->
5475
+ <xsl:variable name="simple-table-id">
5476
+ <xsl:apply-templates select="xalan:nodeset($simple-table-rowspan)" mode="simple-table-id">
5477
+ <xsl:with-param name="id" select="$id"/>
5478
+ </xsl:apply-templates>
5479
+ </xsl:variable>
5480
+
5481
+ <xsl:copy-of select="xalan:nodeset($simple-table-id)"/>
5482
+
4762
5483
  </xsl:variable>
4763
5484
  <xsl:copy-of select="$simple-table"/>
5485
+ </xsl:template><xsl:template match="@*|node()" mode="table-without-br">
5486
+ <xsl:copy>
5487
+ <xsl:apply-templates select="@*|node()" mode="table-without-br"/>
5488
+ </xsl:copy>
5489
+ </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">
5490
+ <xsl:copy>
5491
+ <xsl:copy-of select="@*"/>
5492
+ <p>
5493
+ <xsl:copy-of select="node()"/>
5494
+ </p>
5495
+ </xsl:copy>
5496
+ </xsl:template><xsl:template match="*[local-name()='th' or local-name()='td'][*[local-name()='br']]" mode="table-without-br">
5497
+ <xsl:copy>
5498
+ <xsl:copy-of select="@*"/>
5499
+ <xsl:for-each select="*[local-name()='br']">
5500
+ <xsl:variable name="current_id" select="generate-id()"/>
5501
+ <p>
5502
+ <xsl:for-each select="preceding-sibling::node()[following-sibling::*[local-name() = 'br'][1][generate-id() = $current_id]][not(local-name() = 'br')]">
5503
+ <xsl:copy-of select="."/>
5504
+ </xsl:for-each>
5505
+ </p>
5506
+ <xsl:if test="not(following-sibling::*[local-name() = 'br'])">
5507
+ <p>
5508
+ <xsl:for-each select="following-sibling::node()">
5509
+ <xsl:copy-of select="."/>
5510
+ </xsl:for-each>
5511
+ </p>
5512
+ </xsl:if>
5513
+ </xsl:for-each>
5514
+ </xsl:copy>
5515
+ </xsl:template><xsl:template match="*[local-name()='th' or local-name()='td']/*[local-name() = 'p'][*[local-name()='br']]" mode="table-without-br">
5516
+ <xsl:for-each select="*[local-name()='br']">
5517
+ <xsl:variable name="current_id" select="generate-id()"/>
5518
+ <p>
5519
+ <xsl:for-each select="preceding-sibling::node()[following-sibling::*[local-name() = 'br'][1][generate-id() = $current_id]][not(local-name() = 'br')]">
5520
+ <xsl:copy-of select="."/>
5521
+ </xsl:for-each>
5522
+ </p>
5523
+ <xsl:if test="not(following-sibling::*[local-name() = 'br'])">
5524
+ <p>
5525
+ <xsl:for-each select="following-sibling::node()">
5526
+ <xsl:copy-of select="."/>
5527
+ </xsl:for-each>
5528
+ </p>
5529
+ </xsl:if>
5530
+ </xsl:for-each>
5531
+ </xsl:template><xsl:template match="text()[not(ancestor::*[local-name() = 'sourcecode'])]" mode="table-without-br">
5532
+ <xsl:variable name="text" select="translate(.,'&#9;&#10;&#13;','')"/>
5533
+ <xsl:value-of select="java:replaceAll(java:java.lang.String.new($text),' {2,}',' ')"/>
4764
5534
  </xsl:template><xsl:template match="*[local-name()='thead'] | *[local-name()='tbody']" mode="simple-table-colspan">
4765
5535
  <xsl:apply-templates mode="simple-table-colspan"/>
4766
5536
  </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">
@@ -4850,6 +5620,126 @@
4850
5620
  <xsl:apply-templates select="following-sibling::tr[1]" mode="simple-table-rowspan">
4851
5621
  <xsl:with-param name="previousRow" select="$newRow"/>
4852
5622
  </xsl:apply-templates>
5623
+ </xsl:template><xsl:template match="/" mode="simple-table-id">
5624
+ <xsl:param name="id"/>
5625
+ <xsl:variable name="id_prefixed" select="concat('table_if_',$id)"/> <!-- table id prefixed by 'table_if_' to simple search in IF -->
5626
+ <xsl:apply-templates select="@*|node()" mode="simple-table-id">
5627
+ <xsl:with-param name="id" select="$id_prefixed"/>
5628
+ </xsl:apply-templates>
5629
+ </xsl:template><xsl:template match="@*|node()" mode="simple-table-id">
5630
+ <xsl:param name="id"/>
5631
+ <xsl:copy>
5632
+ <xsl:apply-templates select="@*|node()" mode="simple-table-id">
5633
+ <xsl:with-param name="id" select="$id"/>
5634
+ </xsl:apply-templates>
5635
+ </xsl:copy>
5636
+ </xsl:template><xsl:template match="*[local-name()='tbody']" mode="simple-table-id">
5637
+ <xsl:param name="id"/>
5638
+ <xsl:copy>
5639
+ <xsl:copy-of select="@*"/>
5640
+ <xsl:attribute name="id"><xsl:value-of select="$id"/></xsl:attribute>
5641
+ <xsl:apply-templates select="node()" mode="simple-table-id">
5642
+ <xsl:with-param name="id" select="$id"/>
5643
+ </xsl:apply-templates>
5644
+ </xsl:copy>
5645
+ </xsl:template><xsl:template match="*[local-name()='th' or local-name()='td']" mode="simple-table-id">
5646
+ <xsl:param name="id"/>
5647
+ <xsl:copy>
5648
+ <xsl:copy-of select="@*"/>
5649
+ <xsl:variable name="row_number" select="count(../preceding-sibling::*) + 1"/>
5650
+ <xsl:variable name="col_number" select="count(preceding-sibling::*) + 1"/>
5651
+ <xsl:attribute name="id">
5652
+ <xsl:value-of select="concat($id,'_',$row_number,'_',$col_number)"/>
5653
+ </xsl:attribute>
5654
+
5655
+ <xsl:for-each select="*[local-name() = 'p']">
5656
+ <xsl:copy>
5657
+ <xsl:copy-of select="@*"/>
5658
+ <xsl:variable name="p_num" select="count(preceding-sibling::*[local-name() = 'p']) + 1"/>
5659
+ <xsl:attribute name="id">
5660
+ <xsl:value-of select="concat($id,'_',$row_number,'_',$col_number,'_p_',$p_num)"/>
5661
+ </xsl:attribute>
5662
+
5663
+ <xsl:copy-of select="node()"/>
5664
+ </xsl:copy>
5665
+ </xsl:for-each>
5666
+
5667
+
5668
+ <xsl:if test="$isGenerateTableIF = 'true'"> <!-- split each paragraph to words, image, math -->
5669
+
5670
+ <xsl:variable name="td_text">
5671
+ <xsl:apply-templates select="." mode="td_text_with_formatting"/>
5672
+ </xsl:variable>
5673
+
5674
+ <!-- td_text='<xsl:copy-of select="$td_text"/>' -->
5675
+
5676
+ <xsl:variable name="words">
5677
+ <xsl:for-each select=".//*[local-name() = 'image' or local-name() = 'stem']">
5678
+ <word>
5679
+ <xsl:copy-of select="."/>
5680
+ </word>
5681
+ </xsl:for-each>
5682
+
5683
+ <xsl:for-each select="xalan:nodeset($td_text)//*[local-name() = 'word'][normalize-space() != '']">
5684
+ <xsl:copy-of select="."/>
5685
+ </xsl:for-each>
5686
+
5687
+ </xsl:variable>
5688
+
5689
+ <xsl:for-each select="xalan:nodeset($words)/word">
5690
+ <xsl:variable name="num" select="count(preceding-sibling::word) + 1"/>
5691
+ <xsl:copy>
5692
+ <xsl:attribute name="id">
5693
+ <xsl:value-of select="concat($id,'_',$row_number,'_',$col_number,'_word_',$num)"/>
5694
+ </xsl:attribute>
5695
+ <xsl:copy-of select="node()"/>
5696
+ </xsl:copy>
5697
+ </xsl:for-each>
5698
+ </xsl:if>
5699
+ </xsl:copy>
5700
+
5701
+ </xsl:template><xsl:template match="@*|node()" mode="td_text_with_formatting">
5702
+ <xsl:copy>
5703
+ <xsl:apply-templates select="@*|node()" mode="td_text_with_formatting"/>
5704
+ </xsl:copy>
5705
+ </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">
5706
+ <xsl:variable name="formatting_tags">
5707
+ <xsl:call-template name="getFormattingTags"/>
5708
+ </xsl:variable>
5709
+ <word>
5710
+ <xsl:call-template name="enclose_text_in_tags">
5711
+ <xsl:with-param name="text" select="normalize-space(.)"/>
5712
+ <xsl:with-param name="tags" select="$formatting_tags"/>
5713
+ </xsl:call-template>
5714
+ </word>
5715
+ </xsl:template><xsl:template match="*[local-name() != 'keep-together_within-line']/text()" mode="td_text_with_formatting">
5716
+
5717
+ <xsl:variable name="td_text" select="."/>
5718
+
5719
+ <xsl:variable name="string_with_added_zerospaces">
5720
+ <xsl:call-template name="add-zero-spaces-java">
5721
+ <xsl:with-param name="text" select="$td_text"/>
5722
+ </xsl:call-template>
5723
+ </xsl:variable>
5724
+
5725
+ <xsl:variable name="formatting_tags">
5726
+ <xsl:call-template name="getFormattingTags"/>
5727
+ </xsl:variable>
5728
+
5729
+ <!-- <word>text</word> -->
5730
+ <xsl:call-template name="tokenize_with_tags">
5731
+ <xsl:with-param name="tags" select="$formatting_tags"/>
5732
+ <xsl:with-param name="text" select="normalize-space(translate($string_with_added_zerospaces, '​­', ' '))"/> <!-- replace zero-width-space and soft-hyphen to space -->
5733
+ </xsl:call-template>
5734
+ </xsl:template><xsl:template name="getFormattingTags">
5735
+ <tags>
5736
+ <xsl:if test="ancestor::*[local-name() = 'strong']"><tag>strong</tag></xsl:if>
5737
+ <xsl:if test="ancestor::*[local-name() = 'em']"><tag>em</tag></xsl:if>
5738
+ <xsl:if test="ancestor::*[local-name() = 'sub']"><tag>sub</tag></xsl:if>
5739
+ <xsl:if test="ancestor::*[local-name() = 'sup']"><tag>sup</tag></xsl:if>
5740
+ <xsl:if test="ancestor::*[local-name() = 'tt']"><tag>tt</tag></xsl:if>
5741
+ <xsl:if test="ancestor::*[local-name() = 'keep-together_within-line']"><tag>keep-together_within-line</tag></xsl:if>
5742
+ </tags>
4853
5743
  </xsl:template><xsl:template name="getLang">
4854
5744
  <xsl:variable name="language_current" select="normalize-space(//*[local-name()='bibdata']//*[local-name()='language'][@current = 'true'])"/>
4855
5745
  <xsl:variable name="language">
@@ -6580,7 +7470,9 @@
6580
7470
  <!-- <xsl:attribute name="border">0.5pt solid black</xsl:attribute> -->
6581
7471
  </xsl:if>
6582
7472
  <xsl:variable name="simple-table">
6583
- <xsl:call-template name="getSimpleTable"/>
7473
+ <xsl:call-template name="getSimpleTable">
7474
+ <xsl:with-param name="id" select="@id"/>
7475
+ </xsl:call-template>
6584
7476
  </xsl:variable>
6585
7477
  <xsl:variable name="cols-count" select="count(xalan:nodeset($simple-table)//tr[1]/td)"/>
6586
7478
  <xsl:if test="$cols-count = 2 and not(ancestor::*[local-name()='table'])">
@@ -7539,7 +8431,7 @@
7539
8431
  <!-- <fo:inline id="{@id}" font-size="1pt"/> -->
7540
8432
  <fo:inline id="{@id}" font-size="1pt"><xsl:value-of select="$hair_space"/></fo:inline>
7541
8433
  <!-- we need to add zero-width space, otherwise this fo:inline is missing in IF xml -->
7542
- <xsl:if test="not(following-sibling::node()[normalize-space() != ''])"> </xsl:if>
8434
+ <xsl:if test="not(following-sibling::node()[normalize-space() != ''])"><fo:inline font-size="1pt"> </fo:inline></xsl:if>
7543
8435
  </xsl:template><xsl:template match="*[local-name() = 'errata']">
7544
8436
  <!-- <row>
7545
8437
  <date>05-07-2013</date>
@@ -9007,4 +9899,40 @@
9007
9899
  <xsl:value-of select="$value"/>
9008
9900
  </xsl:otherwise>
9009
9901
  </xsl:choose>
9902
+ </xsl:template><xsl:template match="*" mode="print_as_xml">
9903
+ <xsl:param name="level">0</xsl:param>
9904
+
9905
+ <fo:block margin-left="{2*$level}mm">
9906
+ <xsl:text>
9907
+ &lt;</xsl:text>
9908
+ <xsl:value-of select="local-name()"/>
9909
+ <xsl:for-each select="@*">
9910
+ <xsl:text> </xsl:text>
9911
+ <xsl:value-of select="local-name()"/>
9912
+ <xsl:text>="</xsl:text>
9913
+ <xsl:value-of select="."/>
9914
+ <xsl:text>"</xsl:text>
9915
+ </xsl:for-each>
9916
+ <xsl:text>&gt;</xsl:text>
9917
+
9918
+ <xsl:if test="not(*)">
9919
+ <fo:inline font-weight="bold"><xsl:value-of select="."/></fo:inline>
9920
+ <xsl:text>&lt;/</xsl:text>
9921
+ <xsl:value-of select="local-name()"/>
9922
+ <xsl:text>&gt;</xsl:text>
9923
+ </xsl:if>
9924
+ </fo:block>
9925
+
9926
+ <xsl:if test="*">
9927
+ <fo:block>
9928
+ <xsl:apply-templates mode="print_as_xml">
9929
+ <xsl:with-param name="level" select="$level + 1"/>
9930
+ </xsl:apply-templates>
9931
+ </fo:block>
9932
+ <fo:block margin-left="{2*$level}mm">
9933
+ <xsl:text>&lt;/</xsl:text>
9934
+ <xsl:value-of select="local-name()"/>
9935
+ <xsl:text>&gt;</xsl:text>
9936
+ </fo:block>
9937
+ </xsl:if>
9010
9938
  </xsl:template></xsl:stylesheet>