metanorma-bipm 2.0.7 → 2.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,8 +5,6 @@
5
5
  <xsl:param name="initial_page_number"/>
6
6
  <xsl:param name="doc_split_by_language"/>
7
7
 
8
- <xsl:param name="add_math_as_text">true</xsl:param>
9
-
10
8
  <xsl:param name="add_math_as_attachment">true</xsl:param>
11
9
 
12
10
  <xsl:key name="kfn" match="*[local-name() = 'fn'][not(ancestor::*[(local-name() = 'table' or local-name() = 'figure') and not(ancestor::*[local-name() = 'name'])])]" use="@reference"/>
@@ -220,7 +218,13 @@
220
218
 
221
219
 
222
220
  <xsl:template match="/">
223
- <fo:root xsl:use-attribute-sets="root-style" xml:lang="{$lang}">
221
+ <fo:root xml:lang="{$lang}">
222
+ <xsl:variable name="root-style">
223
+ <root-style xsl:use-attribute-sets="root-style"/>
224
+ </xsl:variable>
225
+ <xsl:call-template name="insertRootStyle">
226
+ <xsl:with-param name="root-style" select="$root-style"/>
227
+ </xsl:call-template>
224
228
  <fo:layout-master-set>
225
229
 
226
230
  <!-- blank page -->
@@ -979,7 +983,7 @@
979
983
  <fo:block-container font-size="9pt" border-bottom="1pt solid black" width="68mm" text-align="center" margin-bottom="14pt">
980
984
  <fo:block font-weight="bold" margin-bottom="2.5mm">
981
985
  <fo:inline padding-right="10mm">
982
- <xsl:apply-templates select="bipm:bibdata/bipm:edition">
986
+ <xsl:apply-templates select="bipm:bibdata/bipm:edition[normalize-space(@language) = '']">
983
987
  <xsl:with-param name="font-size" select="'70%'"/>
984
988
  <xsl:with-param name="baseline-shift" select="'45%'"/>
985
989
  <xsl:with-param name="curr_lang" select="$curr_lang"/>
@@ -1259,7 +1263,7 @@
1259
1263
  <fo:block-container font-size="9pt" border-bottom="1pt solid black" width="68mm" text-align="center" margin-bottom="14pt">
1260
1264
  <fo:block font-weight="bold" margin-bottom="2.5mm">
1261
1265
  <fo:inline padding-right="10mm">
1262
- <xsl:apply-templates select="bipm:bibdata/bipm:edition">
1266
+ <xsl:apply-templates select="bipm:bibdata/bipm:edition[normalize-space(@language) = '']">
1263
1267
  <xsl:with-param name="font-size" select="'70%'"/>
1264
1268
  <xsl:with-param name="baseline-shift" select="'45%'"/>
1265
1269
  <xsl:with-param name="curr_lang" select="$curr_lang"/>
@@ -1347,7 +1351,7 @@
1347
1351
  <xsl:call-template name="getLanguages"/>
1348
1352
  </xsl:variable>
1349
1353
  <xsl:variable name="editionFO">
1350
- <xsl:apply-templates select="(//bipm:bipm-standard)[1]/bipm:bibdata/bipm:edition">
1354
+ <xsl:apply-templates select="(//bipm:bipm-standard)[1]/bipm:bibdata/bipm:edition[normalize-space(@language) = '']">
1351
1355
  <xsl:with-param name="curr_lang" select="xalan:nodeset($languages)/lang[1]"/>
1352
1356
  </xsl:apply-templates>
1353
1357
  </xsl:variable>
@@ -1426,7 +1430,7 @@
1426
1430
 
1427
1431
  <xsl:variable name="edition_str">édition</xsl:variable>
1428
1432
 
1429
- <fo:block font-size="14pt" font-weight="{$weight-bold}" margin-top="4mm"><xsl:value-of select="concat((//bipm:bipm-standard)[1]/bipm:bibdata/bipm:edition, ' ', $edition_str, ' ', $copyrightYear)"/></fo:block>
1433
+ <fo:block font-size="14pt" font-weight="{$weight-bold}" margin-top="4mm"><xsl:value-of select="concat((//bipm:bipm-standard)[1]/bipm:bibdata/bipm:edition[normalize-space(@language) = ''], ' ', $edition_str, ' ', $copyrightYear)"/></fo:block>
1430
1434
  </fo:block-container>
1431
1435
 
1432
1436
  <fo:block-container absolute-position="fixed" left="12.5mm" top="92mm" height="170mm" width="144mm" display-align="center">
@@ -2103,12 +2107,6 @@
2103
2107
  <xsl:param name="baseline-shift" select="'30%'"/>
2104
2108
  <xsl:param name="curr_lang" select="'fr'"/>
2105
2109
  <fo:inline>
2106
- <xsl:variable name="title-edition">
2107
- <xsl:call-template name="getTitle">
2108
- <xsl:with-param name="name" select="'title-edition'"/>
2109
- <xsl:with-param name="lang" select="$curr_lang"/>
2110
- </xsl:call-template>
2111
- </xsl:variable>
2112
2110
  <xsl:value-of select="."/>
2113
2111
  <fo:inline font-size="{$font-size}" baseline-shift="{$baseline-shift}">
2114
2112
  <xsl:call-template name="number-to-ordinal">
@@ -2117,7 +2115,9 @@
2117
2115
  </xsl:call-template>
2118
2116
  </fo:inline>
2119
2117
  <xsl:text> </xsl:text>
2120
- <xsl:value-of select="java:toLowerCase(java:java.lang.String.new($title-edition))"/>
2118
+ <xsl:call-template name="getLocalizedString">
2119
+ <xsl:with-param name="key">edition</xsl:with-param>
2120
+ </xsl:call-template>
2121
2121
  <xsl:text/>
2122
2122
  </fo:inline>
2123
2123
  </xsl:template>
@@ -2727,6 +2727,7 @@
2727
2727
 
2728
2728
  <xsl:template match="bipm:p" name="paragraph">
2729
2729
  <xsl:param name="inline" select="'false'"/>
2730
+ <xsl:param name="split_keep-within-line"/>
2730
2731
 
2731
2732
  <xsl:variable name="previous-element" select="local-name(preceding-sibling::*[1])"/>
2732
2733
  <xsl:variable name="element-name">
@@ -2773,7 +2774,9 @@
2773
2774
  <xsl:attribute name="role">BlockQuote</xsl:attribute>
2774
2775
  </xsl:if>
2775
2776
  <xsl:attribute name="line-height-shift-adjustment">disregard-shifts</xsl:attribute>
2776
- <xsl:apply-templates/>
2777
+ <xsl:apply-templates>
2778
+ <xsl:with-param name="split_keep-within-line" select="$split_keep-within-line"/>
2779
+ </xsl:apply-templates>
2777
2780
  </xsl:element>
2778
2781
  <xsl:if test="$element-name = 'fo:inline' and not($inline = 'true') and not(local-name(..) = 'admonition')">
2779
2782
  <fo:block margin-bottom="6pt">
@@ -3201,112 +3204,6 @@
3201
3204
  <xsl:value-of select="translate(., ' ', ' ')"/>
3202
3205
  </xsl:template>
3203
3206
 
3204
- <xsl:template match="mathml:math" priority="2">
3205
- <xsl:variable name="isAdded" select="@added"/>
3206
- <xsl:variable name="isDeleted" select="@deleted"/>
3207
-
3208
- <fo:inline xsl:use-attribute-sets="mathml-style">
3209
-
3210
- <xsl:if test="ancestor::*[local-name()='table']">
3211
- <xsl:attribute name="font-size">95%</xsl:attribute> <!-- base font in table is 10pt -->
3212
- </xsl:if>
3213
-
3214
- <xsl:call-template name="setTrackChangesStyles">
3215
- <xsl:with-param name="isAdded" select="$isAdded"/>
3216
- <xsl:with-param name="isDeleted" select="$isDeleted"/>
3217
- </xsl:call-template>
3218
-
3219
- <xsl:if test="$add_math_as_text = 'true'">
3220
- <!-- set unique font-size (fiction) -->
3221
- <xsl:variable name="font-size_sfx"><xsl:number level="any"/></xsl:variable>
3222
- <fo:inline color="white" font-size="1.{$font-size_sfx}pt" font-style="normal" font-weight="normal"><xsl:value-of select="$zero_width_space"/></fo:inline> <!-- zero width space -->
3223
- </xsl:if>
3224
-
3225
- <!-- <fo:wrapper role="artifact"> -->
3226
-
3227
- <xsl:variable name="mathml_content">
3228
- <xsl:apply-templates select="." mode="mathml_actual_text"/>
3229
- </xsl:variable>
3230
- <!-- DEBUG: mathml_content=<xsl:value-of select="$mathml_content"/> -->
3231
-
3232
- <xsl:variable name="comment_text_following" select="following-sibling::node()[1][self::comment()]"/>
3233
- <xsl:variable name="comment_text_">
3234
- <xsl:choose>
3235
- <xsl:when test="normalize-space($comment_text_following) != ''">
3236
- <xsl:value-of select="$comment_text_following"/>
3237
- </xsl:when>
3238
- <xsl:otherwise>
3239
- <xsl:value-of select="normalize-space(translate(.,' ⁢',' '))"/>
3240
- </xsl:otherwise>
3241
- </xsl:choose>
3242
- </xsl:variable>
3243
- <xsl:variable name="comment_text_2" select="java:org.metanorma.fop.Util.unescape($comment_text_)"/>
3244
- <xsl:variable name="comment_text" select="java:trim(java:java.lang.String.new($comment_text_2))"/>
3245
-
3246
- <xsl:variable name="filename" select="xalan:nodeset($mathml_attachments)//attachment[. = $mathml_content]/@filename"/>
3247
- <xsl:choose>
3248
- <xsl:when test="$add_math_as_attachment = 'true' and normalize-space($filename) != ''">
3249
- <xsl:variable name="url" select="concat('url(embedded-file:', $filename, ')')"/>
3250
- <fo:basic-link external-destination="{$url}" fox:alt-text="MathLink">
3251
- <xsl:if test="normalize-space($comment_text) != ''">
3252
- <!-- put Mathin Alternate Text -->
3253
- <xsl:attribute name="fox:alt-text">
3254
- <xsl:value-of select="$comment_text"/>
3255
- </xsl:attribute>
3256
- </xsl:if>
3257
- <xsl:call-template name="mathml_instream_object">
3258
- <xsl:with-param name="mathml_content" select="$mathml_content"/>
3259
- <xsl:with-param name="comment_text" select="$comment_text"/>
3260
- </xsl:call-template>
3261
- </fo:basic-link>
3262
- <!-- </xsl:if> -->
3263
- </xsl:when>
3264
- <xsl:otherwise>
3265
- <xsl:call-template name="mathml_instream_object">
3266
- <xsl:with-param name="mathml_content" select="$mathml_content"/>
3267
- <xsl:with-param name="comment_text" select="$comment_text"/>
3268
- </xsl:call-template>
3269
- </xsl:otherwise>
3270
- </xsl:choose>
3271
- <!-- </fo:wrapper> -->
3272
- </fo:inline>
3273
- </xsl:template>
3274
-
3275
- <xsl:template name="mathml_instream_object">
3276
- <xsl:param name="mathml_content"/>
3277
- <xsl:param name="comment_text"/>
3278
-
3279
- <xsl:variable name="mathml">
3280
- <xsl:apply-templates select="." mode="mathml"/>
3281
- </xsl:variable>
3282
-
3283
- <fo:instream-foreign-object fox:alt-text="Math">
3284
-
3285
- <xsl:if test="local-name(../..) = 'formula'">
3286
- <xsl:attribute name="width">95%</xsl:attribute>
3287
- <xsl:attribute name="content-height">100%</xsl:attribute>
3288
- <xsl:attribute name="content-width">scale-down-to-fit</xsl:attribute>
3289
- <xsl:attribute name="scaling">uniform</xsl:attribute>
3290
- </xsl:if>
3291
-
3292
- <!-- put MathML in Actual Text -->
3293
- <xsl:attribute name="fox:actual-text">
3294
- <xsl:value-of select="$mathml_content"/>
3295
- </xsl:attribute>
3296
-
3297
- <xsl:if test="$add_math_as_text = 'true'">
3298
- <xsl:if test="normalize-space($comment_text) != ''">
3299
- <!-- put Mathin Alternate Text -->
3300
- <xsl:attribute name="fox:alt-text">
3301
- <xsl:value-of select="$comment_text"/>
3302
- </xsl:attribute>
3303
- </xsl:if>
3304
- </xsl:if>
3305
-
3306
- <xsl:copy-of select="xalan:nodeset($mathml)"/>
3307
- </fo:instream-foreign-object>
3308
- </xsl:template>
3309
-
3310
3207
 
3311
3208
  <!-- =================== -->
3312
3209
  <!-- Table of Contents (ToC) processing -->
@@ -3916,7 +3813,9 @@
3916
3813
  </xsl:template>
3917
3814
 
3918
3815
 
3919
- <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:variable name="lang">
3816
+ <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_">
3817
+ false
3818
+ </xsl:variable><xsl:variable name="isGenerateTableIF" select="normalize-space($isGenerateTableIF_)"/><xsl:variable name="lang">
3920
3819
  <xsl:call-template name="getLang"/>
3921
3820
  </xsl:variable><xsl:variable name="pageWidth_">
3922
3821
  210
@@ -3931,20 +3830,7 @@
3931
3830
  </xsl:variable><xsl:variable name="marginTop" select="normalize-space($marginTop_)"/><xsl:variable name="marginBottom_">
3932
3831
  22
3933
3832
  </xsl:variable><xsl:variable name="marginBottom" select="normalize-space($marginBottom_)"/><xsl:variable name="titles_">
3934
-
3935
- <title-edition lang="en">
3936
-
3937
- <xsl:text>Edition </xsl:text>
3938
-
3939
- </title-edition>
3940
3833
 
3941
- <title-edition lang="fr">
3942
- <xsl:text>Édition </xsl:text>
3943
- </title-edition>
3944
-
3945
- <title-edition lang="ru">
3946
- <xsl:text>Издание </xsl:text>
3947
- </title-edition>
3948
3834
 
3949
3835
  <!-- These titles of Table of contents renders different than determined in localized-strings -->
3950
3836
  <title-toc lang="en">
@@ -4027,7 +3913,7 @@
4027
3913
  </xsl:variable><xsl:variable name="bibdata">
4028
3914
  <xsl:copy-of select="//*[contains(local-name(), '-standard')]/*[local-name() = 'bibdata']"/>
4029
3915
  <xsl:copy-of select="//*[contains(local-name(), '-standard')]/*[local-name() = 'localized-strings']"/>
4030
- </xsl:variable><xsl:variable name="linebreak">&#8232;</xsl:variable><xsl:variable name="tab_zh"> </xsl:variable><xsl:variable name="non_breaking_hyphen">‑</xsl:variable><xsl:variable name="thin_space"> </xsl:variable><xsl:variable name="zero_width_space">​</xsl:variable><xsl:variable name="en_dash">–</xsl:variable><xsl:template name="getTitle">
3916
+ </xsl:variable><xsl:variable name="linebreak">&#8232;</xsl:variable><xsl:variable name="tab_zh"> </xsl:variable><xsl:variable name="non_breaking_hyphen">‑</xsl:variable><xsl:variable name="thin_space"> </xsl:variable><xsl:variable name="zero_width_space">​</xsl:variable><xsl:variable name="hair_space"> </xsl:variable><xsl:variable name="en_dash">–</xsl:variable><xsl:template name="getTitle">
4031
3917
  <xsl:param name="name"/>
4032
3918
  <xsl:param name="lang"/>
4033
3919
  <xsl:variable name="lang_">
@@ -4070,7 +3956,30 @@
4070
3956
 
4071
3957
 
4072
3958
 
4073
- </xsl:attribute-set><xsl:attribute-set name="copyright-statement-style">
3959
+ </xsl:attribute-set><xsl:template name="insertRootStyle">
3960
+ <xsl:param name="root-style"/>
3961
+ <xsl:variable name="root-style_" select="xalan:nodeset($root-style)"/>
3962
+
3963
+ <xsl:variable name="additional_fonts_">
3964
+ <xsl:for-each select="//*[contains(local-name(), '-standard')][1]/*[local-name() = 'misc-container']/*[local-name() = 'presentation-metadata'][*[local-name() = 'name'] = 'fonts']/*[local-name() = 'value'] | //*[contains(local-name(), '-standard')][1]/*[local-name() = 'presentation-metadata'][*[local-name() = 'name'] = 'fonts']/*[local-name() = 'value']">
3965
+ <xsl:value-of select="."/><xsl:if test="position() != last()">, </xsl:if>
3966
+ </xsl:for-each>
3967
+ </xsl:variable>
3968
+ <xsl:variable name="additional_fonts" select="normalize-space($additional_fonts_)"/>
3969
+
3970
+ <xsl:for-each select="$root-style_/root-style/@*">
3971
+ <xsl:choose>
3972
+ <xsl:when test="local-name() = 'font-family' and $additional_fonts != ''">
3973
+ <xsl:attribute name="{local-name()}">
3974
+ <xsl:value-of select="."/>, <xsl:value-of select="$additional_fonts"/>
3975
+ </xsl:attribute>
3976
+ </xsl:when>
3977
+ <xsl:otherwise>
3978
+ <xsl:copy-of select="."/>
3979
+ </xsl:otherwise>
3980
+ </xsl:choose>
3981
+ </xsl:for-each>
3982
+ </xsl:template><xsl:attribute-set name="copyright-statement-style">
4074
3983
 
4075
3984
  </xsl:attribute-set><xsl:attribute-set name="copyright-statement-title-style">
4076
3985
 
@@ -4139,7 +4048,6 @@
4139
4048
 
4140
4049
 
4141
4050
  </xsl:attribute-set><xsl:attribute-set name="sourcecode-container-style">
4142
- <xsl:attribute name="margin-left">0mm</xsl:attribute>
4143
4051
 
4144
4052
  </xsl:attribute-set><xsl:attribute-set name="sourcecode-style">
4145
4053
  <xsl:attribute name="white-space">pre</xsl:attribute>
@@ -4218,6 +4126,7 @@
4218
4126
 
4219
4127
 
4220
4128
 
4129
+
4221
4130
  </xsl:attribute-set><xsl:attribute-set name="example-name-style">
4222
4131
 
4223
4132
 
@@ -4367,6 +4276,7 @@
4367
4276
  <xsl:attribute name="font-weight">bold</xsl:attribute>
4368
4277
  <xsl:attribute name="border">solid black 1pt</xsl:attribute>
4369
4278
  <xsl:attribute name="padding-left">1mm</xsl:attribute>
4279
+ <xsl:attribute name="padding-right">1mm</xsl:attribute>
4370
4280
  <xsl:attribute name="display-align">center</xsl:attribute>
4371
4281
 
4372
4282
  <xsl:attribute name="font-weight">normal</xsl:attribute>
@@ -4391,6 +4301,7 @@
4391
4301
  <xsl:attribute name="display-align">center</xsl:attribute>
4392
4302
  <xsl:attribute name="border">solid black 1pt</xsl:attribute>
4393
4303
  <xsl:attribute name="padding-left">1mm</xsl:attribute>
4304
+ <xsl:attribute name="padding-right">1mm</xsl:attribute>
4394
4305
 
4395
4306
 
4396
4307
  <xsl:attribute name="border">solid 0pt white</xsl:attribute>
@@ -4488,7 +4399,8 @@
4488
4399
  </xsl:attribute-set><xsl:attribute-set name="dt-row-style">
4489
4400
 
4490
4401
 
4491
- </xsl:attribute-set><xsl:attribute-set name="dt-style">
4402
+ </xsl:attribute-set><xsl:attribute-set name="dt-cell-style">
4403
+ </xsl:attribute-set><xsl:attribute-set name="dt-block-style">
4492
4404
  <xsl:attribute name="margin-top">6pt</xsl:attribute>
4493
4405
 
4494
4406
 
@@ -4503,6 +4415,8 @@
4503
4415
 
4504
4416
 
4505
4417
 
4418
+ </xsl:attribute-set><xsl:attribute-set name="dd-cell-style">
4419
+ <xsl:attribute name="padding-left">2mm</xsl:attribute>
4506
4420
  </xsl:attribute-set><xsl:attribute-set name="appendix-style">
4507
4421
 
4508
4422
 
@@ -4589,7 +4503,7 @@
4589
4503
 
4590
4504
 
4591
4505
 
4592
- </xsl:attribute-set><xsl:attribute-set name="termnote-name-style">
4506
+ </xsl:attribute-set><xsl:attribute-set name="termnote-name-style">
4593
4507
 
4594
4508
 
4595
4509
 
@@ -5302,22 +5216,32 @@
5302
5216
  <xsl:sort select="@displayorder" data-type="number"/>
5303
5217
  <xsl:apply-templates select="."/>
5304
5218
  </xsl:for-each>
5305
- </xsl:template><xsl:variable name="tag_open">###fo:inline###</xsl:variable><xsl:variable name="tag_close">###/fo:inline###</xsl:variable><xsl:template match="text()" name="text">
5306
- <xsl:variable name="regex_standard_reference">([A-Z]{2,}(/[A-Z]{2,})* \d+(-\d+)*(:\d{4})?)</xsl:variable>
5307
- <xsl:variable name="text" select="java:replaceAll(java:java.lang.String.new(.),$regex_standard_reference,concat($tag_open,'$1',$tag_close))"/>
5308
- <xsl:call-template name="replace_fo_inline">
5309
- <xsl:with-param name="text" select="$text"/>
5310
- </xsl:call-template>
5311
- </xsl:template><xsl:template name="replace_fo_inline">
5219
+ </xsl:template><xsl:variable name="tag_fo_inline_keep-together_within-line_open">###fo:inline keep-together_within-line###</xsl:variable><xsl:variable name="tag_fo_inline_keep-together_within-line_close">###/fo:inline keep-together_within-line###</xsl:variable><xsl:template match="text()" name="text">
5220
+
5221
+ <xsl:variable name="regex_standard_reference">([A-Z]{2,}(/[A-Z]{2,})* \d+(-\d+)*(:\d{4})?)</xsl:variable>
5222
+ <xsl:variable name="text" select="java:replaceAll(java:java.lang.String.new(.),$regex_standard_reference,concat($tag_fo_inline_keep-together_within-line_open,'$1',$tag_fo_inline_keep-together_within-line_close))"/>
5223
+ <xsl:call-template name="replace_fo_inline_tags">
5224
+ <xsl:with-param name="tag_open" select="$tag_fo_inline_keep-together_within-line_open"/>
5225
+ <xsl:with-param name="tag_close" select="$tag_fo_inline_keep-together_within-line_close"/>
5226
+ <xsl:with-param name="text" select="$text"/>
5227
+ </xsl:call-template>
5228
+
5229
+ </xsl:template><xsl:template name="replace_fo_inline_tags">
5230
+ <xsl:param name="tag_open"/>
5231
+ <xsl:param name="tag_close"/>
5312
5232
  <xsl:param name="text"/>
5313
5233
  <xsl:choose>
5314
5234
  <xsl:when test="contains($text, $tag_open)">
5315
5235
  <xsl:value-of select="substring-before($text, $tag_open)"/>
5316
- <xsl:text disable-output-escaping="yes">&lt;fo:inline keep-together.within-line="always"&gt;</xsl:text>
5236
+ <!-- <xsl:text disable-output-escaping="yes">&lt;fo:inline keep-together.within-line="always"&gt;</xsl:text> -->
5317
5237
  <xsl:variable name="text_after" select="substring-after($text, $tag_open)"/>
5318
- <xsl:value-of select="substring-before($text_after, $tag_close)"/>
5319
- <xsl:text disable-output-escaping="yes">&lt;/fo:inline&gt;</xsl:text>
5320
- <xsl:call-template name="replace_fo_inline">
5238
+ <fo:inline keep-together.within-line="always">
5239
+ <xsl:value-of select="substring-before($text_after, $tag_close)"/>
5240
+ </fo:inline>
5241
+ <!-- <xsl:text disable-output-escaping="yes">&lt;/fo:inline&gt;</xsl:text> -->
5242
+ <xsl:call-template name="replace_fo_inline_tags">
5243
+ <xsl:with-param name="tag_open" select="$tag_open"/>
5244
+ <xsl:with-param name="tag_close" select="$tag_close"/>
5321
5245
  <xsl:with-param name="text" select="substring-after($text_after, $tag_close)"/>
5322
5246
  </xsl:call-template>
5323
5247
  </xsl:when>
@@ -5325,6 +5249,39 @@
5325
5249
  </xsl:choose>
5326
5250
  </xsl:template><xsl:template match="*[local-name()='br']">
5327
5251
  <xsl:value-of select="$linebreak"/>
5252
+ </xsl:template><xsl:template match="*[local-name() = 'keep-together_within-line']">
5253
+ <xsl:param name="split_keep-within-line"/>
5254
+
5255
+ <!-- <fo:inline>split_keep-within-line='<xsl:value-of select="$split_keep-within-line"/>'</fo:inline> -->
5256
+ <xsl:choose>
5257
+
5258
+ <xsl:when test="normalize-space($split_keep-within-line) = 'true'">
5259
+ <xsl:variable name="sep">_</xsl:variable>
5260
+ <xsl:variable name="items">
5261
+ <xsl:call-template name="split">
5262
+ <xsl:with-param name="pText" select="."/>
5263
+ <xsl:with-param name="sep" select="$sep"/>
5264
+ <xsl:with-param name="normalize-space">false</xsl:with-param>
5265
+ <xsl:with-param name="keep_sep">true</xsl:with-param>
5266
+ </xsl:call-template>
5267
+ </xsl:variable>
5268
+ <xsl:for-each select="xalan:nodeset($items)/item">
5269
+ <xsl:choose>
5270
+ <xsl:when test=". = $sep">
5271
+ <xsl:value-of select="$sep"/><xsl:value-of select="$zero_width_space"/>
5272
+ </xsl:when>
5273
+ <xsl:otherwise>
5274
+ <fo:inline keep-together.within-line="always"><xsl:apply-templates/></fo:inline>
5275
+ </xsl:otherwise>
5276
+ </xsl:choose>
5277
+ </xsl:for-each>
5278
+ </xsl:when>
5279
+
5280
+ <xsl:otherwise>
5281
+ <fo:inline keep-together.within-line="always"><xsl:apply-templates/></fo:inline>
5282
+ </xsl:otherwise>
5283
+
5284
+ </xsl:choose>
5328
5285
  </xsl:template><xsl:template match="*[local-name()='copyright-statement']">
5329
5286
  <fo:block xsl:use-attribute-sets="copyright-statement-style">
5330
5287
  <xsl:apply-templates/>
@@ -5400,8 +5357,23 @@
5400
5357
  </xsl:call-template>
5401
5358
 
5402
5359
  </xsl:template><xsl:template match="*[local-name()='td']//text() | *[local-name()='th']//text() | *[local-name()='dt']//text() | *[local-name()='dd']//text()" priority="1">
5403
- <!-- <xsl:call-template name="add-zero-spaces"/> -->
5404
- <xsl:call-template name="add-zero-spaces-java"/>
5360
+ <xsl:choose>
5361
+ <xsl:when test="parent::*[local-name() = 'keep-together_within-line']">
5362
+ <xsl:value-of select="."/>
5363
+ </xsl:when>
5364
+ <xsl:otherwise>
5365
+ <xsl:call-template name="addZeroWidthSpacesToTextNodes"/>
5366
+ </xsl:otherwise>
5367
+ </xsl:choose>
5368
+ </xsl:template><xsl:template name="addZeroWidthSpacesToTextNodes">
5369
+ <xsl:variable name="text"><text><xsl:call-template name="text"/></text></xsl:variable>
5370
+ <!-- <xsl:copy-of select="$text"/> -->
5371
+ <xsl:for-each select="xalan:nodeset($text)/text/node()">
5372
+ <xsl:choose>
5373
+ <xsl:when test="self::text()"><xsl:call-template name="add-zero-spaces-java"/></xsl:when>
5374
+ <xsl:otherwise><xsl:copy-of select="."/></xsl:otherwise> <!-- copy 'as-is' for <fo:inline keep-together.within-line="always" ... -->
5375
+ </xsl:choose>
5376
+ </xsl:for-each>
5405
5377
  </xsl:template><xsl:template match="*[local-name()='table']" name="table">
5406
5378
 
5407
5379
  <xsl:variable name="table-preamble">
@@ -5411,9 +5383,14 @@
5411
5383
 
5412
5384
  <xsl:variable name="table">
5413
5385
 
5414
- <xsl:variable name="simple-table">
5415
- <xsl:call-template name="getSimpleTable"/>
5386
+ <xsl:variable name="simple-table">
5387
+ <xsl:call-template name="getSimpleTable">
5388
+ <xsl:with-param name="id" select="@id"/>
5389
+ </xsl:call-template>
5416
5390
  </xsl:variable>
5391
+ <!-- <xsl:variable name="simple-table" select="xalan:nodeset($simple-table_)"/> -->
5392
+
5393
+ <!-- simple-table=<xsl:copy-of select="$simple-table"/> -->
5417
5394
 
5418
5395
 
5419
5396
  <!-- Display table's name before table as standalone block -->
@@ -5436,7 +5413,23 @@
5436
5413
  </xsl:call-template>
5437
5414
  </xsl:if>
5438
5415
  </xsl:variable>
5439
- <!-- DEBUG colwidths=<xsl:copy-of select="$colwidths"/> -->
5416
+ <!-- <xsl:variable name="colwidths" select="xalan:nodeset($colwidths_)"/> -->
5417
+
5418
+ <!-- DEBUG -->
5419
+ <xsl:if test="$table_if_debug = 'true'">
5420
+ <fo:block font-size="60%">
5421
+ <xsl:apply-templates select="xalan:nodeset($colwidths)" mode="print_as_xml"/>
5422
+ </fo:block>
5423
+ </xsl:if>
5424
+
5425
+
5426
+ <!-- <xsl:copy-of select="$colwidths"/> -->
5427
+
5428
+ <!-- <xsl:text disable-output-escaping="yes">&lt;!- -</xsl:text>
5429
+ DEBUG
5430
+ colwidths=<xsl:copy-of select="$colwidths"/>
5431
+ <xsl:text disable-output-escaping="yes">- -&gt;</xsl:text> -->
5432
+
5440
5433
 
5441
5434
 
5442
5435
  <xsl:variable name="margin-side">
@@ -5515,9 +5508,17 @@
5515
5508
  </xsl:element>
5516
5509
  </xsl:variable>
5517
5510
 
5511
+ <xsl:if test="$isGenerateTableIF = 'true'">
5512
+ <!-- to determine start of table -->
5513
+ <fo:block id="{concat('table_if_start_',@id)}" keep-with-next="always" font-size="1pt">Start table '<xsl:value-of select="@id"/>'.</fo:block>
5514
+ </xsl:if>
5518
5515
 
5519
5516
  <fo:table id="{@id}">
5520
5517
 
5518
+ <xsl:if test="$isGenerateTableIF = 'true'">
5519
+ <xsl:attribute name="wrap-option">no-wrap</xsl:attribute>
5520
+ </xsl:if>
5521
+
5521
5522
  <xsl:for-each select="xalan:nodeset($table_attributes)/table_attributes/@*">
5522
5523
  <xsl:attribute name="{local-name()}">
5523
5524
  <xsl:value-of select="."/>
@@ -5531,31 +5532,47 @@
5531
5532
 
5532
5533
 
5533
5534
  <xsl:choose>
5534
- <xsl:when test="*[local-name()='colgroup']/*[local-name()='col']">
5535
- <xsl:for-each select="*[local-name()='colgroup']/*[local-name()='col']">
5536
- <fo:table-column column-width="{@width}"/>
5537
- </xsl:for-each>
5535
+ <xsl:when test="$isGenerateTableIF = 'true'">
5536
+ <!-- generate IF for table widths -->
5537
+ <!-- example:
5538
+ <tr>
5539
+ <td valign="top" align="left" id="tab-symdu_1_1">
5540
+ <p>Symbol</p>
5541
+ <word id="tab-symdu_1_1_word_1">Symbol</word>
5542
+ </td>
5543
+ <td valign="top" align="left" id="tab-symdu_1_2">
5544
+ <p>Description</p>
5545
+ <word id="tab-symdu_1_2_word_1">Description</word>
5546
+ </td>
5547
+ </tr>
5548
+ -->
5549
+ <xsl:apply-templates select="xalan:nodeset($simple-table)" mode="process_table-if"/>
5550
+
5538
5551
  </xsl:when>
5539
5552
  <xsl:otherwise>
5540
- <xsl:for-each select="xalan:nodeset($colwidths)//column">
5541
- <xsl:choose>
5542
- <xsl:when test=". = 1 or . = 0">
5543
- <fo:table-column column-width="proportional-column-width(2)"/>
5544
- </xsl:when>
5545
- <xsl:otherwise>
5546
- <fo:table-column column-width="proportional-column-width({.})"/>
5547
- </xsl:otherwise>
5548
- </xsl:choose>
5549
- </xsl:for-each>
5550
- </xsl:otherwise>
5551
- </xsl:choose>
5552
5553
 
5553
- <xsl:choose>
5554
- <xsl:when test="not(*[local-name()='tbody']) and *[local-name()='thead']">
5555
- <xsl:apply-templates select="*[local-name()='thead']" mode="process_tbody"/>
5556
- </xsl:when>
5557
- <xsl:otherwise>
5558
- <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 -->
5554
+ <xsl:choose>
5555
+ <xsl:when test="*[local-name()='colgroup']/*[local-name()='col']">
5556
+ <xsl:for-each select="*[local-name()='colgroup']/*[local-name()='col']">
5557
+ <fo:table-column column-width="{@width}"/>
5558
+ </xsl:for-each>
5559
+ </xsl:when>
5560
+ <xsl:otherwise>
5561
+ <xsl:call-template name="insertTableColumnWidth">
5562
+ <xsl:with-param name="colwidths" select="$colwidths"/>
5563
+ </xsl:call-template>
5564
+ </xsl:otherwise>
5565
+ </xsl:choose>
5566
+
5567
+ <xsl:choose>
5568
+ <xsl:when test="not(*[local-name()='tbody']) and *[local-name()='thead']">
5569
+ <xsl:apply-templates select="*[local-name()='thead']" mode="process_tbody"/>
5570
+ </xsl:when>
5571
+ <xsl:otherwise>
5572
+ <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 -->
5573
+ </xsl:otherwise>
5574
+ </xsl:choose>
5575
+
5559
5576
  </xsl:otherwise>
5560
5577
  </xsl:choose>
5561
5578
 
@@ -5662,11 +5679,22 @@
5662
5679
  <xsl:variable name="columns-with-colspan" select="count($table-row/*[@colspan])"/>
5663
5680
  <xsl:value-of select="$columns-count + $sum-colspans - $columns-with-colspan"/>
5664
5681
  </xsl:template><xsl:template name="calculate-column-widths">
5682
+ <xsl:param name="table"/>
5683
+ <xsl:param name="cols-count"/>
5684
+
5685
+ <xsl:call-template name="calculate-column-widths-proportional">
5686
+ <xsl:with-param name="cols-count" select="$cols-count"/>
5687
+ <xsl:with-param name="table" select="$table"/>
5688
+ </xsl:call-template>
5689
+
5690
+ </xsl:template><xsl:template name="calculate-column-widths-proportional">
5665
5691
  <xsl:param name="table"/>
5666
5692
  <xsl:param name="cols-count"/>
5667
5693
  <xsl:param name="curr-col" select="1"/>
5668
5694
  <xsl:param name="width" select="0"/>
5669
5695
 
5696
+ <!-- table=<xsl:copy-of select="$table"/> -->
5697
+
5670
5698
  <xsl:if test="$curr-col &lt;= $cols-count">
5671
5699
  <xsl:variable name="widths">
5672
5700
  <xsl:choose>
@@ -5704,16 +5732,22 @@
5704
5732
  </xsl:for-each>
5705
5733
  </xsl:when>
5706
5734
  <xsl:otherwise>
5707
- <xsl:for-each select="xalan:nodeset($table)/*/tr">
5735
+ <!-- <curr_col><xsl:value-of select="$curr-col"/></curr_col> -->
5736
+
5737
+ <!-- <table><xsl:copy-of select="$table"/></table>
5738
+ -->
5739
+ <xsl:for-each select="xalan:nodeset($table)/*/*[local-name()='tr']">
5708
5740
  <xsl:variable name="td_text">
5709
5741
  <xsl:apply-templates select="td[$curr-col]" mode="td_text"/>
5710
5742
  </xsl:variable>
5743
+ <!-- <td_text><xsl:value-of select="$td_text"/></td_text> -->
5711
5744
  <xsl:variable name="words">
5712
5745
  <xsl:variable name="string_with_added_zerospaces">
5713
5746
  <xsl:call-template name="add-zero-spaces-java">
5714
5747
  <xsl:with-param name="text" select="$td_text"/>
5715
5748
  </xsl:call-template>
5716
5749
  </xsl:variable>
5750
+ <!-- <xsl:message>string_with_added_zerospaces=<xsl:value-of select="$string_with_added_zerospaces"/></xsl:message> -->
5717
5751
  <xsl:call-template name="tokenize">
5718
5752
  <!-- <xsl:with-param name="text" select="translate(td[$curr-col],'- —:', ' ')"/> -->
5719
5753
  <!-- 2009 thinspace -->
@@ -5721,11 +5755,13 @@
5721
5755
  <xsl:with-param name="text" select="normalize-space(translate($string_with_added_zerospaces, '​­', ' '))"/> <!-- replace zero-width-space and soft-hyphen to space -->
5722
5756
  </xsl:call-template>
5723
5757
  </xsl:variable>
5758
+ <!-- words=<xsl:copy-of select="$words"/> -->
5724
5759
  <xsl:variable name="max_length">
5725
5760
  <xsl:call-template name="max_length">
5726
5761
  <xsl:with-param name="words" select="xalan:nodeset($words)"/>
5727
5762
  </xsl:call-template>
5728
5763
  </xsl:variable>
5764
+ <!-- <xsl:message>max_length=<xsl:value-of select="$max_length"/></xsl:message> -->
5729
5765
  <width>
5730
5766
  <xsl:variable name="divider">
5731
5767
  <xsl:choose>
@@ -5744,6 +5780,8 @@
5744
5780
  </xsl:choose>
5745
5781
  </xsl:variable>
5746
5782
 
5783
+ <!-- widths=<xsl:copy-of select="$widths"/> -->
5784
+
5747
5785
  <column>
5748
5786
  <xsl:for-each select="xalan:nodeset($widths)//width">
5749
5787
  <xsl:sort select="." data-type="number" order="descending"/>
@@ -5752,79 +5790,377 @@
5752
5790
  </xsl:if>
5753
5791
  </xsl:for-each>
5754
5792
  </column>
5755
- <xsl:call-template name="calculate-column-widths">
5793
+ <xsl:call-template name="calculate-column-widths-proportional">
5756
5794
  <xsl:with-param name="cols-count" select="$cols-count"/>
5757
5795
  <xsl:with-param name="curr-col" select="$curr-col +1"/>
5758
5796
  <xsl:with-param name="table" select="$table"/>
5759
5797
  </xsl:call-template>
5760
5798
  </xsl:if>
5799
+ </xsl:template><xsl:template match="*[@keep-together.within-line or local-name() = 'keep-together_within-line']/text()" priority="2" mode="td_text">
5800
+ <!-- <xsl:message>DEBUG t1=<xsl:value-of select="."/></xsl:message>
5801
+ <xsl:message>DEBUG t2=<xsl:value-of select="java:replaceAll(java:java.lang.String.new(.),'.','X')"/></xsl:message> -->
5802
+ <xsl:value-of select="java:replaceAll(java:java.lang.String.new(.),'.','X')"/>
5803
+
5804
+ <!-- if all capitals english letters or digits -->
5805
+ <xsl:if test="normalize-space(translate(., concat($upper,'0123456789'), '')) = ''">
5806
+ <xsl:call-template name="repeat">
5807
+ <xsl:with-param name="char" select="'X'"/>
5808
+ <xsl:with-param name="count" select="string-length(normalize-space(.)) * 0.5"/>
5809
+ </xsl:call-template>
5810
+ </xsl:if>
5761
5811
  </xsl:template><xsl:template match="text()" mode="td_text">
5762
5812
  <xsl:value-of select="translate(., $zero_width_space, ' ')"/><xsl:text> </xsl:text>
5763
5813
  </xsl:template><xsl:template match="*[local-name()='termsource']" mode="td_text">
5764
5814
  <xsl:value-of select="*[local-name()='origin']/@citeas"/>
5765
5815
  </xsl:template><xsl:template match="*[local-name()='link']" mode="td_text">
5766
5816
  <xsl:value-of select="@target"/>
5767
- </xsl:template><xsl:template match="*[local-name()='math']" mode="td_text">
5768
- <xsl:variable name="mathml">
5769
- <xsl:for-each select="*">
5770
- <xsl:if test="local-name() != 'unit' and local-name() != 'prefix' and local-name() != 'dimension' and local-name() != 'quantity'">
5771
- <xsl:copy-of select="."/>
5772
- </xsl:if>
5773
- </xsl:for-each>
5774
- </xsl:variable>
5817
+ </xsl:template><xsl:template match="*[local-name()='math']" mode="td_text" name="math_length">
5818
+ <xsl:if test="$isGenerateTableIF = 'false'">
5819
+ <xsl:variable name="mathml_">
5820
+ <xsl:for-each select="*">
5821
+ <xsl:if test="local-name() != 'unit' and local-name() != 'prefix' and local-name() != 'dimension' and local-name() != 'quantity'">
5822
+ <xsl:copy-of select="."/>
5823
+ </xsl:if>
5824
+ </xsl:for-each>
5825
+ </xsl:variable>
5826
+ <xsl:variable name="mathml" select="xalan:nodeset($mathml_)"/>
5827
+
5828
+ <xsl:variable name="math_text">
5829
+ <xsl:value-of select="normalize-space($mathml)"/>
5830
+ <xsl:for-each select="$mathml//@open"><xsl:value-of select="."/></xsl:for-each>
5831
+ <xsl:for-each select="$mathml//@close"><xsl:value-of select="."/></xsl:for-each>
5832
+ </xsl:variable>
5833
+ <xsl:value-of select="translate($math_text, ' ', '#')"/><!-- mathml images as one 'word' without spaces -->
5834
+ </xsl:if>
5835
+ </xsl:template><xsl:template name="calculate-column-widths-autolayout-algorithm">
5836
+ <xsl:param name="table"/>
5837
+ <xsl:param name="if">false</xsl:param> <!-- via intermediate format -->
5838
+
5839
+ <!-- The algorithm uses two passes through the table data and scales linearly with the size of the table -->
5840
+
5841
+ <!-- In the first pass, line wrapping is disabled, and the user agent keeps track of the minimum and maximum width of each cell. -->
5842
+
5843
+ <!-- Since line wrap has been disabled, paragraphs are treated as long lines unless broken by BR elements. -->
5844
+
5845
+ <!-- get current table id -->
5846
+ <xsl:variable name="table_id" select="@id"/>
5847
+ <!-- find table by id in the file 'table_widths' -->
5848
+ <xsl:variable name="table-if_" select="$table_widths_from_if//table[@id = $table_id]"/>
5849
+ <xsl:variable name="table-if" select="xalan:nodeset($table-if_)"/>
5775
5850
 
5776
- <xsl:variable name="math_text" select="normalize-space(xalan:nodeset($mathml))"/>
5777
- <xsl:value-of select="translate($math_text, ' ', '#')"/><!-- mathml images as one 'word' without spaces -->
5778
- </xsl:template><xsl:template match="*[local-name()='thead']">
5779
- <xsl:param name="cols-count"/>
5780
- <fo:table-header>
5781
-
5782
-
5783
- <xsl:apply-templates/>
5784
- </fo:table-header>
5785
- </xsl:template><xsl:template name="table-header-title">
5786
- <xsl:param name="cols-count"/>
5787
- <!-- row for title -->
5788
- <fo:table-row>
5789
- <fo:table-cell number-columns-spanned="{$cols-count}" border-left="1.5pt solid white" border-right="1.5pt solid white" border-top="1.5pt solid white" border-bottom="1.5pt solid black">
5790
-
5791
- <xsl:apply-templates select="ancestor::*[local-name()='table']/*[local-name()='name']">
5792
- <xsl:with-param name="continued">true</xsl:with-param>
5793
- </xsl:apply-templates>
5794
-
5795
-
5851
+
5852
+ <!-- table='<xsl:copy-of select="$table"/>' -->
5853
+ <!-- table_id='<xsl:value-of select="$table_id"/>\ -->
5854
+ <!-- table-if='<xsl:copy-of select="$table-if"/>' -->
5855
+ <!-- table_widths_from_if='<xsl:copy-of select="$table_widths_from_if"/>' -->
5856
+
5857
+ <xsl:variable name="table_with_cell_widths_">
5858
+ <xsl:choose>
5859
+ <xsl:when test="$if = 'true' and normalize-space($table-if) != ''"> <!-- if we read column's width from IF and there is table in IF -->
5796
5860
 
5797
- </fo:table-cell>
5798
- </fo:table-row>
5799
- </xsl:template><xsl:template match="*[local-name()='thead']" mode="process_tbody">
5800
- <fo:table-body>
5801
- <xsl:apply-templates/>
5802
- </fo:table-body>
5803
- </xsl:template><xsl:template match="*[local-name()='tfoot']">
5804
- <xsl:apply-templates/>
5805
- </xsl:template><xsl:template name="insertTableFooter">
5806
- <xsl:param name="cols-count"/>
5807
- <xsl:if test="../*[local-name()='tfoot']">
5808
- <fo:table-footer>
5809
- <xsl:apply-templates select="../*[local-name()='tfoot']"/>
5810
- </fo:table-footer>
5861
+ <!-- Example: <column>10</column>
5862
+ <column>11</column>
5863
+ -->
5864
+ <xsl:apply-templates select="$table-if" mode="determine_cell_widths-if"/>
5865
+ </xsl:when>
5866
+ <xsl:otherwise>
5867
+ <xsl:apply-templates select="xalan:nodeset($table)" mode="determine_cell_widths"/>
5868
+ </xsl:otherwise>
5869
+ </xsl:choose>
5870
+ </xsl:variable>
5871
+ <xsl:variable name="table_with_cell_widths" select="xalan:nodeset($table_with_cell_widths_)"/>
5872
+
5873
+ <xsl:if test="$table_if_debug = 'true'">
5874
+ <xsl:copy-of select="$table_with_cell_widths"/>
5811
5875
  </xsl:if>
5812
- </xsl:template><xsl:template name="insertTableFooterInSeparateTable">
5813
- <xsl:param name="table_attributes"/>
5814
- <xsl:param name="colwidths"/>
5815
- <xsl:param name="colgroup"/>
5816
5876
 
5817
- <xsl:variable name="isNoteOrFnExist" select="../*[local-name()='note'] or ..//*[local-name()='fn'][local-name(..) != 'name']"/>
5818
5877
 
5819
- <xsl:variable name="isNoteOrFnExistShowAfterTable">
5820
-
5878
+ <!-- The minimum and maximum cell widths are then used to determine the corresponding minimum and maximum widths for the columns. -->
5879
+
5880
+ <xsl:variable name="column_widths_">
5881
+ <!-- iteration of columns -->
5882
+ <xsl:for-each select="$table_with_cell_widths//tr[1]/td">
5883
+ <xsl:variable name="pos" select="position()"/>
5884
+ <column>
5885
+ <xsl:attribute name="width_max">
5886
+ <xsl:for-each select="ancestor::tbody//tr/td[$pos]/@width_max">
5887
+ <xsl:sort select="." data-type="number" order="descending"/>
5888
+ <xsl:if test="position() = 1"><xsl:value-of select="."/></xsl:if>
5889
+ </xsl:for-each>
5890
+ </xsl:attribute>
5891
+ <xsl:attribute name="width_min">
5892
+ <xsl:for-each select="ancestor::tbody//tr/td[$pos]/@width_min">
5893
+ <xsl:sort select="." data-type="number" order="descending"/>
5894
+ <xsl:if test="position() = 1"><xsl:value-of select="."/></xsl:if>
5895
+ </xsl:for-each>
5896
+ </xsl:attribute>
5897
+ </column>
5898
+ </xsl:for-each>
5821
5899
  </xsl:variable>
5900
+ <xsl:variable name="column_widths" select="xalan:nodeset($column_widths_)"/>
5822
5901
 
5823
- <xsl:if test="$isNoteOrFnExist = 'true' or normalize-space($isNoteOrFnExistShowAfterTable) = 'true'">
5902
+ <!-- <column_widths>
5903
+ <xsl:copy-of select="$column_widths"/>
5904
+ </column_widths> -->
5824
5905
 
5825
- <xsl:variable name="cols-count">
5826
- <xsl:choose>
5827
- <xsl:when test="xalan:nodeset($colgroup)//*[local-name()='col']">
5906
+ <!-- These in turn, are used to find the minimum and maximum width for the table. -->
5907
+ <xsl:variable name="table_widths_">
5908
+ <table>
5909
+ <xsl:attribute name="width_max">
5910
+ <xsl:value-of select="sum($column_widths/column/@width_max)"/>
5911
+ </xsl:attribute>
5912
+ <xsl:attribute name="width_min">
5913
+ <xsl:value-of select="sum($column_widths/column/@width_min)"/>
5914
+ </xsl:attribute>
5915
+ </table>
5916
+ </xsl:variable>
5917
+ <xsl:variable name="table_widths" select="xalan:nodeset($table_widths_)"/>
5918
+
5919
+ <xsl:variable name="page_width">
5920
+ <xsl:choose>
5921
+ <xsl:when test="$if = 'true'"><xsl:value-of select="$table-if/@page-width"/></xsl:when>
5922
+ <xsl:otherwise>75</xsl:otherwise>
5923
+ </xsl:choose>
5924
+ </xsl:variable>
5925
+
5926
+ <xsl:if test="$table_if_debug = 'true'">
5927
+ <table_width>
5928
+ <xsl:copy-of select="$table_widths"/>
5929
+ </table_width>
5930
+ <!-- <debug>$table_widths/@width_min=<xsl:value-of select="$table_widths/table/@width_min"/></debug>
5931
+ <debug>$table_widths/@width_max=<xsl:value-of select="$table_widths/table/@width_max"/></debug>
5932
+ -->
5933
+ <debug>$page_width=<xsl:value-of select="$page_width"/></debug>
5934
+ </xsl:if>
5935
+
5936
+
5937
+ <!-- There are three cases: -->
5938
+ <xsl:choose>
5939
+ <!-- 1. The minimum table width is equal to or wider than the available space -->
5940
+ <xsl:when test="$table_widths/table/@width_min &gt;= $page_width and 1 = 2"> <!-- this condition isn't working see case 3 below -->
5941
+ <!-- call old algorithm -->
5942
+ <case1/>
5943
+ <xsl:variable name="cols-count" select="count(xalan:nodeset($table)/*/tr[1]/td)"/>
5944
+ <xsl:call-template name="calculate-column-widths-proportional">
5945
+ <xsl:with-param name="cols-count" select="$cols-count"/>
5946
+ <xsl:with-param name="table" select="$table"/>
5947
+ </xsl:call-template>
5948
+ </xsl:when>
5949
+ <!-- 2. The maximum table width fits within the available space. In this case, set the columns to their maximum widths. -->
5950
+ <xsl:when test="$table_widths/table/@width_max &lt;= $page_width">
5951
+ <case2/>
5952
+ <autolayout/>
5953
+ <xsl:for-each select="$column_widths/column/@width_max">
5954
+ <column divider="100"><xsl:value-of select="."/></column>
5955
+ </xsl:for-each>
5956
+ </xsl:when>
5957
+ <!-- 3. The maximum width of the table is greater than the available space, but the minimum table width is smaller.
5958
+ In this case, find the difference between the available space and the minimum table width, lets call it W.
5959
+ Lets also call D the difference between maximum and minimum width of the table.
5960
+ For each column, let d be the difference between maximum and minimum width of that column.
5961
+ Now set the column's width to the minimum width plus d times W over D.
5962
+ This makes columns with large differences between minimum and maximum widths wider than columns with smaller differences. -->
5963
+ <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)">
5964
+ <!-- difference between the available space and the minimum table width -->
5965
+ <xsl:variable name="W" select="$page_width - $table_widths/table/@width_min"/>
5966
+ <W><xsl:value-of select="$W"/></W>
5967
+ <!-- difference between maximum and minimum width of the table -->
5968
+ <xsl:variable name="D" select="$table_widths/table/@width_max - $table_widths/table/@width_min"/>
5969
+ <D><xsl:value-of select="$D"/></D>
5970
+ <case3/>
5971
+ <autolayout/>
5972
+ <xsl:if test="$table_widths/table/@width_min &gt;= $page_width">
5973
+ <split_keep-within-line>true</split_keep-within-line>
5974
+ </xsl:if>
5975
+ <xsl:for-each select="$column_widths/column">
5976
+ <!-- difference between maximum and minimum width of that column. -->
5977
+ <xsl:variable name="d" select="@width_max - @width_min"/>
5978
+ <d><xsl:value-of select="$d"/></d>
5979
+ <width_min><xsl:value-of select="@width_min"/></width_min>
5980
+ <e><xsl:value-of select="$d * $W div $D"/></e>
5981
+ <!-- set the column's width to the minimum width plus d times W over D. -->
5982
+ <column divider="100">
5983
+ <xsl:value-of select="round(@width_min + $d * $W div $D)"/> <!-- * 10 -->
5984
+ </column>
5985
+ </xsl:for-each>
5986
+
5987
+ </xsl:when>
5988
+ <xsl:otherwise><unknown_case/></xsl:otherwise>
5989
+ </xsl:choose>
5990
+
5991
+
5992
+ </xsl:template><xsl:template match="@*|node()" mode="determine_cell_widths">
5993
+ <xsl:copy>
5994
+ <xsl:apply-templates select="@*|node()" mode="determine_cell_widths"/>
5995
+ </xsl:copy>
5996
+ </xsl:template><xsl:template match="td | th" mode="determine_cell_widths">
5997
+ <xsl:copy>
5998
+ <xsl:copy-of select="@*"/>
5999
+
6000
+ <!-- The maximum width is given by the widest line. -->
6001
+ <xsl:variable name="widths_max">
6002
+ <xsl:for-each select=".//*[local-name() = 'p']">
6003
+ <xsl:call-template name="add_width"/>
6004
+ </xsl:for-each>
6005
+ <xsl:if test="not(*[local-name() = 'p'])">
6006
+ <xsl:call-template name="add_width"/>
6007
+ </xsl:if>
6008
+ </xsl:variable>
6009
+ <xsl:variable name="width_max">
6010
+ <xsl:for-each select="xalan:nodeset($widths_max)//width">
6011
+ <xsl:sort select="." data-type="number" order="descending"/>
6012
+ <xsl:if test="position() = 1"><xsl:value-of select="."/></xsl:if>
6013
+ </xsl:for-each>
6014
+ </xsl:variable>
6015
+ <xsl:attribute name="width_max">
6016
+ <xsl:value-of select="$width_max"/>
6017
+ </xsl:attribute>
6018
+
6019
+ <!-- The minimum width is given by the widest text element (word, image, etc.) -->
6020
+ <!-- To do: image width -->
6021
+ <xsl:variable name="td_text">
6022
+ <xsl:apply-templates select="." mode="td_text"/>
6023
+ </xsl:variable>
6024
+ <xsl:variable name="words">
6025
+ <xsl:variable name="string_with_added_zerospaces">
6026
+ <xsl:call-template name="add-zero-spaces-java">
6027
+ <xsl:with-param name="text" select="$td_text"/>
6028
+ </xsl:call-template>
6029
+ </xsl:variable>
6030
+ <xsl:call-template name="tokenize">
6031
+ <xsl:with-param name="text" select="normalize-space(translate($string_with_added_zerospaces, '​­', ' '))"/> <!-- replace zero-width-space and soft-hyphen to space -->
6032
+ </xsl:call-template>
6033
+ </xsl:variable>
6034
+
6035
+ <xsl:variable name="max_word_length">
6036
+ <xsl:call-template name="max_length">
6037
+ <xsl:with-param name="words" select="xalan:nodeset($words)"/>
6038
+ </xsl:call-template>
6039
+ </xsl:variable>
6040
+ <xsl:variable name="width_min">
6041
+ <xsl:value-of select="$max_word_length"/>
6042
+ </xsl:variable>
6043
+ <xsl:attribute name="width_min">
6044
+ <xsl:value-of select="$width_min"/>
6045
+ </xsl:attribute>
6046
+ <!-- width_max="1" width_min="1.5"> --> <!-- see 'tokenize' template, multiply 1.5 for all latin capitals -->
6047
+ <xsl:if test="$width_min &gt; $width_max">
6048
+ <xsl:attribute name="width_max">
6049
+ <xsl:value-of select="$width_min"/>
6050
+ </xsl:attribute>
6051
+ </xsl:if>
6052
+ <xsl:if test="$width_min = 0">
6053
+ <xsl:attribute name="width_min">1</xsl:attribute>
6054
+ </xsl:if>
6055
+
6056
+ <xsl:apply-templates select="node()" mode="determine_cell_widths"/>
6057
+
6058
+ </xsl:copy>
6059
+ </xsl:template><xsl:template name="add_width">
6060
+ <xsl:variable name="p_text"><xsl:apply-templates select="." mode="td_text"/></xsl:variable>
6061
+ <xsl:variable name="p_text_len_" select="string-length(normalize-space($p_text))"/>
6062
+
6063
+ <xsl:variable name="p_text_len">
6064
+ <xsl:choose>
6065
+ <xsl:when test="normalize-space(translate($p_text, concat($upper,'0123456789'), '')) = ''"> <!-- english word in CAPITAL letters -->
6066
+ <xsl:value-of select="$p_text_len_ * 1.5"/>
6067
+ </xsl:when>
6068
+ <xsl:otherwise><xsl:value-of select="$p_text_len_"/></xsl:otherwise>
6069
+ </xsl:choose>
6070
+ </xsl:variable>
6071
+
6072
+ <xsl:variable name="math_addon_text">
6073
+ <xsl:for-each select=".//*[local-name() = 'math']">
6074
+ <xsl:apply-templates mode="td_text"/>
6075
+ </xsl:for-each>
6076
+ </xsl:variable>
6077
+ <xsl:variable name="math_addon_length" select="string-length(normalize-space($math_addon_text)) * 0.2"/> <!-- plus 20% -->
6078
+
6079
+ <width><xsl:value-of select="$p_text_len + $math_addon_length"/></width>
6080
+ </xsl:template><xsl:template match="@*|node()" mode="determine_cell_widths-if">
6081
+ <xsl:copy>
6082
+ <xsl:apply-templates select="@*|node()" mode="determine_cell_widths-if"/>
6083
+ </xsl:copy>
6084
+ </xsl:template><xsl:template match="td | th" mode="determine_cell_widths-if">
6085
+ <xsl:copy>
6086
+ <xsl:copy-of select="@*"/>
6087
+
6088
+ <!-- The maximum width is given by the widest line. -->
6089
+ <xsl:attribute name="width_max">
6090
+ <xsl:for-each select="p_len">
6091
+ <xsl:sort select="." data-type="number" order="descending"/>
6092
+ <xsl:if test="position() = 1"><xsl:value-of select="."/></xsl:if>
6093
+ </xsl:for-each>
6094
+ </xsl:attribute>
6095
+
6096
+ <!-- The minimum width is given by the widest text element (word, image, etc.) -->
6097
+ <xsl:variable name="width_min">
6098
+ <xsl:for-each select="word_len">
6099
+ <xsl:sort select="." data-type="number" order="descending"/>
6100
+ <xsl:if test="position() = 1"><xsl:value-of select="."/></xsl:if>
6101
+ </xsl:for-each>
6102
+ </xsl:variable>
6103
+ <xsl:attribute name="width_min">
6104
+ <xsl:value-of select="$width_min"/>
6105
+ </xsl:attribute>
6106
+
6107
+ <xsl:if test="$width_min = 0">
6108
+ <xsl:attribute name="width_min">1</xsl:attribute>
6109
+ </xsl:if>
6110
+
6111
+ <xsl:apply-templates select="node()" mode="determine_cell_widths-if"/>
6112
+
6113
+ </xsl:copy>
6114
+ </xsl:template><xsl:template match="*[local-name()='thead']">
6115
+ <xsl:param name="cols-count"/>
6116
+ <fo:table-header>
6117
+
6118
+
6119
+ <xsl:apply-templates/>
6120
+ </fo:table-header>
6121
+ </xsl:template><xsl:template name="table-header-title">
6122
+ <xsl:param name="cols-count"/>
6123
+ <!-- row for title -->
6124
+ <fo:table-row>
6125
+ <fo:table-cell number-columns-spanned="{$cols-count}" border-left="1.5pt solid white" border-right="1.5pt solid white" border-top="1.5pt solid white" border-bottom="1.5pt solid black">
6126
+
6127
+ <xsl:apply-templates select="ancestor::*[local-name()='table']/*[local-name()='name']">
6128
+ <xsl:with-param name="continued">true</xsl:with-param>
6129
+ </xsl:apply-templates>
6130
+
6131
+
6132
+
6133
+ </fo:table-cell>
6134
+ </fo:table-row>
6135
+ </xsl:template><xsl:template match="*[local-name()='thead']" mode="process_tbody">
6136
+ <fo:table-body>
6137
+ <xsl:apply-templates/>
6138
+ </fo:table-body>
6139
+ </xsl:template><xsl:template match="*[local-name()='tfoot']">
6140
+ <xsl:apply-templates/>
6141
+ </xsl:template><xsl:template name="insertTableFooter">
6142
+ <xsl:param name="cols-count"/>
6143
+ <xsl:if test="../*[local-name()='tfoot']">
6144
+ <fo:table-footer>
6145
+ <xsl:apply-templates select="../*[local-name()='tfoot']"/>
6146
+ </fo:table-footer>
6147
+ </xsl:if>
6148
+ </xsl:template><xsl:template name="insertTableFooterInSeparateTable">
6149
+ <xsl:param name="table_attributes"/>
6150
+ <xsl:param name="colwidths"/>
6151
+ <xsl:param name="colgroup"/>
6152
+
6153
+ <xsl:variable name="isNoteOrFnExist" select="../*[local-name()='note'] or ..//*[local-name()='fn'][local-name(..) != 'name']"/>
6154
+
6155
+ <xsl:variable name="isNoteOrFnExistShowAfterTable">
6156
+
6157
+ </xsl:variable>
6158
+
6159
+ <xsl:if test="$isNoteOrFnExist = 'true' or normalize-space($isNoteOrFnExistShowAfterTable) = 'true'">
6160
+
6161
+ <xsl:variable name="cols-count">
6162
+ <xsl:choose>
6163
+ <xsl:when test="xalan:nodeset($colgroup)//*[local-name()='col']">
5828
6164
  <xsl:value-of select="count(xalan:nodeset($colgroup)//*[local-name()='col'])"/>
5829
6165
  </xsl:when>
5830
6166
  <xsl:otherwise>
@@ -5859,16 +6195,10 @@
5859
6195
  </xsl:for-each>
5860
6196
  </xsl:when>
5861
6197
  <xsl:otherwise>
5862
- <xsl:for-each select="xalan:nodeset($colwidths)//column">
5863
- <xsl:choose>
5864
- <xsl:when test=". = 1 or . = 0">
5865
- <fo:table-column column-width="proportional-column-width(2)"/>
5866
- </xsl:when>
5867
- <xsl:otherwise>
5868
- <fo:table-column column-width="proportional-column-width({.})"/>
5869
- </xsl:otherwise>
5870
- </xsl:choose>
5871
- </xsl:for-each>
6198
+ <!-- $colwidths=<xsl:copy-of select="$colwidths"/> -->
6199
+ <xsl:call-template name="insertTableColumnWidth">
6200
+ <xsl:with-param name="colwidths" select="$colwidths"/>
6201
+ </xsl:call-template>
5872
6202
  </xsl:otherwise>
5873
6203
  </xsl:choose>
5874
6204
 
@@ -5955,6 +6285,52 @@
5955
6285
 
5956
6286
  </fo:table-body>
5957
6287
 
6288
+ </xsl:template><xsl:template match="/" mode="process_table-if">
6289
+ <xsl:param name="table_or_dl">table</xsl:param>
6290
+ <xsl:apply-templates mode="process_table-if">
6291
+ <xsl:with-param name="table_or_dl" select="$table_or_dl"/>
6292
+ </xsl:apply-templates>
6293
+ </xsl:template><xsl:template match="*[local-name()='tbody']" mode="process_table-if">
6294
+ <xsl:param name="table_or_dl">table</xsl:param>
6295
+
6296
+ <fo:table-body>
6297
+ <xsl:for-each select="*[local-name() = 'tr']">
6298
+ <xsl:variable name="col_count" select="count(*)"/>
6299
+
6300
+ <!-- iteration for each tr/td -->
6301
+
6302
+ <xsl:choose>
6303
+ <xsl:when test="$table_or_dl = 'table'">
6304
+ <xsl:for-each select="*[local-name() = 'td' or local-name() = 'th']/*">
6305
+ <fo:table-row number-columns-spanned="{$col_count}">
6306
+ <!-- <test_table><xsl:copy-of select="."/></test_table> -->
6307
+ <xsl:call-template name="td"/>
6308
+ </fo:table-row>
6309
+ </xsl:for-each>
6310
+ </xsl:when>
6311
+ <xsl:otherwise> <!-- $table_or_dl = 'dl' -->
6312
+ <xsl:for-each select="*[local-name() = 'td' or local-name() = 'th']">
6313
+ <xsl:variable name="is_dt" select="position() = 1"/>
6314
+
6315
+ <xsl:for-each select="*">
6316
+ <!-- <test><xsl:copy-of select="."/></test> -->
6317
+ <fo:table-row number-columns-spanned="{$col_count}">
6318
+ <xsl:choose>
6319
+ <xsl:when test="$is_dt">
6320
+ <xsl:call-template name="insert_dt_cell"/>
6321
+ </xsl:when>
6322
+ <xsl:otherwise>
6323
+ <xsl:call-template name="insert_dd_cell"/>
6324
+ </xsl:otherwise>
6325
+ </xsl:choose>
6326
+ </fo:table-row>
6327
+ </xsl:for-each>
6328
+ </xsl:for-each>
6329
+ </xsl:otherwise>
6330
+ </xsl:choose>
6331
+
6332
+ </xsl:for-each>
6333
+ </fo:table-body>
5958
6334
  </xsl:template><xsl:template match="*[local-name()='thead']/*[local-name()='tr']" priority="2">
5959
6335
  <fo:table-row xsl:use-attribute-sets="table-header-row-style">
5960
6336
 
@@ -6059,7 +6435,7 @@
6059
6435
  </xsl:choose>
6060
6436
  </xsl:attribute>
6061
6437
  </xsl:if>
6062
- </xsl:template><xsl:template match="*[local-name()='td']">
6438
+ </xsl:template><xsl:template match="*[local-name()='td']" name="td">
6063
6439
  <fo:table-cell xsl:use-attribute-sets="table-cell-style"> <!-- text-align="{@align}" -->
6064
6440
  <xsl:call-template name="setTextAlignment">
6065
6441
  <xsl:with-param name="default">left</xsl:with-param>
@@ -6104,8 +6480,18 @@
6104
6480
 
6105
6481
  <xsl:call-template name="setTableCellAttributes"/>
6106
6482
 
6483
+ <xsl:if test="$isGenerateTableIF = 'true'">
6484
+ <xsl:attribute name="border">1pt solid black</xsl:attribute> <!-- border is mandatory, to determine page width -->
6485
+ <xsl:attribute name="text-align">left</xsl:attribute>
6486
+ </xsl:if>
6487
+
6107
6488
  <fo:block>
6108
6489
 
6490
+ <xsl:if test="$isGenerateTableIF = 'true'">
6491
+ <xsl:attribute name="id"><xsl:value-of select="@id"/></xsl:attribute>
6492
+ </xsl:if>
6493
+
6494
+
6109
6495
 
6110
6496
  <xsl:if test="not(.//bipm:image)">
6111
6497
  <xsl:attribute name="line-stacking-strategy">font-height</xsl:attribute>
@@ -6118,6 +6504,9 @@
6118
6504
 
6119
6505
 
6120
6506
  <xsl:apply-templates/>
6507
+
6508
+ <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"/> -->
6509
+
6121
6510
  </fo:block>
6122
6511
  </fo:table-cell>
6123
6512
  </xsl:template><xsl:template match="*[local-name()='table']/*[local-name()='note']" priority="2">
@@ -6331,9 +6720,9 @@
6331
6720
  <!-- current hierarchy is 'figure' element -->
6332
6721
  <xsl:variable name="following_dl_colwidths">
6333
6722
  <xsl:if test="*[local-name() = 'dl']"><!-- if there is a 'dl', then set the same columns width as for 'dl' -->
6334
- <xsl:variable name="html-table">
6335
- <xsl:variable name="doc_ns">
6336
- bipm
6723
+ <xsl:variable name="simple-table">
6724
+ <!-- <xsl:variable name="doc_ns">
6725
+ <xsl:if test="$namespace = 'bipm'">bipm</xsl:if>
6337
6726
  </xsl:variable>
6338
6727
  <xsl:variable name="ns">
6339
6728
  <xsl:choose>
@@ -6344,7 +6733,7 @@
6344
6733
  <xsl:value-of select="substring-before(name(/*), '-')"/>
6345
6734
  </xsl:otherwise>
6346
6735
  </xsl:choose>
6347
- </xsl:variable>
6736
+ </xsl:variable> -->
6348
6737
 
6349
6738
  <xsl:for-each select="*[local-name() = 'dl'][1]">
6350
6739
  <tbody>
@@ -6355,7 +6744,7 @@
6355
6744
 
6356
6745
  <xsl:call-template name="calculate-column-widths">
6357
6746
  <xsl:with-param name="cols-count" select="2"/>
6358
- <xsl:with-param name="table" select="$html-table"/>
6747
+ <xsl:with-param name="table" select="$simple-table"/>
6359
6748
  </xsl:call-template>
6360
6749
 
6361
6750
  </xsl:if>
@@ -6479,8 +6868,10 @@
6479
6868
  <!-- and (not(../@class) or ../@class !='pseudocode') -->
6480
6869
  </xsl:variable>
6481
6870
 
6871
+ <xsl:variable name="onlyOneComponent" select="normalize-space($parent = 'formula' and count(*[local-name()='dt']) = 1)"/>
6872
+
6482
6873
  <xsl:choose>
6483
- <xsl:when test="$parent = 'formula' and count(*[local-name()='dt']) = 1"> <!-- only one component -->
6874
+ <xsl:when test="$onlyOneComponent = 'true'"> <!-- only one component -->
6484
6875
 
6485
6876
  <fo:block margin-bottom="12pt" text-align="left">
6486
6877
 
@@ -6495,7 +6886,7 @@
6495
6886
  <xsl:apply-templates select="*[local-name()='dd']/*" mode="inline"/>
6496
6887
  </fo:block>
6497
6888
 
6498
- </xsl:when>
6889
+ </xsl:when> <!-- END: only one component -->
6499
6890
  <xsl:when test="$parent = 'formula'"> <!-- a few components -->
6500
6891
  <fo:block margin-bottom="12pt" text-align="left">
6501
6892
 
@@ -6509,8 +6900,8 @@
6509
6900
  </xsl:variable>
6510
6901
  <xsl:value-of select="$title-where"/>
6511
6902
  </fo:block>
6512
- </xsl:when>
6513
- <xsl:when test="$parent = 'figure' and (not(../@class) or ../@class !='pseudocode')">
6903
+ </xsl:when> <!-- END: a few components -->
6904
+ <xsl:when test="$parent = 'figure' and (not(../@class) or ../@class !='pseudocode')"> <!-- definition list in a figure -->
6514
6905
  <fo:block font-weight="bold" text-align="left" margin-bottom="12pt" keep-with-next="always">
6515
6906
 
6516
6907
 
@@ -6523,11 +6914,11 @@
6523
6914
  </xsl:variable>
6524
6915
  <xsl:value-of select="$title-key"/>
6525
6916
  </fo:block>
6526
- </xsl:when>
6917
+ </xsl:when> <!-- END: definition list in a figure -->
6527
6918
  </xsl:choose>
6528
6919
 
6529
6920
  <!-- a few components -->
6530
- <xsl:if test="not($parent = 'formula' and count(*[local-name()='dt']) = 1)">
6921
+ <xsl:if test="$onlyOneComponent = 'false'">
6531
6922
  <fo:block>
6532
6923
 
6533
6924
 
@@ -6538,7 +6929,18 @@
6538
6929
 
6539
6930
 
6540
6931
 
6932
+
6933
+ <xsl:if test="$isGenerateTableIF = 'true'">
6934
+ <!-- to determine start of table -->
6935
+ <fo:block id="{concat('table_if_start_',@id)}" keep-with-next="always" font-size="1pt">Start table '<xsl:value-of select="@id"/>'.</fo:block>
6936
+ </xsl:if>
6937
+
6541
6938
  <fo:table width="95%" table-layout="fixed">
6939
+
6940
+ <xsl:if test="$isGenerateTableIF = 'true'">
6941
+ <xsl:attribute name="wrap-option">no-wrap</xsl:attribute>
6942
+ </xsl:if>
6943
+
6542
6944
 
6543
6945
  <xsl:choose>
6544
6946
  <xsl:when test="normalize-space($key_iso) = 'true' and $parent = 'formula'"/>
@@ -6547,54 +6949,143 @@
6547
6949
 
6548
6950
  </xsl:when>
6549
6951
  </xsl:choose>
6550
- <!-- create virtual html table for dl/[dt and dd] -->
6551
- <xsl:variable name="html-table">
6552
- <xsl:variable name="doc_ns">
6553
- bipm
6554
- </xsl:variable>
6555
- <xsl:variable name="ns">
6556
- <xsl:choose>
6557
- <xsl:when test="normalize-space($doc_ns) != ''">
6558
- <xsl:value-of select="normalize-space($doc_ns)"/>
6559
- </xsl:when>
6560
- <xsl:otherwise>
6561
- <xsl:value-of select="substring-before(name(/*), '-')"/>
6562
- </xsl:otherwise>
6563
- </xsl:choose>
6564
- </xsl:variable>
6565
- <tbody>
6566
- <xsl:apply-templates mode="dl"/>
6567
- </tbody>
6568
- </xsl:variable>
6569
- <!-- html-table<xsl:copy-of select="$html-table"/> -->
6570
- <xsl:variable name="colwidths">
6571
- <xsl:call-template name="calculate-column-widths">
6572
- <xsl:with-param name="cols-count" select="2"/>
6573
- <xsl:with-param name="table" select="$html-table"/>
6574
- </xsl:call-template>
6575
- </xsl:variable>
6576
- <!-- colwidths=<xsl:copy-of select="$colwidths"/> -->
6577
- <xsl:variable name="maxlength_dt">
6578
- <xsl:call-template name="getMaxLength_dt"/>
6579
- </xsl:variable>
6580
- <xsl:call-template name="setColumnWidth_dl">
6581
- <xsl:with-param name="colwidths" select="$colwidths"/>
6582
- <xsl:with-param name="maxlength_dt" select="$maxlength_dt"/>
6583
- </xsl:call-template>
6584
- <fo:table-body>
6585
- <xsl:apply-templates>
6586
- <xsl:with-param name="key_iso" select="normalize-space($key_iso)"/>
6587
- </xsl:apply-templates>
6588
- </fo:table-body>
6952
+
6953
+
6954
+ <xsl:choose>
6955
+ <xsl:when test="$isGenerateTableIF = 'true'">
6956
+ <!-- generate IF for table widths -->
6957
+ <!-- example:
6958
+ <tr>
6959
+ <td valign="top" align="left" id="tab-symdu_1_1">
6960
+ <p>Symbol</p>
6961
+ <word id="tab-symdu_1_1_word_1">Symbol</word>
6962
+ </td>
6963
+ <td valign="top" align="left" id="tab-symdu_1_2">
6964
+ <p>Description</p>
6965
+ <word id="tab-symdu_1_2_word_1">Description</word>
6966
+ </td>
6967
+ </tr>
6968
+ -->
6969
+
6970
+ <!-- create virtual html table for dl/[dt and dd] -->
6971
+ <xsl:variable name="simple-table">
6972
+
6973
+ <xsl:variable name="dl_table">
6974
+ <tbody>
6975
+ <xsl:apply-templates mode="dl_if">
6976
+ <xsl:with-param name="id" select="@id"/>
6977
+ </xsl:apply-templates>
6978
+ </tbody>
6979
+ </xsl:variable>
6980
+
6981
+ <!-- dl_table='<xsl:copy-of select="$dl_table"/>' -->
6982
+
6983
+ <!-- Step: replace <br/> to <p>...</p> -->
6984
+ <xsl:variable name="table_without_br">
6985
+ <xsl:apply-templates select="xalan:nodeset($dl_table)" mode="table-without-br"/>
6986
+ </xsl:variable>
6987
+
6988
+ <!-- table_without_br='<xsl:copy-of select="$table_without_br"/>' -->
6989
+
6990
+ <!-- Step: add id to each cell -->
6991
+ <!-- add <word>...</word> for each word, image, math -->
6992
+ <xsl:variable name="simple-table-id">
6993
+ <xsl:apply-templates select="xalan:nodeset($table_without_br)" mode="simple-table-id">
6994
+ <xsl:with-param name="id" select="@id"/>
6995
+ </xsl:apply-templates>
6996
+ </xsl:variable>
6997
+
6998
+ <!-- simple-table-id='<xsl:copy-of select="$simple-table-id"/>' -->
6999
+
7000
+ <xsl:copy-of select="xalan:nodeset($simple-table-id)"/>
7001
+
7002
+ </xsl:variable>
7003
+
7004
+ <!-- DEBUG: simple-table<xsl:copy-of select="$simple-table"/> -->
7005
+
7006
+ <xsl:apply-templates select="xalan:nodeset($simple-table)" mode="process_table-if">
7007
+ <xsl:with-param name="table_or_dl">dl</xsl:with-param>
7008
+ </xsl:apply-templates>
7009
+
7010
+ </xsl:when>
7011
+ <xsl:otherwise>
7012
+
7013
+ <xsl:variable name="simple-table">
7014
+
7015
+ <xsl:variable name="dl_table">
7016
+ <tbody>
7017
+ <xsl:apply-templates mode="dl">
7018
+ <xsl:with-param name="id" select="@id"/>
7019
+ </xsl:apply-templates>
7020
+ </tbody>
7021
+ </xsl:variable>
7022
+
7023
+ <xsl:copy-of select="$dl_table"/>
7024
+ </xsl:variable>
7025
+
7026
+ <xsl:variable name="colwidths">
7027
+ <xsl:call-template name="calculate-column-widths">
7028
+ <xsl:with-param name="cols-count" select="2"/>
7029
+ <xsl:with-param name="table" select="$simple-table"/>
7030
+ </xsl:call-template>
7031
+ </xsl:variable>
7032
+
7033
+ <!-- <xsl:text disable-output-escaping="yes">&lt;!- -</xsl:text>
7034
+ DEBUG
7035
+ colwidths=<xsl:copy-of select="$colwidths"/>
7036
+ <xsl:text disable-output-escaping="yes">- -&gt;</xsl:text> -->
7037
+
7038
+ <!-- colwidths=<xsl:copy-of select="$colwidths"/> -->
7039
+
7040
+ <xsl:variable name="maxlength_dt">
7041
+ <xsl:call-template name="getMaxLength_dt"/>
7042
+ </xsl:variable>
7043
+
7044
+ <xsl:variable name="isContainsKeepTogetherTag_">
7045
+ false
7046
+ </xsl:variable>
7047
+ <xsl:variable name="isContainsKeepTogetherTag" select="normalize-space($isContainsKeepTogetherTag_)"/>
7048
+ <!-- isContainsExpressReference=<xsl:value-of select="$isContainsExpressReference"/> -->
7049
+
7050
+
7051
+ <xsl:call-template name="setColumnWidth_dl">
7052
+ <xsl:with-param name="colwidths" select="$colwidths"/>
7053
+ <xsl:with-param name="maxlength_dt" select="$maxlength_dt"/>
7054
+ <xsl:with-param name="isContainsKeepTogetherTag" select="$isContainsKeepTogetherTag"/>
7055
+ </xsl:call-template>
7056
+
7057
+ <fo:table-body>
7058
+
7059
+ <!-- DEBUG -->
7060
+ <xsl:if test="$table_if_debug = 'true'">
7061
+ <fo:table-row>
7062
+ <fo:table-cell number-columns-spanned="2" font-size="60%">
7063
+ <xsl:apply-templates select="xalan:nodeset($colwidths)" mode="print_as_xml"/>
7064
+ </fo:table-cell>
7065
+ </fo:table-row>
7066
+ </xsl:if>
7067
+
7068
+ <xsl:apply-templates>
7069
+ <xsl:with-param name="key_iso" select="normalize-space($key_iso)"/>
7070
+ <xsl:with-param name="split_keep-within-line" select="xalan:nodeset($colwidths)/split_keep-within-line"/>
7071
+ </xsl:apply-templates>
7072
+
7073
+ </fo:table-body>
7074
+ </xsl:otherwise>
7075
+ </xsl:choose>
6589
7076
  </fo:table>
6590
7077
  </fo:block>
6591
7078
  </fo:block>
6592
- </xsl:if>
7079
+ </xsl:if> <!-- END: a few components -->
6593
7080
  </fo:block-container>
6594
7081
  </fo:block-container>
6595
7082
  </xsl:template><xsl:template name="setColumnWidth_dl">
6596
7083
  <xsl:param name="colwidths"/>
6597
7084
  <xsl:param name="maxlength_dt"/>
7085
+ <xsl:param name="isContainsKeepTogetherTag"/>
7086
+
7087
+ <!-- <colwidths><xsl:copy-of select="$colwidths"/></colwidths> -->
7088
+
6598
7089
  <xsl:choose>
6599
7090
  <xsl:when test="ancestor::*[local-name()='dl']"><!-- second level, i.e. inlined table -->
6600
7091
  <fo:table-column column-width="50%"/>
@@ -6602,6 +7093,16 @@
6602
7093
  </xsl:when>
6603
7094
  <xsl:otherwise>
6604
7095
  <xsl:choose>
7096
+ <xsl:when test="xalan:nodeset($colwidths)/autolayout">
7097
+ <xsl:call-template name="insertTableColumnWidth">
7098
+ <xsl:with-param name="colwidths" select="$colwidths"/>
7099
+ </xsl:call-template>
7100
+ </xsl:when>
7101
+ <xsl:when test="$isContainsKeepTogetherTag">
7102
+ <xsl:call-template name="insertTableColumnWidth">
7103
+ <xsl:with-param name="colwidths" select="$colwidths"/>
7104
+ </xsl:call-template>
7105
+ </xsl:when>
6605
7106
  <!-- to set width check most wide chars like `W` -->
6606
7107
  <xsl:when test="normalize-space($maxlength_dt) != '' and number($maxlength_dt) &lt;= 2"> <!-- if dt contains short text like t90, a, etc -->
6607
7108
  <fo:table-column column-width="7%"/>
@@ -6632,20 +7133,31 @@
6632
7133
  <fo:table-column column-width="60%"/>
6633
7134
  </xsl:when>
6634
7135
  <xsl:otherwise>
6635
- <xsl:for-each select="xalan:nodeset($colwidths)//column">
6636
- <xsl:choose>
6637
- <xsl:when test=". = 1 or . = 0">
6638
- <fo:table-column column-width="proportional-column-width(2)"/>
6639
- </xsl:when>
6640
- <xsl:otherwise>
6641
- <fo:table-column column-width="proportional-column-width({.})"/>
6642
- </xsl:otherwise>
6643
- </xsl:choose>
6644
- </xsl:for-each>
7136
+ <xsl:call-template name="insertTableColumnWidth">
7137
+ <xsl:with-param name="colwidths" select="$colwidths"/>
7138
+ </xsl:call-template>
6645
7139
  </xsl:otherwise>
6646
7140
  </xsl:choose>
6647
7141
  </xsl:otherwise>
6648
7142
  </xsl:choose>
7143
+ </xsl:template><xsl:template name="insertTableColumnWidth">
7144
+ <xsl:param name="colwidths"/>
7145
+
7146
+ <xsl:for-each select="xalan:nodeset($colwidths)//column">
7147
+ <xsl:choose>
7148
+ <xsl:when test=". = 1 or . = 0">
7149
+ <fo:table-column column-width="proportional-column-width(2)"/>
7150
+ </xsl:when>
7151
+ <xsl:otherwise>
7152
+ <!-- <fo:table-column column-width="proportional-column-width({.})"/> -->
7153
+ <xsl:variable name="divider">
7154
+ <xsl:value-of select="@divider"/>
7155
+ <xsl:if test="not(@divider)">1</xsl:if>
7156
+ </xsl:variable>
7157
+ <fo:table-column column-width="proportional-column-width({round(. div $divider)})"/>
7158
+ </xsl:otherwise>
7159
+ </xsl:choose>
7160
+ </xsl:for-each>
6649
7161
  </xsl:template><xsl:template name="getMaxLength_dt">
6650
7162
  <xsl:variable name="lengths">
6651
7163
  <xsl:for-each select="*[local-name()='dt']">
@@ -6669,7 +7181,6 @@
6669
7181
  <xsl:value-of select="$maxLength"/>
6670
7182
  </xsl:template><xsl:template match="*[local-name()='dl']/*[local-name()='note']" priority="2">
6671
7183
  <xsl:param name="key_iso"/>
6672
-
6673
7184
  <!-- <tr>
6674
7185
  <td>NOTE</td>
6675
7186
  <td>
@@ -6677,27 +7188,47 @@
6677
7188
  </td>
6678
7189
  </tr>
6679
7190
  -->
6680
- <fo:table-row>
7191
+ <!-- OLD Variant -->
7192
+ <!-- <fo:table-row>
6681
7193
  <fo:table-cell>
6682
7194
  <fo:block margin-top="6pt">
6683
7195
  <xsl:if test="normalize-space($key_iso) = 'true'">
6684
7196
  <xsl:attribute name="margin-top">0</xsl:attribute>
6685
7197
  </xsl:if>
6686
- <xsl:apply-templates select="*[local-name() = 'name']"/>
7198
+ <xsl:apply-templates select="*[local-name() = 'name']" />
6687
7199
  </fo:block>
6688
7200
  </fo:table-cell>
6689
7201
  <fo:table-cell>
6690
7202
  <fo:block>
6691
- <xsl:apply-templates select="node()[not(local-name() = 'name')]"/>
7203
+ <xsl:apply-templates select="node()[not(local-name() = 'name')]" />
7204
+ </fo:block>
7205
+ </fo:table-cell>
7206
+ </fo:table-row> -->
7207
+ <!-- <tr>
7208
+ <td number-columns-spanned="2">NOTE <xsl:apply-templates /> </td>
7209
+ </tr>
7210
+ -->
7211
+ <fo:table-row>
7212
+ <fo:table-cell number-columns-spanned="2">
7213
+ <fo:block>
7214
+ <xsl:call-template name="note"/>
6692
7215
  </fo:block>
6693
7216
  </fo:table-cell>
6694
7217
  </fo:table-row>
6695
7218
  </xsl:template><xsl:template match="*[local-name()='dt']" mode="dl">
7219
+ <xsl:param name="id"/>
7220
+ <xsl:variable name="row_number" select="count(preceding-sibling::*[local-name()='dt']) + 1"/>
6696
7221
  <tr>
6697
7222
  <td>
7223
+ <xsl:attribute name="id">
7224
+ <xsl:value-of select="concat($id,'_',$row_number,'_1')"/>
7225
+ </xsl:attribute>
6698
7226
  <xsl:apply-templates/>
6699
7227
  </td>
6700
7228
  <td>
7229
+ <xsl:attribute name="id">
7230
+ <xsl:value-of select="concat($id,'_',$row_number,'_2')"/>
7231
+ </xsl:attribute>
6701
7232
 
6702
7233
  <xsl:apply-templates select="following-sibling::*[local-name()='dd'][1]">
6703
7234
  <xsl:with-param name="process">true</xsl:with-param>
@@ -6708,50 +7239,122 @@
6708
7239
 
6709
7240
  </xsl:template><xsl:template match="*[local-name()='dt']">
6710
7241
  <xsl:param name="key_iso"/>
7242
+ <xsl:param name="split_keep-within-line"/>
6711
7243
 
6712
7244
  <fo:table-row xsl:use-attribute-sets="dt-row-style">
6713
- <fo:table-cell>
7245
+ <xsl:call-template name="insert_dt_cell">
7246
+ <xsl:with-param name="key_iso" select="$key_iso"/>
7247
+ <xsl:with-param name="split_keep-within-line" select="$split_keep-within-line"/>
7248
+ </xsl:call-template>
7249
+ <xsl:for-each select="following-sibling::*[local-name()='dd'][1]">
7250
+ <xsl:call-template name="insert_dd_cell">
7251
+ <xsl:with-param name="split_keep-within-line" select="$split_keep-within-line"/>
7252
+ </xsl:call-template>
7253
+ </xsl:for-each>
7254
+ </fo:table-row>
7255
+ </xsl:template><xsl:template name="insert_dt_cell">
7256
+ <xsl:param name="key_iso"/>
7257
+ <xsl:param name="split_keep-within-line"/>
7258
+ <fo:table-cell xsl:use-attribute-sets="dt-cell-style">
7259
+
7260
+ <xsl:if test="$isGenerateTableIF = 'true'">
7261
+ <!-- border is mandatory, to calculate real width -->
7262
+ <xsl:attribute name="border">0.1pt solid black</xsl:attribute>
7263
+ <xsl:attribute name="text-align">left</xsl:attribute>
7264
+ </xsl:if>
7265
+
7266
+
7267
+ <fo:block xsl:use-attribute-sets="dt-block-style">
7268
+ <xsl:copy-of select="@id"/>
7269
+
7270
+ <xsl:if test="normalize-space($key_iso) = 'true'">
7271
+ <xsl:attribute name="margin-top">0</xsl:attribute>
7272
+ </xsl:if>
7273
+
7274
+
7275
+
7276
+ <xsl:apply-templates>
7277
+ <xsl:with-param name="split_keep-within-line" select="$split_keep-within-line"/>
7278
+ </xsl:apply-templates>
7279
+
7280
+ <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"/> -->
7281
+
7282
+ </fo:block>
7283
+ </fo:table-cell>
7284
+ </xsl:template><xsl:template name="insert_dd_cell">
7285
+ <xsl:param name="split_keep-within-line"/>
7286
+ <fo:table-cell xsl:use-attribute-sets="dd-cell-style">
7287
+
7288
+ <xsl:if test="$isGenerateTableIF = 'true'">
7289
+ <!-- border is mandatory, to calculate real width -->
7290
+ <xsl:attribute name="border">0.1pt solid black</xsl:attribute>
7291
+ </xsl:if>
7292
+
7293
+ <fo:block>
7294
+
7295
+ <xsl:if test="$isGenerateTableIF = 'true'">
7296
+ <xsl:attribute name="id"><xsl:value-of select="@id"/></xsl:attribute>
7297
+ </xsl:if>
7298
+
6714
7299
 
6715
- <fo:block xsl:use-attribute-sets="dt-style">
6716
- <xsl:copy-of select="@id"/>
6717
-
6718
- <xsl:if test="normalize-space($key_iso) = 'true'">
6719
- <xsl:attribute name="margin-top">0</xsl:attribute>
6720
- </xsl:if>
6721
-
6722
-
6723
-
6724
- <xsl:apply-templates/>
6725
- </fo:block>
6726
- </fo:table-cell>
6727
- <fo:table-cell>
6728
- <fo:block>
6729
-
6730
7300
 
6731
- <xsl:apply-templates select="following-sibling::*[local-name()='dd'][1]">
6732
- <xsl:with-param name="process">true</xsl:with-param>
6733
- </xsl:apply-templates>
6734
- </fo:block>
6735
- </fo:table-cell>
6736
- </fo:table-row>
7301
+ <xsl:choose>
7302
+ <xsl:when test="$isGenerateTableIF = 'true'">
7303
+ <xsl:apply-templates> <!-- following-sibling::*[local-name()='dd'][1] -->
7304
+ <xsl:with-param name="process">true</xsl:with-param>
7305
+ </xsl:apply-templates>
7306
+ </xsl:when>
7307
+ <xsl:otherwise>
7308
+ <xsl:apply-templates select="."> <!-- following-sibling::*[local-name()='dd'][1] -->
7309
+ <xsl:with-param name="process">true</xsl:with-param>
7310
+ <xsl:with-param name="split_keep-within-line" select="$split_keep-within-line"/>
7311
+ </xsl:apply-templates>
7312
+ </xsl:otherwise>
7313
+
7314
+ </xsl:choose>
7315
+
7316
+ <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"/> -->
7317
+
7318
+ </fo:block>
7319
+ </fo:table-cell>
6737
7320
  </xsl:template><xsl:template match="*[local-name()='dd']" mode="dl"/><xsl:template match="*[local-name()='dd']" mode="dl_process">
6738
7321
  <xsl:apply-templates/>
6739
7322
  </xsl:template><xsl:template match="*[local-name()='dd']">
6740
7323
  <xsl:param name="process">false</xsl:param>
7324
+ <xsl:param name="split_keep-within-line"/>
6741
7325
  <xsl:if test="$process = 'true'">
6742
7326
  <xsl:apply-templates select="@language"/>
6743
- <xsl:apply-templates/>
7327
+ <xsl:apply-templates>
7328
+ <xsl:with-param name="split_keep-within-line" select="$split_keep-within-line"/>
7329
+ </xsl:apply-templates>
6744
7330
  </xsl:if>
6745
7331
  </xsl:template><xsl:template match="*[local-name()='dd']/*[local-name()='p']" mode="inline">
6746
7332
  <fo:inline><xsl:text> </xsl:text><xsl:apply-templates/></fo:inline>
6747
- </xsl:template><xsl:template match="*[local-name()='em']">
7333
+ </xsl:template><xsl:template match="*[local-name()='dt']" mode="dl_if">
7334
+ <xsl:param name="id"/>
7335
+ <xsl:variable name="row_number" select="count(preceding-sibling::*[local-name()='dt']) + 1"/>
7336
+ <tr>
7337
+ <td>
7338
+ <xsl:copy-of select="node()"/>
7339
+ </td>
7340
+ <td>
7341
+
7342
+ <xsl:copy-of select="following-sibling::*[local-name()='dd'][1]/node()"/>
7343
+
7344
+ </td>
7345
+ </tr>
7346
+
7347
+ </xsl:template><xsl:template match="*[local-name()='dd']" mode="dl_if"/><xsl:template match="*[local-name()='em']">
6748
7348
  <fo:inline font-style="italic">
6749
7349
  <xsl:apply-templates/>
6750
7350
  </fo:inline>
6751
7351
  </xsl:template><xsl:template match="*[local-name()='strong'] | *[local-name()='b']">
7352
+ <xsl:param name="split_keep-within-line"/>
6752
7353
  <fo:inline font-weight="bold">
6753
7354
 
6754
- <xsl:apply-templates/>
7355
+ <xsl:apply-templates>
7356
+ <xsl:with-param name="split_keep-within-line" select="$split_keep-within-line"/>
7357
+ </xsl:apply-templates>
6755
7358
  </fo:inline>
6756
7359
  </xsl:template><xsl:template match="*[local-name()='padding']">
6757
7360
  <fo:inline padding-right="{@value}"> </fo:inline>
@@ -6790,13 +7393,15 @@
6790
7393
  <xsl:choose>
6791
7394
  <xsl:when test="$font-size = 'inherit'"><xsl:value-of select="$font-size"/></xsl:when>
6792
7395
  <xsl:when test="contains($font-size, '%')"><xsl:value-of select="$font-size"/></xsl:when>
6793
- <xsl:when test="ancestor::*[local-name()='note']"><xsl:value-of select="$font-size * 0.91"/>pt</xsl:when>
7396
+ <xsl:when test="ancestor::*[local-name()='note'] or ancestor::*[local-name()='example']"><xsl:value-of select="$font-size * 0.91"/>pt</xsl:when>
6794
7397
  <xsl:otherwise><xsl:value-of select="$font-size"/>pt</xsl:otherwise>
6795
7398
  </xsl:choose>
6796
7399
  </xsl:attribute>
6797
7400
  </xsl:if>
6798
7401
  <xsl:apply-templates/>
6799
7402
  </fo:inline>
7403
+ </xsl:template><xsl:template match="*[local-name()='tt']/text()" priority="2">
7404
+ <xsl:call-template name="add_spaces_to_sourcecode"/>
6800
7405
  </xsl:template><xsl:template match="*[local-name()='underline']">
6801
7406
  <fo:inline text-decoration="underline">
6802
7407
  <xsl:apply-templates/>
@@ -6944,54 +7549,120 @@
6944
7549
  <fo:block break-after="page"/>
6945
7550
  <fo:block> </fo:block>
6946
7551
  <fo:block break-after="page"/>
7552
+ </xsl:template><xsl:template match="*[local-name() = 'span']">
7553
+ <xsl:apply-templates/>
6947
7554
  </xsl:template><xsl:template name="tokenize">
6948
7555
  <xsl:param name="text"/>
6949
7556
  <xsl:param name="separator" select="' '"/>
6950
7557
  <xsl:choose>
7558
+
7559
+ <xsl:when test="$isGenerateTableIF = 'true' and not(contains($text, $separator))">
7560
+ <word><xsl:value-of select="normalize-space($text)"/></word>
7561
+ </xsl:when>
6951
7562
  <xsl:when test="not(contains($text, $separator))">
6952
7563
  <word>
6953
- <xsl:variable name="str_no_en_chars" select="normalize-space(translate($text, $en_chars, ''))"/>
6954
- <xsl:variable name="len_str_no_en_chars" select="string-length($str_no_en_chars)"/>
6955
7564
  <xsl:variable name="len_str_tmp" select="string-length(normalize-space($text))"/>
6956
- <xsl:variable name="len_str">
6957
- <xsl:choose>
6958
- <xsl:when test="normalize-space(translate($text, $upper, '')) = ''"> <!-- english word in CAPITAL letters -->
6959
- <xsl:value-of select="$len_str_tmp * 1.5"/>
6960
- </xsl:when>
6961
- <xsl:otherwise>
6962
- <xsl:value-of select="$len_str_tmp"/>
6963
- </xsl:otherwise>
6964
- </xsl:choose>
6965
- </xsl:variable>
6966
-
6967
- <!-- <xsl:if test="$len_str_no_en_chars div $len_str &gt; 0.8">
6968
- <xsl:message>
6969
- div=<xsl:value-of select="$len_str_no_en_chars div $len_str"/>
6970
- len_str=<xsl:value-of select="$len_str"/>
6971
- len_str_no_en_chars=<xsl:value-of select="$len_str_no_en_chars"/>
6972
- </xsl:message>
6973
- </xsl:if> -->
6974
- <!-- <len_str_no_en_chars><xsl:value-of select="$len_str_no_en_chars"/></len_str_no_en_chars>
6975
- <len_str><xsl:value-of select="$len_str"/></len_str> -->
6976
7565
  <xsl:choose>
6977
- <xsl:when test="$len_str_no_en_chars div $len_str &gt; 0.8"> <!-- means non-english string -->
6978
- <xsl:value-of select="$len_str - $len_str_no_en_chars"/>
7566
+ <xsl:when test="normalize-space(translate($text, 'X', '')) = ''"> <!-- special case for keep-together.within-line -->
7567
+ <xsl:value-of select="$len_str_tmp"/>
6979
7568
  </xsl:when>
6980
7569
  <xsl:otherwise>
6981
- <xsl:value-of select="$len_str"/>
7570
+ <xsl:variable name="str_no_en_chars" select="normalize-space(translate($text, $en_chars, ''))"/>
7571
+ <xsl:variable name="len_str_no_en_chars" select="string-length($str_no_en_chars)"/>
7572
+ <xsl:variable name="len_str">
7573
+ <xsl:choose>
7574
+ <xsl:when test="normalize-space(translate($text, $upper, '')) = ''"> <!-- english word in CAPITAL letters -->
7575
+ <xsl:value-of select="$len_str_tmp * 1.5"/>
7576
+ </xsl:when>
7577
+ <xsl:otherwise>
7578
+ <xsl:value-of select="$len_str_tmp"/>
7579
+ </xsl:otherwise>
7580
+ </xsl:choose>
7581
+ </xsl:variable>
7582
+
7583
+ <!-- <xsl:if test="$len_str_no_en_chars div $len_str &gt; 0.8">
7584
+ <xsl:message>
7585
+ div=<xsl:value-of select="$len_str_no_en_chars div $len_str"/>
7586
+ len_str=<xsl:value-of select="$len_str"/>
7587
+ len_str_no_en_chars=<xsl:value-of select="$len_str_no_en_chars"/>
7588
+ </xsl:message>
7589
+ </xsl:if> -->
7590
+ <!-- <len_str_no_en_chars><xsl:value-of select="$len_str_no_en_chars"/></len_str_no_en_chars>
7591
+ <len_str><xsl:value-of select="$len_str"/></len_str> -->
7592
+ <xsl:choose>
7593
+ <xsl:when test="$len_str_no_en_chars div $len_str &gt; 0.8"> <!-- means non-english string -->
7594
+ <xsl:value-of select="$len_str - $len_str_no_en_chars"/>
7595
+ </xsl:when>
7596
+ <xsl:otherwise>
7597
+ <xsl:value-of select="$len_str"/>
7598
+ </xsl:otherwise>
7599
+ </xsl:choose>
6982
7600
  </xsl:otherwise>
6983
7601
  </xsl:choose>
6984
7602
  </word>
6985
7603
  </xsl:when>
6986
7604
  <xsl:otherwise>
6987
7605
  <word>
6988
- <xsl:value-of select="string-length(normalize-space(substring-before($text, $separator)))"/>
7606
+ <xsl:variable name="word" select="normalize-space(substring-before($text, $separator))"/>
7607
+ <xsl:choose>
7608
+ <xsl:when test="$isGenerateTableIF = 'true'">
7609
+ <xsl:value-of select="$word"/>
7610
+ </xsl:when>
7611
+ <xsl:otherwise>
7612
+ <xsl:value-of select="string-length($word)"/>
7613
+ </xsl:otherwise>
7614
+ </xsl:choose>
6989
7615
  </word>
6990
7616
  <xsl:call-template name="tokenize">
6991
7617
  <xsl:with-param name="text" select="substring-after($text, $separator)"/>
6992
7618
  </xsl:call-template>
6993
7619
  </xsl:otherwise>
6994
7620
  </xsl:choose>
7621
+ </xsl:template><xsl:template name="tokenize_with_tags">
7622
+ <xsl:param name="tags"/>
7623
+ <xsl:param name="text"/>
7624
+ <xsl:param name="separator" select="' '"/>
7625
+ <xsl:choose>
7626
+
7627
+ <xsl:when test="not(contains($text, $separator))">
7628
+ <word>
7629
+ <xsl:call-template name="enclose_text_in_tags">
7630
+ <xsl:with-param name="text" select="normalize-space($text)"/>
7631
+ <xsl:with-param name="tags" select="$tags"/>
7632
+ </xsl:call-template>
7633
+ </word>
7634
+ </xsl:when>
7635
+ <xsl:otherwise>
7636
+ <word>
7637
+ <xsl:call-template name="enclose_text_in_tags">
7638
+ <xsl:with-param name="text" select="normalize-space(substring-before($text, $separator))"/>
7639
+ <xsl:with-param name="tags" select="$tags"/>
7640
+ </xsl:call-template>
7641
+ </word>
7642
+ <xsl:call-template name="tokenize_with_tags">
7643
+ <xsl:with-param name="text" select="substring-after($text, $separator)"/>
7644
+ </xsl:call-template>
7645
+ </xsl:otherwise>
7646
+ </xsl:choose>
7647
+ </xsl:template><xsl:template name="enclose_text_in_tags">
7648
+ <xsl:param name="text"/>
7649
+ <xsl:param name="tags"/>
7650
+ <xsl:param name="num">1</xsl:param> <!-- default (start) value -->
7651
+
7652
+ <xsl:variable name="tag_name" select="normalize-space(xalan:nodeset($tags)//tag[$num])"/>
7653
+
7654
+ <xsl:choose>
7655
+ <xsl:when test="$tag_name = ''"><xsl:value-of select="$text"/></xsl:when>
7656
+ <xsl:otherwise>
7657
+ <xsl:element name="{$tag_name}">
7658
+ <xsl:call-template name="enclose_text_in_tags">
7659
+ <xsl:with-param name="text" select="$text"/>
7660
+ <xsl:with-param name="tags" select="$tags"/>
7661
+ <xsl:with-param name="num" select="$num + 1"/>
7662
+ </xsl:call-template>
7663
+ </xsl:element>
7664
+ </xsl:otherwise>
7665
+ </xsl:choose>
6995
7666
  </xsl:template><xsl:template name="max_length">
6996
7667
  <xsl:param name="words"/>
6997
7668
  <xsl:for-each select="$words//word">
@@ -7064,36 +7735,47 @@
7064
7735
  </xsl:template><xsl:template name="add-zero-spaces-equal">
7065
7736
  <xsl:param name="text" select="."/>
7066
7737
  <xsl:variable name="zero-space-after-equals">==========</xsl:variable>
7738
+ <xsl:variable name="regex_zero-space-after-equals">(==========)</xsl:variable>
7067
7739
  <xsl:variable name="zero-space-after-equal">=</xsl:variable>
7740
+ <xsl:variable name="regex_zero-space-after-equal">(=)</xsl:variable>
7068
7741
  <xsl:variable name="zero-space">​</xsl:variable>
7069
7742
  <xsl:choose>
7070
7743
  <xsl:when test="contains($text, $zero-space-after-equals)">
7071
- <xsl:value-of select="substring-before($text, $zero-space-after-equals)"/>
7744
+ <!-- <xsl:value-of select="substring-before($text, $zero-space-after-equals)"/>
7072
7745
  <xsl:value-of select="$zero-space-after-equals"/>
7073
7746
  <xsl:value-of select="$zero-space"/>
7074
7747
  <xsl:call-template name="add-zero-spaces-equal">
7075
7748
  <xsl:with-param name="text" select="substring-after($text, $zero-space-after-equals)"/>
7076
- </xsl:call-template>
7749
+ </xsl:call-template> -->
7750
+ <xsl:value-of select="java:replaceAll(java:java.lang.String.new(.),$regex_zero-space-after-equals,concat('$1',$zero_width_space))"/>
7077
7751
  </xsl:when>
7078
7752
  <xsl:when test="contains($text, $zero-space-after-equal)">
7079
- <xsl:value-of select="substring-before($text, $zero-space-after-equal)"/>
7753
+ <!-- <xsl:value-of select="substring-before($text, $zero-space-after-equal)"/>
7080
7754
  <xsl:value-of select="$zero-space-after-equal"/>
7081
7755
  <xsl:value-of select="$zero-space"/>
7082
7756
  <xsl:call-template name="add-zero-spaces-equal">
7083
7757
  <xsl:with-param name="text" select="substring-after($text, $zero-space-after-equal)"/>
7084
- </xsl:call-template>
7758
+ </xsl:call-template> -->
7759
+ <xsl:value-of select="java:replaceAll(java:java.lang.String.new(.),$regex_zero-space-after-equal,concat('$1',$zero_width_space))"/>
7085
7760
  </xsl:when>
7086
7761
  <xsl:otherwise>
7087
7762
  <xsl:value-of select="$text"/>
7088
7763
  </xsl:otherwise>
7089
7764
  </xsl:choose>
7090
7765
  </xsl:template><xsl:template name="getSimpleTable">
7766
+ <xsl:param name="id"/>
7767
+
7091
7768
  <xsl:variable name="simple-table">
7092
7769
 
7770
+ <!-- Step 0. replace <br/> to <p>...</p> -->
7771
+ <xsl:variable name="table_without_br">
7772
+ <xsl:apply-templates mode="table-without-br"/>
7773
+ </xsl:variable>
7774
+
7093
7775
  <!-- Step 1. colspan processing -->
7094
7776
  <xsl:variable name="simple-table-colspan">
7095
7777
  <tbody>
7096
- <xsl:apply-templates mode="simple-table-colspan"/>
7778
+ <xsl:apply-templates select="xalan:nodeset($table_without_br)" mode="simple-table-colspan"/>
7097
7779
  </tbody>
7098
7780
  </xsl:variable>
7099
7781
 
@@ -7102,10 +7784,67 @@
7102
7784
  <xsl:apply-templates select="xalan:nodeset($simple-table-colspan)" mode="simple-table-rowspan"/>
7103
7785
  </xsl:variable>
7104
7786
 
7105
- <xsl:copy-of select="xalan:nodeset($simple-table-rowspan)"/>
7106
-
7787
+ <!-- Step 3: add id to each cell -->
7788
+ <!-- add <word>...</word> for each word, image, math -->
7789
+ <xsl:variable name="simple-table-id">
7790
+ <xsl:apply-templates select="xalan:nodeset($simple-table-rowspan)" mode="simple-table-id">
7791
+ <xsl:with-param name="id" select="$id"/>
7792
+ </xsl:apply-templates>
7793
+ </xsl:variable>
7794
+
7795
+ <xsl:copy-of select="xalan:nodeset($simple-table-id)"/>
7796
+
7107
7797
  </xsl:variable>
7108
7798
  <xsl:copy-of select="$simple-table"/>
7799
+ </xsl:template><xsl:template match="@*|node()" mode="table-without-br">
7800
+ <xsl:copy>
7801
+ <xsl:apply-templates select="@*|node()" mode="table-without-br"/>
7802
+ </xsl:copy>
7803
+ </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">
7804
+ <xsl:copy>
7805
+ <xsl:copy-of select="@*"/>
7806
+ <p>
7807
+ <xsl:copy-of select="node()"/>
7808
+ </p>
7809
+ </xsl:copy>
7810
+ </xsl:template><xsl:template match="*[local-name()='th' or local-name()='td'][*[local-name()='br']]" mode="table-without-br">
7811
+ <xsl:copy>
7812
+ <xsl:copy-of select="@*"/>
7813
+ <xsl:for-each select="*[local-name()='br']">
7814
+ <xsl:variable name="current_id" select="generate-id()"/>
7815
+ <p>
7816
+ <xsl:for-each select="preceding-sibling::node()[following-sibling::*[local-name() = 'br'][1][generate-id() = $current_id]][not(local-name() = 'br')]">
7817
+ <xsl:copy-of select="."/>
7818
+ </xsl:for-each>
7819
+ </p>
7820
+ <xsl:if test="not(following-sibling::*[local-name() = 'br'])">
7821
+ <p>
7822
+ <xsl:for-each select="following-sibling::node()">
7823
+ <xsl:copy-of select="."/>
7824
+ </xsl:for-each>
7825
+ </p>
7826
+ </xsl:if>
7827
+ </xsl:for-each>
7828
+ </xsl:copy>
7829
+ </xsl:template><xsl:template match="*[local-name()='th' or local-name()='td']/*[local-name() = 'p'][*[local-name()='br']]" mode="table-without-br">
7830
+ <xsl:for-each select="*[local-name()='br']">
7831
+ <xsl:variable name="current_id" select="generate-id()"/>
7832
+ <p>
7833
+ <xsl:for-each select="preceding-sibling::node()[following-sibling::*[local-name() = 'br'][1][generate-id() = $current_id]][not(local-name() = 'br')]">
7834
+ <xsl:copy-of select="."/>
7835
+ </xsl:for-each>
7836
+ </p>
7837
+ <xsl:if test="not(following-sibling::*[local-name() = 'br'])">
7838
+ <p>
7839
+ <xsl:for-each select="following-sibling::node()">
7840
+ <xsl:copy-of select="."/>
7841
+ </xsl:for-each>
7842
+ </p>
7843
+ </xsl:if>
7844
+ </xsl:for-each>
7845
+ </xsl:template><xsl:template match="text()[not(ancestor::*[local-name() = 'sourcecode'])]" mode="table-without-br">
7846
+ <xsl:variable name="text" select="translate(.,'&#9;&#10;&#13;','')"/>
7847
+ <xsl:value-of select="java:replaceAll(java:java.lang.String.new($text),' {2,}',' ')"/>
7109
7848
  </xsl:template><xsl:template match="*[local-name()='thead'] | *[local-name()='tbody']" mode="simple-table-colspan">
7110
7849
  <xsl:apply-templates mode="simple-table-colspan"/>
7111
7850
  </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">
@@ -7183,18 +7922,138 @@
7183
7922
  </xsl:choose>
7184
7923
  </xsl:for-each>
7185
7924
  </xsl:variable>
7186
-
7187
- <xsl:variable name="newRow">
7188
- <xsl:copy>
7189
- <xsl:copy-of select="$currentRow/@*"/>
7190
- <xsl:copy-of select="xalan:nodeset($normalizedTDs)"/>
7191
- </xsl:copy>
7925
+
7926
+ <xsl:variable name="newRow">
7927
+ <xsl:copy>
7928
+ <xsl:copy-of select="$currentRow/@*"/>
7929
+ <xsl:copy-of select="xalan:nodeset($normalizedTDs)"/>
7930
+ </xsl:copy>
7931
+ </xsl:variable>
7932
+ <xsl:copy-of select="$newRow"/>
7933
+
7934
+ <xsl:apply-templates select="following-sibling::tr[1]" mode="simple-table-rowspan">
7935
+ <xsl:with-param name="previousRow" select="$newRow"/>
7936
+ </xsl:apply-templates>
7937
+ </xsl:template><xsl:template match="/" mode="simple-table-id">
7938
+ <xsl:param name="id"/>
7939
+ <xsl:variable name="id_prefixed" select="concat('table_if_',$id)"/> <!-- table id prefixed by 'table_if_' to simple search in IF -->
7940
+ <xsl:apply-templates select="@*|node()" mode="simple-table-id">
7941
+ <xsl:with-param name="id" select="$id_prefixed"/>
7942
+ </xsl:apply-templates>
7943
+ </xsl:template><xsl:template match="@*|node()" mode="simple-table-id">
7944
+ <xsl:param name="id"/>
7945
+ <xsl:copy>
7946
+ <xsl:apply-templates select="@*|node()" mode="simple-table-id">
7947
+ <xsl:with-param name="id" select="$id"/>
7948
+ </xsl:apply-templates>
7949
+ </xsl:copy>
7950
+ </xsl:template><xsl:template match="*[local-name()='tbody']" mode="simple-table-id">
7951
+ <xsl:param name="id"/>
7952
+ <xsl:copy>
7953
+ <xsl:copy-of select="@*"/>
7954
+ <xsl:attribute name="id"><xsl:value-of select="$id"/></xsl:attribute>
7955
+ <xsl:apply-templates select="node()" mode="simple-table-id">
7956
+ <xsl:with-param name="id" select="$id"/>
7957
+ </xsl:apply-templates>
7958
+ </xsl:copy>
7959
+ </xsl:template><xsl:template match="*[local-name()='th' or local-name()='td']" mode="simple-table-id">
7960
+ <xsl:param name="id"/>
7961
+ <xsl:copy>
7962
+ <xsl:copy-of select="@*"/>
7963
+ <xsl:variable name="row_number" select="count(../preceding-sibling::*) + 1"/>
7964
+ <xsl:variable name="col_number" select="count(preceding-sibling::*) + 1"/>
7965
+ <xsl:attribute name="id">
7966
+ <xsl:value-of select="concat($id,'_',$row_number,'_',$col_number)"/>
7967
+ </xsl:attribute>
7968
+
7969
+ <xsl:for-each select="*[local-name() = 'p']">
7970
+ <xsl:copy>
7971
+ <xsl:copy-of select="@*"/>
7972
+ <xsl:variable name="p_num" select="count(preceding-sibling::*[local-name() = 'p']) + 1"/>
7973
+ <xsl:attribute name="id">
7974
+ <xsl:value-of select="concat($id,'_',$row_number,'_',$col_number,'_p_',$p_num)"/>
7975
+ </xsl:attribute>
7976
+
7977
+ <xsl:copy-of select="node()"/>
7978
+ </xsl:copy>
7979
+ </xsl:for-each>
7980
+
7981
+
7982
+ <xsl:if test="$isGenerateTableIF = 'true'"> <!-- split each paragraph to words, image, math -->
7983
+
7984
+ <xsl:variable name="td_text">
7985
+ <xsl:apply-templates select="." mode="td_text_with_formatting"/>
7986
+ </xsl:variable>
7987
+
7988
+ <!-- td_text='<xsl:copy-of select="$td_text"/>' -->
7989
+
7990
+ <xsl:variable name="words">
7991
+ <xsl:for-each select=".//*[local-name() = 'image' or local-name() = 'stem']">
7992
+ <word>
7993
+ <xsl:copy-of select="."/>
7994
+ </word>
7995
+ </xsl:for-each>
7996
+
7997
+ <xsl:for-each select="xalan:nodeset($td_text)//*[local-name() = 'word'][normalize-space() != '']">
7998
+ <xsl:copy-of select="."/>
7999
+ </xsl:for-each>
8000
+
8001
+ </xsl:variable>
8002
+
8003
+ <xsl:for-each select="xalan:nodeset($words)/word">
8004
+ <xsl:variable name="num" select="count(preceding-sibling::word) + 1"/>
8005
+ <xsl:copy>
8006
+ <xsl:attribute name="id">
8007
+ <xsl:value-of select="concat($id,'_',$row_number,'_',$col_number,'_word_',$num)"/>
8008
+ </xsl:attribute>
8009
+ <xsl:copy-of select="node()"/>
8010
+ </xsl:copy>
8011
+ </xsl:for-each>
8012
+ </xsl:if>
8013
+ </xsl:copy>
8014
+
8015
+ </xsl:template><xsl:template match="@*|node()" mode="td_text_with_formatting">
8016
+ <xsl:copy>
8017
+ <xsl:apply-templates select="@*|node()" mode="td_text_with_formatting"/>
8018
+ </xsl:copy>
8019
+ </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">
8020
+ <xsl:variable name="formatting_tags">
8021
+ <xsl:call-template name="getFormattingTags"/>
8022
+ </xsl:variable>
8023
+ <word>
8024
+ <xsl:call-template name="enclose_text_in_tags">
8025
+ <xsl:with-param name="text" select="normalize-space(.)"/>
8026
+ <xsl:with-param name="tags" select="$formatting_tags"/>
8027
+ </xsl:call-template>
8028
+ </word>
8029
+ </xsl:template><xsl:template match="*[local-name() != 'keep-together_within-line']/text()" mode="td_text_with_formatting">
8030
+
8031
+ <xsl:variable name="td_text" select="."/>
8032
+
8033
+ <xsl:variable name="string_with_added_zerospaces">
8034
+ <xsl:call-template name="add-zero-spaces-java">
8035
+ <xsl:with-param name="text" select="$td_text"/>
8036
+ </xsl:call-template>
7192
8037
  </xsl:variable>
7193
- <xsl:copy-of select="$newRow"/>
7194
-
7195
- <xsl:apply-templates select="following-sibling::tr[1]" mode="simple-table-rowspan">
7196
- <xsl:with-param name="previousRow" select="$newRow"/>
7197
- </xsl:apply-templates>
8038
+
8039
+ <xsl:variable name="formatting_tags">
8040
+ <xsl:call-template name="getFormattingTags"/>
8041
+ </xsl:variable>
8042
+
8043
+ <!-- <word>text</word> -->
8044
+ <xsl:call-template name="tokenize_with_tags">
8045
+ <xsl:with-param name="tags" select="$formatting_tags"/>
8046
+ <xsl:with-param name="text" select="normalize-space(translate($string_with_added_zerospaces, '​­', ' '))"/> <!-- replace zero-width-space and soft-hyphen to space -->
8047
+ </xsl:call-template>
8048
+ </xsl:template><xsl:template name="getFormattingTags">
8049
+ <tags>
8050
+ <xsl:if test="ancestor::*[local-name() = 'strong']"><tag>strong</tag></xsl:if>
8051
+ <xsl:if test="ancestor::*[local-name() = 'em']"><tag>em</tag></xsl:if>
8052
+ <xsl:if test="ancestor::*[local-name() = 'sub']"><tag>sub</tag></xsl:if>
8053
+ <xsl:if test="ancestor::*[local-name() = 'sup']"><tag>sup</tag></xsl:if>
8054
+ <xsl:if test="ancestor::*[local-name() = 'tt']"><tag>tt</tag></xsl:if>
8055
+ <xsl:if test="ancestor::*[local-name() = 'keep-together_within-line']"><tag>keep-together_within-line</tag></xsl:if>
8056
+ </tags>
7198
8057
  </xsl:template><xsl:template name="getLang">
7199
8058
  <xsl:variable name="language_current" select="normalize-space(//*[local-name()='bibdata']//*[local-name()='language'][@current = 'true'])"/>
7200
8059
  <xsl:variable name="language">
@@ -7249,81 +8108,125 @@
7249
8108
  <xsl:variable name="isDeleted" select="@deleted"/>
7250
8109
 
7251
8110
  <fo:inline xsl:use-attribute-sets="mathml-style">
8111
+
7252
8112
 
7253
8113
  <xsl:if test="ancestor::*[local-name()='table']">
7254
8114
  <xsl:attribute name="font-size">95%</xsl:attribute> <!-- base font in table is 10pt -->
7255
8115
  </xsl:if>
7256
8116
 
7257
8117
 
8118
+
8119
+
7258
8120
  <xsl:call-template name="setTrackChangesStyles">
7259
8121
  <xsl:with-param name="isAdded" select="$isAdded"/>
7260
8122
  <xsl:with-param name="isDeleted" select="$isDeleted"/>
7261
8123
  </xsl:call-template>
7262
8124
 
7263
- <!-- insert helper tag -->
7264
- <xsl:if test="$add_math_as_text = 'true'">
7265
- <fo:inline color="white" font-size="1pt" font-style="normal" font-weight="normal">​</fo:inline> <!-- zero width space -->
7266
- </xsl:if>
7267
-
8125
+ <xsl:if test="$add_math_as_text = 'true'">
8126
+ <!-- insert helper tag -->
8127
+ <!-- set unique font-size (fiction) -->
8128
+ <xsl:variable name="font-size_sfx"><xsl:number level="any"/></xsl:variable>
8129
+ <fo:inline color="white" font-size="1.{$font-size_sfx}pt" font-style="normal" font-weight="normal"><xsl:value-of select="$zero_width_space"/></fo:inline> <!-- zero width space -->
8130
+ </xsl:if>
7268
8131
 
7269
- <xsl:variable name="mathml">
7270
- <xsl:apply-templates select="." mode="mathml"/>
8132
+ <xsl:variable name="mathml_content">
8133
+ <xsl:apply-templates select="." mode="mathml_actual_text"/>
7271
8134
  </xsl:variable>
7272
- <fo:instream-foreign-object fox:alt-text="Math">
7273
8135
 
7274
-
7275
- <xsl:if test="local-name(../..) = 'formula'">
7276
- <xsl:attribute name="width">95%</xsl:attribute>
7277
- <xsl:attribute name="content-height">100%</xsl:attribute>
7278
- <xsl:attribute name="content-width">scale-down-to-fit</xsl:attribute>
7279
- <xsl:attribute name="scaling">uniform</xsl:attribute>
7280
- </xsl:if>
7281
-
7282
- <xsl:if test="$add_math_as_text = 'true'">
7283
- <!-- <xsl:variable name="comment_text" select="following-sibling::node()[1][self::comment()]"/> -->
7284
- <xsl:variable name="comment_text" select="normalize-space(translate(.,' ⁢',' '))"/>
7285
- <xsl:if test="normalize-space($comment_text) != ''">
7286
- <!-- put Mathin Alternate Text -->
7287
- <xsl:attribute name="fox:alt-text">
7288
- <xsl:value-of select="java:org.metanorma.fop.Util.unescape($comment_text)"/>
7289
- </xsl:attribute>
7290
- </xsl:if>
7291
- </xsl:if>
7292
-
7293
-
7294
- <xsl:variable name="comment_text_following" select="following-sibling::node()[1][self::comment()]"/>
7295
- <xsl:variable name="comment_text_">
8136
+
8137
+ <xsl:variable name="filename" select="xalan:nodeset($mathml_attachments)//attachment[. = $mathml_content]/@filename"/>
7296
8138
  <xsl:choose>
7297
- <xsl:when test="normalize-space($comment_text_following) != ''">
7298
- <xsl:value-of select="$comment_text_following"/>
8139
+ <xsl:when test="$add_math_as_attachment = 'true' and normalize-space($filename) != ''">
8140
+ <xsl:variable name="url" select="concat('url(embedded-file:', $filename, ')')"/>
8141
+ <fo:basic-link external-destination="{$url}" fox:alt-text="MathLink">
8142
+ <xsl:variable name="comment_text">
8143
+ <xsl:call-template name="getMathml_comment_text"/>
8144
+ </xsl:variable>
8145
+ <xsl:if test="normalize-space($comment_text) != ''">
8146
+ <!-- put Mathin Alternate Text -->
8147
+ <xsl:attribute name="fox:alt-text">
8148
+ <xsl:value-of select="$comment_text"/>
8149
+ </xsl:attribute>
8150
+ </xsl:if>
8151
+ <xsl:call-template name="mathml_instream_object">
8152
+ <xsl:with-param name="comment_text" select="$comment_text"/>
8153
+ <xsl:with-param name="mathml_content" select="$mathml_content"/>
8154
+ </xsl:call-template>
8155
+ </fo:basic-link>
7299
8156
  </xsl:when>
7300
8157
  <xsl:otherwise>
7301
- <xsl:value-of select="normalize-space(translate(.,' ⁢',' '))"/>
8158
+ <xsl:call-template name="mathml_instream_object">
8159
+ <xsl:with-param name="mathml_content" select="$mathml_content"/>
8160
+ </xsl:call-template>
7302
8161
  </xsl:otherwise>
7303
8162
  </xsl:choose>
7304
- </xsl:variable>
7305
- <xsl:variable name="comment_text" select="java:org.metanorma.fop.Util.unescape($comment_text_)"/>
8163
+ <!-- end BSI -->
7306
8164
 
7307
- <xsl:if test="normalize-space($comment_text) != ''">
7308
- <!-- put Mathin Alternate Text -->
7309
- <xsl:attribute name="fox:alt-text">
7310
- <xsl:value-of select="java:org.metanorma.fop.Util.unescape($comment_text)"/>
7311
- </xsl:attribute>
8165
+
8166
+ </fo:inline>
8167
+ </xsl:template><xsl:template name="getMathml_comment_text">
8168
+ <xsl:variable name="comment_text_following" select="following-sibling::node()[1][self::comment()]"/>
8169
+ <xsl:variable name="comment_text_">
8170
+ <xsl:choose>
8171
+ <xsl:when test="normalize-space($comment_text_following) != ''">
8172
+ <xsl:value-of select="$comment_text_following"/>
8173
+ </xsl:when>
8174
+ <xsl:otherwise>
8175
+ <xsl:value-of select="normalize-space(translate(.,' ⁢',' '))"/>
8176
+ </xsl:otherwise>
8177
+ </xsl:choose>
8178
+ </xsl:variable>
8179
+ <xsl:variable name="comment_text_2" select="java:org.metanorma.fop.Util.unescape($comment_text_)"/>
8180
+ <xsl:variable name="comment_text" select="java:trim(java:java.lang.String.new($comment_text_2))"/>
8181
+ <xsl:value-of select="$comment_text"/>
8182
+ </xsl:template><xsl:template name="mathml_instream_object">
8183
+ <xsl:param name="comment_text"/>
8184
+ <xsl:param name="mathml_content"/>
8185
+
8186
+ <xsl:variable name="comment_text_">
8187
+ <xsl:choose>
8188
+ <xsl:when test="normalize-space($comment_text) != ''"><xsl:value-of select="$comment_text"/></xsl:when>
8189
+ <xsl:otherwise><xsl:call-template name="getMathml_comment_text"/></xsl:otherwise>
8190
+ </xsl:choose>
8191
+ </xsl:variable>
8192
+
8193
+ <xsl:variable name="mathml">
8194
+ <xsl:apply-templates select="." mode="mathml"/>
8195
+ </xsl:variable>
8196
+
8197
+ <fo:instream-foreign-object fox:alt-text="Math">
8198
+
8199
+
8200
+ <xsl:if test="local-name(../..) = 'formula'">
8201
+ <xsl:attribute name="width">95%</xsl:attribute>
8202
+ <xsl:attribute name="content-height">100%</xsl:attribute>
8203
+ <xsl:attribute name="content-width">scale-down-to-fit</xsl:attribute>
8204
+ <xsl:attribute name="scaling">uniform</xsl:attribute>
7312
8205
  </xsl:if>
7313
-
7314
- <xsl:variable name="mathml_content">
7315
- <xsl:apply-templates select="." mode="mathml_actual_text"/>
7316
- </xsl:variable>
7317
- <!-- put MathML in Actual Text -->
7318
- <xsl:attribute name="fox:actual-text">
7319
- <xsl:value-of select="$mathml_content"/>
8206
+
8207
+
8208
+
8209
+
8210
+
8211
+
8212
+ <!-- put MathML in Actual Text -->
8213
+ <!-- DEBUG: mathml_content=<xsl:value-of select="$mathml_content"/> -->
8214
+ <xsl:attribute name="fox:actual-text">
8215
+ <xsl:value-of select="$mathml_content"/>
8216
+ </xsl:attribute>
8217
+
8218
+ <!-- <xsl:if test="$add_math_as_text = 'true'"> -->
8219
+ <xsl:if test="normalize-space($comment_text_) != ''">
8220
+ <!-- put Mathin Alternate Text -->
8221
+ <xsl:attribute name="fox:alt-text">
8222
+ <xsl:value-of select="$comment_text_"/>
7320
8223
  </xsl:attribute>
7321
-
7322
-
7323
-
7324
- <xsl:copy-of select="xalan:nodeset($mathml)"/>
7325
- </fo:instream-foreign-object>
7326
- </fo:inline>
8224
+ </xsl:if>
8225
+ <!-- </xsl:if> -->
8226
+
8227
+ <xsl:copy-of select="xalan:nodeset($mathml)"/>
8228
+
8229
+ </fo:instream-foreign-object>
7327
8230
  </xsl:template><xsl:template match="mathml:*" mode="mathml_actual_text">
7328
8231
  <!-- <xsl:text>a+b</xsl:text> -->
7329
8232
  <xsl:text>&lt;</xsl:text>
@@ -7354,7 +8257,9 @@
7354
8257
  <!-- replace start and end spaces to non-break space -->
7355
8258
  <xsl:value-of select="java:replaceAll(java:java.lang.String.new(.),'(^ )|( $)',' ')"/>
7356
8259
  </xsl:copy>
7357
- </xsl:template><xsl:template match="mathml:math/*[local-name()='unit']" mode="mathml"/><xsl:template match="mathml:math/*[local-name()='prefix']" mode="mathml"/><xsl:template match="mathml:math/*[local-name()='dimension']" mode="mathml"/><xsl:template match="mathml:math/*[local-name()='quantity']" mode="mathml"/><xsl:template match="*[local-name()='localityStack']"/><xsl:template match="*[local-name()='link']" name="link">
8260
+ </xsl:template><xsl:template match="mathml:math/*[local-name()='unit']" mode="mathml"/><xsl:template match="mathml:math/*[local-name()='prefix']" mode="mathml"/><xsl:template match="mathml:math/*[local-name()='dimension']" mode="mathml"/><xsl:template match="mathml:math/*[local-name()='quantity']" mode="mathml"/><xsl:template match="mathml:mtd/mathml:mo/text()[. = '/']" mode="mathml">
8261
+ <xsl:value-of select="."/><xsl:value-of select="$zero_width_space"/>
8262
+ </xsl:template><xsl:template match="*[local-name()='localityStack']"/><xsl:template match="*[local-name()='link']" name="link">
7358
8263
  <xsl:variable name="target">
7359
8264
  <xsl:choose>
7360
8265
  <xsl:when test="@updatetype = 'true'">
@@ -7595,7 +8500,12 @@
7595
8500
 
7596
8501
  <fo:inline xsl:use-attribute-sets="termnote-name-style">
7597
8502
 
8503
+ <xsl:if test="not(*[local-name() = 'name']/following-sibling::node()[1][self::text()][normalize-space()=''])">
8504
+ <xsl:attribute name="padding-right">1mm</xsl:attribute>
8505
+ </xsl:if>
8506
+
7598
8507
 
8508
+
7599
8509
 
7600
8510
  <!-- if 'p' contains all text in 'add' first and last elements in first p are 'add' -->
7601
8511
  <!-- <xsl:if test="*[not(local-name()='name')][1][node()[normalize-space() != ''][1][local-name() = 'add'] and node()[normalize-space() != ''][last()][local-name() = 'add']]"> -->
@@ -7960,18 +8870,33 @@
7960
8870
  </xsl:template><xsl:template match="*[local-name() = 'svg'][not(@width and @height)]" mode="svg_update">
7961
8871
  <xsl:copy>
7962
8872
  <xsl:apply-templates select="@*" mode="svg_update"/>
7963
- <xsl:variable name="viewbox">
8873
+ <xsl:variable name="viewbox_">
7964
8874
  <xsl:call-template name="split">
7965
8875
  <xsl:with-param name="pText" select="@viewBox"/>
7966
8876
  <xsl:with-param name="sep" select="' '"/>
7967
8877
  </xsl:call-template>
7968
8878
  </xsl:variable>
8879
+ <xsl:variable name="viewbox" select="xalan:nodeset($viewbox_)"/>
8880
+ <xsl:variable name="width" select="normalize-space($viewbox//item[3])"/>
8881
+ <xsl:variable name="height" select="normalize-space($viewbox//item[4])"/>
8882
+
7969
8883
  <xsl:attribute name="width">
7970
- <xsl:value-of select="round(xalan:nodeset($viewbox)//item[3])"/>
8884
+ <xsl:choose>
8885
+ <xsl:when test="$width != ''">
8886
+ <xsl:value-of select="round($width)"/>
8887
+ </xsl:when>
8888
+ <xsl:otherwise>400</xsl:otherwise> <!-- default width -->
8889
+ </xsl:choose>
7971
8890
  </xsl:attribute>
7972
8891
  <xsl:attribute name="height">
7973
- <xsl:value-of select="round(xalan:nodeset($viewbox)//item[4])"/>
8892
+ <xsl:choose>
8893
+ <xsl:when test="$height != ''">
8894
+ <xsl:value-of select="round($height)"/>
8895
+ </xsl:when>
8896
+ <xsl:otherwise>400</xsl:otherwise> <!-- default height -->
8897
+ </xsl:choose>
7974
8898
  </xsl:attribute>
8899
+
7975
8900
  <xsl:apply-templates mode="svg_update"/>
7976
8901
  </xsl:copy>
7977
8902
  </xsl:template><xsl:template match="*[local-name() = 'figure']/*[local-name() = 'image'][*[local-name() = 'svg']]" priority="3">
@@ -8166,7 +9091,11 @@
8166
9091
  <xsl:apply-templates mode="bookmarks"/>
8167
9092
  </xsl:template><xsl:template match="*[local-name() = 'title' or local-name() = 'name']//*[local-name() = 'stem']" mode="contents">
8168
9093
  <xsl:apply-templates select="."/>
8169
- </xsl:template><xsl:template match="*[local-name() = 'references'][@hidden='true']" mode="contents" priority="3"/><xsl:template match="*[local-name() = 'references']/*[local-name() = 'bibitem']" mode="contents"/><xsl:template match="*[local-name() = 'stem']" mode="bookmarks">
9094
+ </xsl:template><xsl:template match="*[local-name() = 'references'][@hidden='true']" mode="contents" priority="3"/><xsl:template match="*[local-name() = 'references']/*[local-name() = 'bibitem']" mode="contents"/><xsl:template match="*[local-name() = 'span']" mode="contents">
9095
+ <xsl:apply-templates mode="contents"/>
9096
+ </xsl:template><xsl:template match="*[local-name() = 'stem']" mode="bookmarks">
9097
+ <xsl:apply-templates mode="bookmarks"/>
9098
+ </xsl:template><xsl:template match="*[local-name() = 'span']" mode="bookmarks">
8170
9099
  <xsl:apply-templates mode="bookmarks"/>
8171
9100
  </xsl:template><xsl:template name="addBookmarks">
8172
9101
  <xsl:param name="contents"/>
@@ -8462,7 +9391,9 @@
8462
9391
  <xsl:apply-templates/>
8463
9392
  </xsl:otherwise>
8464
9393
  </xsl:choose>
8465
- </xsl:template><xsl:template match="*[local-name() = 'fn']" mode="contents"/><xsl:template match="*[local-name() = 'fn']" mode="bookmarks"/><xsl:template match="*[local-name() = 'fn']" mode="contents_item"/><xsl:template match="*[local-name() = 'tab']" mode="contents_item">
9394
+ </xsl:template><xsl:template match="*[local-name() = 'fn']" mode="contents"/><xsl:template match="*[local-name() = 'fn']" mode="bookmarks"/><xsl:template match="*[local-name() = 'fn']" mode="contents_item"/><xsl:template match="*[local-name() = 'xref']" mode="contents">
9395
+ <xsl:value-of select="."/>
9396
+ </xsl:template><xsl:template match="*[local-name() = 'tab']" mode="contents_item">
8466
9397
  <xsl:text> </xsl:text>
8467
9398
  </xsl:template><xsl:template match="*[local-name() = 'strong']" mode="contents_item">
8468
9399
  <xsl:copy>
@@ -8493,9 +9424,22 @@
8493
9424
  </xsl:when>
8494
9425
  <xsl:otherwise><xsl:apply-templates mode="contents_item"/></xsl:otherwise>
8495
9426
  </xsl:choose>
9427
+ </xsl:template><xsl:template match="text()" mode="contents_item">
9428
+ <xsl:call-template name="keep_together_standard_number"/>
9429
+ </xsl:template><xsl:template match="*[local-name() = 'span']" mode="contents_item">
9430
+ <xsl:apply-templates mode="contents_item"/>
8496
9431
  </xsl:template><xsl:template match="*[local-name()='sourcecode']" name="sourcecode">
8497
9432
 
8498
9433
  <fo:block-container xsl:use-attribute-sets="sourcecode-container-style">
9434
+
9435
+ <xsl:if test="not(ancestor::*[local-name() = 'li']) or ancestor::*[local-name() = 'example']">
9436
+ <xsl:attribute name="margin-left">0mm</xsl:attribute>
9437
+ </xsl:if>
9438
+
9439
+ <xsl:if test="ancestor::*[local-name() = 'example']">
9440
+ <xsl:attribute name="margin-right">0mm</xsl:attribute>
9441
+ </xsl:if>
9442
+
8499
9443
  <xsl:copy-of select="@id"/>
8500
9444
 
8501
9445
  <xsl:if test="parent::*[local-name() = 'note']">
@@ -8595,17 +9539,15 @@
8595
9539
 
8596
9540
  <!-- split text by zero-width space -->
8597
9541
  <xsl:variable name="text_step4">
8598
- <xsl:call-template name="split">
9542
+ <xsl:call-template name="split_for_interspers">
8599
9543
  <xsl:with-param name="pText" select="$text_step3"/>
8600
9544
  <xsl:with-param name="sep" select="$zero_width_space"/>
8601
- <xsl:with-param name="normalize-space">false</xsl:with-param>
8602
- <xsl:with-param name="keep_sep">true</xsl:with-param>
8603
9545
  </xsl:call-template>
8604
9546
  </xsl:variable>
8605
9547
 
8606
- <xsl:for-each select="xalan:nodeset($text_step4)/item">
9548
+ <xsl:for-each select="xalan:nodeset($text_step4)/node()">
8607
9549
  <xsl:choose>
8608
- <xsl:when test="string-length() &gt; 30"> <!-- word with length more than 30 will be interspersed with zero-width space -->
9550
+ <xsl:when test="local-name() = 'interspers'"> <!-- word with length more than 30 will be interspersed with zero-width space -->
8609
9551
  <xsl:call-template name="interspers">
8610
9552
  <xsl:with-param name="str" select="."/>
8611
9553
  </xsl:call-template>
@@ -8616,6 +9558,30 @@
8616
9558
  </xsl:choose>
8617
9559
  </xsl:for-each>
8618
9560
 
9561
+ </xsl:template><xsl:variable name="interspers_tag_open">###interspers123###</xsl:variable><xsl:variable name="interspers_tag_close">###/interspers123###</xsl:variable><xsl:template name="split_for_interspers">
9562
+ <xsl:param name="pText" select="."/>
9563
+ <xsl:param name="sep" select="','"/>
9564
+ <!-- word with length more than 30 will be interspersed with zero-width space -->
9565
+ <xsl:variable name="regex" select="concat('([^', $zero_width_space, ']{31,})')"/> <!-- sequence of characters (more 31), that doesn't contains zero-width space -->
9566
+ <xsl:variable name="text" select="java:replaceAll(java:java.lang.String.new($pText),$regex,concat($interspers_tag_open,'$1',$interspers_tag_close))"/>
9567
+ <xsl:call-template name="replace_tag_interspers">
9568
+ <xsl:with-param name="text" select="$text"/>
9569
+ </xsl:call-template>
9570
+ </xsl:template><xsl:template name="replace_tag_interspers">
9571
+ <xsl:param name="text"/>
9572
+ <xsl:choose>
9573
+ <xsl:when test="contains($text, $interspers_tag_open)">
9574
+ <xsl:value-of select="substring-before($text, $interspers_tag_open)"/>
9575
+ <xsl:variable name="text_after" select="substring-after($text, $interspers_tag_open)"/>
9576
+ <interspers>
9577
+ <xsl:value-of select="substring-before($text_after, $interspers_tag_close)"/>
9578
+ </interspers>
9579
+ <xsl:call-template name="replace_tag_interspers">
9580
+ <xsl:with-param name="text" select="substring-after($text_after, $interspers_tag_close)"/>
9581
+ </xsl:call-template>
9582
+ </xsl:when>
9583
+ <xsl:otherwise><xsl:value-of select="$text"/></xsl:otherwise>
9584
+ </xsl:choose>
8619
9585
  </xsl:template><xsl:template name="interspers">
8620
9586
  <xsl:param name="str"/>
8621
9587
  <xsl:param name="char" select="$zero_width_space"/>
@@ -8844,7 +9810,9 @@
8844
9810
  <!-- <xsl:attribute name="border">0.5pt solid black</xsl:attribute> -->
8845
9811
  </xsl:if>
8846
9812
  <xsl:variable name="simple-table">
8847
- <xsl:call-template name="getSimpleTable"/>
9813
+ <xsl:call-template name="getSimpleTable">
9814
+ <xsl:with-param name="id" select="@id"/>
9815
+ </xsl:call-template>
8848
9816
  </xsl:variable>
8849
9817
  <xsl:variable name="cols-count" select="count(xalan:nodeset($simple-table)//tr[1]/td)"/>
8850
9818
  <xsl:if test="$cols-count = 2 and not(ancestor::*[local-name()='table'])">
@@ -8951,39 +9919,67 @@
8951
9919
  </xsl:otherwise>
8952
9920
  </xsl:choose>
8953
9921
  </xsl:template><xsl:template match="*[local-name() = 'example']">
8954
- <fo:block id="{@id}" xsl:use-attribute-sets="example-style">
8955
-
9922
+
9923
+ <fo:block-container id="{@id}" xsl:use-attribute-sets="example-style">
9924
+
8956
9925
 
9926
+
8957
9927
  <xsl:variable name="fo_element">
8958
- <xsl:if test=".//*[local-name() = 'table'] or .//*[local-name() = 'dl']">block</xsl:if>
9928
+ <xsl:if test=".//*[local-name() = 'table'] or .//*[local-name() = 'dl'] or *[not(local-name() = 'name')][1][local-name() = 'sourcecode']">block</xsl:if>
8959
9929
  block
8960
9930
  </xsl:variable>
8961
9931
 
8962
- <!-- display 'EXAMPLE' -->
8963
- <xsl:apply-templates select="*[local-name()='name']">
8964
- <xsl:with-param name="fo_element" select="$fo_element"/>
8965
- </xsl:apply-templates>
9932
+ <fo:block-container margin-left="0mm">
8966
9933
 
8967
- <xsl:choose>
8968
- <xsl:when test="contains(normalize-space($fo_element), 'block')">
8969
- <fo:block-container xsl:use-attribute-sets="example-body-style">
8970
- <fo:block-container margin-left="0mm" margin-right="0mm">
8971
- <xsl:apply-templates select="node()[not(local-name() = 'name')]">
9934
+ <xsl:choose>
9935
+
9936
+ <xsl:when test="contains(normalize-space($fo_element), 'block')">
9937
+
9938
+ <!-- display name 'EXAMPLE' in a separate block -->
9939
+ <fo:block>
9940
+ <xsl:apply-templates select="*[local-name()='name']">
8972
9941
  <xsl:with-param name="fo_element" select="$fo_element"/>
8973
9942
  </xsl:apply-templates>
9943
+ </fo:block>
9944
+
9945
+ <fo:block-container xsl:use-attribute-sets="example-body-style">
9946
+ <fo:block-container margin-left="0mm" margin-right="0mm">
9947
+ <xsl:apply-templates select="node()[not(local-name() = 'name')]">
9948
+ <xsl:with-param name="fo_element" select="$fo_element"/>
9949
+ </xsl:apply-templates>
9950
+ </fo:block-container>
8974
9951
  </fo:block-container>
8975
- </fo:block-container>
8976
- </xsl:when>
8977
- <xsl:otherwise>
8978
- <fo:inline>
8979
- <xsl:apply-templates select="node()[not(local-name() = 'name')]">
8980
- <xsl:with-param name="fo_element" select="$fo_element"/>
8981
- </xsl:apply-templates>
8982
- </fo:inline>
8983
- </xsl:otherwise>
8984
- </xsl:choose>
8985
-
8986
- </fo:block>
9952
+ </xsl:when> <!-- end block -->
9953
+
9954
+ <xsl:otherwise> <!-- inline -->
9955
+
9956
+ <!-- display 'EXAMPLE' and first element in the same line -->
9957
+ <fo:block>
9958
+ <xsl:apply-templates select="*[local-name()='name']">
9959
+ <xsl:with-param name="fo_element" select="$fo_element"/>
9960
+ </xsl:apply-templates>
9961
+ <fo:inline>
9962
+ <xsl:apply-templates select="*[not(local-name() = 'name')][1]">
9963
+ <xsl:with-param name="fo_element" select="$fo_element"/>
9964
+ </xsl:apply-templates>
9965
+ </fo:inline>
9966
+ </fo:block>
9967
+
9968
+ <xsl:if test="*[not(local-name() = 'name')][position() &gt; 1]">
9969
+ <!-- display further elements in blocks -->
9970
+ <fo:block-container xsl:use-attribute-sets="example-body-style">
9971
+ <fo:block-container margin-left="0mm" margin-right="0mm">
9972
+ <xsl:apply-templates select="*[not(local-name() = 'name')][position() &gt; 1]">
9973
+ <xsl:with-param name="fo_element" select="'block'"/>
9974
+ </xsl:apply-templates>
9975
+ </fo:block-container>
9976
+ </fo:block-container>
9977
+ </xsl:if>
9978
+ </xsl:otherwise> <!-- end inline -->
9979
+
9980
+ </xsl:choose>
9981
+ </fo:block-container>
9982
+ </fo:block-container>
8987
9983
  </xsl:template><xsl:template match="*[local-name() = 'example']/*[local-name() = 'name']">
8988
9984
  <xsl:param name="fo_element">block</xsl:param>
8989
9985
 
@@ -9015,10 +10011,16 @@
9015
10011
  </xsl:variable>
9016
10012
  <xsl:choose>
9017
10013
  <xsl:when test="starts-with(normalize-space($element), 'block')">
9018
- <fo:block xsl:use-attribute-sets="example-p-style">
9019
-
9020
- <xsl:apply-templates/>
9021
- </fo:block>
10014
+ <fo:block-container>
10015
+ <xsl:if test="ancestor::*[local-name() = 'li'] and contains(normalize-space($fo_element), 'block')">
10016
+ <xsl:attribute name="margin-left">0mm</xsl:attribute>
10017
+ <xsl:attribute name="margin-right">0mm</xsl:attribute>
10018
+ </xsl:if>
10019
+ <fo:block xsl:use-attribute-sets="example-p-style">
10020
+
10021
+ <xsl:apply-templates/>
10022
+ </fo:block>
10023
+ </fo:block-container>
9022
10024
  </xsl:when>
9023
10025
  <xsl:otherwise>
9024
10026
  <fo:inline xsl:use-attribute-sets="example-p-style">
@@ -9063,7 +10065,7 @@
9063
10065
  </xsl:otherwise>
9064
10066
  </xsl:choose> -->
9065
10067
  </fo:block>
9066
- </xsl:template><xsl:template match="*[local-name() = 'termsource']/text()[starts-with(., '[SOURCE: Adapted from: ')]" priority="2">
10068
+ </xsl:template><xsl:template match="*[local-name() = 'termsource']/text()[starts-with(., '[SOURCE: Adapted from: ') or starts-with(., '[SOURCE: Quoted from: ') or starts-with(., '[SOURCE: Modified from: ')]" priority="2">
9067
10069
  <xsl:text>[</xsl:text><xsl:value-of select="substring-after(., '[SOURCE: ')"/>
9068
10070
  </xsl:template><xsl:template match="*[local-name() = 'termsource']/text()">
9069
10071
  <xsl:if test="normalize-space() != ''">
@@ -9206,7 +10208,16 @@
9206
10208
  </fo:inline>
9207
10209
  </xsl:when>
9208
10210
  <xsl:otherwise> <!-- if there is key('bibitems_hidden', $current_bibitemid) -->
9209
- <fo:inline><xsl:apply-templates/></fo:inline>
10211
+
10212
+ <!-- if in bibitem[@hidden='true'] there is url[@type='src'], then create hyperlink -->
10213
+ <xsl:variable name="uri_src" select="normalize-space($bibitems_hidden/*[local-name() ='bibitem'][@id = $current_bibitemid]/*[local-name() = 'uri'][@type = 'src'])"/>
10214
+ <xsl:choose>
10215
+ <xsl:when test="$uri_src != ''">
10216
+ <fo:basic-link external-destination="{$uri_src}" fox:alt-text="{$uri_src}"><xsl:apply-templates/></fo:basic-link>
10217
+ </xsl:when>
10218
+ <xsl:otherwise><fo:inline><xsl:apply-templates/></fo:inline></xsl:otherwise>
10219
+ </xsl:choose>
10220
+
9210
10221
  </xsl:otherwise>
9211
10222
  </xsl:choose>
9212
10223
  </xsl:template><xsl:template match="*[local-name() = 'tab']">
@@ -9379,10 +10390,24 @@
9379
10390
 
9380
10391
  </fo:block>
9381
10392
  <xsl:apply-templates/>
9382
- </xsl:template><xsl:template match="*[local-name() = 'review']">
10393
+ </xsl:template><xsl:template match="*[local-name() = 'review']"> <!-- 'review' will be processed in mn2pdf/review.xsl -->
9383
10394
  <!-- comment 2019-11-29 -->
9384
10395
  <!-- <fo:block font-weight="bold">Review:</fo:block>
9385
10396
  <xsl:apply-templates /> -->
10397
+
10398
+ <xsl:variable name="id_from" select="normalize-space(current()/@from)"/>
10399
+
10400
+ <xsl:choose>
10401
+ <!-- if there isn't the attribute '@from', then -->
10402
+ <xsl:when test="$id_from = ''">
10403
+ <fo:block id="{@id}" font-size="1pt"><xsl:value-of select="$hair_space"/></fo:block>
10404
+ </xsl:when>
10405
+ <!-- if there isn't element with id 'from', then create 'bookmark' here -->
10406
+ <xsl:when test="not(ancestor::*[contains(local-name(), '-standard')]//*[@id = $id_from])">
10407
+ <fo:block id="{@from}" font-size="1pt"><xsl:value-of select="$hair_space"/></fo:block>
10408
+ </xsl:when>
10409
+ </xsl:choose>
10410
+
9386
10411
  </xsl:template><xsl:template match="*[local-name() = 'name']/text()">
9387
10412
  <!-- 0xA0 to space replacement -->
9388
10413
  <xsl:value-of select="java:replaceAll(java:java.lang.String.new(.),' ',' ')"/>
@@ -9743,7 +10768,10 @@
9743
10768
  <!-- to split by '_' and other chars -->
9744
10769
  <xsl:call-template name="add-zero-spaces-java"/>
9745
10770
  </xsl:template><xsl:template match="*[local-name() = 'bookmark']" name="bookmark">
9746
- <fo:inline id="{@id}" font-size="1pt"/>
10771
+ <!-- <fo:inline id="{@id}" font-size="1pt"/> -->
10772
+ <fo:inline id="{@id}" font-size="1pt"><xsl:value-of select="$hair_space"/></fo:inline>
10773
+ <!-- we need to add zero-width space, otherwise this fo:inline is missing in IF xml -->
10774
+ <xsl:if test="not(following-sibling::node()[normalize-space() != ''])"><fo:inline font-size="1pt"> </fo:inline></xsl:if>
9747
10775
  </xsl:template><xsl:template match="*[local-name() = 'errata']">
9748
10776
  <!-- <row>
9749
10777
  <date>05-07-2013</date>
@@ -10303,6 +11331,120 @@
10303
11331
  <xsl:apply-templates select="." mode="update_xml_step1"/>
10304
11332
  </xsl:for-each>
10305
11333
  </xsl:copy>
11334
+ </xsl:template><xsl:template match="*[local-name() = 'span']" mode="update_xml_step1">
11335
+ <xsl:apply-templates mode="update_xml_step1"/>
11336
+ </xsl:template><xsl:template match="@*|node()" mode="update_xml_enclose_keep-together_within-line">
11337
+ <xsl:copy>
11338
+ <xsl:apply-templates select="@*|node()" mode="update_xml_enclose_keep-together_within-line"/>
11339
+ </xsl:copy>
11340
+ </xsl:template><xsl:variable name="express_reference_separators">_.\</xsl:variable><xsl:variable name="express_reference_characters" select="concat($upper,$lower,'1234567890',$express_reference_separators)"/><xsl:variable name="element_name_keep-together_within-line">keep-together_within-line</xsl:variable><xsl:template match="text()[not(ancestor::*[local-name() = 'bibdata'] or ancestor::*[local-name() = 'sourcecode'] or ancestor::*[local-name() = 'math'])]" name="keep_together_standard_number" mode="update_xml_enclose_keep-together_within-line">
11341
+
11342
+ <!-- enclose standard's number into tag 'keep-together_within-line' -->
11343
+ <xsl:variable name="regex_standard_reference">([A-Z]{2,}(/[A-Z]{2,})* \d+(-\d+)*(:\d{4})?)</xsl:variable>
11344
+ <xsl:variable name="tag_keep-together_within-line_open">###<xsl:value-of select="$element_name_keep-together_within-line"/>###</xsl:variable>
11345
+ <xsl:variable name="tag_keep-together_within-line_close">###/<xsl:value-of select="$element_name_keep-together_within-line"/>###</xsl:variable>
11346
+ <xsl:variable name="text_" select="java:replaceAll(java:java.lang.String.new(.),$regex_standard_reference,concat($tag_keep-together_within-line_open,'$1',$tag_keep-together_within-line_close))"/>
11347
+ <xsl:variable name="text"><text><xsl:call-template name="replace_text_tags">
11348
+ <xsl:with-param name="tag_open" select="$tag_keep-together_within-line_open"/>
11349
+ <xsl:with-param name="tag_close" select="$tag_keep-together_within-line_close"/>
11350
+ <xsl:with-param name="text" select="$text_"/>
11351
+ </xsl:call-template></text></xsl:variable>
11352
+
11353
+ <xsl:variable name="parent" select="local-name(..)"/>
11354
+
11355
+ <xsl:variable name="text2">
11356
+ <text><xsl:for-each select="xalan:nodeset($text)/text/node()">
11357
+ <xsl:copy-of select="."/>
11358
+ </xsl:for-each></text>
11359
+ </xsl:variable>
11360
+
11361
+ <!-- keep-together_within-line for: a/b, aaa/b, a/bbb, /b -->
11362
+ <xsl:variable name="regex_solidus_units">((\b((\S{1,3}\/\S+)|(\S+\/\S{1,3}))\b)|(\/\S{1,3})\b)</xsl:variable>
11363
+ <xsl:variable name="text3">
11364
+ <text><xsl:for-each select="xalan:nodeset($text2)/text/node()">
11365
+ <xsl:choose>
11366
+ <xsl:when test="self::text()">
11367
+ <xsl:variable name="text_units_" select="java:replaceAll(java:java.lang.String.new(.),$regex_solidus_units,concat($tag_keep-together_within-line_open,'$1',$tag_keep-together_within-line_close))"/>
11368
+ <xsl:variable name="text_units"><text><xsl:call-template name="replace_text_tags">
11369
+ <xsl:with-param name="tag_open" select="$tag_keep-together_within-line_open"/>
11370
+ <xsl:with-param name="tag_close" select="$tag_keep-together_within-line_close"/>
11371
+ <xsl:with-param name="text" select="$text_units_"/>
11372
+ </xsl:call-template></text></xsl:variable>
11373
+ <xsl:copy-of select="xalan:nodeset($text_units)/text/node()"/>
11374
+ </xsl:when>
11375
+ <xsl:otherwise><xsl:copy-of select="."/></xsl:otherwise> <!-- copy 'as-is' for <fo:inline keep-together.within-line="always" ... -->
11376
+ </xsl:choose>
11377
+ </xsl:for-each></text>
11378
+ </xsl:variable>
11379
+
11380
+ <xsl:choose>
11381
+ <xsl:when test="ancestor::*[local-name() = 'td' or local-name() = 'th']">
11382
+ <!-- keep-together_within-line for: a.b, aaa.b, a.bbb, .b in table's cell ONLY -->
11383
+ <xsl:variable name="regex_dots_units">((\b((\S{1,3}\.\S+)|(\S+\.\S{1,3}))\b)|(\.\S{1,3})\b)</xsl:variable>
11384
+ <xsl:for-each select="xalan:nodeset($text3)/text/node()">
11385
+ <xsl:choose>
11386
+ <xsl:when test="self::text()">
11387
+ <xsl:variable name="text_dots_" select="java:replaceAll(java:java.lang.String.new(.),$regex_dots_units,concat($tag_keep-together_within-line_open,'$1',$tag_keep-together_within-line_close))"/>
11388
+ <xsl:variable name="text_dots"><text><xsl:call-template name="replace_text_tags">
11389
+ <xsl:with-param name="tag_open" select="$tag_keep-together_within-line_open"/>
11390
+ <xsl:with-param name="tag_close" select="$tag_keep-together_within-line_close"/>
11391
+ <xsl:with-param name="text" select="$text_dots_"/>
11392
+ </xsl:call-template></text></xsl:variable>
11393
+ <xsl:copy-of select="xalan:nodeset($text_dots)/text/node()"/>
11394
+ </xsl:when>
11395
+ <xsl:otherwise><xsl:copy-of select="."/></xsl:otherwise> <!-- copy 'as-is' for <fo:inline keep-together.within-line="always" ... -->
11396
+ </xsl:choose>
11397
+ </xsl:for-each>
11398
+ </xsl:when>
11399
+ <xsl:otherwise><xsl:copy-of select="xalan:nodeset($text3)/text/node()"/></xsl:otherwise>
11400
+ </xsl:choose>
11401
+
11402
+ </xsl:template><xsl:template name="replace_text_tags">
11403
+ <xsl:param name="tag_open"/>
11404
+ <xsl:param name="tag_close"/>
11405
+ <xsl:param name="text"/>
11406
+ <xsl:choose>
11407
+ <xsl:when test="contains($text, $tag_open)">
11408
+ <xsl:value-of select="substring-before($text, $tag_open)"/>
11409
+ <xsl:variable name="text_after" select="substring-after($text, $tag_open)"/>
11410
+
11411
+ <xsl:element name="{substring-before(substring-after($tag_open, '###'),'###')}">
11412
+ <xsl:value-of select="substring-before($text_after, $tag_close)"/>
11413
+ </xsl:element>
11414
+
11415
+ <xsl:call-template name="replace_text_tags">
11416
+ <xsl:with-param name="tag_open" select="$tag_open"/>
11417
+ <xsl:with-param name="tag_close" select="$tag_close"/>
11418
+ <xsl:with-param name="text" select="substring-after($text_after, $tag_close)"/>
11419
+ </xsl:call-template>
11420
+ </xsl:when>
11421
+ <xsl:otherwise><xsl:value-of select="$text"/></xsl:otherwise>
11422
+ </xsl:choose>
11423
+ </xsl:template><xsl:template name="printEdition">
11424
+ <xsl:variable name="edition_i18n" select="normalize-space((//*[contains(local-name(), '-standard')])[1]/*[local-name() = 'bibdata']/*[local-name() = 'edition'][normalize-space(@language) != ''])"/>
11425
+ <xsl:text> </xsl:text>
11426
+ <xsl:choose>
11427
+ <xsl:when test="$edition_i18n != ''">
11428
+ <!-- Example: <edition language="fr">deuxième édition</edition> -->
11429
+ <xsl:call-template name="capitalize">
11430
+ <xsl:with-param name="str" select="$edition_i18n"/>
11431
+ </xsl:call-template>
11432
+ </xsl:when>
11433
+ <xsl:otherwise>
11434
+ <xsl:variable name="edition" select="normalize-space((//*[contains(local-name(), '-standard')])[1]/*[local-name() = 'bibdata']/*[local-name() = 'edition'])"/>
11435
+ <xsl:if test="$edition != ''"> <!-- Example: 1.3 -->
11436
+ <xsl:call-template name="capitalize">
11437
+ <xsl:with-param name="str">
11438
+ <xsl:call-template name="getLocalizedString">
11439
+ <xsl:with-param name="key">edition</xsl:with-param>
11440
+ </xsl:call-template>
11441
+ </xsl:with-param>
11442
+ </xsl:call-template>
11443
+ <xsl:text> </xsl:text>
11444
+ <xsl:value-of select="$edition"/>
11445
+ </xsl:if>
11446
+ </xsl:otherwise>
11447
+ </xsl:choose>
10306
11448
  </xsl:template><xsl:template name="convertDate">
10307
11449
  <xsl:param name="date"/>
10308
11450
  <xsl:param name="format" select="'short'"/>
@@ -10990,4 +12132,40 @@
10990
12132
  <xsl:value-of select="$value"/>
10991
12133
  </xsl:otherwise>
10992
12134
  </xsl:choose>
12135
+ </xsl:template><xsl:template match="*" mode="print_as_xml">
12136
+ <xsl:param name="level">0</xsl:param>
12137
+
12138
+ <fo:block margin-left="{2*$level}mm">
12139
+ <xsl:text>
12140
+ &lt;</xsl:text>
12141
+ <xsl:value-of select="local-name()"/>
12142
+ <xsl:for-each select="@*">
12143
+ <xsl:text> </xsl:text>
12144
+ <xsl:value-of select="local-name()"/>
12145
+ <xsl:text>="</xsl:text>
12146
+ <xsl:value-of select="."/>
12147
+ <xsl:text>"</xsl:text>
12148
+ </xsl:for-each>
12149
+ <xsl:text>&gt;</xsl:text>
12150
+
12151
+ <xsl:if test="not(*)">
12152
+ <fo:inline font-weight="bold"><xsl:value-of select="."/></fo:inline>
12153
+ <xsl:text>&lt;/</xsl:text>
12154
+ <xsl:value-of select="local-name()"/>
12155
+ <xsl:text>&gt;</xsl:text>
12156
+ </xsl:if>
12157
+ </fo:block>
12158
+
12159
+ <xsl:if test="*">
12160
+ <fo:block>
12161
+ <xsl:apply-templates mode="print_as_xml">
12162
+ <xsl:with-param name="level" select="$level + 1"/>
12163
+ </xsl:apply-templates>
12164
+ </fo:block>
12165
+ <fo:block margin-left="{2*$level}mm">
12166
+ <xsl:text>&lt;/</xsl:text>
12167
+ <xsl:value-of select="local-name()"/>
12168
+ <xsl:text>&gt;</xsl:text>
12169
+ </fo:block>
12170
+ </xsl:if>
10993
12171
  </xsl:template></xsl:stylesheet>