metanorma-mpfa 0.8.7 → 0.9.1

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>
@@ -409,6 +422,7 @@
409
422
 
410
423
  <xsl:template match="mpfd:p" name="paragraph">
411
424
  <xsl:param name="inline" select="'false'"/>
425
+ <xsl:param name="split_keep-within-line"/>
412
426
  <xsl:variable name="previous-element" select="local-name(preceding-sibling::*[1])"/>
413
427
  <xsl:variable name="element-name">
414
428
  <xsl:choose>
@@ -433,7 +447,9 @@
433
447
  <xsl:attribute name="margin-bottom">0pt</xsl:attribute>
434
448
  </xsl:if>
435
449
  <xsl:attribute name="line-height">115%</xsl:attribute>
436
- <xsl:apply-templates/>
450
+ <xsl:apply-templates>
451
+ <xsl:with-param name="split_keep-within-line" select="$split_keep-within-line"/>
452
+ </xsl:apply-templates>
437
453
  </xsl:element>
438
454
  <xsl:if test="$element-name = 'fo:inline' and not($inline = 'true') and not(local-name(..) = 'admonition')">
439
455
  <xsl:choose>
@@ -570,7 +586,9 @@
570
586
  </xsl:template>
571
587
 
572
588
 
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">
589
+ <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_">
590
+ false
591
+ </xsl:variable><xsl:variable name="isGenerateTableIF" select="normalize-space($isGenerateTableIF_)"/><xsl:variable name="lang">
574
592
  <xsl:call-template name="getLang"/>
575
593
  </xsl:variable><xsl:variable name="pageWidth_">
576
594
  210
@@ -585,20 +603,7 @@
585
603
  </xsl:variable><xsl:variable name="marginTop" select="normalize-space($marginTop_)"/><xsl:variable name="marginBottom_">
586
604
  10
587
605
  </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
-
595
- <title-edition lang="fr">
596
- <xsl:text>Édition </xsl:text>
597
- </title-edition>
598
606
 
599
- <title-edition lang="ru">
600
- <xsl:text>Издание </xsl:text>
601
- </title-edition>
602
607
 
603
608
  <!-- These titles of Table of contents renders different than determined in localized-strings -->
604
609
  <title-toc lang="en">
@@ -679,7 +684,7 @@
679
684
  </xsl:variable><xsl:variable name="bibdata">
680
685
  <xsl:copy-of select="//*[contains(local-name(), '-standard')]/*[local-name() = 'bibdata']"/>
681
686
  <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">
687
+ </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
688
  <xsl:param name="name"/>
684
689
  <xsl:param name="lang"/>
685
690
  <xsl:variable name="lang_">
@@ -722,7 +727,30 @@
722
727
 
723
728
 
724
729
 
725
- </xsl:attribute-set><xsl:attribute-set name="copyright-statement-style">
730
+ </xsl:attribute-set><xsl:template name="insertRootStyle">
731
+ <xsl:param name="root-style"/>
732
+ <xsl:variable name="root-style_" select="xalan:nodeset($root-style)"/>
733
+
734
+ <xsl:variable name="additional_fonts_">
735
+ <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']">
736
+ <xsl:value-of select="."/><xsl:if test="position() != last()">, </xsl:if>
737
+ </xsl:for-each>
738
+ </xsl:variable>
739
+ <xsl:variable name="additional_fonts" select="normalize-space($additional_fonts_)"/>
740
+
741
+ <xsl:for-each select="$root-style_/root-style/@*">
742
+ <xsl:choose>
743
+ <xsl:when test="local-name() = 'font-family' and $additional_fonts != ''">
744
+ <xsl:attribute name="{local-name()}">
745
+ <xsl:value-of select="."/>, <xsl:value-of select="$additional_fonts"/>
746
+ </xsl:attribute>
747
+ </xsl:when>
748
+ <xsl:otherwise>
749
+ <xsl:copy-of select="."/>
750
+ </xsl:otherwise>
751
+ </xsl:choose>
752
+ </xsl:for-each>
753
+ </xsl:template><xsl:attribute-set name="copyright-statement-style">
726
754
 
727
755
  </xsl:attribute-set><xsl:attribute-set name="copyright-statement-title-style">
728
756
 
@@ -779,7 +807,6 @@
779
807
 
780
808
 
781
809
  </xsl:attribute-set><xsl:attribute-set name="sourcecode-container-style">
782
- <xsl:attribute name="margin-left">0mm</xsl:attribute>
783
810
 
784
811
  </xsl:attribute-set><xsl:attribute-set name="sourcecode-style">
785
812
  <xsl:attribute name="white-space">pre</xsl:attribute>
@@ -855,6 +882,7 @@
855
882
 
856
883
 
857
884
 
885
+
858
886
  <xsl:attribute name="margin-left">12.5mm</xsl:attribute>
859
887
  <xsl:attribute name="margin-bottom">18pt</xsl:attribute>
860
888
 
@@ -1010,6 +1038,7 @@
1010
1038
  <xsl:attribute name="font-weight">bold</xsl:attribute>
1011
1039
  <xsl:attribute name="border">solid black 1pt</xsl:attribute>
1012
1040
  <xsl:attribute name="padding-left">1mm</xsl:attribute>
1041
+ <xsl:attribute name="padding-right">1mm</xsl:attribute>
1013
1042
  <xsl:attribute name="display-align">center</xsl:attribute>
1014
1043
 
1015
1044
 
@@ -1031,6 +1060,7 @@
1031
1060
  <xsl:attribute name="display-align">center</xsl:attribute>
1032
1061
  <xsl:attribute name="border">solid black 1pt</xsl:attribute>
1033
1062
  <xsl:attribute name="padding-left">1mm</xsl:attribute>
1063
+ <xsl:attribute name="padding-right">1mm</xsl:attribute>
1034
1064
 
1035
1065
 
1036
1066
 
@@ -1113,7 +1143,8 @@
1113
1143
  </xsl:attribute-set><xsl:attribute-set name="dt-row-style">
1114
1144
 
1115
1145
 
1116
- </xsl:attribute-set><xsl:attribute-set name="dt-style">
1146
+ </xsl:attribute-set><xsl:attribute-set name="dt-cell-style">
1147
+ </xsl:attribute-set><xsl:attribute-set name="dt-block-style">
1117
1148
  <xsl:attribute name="margin-top">6pt</xsl:attribute>
1118
1149
 
1119
1150
 
@@ -1125,6 +1156,8 @@
1125
1156
 
1126
1157
 
1127
1158
 
1159
+ </xsl:attribute-set><xsl:attribute-set name="dd-cell-style">
1160
+ <xsl:attribute name="padding-left">2mm</xsl:attribute>
1128
1161
  </xsl:attribute-set><xsl:attribute-set name="appendix-style">
1129
1162
 
1130
1163
 
@@ -1211,7 +1244,7 @@
1211
1244
 
1212
1245
 
1213
1246
 
1214
- </xsl:attribute-set><xsl:attribute-set name="termnote-name-style">
1247
+ </xsl:attribute-set><xsl:attribute-set name="termnote-name-style">
1215
1248
 
1216
1249
 
1217
1250
 
@@ -1898,22 +1931,32 @@
1898
1931
  <xsl:sort select="@displayorder" data-type="number"/>
1899
1932
  <xsl:apply-templates select="."/>
1900
1933
  </xsl:for-each>
1901
- </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">
1902
- <xsl:variable name="regex_standard_reference">([A-Z]{2,}(/[A-Z]{2,})* \d+(-\d+)*(:\d{4})?)</xsl:variable>
1903
- <xsl:variable name="text" select="java:replaceAll(java:java.lang.String.new(.),$regex_standard_reference,concat($tag_open,'$1',$tag_close))"/>
1904
- <xsl:call-template name="replace_fo_inline">
1905
- <xsl:with-param name="text" select="$text"/>
1906
- </xsl:call-template>
1907
- </xsl:template><xsl:template name="replace_fo_inline">
1934
+ </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">
1935
+
1936
+ <xsl:variable name="regex_standard_reference">([A-Z]{2,}(/[A-Z]{2,})* \d+(-\d+)*(:\d{4})?)</xsl:variable>
1937
+ <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))"/>
1938
+ <xsl:call-template name="replace_fo_inline_tags">
1939
+ <xsl:with-param name="tag_open" select="$tag_fo_inline_keep-together_within-line_open"/>
1940
+ <xsl:with-param name="tag_close" select="$tag_fo_inline_keep-together_within-line_close"/>
1941
+ <xsl:with-param name="text" select="$text"/>
1942
+ </xsl:call-template>
1943
+
1944
+ </xsl:template><xsl:template name="replace_fo_inline_tags">
1945
+ <xsl:param name="tag_open"/>
1946
+ <xsl:param name="tag_close"/>
1908
1947
  <xsl:param name="text"/>
1909
1948
  <xsl:choose>
1910
1949
  <xsl:when test="contains($text, $tag_open)">
1911
1950
  <xsl:value-of select="substring-before($text, $tag_open)"/>
1912
- <xsl:text disable-output-escaping="yes">&lt;fo:inline keep-together.within-line="always"&gt;</xsl:text>
1951
+ <!-- <xsl:text disable-output-escaping="yes">&lt;fo:inline keep-together.within-line="always"&gt;</xsl:text> -->
1913
1952
  <xsl:variable name="text_after" select="substring-after($text, $tag_open)"/>
1914
- <xsl:value-of select="substring-before($text_after, $tag_close)"/>
1915
- <xsl:text disable-output-escaping="yes">&lt;/fo:inline&gt;</xsl:text>
1916
- <xsl:call-template name="replace_fo_inline">
1953
+ <fo:inline keep-together.within-line="always">
1954
+ <xsl:value-of select="substring-before($text_after, $tag_close)"/>
1955
+ </fo:inline>
1956
+ <!-- <xsl:text disable-output-escaping="yes">&lt;/fo:inline&gt;</xsl:text> -->
1957
+ <xsl:call-template name="replace_fo_inline_tags">
1958
+ <xsl:with-param name="tag_open" select="$tag_open"/>
1959
+ <xsl:with-param name="tag_close" select="$tag_close"/>
1917
1960
  <xsl:with-param name="text" select="substring-after($text_after, $tag_close)"/>
1918
1961
  </xsl:call-template>
1919
1962
  </xsl:when>
@@ -1921,6 +1964,39 @@
1921
1964
  </xsl:choose>
1922
1965
  </xsl:template><xsl:template match="*[local-name()='br']">
1923
1966
  <xsl:value-of select="$linebreak"/>
1967
+ </xsl:template><xsl:template match="*[local-name() = 'keep-together_within-line']">
1968
+ <xsl:param name="split_keep-within-line"/>
1969
+
1970
+ <!-- <fo:inline>split_keep-within-line='<xsl:value-of select="$split_keep-within-line"/>'</fo:inline> -->
1971
+ <xsl:choose>
1972
+
1973
+ <xsl:when test="normalize-space($split_keep-within-line) = 'true'">
1974
+ <xsl:variable name="sep">_</xsl:variable>
1975
+ <xsl:variable name="items">
1976
+ <xsl:call-template name="split">
1977
+ <xsl:with-param name="pText" select="."/>
1978
+ <xsl:with-param name="sep" select="$sep"/>
1979
+ <xsl:with-param name="normalize-space">false</xsl:with-param>
1980
+ <xsl:with-param name="keep_sep">true</xsl:with-param>
1981
+ </xsl:call-template>
1982
+ </xsl:variable>
1983
+ <xsl:for-each select="xalan:nodeset($items)/item">
1984
+ <xsl:choose>
1985
+ <xsl:when test=". = $sep">
1986
+ <xsl:value-of select="$sep"/><xsl:value-of select="$zero_width_space"/>
1987
+ </xsl:when>
1988
+ <xsl:otherwise>
1989
+ <fo:inline keep-together.within-line="always"><xsl:apply-templates/></fo:inline>
1990
+ </xsl:otherwise>
1991
+ </xsl:choose>
1992
+ </xsl:for-each>
1993
+ </xsl:when>
1994
+
1995
+ <xsl:otherwise>
1996
+ <fo:inline keep-together.within-line="always"><xsl:apply-templates/></fo:inline>
1997
+ </xsl:otherwise>
1998
+
1999
+ </xsl:choose>
1924
2000
  </xsl:template><xsl:template match="*[local-name()='copyright-statement']">
1925
2001
  <fo:block xsl:use-attribute-sets="copyright-statement-style">
1926
2002
  <xsl:apply-templates/>
@@ -1986,8 +2062,23 @@
1986
2062
  </xsl:call-template>
1987
2063
 
1988
2064
  </xsl:template><xsl:template match="*[local-name()='td']//text() | *[local-name()='th']//text() | *[local-name()='dt']//text() | *[local-name()='dd']//text()" priority="1">
1989
- <!-- <xsl:call-template name="add-zero-spaces"/> -->
1990
- <xsl:call-template name="add-zero-spaces-java"/>
2065
+ <xsl:choose>
2066
+ <xsl:when test="parent::*[local-name() = 'keep-together_within-line']">
2067
+ <xsl:value-of select="."/>
2068
+ </xsl:when>
2069
+ <xsl:otherwise>
2070
+ <xsl:call-template name="addZeroWidthSpacesToTextNodes"/>
2071
+ </xsl:otherwise>
2072
+ </xsl:choose>
2073
+ </xsl:template><xsl:template name="addZeroWidthSpacesToTextNodes">
2074
+ <xsl:variable name="text"><text><xsl:call-template name="text"/></text></xsl:variable>
2075
+ <!-- <xsl:copy-of select="$text"/> -->
2076
+ <xsl:for-each select="xalan:nodeset($text)/text/node()">
2077
+ <xsl:choose>
2078
+ <xsl:when test="self::text()"><xsl:call-template name="add-zero-spaces-java"/></xsl:when>
2079
+ <xsl:otherwise><xsl:copy-of select="."/></xsl:otherwise> <!-- copy 'as-is' for <fo:inline keep-together.within-line="always" ... -->
2080
+ </xsl:choose>
2081
+ </xsl:for-each>
1991
2082
  </xsl:template><xsl:template match="*[local-name()='table']" name="table">
1992
2083
 
1993
2084
  <xsl:variable name="table-preamble">
@@ -1997,9 +2088,14 @@
1997
2088
 
1998
2089
  <xsl:variable name="table">
1999
2090
 
2000
- <xsl:variable name="simple-table">
2001
- <xsl:call-template name="getSimpleTable"/>
2091
+ <xsl:variable name="simple-table">
2092
+ <xsl:call-template name="getSimpleTable">
2093
+ <xsl:with-param name="id" select="@id"/>
2094
+ </xsl:call-template>
2002
2095
  </xsl:variable>
2096
+ <!-- <xsl:variable name="simple-table" select="xalan:nodeset($simple-table_)"/> -->
2097
+
2098
+ <!-- simple-table=<xsl:copy-of select="$simple-table"/> -->
2003
2099
 
2004
2100
 
2005
2101
  <!-- Display table's name before table as standalone block -->
@@ -2022,7 +2118,23 @@
2022
2118
  </xsl:call-template>
2023
2119
  </xsl:if>
2024
2120
  </xsl:variable>
2025
- <!-- DEBUG colwidths=<xsl:copy-of select="$colwidths"/> -->
2121
+ <!-- <xsl:variable name="colwidths" select="xalan:nodeset($colwidths_)"/> -->
2122
+
2123
+ <!-- DEBUG -->
2124
+ <xsl:if test="$table_if_debug = 'true'">
2125
+ <fo:block font-size="60%">
2126
+ <xsl:apply-templates select="xalan:nodeset($colwidths)" mode="print_as_xml"/>
2127
+ </fo:block>
2128
+ </xsl:if>
2129
+
2130
+
2131
+ <!-- <xsl:copy-of select="$colwidths"/> -->
2132
+
2133
+ <!-- <xsl:text disable-output-escaping="yes">&lt;!- -</xsl:text>
2134
+ DEBUG
2135
+ colwidths=<xsl:copy-of select="$colwidths"/>
2136
+ <xsl:text disable-output-escaping="yes">- -&gt;</xsl:text> -->
2137
+
2026
2138
 
2027
2139
 
2028
2140
  <xsl:variable name="margin-side">
@@ -2083,9 +2195,17 @@
2083
2195
  </xsl:element>
2084
2196
  </xsl:variable>
2085
2197
 
2198
+ <xsl:if test="$isGenerateTableIF = 'true'">
2199
+ <!-- to determine start of table -->
2200
+ <fo:block id="{concat('table_if_start_',@id)}" keep-with-next="always" font-size="1pt">Start table '<xsl:value-of select="@id"/>'.</fo:block>
2201
+ </xsl:if>
2086
2202
 
2087
2203
  <fo:table id="{@id}">
2088
2204
 
2205
+ <xsl:if test="$isGenerateTableIF = 'true'">
2206
+ <xsl:attribute name="wrap-option">no-wrap</xsl:attribute>
2207
+ </xsl:if>
2208
+
2089
2209
  <xsl:for-each select="xalan:nodeset($table_attributes)/table_attributes/@*">
2090
2210
  <xsl:attribute name="{local-name()}">
2091
2211
  <xsl:value-of select="."/>
@@ -2099,31 +2219,47 @@
2099
2219
 
2100
2220
 
2101
2221
  <xsl:choose>
2102
- <xsl:when test="*[local-name()='colgroup']/*[local-name()='col']">
2103
- <xsl:for-each select="*[local-name()='colgroup']/*[local-name()='col']">
2104
- <fo:table-column column-width="{@width}"/>
2105
- </xsl:for-each>
2222
+ <xsl:when test="$isGenerateTableIF = 'true'">
2223
+ <!-- generate IF for table widths -->
2224
+ <!-- example:
2225
+ <tr>
2226
+ <td valign="top" align="left" id="tab-symdu_1_1">
2227
+ <p>Symbol</p>
2228
+ <word id="tab-symdu_1_1_word_1">Symbol</word>
2229
+ </td>
2230
+ <td valign="top" align="left" id="tab-symdu_1_2">
2231
+ <p>Description</p>
2232
+ <word id="tab-symdu_1_2_word_1">Description</word>
2233
+ </td>
2234
+ </tr>
2235
+ -->
2236
+ <xsl:apply-templates select="xalan:nodeset($simple-table)" mode="process_table-if"/>
2237
+
2106
2238
  </xsl:when>
2107
2239
  <xsl:otherwise>
2108
- <xsl:for-each select="xalan:nodeset($colwidths)//column">
2109
- <xsl:choose>
2110
- <xsl:when test=". = 1 or . = 0">
2111
- <fo:table-column column-width="proportional-column-width(2)"/>
2112
- </xsl:when>
2113
- <xsl:otherwise>
2114
- <fo:table-column column-width="proportional-column-width({.})"/>
2115
- </xsl:otherwise>
2116
- </xsl:choose>
2117
- </xsl:for-each>
2118
- </xsl:otherwise>
2119
- </xsl:choose>
2120
2240
 
2121
- <xsl:choose>
2122
- <xsl:when test="not(*[local-name()='tbody']) and *[local-name()='thead']">
2123
- <xsl:apply-templates select="*[local-name()='thead']" mode="process_tbody"/>
2124
- </xsl:when>
2125
- <xsl:otherwise>
2126
- <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 -->
2241
+ <xsl:choose>
2242
+ <xsl:when test="*[local-name()='colgroup']/*[local-name()='col']">
2243
+ <xsl:for-each select="*[local-name()='colgroup']/*[local-name()='col']">
2244
+ <fo:table-column column-width="{@width}"/>
2245
+ </xsl:for-each>
2246
+ </xsl:when>
2247
+ <xsl:otherwise>
2248
+ <xsl:call-template name="insertTableColumnWidth">
2249
+ <xsl:with-param name="colwidths" select="$colwidths"/>
2250
+ </xsl:call-template>
2251
+ </xsl:otherwise>
2252
+ </xsl:choose>
2253
+
2254
+ <xsl:choose>
2255
+ <xsl:when test="not(*[local-name()='tbody']) and *[local-name()='thead']">
2256
+ <xsl:apply-templates select="*[local-name()='thead']" mode="process_tbody"/>
2257
+ </xsl:when>
2258
+ <xsl:otherwise>
2259
+ <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 -->
2260
+ </xsl:otherwise>
2261
+ </xsl:choose>
2262
+
2127
2263
  </xsl:otherwise>
2128
2264
  </xsl:choose>
2129
2265
 
@@ -2226,11 +2362,22 @@
2226
2362
  <xsl:variable name="columns-with-colspan" select="count($table-row/*[@colspan])"/>
2227
2363
  <xsl:value-of select="$columns-count + $sum-colspans - $columns-with-colspan"/>
2228
2364
  </xsl:template><xsl:template name="calculate-column-widths">
2365
+ <xsl:param name="table"/>
2366
+ <xsl:param name="cols-count"/>
2367
+
2368
+ <xsl:call-template name="calculate-column-widths-proportional">
2369
+ <xsl:with-param name="cols-count" select="$cols-count"/>
2370
+ <xsl:with-param name="table" select="$table"/>
2371
+ </xsl:call-template>
2372
+
2373
+ </xsl:template><xsl:template name="calculate-column-widths-proportional">
2229
2374
  <xsl:param name="table"/>
2230
2375
  <xsl:param name="cols-count"/>
2231
2376
  <xsl:param name="curr-col" select="1"/>
2232
2377
  <xsl:param name="width" select="0"/>
2233
2378
 
2379
+ <!-- table=<xsl:copy-of select="$table"/> -->
2380
+
2234
2381
  <xsl:if test="$curr-col &lt;= $cols-count">
2235
2382
  <xsl:variable name="widths">
2236
2383
  <xsl:choose>
@@ -2268,16 +2415,22 @@
2268
2415
  </xsl:for-each>
2269
2416
  </xsl:when>
2270
2417
  <xsl:otherwise>
2271
- <xsl:for-each select="xalan:nodeset($table)/*/tr">
2418
+ <!-- <curr_col><xsl:value-of select="$curr-col"/></curr_col> -->
2419
+
2420
+ <!-- <table><xsl:copy-of select="$table"/></table>
2421
+ -->
2422
+ <xsl:for-each select="xalan:nodeset($table)/*/*[local-name()='tr']">
2272
2423
  <xsl:variable name="td_text">
2273
2424
  <xsl:apply-templates select="td[$curr-col]" mode="td_text"/>
2274
2425
  </xsl:variable>
2426
+ <!-- <td_text><xsl:value-of select="$td_text"/></td_text> -->
2275
2427
  <xsl:variable name="words">
2276
2428
  <xsl:variable name="string_with_added_zerospaces">
2277
2429
  <xsl:call-template name="add-zero-spaces-java">
2278
2430
  <xsl:with-param name="text" select="$td_text"/>
2279
2431
  </xsl:call-template>
2280
2432
  </xsl:variable>
2433
+ <!-- <xsl:message>string_with_added_zerospaces=<xsl:value-of select="$string_with_added_zerospaces"/></xsl:message> -->
2281
2434
  <xsl:call-template name="tokenize">
2282
2435
  <!-- <xsl:with-param name="text" select="translate(td[$curr-col],'- —:', ' ')"/> -->
2283
2436
  <!-- 2009 thinspace -->
@@ -2285,11 +2438,13 @@
2285
2438
  <xsl:with-param name="text" select="normalize-space(translate($string_with_added_zerospaces, '​­', ' '))"/> <!-- replace zero-width-space and soft-hyphen to space -->
2286
2439
  </xsl:call-template>
2287
2440
  </xsl:variable>
2441
+ <!-- words=<xsl:copy-of select="$words"/> -->
2288
2442
  <xsl:variable name="max_length">
2289
2443
  <xsl:call-template name="max_length">
2290
2444
  <xsl:with-param name="words" select="xalan:nodeset($words)"/>
2291
2445
  </xsl:call-template>
2292
2446
  </xsl:variable>
2447
+ <!-- <xsl:message>max_length=<xsl:value-of select="$max_length"/></xsl:message> -->
2293
2448
  <width>
2294
2449
  <xsl:variable name="divider">
2295
2450
  <xsl:choose>
@@ -2308,6 +2463,8 @@
2308
2463
  </xsl:choose>
2309
2464
  </xsl:variable>
2310
2465
 
2466
+ <!-- widths=<xsl:copy-of select="$widths"/> -->
2467
+
2311
2468
  <column>
2312
2469
  <xsl:for-each select="xalan:nodeset($widths)//width">
2313
2470
  <xsl:sort select="." data-type="number" order="descending"/>
@@ -2316,29 +2473,327 @@
2316
2473
  </xsl:if>
2317
2474
  </xsl:for-each>
2318
2475
  </column>
2319
- <xsl:call-template name="calculate-column-widths">
2476
+ <xsl:call-template name="calculate-column-widths-proportional">
2320
2477
  <xsl:with-param name="cols-count" select="$cols-count"/>
2321
2478
  <xsl:with-param name="curr-col" select="$curr-col +1"/>
2322
2479
  <xsl:with-param name="table" select="$table"/>
2323
2480
  </xsl:call-template>
2324
2481
  </xsl:if>
2482
+ </xsl:template><xsl:template match="*[@keep-together.within-line or local-name() = 'keep-together_within-line']/text()" priority="2" mode="td_text">
2483
+ <!-- <xsl:message>DEBUG t1=<xsl:value-of select="."/></xsl:message>
2484
+ <xsl:message>DEBUG t2=<xsl:value-of select="java:replaceAll(java:java.lang.String.new(.),'.','X')"/></xsl:message> -->
2485
+ <xsl:value-of select="java:replaceAll(java:java.lang.String.new(.),'.','X')"/>
2486
+
2487
+ <!-- if all capitals english letters or digits -->
2488
+ <xsl:if test="normalize-space(translate(., concat($upper,'0123456789'), '')) = ''">
2489
+ <xsl:call-template name="repeat">
2490
+ <xsl:with-param name="char" select="'X'"/>
2491
+ <xsl:with-param name="count" select="string-length(normalize-space(.)) * 0.5"/>
2492
+ </xsl:call-template>
2493
+ </xsl:if>
2325
2494
  </xsl:template><xsl:template match="text()" mode="td_text">
2326
2495
  <xsl:value-of select="translate(., $zero_width_space, ' ')"/><xsl:text> </xsl:text>
2327
2496
  </xsl:template><xsl:template match="*[local-name()='termsource']" mode="td_text">
2328
2497
  <xsl:value-of select="*[local-name()='origin']/@citeas"/>
2329
2498
  </xsl:template><xsl:template match="*[local-name()='link']" mode="td_text">
2330
2499
  <xsl:value-of select="@target"/>
2331
- </xsl:template><xsl:template match="*[local-name()='math']" mode="td_text">
2332
- <xsl:variable name="mathml">
2333
- <xsl:for-each select="*">
2334
- <xsl:if test="local-name() != 'unit' and local-name() != 'prefix' and local-name() != 'dimension' and local-name() != 'quantity'">
2335
- <xsl:copy-of select="."/>
2500
+ </xsl:template><xsl:template match="*[local-name()='math']" mode="td_text" name="math_length">
2501
+ <xsl:if test="$isGenerateTableIF = 'false'">
2502
+ <xsl:variable name="mathml_">
2503
+ <xsl:for-each select="*">
2504
+ <xsl:if test="local-name() != 'unit' and local-name() != 'prefix' and local-name() != 'dimension' and local-name() != 'quantity'">
2505
+ <xsl:copy-of select="."/>
2506
+ </xsl:if>
2507
+ </xsl:for-each>
2508
+ </xsl:variable>
2509
+ <xsl:variable name="mathml" select="xalan:nodeset($mathml_)"/>
2510
+
2511
+ <xsl:variable name="math_text">
2512
+ <xsl:value-of select="normalize-space($mathml)"/>
2513
+ <xsl:for-each select="$mathml//@open"><xsl:value-of select="."/></xsl:for-each>
2514
+ <xsl:for-each select="$mathml//@close"><xsl:value-of select="."/></xsl:for-each>
2515
+ </xsl:variable>
2516
+ <xsl:value-of select="translate($math_text, ' ', '#')"/><!-- mathml images as one 'word' without spaces -->
2517
+ </xsl:if>
2518
+ </xsl:template><xsl:template name="calculate-column-widths-autolayout-algorithm">
2519
+ <xsl:param name="table"/>
2520
+ <xsl:param name="if">false</xsl:param> <!-- via intermediate format -->
2521
+
2522
+ <!-- The algorithm uses two passes through the table data and scales linearly with the size of the table -->
2523
+
2524
+ <!-- In the first pass, line wrapping is disabled, and the user agent keeps track of the minimum and maximum width of each cell. -->
2525
+
2526
+ <!-- Since line wrap has been disabled, paragraphs are treated as long lines unless broken by BR elements. -->
2527
+
2528
+ <!-- get current table id -->
2529
+ <xsl:variable name="table_id" select="@id"/>
2530
+ <!-- find table by id in the file 'table_widths' -->
2531
+ <xsl:variable name="table-if_" select="$table_widths_from_if//table[@id = $table_id]"/>
2532
+ <xsl:variable name="table-if" select="xalan:nodeset($table-if_)"/>
2533
+
2534
+
2535
+ <!-- table='<xsl:copy-of select="$table"/>' -->
2536
+ <!-- table_id='<xsl:value-of select="$table_id"/>\ -->
2537
+ <!-- table-if='<xsl:copy-of select="$table-if"/>' -->
2538
+ <!-- table_widths_from_if='<xsl:copy-of select="$table_widths_from_if"/>' -->
2539
+
2540
+ <xsl:variable name="table_with_cell_widths_">
2541
+ <xsl:choose>
2542
+ <xsl:when test="$if = 'true' and normalize-space($table-if) != ''"> <!-- if we read column's width from IF and there is table in IF -->
2543
+
2544
+ <!-- Example: <column>10</column>
2545
+ <column>11</column>
2546
+ -->
2547
+ <xsl:apply-templates select="$table-if" mode="determine_cell_widths-if"/>
2548
+ </xsl:when>
2549
+ <xsl:otherwise>
2550
+ <xsl:apply-templates select="xalan:nodeset($table)" mode="determine_cell_widths"/>
2551
+ </xsl:otherwise>
2552
+ </xsl:choose>
2553
+ </xsl:variable>
2554
+ <xsl:variable name="table_with_cell_widths" select="xalan:nodeset($table_with_cell_widths_)"/>
2555
+
2556
+ <xsl:if test="$table_if_debug = 'true'">
2557
+ <xsl:copy-of select="$table_with_cell_widths"/>
2558
+ </xsl:if>
2559
+
2560
+
2561
+ <!-- The minimum and maximum cell widths are then used to determine the corresponding minimum and maximum widths for the columns. -->
2562
+
2563
+ <xsl:variable name="column_widths_">
2564
+ <!-- iteration of columns -->
2565
+ <xsl:for-each select="$table_with_cell_widths//tr[1]/td">
2566
+ <xsl:variable name="pos" select="position()"/>
2567
+ <column>
2568
+ <xsl:attribute name="width_max">
2569
+ <xsl:for-each select="ancestor::tbody//tr/td[$pos]/@width_max">
2570
+ <xsl:sort select="." data-type="number" order="descending"/>
2571
+ <xsl:if test="position() = 1"><xsl:value-of select="."/></xsl:if>
2572
+ </xsl:for-each>
2573
+ </xsl:attribute>
2574
+ <xsl:attribute name="width_min">
2575
+ <xsl:for-each select="ancestor::tbody//tr/td[$pos]/@width_min">
2576
+ <xsl:sort select="." data-type="number" order="descending"/>
2577
+ <xsl:if test="position() = 1"><xsl:value-of select="."/></xsl:if>
2578
+ </xsl:for-each>
2579
+ </xsl:attribute>
2580
+ </column>
2581
+ </xsl:for-each>
2582
+ </xsl:variable>
2583
+ <xsl:variable name="column_widths" select="xalan:nodeset($column_widths_)"/>
2584
+
2585
+ <!-- <column_widths>
2586
+ <xsl:copy-of select="$column_widths"/>
2587
+ </column_widths> -->
2588
+
2589
+ <!-- These in turn, are used to find the minimum and maximum width for the table. -->
2590
+ <xsl:variable name="table_widths_">
2591
+ <table>
2592
+ <xsl:attribute name="width_max">
2593
+ <xsl:value-of select="sum($column_widths/column/@width_max)"/>
2594
+ </xsl:attribute>
2595
+ <xsl:attribute name="width_min">
2596
+ <xsl:value-of select="sum($column_widths/column/@width_min)"/>
2597
+ </xsl:attribute>
2598
+ </table>
2599
+ </xsl:variable>
2600
+ <xsl:variable name="table_widths" select="xalan:nodeset($table_widths_)"/>
2601
+
2602
+ <xsl:variable name="page_width">
2603
+ <xsl:choose>
2604
+ <xsl:when test="$if = 'true'"><xsl:value-of select="$table-if/@page-width"/></xsl:when>
2605
+ <xsl:otherwise>75</xsl:otherwise>
2606
+ </xsl:choose>
2607
+ </xsl:variable>
2608
+
2609
+ <xsl:if test="$table_if_debug = 'true'">
2610
+ <table_width>
2611
+ <xsl:copy-of select="$table_widths"/>
2612
+ </table_width>
2613
+ <!-- <debug>$table_widths/@width_min=<xsl:value-of select="$table_widths/table/@width_min"/></debug>
2614
+ <debug>$table_widths/@width_max=<xsl:value-of select="$table_widths/table/@width_max"/></debug>
2615
+ -->
2616
+ <debug>$page_width=<xsl:value-of select="$page_width"/></debug>
2617
+ </xsl:if>
2618
+
2619
+
2620
+ <!-- There are three cases: -->
2621
+ <xsl:choose>
2622
+ <!-- 1. The minimum table width is equal to or wider than the available space -->
2623
+ <xsl:when test="$table_widths/table/@width_min &gt;= $page_width and 1 = 2"> <!-- this condition isn't working see case 3 below -->
2624
+ <!-- call old algorithm -->
2625
+ <case1/>
2626
+ <xsl:variable name="cols-count" select="count(xalan:nodeset($table)/*/tr[1]/td)"/>
2627
+ <xsl:call-template name="calculate-column-widths-proportional">
2628
+ <xsl:with-param name="cols-count" select="$cols-count"/>
2629
+ <xsl:with-param name="table" select="$table"/>
2630
+ </xsl:call-template>
2631
+ </xsl:when>
2632
+ <!-- 2. The maximum table width fits within the available space. In this case, set the columns to their maximum widths. -->
2633
+ <xsl:when test="$table_widths/table/@width_max &lt;= $page_width">
2634
+ <case2/>
2635
+ <autolayout/>
2636
+ <xsl:for-each select="$column_widths/column/@width_max">
2637
+ <column divider="100"><xsl:value-of select="."/></column>
2638
+ </xsl:for-each>
2639
+ </xsl:when>
2640
+ <!-- 3. The maximum width of the table is greater than the available space, but the minimum table width is smaller.
2641
+ In this case, find the difference between the available space and the minimum table width, lets call it W.
2642
+ Lets also call D the difference between maximum and minimum width of the table.
2643
+ For each column, let d be the difference between maximum and minimum width of that column.
2644
+ Now set the column's width to the minimum width plus d times W over D.
2645
+ This makes columns with large differences between minimum and maximum widths wider than columns with smaller differences. -->
2646
+ <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)">
2647
+ <!-- difference between the available space and the minimum table width -->
2648
+ <xsl:variable name="W" select="$page_width - $table_widths/table/@width_min"/>
2649
+ <W><xsl:value-of select="$W"/></W>
2650
+ <!-- difference between maximum and minimum width of the table -->
2651
+ <xsl:variable name="D" select="$table_widths/table/@width_max - $table_widths/table/@width_min"/>
2652
+ <D><xsl:value-of select="$D"/></D>
2653
+ <case3/>
2654
+ <autolayout/>
2655
+ <xsl:if test="$table_widths/table/@width_min &gt;= $page_width">
2656
+ <split_keep-within-line>true</split_keep-within-line>
2336
2657
  </xsl:if>
2658
+ <xsl:for-each select="$column_widths/column">
2659
+ <!-- difference between maximum and minimum width of that column. -->
2660
+ <xsl:variable name="d" select="@width_max - @width_min"/>
2661
+ <d><xsl:value-of select="$d"/></d>
2662
+ <width_min><xsl:value-of select="@width_min"/></width_min>
2663
+ <e><xsl:value-of select="$d * $W div $D"/></e>
2664
+ <!-- set the column's width to the minimum width plus d times W over D. -->
2665
+ <column divider="100">
2666
+ <xsl:value-of select="round(@width_min + $d * $W div $D)"/> <!-- * 10 -->
2667
+ </column>
2668
+ </xsl:for-each>
2669
+
2670
+ </xsl:when>
2671
+ <xsl:otherwise><unknown_case/></xsl:otherwise>
2672
+ </xsl:choose>
2673
+
2674
+
2675
+ </xsl:template><xsl:template match="@*|node()" mode="determine_cell_widths">
2676
+ <xsl:copy>
2677
+ <xsl:apply-templates select="@*|node()" mode="determine_cell_widths"/>
2678
+ </xsl:copy>
2679
+ </xsl:template><xsl:template match="td | th" mode="determine_cell_widths">
2680
+ <xsl:copy>
2681
+ <xsl:copy-of select="@*"/>
2682
+
2683
+ <!-- The maximum width is given by the widest line. -->
2684
+ <xsl:variable name="widths_max">
2685
+ <xsl:for-each select=".//*[local-name() = 'p']">
2686
+ <xsl:call-template name="add_width"/>
2687
+ </xsl:for-each>
2688
+ <xsl:if test="not(*[local-name() = 'p'])">
2689
+ <xsl:call-template name="add_width"/>
2690
+ </xsl:if>
2691
+ </xsl:variable>
2692
+ <xsl:variable name="width_max">
2693
+ <xsl:for-each select="xalan:nodeset($widths_max)//width">
2694
+ <xsl:sort select="." data-type="number" order="descending"/>
2695
+ <xsl:if test="position() = 1"><xsl:value-of select="."/></xsl:if>
2696
+ </xsl:for-each>
2697
+ </xsl:variable>
2698
+ <xsl:attribute name="width_max">
2699
+ <xsl:value-of select="$width_max"/>
2700
+ </xsl:attribute>
2701
+
2702
+ <!-- The minimum width is given by the widest text element (word, image, etc.) -->
2703
+ <!-- To do: image width -->
2704
+ <xsl:variable name="td_text">
2705
+ <xsl:apply-templates select="." mode="td_text"/>
2706
+ </xsl:variable>
2707
+ <xsl:variable name="words">
2708
+ <xsl:variable name="string_with_added_zerospaces">
2709
+ <xsl:call-template name="add-zero-spaces-java">
2710
+ <xsl:with-param name="text" select="$td_text"/>
2711
+ </xsl:call-template>
2712
+ </xsl:variable>
2713
+ <xsl:call-template name="tokenize">
2714
+ <xsl:with-param name="text" select="normalize-space(translate($string_with_added_zerospaces, '​­', ' '))"/> <!-- replace zero-width-space and soft-hyphen to space -->
2715
+ </xsl:call-template>
2716
+ </xsl:variable>
2717
+
2718
+ <xsl:variable name="max_word_length">
2719
+ <xsl:call-template name="max_length">
2720
+ <xsl:with-param name="words" select="xalan:nodeset($words)"/>
2721
+ </xsl:call-template>
2722
+ </xsl:variable>
2723
+ <xsl:variable name="width_min">
2724
+ <xsl:value-of select="$max_word_length"/>
2725
+ </xsl:variable>
2726
+ <xsl:attribute name="width_min">
2727
+ <xsl:value-of select="$width_min"/>
2728
+ </xsl:attribute>
2729
+ <!-- width_max="1" width_min="1.5"> --> <!-- see 'tokenize' template, multiply 1.5 for all latin capitals -->
2730
+ <xsl:if test="$width_min &gt; $width_max">
2731
+ <xsl:attribute name="width_max">
2732
+ <xsl:value-of select="$width_min"/>
2733
+ </xsl:attribute>
2734
+ </xsl:if>
2735
+ <xsl:if test="$width_min = 0">
2736
+ <xsl:attribute name="width_min">1</xsl:attribute>
2737
+ </xsl:if>
2738
+
2739
+ <xsl:apply-templates select="node()" mode="determine_cell_widths"/>
2740
+
2741
+ </xsl:copy>
2742
+ </xsl:template><xsl:template name="add_width">
2743
+ <xsl:variable name="p_text"><xsl:apply-templates select="." mode="td_text"/></xsl:variable>
2744
+ <xsl:variable name="p_text_len_" select="string-length(normalize-space($p_text))"/>
2745
+
2746
+ <xsl:variable name="p_text_len">
2747
+ <xsl:choose>
2748
+ <xsl:when test="normalize-space(translate($p_text, concat($upper,'0123456789'), '')) = ''"> <!-- english word in CAPITAL letters -->
2749
+ <xsl:value-of select="$p_text_len_ * 1.5"/>
2750
+ </xsl:when>
2751
+ <xsl:otherwise><xsl:value-of select="$p_text_len_"/></xsl:otherwise>
2752
+ </xsl:choose>
2753
+ </xsl:variable>
2754
+
2755
+ <xsl:variable name="math_addon_text">
2756
+ <xsl:for-each select=".//*[local-name() = 'math']">
2757
+ <xsl:apply-templates mode="td_text"/>
2337
2758
  </xsl:for-each>
2338
2759
  </xsl:variable>
2760
+ <xsl:variable name="math_addon_length" select="string-length(normalize-space($math_addon_text)) * 0.2"/> <!-- plus 20% -->
2339
2761
 
2340
- <xsl:variable name="math_text" select="normalize-space(xalan:nodeset($mathml))"/>
2341
- <xsl:value-of select="translate($math_text, ' ', '#')"/><!-- mathml images as one 'word' without spaces -->
2762
+ <width><xsl:value-of select="$p_text_len + $math_addon_length"/></width>
2763
+ </xsl:template><xsl:template match="@*|node()" mode="determine_cell_widths-if">
2764
+ <xsl:copy>
2765
+ <xsl:apply-templates select="@*|node()" mode="determine_cell_widths-if"/>
2766
+ </xsl:copy>
2767
+ </xsl:template><xsl:template match="td | th" mode="determine_cell_widths-if">
2768
+ <xsl:copy>
2769
+ <xsl:copy-of select="@*"/>
2770
+
2771
+ <!-- The maximum width is given by the widest line. -->
2772
+ <xsl:attribute name="width_max">
2773
+ <xsl:for-each select="p_len">
2774
+ <xsl:sort select="." data-type="number" order="descending"/>
2775
+ <xsl:if test="position() = 1"><xsl:value-of select="."/></xsl:if>
2776
+ </xsl:for-each>
2777
+ </xsl:attribute>
2778
+
2779
+ <!-- The minimum width is given by the widest text element (word, image, etc.) -->
2780
+ <xsl:variable name="width_min">
2781
+ <xsl:for-each select="word_len">
2782
+ <xsl:sort select="." data-type="number" order="descending"/>
2783
+ <xsl:if test="position() = 1"><xsl:value-of select="."/></xsl:if>
2784
+ </xsl:for-each>
2785
+ </xsl:variable>
2786
+ <xsl:attribute name="width_min">
2787
+ <xsl:value-of select="$width_min"/>
2788
+ </xsl:attribute>
2789
+
2790
+ <xsl:if test="$width_min = 0">
2791
+ <xsl:attribute name="width_min">1</xsl:attribute>
2792
+ </xsl:if>
2793
+
2794
+ <xsl:apply-templates select="node()" mode="determine_cell_widths-if"/>
2795
+
2796
+ </xsl:copy>
2342
2797
  </xsl:template><xsl:template match="*[local-name()='thead']">
2343
2798
  <xsl:param name="cols-count"/>
2344
2799
  <fo:table-header>
@@ -2423,16 +2878,10 @@
2423
2878
  </xsl:for-each>
2424
2879
  </xsl:when>
2425
2880
  <xsl:otherwise>
2426
- <xsl:for-each select="xalan:nodeset($colwidths)//column">
2427
- <xsl:choose>
2428
- <xsl:when test=". = 1 or . = 0">
2429
- <fo:table-column column-width="proportional-column-width(2)"/>
2430
- </xsl:when>
2431
- <xsl:otherwise>
2432
- <fo:table-column column-width="proportional-column-width({.})"/>
2433
- </xsl:otherwise>
2434
- </xsl:choose>
2435
- </xsl:for-each>
2881
+ <!-- $colwidths=<xsl:copy-of select="$colwidths"/> -->
2882
+ <xsl:call-template name="insertTableColumnWidth">
2883
+ <xsl:with-param name="colwidths" select="$colwidths"/>
2884
+ </xsl:call-template>
2436
2885
  </xsl:otherwise>
2437
2886
  </xsl:choose>
2438
2887
 
@@ -2509,6 +2958,52 @@
2509
2958
 
2510
2959
  </fo:table-body>
2511
2960
 
2961
+ </xsl:template><xsl:template match="/" mode="process_table-if">
2962
+ <xsl:param name="table_or_dl">table</xsl:param>
2963
+ <xsl:apply-templates mode="process_table-if">
2964
+ <xsl:with-param name="table_or_dl" select="$table_or_dl"/>
2965
+ </xsl:apply-templates>
2966
+ </xsl:template><xsl:template match="*[local-name()='tbody']" mode="process_table-if">
2967
+ <xsl:param name="table_or_dl">table</xsl:param>
2968
+
2969
+ <fo:table-body>
2970
+ <xsl:for-each select="*[local-name() = 'tr']">
2971
+ <xsl:variable name="col_count" select="count(*)"/>
2972
+
2973
+ <!-- iteration for each tr/td -->
2974
+
2975
+ <xsl:choose>
2976
+ <xsl:when test="$table_or_dl = 'table'">
2977
+ <xsl:for-each select="*[local-name() = 'td' or local-name() = 'th']/*">
2978
+ <fo:table-row number-columns-spanned="{$col_count}">
2979
+ <!-- <test_table><xsl:copy-of select="."/></test_table> -->
2980
+ <xsl:call-template name="td"/>
2981
+ </fo:table-row>
2982
+ </xsl:for-each>
2983
+ </xsl:when>
2984
+ <xsl:otherwise> <!-- $table_or_dl = 'dl' -->
2985
+ <xsl:for-each select="*[local-name() = 'td' or local-name() = 'th']">
2986
+ <xsl:variable name="is_dt" select="position() = 1"/>
2987
+
2988
+ <xsl:for-each select="*">
2989
+ <!-- <test><xsl:copy-of select="."/></test> -->
2990
+ <fo:table-row number-columns-spanned="{$col_count}">
2991
+ <xsl:choose>
2992
+ <xsl:when test="$is_dt">
2993
+ <xsl:call-template name="insert_dt_cell"/>
2994
+ </xsl:when>
2995
+ <xsl:otherwise>
2996
+ <xsl:call-template name="insert_dd_cell"/>
2997
+ </xsl:otherwise>
2998
+ </xsl:choose>
2999
+ </fo:table-row>
3000
+ </xsl:for-each>
3001
+ </xsl:for-each>
3002
+ </xsl:otherwise>
3003
+ </xsl:choose>
3004
+
3005
+ </xsl:for-each>
3006
+ </fo:table-body>
2512
3007
  </xsl:template><xsl:template match="*[local-name()='thead']/*[local-name()='tr']" priority="2">
2513
3008
  <fo:table-row xsl:use-attribute-sets="table-header-row-style">
2514
3009
 
@@ -2595,7 +3090,7 @@
2595
3090
  </xsl:choose>
2596
3091
  </xsl:attribute>
2597
3092
  </xsl:if>
2598
- </xsl:template><xsl:template match="*[local-name()='td']">
3093
+ </xsl:template><xsl:template match="*[local-name()='td']" name="td">
2599
3094
  <fo:table-cell xsl:use-attribute-sets="table-cell-style"> <!-- text-align="{@align}" -->
2600
3095
  <xsl:call-template name="setTextAlignment">
2601
3096
  <xsl:with-param name="default">left</xsl:with-param>
@@ -2629,11 +3124,24 @@
2629
3124
 
2630
3125
  <xsl:call-template name="setTableCellAttributes"/>
2631
3126
 
3127
+ <xsl:if test="$isGenerateTableIF = 'true'">
3128
+ <xsl:attribute name="border">1pt solid black</xsl:attribute> <!-- border is mandatory, to determine page width -->
3129
+ <xsl:attribute name="text-align">left</xsl:attribute>
3130
+ </xsl:if>
3131
+
2632
3132
  <fo:block>
2633
3133
 
3134
+ <xsl:if test="$isGenerateTableIF = 'true'">
3135
+ <xsl:attribute name="id"><xsl:value-of select="@id"/></xsl:attribute>
3136
+ </xsl:if>
3137
+
3138
+
2634
3139
 
2635
3140
 
2636
3141
  <xsl:apply-templates/>
3142
+
3143
+ <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"/> -->
3144
+
2637
3145
  </fo:block>
2638
3146
  </fo:table-cell>
2639
3147
  </xsl:template><xsl:template match="*[local-name()='table']/*[local-name()='note']" priority="2">
@@ -2830,9 +3338,9 @@
2830
3338
  <!-- current hierarchy is 'figure' element -->
2831
3339
  <xsl:variable name="following_dl_colwidths">
2832
3340
  <xsl:if test="*[local-name() = 'dl']"><!-- if there is a 'dl', then set the same columns width as for 'dl' -->
2833
- <xsl:variable name="html-table">
2834
- <xsl:variable name="doc_ns">
2835
-
3341
+ <xsl:variable name="simple-table">
3342
+ <!-- <xsl:variable name="doc_ns">
3343
+ <xsl:if test="$namespace = 'bipm'">bipm</xsl:if>
2836
3344
  </xsl:variable>
2837
3345
  <xsl:variable name="ns">
2838
3346
  <xsl:choose>
@@ -2843,7 +3351,7 @@
2843
3351
  <xsl:value-of select="substring-before(name(/*), '-')"/>
2844
3352
  </xsl:otherwise>
2845
3353
  </xsl:choose>
2846
- </xsl:variable>
3354
+ </xsl:variable> -->
2847
3355
 
2848
3356
  <xsl:for-each select="*[local-name() = 'dl'][1]">
2849
3357
  <tbody>
@@ -2854,7 +3362,7 @@
2854
3362
 
2855
3363
  <xsl:call-template name="calculate-column-widths">
2856
3364
  <xsl:with-param name="cols-count" select="2"/>
2857
- <xsl:with-param name="table" select="$html-table"/>
3365
+ <xsl:with-param name="table" select="$simple-table"/>
2858
3366
  </xsl:call-template>
2859
3367
 
2860
3368
  </xsl:if>
@@ -2973,8 +3481,10 @@
2973
3481
  <!-- and (not(../@class) or ../@class !='pseudocode') -->
2974
3482
  </xsl:variable>
2975
3483
 
3484
+ <xsl:variable name="onlyOneComponent" select="normalize-space($parent = 'formula' and count(*[local-name()='dt']) = 1)"/>
3485
+
2976
3486
  <xsl:choose>
2977
- <xsl:when test="$parent = 'formula' and count(*[local-name()='dt']) = 1"> <!-- only one component -->
3487
+ <xsl:when test="$onlyOneComponent = 'true'"> <!-- only one component -->
2978
3488
 
2979
3489
  <fo:block margin-bottom="12pt" text-align="left">
2980
3490
 
@@ -2989,7 +3499,7 @@
2989
3499
  <xsl:apply-templates select="*[local-name()='dd']/*" mode="inline"/>
2990
3500
  </fo:block>
2991
3501
 
2992
- </xsl:when>
3502
+ </xsl:when> <!-- END: only one component -->
2993
3503
  <xsl:when test="$parent = 'formula'"> <!-- a few components -->
2994
3504
  <fo:block margin-bottom="12pt" text-align="left">
2995
3505
 
@@ -3003,8 +3513,8 @@
3003
3513
  </xsl:variable>
3004
3514
  <xsl:value-of select="$title-where"/>
3005
3515
  </fo:block>
3006
- </xsl:when>
3007
- <xsl:when test="$parent = 'figure' and (not(../@class) or ../@class !='pseudocode')">
3516
+ </xsl:when> <!-- END: a few components -->
3517
+ <xsl:when test="$parent = 'figure' and (not(../@class) or ../@class !='pseudocode')"> <!-- definition list in a figure -->
3008
3518
  <fo:block font-weight="bold" text-align="left" margin-bottom="12pt" keep-with-next="always">
3009
3519
 
3010
3520
 
@@ -3017,11 +3527,11 @@
3017
3527
  </xsl:variable>
3018
3528
  <xsl:value-of select="$title-key"/>
3019
3529
  </fo:block>
3020
- </xsl:when>
3530
+ </xsl:when> <!-- END: definition list in a figure -->
3021
3531
  </xsl:choose>
3022
3532
 
3023
3533
  <!-- a few components -->
3024
- <xsl:if test="not($parent = 'formula' and count(*[local-name()='dt']) = 1)">
3534
+ <xsl:if test="$onlyOneComponent = 'false'">
3025
3535
  <fo:block>
3026
3536
 
3027
3537
 
@@ -3032,7 +3542,18 @@
3032
3542
 
3033
3543
 
3034
3544
 
3545
+
3546
+ <xsl:if test="$isGenerateTableIF = 'true'">
3547
+ <!-- to determine start of table -->
3548
+ <fo:block id="{concat('table_if_start_',@id)}" keep-with-next="always" font-size="1pt">Start table '<xsl:value-of select="@id"/>'.</fo:block>
3549
+ </xsl:if>
3550
+
3035
3551
  <fo:table width="95%" table-layout="fixed">
3552
+
3553
+ <xsl:if test="$isGenerateTableIF = 'true'">
3554
+ <xsl:attribute name="wrap-option">no-wrap</xsl:attribute>
3555
+ </xsl:if>
3556
+
3036
3557
 
3037
3558
  <xsl:choose>
3038
3559
  <xsl:when test="normalize-space($key_iso) = 'true' and $parent = 'formula'"/>
@@ -3041,54 +3562,143 @@
3041
3562
 
3042
3563
  </xsl:when>
3043
3564
  </xsl:choose>
3044
- <!-- create virtual html table for dl/[dt and dd] -->
3045
- <xsl:variable name="html-table">
3046
- <xsl:variable name="doc_ns">
3565
+
3566
+
3567
+ <xsl:choose>
3568
+ <xsl:when test="$isGenerateTableIF = 'true'">
3569
+ <!-- generate IF for table widths -->
3570
+ <!-- example:
3571
+ <tr>
3572
+ <td valign="top" align="left" id="tab-symdu_1_1">
3573
+ <p>Symbol</p>
3574
+ <word id="tab-symdu_1_1_word_1">Symbol</word>
3575
+ </td>
3576
+ <td valign="top" align="left" id="tab-symdu_1_2">
3577
+ <p>Description</p>
3578
+ <word id="tab-symdu_1_2_word_1">Description</word>
3579
+ </td>
3580
+ </tr>
3581
+ -->
3047
3582
 
3048
- </xsl:variable>
3049
- <xsl:variable name="ns">
3050
- <xsl:choose>
3051
- <xsl:when test="normalize-space($doc_ns) != ''">
3052
- <xsl:value-of select="normalize-space($doc_ns)"/>
3053
- </xsl:when>
3054
- <xsl:otherwise>
3055
- <xsl:value-of select="substring-before(name(/*), '-')"/>
3056
- </xsl:otherwise>
3057
- </xsl:choose>
3058
- </xsl:variable>
3059
- <tbody>
3060
- <xsl:apply-templates mode="dl"/>
3061
- </tbody>
3062
- </xsl:variable>
3063
- <!-- html-table<xsl:copy-of select="$html-table"/> -->
3064
- <xsl:variable name="colwidths">
3065
- <xsl:call-template name="calculate-column-widths">
3066
- <xsl:with-param name="cols-count" select="2"/>
3067
- <xsl:with-param name="table" select="$html-table"/>
3068
- </xsl:call-template>
3069
- </xsl:variable>
3070
- <!-- colwidths=<xsl:copy-of select="$colwidths"/> -->
3071
- <xsl:variable name="maxlength_dt">
3072
- <xsl:call-template name="getMaxLength_dt"/>
3073
- </xsl:variable>
3074
- <xsl:call-template name="setColumnWidth_dl">
3075
- <xsl:with-param name="colwidths" select="$colwidths"/>
3076
- <xsl:with-param name="maxlength_dt" select="$maxlength_dt"/>
3077
- </xsl:call-template>
3078
- <fo:table-body>
3079
- <xsl:apply-templates>
3080
- <xsl:with-param name="key_iso" select="normalize-space($key_iso)"/>
3081
- </xsl:apply-templates>
3082
- </fo:table-body>
3583
+ <!-- create virtual html table for dl/[dt and dd] -->
3584
+ <xsl:variable name="simple-table">
3585
+
3586
+ <xsl:variable name="dl_table">
3587
+ <tbody>
3588
+ <xsl:apply-templates mode="dl_if">
3589
+ <xsl:with-param name="id" select="@id"/>
3590
+ </xsl:apply-templates>
3591
+ </tbody>
3592
+ </xsl:variable>
3593
+
3594
+ <!-- dl_table='<xsl:copy-of select="$dl_table"/>' -->
3595
+
3596
+ <!-- Step: replace <br/> to <p>...</p> -->
3597
+ <xsl:variable name="table_without_br">
3598
+ <xsl:apply-templates select="xalan:nodeset($dl_table)" mode="table-without-br"/>
3599
+ </xsl:variable>
3600
+
3601
+ <!-- table_without_br='<xsl:copy-of select="$table_without_br"/>' -->
3602
+
3603
+ <!-- Step: add id to each cell -->
3604
+ <!-- add <word>...</word> for each word, image, math -->
3605
+ <xsl:variable name="simple-table-id">
3606
+ <xsl:apply-templates select="xalan:nodeset($table_without_br)" mode="simple-table-id">
3607
+ <xsl:with-param name="id" select="@id"/>
3608
+ </xsl:apply-templates>
3609
+ </xsl:variable>
3610
+
3611
+ <!-- simple-table-id='<xsl:copy-of select="$simple-table-id"/>' -->
3612
+
3613
+ <xsl:copy-of select="xalan:nodeset($simple-table-id)"/>
3614
+
3615
+ </xsl:variable>
3616
+
3617
+ <!-- DEBUG: simple-table<xsl:copy-of select="$simple-table"/> -->
3618
+
3619
+ <xsl:apply-templates select="xalan:nodeset($simple-table)" mode="process_table-if">
3620
+ <xsl:with-param name="table_or_dl">dl</xsl:with-param>
3621
+ </xsl:apply-templates>
3622
+
3623
+ </xsl:when>
3624
+ <xsl:otherwise>
3625
+
3626
+ <xsl:variable name="simple-table">
3627
+
3628
+ <xsl:variable name="dl_table">
3629
+ <tbody>
3630
+ <xsl:apply-templates mode="dl">
3631
+ <xsl:with-param name="id" select="@id"/>
3632
+ </xsl:apply-templates>
3633
+ </tbody>
3634
+ </xsl:variable>
3635
+
3636
+ <xsl:copy-of select="$dl_table"/>
3637
+ </xsl:variable>
3638
+
3639
+ <xsl:variable name="colwidths">
3640
+ <xsl:call-template name="calculate-column-widths">
3641
+ <xsl:with-param name="cols-count" select="2"/>
3642
+ <xsl:with-param name="table" select="$simple-table"/>
3643
+ </xsl:call-template>
3644
+ </xsl:variable>
3645
+
3646
+ <!-- <xsl:text disable-output-escaping="yes">&lt;!- -</xsl:text>
3647
+ DEBUG
3648
+ colwidths=<xsl:copy-of select="$colwidths"/>
3649
+ <xsl:text disable-output-escaping="yes">- -&gt;</xsl:text> -->
3650
+
3651
+ <!-- colwidths=<xsl:copy-of select="$colwidths"/> -->
3652
+
3653
+ <xsl:variable name="maxlength_dt">
3654
+ <xsl:call-template name="getMaxLength_dt"/>
3655
+ </xsl:variable>
3656
+
3657
+ <xsl:variable name="isContainsKeepTogetherTag_">
3658
+ false
3659
+ </xsl:variable>
3660
+ <xsl:variable name="isContainsKeepTogetherTag" select="normalize-space($isContainsKeepTogetherTag_)"/>
3661
+ <!-- isContainsExpressReference=<xsl:value-of select="$isContainsExpressReference"/> -->
3662
+
3663
+
3664
+ <xsl:call-template name="setColumnWidth_dl">
3665
+ <xsl:with-param name="colwidths" select="$colwidths"/>
3666
+ <xsl:with-param name="maxlength_dt" select="$maxlength_dt"/>
3667
+ <xsl:with-param name="isContainsKeepTogetherTag" select="$isContainsKeepTogetherTag"/>
3668
+ </xsl:call-template>
3669
+
3670
+ <fo:table-body>
3671
+
3672
+ <!-- DEBUG -->
3673
+ <xsl:if test="$table_if_debug = 'true'">
3674
+ <fo:table-row>
3675
+ <fo:table-cell number-columns-spanned="2" font-size="60%">
3676
+ <xsl:apply-templates select="xalan:nodeset($colwidths)" mode="print_as_xml"/>
3677
+ </fo:table-cell>
3678
+ </fo:table-row>
3679
+ </xsl:if>
3680
+
3681
+ <xsl:apply-templates>
3682
+ <xsl:with-param name="key_iso" select="normalize-space($key_iso)"/>
3683
+ <xsl:with-param name="split_keep-within-line" select="xalan:nodeset($colwidths)/split_keep-within-line"/>
3684
+ </xsl:apply-templates>
3685
+
3686
+ </fo:table-body>
3687
+ </xsl:otherwise>
3688
+ </xsl:choose>
3083
3689
  </fo:table>
3084
3690
  </fo:block>
3085
3691
  </fo:block>
3086
- </xsl:if>
3692
+ </xsl:if> <!-- END: a few components -->
3087
3693
  </fo:block-container>
3088
3694
  </fo:block-container>
3089
3695
  </xsl:template><xsl:template name="setColumnWidth_dl">
3090
3696
  <xsl:param name="colwidths"/>
3091
3697
  <xsl:param name="maxlength_dt"/>
3698
+ <xsl:param name="isContainsKeepTogetherTag"/>
3699
+
3700
+ <!-- <colwidths><xsl:copy-of select="$colwidths"/></colwidths> -->
3701
+
3092
3702
  <xsl:choose>
3093
3703
  <xsl:when test="ancestor::*[local-name()='dl']"><!-- second level, i.e. inlined table -->
3094
3704
  <fo:table-column column-width="50%"/>
@@ -3096,6 +3706,16 @@
3096
3706
  </xsl:when>
3097
3707
  <xsl:otherwise>
3098
3708
  <xsl:choose>
3709
+ <xsl:when test="xalan:nodeset($colwidths)/autolayout">
3710
+ <xsl:call-template name="insertTableColumnWidth">
3711
+ <xsl:with-param name="colwidths" select="$colwidths"/>
3712
+ </xsl:call-template>
3713
+ </xsl:when>
3714
+ <xsl:when test="$isContainsKeepTogetherTag">
3715
+ <xsl:call-template name="insertTableColumnWidth">
3716
+ <xsl:with-param name="colwidths" select="$colwidths"/>
3717
+ </xsl:call-template>
3718
+ </xsl:when>
3099
3719
  <!-- to set width check most wide chars like `W` -->
3100
3720
  <xsl:when test="normalize-space($maxlength_dt) != '' and number($maxlength_dt) &lt;= 2"> <!-- if dt contains short text like t90, a, etc -->
3101
3721
  <fo:table-column column-width="7%"/>
@@ -3126,20 +3746,31 @@
3126
3746
  <fo:table-column column-width="60%"/>
3127
3747
  </xsl:when>
3128
3748
  <xsl:otherwise>
3129
- <xsl:for-each select="xalan:nodeset($colwidths)//column">
3130
- <xsl:choose>
3131
- <xsl:when test=". = 1 or . = 0">
3132
- <fo:table-column column-width="proportional-column-width(2)"/>
3133
- </xsl:when>
3134
- <xsl:otherwise>
3135
- <fo:table-column column-width="proportional-column-width({.})"/>
3136
- </xsl:otherwise>
3137
- </xsl:choose>
3138
- </xsl:for-each>
3749
+ <xsl:call-template name="insertTableColumnWidth">
3750
+ <xsl:with-param name="colwidths" select="$colwidths"/>
3751
+ </xsl:call-template>
3139
3752
  </xsl:otherwise>
3140
3753
  </xsl:choose>
3141
3754
  </xsl:otherwise>
3142
3755
  </xsl:choose>
3756
+ </xsl:template><xsl:template name="insertTableColumnWidth">
3757
+ <xsl:param name="colwidths"/>
3758
+
3759
+ <xsl:for-each select="xalan:nodeset($colwidths)//column">
3760
+ <xsl:choose>
3761
+ <xsl:when test=". = 1 or . = 0">
3762
+ <fo:table-column column-width="proportional-column-width(2)"/>
3763
+ </xsl:when>
3764
+ <xsl:otherwise>
3765
+ <!-- <fo:table-column column-width="proportional-column-width({.})"/> -->
3766
+ <xsl:variable name="divider">
3767
+ <xsl:value-of select="@divider"/>
3768
+ <xsl:if test="not(@divider)">1</xsl:if>
3769
+ </xsl:variable>
3770
+ <fo:table-column column-width="proportional-column-width({round(. div $divider)})"/>
3771
+ </xsl:otherwise>
3772
+ </xsl:choose>
3773
+ </xsl:for-each>
3143
3774
  </xsl:template><xsl:template name="getMaxLength_dt">
3144
3775
  <xsl:variable name="lengths">
3145
3776
  <xsl:for-each select="*[local-name()='dt']">
@@ -3163,7 +3794,6 @@
3163
3794
  <xsl:value-of select="$maxLength"/>
3164
3795
  </xsl:template><xsl:template match="*[local-name()='dl']/*[local-name()='note']" priority="2">
3165
3796
  <xsl:param name="key_iso"/>
3166
-
3167
3797
  <!-- <tr>
3168
3798
  <td>NOTE</td>
3169
3799
  <td>
@@ -3171,27 +3801,47 @@
3171
3801
  </td>
3172
3802
  </tr>
3173
3803
  -->
3174
- <fo:table-row>
3804
+ <!-- OLD Variant -->
3805
+ <!-- <fo:table-row>
3175
3806
  <fo:table-cell>
3176
3807
  <fo:block margin-top="6pt">
3177
3808
  <xsl:if test="normalize-space($key_iso) = 'true'">
3178
3809
  <xsl:attribute name="margin-top">0</xsl:attribute>
3179
3810
  </xsl:if>
3180
- <xsl:apply-templates select="*[local-name() = 'name']"/>
3811
+ <xsl:apply-templates select="*[local-name() = 'name']" />
3181
3812
  </fo:block>
3182
3813
  </fo:table-cell>
3183
3814
  <fo:table-cell>
3184
3815
  <fo:block>
3185
- <xsl:apply-templates select="node()[not(local-name() = 'name')]"/>
3816
+ <xsl:apply-templates select="node()[not(local-name() = 'name')]" />
3817
+ </fo:block>
3818
+ </fo:table-cell>
3819
+ </fo:table-row> -->
3820
+ <!-- <tr>
3821
+ <td number-columns-spanned="2">NOTE <xsl:apply-templates /> </td>
3822
+ </tr>
3823
+ -->
3824
+ <fo:table-row>
3825
+ <fo:table-cell number-columns-spanned="2">
3826
+ <fo:block>
3827
+ <xsl:call-template name="note"/>
3186
3828
  </fo:block>
3187
3829
  </fo:table-cell>
3188
3830
  </fo:table-row>
3189
3831
  </xsl:template><xsl:template match="*[local-name()='dt']" mode="dl">
3832
+ <xsl:param name="id"/>
3833
+ <xsl:variable name="row_number" select="count(preceding-sibling::*[local-name()='dt']) + 1"/>
3190
3834
  <tr>
3191
3835
  <td>
3836
+ <xsl:attribute name="id">
3837
+ <xsl:value-of select="concat($id,'_',$row_number,'_1')"/>
3838
+ </xsl:attribute>
3192
3839
  <xsl:apply-templates/>
3193
3840
  </td>
3194
3841
  <td>
3842
+ <xsl:attribute name="id">
3843
+ <xsl:value-of select="concat($id,'_',$row_number,'_2')"/>
3844
+ </xsl:attribute>
3195
3845
 
3196
3846
  <xsl:apply-templates select="following-sibling::*[local-name()='dd'][1]">
3197
3847
  <xsl:with-param name="process">true</xsl:with-param>
@@ -3202,50 +3852,122 @@
3202
3852
 
3203
3853
  </xsl:template><xsl:template match="*[local-name()='dt']">
3204
3854
  <xsl:param name="key_iso"/>
3855
+ <xsl:param name="split_keep-within-line"/>
3205
3856
 
3206
3857
  <fo:table-row xsl:use-attribute-sets="dt-row-style">
3207
- <fo:table-cell>
3858
+ <xsl:call-template name="insert_dt_cell">
3859
+ <xsl:with-param name="key_iso" select="$key_iso"/>
3860
+ <xsl:with-param name="split_keep-within-line" select="$split_keep-within-line"/>
3861
+ </xsl:call-template>
3862
+ <xsl:for-each select="following-sibling::*[local-name()='dd'][1]">
3863
+ <xsl:call-template name="insert_dd_cell">
3864
+ <xsl:with-param name="split_keep-within-line" select="$split_keep-within-line"/>
3865
+ </xsl:call-template>
3866
+ </xsl:for-each>
3867
+ </fo:table-row>
3868
+ </xsl:template><xsl:template name="insert_dt_cell">
3869
+ <xsl:param name="key_iso"/>
3870
+ <xsl:param name="split_keep-within-line"/>
3871
+ <fo:table-cell xsl:use-attribute-sets="dt-cell-style">
3872
+
3873
+ <xsl:if test="$isGenerateTableIF = 'true'">
3874
+ <!-- border is mandatory, to calculate real width -->
3875
+ <xsl:attribute name="border">0.1pt solid black</xsl:attribute>
3876
+ <xsl:attribute name="text-align">left</xsl:attribute>
3877
+ </xsl:if>
3878
+
3879
+
3880
+ <fo:block xsl:use-attribute-sets="dt-block-style">
3881
+ <xsl:copy-of select="@id"/>
3882
+
3883
+ <xsl:if test="normalize-space($key_iso) = 'true'">
3884
+ <xsl:attribute name="margin-top">0</xsl:attribute>
3885
+ </xsl:if>
3886
+
3887
+
3888
+
3889
+ <xsl:apply-templates>
3890
+ <xsl:with-param name="split_keep-within-line" select="$split_keep-within-line"/>
3891
+ </xsl:apply-templates>
3892
+
3893
+ <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"/> -->
3894
+
3895
+ </fo:block>
3896
+ </fo:table-cell>
3897
+ </xsl:template><xsl:template name="insert_dd_cell">
3898
+ <xsl:param name="split_keep-within-line"/>
3899
+ <fo:table-cell xsl:use-attribute-sets="dd-cell-style">
3900
+
3901
+ <xsl:if test="$isGenerateTableIF = 'true'">
3902
+ <!-- border is mandatory, to calculate real width -->
3903
+ <xsl:attribute name="border">0.1pt solid black</xsl:attribute>
3904
+ </xsl:if>
3905
+
3906
+ <fo:block>
3907
+
3908
+ <xsl:if test="$isGenerateTableIF = 'true'">
3909
+ <xsl:attribute name="id"><xsl:value-of select="@id"/></xsl:attribute>
3910
+ </xsl:if>
3911
+
3208
3912
 
3209
- <fo:block xsl:use-attribute-sets="dt-style">
3210
- <xsl:copy-of select="@id"/>
3211
-
3212
- <xsl:if test="normalize-space($key_iso) = 'true'">
3213
- <xsl:attribute name="margin-top">0</xsl:attribute>
3214
- </xsl:if>
3215
-
3216
-
3217
-
3218
- <xsl:apply-templates/>
3219
- </fo:block>
3220
- </fo:table-cell>
3221
- <fo:table-cell>
3222
- <fo:block>
3223
-
3224
3913
 
3225
- <xsl:apply-templates select="following-sibling::*[local-name()='dd'][1]">
3226
- <xsl:with-param name="process">true</xsl:with-param>
3227
- </xsl:apply-templates>
3228
- </fo:block>
3229
- </fo:table-cell>
3230
- </fo:table-row>
3914
+ <xsl:choose>
3915
+ <xsl:when test="$isGenerateTableIF = 'true'">
3916
+ <xsl:apply-templates> <!-- following-sibling::*[local-name()='dd'][1] -->
3917
+ <xsl:with-param name="process">true</xsl:with-param>
3918
+ </xsl:apply-templates>
3919
+ </xsl:when>
3920
+ <xsl:otherwise>
3921
+ <xsl:apply-templates select="."> <!-- following-sibling::*[local-name()='dd'][1] -->
3922
+ <xsl:with-param name="process">true</xsl:with-param>
3923
+ <xsl:with-param name="split_keep-within-line" select="$split_keep-within-line"/>
3924
+ </xsl:apply-templates>
3925
+ </xsl:otherwise>
3926
+
3927
+ </xsl:choose>
3928
+
3929
+ <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"/> -->
3930
+
3931
+ </fo:block>
3932
+ </fo:table-cell>
3231
3933
  </xsl:template><xsl:template match="*[local-name()='dd']" mode="dl"/><xsl:template match="*[local-name()='dd']" mode="dl_process">
3232
3934
  <xsl:apply-templates/>
3233
3935
  </xsl:template><xsl:template match="*[local-name()='dd']">
3234
3936
  <xsl:param name="process">false</xsl:param>
3937
+ <xsl:param name="split_keep-within-line"/>
3235
3938
  <xsl:if test="$process = 'true'">
3236
3939
  <xsl:apply-templates select="@language"/>
3237
- <xsl:apply-templates/>
3940
+ <xsl:apply-templates>
3941
+ <xsl:with-param name="split_keep-within-line" select="$split_keep-within-line"/>
3942
+ </xsl:apply-templates>
3238
3943
  </xsl:if>
3239
3944
  </xsl:template><xsl:template match="*[local-name()='dd']/*[local-name()='p']" mode="inline">
3240
3945
  <fo:inline><xsl:text> </xsl:text><xsl:apply-templates/></fo:inline>
3241
- </xsl:template><xsl:template match="*[local-name()='em']">
3946
+ </xsl:template><xsl:template match="*[local-name()='dt']" mode="dl_if">
3947
+ <xsl:param name="id"/>
3948
+ <xsl:variable name="row_number" select="count(preceding-sibling::*[local-name()='dt']) + 1"/>
3949
+ <tr>
3950
+ <td>
3951
+ <xsl:copy-of select="node()"/>
3952
+ </td>
3953
+ <td>
3954
+
3955
+ <xsl:copy-of select="following-sibling::*[local-name()='dd'][1]/node()"/>
3956
+
3957
+ </td>
3958
+ </tr>
3959
+
3960
+ </xsl:template><xsl:template match="*[local-name()='dd']" mode="dl_if"/><xsl:template match="*[local-name()='em']">
3242
3961
  <fo:inline font-style="italic">
3243
3962
  <xsl:apply-templates/>
3244
3963
  </fo:inline>
3245
3964
  </xsl:template><xsl:template match="*[local-name()='strong'] | *[local-name()='b']">
3965
+ <xsl:param name="split_keep-within-line"/>
3246
3966
  <fo:inline font-weight="bold">
3247
3967
 
3248
- <xsl:apply-templates/>
3968
+ <xsl:apply-templates>
3969
+ <xsl:with-param name="split_keep-within-line" select="$split_keep-within-line"/>
3970
+ </xsl:apply-templates>
3249
3971
  </fo:inline>
3250
3972
  </xsl:template><xsl:template match="*[local-name()='padding']">
3251
3973
  <fo:inline padding-right="{@value}"> </fo:inline>
@@ -3284,13 +4006,15 @@
3284
4006
  <xsl:choose>
3285
4007
  <xsl:when test="$font-size = 'inherit'"><xsl:value-of select="$font-size"/></xsl:when>
3286
4008
  <xsl:when test="contains($font-size, '%')"><xsl:value-of select="$font-size"/></xsl:when>
3287
- <xsl:when test="ancestor::*[local-name()='note']"><xsl:value-of select="$font-size * 0.91"/>pt</xsl:when>
4009
+ <xsl:when test="ancestor::*[local-name()='note'] or ancestor::*[local-name()='example']"><xsl:value-of select="$font-size * 0.91"/>pt</xsl:when>
3288
4010
  <xsl:otherwise><xsl:value-of select="$font-size"/>pt</xsl:otherwise>
3289
4011
  </xsl:choose>
3290
4012
  </xsl:attribute>
3291
4013
  </xsl:if>
3292
4014
  <xsl:apply-templates/>
3293
4015
  </fo:inline>
4016
+ </xsl:template><xsl:template match="*[local-name()='tt']/text()" priority="2">
4017
+ <xsl:call-template name="add_spaces_to_sourcecode"/>
3294
4018
  </xsl:template><xsl:template match="*[local-name()='underline']">
3295
4019
  <fo:inline text-decoration="underline">
3296
4020
  <xsl:apply-templates/>
@@ -3438,54 +4162,120 @@
3438
4162
  <fo:block break-after="page"/>
3439
4163
  <fo:block> </fo:block>
3440
4164
  <fo:block break-after="page"/>
4165
+ </xsl:template><xsl:template match="*[local-name() = 'span']">
4166
+ <xsl:apply-templates/>
3441
4167
  </xsl:template><xsl:template name="tokenize">
3442
4168
  <xsl:param name="text"/>
3443
4169
  <xsl:param name="separator" select="' '"/>
3444
4170
  <xsl:choose>
4171
+
4172
+ <xsl:when test="$isGenerateTableIF = 'true' and not(contains($text, $separator))">
4173
+ <word><xsl:value-of select="normalize-space($text)"/></word>
4174
+ </xsl:when>
3445
4175
  <xsl:when test="not(contains($text, $separator))">
3446
4176
  <word>
3447
- <xsl:variable name="str_no_en_chars" select="normalize-space(translate($text, $en_chars, ''))"/>
3448
- <xsl:variable name="len_str_no_en_chars" select="string-length($str_no_en_chars)"/>
3449
4177
  <xsl:variable name="len_str_tmp" select="string-length(normalize-space($text))"/>
3450
- <xsl:variable name="len_str">
3451
- <xsl:choose>
3452
- <xsl:when test="normalize-space(translate($text, $upper, '')) = ''"> <!-- english word in CAPITAL letters -->
3453
- <xsl:value-of select="$len_str_tmp * 1.5"/>
3454
- </xsl:when>
3455
- <xsl:otherwise>
3456
- <xsl:value-of select="$len_str_tmp"/>
3457
- </xsl:otherwise>
3458
- </xsl:choose>
3459
- </xsl:variable>
3460
-
3461
- <!-- <xsl:if test="$len_str_no_en_chars div $len_str &gt; 0.8">
3462
- <xsl:message>
3463
- div=<xsl:value-of select="$len_str_no_en_chars div $len_str"/>
3464
- len_str=<xsl:value-of select="$len_str"/>
3465
- len_str_no_en_chars=<xsl:value-of select="$len_str_no_en_chars"/>
3466
- </xsl:message>
3467
- </xsl:if> -->
3468
- <!-- <len_str_no_en_chars><xsl:value-of select="$len_str_no_en_chars"/></len_str_no_en_chars>
3469
- <len_str><xsl:value-of select="$len_str"/></len_str> -->
3470
4178
  <xsl:choose>
3471
- <xsl:when test="$len_str_no_en_chars div $len_str &gt; 0.8"> <!-- means non-english string -->
3472
- <xsl:value-of select="$len_str - $len_str_no_en_chars"/>
4179
+ <xsl:when test="normalize-space(translate($text, 'X', '')) = ''"> <!-- special case for keep-together.within-line -->
4180
+ <xsl:value-of select="$len_str_tmp"/>
3473
4181
  </xsl:when>
3474
4182
  <xsl:otherwise>
3475
- <xsl:value-of select="$len_str"/>
4183
+ <xsl:variable name="str_no_en_chars" select="normalize-space(translate($text, $en_chars, ''))"/>
4184
+ <xsl:variable name="len_str_no_en_chars" select="string-length($str_no_en_chars)"/>
4185
+ <xsl:variable name="len_str">
4186
+ <xsl:choose>
4187
+ <xsl:when test="normalize-space(translate($text, $upper, '')) = ''"> <!-- english word in CAPITAL letters -->
4188
+ <xsl:value-of select="$len_str_tmp * 1.5"/>
4189
+ </xsl:when>
4190
+ <xsl:otherwise>
4191
+ <xsl:value-of select="$len_str_tmp"/>
4192
+ </xsl:otherwise>
4193
+ </xsl:choose>
4194
+ </xsl:variable>
4195
+
4196
+ <!-- <xsl:if test="$len_str_no_en_chars div $len_str &gt; 0.8">
4197
+ <xsl:message>
4198
+ div=<xsl:value-of select="$len_str_no_en_chars div $len_str"/>
4199
+ len_str=<xsl:value-of select="$len_str"/>
4200
+ len_str_no_en_chars=<xsl:value-of select="$len_str_no_en_chars"/>
4201
+ </xsl:message>
4202
+ </xsl:if> -->
4203
+ <!-- <len_str_no_en_chars><xsl:value-of select="$len_str_no_en_chars"/></len_str_no_en_chars>
4204
+ <len_str><xsl:value-of select="$len_str"/></len_str> -->
4205
+ <xsl:choose>
4206
+ <xsl:when test="$len_str_no_en_chars div $len_str &gt; 0.8"> <!-- means non-english string -->
4207
+ <xsl:value-of select="$len_str - $len_str_no_en_chars"/>
4208
+ </xsl:when>
4209
+ <xsl:otherwise>
4210
+ <xsl:value-of select="$len_str"/>
4211
+ </xsl:otherwise>
4212
+ </xsl:choose>
3476
4213
  </xsl:otherwise>
3477
4214
  </xsl:choose>
3478
4215
  </word>
3479
4216
  </xsl:when>
3480
4217
  <xsl:otherwise>
3481
4218
  <word>
3482
- <xsl:value-of select="string-length(normalize-space(substring-before($text, $separator)))"/>
4219
+ <xsl:variable name="word" select="normalize-space(substring-before($text, $separator))"/>
4220
+ <xsl:choose>
4221
+ <xsl:when test="$isGenerateTableIF = 'true'">
4222
+ <xsl:value-of select="$word"/>
4223
+ </xsl:when>
4224
+ <xsl:otherwise>
4225
+ <xsl:value-of select="string-length($word)"/>
4226
+ </xsl:otherwise>
4227
+ </xsl:choose>
3483
4228
  </word>
3484
4229
  <xsl:call-template name="tokenize">
3485
4230
  <xsl:with-param name="text" select="substring-after($text, $separator)"/>
3486
4231
  </xsl:call-template>
3487
4232
  </xsl:otherwise>
3488
4233
  </xsl:choose>
4234
+ </xsl:template><xsl:template name="tokenize_with_tags">
4235
+ <xsl:param name="tags"/>
4236
+ <xsl:param name="text"/>
4237
+ <xsl:param name="separator" select="' '"/>
4238
+ <xsl:choose>
4239
+
4240
+ <xsl:when test="not(contains($text, $separator))">
4241
+ <word>
4242
+ <xsl:call-template name="enclose_text_in_tags">
4243
+ <xsl:with-param name="text" select="normalize-space($text)"/>
4244
+ <xsl:with-param name="tags" select="$tags"/>
4245
+ </xsl:call-template>
4246
+ </word>
4247
+ </xsl:when>
4248
+ <xsl:otherwise>
4249
+ <word>
4250
+ <xsl:call-template name="enclose_text_in_tags">
4251
+ <xsl:with-param name="text" select="normalize-space(substring-before($text, $separator))"/>
4252
+ <xsl:with-param name="tags" select="$tags"/>
4253
+ </xsl:call-template>
4254
+ </word>
4255
+ <xsl:call-template name="tokenize_with_tags">
4256
+ <xsl:with-param name="text" select="substring-after($text, $separator)"/>
4257
+ </xsl:call-template>
4258
+ </xsl:otherwise>
4259
+ </xsl:choose>
4260
+ </xsl:template><xsl:template name="enclose_text_in_tags">
4261
+ <xsl:param name="text"/>
4262
+ <xsl:param name="tags"/>
4263
+ <xsl:param name="num">1</xsl:param> <!-- default (start) value -->
4264
+
4265
+ <xsl:variable name="tag_name" select="normalize-space(xalan:nodeset($tags)//tag[$num])"/>
4266
+
4267
+ <xsl:choose>
4268
+ <xsl:when test="$tag_name = ''"><xsl:value-of select="$text"/></xsl:when>
4269
+ <xsl:otherwise>
4270
+ <xsl:element name="{$tag_name}">
4271
+ <xsl:call-template name="enclose_text_in_tags">
4272
+ <xsl:with-param name="text" select="$text"/>
4273
+ <xsl:with-param name="tags" select="$tags"/>
4274
+ <xsl:with-param name="num" select="$num + 1"/>
4275
+ </xsl:call-template>
4276
+ </xsl:element>
4277
+ </xsl:otherwise>
4278
+ </xsl:choose>
3489
4279
  </xsl:template><xsl:template name="max_length">
3490
4280
  <xsl:param name="words"/>
3491
4281
  <xsl:for-each select="$words//word">
@@ -3558,36 +4348,47 @@
3558
4348
  </xsl:template><xsl:template name="add-zero-spaces-equal">
3559
4349
  <xsl:param name="text" select="."/>
3560
4350
  <xsl:variable name="zero-space-after-equals">==========</xsl:variable>
4351
+ <xsl:variable name="regex_zero-space-after-equals">(==========)</xsl:variable>
3561
4352
  <xsl:variable name="zero-space-after-equal">=</xsl:variable>
4353
+ <xsl:variable name="regex_zero-space-after-equal">(=)</xsl:variable>
3562
4354
  <xsl:variable name="zero-space">​</xsl:variable>
3563
4355
  <xsl:choose>
3564
4356
  <xsl:when test="contains($text, $zero-space-after-equals)">
3565
- <xsl:value-of select="substring-before($text, $zero-space-after-equals)"/>
4357
+ <!-- <xsl:value-of select="substring-before($text, $zero-space-after-equals)"/>
3566
4358
  <xsl:value-of select="$zero-space-after-equals"/>
3567
4359
  <xsl:value-of select="$zero-space"/>
3568
4360
  <xsl:call-template name="add-zero-spaces-equal">
3569
4361
  <xsl:with-param name="text" select="substring-after($text, $zero-space-after-equals)"/>
3570
- </xsl:call-template>
4362
+ </xsl:call-template> -->
4363
+ <xsl:value-of select="java:replaceAll(java:java.lang.String.new(.),$regex_zero-space-after-equals,concat('$1',$zero_width_space))"/>
3571
4364
  </xsl:when>
3572
4365
  <xsl:when test="contains($text, $zero-space-after-equal)">
3573
- <xsl:value-of select="substring-before($text, $zero-space-after-equal)"/>
4366
+ <!-- <xsl:value-of select="substring-before($text, $zero-space-after-equal)"/>
3574
4367
  <xsl:value-of select="$zero-space-after-equal"/>
3575
4368
  <xsl:value-of select="$zero-space"/>
3576
4369
  <xsl:call-template name="add-zero-spaces-equal">
3577
4370
  <xsl:with-param name="text" select="substring-after($text, $zero-space-after-equal)"/>
3578
- </xsl:call-template>
4371
+ </xsl:call-template> -->
4372
+ <xsl:value-of select="java:replaceAll(java:java.lang.String.new(.),$regex_zero-space-after-equal,concat('$1',$zero_width_space))"/>
3579
4373
  </xsl:when>
3580
4374
  <xsl:otherwise>
3581
4375
  <xsl:value-of select="$text"/>
3582
4376
  </xsl:otherwise>
3583
4377
  </xsl:choose>
3584
4378
  </xsl:template><xsl:template name="getSimpleTable">
4379
+ <xsl:param name="id"/>
4380
+
3585
4381
  <xsl:variable name="simple-table">
3586
4382
 
4383
+ <!-- Step 0. replace <br/> to <p>...</p> -->
4384
+ <xsl:variable name="table_without_br">
4385
+ <xsl:apply-templates mode="table-without-br"/>
4386
+ </xsl:variable>
4387
+
3587
4388
  <!-- Step 1. colspan processing -->
3588
4389
  <xsl:variable name="simple-table-colspan">
3589
4390
  <tbody>
3590
- <xsl:apply-templates mode="simple-table-colspan"/>
4391
+ <xsl:apply-templates select="xalan:nodeset($table_without_br)" mode="simple-table-colspan"/>
3591
4392
  </tbody>
3592
4393
  </xsl:variable>
3593
4394
 
@@ -3596,10 +4397,67 @@
3596
4397
  <xsl:apply-templates select="xalan:nodeset($simple-table-colspan)" mode="simple-table-rowspan"/>
3597
4398
  </xsl:variable>
3598
4399
 
3599
- <xsl:copy-of select="xalan:nodeset($simple-table-rowspan)"/>
3600
-
4400
+ <!-- Step 3: add id to each cell -->
4401
+ <!-- add <word>...</word> for each word, image, math -->
4402
+ <xsl:variable name="simple-table-id">
4403
+ <xsl:apply-templates select="xalan:nodeset($simple-table-rowspan)" mode="simple-table-id">
4404
+ <xsl:with-param name="id" select="$id"/>
4405
+ </xsl:apply-templates>
4406
+ </xsl:variable>
4407
+
4408
+ <xsl:copy-of select="xalan:nodeset($simple-table-id)"/>
4409
+
3601
4410
  </xsl:variable>
3602
4411
  <xsl:copy-of select="$simple-table"/>
4412
+ </xsl:template><xsl:template match="@*|node()" mode="table-without-br">
4413
+ <xsl:copy>
4414
+ <xsl:apply-templates select="@*|node()" mode="table-without-br"/>
4415
+ </xsl:copy>
4416
+ </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">
4417
+ <xsl:copy>
4418
+ <xsl:copy-of select="@*"/>
4419
+ <p>
4420
+ <xsl:copy-of select="node()"/>
4421
+ </p>
4422
+ </xsl:copy>
4423
+ </xsl:template><xsl:template match="*[local-name()='th' or local-name()='td'][*[local-name()='br']]" mode="table-without-br">
4424
+ <xsl:copy>
4425
+ <xsl:copy-of select="@*"/>
4426
+ <xsl:for-each select="*[local-name()='br']">
4427
+ <xsl:variable name="current_id" select="generate-id()"/>
4428
+ <p>
4429
+ <xsl:for-each select="preceding-sibling::node()[following-sibling::*[local-name() = 'br'][1][generate-id() = $current_id]][not(local-name() = 'br')]">
4430
+ <xsl:copy-of select="."/>
4431
+ </xsl:for-each>
4432
+ </p>
4433
+ <xsl:if test="not(following-sibling::*[local-name() = 'br'])">
4434
+ <p>
4435
+ <xsl:for-each select="following-sibling::node()">
4436
+ <xsl:copy-of select="."/>
4437
+ </xsl:for-each>
4438
+ </p>
4439
+ </xsl:if>
4440
+ </xsl:for-each>
4441
+ </xsl:copy>
4442
+ </xsl:template><xsl:template match="*[local-name()='th' or local-name()='td']/*[local-name() = 'p'][*[local-name()='br']]" mode="table-without-br">
4443
+ <xsl:for-each select="*[local-name()='br']">
4444
+ <xsl:variable name="current_id" select="generate-id()"/>
4445
+ <p>
4446
+ <xsl:for-each select="preceding-sibling::node()[following-sibling::*[local-name() = 'br'][1][generate-id() = $current_id]][not(local-name() = 'br')]">
4447
+ <xsl:copy-of select="."/>
4448
+ </xsl:for-each>
4449
+ </p>
4450
+ <xsl:if test="not(following-sibling::*[local-name() = 'br'])">
4451
+ <p>
4452
+ <xsl:for-each select="following-sibling::node()">
4453
+ <xsl:copy-of select="."/>
4454
+ </xsl:for-each>
4455
+ </p>
4456
+ </xsl:if>
4457
+ </xsl:for-each>
4458
+ </xsl:template><xsl:template match="text()[not(ancestor::*[local-name() = 'sourcecode'])]" mode="table-without-br">
4459
+ <xsl:variable name="text" select="translate(.,'&#9;&#10;&#13;','')"/>
4460
+ <xsl:value-of select="java:replaceAll(java:java.lang.String.new($text),' {2,}',' ')"/>
3603
4461
  </xsl:template><xsl:template match="*[local-name()='thead'] | *[local-name()='tbody']" mode="simple-table-colspan">
3604
4462
  <xsl:apply-templates mode="simple-table-colspan"/>
3605
4463
  </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">
@@ -3689,6 +4547,126 @@
3689
4547
  <xsl:apply-templates select="following-sibling::tr[1]" mode="simple-table-rowspan">
3690
4548
  <xsl:with-param name="previousRow" select="$newRow"/>
3691
4549
  </xsl:apply-templates>
4550
+ </xsl:template><xsl:template match="/" mode="simple-table-id">
4551
+ <xsl:param name="id"/>
4552
+ <xsl:variable name="id_prefixed" select="concat('table_if_',$id)"/> <!-- table id prefixed by 'table_if_' to simple search in IF -->
4553
+ <xsl:apply-templates select="@*|node()" mode="simple-table-id">
4554
+ <xsl:with-param name="id" select="$id_prefixed"/>
4555
+ </xsl:apply-templates>
4556
+ </xsl:template><xsl:template match="@*|node()" mode="simple-table-id">
4557
+ <xsl:param name="id"/>
4558
+ <xsl:copy>
4559
+ <xsl:apply-templates select="@*|node()" mode="simple-table-id">
4560
+ <xsl:with-param name="id" select="$id"/>
4561
+ </xsl:apply-templates>
4562
+ </xsl:copy>
4563
+ </xsl:template><xsl:template match="*[local-name()='tbody']" mode="simple-table-id">
4564
+ <xsl:param name="id"/>
4565
+ <xsl:copy>
4566
+ <xsl:copy-of select="@*"/>
4567
+ <xsl:attribute name="id"><xsl:value-of select="$id"/></xsl:attribute>
4568
+ <xsl:apply-templates select="node()" mode="simple-table-id">
4569
+ <xsl:with-param name="id" select="$id"/>
4570
+ </xsl:apply-templates>
4571
+ </xsl:copy>
4572
+ </xsl:template><xsl:template match="*[local-name()='th' or local-name()='td']" mode="simple-table-id">
4573
+ <xsl:param name="id"/>
4574
+ <xsl:copy>
4575
+ <xsl:copy-of select="@*"/>
4576
+ <xsl:variable name="row_number" select="count(../preceding-sibling::*) + 1"/>
4577
+ <xsl:variable name="col_number" select="count(preceding-sibling::*) + 1"/>
4578
+ <xsl:attribute name="id">
4579
+ <xsl:value-of select="concat($id,'_',$row_number,'_',$col_number)"/>
4580
+ </xsl:attribute>
4581
+
4582
+ <xsl:for-each select="*[local-name() = 'p']">
4583
+ <xsl:copy>
4584
+ <xsl:copy-of select="@*"/>
4585
+ <xsl:variable name="p_num" select="count(preceding-sibling::*[local-name() = 'p']) + 1"/>
4586
+ <xsl:attribute name="id">
4587
+ <xsl:value-of select="concat($id,'_',$row_number,'_',$col_number,'_p_',$p_num)"/>
4588
+ </xsl:attribute>
4589
+
4590
+ <xsl:copy-of select="node()"/>
4591
+ </xsl:copy>
4592
+ </xsl:for-each>
4593
+
4594
+
4595
+ <xsl:if test="$isGenerateTableIF = 'true'"> <!-- split each paragraph to words, image, math -->
4596
+
4597
+ <xsl:variable name="td_text">
4598
+ <xsl:apply-templates select="." mode="td_text_with_formatting"/>
4599
+ </xsl:variable>
4600
+
4601
+ <!-- td_text='<xsl:copy-of select="$td_text"/>' -->
4602
+
4603
+ <xsl:variable name="words">
4604
+ <xsl:for-each select=".//*[local-name() = 'image' or local-name() = 'stem']">
4605
+ <word>
4606
+ <xsl:copy-of select="."/>
4607
+ </word>
4608
+ </xsl:for-each>
4609
+
4610
+ <xsl:for-each select="xalan:nodeset($td_text)//*[local-name() = 'word'][normalize-space() != '']">
4611
+ <xsl:copy-of select="."/>
4612
+ </xsl:for-each>
4613
+
4614
+ </xsl:variable>
4615
+
4616
+ <xsl:for-each select="xalan:nodeset($words)/word">
4617
+ <xsl:variable name="num" select="count(preceding-sibling::word) + 1"/>
4618
+ <xsl:copy>
4619
+ <xsl:attribute name="id">
4620
+ <xsl:value-of select="concat($id,'_',$row_number,'_',$col_number,'_word_',$num)"/>
4621
+ </xsl:attribute>
4622
+ <xsl:copy-of select="node()"/>
4623
+ </xsl:copy>
4624
+ </xsl:for-each>
4625
+ </xsl:if>
4626
+ </xsl:copy>
4627
+
4628
+ </xsl:template><xsl:template match="@*|node()" mode="td_text_with_formatting">
4629
+ <xsl:copy>
4630
+ <xsl:apply-templates select="@*|node()" mode="td_text_with_formatting"/>
4631
+ </xsl:copy>
4632
+ </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">
4633
+ <xsl:variable name="formatting_tags">
4634
+ <xsl:call-template name="getFormattingTags"/>
4635
+ </xsl:variable>
4636
+ <word>
4637
+ <xsl:call-template name="enclose_text_in_tags">
4638
+ <xsl:with-param name="text" select="normalize-space(.)"/>
4639
+ <xsl:with-param name="tags" select="$formatting_tags"/>
4640
+ </xsl:call-template>
4641
+ </word>
4642
+ </xsl:template><xsl:template match="*[local-name() != 'keep-together_within-line']/text()" mode="td_text_with_formatting">
4643
+
4644
+ <xsl:variable name="td_text" select="."/>
4645
+
4646
+ <xsl:variable name="string_with_added_zerospaces">
4647
+ <xsl:call-template name="add-zero-spaces-java">
4648
+ <xsl:with-param name="text" select="$td_text"/>
4649
+ </xsl:call-template>
4650
+ </xsl:variable>
4651
+
4652
+ <xsl:variable name="formatting_tags">
4653
+ <xsl:call-template name="getFormattingTags"/>
4654
+ </xsl:variable>
4655
+
4656
+ <!-- <word>text</word> -->
4657
+ <xsl:call-template name="tokenize_with_tags">
4658
+ <xsl:with-param name="tags" select="$formatting_tags"/>
4659
+ <xsl:with-param name="text" select="normalize-space(translate($string_with_added_zerospaces, '​­', ' '))"/> <!-- replace zero-width-space and soft-hyphen to space -->
4660
+ </xsl:call-template>
4661
+ </xsl:template><xsl:template name="getFormattingTags">
4662
+ <tags>
4663
+ <xsl:if test="ancestor::*[local-name() = 'strong']"><tag>strong</tag></xsl:if>
4664
+ <xsl:if test="ancestor::*[local-name() = 'em']"><tag>em</tag></xsl:if>
4665
+ <xsl:if test="ancestor::*[local-name() = 'sub']"><tag>sub</tag></xsl:if>
4666
+ <xsl:if test="ancestor::*[local-name() = 'sup']"><tag>sup</tag></xsl:if>
4667
+ <xsl:if test="ancestor::*[local-name() = 'tt']"><tag>tt</tag></xsl:if>
4668
+ <xsl:if test="ancestor::*[local-name() = 'keep-together_within-line']"><tag>keep-together_within-line</tag></xsl:if>
4669
+ </tags>
3692
4670
  </xsl:template><xsl:template name="getLang">
3693
4671
  <xsl:variable name="language_current" select="normalize-space(//*[local-name()='bibdata']//*[local-name()='language'][@current = 'true'])"/>
3694
4672
  <xsl:variable name="language">
@@ -3743,6 +4721,9 @@
3743
4721
  <xsl:variable name="isDeleted" select="@deleted"/>
3744
4722
 
3745
4723
  <fo:inline xsl:use-attribute-sets="mathml-style">
4724
+
4725
+
4726
+
3746
4727
 
3747
4728
 
3748
4729
  <xsl:call-template name="setTrackChangesStyles">
@@ -3750,48 +4731,80 @@
3750
4731
  <xsl:with-param name="isDeleted" select="$isDeleted"/>
3751
4732
  </xsl:call-template>
3752
4733
 
4734
+ <xsl:if test="$add_math_as_text = 'true'">
4735
+ <!-- insert helper tag -->
4736
+ <!-- set unique font-size (fiction) -->
4737
+ <xsl:variable name="font-size_sfx"><xsl:number level="any"/></xsl:variable>
4738
+ <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 -->
4739
+ </xsl:if>
3753
4740
 
3754
-
3755
- <xsl:variable name="mathml">
3756
- <xsl:apply-templates select="." mode="mathml"/>
4741
+ <xsl:variable name="mathml_content">
4742
+ <xsl:apply-templates select="." mode="mathml_actual_text"/>
3757
4743
  </xsl:variable>
3758
- <fo:instream-foreign-object fox:alt-text="Math">
3759
4744
 
4745
+
4746
+ <xsl:call-template name="mathml_instream_object">
4747
+ <xsl:with-param name="mathml_content" select="$mathml_content"/>
4748
+ </xsl:call-template>
3760
4749
 
3761
-
3762
- <xsl:variable name="comment_text_following" select="following-sibling::node()[1][self::comment()]"/>
3763
- <xsl:variable name="comment_text_">
3764
- <xsl:choose>
3765
- <xsl:when test="normalize-space($comment_text_following) != ''">
3766
- <xsl:value-of select="$comment_text_following"/>
3767
- </xsl:when>
3768
- <xsl:otherwise>
3769
- <xsl:value-of select="normalize-space(translate(.,' ⁢',' '))"/>
3770
- </xsl:otherwise>
3771
- </xsl:choose>
3772
- </xsl:variable>
3773
- <xsl:variable name="comment_text" select="java:org.metanorma.fop.Util.unescape($comment_text_)"/>
3774
-
3775
- <xsl:if test="normalize-space($comment_text) != ''">
3776
- <!-- put Mathin Alternate Text -->
3777
- <xsl:attribute name="fox:alt-text">
3778
- <xsl:value-of select="java:org.metanorma.fop.Util.unescape($comment_text)"/>
3779
- </xsl:attribute>
3780
- </xsl:if>
3781
-
3782
- <xsl:variable name="mathml_content">
3783
- <xsl:apply-templates select="." mode="mathml_actual_text"/>
3784
- </xsl:variable>
3785
- <!-- put MathML in Actual Text -->
3786
- <xsl:attribute name="fox:actual-text">
3787
- <xsl:value-of select="$mathml_content"/>
3788
- </xsl:attribute>
3789
-
3790
-
3791
-
3792
- <xsl:copy-of select="xalan:nodeset($mathml)"/>
3793
- </fo:instream-foreign-object>
4750
+
3794
4751
  </fo:inline>
4752
+ </xsl:template><xsl:template name="getMathml_comment_text">
4753
+ <xsl:variable name="comment_text_following" select="following-sibling::node()[1][self::comment()]"/>
4754
+ <xsl:variable name="comment_text_">
4755
+ <xsl:choose>
4756
+ <xsl:when test="normalize-space($comment_text_following) != ''">
4757
+ <xsl:value-of select="$comment_text_following"/>
4758
+ </xsl:when>
4759
+ <xsl:otherwise>
4760
+ <xsl:value-of select="normalize-space(translate(.,' ⁢',' '))"/>
4761
+ </xsl:otherwise>
4762
+ </xsl:choose>
4763
+ </xsl:variable>
4764
+ <xsl:variable name="comment_text_2" select="java:org.metanorma.fop.Util.unescape($comment_text_)"/>
4765
+ <xsl:variable name="comment_text" select="java:trim(java:java.lang.String.new($comment_text_2))"/>
4766
+ <xsl:value-of select="$comment_text"/>
4767
+ </xsl:template><xsl:template name="mathml_instream_object">
4768
+ <xsl:param name="comment_text"/>
4769
+ <xsl:param name="mathml_content"/>
4770
+
4771
+ <xsl:variable name="comment_text_">
4772
+ <xsl:choose>
4773
+ <xsl:when test="normalize-space($comment_text) != ''"><xsl:value-of select="$comment_text"/></xsl:when>
4774
+ <xsl:otherwise><xsl:call-template name="getMathml_comment_text"/></xsl:otherwise>
4775
+ </xsl:choose>
4776
+ </xsl:variable>
4777
+
4778
+ <xsl:variable name="mathml">
4779
+ <xsl:apply-templates select="." mode="mathml"/>
4780
+ </xsl:variable>
4781
+
4782
+ <fo:instream-foreign-object fox:alt-text="Math">
4783
+
4784
+
4785
+
4786
+
4787
+
4788
+
4789
+
4790
+ <!-- put MathML in Actual Text -->
4791
+ <!-- DEBUG: mathml_content=<xsl:value-of select="$mathml_content"/> -->
4792
+ <xsl:attribute name="fox:actual-text">
4793
+ <xsl:value-of select="$mathml_content"/>
4794
+ </xsl:attribute>
4795
+
4796
+ <!-- <xsl:if test="$add_math_as_text = 'true'"> -->
4797
+ <xsl:if test="normalize-space($comment_text_) != ''">
4798
+ <!-- put Mathin Alternate Text -->
4799
+ <xsl:attribute name="fox:alt-text">
4800
+ <xsl:value-of select="$comment_text_"/>
4801
+ </xsl:attribute>
4802
+ </xsl:if>
4803
+ <!-- </xsl:if> -->
4804
+
4805
+ <xsl:copy-of select="xalan:nodeset($mathml)"/>
4806
+
4807
+ </fo:instream-foreign-object>
3795
4808
  </xsl:template><xsl:template match="mathml:*" mode="mathml_actual_text">
3796
4809
  <!-- <xsl:text>a+b</xsl:text> -->
3797
4810
  <xsl:text>&lt;</xsl:text>
@@ -3822,7 +4835,9 @@
3822
4835
  <!-- replace start and end spaces to non-break space -->
3823
4836
  <xsl:value-of select="java:replaceAll(java:java.lang.String.new(.),'(^ )|( $)',' ')"/>
3824
4837
  </xsl:copy>
3825
- </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">
4838
+ </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">
4839
+ <xsl:value-of select="."/><xsl:value-of select="$zero_width_space"/>
4840
+ </xsl:template><xsl:template match="*[local-name()='localityStack']"/><xsl:template match="*[local-name()='link']" name="link">
3826
4841
  <xsl:variable name="target">
3827
4842
  <xsl:choose>
3828
4843
  <xsl:when test="@updatetype = 'true'">
@@ -4051,7 +5066,12 @@
4051
5066
 
4052
5067
  <fo:inline xsl:use-attribute-sets="termnote-name-style">
4053
5068
 
5069
+ <xsl:if test="not(*[local-name() = 'name']/following-sibling::node()[1][self::text()][normalize-space()=''])">
5070
+ <xsl:attribute name="padding-right">1mm</xsl:attribute>
5071
+ </xsl:if>
5072
+
4054
5073
 
5074
+
4055
5075
 
4056
5076
  <!-- if 'p' contains all text in 'add' first and last elements in first p are 'add' -->
4057
5077
  <!-- <xsl:if test="*[not(local-name()='name')][1][node()[normalize-space() != ''][1][local-name() = 'add'] and node()[normalize-space() != ''][last()][local-name() = 'add']]"> -->
@@ -4408,18 +5428,33 @@
4408
5428
  </xsl:template><xsl:template match="*[local-name() = 'svg'][not(@width and @height)]" mode="svg_update">
4409
5429
  <xsl:copy>
4410
5430
  <xsl:apply-templates select="@*" mode="svg_update"/>
4411
- <xsl:variable name="viewbox">
5431
+ <xsl:variable name="viewbox_">
4412
5432
  <xsl:call-template name="split">
4413
5433
  <xsl:with-param name="pText" select="@viewBox"/>
4414
5434
  <xsl:with-param name="sep" select="' '"/>
4415
5435
  </xsl:call-template>
4416
5436
  </xsl:variable>
5437
+ <xsl:variable name="viewbox" select="xalan:nodeset($viewbox_)"/>
5438
+ <xsl:variable name="width" select="normalize-space($viewbox//item[3])"/>
5439
+ <xsl:variable name="height" select="normalize-space($viewbox//item[4])"/>
5440
+
4417
5441
  <xsl:attribute name="width">
4418
- <xsl:value-of select="round(xalan:nodeset($viewbox)//item[3])"/>
5442
+ <xsl:choose>
5443
+ <xsl:when test="$width != ''">
5444
+ <xsl:value-of select="round($width)"/>
5445
+ </xsl:when>
5446
+ <xsl:otherwise>400</xsl:otherwise> <!-- default width -->
5447
+ </xsl:choose>
4419
5448
  </xsl:attribute>
4420
5449
  <xsl:attribute name="height">
4421
- <xsl:value-of select="round(xalan:nodeset($viewbox)//item[4])"/>
5450
+ <xsl:choose>
5451
+ <xsl:when test="$height != ''">
5452
+ <xsl:value-of select="round($height)"/>
5453
+ </xsl:when>
5454
+ <xsl:otherwise>400</xsl:otherwise> <!-- default height -->
5455
+ </xsl:choose>
4422
5456
  </xsl:attribute>
5457
+
4423
5458
  <xsl:apply-templates mode="svg_update"/>
4424
5459
  </xsl:copy>
4425
5460
  </xsl:template><xsl:template match="*[local-name() = 'figure']/*[local-name() = 'image'][*[local-name() = 'svg']]" priority="3">
@@ -4614,7 +5649,11 @@
4614
5649
  <xsl:apply-templates mode="bookmarks"/>
4615
5650
  </xsl:template><xsl:template match="*[local-name() = 'title' or local-name() = 'name']//*[local-name() = 'stem']" mode="contents">
4616
5651
  <xsl:apply-templates select="."/>
4617
- </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">
5652
+ </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">
5653
+ <xsl:apply-templates mode="contents"/>
5654
+ </xsl:template><xsl:template match="*[local-name() = 'stem']" mode="bookmarks">
5655
+ <xsl:apply-templates mode="bookmarks"/>
5656
+ </xsl:template><xsl:template match="*[local-name() = 'span']" mode="bookmarks">
4618
5657
  <xsl:apply-templates mode="bookmarks"/>
4619
5658
  </xsl:template><xsl:template name="addBookmarks">
4620
5659
  <xsl:param name="contents"/>
@@ -4896,7 +5935,9 @@
4896
5935
  <xsl:apply-templates/>
4897
5936
  </xsl:otherwise>
4898
5937
  </xsl:choose>
4899
- </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">
5938
+ </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">
5939
+ <xsl:value-of select="."/>
5940
+ </xsl:template><xsl:template match="*[local-name() = 'tab']" mode="contents_item">
4900
5941
  <xsl:text> </xsl:text>
4901
5942
  </xsl:template><xsl:template match="*[local-name() = 'strong']" mode="contents_item">
4902
5943
  <xsl:copy>
@@ -4927,9 +5968,22 @@
4927
5968
  </xsl:when>
4928
5969
  <xsl:otherwise><xsl:apply-templates mode="contents_item"/></xsl:otherwise>
4929
5970
  </xsl:choose>
5971
+ </xsl:template><xsl:template match="text()" mode="contents_item">
5972
+ <xsl:call-template name="keep_together_standard_number"/>
5973
+ </xsl:template><xsl:template match="*[local-name() = 'span']" mode="contents_item">
5974
+ <xsl:apply-templates mode="contents_item"/>
4930
5975
  </xsl:template><xsl:template match="*[local-name()='sourcecode']" name="sourcecode">
4931
5976
 
4932
5977
  <fo:block-container xsl:use-attribute-sets="sourcecode-container-style">
5978
+
5979
+ <xsl:if test="not(ancestor::*[local-name() = 'li']) or ancestor::*[local-name() = 'example']">
5980
+ <xsl:attribute name="margin-left">0mm</xsl:attribute>
5981
+ </xsl:if>
5982
+
5983
+ <xsl:if test="ancestor::*[local-name() = 'example']">
5984
+ <xsl:attribute name="margin-right">0mm</xsl:attribute>
5985
+ </xsl:if>
5986
+
4933
5987
  <xsl:copy-of select="@id"/>
4934
5988
 
4935
5989
  <xsl:if test="parent::*[local-name() = 'note']">
@@ -5029,17 +6083,15 @@
5029
6083
 
5030
6084
  <!-- split text by zero-width space -->
5031
6085
  <xsl:variable name="text_step4">
5032
- <xsl:call-template name="split">
6086
+ <xsl:call-template name="split_for_interspers">
5033
6087
  <xsl:with-param name="pText" select="$text_step3"/>
5034
6088
  <xsl:with-param name="sep" select="$zero_width_space"/>
5035
- <xsl:with-param name="normalize-space">false</xsl:with-param>
5036
- <xsl:with-param name="keep_sep">true</xsl:with-param>
5037
6089
  </xsl:call-template>
5038
6090
  </xsl:variable>
5039
6091
 
5040
- <xsl:for-each select="xalan:nodeset($text_step4)/item">
6092
+ <xsl:for-each select="xalan:nodeset($text_step4)/node()">
5041
6093
  <xsl:choose>
5042
- <xsl:when test="string-length() &gt; 30"> <!-- word with length more than 30 will be interspersed with zero-width space -->
6094
+ <xsl:when test="local-name() = 'interspers'"> <!-- word with length more than 30 will be interspersed with zero-width space -->
5043
6095
  <xsl:call-template name="interspers">
5044
6096
  <xsl:with-param name="str" select="."/>
5045
6097
  </xsl:call-template>
@@ -5050,6 +6102,30 @@
5050
6102
  </xsl:choose>
5051
6103
  </xsl:for-each>
5052
6104
 
6105
+ </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">
6106
+ <xsl:param name="pText" select="."/>
6107
+ <xsl:param name="sep" select="','"/>
6108
+ <!-- word with length more than 30 will be interspersed with zero-width space -->
6109
+ <xsl:variable name="regex" select="concat('([^', $zero_width_space, ']{31,})')"/> <!-- sequence of characters (more 31), that doesn't contains zero-width space -->
6110
+ <xsl:variable name="text" select="java:replaceAll(java:java.lang.String.new($pText),$regex,concat($interspers_tag_open,'$1',$interspers_tag_close))"/>
6111
+ <xsl:call-template name="replace_tag_interspers">
6112
+ <xsl:with-param name="text" select="$text"/>
6113
+ </xsl:call-template>
6114
+ </xsl:template><xsl:template name="replace_tag_interspers">
6115
+ <xsl:param name="text"/>
6116
+ <xsl:choose>
6117
+ <xsl:when test="contains($text, $interspers_tag_open)">
6118
+ <xsl:value-of select="substring-before($text, $interspers_tag_open)"/>
6119
+ <xsl:variable name="text_after" select="substring-after($text, $interspers_tag_open)"/>
6120
+ <interspers>
6121
+ <xsl:value-of select="substring-before($text_after, $interspers_tag_close)"/>
6122
+ </interspers>
6123
+ <xsl:call-template name="replace_tag_interspers">
6124
+ <xsl:with-param name="text" select="substring-after($text_after, $interspers_tag_close)"/>
6125
+ </xsl:call-template>
6126
+ </xsl:when>
6127
+ <xsl:otherwise><xsl:value-of select="$text"/></xsl:otherwise>
6128
+ </xsl:choose>
5053
6129
  </xsl:template><xsl:template name="interspers">
5054
6130
  <xsl:param name="str"/>
5055
6131
  <xsl:param name="char" select="$zero_width_space"/>
@@ -5278,7 +6354,9 @@
5278
6354
  <!-- <xsl:attribute name="border">0.5pt solid black</xsl:attribute> -->
5279
6355
  </xsl:if>
5280
6356
  <xsl:variable name="simple-table">
5281
- <xsl:call-template name="getSimpleTable"/>
6357
+ <xsl:call-template name="getSimpleTable">
6358
+ <xsl:with-param name="id" select="@id"/>
6359
+ </xsl:call-template>
5282
6360
  </xsl:variable>
5283
6361
  <xsl:variable name="cols-count" select="count(xalan:nodeset($simple-table)//tr[1]/td)"/>
5284
6362
  <xsl:if test="$cols-count = 2 and not(ancestor::*[local-name()='table'])">
@@ -5385,39 +6463,67 @@
5385
6463
  </xsl:otherwise>
5386
6464
  </xsl:choose>
5387
6465
  </xsl:template><xsl:template match="*[local-name() = 'example']">
5388
- <fo:block id="{@id}" xsl:use-attribute-sets="example-style">
5389
-
6466
+
6467
+ <fo:block-container id="{@id}" xsl:use-attribute-sets="example-style">
6468
+
5390
6469
 
6470
+
5391
6471
  <xsl:variable name="fo_element">
5392
- <xsl:if test=".//*[local-name() = 'table'] or .//*[local-name() = 'dl']">block</xsl:if>
6472
+ <xsl:if test=".//*[local-name() = 'table'] or .//*[local-name() = 'dl'] or *[not(local-name() = 'name')][1][local-name() = 'sourcecode']">block</xsl:if>
5393
6473
  block
5394
6474
  </xsl:variable>
5395
6475
 
5396
- <!-- display 'EXAMPLE' -->
5397
- <xsl:apply-templates select="*[local-name()='name']">
5398
- <xsl:with-param name="fo_element" select="$fo_element"/>
5399
- </xsl:apply-templates>
6476
+ <fo:block-container margin-left="0mm">
5400
6477
 
5401
- <xsl:choose>
5402
- <xsl:when test="contains(normalize-space($fo_element), 'block')">
5403
- <fo:block-container xsl:use-attribute-sets="example-body-style">
5404
- <fo:block-container margin-left="0mm" margin-right="0mm">
5405
- <xsl:apply-templates select="node()[not(local-name() = 'name')]">
6478
+ <xsl:choose>
6479
+
6480
+ <xsl:when test="contains(normalize-space($fo_element), 'block')">
6481
+
6482
+ <!-- display name 'EXAMPLE' in a separate block -->
6483
+ <fo:block>
6484
+ <xsl:apply-templates select="*[local-name()='name']">
5406
6485
  <xsl:with-param name="fo_element" select="$fo_element"/>
5407
6486
  </xsl:apply-templates>
6487
+ </fo:block>
6488
+
6489
+ <fo:block-container xsl:use-attribute-sets="example-body-style">
6490
+ <fo:block-container margin-left="0mm" margin-right="0mm">
6491
+ <xsl:apply-templates select="node()[not(local-name() = 'name')]">
6492
+ <xsl:with-param name="fo_element" select="$fo_element"/>
6493
+ </xsl:apply-templates>
6494
+ </fo:block-container>
5408
6495
  </fo:block-container>
5409
- </fo:block-container>
5410
- </xsl:when>
5411
- <xsl:otherwise>
5412
- <fo:inline>
5413
- <xsl:apply-templates select="node()[not(local-name() = 'name')]">
5414
- <xsl:with-param name="fo_element" select="$fo_element"/>
5415
- </xsl:apply-templates>
5416
- </fo:inline>
5417
- </xsl:otherwise>
5418
- </xsl:choose>
5419
-
5420
- </fo:block>
6496
+ </xsl:when> <!-- end block -->
6497
+
6498
+ <xsl:otherwise> <!-- inline -->
6499
+
6500
+ <!-- display 'EXAMPLE' and first element in the same line -->
6501
+ <fo:block>
6502
+ <xsl:apply-templates select="*[local-name()='name']">
6503
+ <xsl:with-param name="fo_element" select="$fo_element"/>
6504
+ </xsl:apply-templates>
6505
+ <fo:inline>
6506
+ <xsl:apply-templates select="*[not(local-name() = 'name')][1]">
6507
+ <xsl:with-param name="fo_element" select="$fo_element"/>
6508
+ </xsl:apply-templates>
6509
+ </fo:inline>
6510
+ </fo:block>
6511
+
6512
+ <xsl:if test="*[not(local-name() = 'name')][position() &gt; 1]">
6513
+ <!-- display further elements in blocks -->
6514
+ <fo:block-container xsl:use-attribute-sets="example-body-style">
6515
+ <fo:block-container margin-left="0mm" margin-right="0mm">
6516
+ <xsl:apply-templates select="*[not(local-name() = 'name')][position() &gt; 1]">
6517
+ <xsl:with-param name="fo_element" select="'block'"/>
6518
+ </xsl:apply-templates>
6519
+ </fo:block-container>
6520
+ </fo:block-container>
6521
+ </xsl:if>
6522
+ </xsl:otherwise> <!-- end inline -->
6523
+
6524
+ </xsl:choose>
6525
+ </fo:block-container>
6526
+ </fo:block-container>
5421
6527
  </xsl:template><xsl:template match="*[local-name() = 'example']/*[local-name() = 'name']">
5422
6528
  <xsl:param name="fo_element">block</xsl:param>
5423
6529
 
@@ -5449,10 +6555,16 @@
5449
6555
  </xsl:variable>
5450
6556
  <xsl:choose>
5451
6557
  <xsl:when test="starts-with(normalize-space($element), 'block')">
5452
- <fo:block xsl:use-attribute-sets="example-p-style">
5453
-
5454
- <xsl:apply-templates/>
5455
- </fo:block>
6558
+ <fo:block-container>
6559
+ <xsl:if test="ancestor::*[local-name() = 'li'] and contains(normalize-space($fo_element), 'block')">
6560
+ <xsl:attribute name="margin-left">0mm</xsl:attribute>
6561
+ <xsl:attribute name="margin-right">0mm</xsl:attribute>
6562
+ </xsl:if>
6563
+ <fo:block xsl:use-attribute-sets="example-p-style">
6564
+
6565
+ <xsl:apply-templates/>
6566
+ </fo:block>
6567
+ </fo:block-container>
5456
6568
  </xsl:when>
5457
6569
  <xsl:otherwise>
5458
6570
  <fo:inline xsl:use-attribute-sets="example-p-style">
@@ -5497,7 +6609,7 @@
5497
6609
  </xsl:otherwise>
5498
6610
  </xsl:choose> -->
5499
6611
  </fo:block>
5500
- </xsl:template><xsl:template match="*[local-name() = 'termsource']/text()[starts-with(., '[SOURCE: Adapted from: ')]" priority="2">
6612
+ </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">
5501
6613
  <xsl:text>[</xsl:text><xsl:value-of select="substring-after(., '[SOURCE: ')"/>
5502
6614
  </xsl:template><xsl:template match="*[local-name() = 'termsource']/text()">
5503
6615
  <xsl:if test="normalize-space() != ''">
@@ -5634,7 +6746,16 @@
5634
6746
  </fo:inline>
5635
6747
  </xsl:when>
5636
6748
  <xsl:otherwise> <!-- if there is key('bibitems_hidden', $current_bibitemid) -->
5637
- <fo:inline><xsl:apply-templates/></fo:inline>
6749
+
6750
+ <!-- if in bibitem[@hidden='true'] there is url[@type='src'], then create hyperlink -->
6751
+ <xsl:variable name="uri_src" select="normalize-space($bibitems_hidden/*[local-name() ='bibitem'][@id = $current_bibitemid]/*[local-name() = 'uri'][@type = 'src'])"/>
6752
+ <xsl:choose>
6753
+ <xsl:when test="$uri_src != ''">
6754
+ <fo:basic-link external-destination="{$uri_src}" fox:alt-text="{$uri_src}"><xsl:apply-templates/></fo:basic-link>
6755
+ </xsl:when>
6756
+ <xsl:otherwise><fo:inline><xsl:apply-templates/></fo:inline></xsl:otherwise>
6757
+ </xsl:choose>
6758
+
5638
6759
  </xsl:otherwise>
5639
6760
  </xsl:choose>
5640
6761
  </xsl:template><xsl:template match="*[local-name() = 'tab']">
@@ -5800,10 +6921,24 @@
5800
6921
 
5801
6922
  </fo:block>
5802
6923
  <xsl:apply-templates/>
5803
- </xsl:template><xsl:template match="*[local-name() = 'review']">
6924
+ </xsl:template><xsl:template match="*[local-name() = 'review']"> <!-- 'review' will be processed in mn2pdf/review.xsl -->
5804
6925
  <!-- comment 2019-11-29 -->
5805
6926
  <!-- <fo:block font-weight="bold">Review:</fo:block>
5806
6927
  <xsl:apply-templates /> -->
6928
+
6929
+ <xsl:variable name="id_from" select="normalize-space(current()/@from)"/>
6930
+
6931
+ <xsl:choose>
6932
+ <!-- if there isn't the attribute '@from', then -->
6933
+ <xsl:when test="$id_from = ''">
6934
+ <fo:block id="{@id}" font-size="1pt"><xsl:value-of select="$hair_space"/></fo:block>
6935
+ </xsl:when>
6936
+ <!-- if there isn't element with id 'from', then create 'bookmark' here -->
6937
+ <xsl:when test="not(ancestor::*[contains(local-name(), '-standard')]//*[@id = $id_from])">
6938
+ <fo:block id="{@from}" font-size="1pt"><xsl:value-of select="$hair_space"/></fo:block>
6939
+ </xsl:when>
6940
+ </xsl:choose>
6941
+
5807
6942
  </xsl:template><xsl:template match="*[local-name() = 'name']/text()">
5808
6943
  <!-- 0xA0 to space replacement -->
5809
6944
  <xsl:value-of select="java:replaceAll(java:java.lang.String.new(.),' ',' ')"/>
@@ -6164,7 +7299,10 @@
6164
7299
  <!-- to split by '_' and other chars -->
6165
7300
  <xsl:call-template name="add-zero-spaces-java"/>
6166
7301
  </xsl:template><xsl:template match="*[local-name() = 'bookmark']" name="bookmark">
6167
- <fo:inline id="{@id}" font-size="1pt"/>
7302
+ <!-- <fo:inline id="{@id}" font-size="1pt"/> -->
7303
+ <fo:inline id="{@id}" font-size="1pt"><xsl:value-of select="$hair_space"/></fo:inline>
7304
+ <!-- we need to add zero-width space, otherwise this fo:inline is missing in IF xml -->
7305
+ <xsl:if test="not(following-sibling::node()[normalize-space() != ''])"><fo:inline font-size="1pt"> </fo:inline></xsl:if>
6168
7306
  </xsl:template><xsl:template match="*[local-name() = 'errata']">
6169
7307
  <!-- <row>
6170
7308
  <date>05-07-2013</date>
@@ -6704,6 +7842,120 @@
6704
7842
  <xsl:apply-templates select="." mode="update_xml_step1"/>
6705
7843
  </xsl:for-each>
6706
7844
  </xsl:copy>
7845
+ </xsl:template><xsl:template match="*[local-name() = 'span']" mode="update_xml_step1">
7846
+ <xsl:apply-templates mode="update_xml_step1"/>
7847
+ </xsl:template><xsl:template match="@*|node()" mode="update_xml_enclose_keep-together_within-line">
7848
+ <xsl:copy>
7849
+ <xsl:apply-templates select="@*|node()" mode="update_xml_enclose_keep-together_within-line"/>
7850
+ </xsl:copy>
7851
+ </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">
7852
+
7853
+ <!-- enclose standard's number into tag 'keep-together_within-line' -->
7854
+ <xsl:variable name="regex_standard_reference">([A-Z]{2,}(/[A-Z]{2,})* \d+(-\d+)*(:\d{4})?)</xsl:variable>
7855
+ <xsl:variable name="tag_keep-together_within-line_open">###<xsl:value-of select="$element_name_keep-together_within-line"/>###</xsl:variable>
7856
+ <xsl:variable name="tag_keep-together_within-line_close">###/<xsl:value-of select="$element_name_keep-together_within-line"/>###</xsl:variable>
7857
+ <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))"/>
7858
+ <xsl:variable name="text"><text><xsl:call-template name="replace_text_tags">
7859
+ <xsl:with-param name="tag_open" select="$tag_keep-together_within-line_open"/>
7860
+ <xsl:with-param name="tag_close" select="$tag_keep-together_within-line_close"/>
7861
+ <xsl:with-param name="text" select="$text_"/>
7862
+ </xsl:call-template></text></xsl:variable>
7863
+
7864
+ <xsl:variable name="parent" select="local-name(..)"/>
7865
+
7866
+ <xsl:variable name="text2">
7867
+ <text><xsl:for-each select="xalan:nodeset($text)/text/node()">
7868
+ <xsl:copy-of select="."/>
7869
+ </xsl:for-each></text>
7870
+ </xsl:variable>
7871
+
7872
+ <!-- keep-together_within-line for: a/b, aaa/b, a/bbb, /b -->
7873
+ <xsl:variable name="regex_solidus_units">((\b((\S{1,3}\/\S+)|(\S+\/\S{1,3}))\b)|(\/\S{1,3})\b)</xsl:variable>
7874
+ <xsl:variable name="text3">
7875
+ <text><xsl:for-each select="xalan:nodeset($text2)/text/node()">
7876
+ <xsl:choose>
7877
+ <xsl:when test="self::text()">
7878
+ <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))"/>
7879
+ <xsl:variable name="text_units"><text><xsl:call-template name="replace_text_tags">
7880
+ <xsl:with-param name="tag_open" select="$tag_keep-together_within-line_open"/>
7881
+ <xsl:with-param name="tag_close" select="$tag_keep-together_within-line_close"/>
7882
+ <xsl:with-param name="text" select="$text_units_"/>
7883
+ </xsl:call-template></text></xsl:variable>
7884
+ <xsl:copy-of select="xalan:nodeset($text_units)/text/node()"/>
7885
+ </xsl:when>
7886
+ <xsl:otherwise><xsl:copy-of select="."/></xsl:otherwise> <!-- copy 'as-is' for <fo:inline keep-together.within-line="always" ... -->
7887
+ </xsl:choose>
7888
+ </xsl:for-each></text>
7889
+ </xsl:variable>
7890
+
7891
+ <xsl:choose>
7892
+ <xsl:when test="ancestor::*[local-name() = 'td' or local-name() = 'th']">
7893
+ <!-- keep-together_within-line for: a.b, aaa.b, a.bbb, .b in table's cell ONLY -->
7894
+ <xsl:variable name="regex_dots_units">((\b((\S{1,3}\.\S+)|(\S+\.\S{1,3}))\b)|(\.\S{1,3})\b)</xsl:variable>
7895
+ <xsl:for-each select="xalan:nodeset($text3)/text/node()">
7896
+ <xsl:choose>
7897
+ <xsl:when test="self::text()">
7898
+ <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))"/>
7899
+ <xsl:variable name="text_dots"><text><xsl:call-template name="replace_text_tags">
7900
+ <xsl:with-param name="tag_open" select="$tag_keep-together_within-line_open"/>
7901
+ <xsl:with-param name="tag_close" select="$tag_keep-together_within-line_close"/>
7902
+ <xsl:with-param name="text" select="$text_dots_"/>
7903
+ </xsl:call-template></text></xsl:variable>
7904
+ <xsl:copy-of select="xalan:nodeset($text_dots)/text/node()"/>
7905
+ </xsl:when>
7906
+ <xsl:otherwise><xsl:copy-of select="."/></xsl:otherwise> <!-- copy 'as-is' for <fo:inline keep-together.within-line="always" ... -->
7907
+ </xsl:choose>
7908
+ </xsl:for-each>
7909
+ </xsl:when>
7910
+ <xsl:otherwise><xsl:copy-of select="xalan:nodeset($text3)/text/node()"/></xsl:otherwise>
7911
+ </xsl:choose>
7912
+
7913
+ </xsl:template><xsl:template name="replace_text_tags">
7914
+ <xsl:param name="tag_open"/>
7915
+ <xsl:param name="tag_close"/>
7916
+ <xsl:param name="text"/>
7917
+ <xsl:choose>
7918
+ <xsl:when test="contains($text, $tag_open)">
7919
+ <xsl:value-of select="substring-before($text, $tag_open)"/>
7920
+ <xsl:variable name="text_after" select="substring-after($text, $tag_open)"/>
7921
+
7922
+ <xsl:element name="{substring-before(substring-after($tag_open, '###'),'###')}">
7923
+ <xsl:value-of select="substring-before($text_after, $tag_close)"/>
7924
+ </xsl:element>
7925
+
7926
+ <xsl:call-template name="replace_text_tags">
7927
+ <xsl:with-param name="tag_open" select="$tag_open"/>
7928
+ <xsl:with-param name="tag_close" select="$tag_close"/>
7929
+ <xsl:with-param name="text" select="substring-after($text_after, $tag_close)"/>
7930
+ </xsl:call-template>
7931
+ </xsl:when>
7932
+ <xsl:otherwise><xsl:value-of select="$text"/></xsl:otherwise>
7933
+ </xsl:choose>
7934
+ </xsl:template><xsl:template name="printEdition">
7935
+ <xsl:variable name="edition_i18n" select="normalize-space((//*[contains(local-name(), '-standard')])[1]/*[local-name() = 'bibdata']/*[local-name() = 'edition'][normalize-space(@language) != ''])"/>
7936
+ <xsl:text> </xsl:text>
7937
+ <xsl:choose>
7938
+ <xsl:when test="$edition_i18n != ''">
7939
+ <!-- Example: <edition language="fr">deuxième édition</edition> -->
7940
+ <xsl:call-template name="capitalize">
7941
+ <xsl:with-param name="str" select="$edition_i18n"/>
7942
+ </xsl:call-template>
7943
+ </xsl:when>
7944
+ <xsl:otherwise>
7945
+ <xsl:variable name="edition" select="normalize-space((//*[contains(local-name(), '-standard')])[1]/*[local-name() = 'bibdata']/*[local-name() = 'edition'])"/>
7946
+ <xsl:if test="$edition != ''"> <!-- Example: 1.3 -->
7947
+ <xsl:call-template name="capitalize">
7948
+ <xsl:with-param name="str">
7949
+ <xsl:call-template name="getLocalizedString">
7950
+ <xsl:with-param name="key">edition</xsl:with-param>
7951
+ </xsl:call-template>
7952
+ </xsl:with-param>
7953
+ </xsl:call-template>
7954
+ <xsl:text> </xsl:text>
7955
+ <xsl:value-of select="$edition"/>
7956
+ </xsl:if>
7957
+ </xsl:otherwise>
7958
+ </xsl:choose>
6707
7959
  </xsl:template><xsl:template name="convertDate">
6708
7960
  <xsl:param name="date"/>
6709
7961
  <xsl:param name="format" select="'short'"/>
@@ -7391,4 +8643,40 @@
7391
8643
  <xsl:value-of select="$value"/>
7392
8644
  </xsl:otherwise>
7393
8645
  </xsl:choose>
8646
+ </xsl:template><xsl:template match="*" mode="print_as_xml">
8647
+ <xsl:param name="level">0</xsl:param>
8648
+
8649
+ <fo:block margin-left="{2*$level}mm">
8650
+ <xsl:text>
8651
+ &lt;</xsl:text>
8652
+ <xsl:value-of select="local-name()"/>
8653
+ <xsl:for-each select="@*">
8654
+ <xsl:text> </xsl:text>
8655
+ <xsl:value-of select="local-name()"/>
8656
+ <xsl:text>="</xsl:text>
8657
+ <xsl:value-of select="."/>
8658
+ <xsl:text>"</xsl:text>
8659
+ </xsl:for-each>
8660
+ <xsl:text>&gt;</xsl:text>
8661
+
8662
+ <xsl:if test="not(*)">
8663
+ <fo:inline font-weight="bold"><xsl:value-of select="."/></fo:inline>
8664
+ <xsl:text>&lt;/</xsl:text>
8665
+ <xsl:value-of select="local-name()"/>
8666
+ <xsl:text>&gt;</xsl:text>
8667
+ </xsl:if>
8668
+ </fo:block>
8669
+
8670
+ <xsl:if test="*">
8671
+ <fo:block>
8672
+ <xsl:apply-templates mode="print_as_xml">
8673
+ <xsl:with-param name="level" select="$level + 1"/>
8674
+ </xsl:apply-templates>
8675
+ </fo:block>
8676
+ <fo:block margin-left="{2*$level}mm">
8677
+ <xsl:text>&lt;/</xsl:text>
8678
+ <xsl:value-of select="local-name()"/>
8679
+ <xsl:text>&gt;</xsl:text>
8680
+ </fo:block>
8681
+ </xsl:if>
7394
8682
  </xsl:template></xsl:stylesheet>