metanorma-mpfa 0.8.6 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -50,7 +50,13 @@
50
50
 
51
51
  <xsl:template match="/">
52
52
  <xsl:call-template name="namespaceCheck"/>
53
- <fo:root xsl:use-attribute-sets="root-style" xml:lang="{$lang}">
53
+ <fo:root xml:lang="{$lang}">
54
+ <xsl:variable name="root-style">
55
+ <root-style xsl:use-attribute-sets="root-style"/>
56
+ </xsl:variable>
57
+ <xsl:call-template name="insertRootStyle">
58
+ <xsl:with-param name="root-style" select="$root-style"/>
59
+ </xsl:call-template>
54
60
  <fo:layout-master-set>
55
61
 
56
62
  <!-- cover page -->
@@ -134,12 +140,19 @@
134
140
  <fo:block margin-bottom="12pt"> </fo:block>
135
141
  <fo:block-container text-align="center" border="0.5pt solid black" margin-bottom="12pt">
136
142
  <fo:block font-size="16pt" margin-bottom="12pt" padding-top="1mm">
137
- <xsl:value-of select="/mpfd:mpfd-standard/mpfd:bibdata/mpfd:edition"/>
138
- <xsl:text> </xsl:text>
139
- <xsl:call-template name="getTitle">
140
- <xsl:with-param name="name" select="'title-edition'"/>
141
- </xsl:call-template>
142
- <xsl:value-of select="$linebreak"/>
143
+ <xsl:variable name="edition" select="normalize-space(/mpfd:mpfd-standard/mpfd:bibdata/mpfd:edition[normalize-space(@language) = ''])"/>
144
+ <xsl:if test="$edition != ''">
145
+ <xsl:value-of select="$edition"/>
146
+ <xsl:text> </xsl:text>
147
+ <xsl:call-template name="capitalize">
148
+ <xsl:with-param name="str">
149
+ <xsl:call-template name="getLocalizedString">
150
+ <xsl:with-param name="key">edition</xsl:with-param>
151
+ </xsl:call-template>
152
+ </xsl:with-param>
153
+ </xsl:call-template>
154
+ <xsl:value-of select="$linebreak"/>
155
+ </xsl:if>
143
156
  <xsl:call-template name="convertDate">
144
157
  <xsl:with-param name="date" select="/mpfd:mpfd-standard/mpfd:bibdata/mpfd:version/mpfd:revision-date"/>
145
158
  <xsl:with-param name="format">ddMMyyyy</xsl:with-param>
@@ -570,7 +583,7 @@
570
583
  </xsl:template>
571
584
 
572
585
 
573
- <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">
586
+ <xsl:param name="svg_images"/><xsl:variable name="images" select="document($svg_images)"/><xsl:param name="basepath"/><xsl:param name="external_index"/><xsl:param name="syntax-highlight">false</xsl:param><xsl:param name="add_math_as_text">true</xsl:param><xsl:variable name="lang">
574
587
  <xsl:call-template name="getLang"/>
575
588
  </xsl:variable><xsl:variable name="pageWidth_">
576
589
  210
@@ -585,20 +598,7 @@
585
598
  </xsl:variable><xsl:variable name="marginTop" select="normalize-space($marginTop_)"/><xsl:variable name="marginBottom_">
586
599
  10
587
600
  </xsl:variable><xsl:variable name="marginBottom" select="normalize-space($marginBottom_)"/><xsl:variable name="titles_">
588
-
589
- <title-edition lang="en">
590
-
591
- <xsl:text>Edition </xsl:text>
592
-
593
- </title-edition>
594
601
 
595
- <title-edition lang="fr">
596
- <xsl:text>Édition </xsl:text>
597
- </title-edition>
598
-
599
- <title-edition lang="ru">
600
- <xsl:text>Издание </xsl:text>
601
- </title-edition>
602
602
 
603
603
  <!-- These titles of Table of contents renders different than determined in localized-strings -->
604
604
  <title-toc lang="en">
@@ -679,7 +679,7 @@
679
679
  </xsl:variable><xsl:variable name="bibdata">
680
680
  <xsl:copy-of select="//*[contains(local-name(), '-standard')]/*[local-name() = 'bibdata']"/>
681
681
  <xsl:copy-of select="//*[contains(local-name(), '-standard')]/*[local-name() = 'localized-strings']"/>
682
- </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">
682
+ </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">
683
683
  <xsl:param name="name"/>
684
684
  <xsl:param name="lang"/>
685
685
  <xsl:variable name="lang_">
@@ -722,7 +722,30 @@
722
722
 
723
723
 
724
724
 
725
- </xsl:attribute-set><xsl:attribute-set name="copyright-statement-style">
725
+ </xsl:attribute-set><xsl:template name="insertRootStyle">
726
+ <xsl:param name="root-style"/>
727
+ <xsl:variable name="root-style_" select="xalan:nodeset($root-style)"/>
728
+
729
+ <xsl:variable name="additional_fonts_">
730
+ <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']">
731
+ <xsl:value-of select="."/><xsl:if test="position() != last()">, </xsl:if>
732
+ </xsl:for-each>
733
+ </xsl:variable>
734
+ <xsl:variable name="additional_fonts" select="normalize-space($additional_fonts_)"/>
735
+
736
+ <xsl:for-each select="$root-style_/root-style/@*">
737
+ <xsl:choose>
738
+ <xsl:when test="local-name() = 'font-family' and $additional_fonts != ''">
739
+ <xsl:attribute name="{local-name()}">
740
+ <xsl:value-of select="."/>, <xsl:value-of select="$additional_fonts"/>
741
+ </xsl:attribute>
742
+ </xsl:when>
743
+ <xsl:otherwise>
744
+ <xsl:copy-of select="."/>
745
+ </xsl:otherwise>
746
+ </xsl:choose>
747
+ </xsl:for-each>
748
+ </xsl:template><xsl:attribute-set name="copyright-statement-style">
726
749
 
727
750
  </xsl:attribute-set><xsl:attribute-set name="copyright-statement-title-style">
728
751
 
@@ -779,7 +802,6 @@
779
802
 
780
803
 
781
804
  </xsl:attribute-set><xsl:attribute-set name="sourcecode-container-style">
782
- <xsl:attribute name="margin-left">0mm</xsl:attribute>
783
805
 
784
806
  </xsl:attribute-set><xsl:attribute-set name="sourcecode-style">
785
807
  <xsl:attribute name="white-space">pre</xsl:attribute>
@@ -855,6 +877,7 @@
855
877
 
856
878
 
857
879
 
880
+
858
881
  <xsl:attribute name="margin-left">12.5mm</xsl:attribute>
859
882
  <xsl:attribute name="margin-bottom">18pt</xsl:attribute>
860
883
 
@@ -1211,7 +1234,7 @@
1211
1234
 
1212
1235
 
1213
1236
 
1214
- </xsl:attribute-set><xsl:attribute-set name="termnote-name-style">
1237
+ </xsl:attribute-set><xsl:attribute-set name="termnote-name-style">
1215
1238
 
1216
1239
 
1217
1240
 
@@ -1898,10 +1921,41 @@
1898
1921
  <xsl:sort select="@displayorder" data-type="number"/>
1899
1922
  <xsl:apply-templates select="."/>
1900
1923
  </xsl:for-each>
1901
- </xsl:template><xsl:template match="text()">
1902
- <xsl:value-of select="."/>
1924
+ </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">
1925
+
1926
+ <xsl:variable name="regex_standard_reference">([A-Z]{2,}(/[A-Z]{2,})* \d+(-\d+)*(:\d{4})?)</xsl:variable>
1927
+ <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))"/>
1928
+ <xsl:call-template name="replace_fo_inline_tags">
1929
+ <xsl:with-param name="tag_open" select="$tag_fo_inline_keep-together_within-line_open"/>
1930
+ <xsl:with-param name="tag_close" select="$tag_fo_inline_keep-together_within-line_close"/>
1931
+ <xsl:with-param name="text" select="$text"/>
1932
+ </xsl:call-template>
1933
+
1934
+ </xsl:template><xsl:template name="replace_fo_inline_tags">
1935
+ <xsl:param name="tag_open"/>
1936
+ <xsl:param name="tag_close"/>
1937
+ <xsl:param name="text"/>
1938
+ <xsl:choose>
1939
+ <xsl:when test="contains($text, $tag_open)">
1940
+ <xsl:value-of select="substring-before($text, $tag_open)"/>
1941
+ <!-- <xsl:text disable-output-escaping="yes">&lt;fo:inline keep-together.within-line="always"&gt;</xsl:text> -->
1942
+ <xsl:variable name="text_after" select="substring-after($text, $tag_open)"/>
1943
+ <fo:inline keep-together.within-line="always">
1944
+ <xsl:value-of select="substring-before($text_after, $tag_close)"/>
1945
+ </fo:inline>
1946
+ <!-- <xsl:text disable-output-escaping="yes">&lt;/fo:inline&gt;</xsl:text> -->
1947
+ <xsl:call-template name="replace_fo_inline_tags">
1948
+ <xsl:with-param name="tag_open" select="$tag_open"/>
1949
+ <xsl:with-param name="tag_close" select="$tag_close"/>
1950
+ <xsl:with-param name="text" select="substring-after($text_after, $tag_close)"/>
1951
+ </xsl:call-template>
1952
+ </xsl:when>
1953
+ <xsl:otherwise><xsl:value-of select="$text"/></xsl:otherwise>
1954
+ </xsl:choose>
1903
1955
  </xsl:template><xsl:template match="*[local-name()='br']">
1904
1956
  <xsl:value-of select="$linebreak"/>
1957
+ </xsl:template><xsl:template match="*[local-name() = 'keep-together_within-line']">
1958
+ <fo:inline keep-together.within-line="always"><xsl:apply-templates/></fo:inline>
1905
1959
  </xsl:template><xsl:template match="*[local-name()='copyright-statement']">
1906
1960
  <fo:block xsl:use-attribute-sets="copyright-statement-style">
1907
1961
  <xsl:apply-templates/>
@@ -1967,8 +2021,23 @@
1967
2021
  </xsl:call-template>
1968
2022
 
1969
2023
  </xsl:template><xsl:template match="*[local-name()='td']//text() | *[local-name()='th']//text() | *[local-name()='dt']//text() | *[local-name()='dd']//text()" priority="1">
1970
- <!-- <xsl:call-template name="add-zero-spaces"/> -->
1971
- <xsl:call-template name="add-zero-spaces-java"/>
2024
+ <xsl:choose>
2025
+ <xsl:when test="parent::*[local-name() = 'keep-together_within-line']">
2026
+ <xsl:value-of select="."/>
2027
+ </xsl:when>
2028
+ <xsl:otherwise>
2029
+ <xsl:call-template name="addZeroWidthSpacesToTextNodes"/>
2030
+ </xsl:otherwise>
2031
+ </xsl:choose>
2032
+ </xsl:template><xsl:template name="addZeroWidthSpacesToTextNodes">
2033
+ <xsl:variable name="text"><text><xsl:call-template name="text"/></text></xsl:variable>
2034
+ <!-- <xsl:copy-of select="$text"/> -->
2035
+ <xsl:for-each select="xalan:nodeset($text)/text/node()">
2036
+ <xsl:choose>
2037
+ <xsl:when test="self::text()"><xsl:call-template name="add-zero-spaces-java"/></xsl:when>
2038
+ <xsl:otherwise><xsl:copy-of select="."/></xsl:otherwise> <!-- copy 'as-is' for <fo:inline keep-together.within-line="always" ... -->
2039
+ </xsl:choose>
2040
+ </xsl:for-each>
1972
2041
  </xsl:template><xsl:template match="*[local-name()='table']" name="table">
1973
2042
 
1974
2043
  <xsl:variable name="table-preamble">
@@ -2086,16 +2155,9 @@
2086
2155
  </xsl:for-each>
2087
2156
  </xsl:when>
2088
2157
  <xsl:otherwise>
2089
- <xsl:for-each select="xalan:nodeset($colwidths)//column">
2090
- <xsl:choose>
2091
- <xsl:when test=". = 1 or . = 0">
2092
- <fo:table-column column-width="proportional-column-width(2)"/>
2093
- </xsl:when>
2094
- <xsl:otherwise>
2095
- <fo:table-column column-width="proportional-column-width({.})"/>
2096
- </xsl:otherwise>
2097
- </xsl:choose>
2098
- </xsl:for-each>
2158
+ <xsl:call-template name="insertTableColumnWidth">
2159
+ <xsl:with-param name="colwidths" select="$colwidths"/>
2160
+ </xsl:call-template>
2099
2161
  </xsl:otherwise>
2100
2162
  </xsl:choose>
2101
2163
 
@@ -2259,6 +2321,7 @@
2259
2321
  <xsl:with-param name="text" select="$td_text"/>
2260
2322
  </xsl:call-template>
2261
2323
  </xsl:variable>
2324
+ <!-- <xsl:message>string_with_added_zerospaces=<xsl:value-of select="$string_with_added_zerospaces"/></xsl:message> -->
2262
2325
  <xsl:call-template name="tokenize">
2263
2326
  <!-- <xsl:with-param name="text" select="translate(td[$curr-col],'- —:', ' ')"/> -->
2264
2327
  <!-- 2009 thinspace -->
@@ -2271,6 +2334,7 @@
2271
2334
  <xsl:with-param name="words" select="xalan:nodeset($words)"/>
2272
2335
  </xsl:call-template>
2273
2336
  </xsl:variable>
2337
+ <!-- <xsl:message>max_length=<xsl:value-of select="$max_length"/></xsl:message> -->
2274
2338
  <width>
2275
2339
  <xsl:variable name="divider">
2276
2340
  <xsl:choose>
@@ -2303,6 +2367,10 @@
2303
2367
  <xsl:with-param name="table" select="$table"/>
2304
2368
  </xsl:call-template>
2305
2369
  </xsl:if>
2370
+ </xsl:template><xsl:template match="*[@keep-together.within-line]/text()" priority="2" mode="td_text">
2371
+ <!-- <xsl:message>DEBUG t1=<xsl:value-of select="."/></xsl:message>
2372
+ <xsl:message>DEBUG t2=<xsl:value-of select="java:replaceAll(java:java.lang.String.new(.),'.','X')"/></xsl:message> -->
2373
+ <xsl:value-of select="java:replaceAll(java:java.lang.String.new(.),'.','X')"/>
2306
2374
  </xsl:template><xsl:template match="text()" mode="td_text">
2307
2375
  <xsl:value-of select="translate(., $zero_width_space, ' ')"/><xsl:text> </xsl:text>
2308
2376
  </xsl:template><xsl:template match="*[local-name()='termsource']" mode="td_text">
@@ -2404,16 +2472,9 @@
2404
2472
  </xsl:for-each>
2405
2473
  </xsl:when>
2406
2474
  <xsl:otherwise>
2407
- <xsl:for-each select="xalan:nodeset($colwidths)//column">
2408
- <xsl:choose>
2409
- <xsl:when test=". = 1 or . = 0">
2410
- <fo:table-column column-width="proportional-column-width(2)"/>
2411
- </xsl:when>
2412
- <xsl:otherwise>
2413
- <fo:table-column column-width="proportional-column-width({.})"/>
2414
- </xsl:otherwise>
2415
- </xsl:choose>
2416
- </xsl:for-each>
2475
+ <xsl:call-template name="insertTableColumnWidth">
2476
+ <xsl:with-param name="colwidths" select="$colwidths"/>
2477
+ </xsl:call-template>
2417
2478
  </xsl:otherwise>
2418
2479
  </xsl:choose>
2419
2480
 
@@ -2954,8 +3015,10 @@
2954
3015
  <!-- and (not(../@class) or ../@class !='pseudocode') -->
2955
3016
  </xsl:variable>
2956
3017
 
3018
+ <xsl:variable name="onlyOneComponent" select="normalize-space($parent = 'formula' and count(*[local-name()='dt']) = 1)"/>
3019
+
2957
3020
  <xsl:choose>
2958
- <xsl:when test="$parent = 'formula' and count(*[local-name()='dt']) = 1"> <!-- only one component -->
3021
+ <xsl:when test="$onlyOneComponent = 'true'"> <!-- only one component -->
2959
3022
 
2960
3023
  <fo:block margin-bottom="12pt" text-align="left">
2961
3024
 
@@ -2970,7 +3033,7 @@
2970
3033
  <xsl:apply-templates select="*[local-name()='dd']/*" mode="inline"/>
2971
3034
  </fo:block>
2972
3035
 
2973
- </xsl:when>
3036
+ </xsl:when> <!-- END: only one component -->
2974
3037
  <xsl:when test="$parent = 'formula'"> <!-- a few components -->
2975
3038
  <fo:block margin-bottom="12pt" text-align="left">
2976
3039
 
@@ -2984,8 +3047,8 @@
2984
3047
  </xsl:variable>
2985
3048
  <xsl:value-of select="$title-where"/>
2986
3049
  </fo:block>
2987
- </xsl:when>
2988
- <xsl:when test="$parent = 'figure' and (not(../@class) or ../@class !='pseudocode')">
3050
+ </xsl:when> <!-- END: a few components -->
3051
+ <xsl:when test="$parent = 'figure' and (not(../@class) or ../@class !='pseudocode')"> <!-- definition list in a figure -->
2989
3052
  <fo:block font-weight="bold" text-align="left" margin-bottom="12pt" keep-with-next="always">
2990
3053
 
2991
3054
 
@@ -2998,11 +3061,11 @@
2998
3061
  </xsl:variable>
2999
3062
  <xsl:value-of select="$title-key"/>
3000
3063
  </fo:block>
3001
- </xsl:when>
3064
+ </xsl:when> <!-- END: definition list in a figure -->
3002
3065
  </xsl:choose>
3003
3066
 
3004
3067
  <!-- a few components -->
3005
- <xsl:if test="not($parent = 'formula' and count(*[local-name()='dt']) = 1)">
3068
+ <xsl:if test="$onlyOneComponent = 'false'">
3006
3069
  <fo:block>
3007
3070
 
3008
3071
 
@@ -3041,21 +3104,28 @@
3041
3104
  <xsl:apply-templates mode="dl"/>
3042
3105
  </tbody>
3043
3106
  </xsl:variable>
3044
- <!-- html-table<xsl:copy-of select="$html-table"/> -->
3107
+ <!-- DEBUG: html-table<xsl:copy-of select="$html-table"/> -->
3045
3108
  <xsl:variable name="colwidths">
3046
3109
  <xsl:call-template name="calculate-column-widths">
3047
3110
  <xsl:with-param name="cols-count" select="2"/>
3048
3111
  <xsl:with-param name="table" select="$html-table"/>
3049
3112
  </xsl:call-template>
3050
3113
  </xsl:variable>
3051
- <!-- colwidths=<xsl:copy-of select="$colwidths"/> -->
3114
+ <!-- DEBUG: colwidths=<xsl:copy-of select="$colwidths"/> -->
3052
3115
  <xsl:variable name="maxlength_dt">
3053
3116
  <xsl:call-template name="getMaxLength_dt"/>
3054
3117
  </xsl:variable>
3118
+ <xsl:variable name="isContainsKeepTogetherTag_">
3119
+ false
3120
+ </xsl:variable>
3121
+ <xsl:variable name="isContainsKeepTogetherTag" select="normalize-space($isContainsKeepTogetherTag_)"/>
3122
+ <!-- isContainsExpressReference=<xsl:value-of select="$isContainsExpressReference"/> -->
3055
3123
  <xsl:call-template name="setColumnWidth_dl">
3056
3124
  <xsl:with-param name="colwidths" select="$colwidths"/>
3057
3125
  <xsl:with-param name="maxlength_dt" select="$maxlength_dt"/>
3126
+ <xsl:with-param name="isContainsKeepTogetherTag" select="$isContainsKeepTogetherTag"/>
3058
3127
  </xsl:call-template>
3128
+
3059
3129
  <fo:table-body>
3060
3130
  <xsl:apply-templates>
3061
3131
  <xsl:with-param name="key_iso" select="normalize-space($key_iso)"/>
@@ -3064,12 +3134,13 @@
3064
3134
  </fo:table>
3065
3135
  </fo:block>
3066
3136
  </fo:block>
3067
- </xsl:if>
3137
+ </xsl:if> <!-- END: a few components -->
3068
3138
  </fo:block-container>
3069
3139
  </fo:block-container>
3070
3140
  </xsl:template><xsl:template name="setColumnWidth_dl">
3071
3141
  <xsl:param name="colwidths"/>
3072
3142
  <xsl:param name="maxlength_dt"/>
3143
+ <xsl:param name="isContainsKeepTogetherTag"/>
3073
3144
  <xsl:choose>
3074
3145
  <xsl:when test="ancestor::*[local-name()='dl']"><!-- second level, i.e. inlined table -->
3075
3146
  <fo:table-column column-width="50%"/>
@@ -3077,6 +3148,11 @@
3077
3148
  </xsl:when>
3078
3149
  <xsl:otherwise>
3079
3150
  <xsl:choose>
3151
+ <xsl:when test="$isContainsKeepTogetherTag">
3152
+ <xsl:call-template name="insertTableColumnWidth">
3153
+ <xsl:with-param name="colwidths" select="$colwidths"/>
3154
+ </xsl:call-template>
3155
+ </xsl:when>
3080
3156
  <!-- to set width check most wide chars like `W` -->
3081
3157
  <xsl:when test="normalize-space($maxlength_dt) != '' and number($maxlength_dt) &lt;= 2"> <!-- if dt contains short text like t90, a, etc -->
3082
3158
  <fo:table-column column-width="7%"/>
@@ -3107,20 +3183,25 @@
3107
3183
  <fo:table-column column-width="60%"/>
3108
3184
  </xsl:when>
3109
3185
  <xsl:otherwise>
3110
- <xsl:for-each select="xalan:nodeset($colwidths)//column">
3111
- <xsl:choose>
3112
- <xsl:when test=". = 1 or . = 0">
3113
- <fo:table-column column-width="proportional-column-width(2)"/>
3114
- </xsl:when>
3115
- <xsl:otherwise>
3116
- <fo:table-column column-width="proportional-column-width({.})"/>
3117
- </xsl:otherwise>
3118
- </xsl:choose>
3119
- </xsl:for-each>
3186
+ <xsl:call-template name="insertTableColumnWidth">
3187
+ <xsl:with-param name="colwidths" select="$colwidths"/>
3188
+ </xsl:call-template>
3120
3189
  </xsl:otherwise>
3121
3190
  </xsl:choose>
3122
3191
  </xsl:otherwise>
3123
3192
  </xsl:choose>
3193
+ </xsl:template><xsl:template name="insertTableColumnWidth">
3194
+ <xsl:param name="colwidths"/>
3195
+ <xsl:for-each select="xalan:nodeset($colwidths)//column">
3196
+ <xsl:choose>
3197
+ <xsl:when test=". = 1 or . = 0">
3198
+ <fo:table-column column-width="proportional-column-width(2)"/>
3199
+ </xsl:when>
3200
+ <xsl:otherwise>
3201
+ <fo:table-column column-width="proportional-column-width({.})"/>
3202
+ </xsl:otherwise>
3203
+ </xsl:choose>
3204
+ </xsl:for-each>
3124
3205
  </xsl:template><xsl:template name="getMaxLength_dt">
3125
3206
  <xsl:variable name="lengths">
3126
3207
  <xsl:for-each select="*[local-name()='dt']">
@@ -3144,7 +3225,6 @@
3144
3225
  <xsl:value-of select="$maxLength"/>
3145
3226
  </xsl:template><xsl:template match="*[local-name()='dl']/*[local-name()='note']" priority="2">
3146
3227
  <xsl:param name="key_iso"/>
3147
-
3148
3228
  <!-- <tr>
3149
3229
  <td>NOTE</td>
3150
3230
  <td>
@@ -3152,18 +3232,30 @@
3152
3232
  </td>
3153
3233
  </tr>
3154
3234
  -->
3155
- <fo:table-row>
3235
+ <!-- OLD Variant -->
3236
+ <!-- <fo:table-row>
3156
3237
  <fo:table-cell>
3157
3238
  <fo:block margin-top="6pt">
3158
3239
  <xsl:if test="normalize-space($key_iso) = 'true'">
3159
3240
  <xsl:attribute name="margin-top">0</xsl:attribute>
3160
3241
  </xsl:if>
3161
- <xsl:apply-templates select="*[local-name() = 'name']"/>
3242
+ <xsl:apply-templates select="*[local-name() = 'name']" />
3162
3243
  </fo:block>
3163
3244
  </fo:table-cell>
3164
3245
  <fo:table-cell>
3165
3246
  <fo:block>
3166
- <xsl:apply-templates select="node()[not(local-name() = 'name')]"/>
3247
+ <xsl:apply-templates select="node()[not(local-name() = 'name')]" />
3248
+ </fo:block>
3249
+ </fo:table-cell>
3250
+ </fo:table-row> -->
3251
+ <!-- <tr>
3252
+ <td number-columns-spanned="2">NOTE <xsl:apply-templates /> </td>
3253
+ </tr>
3254
+ -->
3255
+ <fo:table-row>
3256
+ <fo:table-cell number-columns-spanned="2">
3257
+ <fo:block>
3258
+ <xsl:call-template name="note"/>
3167
3259
  </fo:block>
3168
3260
  </fo:table-cell>
3169
3261
  </fo:table-row>
@@ -3265,13 +3357,15 @@
3265
3357
  <xsl:choose>
3266
3358
  <xsl:when test="$font-size = 'inherit'"><xsl:value-of select="$font-size"/></xsl:when>
3267
3359
  <xsl:when test="contains($font-size, '%')"><xsl:value-of select="$font-size"/></xsl:when>
3268
- <xsl:when test="ancestor::*[local-name()='note']"><xsl:value-of select="$font-size * 0.91"/>pt</xsl:when>
3360
+ <xsl:when test="ancestor::*[local-name()='note'] or ancestor::*[local-name()='example']"><xsl:value-of select="$font-size * 0.91"/>pt</xsl:when>
3269
3361
  <xsl:otherwise><xsl:value-of select="$font-size"/>pt</xsl:otherwise>
3270
3362
  </xsl:choose>
3271
3363
  </xsl:attribute>
3272
3364
  </xsl:if>
3273
3365
  <xsl:apply-templates/>
3274
3366
  </fo:inline>
3367
+ </xsl:template><xsl:template match="*[local-name()='tt']/text()" priority="2">
3368
+ <xsl:call-template name="add_spaces_to_sourcecode"/>
3275
3369
  </xsl:template><xsl:template match="*[local-name()='underline']">
3276
3370
  <fo:inline text-decoration="underline">
3277
3371
  <xsl:apply-templates/>
@@ -3419,41 +3513,50 @@
3419
3513
  <fo:block break-after="page"/>
3420
3514
  <fo:block> </fo:block>
3421
3515
  <fo:block break-after="page"/>
3516
+ </xsl:template><xsl:template match="*[local-name() = 'span']">
3517
+ <xsl:apply-templates/>
3422
3518
  </xsl:template><xsl:template name="tokenize">
3423
3519
  <xsl:param name="text"/>
3424
3520
  <xsl:param name="separator" select="' '"/>
3425
3521
  <xsl:choose>
3426
3522
  <xsl:when test="not(contains($text, $separator))">
3427
3523
  <word>
3428
- <xsl:variable name="str_no_en_chars" select="normalize-space(translate($text, $en_chars, ''))"/>
3429
- <xsl:variable name="len_str_no_en_chars" select="string-length($str_no_en_chars)"/>
3430
3524
  <xsl:variable name="len_str_tmp" select="string-length(normalize-space($text))"/>
3431
- <xsl:variable name="len_str">
3432
- <xsl:choose>
3433
- <xsl:when test="normalize-space(translate($text, $upper, '')) = ''"> <!-- english word in CAPITAL letters -->
3434
- <xsl:value-of select="$len_str_tmp * 1.5"/>
3435
- </xsl:when>
3436
- <xsl:otherwise>
3437
- <xsl:value-of select="$len_str_tmp"/>
3438
- </xsl:otherwise>
3439
- </xsl:choose>
3440
- </xsl:variable>
3441
-
3442
- <!-- <xsl:if test="$len_str_no_en_chars div $len_str &gt; 0.8">
3443
- <xsl:message>
3444
- div=<xsl:value-of select="$len_str_no_en_chars div $len_str"/>
3445
- len_str=<xsl:value-of select="$len_str"/>
3446
- len_str_no_en_chars=<xsl:value-of select="$len_str_no_en_chars"/>
3447
- </xsl:message>
3448
- </xsl:if> -->
3449
- <!-- <len_str_no_en_chars><xsl:value-of select="$len_str_no_en_chars"/></len_str_no_en_chars>
3450
- <len_str><xsl:value-of select="$len_str"/></len_str> -->
3451
3525
  <xsl:choose>
3452
- <xsl:when test="$len_str_no_en_chars div $len_str &gt; 0.8"> <!-- means non-english string -->
3453
- <xsl:value-of select="$len_str - $len_str_no_en_chars"/>
3526
+ <xsl:when test="normalize-space(translate($text, 'X', '')) = ''"> <!-- special case for keep-together.within-line -->
3527
+ <xsl:value-of select="$len_str_tmp"/>
3454
3528
  </xsl:when>
3455
3529
  <xsl:otherwise>
3456
- <xsl:value-of select="$len_str"/>
3530
+ <xsl:variable name="str_no_en_chars" select="normalize-space(translate($text, $en_chars, ''))"/>
3531
+ <xsl:variable name="len_str_no_en_chars" select="string-length($str_no_en_chars)"/>
3532
+ <xsl:variable name="len_str">
3533
+ <xsl:choose>
3534
+ <xsl:when test="normalize-space(translate($text, $upper, '')) = ''"> <!-- english word in CAPITAL letters -->
3535
+ <xsl:value-of select="$len_str_tmp * 1.5"/>
3536
+ </xsl:when>
3537
+ <xsl:otherwise>
3538
+ <xsl:value-of select="$len_str_tmp"/>
3539
+ </xsl:otherwise>
3540
+ </xsl:choose>
3541
+ </xsl:variable>
3542
+
3543
+ <!-- <xsl:if test="$len_str_no_en_chars div $len_str &gt; 0.8">
3544
+ <xsl:message>
3545
+ div=<xsl:value-of select="$len_str_no_en_chars div $len_str"/>
3546
+ len_str=<xsl:value-of select="$len_str"/>
3547
+ len_str_no_en_chars=<xsl:value-of select="$len_str_no_en_chars"/>
3548
+ </xsl:message>
3549
+ </xsl:if> -->
3550
+ <!-- <len_str_no_en_chars><xsl:value-of select="$len_str_no_en_chars"/></len_str_no_en_chars>
3551
+ <len_str><xsl:value-of select="$len_str"/></len_str> -->
3552
+ <xsl:choose>
3553
+ <xsl:when test="$len_str_no_en_chars div $len_str &gt; 0.8"> <!-- means non-english string -->
3554
+ <xsl:value-of select="$len_str - $len_str_no_en_chars"/>
3555
+ </xsl:when>
3556
+ <xsl:otherwise>
3557
+ <xsl:value-of select="$len_str"/>
3558
+ </xsl:otherwise>
3559
+ </xsl:choose>
3457
3560
  </xsl:otherwise>
3458
3561
  </xsl:choose>
3459
3562
  </word>
@@ -3539,24 +3642,28 @@
3539
3642
  </xsl:template><xsl:template name="add-zero-spaces-equal">
3540
3643
  <xsl:param name="text" select="."/>
3541
3644
  <xsl:variable name="zero-space-after-equals">==========</xsl:variable>
3645
+ <xsl:variable name="regex_zero-space-after-equals">(==========)</xsl:variable>
3542
3646
  <xsl:variable name="zero-space-after-equal">=</xsl:variable>
3647
+ <xsl:variable name="regex_zero-space-after-equal">(=)</xsl:variable>
3543
3648
  <xsl:variable name="zero-space">​</xsl:variable>
3544
3649
  <xsl:choose>
3545
3650
  <xsl:when test="contains($text, $zero-space-after-equals)">
3546
- <xsl:value-of select="substring-before($text, $zero-space-after-equals)"/>
3651
+ <!-- <xsl:value-of select="substring-before($text, $zero-space-after-equals)"/>
3547
3652
  <xsl:value-of select="$zero-space-after-equals"/>
3548
3653
  <xsl:value-of select="$zero-space"/>
3549
3654
  <xsl:call-template name="add-zero-spaces-equal">
3550
3655
  <xsl:with-param name="text" select="substring-after($text, $zero-space-after-equals)"/>
3551
- </xsl:call-template>
3656
+ </xsl:call-template> -->
3657
+ <xsl:value-of select="java:replaceAll(java:java.lang.String.new(.),$regex_zero-space-after-equals,concat('$1',$zero_width_space))"/>
3552
3658
  </xsl:when>
3553
3659
  <xsl:when test="contains($text, $zero-space-after-equal)">
3554
- <xsl:value-of select="substring-before($text, $zero-space-after-equal)"/>
3660
+ <!-- <xsl:value-of select="substring-before($text, $zero-space-after-equal)"/>
3555
3661
  <xsl:value-of select="$zero-space-after-equal"/>
3556
3662
  <xsl:value-of select="$zero-space"/>
3557
3663
  <xsl:call-template name="add-zero-spaces-equal">
3558
3664
  <xsl:with-param name="text" select="substring-after($text, $zero-space-after-equal)"/>
3559
- </xsl:call-template>
3665
+ </xsl:call-template> -->
3666
+ <xsl:value-of select="java:replaceAll(java:java.lang.String.new(.),$regex_zero-space-after-equal,concat('$1',$zero_width_space))"/>
3560
3667
  </xsl:when>
3561
3668
  <xsl:otherwise>
3562
3669
  <xsl:value-of select="$text"/>
@@ -3724,6 +3831,9 @@
3724
3831
  <xsl:variable name="isDeleted" select="@deleted"/>
3725
3832
 
3726
3833
  <fo:inline xsl:use-attribute-sets="mathml-style">
3834
+
3835
+
3836
+
3727
3837
 
3728
3838
 
3729
3839
  <xsl:call-template name="setTrackChangesStyles">
@@ -3731,48 +3841,80 @@
3731
3841
  <xsl:with-param name="isDeleted" select="$isDeleted"/>
3732
3842
  </xsl:call-template>
3733
3843
 
3844
+ <xsl:if test="$add_math_as_text = 'true'">
3845
+ <!-- insert helper tag -->
3846
+ <!-- set unique font-size (fiction) -->
3847
+ <xsl:variable name="font-size_sfx"><xsl:number level="any"/></xsl:variable>
3848
+ <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 -->
3849
+ </xsl:if>
3734
3850
 
3735
-
3736
- <xsl:variable name="mathml">
3737
- <xsl:apply-templates select="." mode="mathml"/>
3851
+ <xsl:variable name="mathml_content">
3852
+ <xsl:apply-templates select="." mode="mathml_actual_text"/>
3738
3853
  </xsl:variable>
3739
- <fo:instream-foreign-object fox:alt-text="Math">
3740
3854
 
3855
+
3856
+ <xsl:call-template name="mathml_instream_object">
3857
+ <xsl:with-param name="mathml_content" select="$mathml_content"/>
3858
+ </xsl:call-template>
3741
3859
 
3742
-
3743
- <xsl:variable name="comment_text_following" select="following-sibling::node()[1][self::comment()]"/>
3744
- <xsl:variable name="comment_text_">
3745
- <xsl:choose>
3746
- <xsl:when test="normalize-space($comment_text_following) != ''">
3747
- <xsl:value-of select="$comment_text_following"/>
3748
- </xsl:when>
3749
- <xsl:otherwise>
3750
- <xsl:value-of select="normalize-space(translate(.,' ⁢',' '))"/>
3751
- </xsl:otherwise>
3752
- </xsl:choose>
3753
- </xsl:variable>
3754
- <xsl:variable name="comment_text" select="java:org.metanorma.fop.Util.unescape($comment_text_)"/>
3755
-
3756
- <xsl:if test="normalize-space($comment_text) != ''">
3757
- <!-- put Mathin Alternate Text -->
3758
- <xsl:attribute name="fox:alt-text">
3759
- <xsl:value-of select="java:org.metanorma.fop.Util.unescape($comment_text)"/>
3760
- </xsl:attribute>
3761
- </xsl:if>
3762
-
3763
- <xsl:variable name="mathml_content">
3764
- <xsl:apply-templates select="." mode="mathml_actual_text"/>
3765
- </xsl:variable>
3766
- <!-- put MathML in Actual Text -->
3767
- <xsl:attribute name="fox:actual-text">
3768
- <xsl:value-of select="$mathml_content"/>
3769
- </xsl:attribute>
3770
-
3771
-
3772
-
3773
- <xsl:copy-of select="xalan:nodeset($mathml)"/>
3774
- </fo:instream-foreign-object>
3860
+
3775
3861
  </fo:inline>
3862
+ </xsl:template><xsl:template name="getMathml_comment_text">
3863
+ <xsl:variable name="comment_text_following" select="following-sibling::node()[1][self::comment()]"/>
3864
+ <xsl:variable name="comment_text_">
3865
+ <xsl:choose>
3866
+ <xsl:when test="normalize-space($comment_text_following) != ''">
3867
+ <xsl:value-of select="$comment_text_following"/>
3868
+ </xsl:when>
3869
+ <xsl:otherwise>
3870
+ <xsl:value-of select="normalize-space(translate(.,' ⁢',' '))"/>
3871
+ </xsl:otherwise>
3872
+ </xsl:choose>
3873
+ </xsl:variable>
3874
+ <xsl:variable name="comment_text_2" select="java:org.metanorma.fop.Util.unescape($comment_text_)"/>
3875
+ <xsl:variable name="comment_text" select="java:trim(java:java.lang.String.new($comment_text_2))"/>
3876
+ <xsl:value-of select="$comment_text"/>
3877
+ </xsl:template><xsl:template name="mathml_instream_object">
3878
+ <xsl:param name="comment_text"/>
3879
+ <xsl:param name="mathml_content"/>
3880
+
3881
+ <xsl:variable name="comment_text_">
3882
+ <xsl:choose>
3883
+ <xsl:when test="normalize-space($comment_text) != ''"><xsl:value-of select="$comment_text"/></xsl:when>
3884
+ <xsl:otherwise><xsl:call-template name="getMathml_comment_text"/></xsl:otherwise>
3885
+ </xsl:choose>
3886
+ </xsl:variable>
3887
+
3888
+ <xsl:variable name="mathml">
3889
+ <xsl:apply-templates select="." mode="mathml"/>
3890
+ </xsl:variable>
3891
+
3892
+ <fo:instream-foreign-object fox:alt-text="Math">
3893
+
3894
+
3895
+
3896
+
3897
+
3898
+
3899
+
3900
+ <!-- put MathML in Actual Text -->
3901
+ <!-- DEBUG: mathml_content=<xsl:value-of select="$mathml_content"/> -->
3902
+ <xsl:attribute name="fox:actual-text">
3903
+ <xsl:value-of select="$mathml_content"/>
3904
+ </xsl:attribute>
3905
+
3906
+ <!-- <xsl:if test="$add_math_as_text = 'true'"> -->
3907
+ <xsl:if test="normalize-space($comment_text_) != ''">
3908
+ <!-- put Mathin Alternate Text -->
3909
+ <xsl:attribute name="fox:alt-text">
3910
+ <xsl:value-of select="$comment_text_"/>
3911
+ </xsl:attribute>
3912
+ </xsl:if>
3913
+ <!-- </xsl:if> -->
3914
+
3915
+ <xsl:copy-of select="xalan:nodeset($mathml)"/>
3916
+
3917
+ </fo:instream-foreign-object>
3776
3918
  </xsl:template><xsl:template match="mathml:*" mode="mathml_actual_text">
3777
3919
  <!-- <xsl:text>a+b</xsl:text> -->
3778
3920
  <xsl:text>&lt;</xsl:text>
@@ -3803,7 +3945,9 @@
3803
3945
  <!-- replace start and end spaces to non-break space -->
3804
3946
  <xsl:value-of select="java:replaceAll(java:java.lang.String.new(.),'(^ )|( $)',' ')"/>
3805
3947
  </xsl:copy>
3806
- </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">
3948
+ </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">
3949
+ <xsl:value-of select="."/><xsl:value-of select="$zero_width_space"/>
3950
+ </xsl:template><xsl:template match="*[local-name()='localityStack']"/><xsl:template match="*[local-name()='link']" name="link">
3807
3951
  <xsl:variable name="target">
3808
3952
  <xsl:choose>
3809
3953
  <xsl:when test="@updatetype = 'true'">
@@ -4032,7 +4176,12 @@
4032
4176
 
4033
4177
  <fo:inline xsl:use-attribute-sets="termnote-name-style">
4034
4178
 
4179
+ <xsl:if test="not(*[local-name() = 'name']/following-sibling::node()[1][self::text()][normalize-space()=''])">
4180
+ <xsl:attribute name="padding-right">1mm</xsl:attribute>
4181
+ </xsl:if>
4182
+
4035
4183
 
4184
+
4036
4185
 
4037
4186
  <!-- if 'p' contains all text in 'add' first and last elements in first p are 'add' -->
4038
4187
  <!-- <xsl:if test="*[not(local-name()='name')][1][node()[normalize-space() != ''][1][local-name() = 'add'] and node()[normalize-space() != ''][last()][local-name() = 'add']]"> -->
@@ -4389,18 +4538,33 @@
4389
4538
  </xsl:template><xsl:template match="*[local-name() = 'svg'][not(@width and @height)]" mode="svg_update">
4390
4539
  <xsl:copy>
4391
4540
  <xsl:apply-templates select="@*" mode="svg_update"/>
4392
- <xsl:variable name="viewbox">
4541
+ <xsl:variable name="viewbox_">
4393
4542
  <xsl:call-template name="split">
4394
4543
  <xsl:with-param name="pText" select="@viewBox"/>
4395
4544
  <xsl:with-param name="sep" select="' '"/>
4396
4545
  </xsl:call-template>
4397
4546
  </xsl:variable>
4547
+ <xsl:variable name="viewbox" select="xalan:nodeset($viewbox_)"/>
4548
+ <xsl:variable name="width" select="normalize-space($viewbox//item[3])"/>
4549
+ <xsl:variable name="height" select="normalize-space($viewbox//item[4])"/>
4550
+
4398
4551
  <xsl:attribute name="width">
4399
- <xsl:value-of select="round(xalan:nodeset($viewbox)//item[3])"/>
4552
+ <xsl:choose>
4553
+ <xsl:when test="$width != ''">
4554
+ <xsl:value-of select="round($width)"/>
4555
+ </xsl:when>
4556
+ <xsl:otherwise>400</xsl:otherwise> <!-- default width -->
4557
+ </xsl:choose>
4400
4558
  </xsl:attribute>
4401
4559
  <xsl:attribute name="height">
4402
- <xsl:value-of select="round(xalan:nodeset($viewbox)//item[4])"/>
4560
+ <xsl:choose>
4561
+ <xsl:when test="$height != ''">
4562
+ <xsl:value-of select="round($height)"/>
4563
+ </xsl:when>
4564
+ <xsl:otherwise>400</xsl:otherwise> <!-- default height -->
4565
+ </xsl:choose>
4403
4566
  </xsl:attribute>
4567
+
4404
4568
  <xsl:apply-templates mode="svg_update"/>
4405
4569
  </xsl:copy>
4406
4570
  </xsl:template><xsl:template match="*[local-name() = 'figure']/*[local-name() = 'image'][*[local-name() = 'svg']]" priority="3">
@@ -4595,7 +4759,11 @@
4595
4759
  <xsl:apply-templates mode="bookmarks"/>
4596
4760
  </xsl:template><xsl:template match="*[local-name() = 'title' or local-name() = 'name']//*[local-name() = 'stem']" mode="contents">
4597
4761
  <xsl:apply-templates select="."/>
4598
- </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">
4762
+ </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">
4763
+ <xsl:apply-templates mode="contents"/>
4764
+ </xsl:template><xsl:template match="*[local-name() = 'stem']" mode="bookmarks">
4765
+ <xsl:apply-templates mode="bookmarks"/>
4766
+ </xsl:template><xsl:template match="*[local-name() = 'span']" mode="bookmarks">
4599
4767
  <xsl:apply-templates mode="bookmarks"/>
4600
4768
  </xsl:template><xsl:template name="addBookmarks">
4601
4769
  <xsl:param name="contents"/>
@@ -4877,7 +5045,9 @@
4877
5045
  <xsl:apply-templates/>
4878
5046
  </xsl:otherwise>
4879
5047
  </xsl:choose>
4880
- </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">
5048
+ </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">
5049
+ <xsl:value-of select="."/>
5050
+ </xsl:template><xsl:template match="*[local-name() = 'tab']" mode="contents_item">
4881
5051
  <xsl:text> </xsl:text>
4882
5052
  </xsl:template><xsl:template match="*[local-name() = 'strong']" mode="contents_item">
4883
5053
  <xsl:copy>
@@ -4908,9 +5078,22 @@
4908
5078
  </xsl:when>
4909
5079
  <xsl:otherwise><xsl:apply-templates mode="contents_item"/></xsl:otherwise>
4910
5080
  </xsl:choose>
5081
+ </xsl:template><xsl:template match="text()" mode="contents_item">
5082
+ <xsl:call-template name="keep_together_standard_number"/>
5083
+ </xsl:template><xsl:template match="*[local-name() = 'span']" mode="contents_item">
5084
+ <xsl:apply-templates mode="contents_item"/>
4911
5085
  </xsl:template><xsl:template match="*[local-name()='sourcecode']" name="sourcecode">
4912
5086
 
4913
5087
  <fo:block-container xsl:use-attribute-sets="sourcecode-container-style">
5088
+
5089
+ <xsl:if test="not(ancestor::*[local-name() = 'li']) or ancestor::*[local-name() = 'example']">
5090
+ <xsl:attribute name="margin-left">0mm</xsl:attribute>
5091
+ </xsl:if>
5092
+
5093
+ <xsl:if test="ancestor::*[local-name() = 'example']">
5094
+ <xsl:attribute name="margin-right">0mm</xsl:attribute>
5095
+ </xsl:if>
5096
+
4914
5097
  <xsl:copy-of select="@id"/>
4915
5098
 
4916
5099
  <xsl:if test="parent::*[local-name() = 'note']">
@@ -5010,17 +5193,15 @@
5010
5193
 
5011
5194
  <!-- split text by zero-width space -->
5012
5195
  <xsl:variable name="text_step4">
5013
- <xsl:call-template name="split">
5196
+ <xsl:call-template name="split_for_interspers">
5014
5197
  <xsl:with-param name="pText" select="$text_step3"/>
5015
5198
  <xsl:with-param name="sep" select="$zero_width_space"/>
5016
- <xsl:with-param name="normalize-space">false</xsl:with-param>
5017
- <xsl:with-param name="keep_sep">true</xsl:with-param>
5018
5199
  </xsl:call-template>
5019
5200
  </xsl:variable>
5020
5201
 
5021
- <xsl:for-each select="xalan:nodeset($text_step4)/item">
5202
+ <xsl:for-each select="xalan:nodeset($text_step4)/node()">
5022
5203
  <xsl:choose>
5023
- <xsl:when test="string-length() &gt; 30"> <!-- word with length more than 30 will be interspersed with zero-width space -->
5204
+ <xsl:when test="local-name() = 'interspers'"> <!-- word with length more than 30 will be interspersed with zero-width space -->
5024
5205
  <xsl:call-template name="interspers">
5025
5206
  <xsl:with-param name="str" select="."/>
5026
5207
  </xsl:call-template>
@@ -5031,6 +5212,30 @@
5031
5212
  </xsl:choose>
5032
5213
  </xsl:for-each>
5033
5214
 
5215
+ </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">
5216
+ <xsl:param name="pText" select="."/>
5217
+ <xsl:param name="sep" select="','"/>
5218
+ <!-- word with length more than 30 will be interspersed with zero-width space -->
5219
+ <xsl:variable name="regex" select="concat('([^', $zero_width_space, ']{31,})')"/> <!-- sequence of characters (more 31), that doesn't contains zero-width space -->
5220
+ <xsl:variable name="text" select="java:replaceAll(java:java.lang.String.new($pText),$regex,concat($interspers_tag_open,'$1',$interspers_tag_close))"/>
5221
+ <xsl:call-template name="replace_tag_interspers">
5222
+ <xsl:with-param name="text" select="$text"/>
5223
+ </xsl:call-template>
5224
+ </xsl:template><xsl:template name="replace_tag_interspers">
5225
+ <xsl:param name="text"/>
5226
+ <xsl:choose>
5227
+ <xsl:when test="contains($text, $interspers_tag_open)">
5228
+ <xsl:value-of select="substring-before($text, $interspers_tag_open)"/>
5229
+ <xsl:variable name="text_after" select="substring-after($text, $interspers_tag_open)"/>
5230
+ <interspers>
5231
+ <xsl:value-of select="substring-before($text_after, $interspers_tag_close)"/>
5232
+ </interspers>
5233
+ <xsl:call-template name="replace_tag_interspers">
5234
+ <xsl:with-param name="text" select="substring-after($text_after, $interspers_tag_close)"/>
5235
+ </xsl:call-template>
5236
+ </xsl:when>
5237
+ <xsl:otherwise><xsl:value-of select="$text"/></xsl:otherwise>
5238
+ </xsl:choose>
5034
5239
  </xsl:template><xsl:template name="interspers">
5035
5240
  <xsl:param name="str"/>
5036
5241
  <xsl:param name="char" select="$zero_width_space"/>
@@ -5366,39 +5571,67 @@
5366
5571
  </xsl:otherwise>
5367
5572
  </xsl:choose>
5368
5573
  </xsl:template><xsl:template match="*[local-name() = 'example']">
5369
- <fo:block id="{@id}" xsl:use-attribute-sets="example-style">
5370
-
5574
+
5575
+ <fo:block-container id="{@id}" xsl:use-attribute-sets="example-style">
5576
+
5371
5577
 
5578
+
5372
5579
  <xsl:variable name="fo_element">
5373
- <xsl:if test=".//*[local-name() = 'table'] or .//*[local-name() = 'dl']">block</xsl:if>
5580
+ <xsl:if test=".//*[local-name() = 'table'] or .//*[local-name() = 'dl'] or *[not(local-name() = 'name')][1][local-name() = 'sourcecode']">block</xsl:if>
5374
5581
  block
5375
5582
  </xsl:variable>
5376
5583
 
5377
- <!-- display 'EXAMPLE' -->
5378
- <xsl:apply-templates select="*[local-name()='name']">
5379
- <xsl:with-param name="fo_element" select="$fo_element"/>
5380
- </xsl:apply-templates>
5584
+ <fo:block-container margin-left="0mm">
5381
5585
 
5382
- <xsl:choose>
5383
- <xsl:when test="contains(normalize-space($fo_element), 'block')">
5384
- <fo:block-container xsl:use-attribute-sets="example-body-style">
5385
- <fo:block-container margin-left="0mm" margin-right="0mm">
5386
- <xsl:apply-templates select="node()[not(local-name() = 'name')]">
5586
+ <xsl:choose>
5587
+
5588
+ <xsl:when test="contains(normalize-space($fo_element), 'block')">
5589
+
5590
+ <!-- display name 'EXAMPLE' in a separate block -->
5591
+ <fo:block>
5592
+ <xsl:apply-templates select="*[local-name()='name']">
5387
5593
  <xsl:with-param name="fo_element" select="$fo_element"/>
5388
5594
  </xsl:apply-templates>
5595
+ </fo:block>
5596
+
5597
+ <fo:block-container xsl:use-attribute-sets="example-body-style">
5598
+ <fo:block-container margin-left="0mm" margin-right="0mm">
5599
+ <xsl:apply-templates select="node()[not(local-name() = 'name')]">
5600
+ <xsl:with-param name="fo_element" select="$fo_element"/>
5601
+ </xsl:apply-templates>
5602
+ </fo:block-container>
5389
5603
  </fo:block-container>
5390
- </fo:block-container>
5391
- </xsl:when>
5392
- <xsl:otherwise>
5393
- <fo:inline>
5394
- <xsl:apply-templates select="node()[not(local-name() = 'name')]">
5395
- <xsl:with-param name="fo_element" select="$fo_element"/>
5396
- </xsl:apply-templates>
5397
- </fo:inline>
5398
- </xsl:otherwise>
5399
- </xsl:choose>
5400
-
5401
- </fo:block>
5604
+ </xsl:when> <!-- end block -->
5605
+
5606
+ <xsl:otherwise> <!-- inline -->
5607
+
5608
+ <!-- display 'EXAMPLE' and first element in the same line -->
5609
+ <fo:block>
5610
+ <xsl:apply-templates select="*[local-name()='name']">
5611
+ <xsl:with-param name="fo_element" select="$fo_element"/>
5612
+ </xsl:apply-templates>
5613
+ <fo:inline>
5614
+ <xsl:apply-templates select="*[not(local-name() = 'name')][1]">
5615
+ <xsl:with-param name="fo_element" select="$fo_element"/>
5616
+ </xsl:apply-templates>
5617
+ </fo:inline>
5618
+ </fo:block>
5619
+
5620
+ <xsl:if test="*[not(local-name() = 'name')][position() &gt; 1]">
5621
+ <!-- display further elements in blocks -->
5622
+ <fo:block-container xsl:use-attribute-sets="example-body-style">
5623
+ <fo:block-container margin-left="0mm" margin-right="0mm">
5624
+ <xsl:apply-templates select="*[not(local-name() = 'name')][position() &gt; 1]">
5625
+ <xsl:with-param name="fo_element" select="'block'"/>
5626
+ </xsl:apply-templates>
5627
+ </fo:block-container>
5628
+ </fo:block-container>
5629
+ </xsl:if>
5630
+ </xsl:otherwise> <!-- end inline -->
5631
+
5632
+ </xsl:choose>
5633
+ </fo:block-container>
5634
+ </fo:block-container>
5402
5635
  </xsl:template><xsl:template match="*[local-name() = 'example']/*[local-name() = 'name']">
5403
5636
  <xsl:param name="fo_element">block</xsl:param>
5404
5637
 
@@ -5430,10 +5663,16 @@
5430
5663
  </xsl:variable>
5431
5664
  <xsl:choose>
5432
5665
  <xsl:when test="starts-with(normalize-space($element), 'block')">
5433
- <fo:block xsl:use-attribute-sets="example-p-style">
5434
-
5435
- <xsl:apply-templates/>
5436
- </fo:block>
5666
+ <fo:block-container>
5667
+ <xsl:if test="ancestor::*[local-name() = 'li'] and contains(normalize-space($fo_element), 'block')">
5668
+ <xsl:attribute name="margin-left">0mm</xsl:attribute>
5669
+ <xsl:attribute name="margin-right">0mm</xsl:attribute>
5670
+ </xsl:if>
5671
+ <fo:block xsl:use-attribute-sets="example-p-style">
5672
+
5673
+ <xsl:apply-templates/>
5674
+ </fo:block>
5675
+ </fo:block-container>
5437
5676
  </xsl:when>
5438
5677
  <xsl:otherwise>
5439
5678
  <fo:inline xsl:use-attribute-sets="example-p-style">
@@ -5478,7 +5717,7 @@
5478
5717
  </xsl:otherwise>
5479
5718
  </xsl:choose> -->
5480
5719
  </fo:block>
5481
- </xsl:template><xsl:template match="*[local-name() = 'termsource']/text()[starts-with(., '[SOURCE: Adapted from: ')]" priority="2">
5720
+ </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">
5482
5721
  <xsl:text>[</xsl:text><xsl:value-of select="substring-after(., '[SOURCE: ')"/>
5483
5722
  </xsl:template><xsl:template match="*[local-name() = 'termsource']/text()">
5484
5723
  <xsl:if test="normalize-space() != ''">
@@ -5514,7 +5753,8 @@
5514
5753
  <fo:inline><xsl:apply-templates/></fo:inline>
5515
5754
  </xsl:template><xsl:template match="*[local-name() = 'modification']/text()">
5516
5755
  <xsl:if test="normalize-space() != ''">
5517
- <xsl:value-of select="."/>
5756
+ <!-- <xsl:value-of select="."/> -->
5757
+ <xsl:call-template name="text"/>
5518
5758
  </xsl:if>
5519
5759
  </xsl:template><xsl:template match="*[local-name() = 'quote']">
5520
5760
  <fo:block-container margin-left="0mm">
@@ -5614,7 +5854,16 @@
5614
5854
  </fo:inline>
5615
5855
  </xsl:when>
5616
5856
  <xsl:otherwise> <!-- if there is key('bibitems_hidden', $current_bibitemid) -->
5617
- <fo:inline><xsl:apply-templates/></fo:inline>
5857
+
5858
+ <!-- if in bibitem[@hidden='true'] there is url[@type='src'], then create hyperlink -->
5859
+ <xsl:variable name="uri_src" select="normalize-space($bibitems_hidden/*[local-name() ='bibitem'][@id = $current_bibitemid]/*[local-name() = 'uri'][@type = 'src'])"/>
5860
+ <xsl:choose>
5861
+ <xsl:when test="$uri_src != ''">
5862
+ <fo:basic-link external-destination="{$uri_src}" fox:alt-text="{$uri_src}"><xsl:apply-templates/></fo:basic-link>
5863
+ </xsl:when>
5864
+ <xsl:otherwise><fo:inline><xsl:apply-templates/></fo:inline></xsl:otherwise>
5865
+ </xsl:choose>
5866
+
5618
5867
  </xsl:otherwise>
5619
5868
  </xsl:choose>
5620
5869
  </xsl:template><xsl:template match="*[local-name() = 'tab']">
@@ -5780,10 +6029,24 @@
5780
6029
 
5781
6030
  </fo:block>
5782
6031
  <xsl:apply-templates/>
5783
- </xsl:template><xsl:template match="*[local-name() = 'review']">
6032
+ </xsl:template><xsl:template match="*[local-name() = 'review']"> <!-- 'review' will be processed in mn2pdf/review.xsl -->
5784
6033
  <!-- comment 2019-11-29 -->
5785
6034
  <!-- <fo:block font-weight="bold">Review:</fo:block>
5786
6035
  <xsl:apply-templates /> -->
6036
+
6037
+ <xsl:variable name="id_from" select="normalize-space(current()/@from)"/>
6038
+
6039
+ <xsl:choose>
6040
+ <!-- if there isn't the attribute '@from', then -->
6041
+ <xsl:when test="$id_from = ''">
6042
+ <fo:block id="{@id}" font-size="1pt"><xsl:value-of select="$hair_space"/></fo:block>
6043
+ </xsl:when>
6044
+ <!-- if there isn't element with id 'from', then create 'bookmark' here -->
6045
+ <xsl:when test="not(ancestor::*[contains(local-name(), '-standard')]//*[@id = $id_from])">
6046
+ <fo:block id="{@from}" font-size="1pt"><xsl:value-of select="$hair_space"/></fo:block>
6047
+ </xsl:when>
6048
+ </xsl:choose>
6049
+
5787
6050
  </xsl:template><xsl:template match="*[local-name() = 'name']/text()">
5788
6051
  <!-- 0xA0 to space replacement -->
5789
6052
  <xsl:value-of select="java:replaceAll(java:java.lang.String.new(.),' ',' ')"/>
@@ -6144,7 +6407,10 @@
6144
6407
  <!-- to split by '_' and other chars -->
6145
6408
  <xsl:call-template name="add-zero-spaces-java"/>
6146
6409
  </xsl:template><xsl:template match="*[local-name() = 'bookmark']" name="bookmark">
6147
- <fo:inline id="{@id}" font-size="1pt"/>
6410
+ <!-- <fo:inline id="{@id}" font-size="1pt"/> -->
6411
+ <fo:inline id="{@id}" font-size="1pt"><xsl:value-of select="$hair_space"/></fo:inline>
6412
+ <!-- we need to add zero-width space, otherwise this fo:inline is missing in IF xml -->
6413
+ <xsl:if test="not(following-sibling::node()[normalize-space() != ''])"> </xsl:if>
6148
6414
  </xsl:template><xsl:template match="*[local-name() = 'errata']">
6149
6415
  <!-- <row>
6150
6416
  <date>05-07-2013</date>
@@ -6684,6 +6950,120 @@
6684
6950
  <xsl:apply-templates select="." mode="update_xml_step1"/>
6685
6951
  </xsl:for-each>
6686
6952
  </xsl:copy>
6953
+ </xsl:template><xsl:template match="*[local-name() = 'span']" mode="update_xml_step1">
6954
+ <xsl:apply-templates mode="update_xml_step1"/>
6955
+ </xsl:template><xsl:template match="@*|node()" mode="update_xml_enclose_keep-together_within-line">
6956
+ <xsl:copy>
6957
+ <xsl:apply-templates select="@*|node()" mode="update_xml_enclose_keep-together_within-line"/>
6958
+ </xsl:copy>
6959
+ </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">
6960
+
6961
+ <!-- enclose standard's number into tag 'keep-together_within-line' -->
6962
+ <xsl:variable name="regex_standard_reference">([A-Z]{2,}(/[A-Z]{2,})* \d+(-\d+)*(:\d{4})?)</xsl:variable>
6963
+ <xsl:variable name="tag_keep-together_within-line_open">###<xsl:value-of select="$element_name_keep-together_within-line"/>###</xsl:variable>
6964
+ <xsl:variable name="tag_keep-together_within-line_close">###/<xsl:value-of select="$element_name_keep-together_within-line"/>###</xsl:variable>
6965
+ <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))"/>
6966
+ <xsl:variable name="text"><text><xsl:call-template name="replace_text_tags">
6967
+ <xsl:with-param name="tag_open" select="$tag_keep-together_within-line_open"/>
6968
+ <xsl:with-param name="tag_close" select="$tag_keep-together_within-line_close"/>
6969
+ <xsl:with-param name="text" select="$text_"/>
6970
+ </xsl:call-template></text></xsl:variable>
6971
+
6972
+ <xsl:variable name="parent" select="local-name(..)"/>
6973
+
6974
+ <xsl:variable name="text2">
6975
+ <text><xsl:for-each select="xalan:nodeset($text)/text/node()">
6976
+ <xsl:copy-of select="."/>
6977
+ </xsl:for-each></text>
6978
+ </xsl:variable>
6979
+
6980
+ <!-- keep-together_within-line for: a/b, aaa/b, a/bbb, /b -->
6981
+ <xsl:variable name="regex_solidus_units">((\b((\S{1,3}\/\S+)|(\S+\/\S{1,3}))\b)|(\/\S{1,3})\b)</xsl:variable>
6982
+ <xsl:variable name="text3">
6983
+ <text><xsl:for-each select="xalan:nodeset($text2)/text/node()">
6984
+ <xsl:choose>
6985
+ <xsl:when test="self::text()">
6986
+ <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))"/>
6987
+ <xsl:variable name="text_units"><text><xsl:call-template name="replace_text_tags">
6988
+ <xsl:with-param name="tag_open" select="$tag_keep-together_within-line_open"/>
6989
+ <xsl:with-param name="tag_close" select="$tag_keep-together_within-line_close"/>
6990
+ <xsl:with-param name="text" select="$text_units_"/>
6991
+ </xsl:call-template></text></xsl:variable>
6992
+ <xsl:copy-of select="xalan:nodeset($text_units)/text/node()"/>
6993
+ </xsl:when>
6994
+ <xsl:otherwise><xsl:copy-of select="."/></xsl:otherwise> <!-- copy 'as-is' for <fo:inline keep-together.within-line="always" ... -->
6995
+ </xsl:choose>
6996
+ </xsl:for-each></text>
6997
+ </xsl:variable>
6998
+
6999
+ <xsl:choose>
7000
+ <xsl:when test="ancestor::*[local-name() = 'td' or local-name() = 'th']">
7001
+ <!-- keep-together_within-line for: a.b, aaa.b, a.bbb, .b in table's cell ONLY -->
7002
+ <xsl:variable name="regex_dots_units">((\b((\S{1,3}\.\S+)|(\S+\.\S{1,3}))\b)|(\.\S{1,3})\b)</xsl:variable>
7003
+ <xsl:for-each select="xalan:nodeset($text3)/text/node()">
7004
+ <xsl:choose>
7005
+ <xsl:when test="self::text()">
7006
+ <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))"/>
7007
+ <xsl:variable name="text_dots"><text><xsl:call-template name="replace_text_tags">
7008
+ <xsl:with-param name="tag_open" select="$tag_keep-together_within-line_open"/>
7009
+ <xsl:with-param name="tag_close" select="$tag_keep-together_within-line_close"/>
7010
+ <xsl:with-param name="text" select="$text_dots_"/>
7011
+ </xsl:call-template></text></xsl:variable>
7012
+ <xsl:copy-of select="xalan:nodeset($text_dots)/text/node()"/>
7013
+ </xsl:when>
7014
+ <xsl:otherwise><xsl:copy-of select="."/></xsl:otherwise> <!-- copy 'as-is' for <fo:inline keep-together.within-line="always" ... -->
7015
+ </xsl:choose>
7016
+ </xsl:for-each>
7017
+ </xsl:when>
7018
+ <xsl:otherwise><xsl:copy-of select="xalan:nodeset($text3)/text/node()"/></xsl:otherwise>
7019
+ </xsl:choose>
7020
+
7021
+ </xsl:template><xsl:template name="replace_text_tags">
7022
+ <xsl:param name="tag_open"/>
7023
+ <xsl:param name="tag_close"/>
7024
+ <xsl:param name="text"/>
7025
+ <xsl:choose>
7026
+ <xsl:when test="contains($text, $tag_open)">
7027
+ <xsl:value-of select="substring-before($text, $tag_open)"/>
7028
+ <xsl:variable name="text_after" select="substring-after($text, $tag_open)"/>
7029
+
7030
+ <xsl:element name="{substring-before(substring-after($tag_open, '###'),'###')}">
7031
+ <xsl:value-of select="substring-before($text_after, $tag_close)"/>
7032
+ </xsl:element>
7033
+
7034
+ <xsl:call-template name="replace_text_tags">
7035
+ <xsl:with-param name="tag_open" select="$tag_open"/>
7036
+ <xsl:with-param name="tag_close" select="$tag_close"/>
7037
+ <xsl:with-param name="text" select="substring-after($text_after, $tag_close)"/>
7038
+ </xsl:call-template>
7039
+ </xsl:when>
7040
+ <xsl:otherwise><xsl:value-of select="$text"/></xsl:otherwise>
7041
+ </xsl:choose>
7042
+ </xsl:template><xsl:template name="printEdition">
7043
+ <xsl:variable name="edition_i18n" select="normalize-space((//*[contains(local-name(), '-standard')])[1]/*[local-name() = 'bibdata']/*[local-name() = 'edition'][normalize-space(@language) != ''])"/>
7044
+ <xsl:text> </xsl:text>
7045
+ <xsl:choose>
7046
+ <xsl:when test="$edition_i18n != ''">
7047
+ <!-- Example: <edition language="fr">deuxième édition</edition> -->
7048
+ <xsl:call-template name="capitalize">
7049
+ <xsl:with-param name="str" select="$edition_i18n"/>
7050
+ </xsl:call-template>
7051
+ </xsl:when>
7052
+ <xsl:otherwise>
7053
+ <xsl:variable name="edition" select="normalize-space((//*[contains(local-name(), '-standard')])[1]/*[local-name() = 'bibdata']/*[local-name() = 'edition'])"/>
7054
+ <xsl:if test="$edition != ''"> <!-- Example: 1.3 -->
7055
+ <xsl:call-template name="capitalize">
7056
+ <xsl:with-param name="str">
7057
+ <xsl:call-template name="getLocalizedString">
7058
+ <xsl:with-param name="key">edition</xsl:with-param>
7059
+ </xsl:call-template>
7060
+ </xsl:with-param>
7061
+ </xsl:call-template>
7062
+ <xsl:text> </xsl:text>
7063
+ <xsl:value-of select="$edition"/>
7064
+ </xsl:if>
7065
+ </xsl:otherwise>
7066
+ </xsl:choose>
6687
7067
  </xsl:template><xsl:template name="convertDate">
6688
7068
  <xsl:param name="date"/>
6689
7069
  <xsl:param name="format" select="'short'"/>