metanorma-ribose 2.0.7 → 2.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -41,20 +41,32 @@
41
41
  <xsl:value-of select="/rsd:rsd-standard/rsd:bibdata/rsd:docidentifier[@type = 'rsd' or @type = 'Ribose']"/>
42
42
  <xsl:text>:</xsl:text>
43
43
  <xsl:value-of select="$copyright_year"/>
44
- <xsl:variable name="edition" select="normalize-space(/rsd:rsd-standard/rsd:bibdata/rsd:edition)"/>
44
+
45
+ <xsl:variable name="edition" select="normalize-space(/rsd:rsd-standard/rsd:bibdata/rsd:edition[normalize-space(@language) = ''])"/>
45
46
  <xsl:if test="$edition != ''">
46
- <xsl:variable name="title-edition">
47
- <xsl:call-template name="getTitle">
48
- <xsl:with-param name="name" select="'title-edition'"/>
47
+ <xsl:variable name="title-version">
48
+ <xsl:call-template name="capitalize">
49
+ <xsl:with-param name="str">
50
+ <xsl:call-template name="getLocalizedString">
51
+ <xsl:with-param name="key">version</xsl:with-param>
52
+ </xsl:call-template>
53
+ </xsl:with-param>
49
54
  </xsl:call-template>
50
55
  </xsl:variable>
51
- <xsl:text>, </xsl:text><xsl:value-of select="$title-edition"/><xsl:text> </xsl:text><xsl:value-of select="$edition"/>
56
+ <xsl:text>, </xsl:text><xsl:value-of select="$title-version"/><xsl:text> </xsl:text><xsl:value-of select="$edition"/>
52
57
  </xsl:if>
58
+
53
59
  </xsl:variable>
54
60
 
55
61
  <xsl:template match="/">
56
62
  <xsl:call-template name="namespaceCheck"/>
57
- <fo:root xsl:use-attribute-sets="root-style" xml:lang="{$lang}">
63
+ <fo:root xml:lang="{$lang}">
64
+ <xsl:variable name="root-style">
65
+ <root-style xsl:use-attribute-sets="root-style"/>
66
+ </xsl:variable>
67
+ <xsl:call-template name="insertRootStyle">
68
+ <xsl:with-param name="root-style" select="$root-style"/>
69
+ </xsl:call-template>
58
70
  <fo:layout-master-set>
59
71
 
60
72
  <!-- Cover page -->
@@ -608,18 +620,6 @@
608
620
  <!-- ============================= -->
609
621
  <!-- ============================= -->
610
622
 
611
- <xsl:template match="/rsd:rsd-standard/rsd:bibdata/rsd:edition">
612
- <fo:block margin-bottom="12pt">
613
- <xsl:variable name="title-edition">
614
- <xsl:call-template name="getTitle">
615
- <xsl:with-param name="name" select="'title-edition'"/>
616
- </xsl:call-template>
617
- </xsl:variable>
618
- <xsl:value-of select="$title-edition"/><xsl:text>: </xsl:text>
619
- <xsl:value-of select="."/><xsl:text> </xsl:text>
620
- </fo:block>
621
- </xsl:template>
622
-
623
623
 
624
624
  <xsl:template match="rsd:feedback-statement" priority="2">
625
625
  <fo:block-container border="1pt solid black" padding="1mm" padding-left="2mm">
@@ -777,6 +777,7 @@
777
777
 
778
778
  <xsl:template match="rsd:p" name="paragraph">
779
779
  <xsl:param name="inline" select="'false'"/>
780
+ <xsl:param name="split_keep-within-line"/>
780
781
  <xsl:variable name="previous-element" select="local-name(preceding-sibling::*[1])"/>
781
782
  <xsl:variable name="element-name">
782
783
  <xsl:choose>
@@ -809,7 +810,9 @@
809
810
  </xsl:if>
810
811
 
811
812
  <!-- <xsl:attribute name="line-height">155%</xsl:attribute> -->
812
- <xsl:apply-templates/>
813
+ <xsl:apply-templates>
814
+ <xsl:with-param name="split_keep-within-line" select="$split_keep-within-line"/>
815
+ </xsl:apply-templates>
813
816
  </xsl:element>
814
817
  <xsl:if test="$element-name = 'fo:inline' and not($inline = 'true') and not(local-name(..) = 'admonition')">
815
818
  <fo:block margin-bottom="12pt">
@@ -1209,7 +1212,9 @@
1209
1212
 
1210
1213
 
1211
1214
 
1212
- <xsl:param name="svg_images"/><xsl:variable name="images" select="document($svg_images)"/><xsl:param name="basepath"/><xsl:param name="external_index"/><xsl:param name="syntax-highlight">false</xsl:param><xsl:variable name="lang">
1215
+ <xsl:param name="svg_images"/><xsl:variable name="images" select="document($svg_images)"/><xsl:param name="basepath"/><xsl:param name="external_index"/><xsl:param name="syntax-highlight">false</xsl:param><xsl:param name="add_math_as_text">true</xsl:param><xsl:param name="table_if">false</xsl:param><xsl:param name="table_widths"/><xsl:variable name="table_widths_from_if" select="xalan:nodeset($table_widths)"/><xsl:param name="table_if_debug">false</xsl:param><xsl:variable name="isGenerateTableIF_">
1216
+ false
1217
+ </xsl:variable><xsl:variable name="isGenerateTableIF" select="normalize-space($isGenerateTableIF_)"/><xsl:variable name="lang">
1213
1218
  <xsl:call-template name="getLang"/>
1214
1219
  </xsl:variable><xsl:variable name="pageWidth_">
1215
1220
  215.9
@@ -1224,20 +1229,7 @@
1224
1229
  </xsl:variable><xsl:variable name="marginTop" select="normalize-space($marginTop_)"/><xsl:variable name="marginBottom_">
1225
1230
  22
1226
1231
  </xsl:variable><xsl:variable name="marginBottom" select="normalize-space($marginBottom_)"/><xsl:variable name="titles_">
1227
-
1228
- <title-edition lang="en">
1229
-
1230
- <xsl:text>Version</xsl:text>
1231
-
1232
- </title-edition>
1233
1232
 
1234
- <title-edition lang="fr">
1235
- <xsl:text>Édition </xsl:text>
1236
- </title-edition>
1237
-
1238
- <title-edition lang="ru">
1239
- <xsl:text>Издание </xsl:text>
1240
- </title-edition>
1241
1233
 
1242
1234
  <!-- These titles of Table of contents renders different than determined in localized-strings -->
1243
1235
  <title-toc lang="en">
@@ -1316,7 +1308,7 @@
1316
1308
  </xsl:variable><xsl:variable name="bibdata">
1317
1309
  <xsl:copy-of select="//*[contains(local-name(), '-standard')]/*[local-name() = 'bibdata']"/>
1318
1310
  <xsl:copy-of select="//*[contains(local-name(), '-standard')]/*[local-name() = 'localized-strings']"/>
1319
- </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">
1311
+ </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">
1320
1312
  <xsl:param name="name"/>
1321
1313
  <xsl:param name="lang"/>
1322
1314
  <xsl:variable name="lang_">
@@ -1361,7 +1353,30 @@
1361
1353
  <xsl:attribute name="color">rgb(88, 88, 90)</xsl:attribute>
1362
1354
 
1363
1355
 
1364
- </xsl:attribute-set><xsl:attribute-set name="copyright-statement-style">
1356
+ </xsl:attribute-set><xsl:template name="insertRootStyle">
1357
+ <xsl:param name="root-style"/>
1358
+ <xsl:variable name="root-style_" select="xalan:nodeset($root-style)"/>
1359
+
1360
+ <xsl:variable name="additional_fonts_">
1361
+ <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']">
1362
+ <xsl:value-of select="."/><xsl:if test="position() != last()">, </xsl:if>
1363
+ </xsl:for-each>
1364
+ </xsl:variable>
1365
+ <xsl:variable name="additional_fonts" select="normalize-space($additional_fonts_)"/>
1366
+
1367
+ <xsl:for-each select="$root-style_/root-style/@*">
1368
+ <xsl:choose>
1369
+ <xsl:when test="local-name() = 'font-family' and $additional_fonts != ''">
1370
+ <xsl:attribute name="{local-name()}">
1371
+ <xsl:value-of select="."/>, <xsl:value-of select="$additional_fonts"/>
1372
+ </xsl:attribute>
1373
+ </xsl:when>
1374
+ <xsl:otherwise>
1375
+ <xsl:copy-of select="."/>
1376
+ </xsl:otherwise>
1377
+ </xsl:choose>
1378
+ </xsl:for-each>
1379
+ </xsl:template><xsl:attribute-set name="copyright-statement-style">
1365
1380
 
1366
1381
  </xsl:attribute-set><xsl:attribute-set name="copyright-statement-title-style">
1367
1382
 
@@ -1423,7 +1438,6 @@
1423
1438
 
1424
1439
 
1425
1440
  </xsl:attribute-set><xsl:attribute-set name="sourcecode-container-style">
1426
- <xsl:attribute name="margin-left">0mm</xsl:attribute>
1427
1441
 
1428
1442
  <xsl:attribute name="space-after">12pt</xsl:attribute>
1429
1443
 
@@ -1511,6 +1525,7 @@
1511
1525
 
1512
1526
 
1513
1527
 
1528
+
1514
1529
  </xsl:attribute-set><xsl:attribute-set name="example-name-style">
1515
1530
 
1516
1531
 
@@ -1674,6 +1689,7 @@
1674
1689
  <xsl:attribute name="font-weight">bold</xsl:attribute>
1675
1690
  <xsl:attribute name="border">solid black 1pt</xsl:attribute>
1676
1691
  <xsl:attribute name="padding-left">1mm</xsl:attribute>
1692
+ <xsl:attribute name="padding-right">1mm</xsl:attribute>
1677
1693
  <xsl:attribute name="display-align">center</xsl:attribute>
1678
1694
 
1679
1695
 
@@ -1695,6 +1711,7 @@
1695
1711
  <xsl:attribute name="display-align">center</xsl:attribute>
1696
1712
  <xsl:attribute name="border">solid black 1pt</xsl:attribute>
1697
1713
  <xsl:attribute name="padding-left">1mm</xsl:attribute>
1714
+ <xsl:attribute name="padding-right">1mm</xsl:attribute>
1698
1715
 
1699
1716
 
1700
1717
 
@@ -1786,7 +1803,8 @@
1786
1803
 
1787
1804
  <xsl:attribute name="min-height">7mm</xsl:attribute>
1788
1805
 
1789
- </xsl:attribute-set><xsl:attribute-set name="dt-style">
1806
+ </xsl:attribute-set><xsl:attribute-set name="dt-cell-style">
1807
+ </xsl:attribute-set><xsl:attribute-set name="dt-block-style">
1790
1808
  <xsl:attribute name="margin-top">6pt</xsl:attribute>
1791
1809
 
1792
1810
 
@@ -1802,6 +1820,8 @@
1802
1820
  <xsl:attribute name="font-weight">bold</xsl:attribute>
1803
1821
  <xsl:attribute name="color"><xsl:value-of select="$color_blue"/></xsl:attribute>
1804
1822
 
1823
+ </xsl:attribute-set><xsl:attribute-set name="dd-cell-style">
1824
+ <xsl:attribute name="padding-left">2mm</xsl:attribute>
1805
1825
  </xsl:attribute-set><xsl:attribute-set name="appendix-style">
1806
1826
 
1807
1827
 
@@ -1909,15 +1929,15 @@
1909
1929
 
1910
1930
  <xsl:attribute name="margin-bottom">6pt</xsl:attribute>
1911
1931
 
1912
- </xsl:attribute-set><xsl:attribute-set name="termnote-name-style">
1932
+ </xsl:attribute-set><xsl:attribute-set name="termnote-name-style">
1913
1933
 
1914
1934
 
1915
1935
 
1916
1936
 
1917
- <xsl:attribute name="font-weight">bold</xsl:attribute>
1918
- <xsl:attribute name="color"><xsl:value-of select="$color_blue"/></xsl:attribute>
1919
- <xsl:attribute name="padding-right">0.5mm</xsl:attribute>
1920
-
1937
+ <xsl:attribute name="font-weight">bold</xsl:attribute>
1938
+ <xsl:attribute name="color"><xsl:value-of select="$color_blue"/></xsl:attribute>
1939
+ <xsl:attribute name="padding-right">0.5mm</xsl:attribute>
1940
+
1921
1941
  </xsl:attribute-set><xsl:attribute-set name="quote-style">
1922
1942
  <xsl:attribute name="margin-left">12mm</xsl:attribute>
1923
1943
  <xsl:attribute name="margin-right">12mm</xsl:attribute>
@@ -2666,22 +2686,32 @@
2666
2686
  <xsl:sort select="@displayorder" data-type="number"/>
2667
2687
  <xsl:apply-templates select="."/>
2668
2688
  </xsl:for-each>
2669
- </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">
2670
- <xsl:variable name="regex_standard_reference">([A-Z]{2,}(/[A-Z]{2,})* \d+(-\d+)*(:\d{4})?)</xsl:variable>
2671
- <xsl:variable name="text" select="java:replaceAll(java:java.lang.String.new(.),$regex_standard_reference,concat($tag_open,'$1',$tag_close))"/>
2672
- <xsl:call-template name="replace_fo_inline">
2673
- <xsl:with-param name="text" select="$text"/>
2674
- </xsl:call-template>
2675
- </xsl:template><xsl:template name="replace_fo_inline">
2689
+ </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">
2690
+
2691
+ <xsl:variable name="regex_standard_reference">([A-Z]{2,}(/[A-Z]{2,})* \d+(-\d+)*(:\d{4})?)</xsl:variable>
2692
+ <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))"/>
2693
+ <xsl:call-template name="replace_fo_inline_tags">
2694
+ <xsl:with-param name="tag_open" select="$tag_fo_inline_keep-together_within-line_open"/>
2695
+ <xsl:with-param name="tag_close" select="$tag_fo_inline_keep-together_within-line_close"/>
2696
+ <xsl:with-param name="text" select="$text"/>
2697
+ </xsl:call-template>
2698
+
2699
+ </xsl:template><xsl:template name="replace_fo_inline_tags">
2700
+ <xsl:param name="tag_open"/>
2701
+ <xsl:param name="tag_close"/>
2676
2702
  <xsl:param name="text"/>
2677
2703
  <xsl:choose>
2678
2704
  <xsl:when test="contains($text, $tag_open)">
2679
2705
  <xsl:value-of select="substring-before($text, $tag_open)"/>
2680
- <xsl:text disable-output-escaping="yes">&lt;fo:inline keep-together.within-line="always"&gt;</xsl:text>
2706
+ <!-- <xsl:text disable-output-escaping="yes">&lt;fo:inline keep-together.within-line="always"&gt;</xsl:text> -->
2681
2707
  <xsl:variable name="text_after" select="substring-after($text, $tag_open)"/>
2682
- <xsl:value-of select="substring-before($text_after, $tag_close)"/>
2683
- <xsl:text disable-output-escaping="yes">&lt;/fo:inline&gt;</xsl:text>
2684
- <xsl:call-template name="replace_fo_inline">
2708
+ <fo:inline keep-together.within-line="always">
2709
+ <xsl:value-of select="substring-before($text_after, $tag_close)"/>
2710
+ </fo:inline>
2711
+ <!-- <xsl:text disable-output-escaping="yes">&lt;/fo:inline&gt;</xsl:text> -->
2712
+ <xsl:call-template name="replace_fo_inline_tags">
2713
+ <xsl:with-param name="tag_open" select="$tag_open"/>
2714
+ <xsl:with-param name="tag_close" select="$tag_close"/>
2685
2715
  <xsl:with-param name="text" select="substring-after($text_after, $tag_close)"/>
2686
2716
  </xsl:call-template>
2687
2717
  </xsl:when>
@@ -2689,6 +2719,39 @@
2689
2719
  </xsl:choose>
2690
2720
  </xsl:template><xsl:template match="*[local-name()='br']">
2691
2721
  <xsl:value-of select="$linebreak"/>
2722
+ </xsl:template><xsl:template match="*[local-name() = 'keep-together_within-line']">
2723
+ <xsl:param name="split_keep-within-line"/>
2724
+
2725
+ <!-- <fo:inline>split_keep-within-line='<xsl:value-of select="$split_keep-within-line"/>'</fo:inline> -->
2726
+ <xsl:choose>
2727
+
2728
+ <xsl:when test="normalize-space($split_keep-within-line) = 'true'">
2729
+ <xsl:variable name="sep">_</xsl:variable>
2730
+ <xsl:variable name="items">
2731
+ <xsl:call-template name="split">
2732
+ <xsl:with-param name="pText" select="."/>
2733
+ <xsl:with-param name="sep" select="$sep"/>
2734
+ <xsl:with-param name="normalize-space">false</xsl:with-param>
2735
+ <xsl:with-param name="keep_sep">true</xsl:with-param>
2736
+ </xsl:call-template>
2737
+ </xsl:variable>
2738
+ <xsl:for-each select="xalan:nodeset($items)/item">
2739
+ <xsl:choose>
2740
+ <xsl:when test=". = $sep">
2741
+ <xsl:value-of select="$sep"/><xsl:value-of select="$zero_width_space"/>
2742
+ </xsl:when>
2743
+ <xsl:otherwise>
2744
+ <fo:inline keep-together.within-line="always"><xsl:apply-templates/></fo:inline>
2745
+ </xsl:otherwise>
2746
+ </xsl:choose>
2747
+ </xsl:for-each>
2748
+ </xsl:when>
2749
+
2750
+ <xsl:otherwise>
2751
+ <fo:inline keep-together.within-line="always"><xsl:apply-templates/></fo:inline>
2752
+ </xsl:otherwise>
2753
+
2754
+ </xsl:choose>
2692
2755
  </xsl:template><xsl:template match="*[local-name()='copyright-statement']">
2693
2756
  <fo:block xsl:use-attribute-sets="copyright-statement-style">
2694
2757
  <xsl:apply-templates/>
@@ -2759,8 +2822,23 @@
2759
2822
  </xsl:call-template>
2760
2823
 
2761
2824
  </xsl:template><xsl:template match="*[local-name()='td']//text() | *[local-name()='th']//text() | *[local-name()='dt']//text() | *[local-name()='dd']//text()" priority="1">
2762
- <!-- <xsl:call-template name="add-zero-spaces"/> -->
2763
- <xsl:call-template name="add-zero-spaces-java"/>
2825
+ <xsl:choose>
2826
+ <xsl:when test="parent::*[local-name() = 'keep-together_within-line']">
2827
+ <xsl:value-of select="."/>
2828
+ </xsl:when>
2829
+ <xsl:otherwise>
2830
+ <xsl:call-template name="addZeroWidthSpacesToTextNodes"/>
2831
+ </xsl:otherwise>
2832
+ </xsl:choose>
2833
+ </xsl:template><xsl:template name="addZeroWidthSpacesToTextNodes">
2834
+ <xsl:variable name="text"><text><xsl:call-template name="text"/></text></xsl:variable>
2835
+ <!-- <xsl:copy-of select="$text"/> -->
2836
+ <xsl:for-each select="xalan:nodeset($text)/text/node()">
2837
+ <xsl:choose>
2838
+ <xsl:when test="self::text()"><xsl:call-template name="add-zero-spaces-java"/></xsl:when>
2839
+ <xsl:otherwise><xsl:copy-of select="."/></xsl:otherwise> <!-- copy 'as-is' for <fo:inline keep-together.within-line="always" ... -->
2840
+ </xsl:choose>
2841
+ </xsl:for-each>
2764
2842
  </xsl:template><xsl:template match="*[local-name()='table']" name="table">
2765
2843
 
2766
2844
  <xsl:variable name="table-preamble">
@@ -2770,9 +2848,14 @@
2770
2848
 
2771
2849
  <xsl:variable name="table">
2772
2850
 
2773
- <xsl:variable name="simple-table">
2774
- <xsl:call-template name="getSimpleTable"/>
2851
+ <xsl:variable name="simple-table">
2852
+ <xsl:call-template name="getSimpleTable">
2853
+ <xsl:with-param name="id" select="@id"/>
2854
+ </xsl:call-template>
2775
2855
  </xsl:variable>
2856
+ <!-- <xsl:variable name="simple-table" select="xalan:nodeset($simple-table_)"/> -->
2857
+
2858
+ <!-- simple-table=<xsl:copy-of select="$simple-table"/> -->
2776
2859
 
2777
2860
 
2778
2861
  <!-- Display table's name before table as standalone block -->
@@ -2793,7 +2876,23 @@
2793
2876
  </xsl:call-template>
2794
2877
  </xsl:if>
2795
2878
  </xsl:variable>
2796
- <!-- DEBUG colwidths=<xsl:copy-of select="$colwidths"/> -->
2879
+ <!-- <xsl:variable name="colwidths" select="xalan:nodeset($colwidths_)"/> -->
2880
+
2881
+ <!-- DEBUG -->
2882
+ <xsl:if test="$table_if_debug = 'true'">
2883
+ <fo:block font-size="60%">
2884
+ <xsl:apply-templates select="xalan:nodeset($colwidths)" mode="print_as_xml"/>
2885
+ </fo:block>
2886
+ </xsl:if>
2887
+
2888
+
2889
+ <!-- <xsl:copy-of select="$colwidths"/> -->
2890
+
2891
+ <!-- <xsl:text disable-output-escaping="yes">&lt;!- -</xsl:text>
2892
+ DEBUG
2893
+ colwidths=<xsl:copy-of select="$colwidths"/>
2894
+ <xsl:text disable-output-escaping="yes">- -&gt;</xsl:text> -->
2895
+
2797
2896
 
2798
2897
 
2799
2898
  <xsl:variable name="margin-side">
@@ -2854,9 +2953,17 @@
2854
2953
  </xsl:element>
2855
2954
  </xsl:variable>
2856
2955
 
2956
+ <xsl:if test="$isGenerateTableIF = 'true'">
2957
+ <!-- to determine start of table -->
2958
+ <fo:block id="{concat('table_if_start_',@id)}" keep-with-next="always" font-size="1pt">Start table '<xsl:value-of select="@id"/>'.</fo:block>
2959
+ </xsl:if>
2857
2960
 
2858
2961
  <fo:table id="{@id}">
2859
2962
 
2963
+ <xsl:if test="$isGenerateTableIF = 'true'">
2964
+ <xsl:attribute name="wrap-option">no-wrap</xsl:attribute>
2965
+ </xsl:if>
2966
+
2860
2967
  <xsl:for-each select="xalan:nodeset($table_attributes)/table_attributes/@*">
2861
2968
  <xsl:attribute name="{local-name()}">
2862
2969
  <xsl:value-of select="."/>
@@ -2870,31 +2977,47 @@
2870
2977
 
2871
2978
 
2872
2979
  <xsl:choose>
2873
- <xsl:when test="*[local-name()='colgroup']/*[local-name()='col']">
2874
- <xsl:for-each select="*[local-name()='colgroup']/*[local-name()='col']">
2875
- <fo:table-column column-width="{@width}"/>
2876
- </xsl:for-each>
2980
+ <xsl:when test="$isGenerateTableIF = 'true'">
2981
+ <!-- generate IF for table widths -->
2982
+ <!-- example:
2983
+ <tr>
2984
+ <td valign="top" align="left" id="tab-symdu_1_1">
2985
+ <p>Symbol</p>
2986
+ <word id="tab-symdu_1_1_word_1">Symbol</word>
2987
+ </td>
2988
+ <td valign="top" align="left" id="tab-symdu_1_2">
2989
+ <p>Description</p>
2990
+ <word id="tab-symdu_1_2_word_1">Description</word>
2991
+ </td>
2992
+ </tr>
2993
+ -->
2994
+ <xsl:apply-templates select="xalan:nodeset($simple-table)" mode="process_table-if"/>
2995
+
2877
2996
  </xsl:when>
2878
2997
  <xsl:otherwise>
2879
- <xsl:for-each select="xalan:nodeset($colwidths)//column">
2880
- <xsl:choose>
2881
- <xsl:when test=". = 1 or . = 0">
2882
- <fo:table-column column-width="proportional-column-width(2)"/>
2883
- </xsl:when>
2884
- <xsl:otherwise>
2885
- <fo:table-column column-width="proportional-column-width({.})"/>
2886
- </xsl:otherwise>
2887
- </xsl:choose>
2888
- </xsl:for-each>
2889
- </xsl:otherwise>
2890
- </xsl:choose>
2891
2998
 
2892
- <xsl:choose>
2893
- <xsl:when test="not(*[local-name()='tbody']) and *[local-name()='thead']">
2894
- <xsl:apply-templates select="*[local-name()='thead']" mode="process_tbody"/>
2895
- </xsl:when>
2896
- <xsl:otherwise>
2897
- <xsl:apply-templates select="node()[not(local-name() = 'name') and not(local-name() = 'note') and not(local-name() = 'thead') and not(local-name() = 'tfoot')]"/> <!-- process all table' elements, except name, header, footer and note that renders separaterely -->
2999
+ <xsl:choose>
3000
+ <xsl:when test="*[local-name()='colgroup']/*[local-name()='col']">
3001
+ <xsl:for-each select="*[local-name()='colgroup']/*[local-name()='col']">
3002
+ <fo:table-column column-width="{@width}"/>
3003
+ </xsl:for-each>
3004
+ </xsl:when>
3005
+ <xsl:otherwise>
3006
+ <xsl:call-template name="insertTableColumnWidth">
3007
+ <xsl:with-param name="colwidths" select="$colwidths"/>
3008
+ </xsl:call-template>
3009
+ </xsl:otherwise>
3010
+ </xsl:choose>
3011
+
3012
+ <xsl:choose>
3013
+ <xsl:when test="not(*[local-name()='tbody']) and *[local-name()='thead']">
3014
+ <xsl:apply-templates select="*[local-name()='thead']" mode="process_tbody"/>
3015
+ </xsl:when>
3016
+ <xsl:otherwise>
3017
+ <xsl:apply-templates select="node()[not(local-name() = 'name') and not(local-name() = 'note') and not(local-name() = 'thead') and not(local-name() = 'tfoot')]"/> <!-- process all table' elements, except name, header, footer and note that renders separaterely -->
3018
+ </xsl:otherwise>
3019
+ </xsl:choose>
3020
+
2898
3021
  </xsl:otherwise>
2899
3022
  </xsl:choose>
2900
3023
 
@@ -2997,11 +3120,22 @@
2997
3120
  <xsl:variable name="columns-with-colspan" select="count($table-row/*[@colspan])"/>
2998
3121
  <xsl:value-of select="$columns-count + $sum-colspans - $columns-with-colspan"/>
2999
3122
  </xsl:template><xsl:template name="calculate-column-widths">
3123
+ <xsl:param name="table"/>
3124
+ <xsl:param name="cols-count"/>
3125
+
3126
+ <xsl:call-template name="calculate-column-widths-proportional">
3127
+ <xsl:with-param name="cols-count" select="$cols-count"/>
3128
+ <xsl:with-param name="table" select="$table"/>
3129
+ </xsl:call-template>
3130
+
3131
+ </xsl:template><xsl:template name="calculate-column-widths-proportional">
3000
3132
  <xsl:param name="table"/>
3001
3133
  <xsl:param name="cols-count"/>
3002
3134
  <xsl:param name="curr-col" select="1"/>
3003
3135
  <xsl:param name="width" select="0"/>
3004
3136
 
3137
+ <!-- table=<xsl:copy-of select="$table"/> -->
3138
+
3005
3139
  <xsl:if test="$curr-col &lt;= $cols-count">
3006
3140
  <xsl:variable name="widths">
3007
3141
  <xsl:choose>
@@ -3039,16 +3173,22 @@
3039
3173
  </xsl:for-each>
3040
3174
  </xsl:when>
3041
3175
  <xsl:otherwise>
3042
- <xsl:for-each select="xalan:nodeset($table)/*/tr">
3176
+ <!-- <curr_col><xsl:value-of select="$curr-col"/></curr_col> -->
3177
+
3178
+ <!-- <table><xsl:copy-of select="$table"/></table>
3179
+ -->
3180
+ <xsl:for-each select="xalan:nodeset($table)/*/*[local-name()='tr']">
3043
3181
  <xsl:variable name="td_text">
3044
3182
  <xsl:apply-templates select="td[$curr-col]" mode="td_text"/>
3045
3183
  </xsl:variable>
3184
+ <!-- <td_text><xsl:value-of select="$td_text"/></td_text> -->
3046
3185
  <xsl:variable name="words">
3047
3186
  <xsl:variable name="string_with_added_zerospaces">
3048
3187
  <xsl:call-template name="add-zero-spaces-java">
3049
3188
  <xsl:with-param name="text" select="$td_text"/>
3050
3189
  </xsl:call-template>
3051
3190
  </xsl:variable>
3191
+ <!-- <xsl:message>string_with_added_zerospaces=<xsl:value-of select="$string_with_added_zerospaces"/></xsl:message> -->
3052
3192
  <xsl:call-template name="tokenize">
3053
3193
  <!-- <xsl:with-param name="text" select="translate(td[$curr-col],'- —:', ' ')"/> -->
3054
3194
  <!-- 2009 thinspace -->
@@ -3056,11 +3196,13 @@
3056
3196
  <xsl:with-param name="text" select="normalize-space(translate($string_with_added_zerospaces, '​­', ' '))"/> <!-- replace zero-width-space and soft-hyphen to space -->
3057
3197
  </xsl:call-template>
3058
3198
  </xsl:variable>
3199
+ <!-- words=<xsl:copy-of select="$words"/> -->
3059
3200
  <xsl:variable name="max_length">
3060
3201
  <xsl:call-template name="max_length">
3061
3202
  <xsl:with-param name="words" select="xalan:nodeset($words)"/>
3062
3203
  </xsl:call-template>
3063
3204
  </xsl:variable>
3205
+ <!-- <xsl:message>max_length=<xsl:value-of select="$max_length"/></xsl:message> -->
3064
3206
  <width>
3065
3207
  <xsl:variable name="divider">
3066
3208
  <xsl:choose>
@@ -3079,6 +3221,8 @@
3079
3221
  </xsl:choose>
3080
3222
  </xsl:variable>
3081
3223
 
3224
+ <!-- widths=<xsl:copy-of select="$widths"/> -->
3225
+
3082
3226
  <column>
3083
3227
  <xsl:for-each select="xalan:nodeset($widths)//width">
3084
3228
  <xsl:sort select="." data-type="number" order="descending"/>
@@ -3087,29 +3231,327 @@
3087
3231
  </xsl:if>
3088
3232
  </xsl:for-each>
3089
3233
  </column>
3090
- <xsl:call-template name="calculate-column-widths">
3234
+ <xsl:call-template name="calculate-column-widths-proportional">
3091
3235
  <xsl:with-param name="cols-count" select="$cols-count"/>
3092
3236
  <xsl:with-param name="curr-col" select="$curr-col +1"/>
3093
3237
  <xsl:with-param name="table" select="$table"/>
3094
3238
  </xsl:call-template>
3095
3239
  </xsl:if>
3240
+ </xsl:template><xsl:template match="*[@keep-together.within-line or local-name() = 'keep-together_within-line']/text()" priority="2" mode="td_text">
3241
+ <!-- <xsl:message>DEBUG t1=<xsl:value-of select="."/></xsl:message>
3242
+ <xsl:message>DEBUG t2=<xsl:value-of select="java:replaceAll(java:java.lang.String.new(.),'.','X')"/></xsl:message> -->
3243
+ <xsl:value-of select="java:replaceAll(java:java.lang.String.new(.),'.','X')"/>
3244
+
3245
+ <!-- if all capitals english letters or digits -->
3246
+ <xsl:if test="normalize-space(translate(., concat($upper,'0123456789'), '')) = ''">
3247
+ <xsl:call-template name="repeat">
3248
+ <xsl:with-param name="char" select="'X'"/>
3249
+ <xsl:with-param name="count" select="string-length(normalize-space(.)) * 0.5"/>
3250
+ </xsl:call-template>
3251
+ </xsl:if>
3096
3252
  </xsl:template><xsl:template match="text()" mode="td_text">
3097
3253
  <xsl:value-of select="translate(., $zero_width_space, ' ')"/><xsl:text> </xsl:text>
3098
3254
  </xsl:template><xsl:template match="*[local-name()='termsource']" mode="td_text">
3099
3255
  <xsl:value-of select="*[local-name()='origin']/@citeas"/>
3100
3256
  </xsl:template><xsl:template match="*[local-name()='link']" mode="td_text">
3101
3257
  <xsl:value-of select="@target"/>
3102
- </xsl:template><xsl:template match="*[local-name()='math']" mode="td_text">
3103
- <xsl:variable name="mathml">
3104
- <xsl:for-each select="*">
3105
- <xsl:if test="local-name() != 'unit' and local-name() != 'prefix' and local-name() != 'dimension' and local-name() != 'quantity'">
3106
- <xsl:copy-of select="."/>
3258
+ </xsl:template><xsl:template match="*[local-name()='math']" mode="td_text" name="math_length">
3259
+ <xsl:if test="$isGenerateTableIF = 'false'">
3260
+ <xsl:variable name="mathml_">
3261
+ <xsl:for-each select="*">
3262
+ <xsl:if test="local-name() != 'unit' and local-name() != 'prefix' and local-name() != 'dimension' and local-name() != 'quantity'">
3263
+ <xsl:copy-of select="."/>
3264
+ </xsl:if>
3265
+ </xsl:for-each>
3266
+ </xsl:variable>
3267
+ <xsl:variable name="mathml" select="xalan:nodeset($mathml_)"/>
3268
+
3269
+ <xsl:variable name="math_text">
3270
+ <xsl:value-of select="normalize-space($mathml)"/>
3271
+ <xsl:for-each select="$mathml//@open"><xsl:value-of select="."/></xsl:for-each>
3272
+ <xsl:for-each select="$mathml//@close"><xsl:value-of select="."/></xsl:for-each>
3273
+ </xsl:variable>
3274
+ <xsl:value-of select="translate($math_text, ' ', '#')"/><!-- mathml images as one 'word' without spaces -->
3275
+ </xsl:if>
3276
+ </xsl:template><xsl:template name="calculate-column-widths-autolayout-algorithm">
3277
+ <xsl:param name="table"/>
3278
+ <xsl:param name="if">false</xsl:param> <!-- via intermediate format -->
3279
+
3280
+ <!-- The algorithm uses two passes through the table data and scales linearly with the size of the table -->
3281
+
3282
+ <!-- In the first pass, line wrapping is disabled, and the user agent keeps track of the minimum and maximum width of each cell. -->
3283
+
3284
+ <!-- Since line wrap has been disabled, paragraphs are treated as long lines unless broken by BR elements. -->
3285
+
3286
+ <!-- get current table id -->
3287
+ <xsl:variable name="table_id" select="@id"/>
3288
+ <!-- find table by id in the file 'table_widths' -->
3289
+ <xsl:variable name="table-if_" select="$table_widths_from_if//table[@id = $table_id]"/>
3290
+ <xsl:variable name="table-if" select="xalan:nodeset($table-if_)"/>
3291
+
3292
+
3293
+ <!-- table='<xsl:copy-of select="$table"/>' -->
3294
+ <!-- table_id='<xsl:value-of select="$table_id"/>\ -->
3295
+ <!-- table-if='<xsl:copy-of select="$table-if"/>' -->
3296
+ <!-- table_widths_from_if='<xsl:copy-of select="$table_widths_from_if"/>' -->
3297
+
3298
+ <xsl:variable name="table_with_cell_widths_">
3299
+ <xsl:choose>
3300
+ <xsl:when test="$if = 'true' and normalize-space($table-if) != ''"> <!-- if we read column's width from IF and there is table in IF -->
3301
+
3302
+ <!-- Example: <column>10</column>
3303
+ <column>11</column>
3304
+ -->
3305
+ <xsl:apply-templates select="$table-if" mode="determine_cell_widths-if"/>
3306
+ </xsl:when>
3307
+ <xsl:otherwise>
3308
+ <xsl:apply-templates select="xalan:nodeset($table)" mode="determine_cell_widths"/>
3309
+ </xsl:otherwise>
3310
+ </xsl:choose>
3311
+ </xsl:variable>
3312
+ <xsl:variable name="table_with_cell_widths" select="xalan:nodeset($table_with_cell_widths_)"/>
3313
+
3314
+ <xsl:if test="$table_if_debug = 'true'">
3315
+ <xsl:copy-of select="$table_with_cell_widths"/>
3316
+ </xsl:if>
3317
+
3318
+
3319
+ <!-- The minimum and maximum cell widths are then used to determine the corresponding minimum and maximum widths for the columns. -->
3320
+
3321
+ <xsl:variable name="column_widths_">
3322
+ <!-- iteration of columns -->
3323
+ <xsl:for-each select="$table_with_cell_widths//tr[1]/td">
3324
+ <xsl:variable name="pos" select="position()"/>
3325
+ <column>
3326
+ <xsl:attribute name="width_max">
3327
+ <xsl:for-each select="ancestor::tbody//tr/td[$pos]/@width_max">
3328
+ <xsl:sort select="." data-type="number" order="descending"/>
3329
+ <xsl:if test="position() = 1"><xsl:value-of select="."/></xsl:if>
3330
+ </xsl:for-each>
3331
+ </xsl:attribute>
3332
+ <xsl:attribute name="width_min">
3333
+ <xsl:for-each select="ancestor::tbody//tr/td[$pos]/@width_min">
3334
+ <xsl:sort select="." data-type="number" order="descending"/>
3335
+ <xsl:if test="position() = 1"><xsl:value-of select="."/></xsl:if>
3336
+ </xsl:for-each>
3337
+ </xsl:attribute>
3338
+ </column>
3339
+ </xsl:for-each>
3340
+ </xsl:variable>
3341
+ <xsl:variable name="column_widths" select="xalan:nodeset($column_widths_)"/>
3342
+
3343
+ <!-- <column_widths>
3344
+ <xsl:copy-of select="$column_widths"/>
3345
+ </column_widths> -->
3346
+
3347
+ <!-- These in turn, are used to find the minimum and maximum width for the table. -->
3348
+ <xsl:variable name="table_widths_">
3349
+ <table>
3350
+ <xsl:attribute name="width_max">
3351
+ <xsl:value-of select="sum($column_widths/column/@width_max)"/>
3352
+ </xsl:attribute>
3353
+ <xsl:attribute name="width_min">
3354
+ <xsl:value-of select="sum($column_widths/column/@width_min)"/>
3355
+ </xsl:attribute>
3356
+ </table>
3357
+ </xsl:variable>
3358
+ <xsl:variable name="table_widths" select="xalan:nodeset($table_widths_)"/>
3359
+
3360
+ <xsl:variable name="page_width">
3361
+ <xsl:choose>
3362
+ <xsl:when test="$if = 'true'"><xsl:value-of select="$table-if/@page-width"/></xsl:when>
3363
+ <xsl:otherwise>75</xsl:otherwise>
3364
+ </xsl:choose>
3365
+ </xsl:variable>
3366
+
3367
+ <xsl:if test="$table_if_debug = 'true'">
3368
+ <table_width>
3369
+ <xsl:copy-of select="$table_widths"/>
3370
+ </table_width>
3371
+ <!-- <debug>$table_widths/@width_min=<xsl:value-of select="$table_widths/table/@width_min"/></debug>
3372
+ <debug>$table_widths/@width_max=<xsl:value-of select="$table_widths/table/@width_max"/></debug>
3373
+ -->
3374
+ <debug>$page_width=<xsl:value-of select="$page_width"/></debug>
3375
+ </xsl:if>
3376
+
3377
+
3378
+ <!-- There are three cases: -->
3379
+ <xsl:choose>
3380
+ <!-- 1. The minimum table width is equal to or wider than the available space -->
3381
+ <xsl:when test="$table_widths/table/@width_min &gt;= $page_width and 1 = 2"> <!-- this condition isn't working see case 3 below -->
3382
+ <!-- call old algorithm -->
3383
+ <case1/>
3384
+ <xsl:variable name="cols-count" select="count(xalan:nodeset($table)/*/tr[1]/td)"/>
3385
+ <xsl:call-template name="calculate-column-widths-proportional">
3386
+ <xsl:with-param name="cols-count" select="$cols-count"/>
3387
+ <xsl:with-param name="table" select="$table"/>
3388
+ </xsl:call-template>
3389
+ </xsl:when>
3390
+ <!-- 2. The maximum table width fits within the available space. In this case, set the columns to their maximum widths. -->
3391
+ <xsl:when test="$table_widths/table/@width_max &lt;= $page_width">
3392
+ <case2/>
3393
+ <autolayout/>
3394
+ <xsl:for-each select="$column_widths/column/@width_max">
3395
+ <column divider="100"><xsl:value-of select="."/></column>
3396
+ </xsl:for-each>
3397
+ </xsl:when>
3398
+ <!-- 3. The maximum width of the table is greater than the available space, but the minimum table width is smaller.
3399
+ In this case, find the difference between the available space and the minimum table width, lets call it W.
3400
+ Lets also call D the difference between maximum and minimum width of the table.
3401
+ For each column, let d be the difference between maximum and minimum width of that column.
3402
+ Now set the column's width to the minimum width plus d times W over D.
3403
+ This makes columns with large differences between minimum and maximum widths wider than columns with smaller differences. -->
3404
+ <xsl:when test="($table_widths/table/@width_max &gt; $page_width and $table_widths/table/@width_min &lt; $page_width) or ($table_widths/table/@width_min &gt;= $page_width)">
3405
+ <!-- difference between the available space and the minimum table width -->
3406
+ <xsl:variable name="W" select="$page_width - $table_widths/table/@width_min"/>
3407
+ <W><xsl:value-of select="$W"/></W>
3408
+ <!-- difference between maximum and minimum width of the table -->
3409
+ <xsl:variable name="D" select="$table_widths/table/@width_max - $table_widths/table/@width_min"/>
3410
+ <D><xsl:value-of select="$D"/></D>
3411
+ <case3/>
3412
+ <autolayout/>
3413
+ <xsl:if test="$table_widths/table/@width_min &gt;= $page_width">
3414
+ <split_keep-within-line>true</split_keep-within-line>
3415
+ </xsl:if>
3416
+ <xsl:for-each select="$column_widths/column">
3417
+ <!-- difference between maximum and minimum width of that column. -->
3418
+ <xsl:variable name="d" select="@width_max - @width_min"/>
3419
+ <d><xsl:value-of select="$d"/></d>
3420
+ <width_min><xsl:value-of select="@width_min"/></width_min>
3421
+ <e><xsl:value-of select="$d * $W div $D"/></e>
3422
+ <!-- set the column's width to the minimum width plus d times W over D. -->
3423
+ <column divider="100">
3424
+ <xsl:value-of select="round(@width_min + $d * $W div $D)"/> <!-- * 10 -->
3425
+ </column>
3426
+ </xsl:for-each>
3427
+
3428
+ </xsl:when>
3429
+ <xsl:otherwise><unknown_case/></xsl:otherwise>
3430
+ </xsl:choose>
3431
+
3432
+
3433
+ </xsl:template><xsl:template match="@*|node()" mode="determine_cell_widths">
3434
+ <xsl:copy>
3435
+ <xsl:apply-templates select="@*|node()" mode="determine_cell_widths"/>
3436
+ </xsl:copy>
3437
+ </xsl:template><xsl:template match="td | th" mode="determine_cell_widths">
3438
+ <xsl:copy>
3439
+ <xsl:copy-of select="@*"/>
3440
+
3441
+ <!-- The maximum width is given by the widest line. -->
3442
+ <xsl:variable name="widths_max">
3443
+ <xsl:for-each select=".//*[local-name() = 'p']">
3444
+ <xsl:call-template name="add_width"/>
3445
+ </xsl:for-each>
3446
+ <xsl:if test="not(*[local-name() = 'p'])">
3447
+ <xsl:call-template name="add_width"/>
3107
3448
  </xsl:if>
3449
+ </xsl:variable>
3450
+ <xsl:variable name="width_max">
3451
+ <xsl:for-each select="xalan:nodeset($widths_max)//width">
3452
+ <xsl:sort select="." data-type="number" order="descending"/>
3453
+ <xsl:if test="position() = 1"><xsl:value-of select="."/></xsl:if>
3454
+ </xsl:for-each>
3455
+ </xsl:variable>
3456
+ <xsl:attribute name="width_max">
3457
+ <xsl:value-of select="$width_max"/>
3458
+ </xsl:attribute>
3459
+
3460
+ <!-- The minimum width is given by the widest text element (word, image, etc.) -->
3461
+ <!-- To do: image width -->
3462
+ <xsl:variable name="td_text">
3463
+ <xsl:apply-templates select="." mode="td_text"/>
3464
+ </xsl:variable>
3465
+ <xsl:variable name="words">
3466
+ <xsl:variable name="string_with_added_zerospaces">
3467
+ <xsl:call-template name="add-zero-spaces-java">
3468
+ <xsl:with-param name="text" select="$td_text"/>
3469
+ </xsl:call-template>
3470
+ </xsl:variable>
3471
+ <xsl:call-template name="tokenize">
3472
+ <xsl:with-param name="text" select="normalize-space(translate($string_with_added_zerospaces, '​­', ' '))"/> <!-- replace zero-width-space and soft-hyphen to space -->
3473
+ </xsl:call-template>
3474
+ </xsl:variable>
3475
+
3476
+ <xsl:variable name="max_word_length">
3477
+ <xsl:call-template name="max_length">
3478
+ <xsl:with-param name="words" select="xalan:nodeset($words)"/>
3479
+ </xsl:call-template>
3480
+ </xsl:variable>
3481
+ <xsl:variable name="width_min">
3482
+ <xsl:value-of select="$max_word_length"/>
3483
+ </xsl:variable>
3484
+ <xsl:attribute name="width_min">
3485
+ <xsl:value-of select="$width_min"/>
3486
+ </xsl:attribute>
3487
+ <!-- width_max="1" width_min="1.5"> --> <!-- see 'tokenize' template, multiply 1.5 for all latin capitals -->
3488
+ <xsl:if test="$width_min &gt; $width_max">
3489
+ <xsl:attribute name="width_max">
3490
+ <xsl:value-of select="$width_min"/>
3491
+ </xsl:attribute>
3492
+ </xsl:if>
3493
+ <xsl:if test="$width_min = 0">
3494
+ <xsl:attribute name="width_min">1</xsl:attribute>
3495
+ </xsl:if>
3496
+
3497
+ <xsl:apply-templates select="node()" mode="determine_cell_widths"/>
3498
+
3499
+ </xsl:copy>
3500
+ </xsl:template><xsl:template name="add_width">
3501
+ <xsl:variable name="p_text"><xsl:apply-templates select="." mode="td_text"/></xsl:variable>
3502
+ <xsl:variable name="p_text_len_" select="string-length(normalize-space($p_text))"/>
3503
+
3504
+ <xsl:variable name="p_text_len">
3505
+ <xsl:choose>
3506
+ <xsl:when test="normalize-space(translate($p_text, concat($upper,'0123456789'), '')) = ''"> <!-- english word in CAPITAL letters -->
3507
+ <xsl:value-of select="$p_text_len_ * 1.5"/>
3508
+ </xsl:when>
3509
+ <xsl:otherwise><xsl:value-of select="$p_text_len_"/></xsl:otherwise>
3510
+ </xsl:choose>
3511
+ </xsl:variable>
3512
+
3513
+ <xsl:variable name="math_addon_text">
3514
+ <xsl:for-each select=".//*[local-name() = 'math']">
3515
+ <xsl:apply-templates mode="td_text"/>
3108
3516
  </xsl:for-each>
3109
3517
  </xsl:variable>
3518
+ <xsl:variable name="math_addon_length" select="string-length(normalize-space($math_addon_text)) * 0.2"/> <!-- plus 20% -->
3110
3519
 
3111
- <xsl:variable name="math_text" select="normalize-space(xalan:nodeset($mathml))"/>
3112
- <xsl:value-of select="translate($math_text, ' ', '#')"/><!-- mathml images as one 'word' without spaces -->
3520
+ <width><xsl:value-of select="$p_text_len + $math_addon_length"/></width>
3521
+ </xsl:template><xsl:template match="@*|node()" mode="determine_cell_widths-if">
3522
+ <xsl:copy>
3523
+ <xsl:apply-templates select="@*|node()" mode="determine_cell_widths-if"/>
3524
+ </xsl:copy>
3525
+ </xsl:template><xsl:template match="td | th" mode="determine_cell_widths-if">
3526
+ <xsl:copy>
3527
+ <xsl:copy-of select="@*"/>
3528
+
3529
+ <!-- The maximum width is given by the widest line. -->
3530
+ <xsl:attribute name="width_max">
3531
+ <xsl:for-each select="p_len">
3532
+ <xsl:sort select="." data-type="number" order="descending"/>
3533
+ <xsl:if test="position() = 1"><xsl:value-of select="."/></xsl:if>
3534
+ </xsl:for-each>
3535
+ </xsl:attribute>
3536
+
3537
+ <!-- The minimum width is given by the widest text element (word, image, etc.) -->
3538
+ <xsl:variable name="width_min">
3539
+ <xsl:for-each select="word_len">
3540
+ <xsl:sort select="." data-type="number" order="descending"/>
3541
+ <xsl:if test="position() = 1"><xsl:value-of select="."/></xsl:if>
3542
+ </xsl:for-each>
3543
+ </xsl:variable>
3544
+ <xsl:attribute name="width_min">
3545
+ <xsl:value-of select="$width_min"/>
3546
+ </xsl:attribute>
3547
+
3548
+ <xsl:if test="$width_min = 0">
3549
+ <xsl:attribute name="width_min">1</xsl:attribute>
3550
+ </xsl:if>
3551
+
3552
+ <xsl:apply-templates select="node()" mode="determine_cell_widths-if"/>
3553
+
3554
+ </xsl:copy>
3113
3555
  </xsl:template><xsl:template match="*[local-name()='thead']">
3114
3556
  <xsl:param name="cols-count"/>
3115
3557
  <fo:table-header>
@@ -3194,16 +3636,10 @@
3194
3636
  </xsl:for-each>
3195
3637
  </xsl:when>
3196
3638
  <xsl:otherwise>
3197
- <xsl:for-each select="xalan:nodeset($colwidths)//column">
3198
- <xsl:choose>
3199
- <xsl:when test=". = 1 or . = 0">
3200
- <fo:table-column column-width="proportional-column-width(2)"/>
3201
- </xsl:when>
3202
- <xsl:otherwise>
3203
- <fo:table-column column-width="proportional-column-width({.})"/>
3204
- </xsl:otherwise>
3205
- </xsl:choose>
3206
- </xsl:for-each>
3639
+ <!-- $colwidths=<xsl:copy-of select="$colwidths"/> -->
3640
+ <xsl:call-template name="insertTableColumnWidth">
3641
+ <xsl:with-param name="colwidths" select="$colwidths"/>
3642
+ </xsl:call-template>
3207
3643
  </xsl:otherwise>
3208
3644
  </xsl:choose>
3209
3645
 
@@ -3280,23 +3716,69 @@
3280
3716
 
3281
3717
  </fo:table-body>
3282
3718
 
3283
- </xsl:template><xsl:template match="*[local-name()='thead']/*[local-name()='tr']" priority="2">
3284
- <fo:table-row xsl:use-attribute-sets="table-header-row-style">
3719
+ </xsl:template><xsl:template match="/" mode="process_table-if">
3720
+ <xsl:param name="table_or_dl">table</xsl:param>
3721
+ <xsl:apply-templates mode="process_table-if">
3722
+ <xsl:with-param name="table_or_dl" select="$table_or_dl"/>
3723
+ </xsl:apply-templates>
3724
+ </xsl:template><xsl:template match="*[local-name()='tbody']" mode="process_table-if">
3725
+ <xsl:param name="table_or_dl">table</xsl:param>
3285
3726
 
3286
-
3287
-
3288
-
3727
+ <fo:table-body>
3728
+ <xsl:for-each select="*[local-name() = 'tr']">
3729
+ <xsl:variable name="col_count" select="count(*)"/>
3289
3730
 
3290
-
3291
-
3292
- <xsl:call-template name="setTableRowAttributes"/>
3293
-
3294
- <xsl:apply-templates/>
3295
- </fo:table-row>
3296
- </xsl:template><xsl:template match="*[local-name()='tfoot']/*[local-name()='tr']" priority="2">
3297
- <fo:table-row xsl:use-attribute-sets="table-footer-row-style">
3298
-
3299
- <xsl:call-template name="setTableRowAttributes"/>
3731
+ <!-- iteration for each tr/td -->
3732
+
3733
+ <xsl:choose>
3734
+ <xsl:when test="$table_or_dl = 'table'">
3735
+ <xsl:for-each select="*[local-name() = 'td' or local-name() = 'th']/*">
3736
+ <fo:table-row number-columns-spanned="{$col_count}">
3737
+ <!-- <test_table><xsl:copy-of select="."/></test_table> -->
3738
+ <xsl:call-template name="td"/>
3739
+ </fo:table-row>
3740
+ </xsl:for-each>
3741
+ </xsl:when>
3742
+ <xsl:otherwise> <!-- $table_or_dl = 'dl' -->
3743
+ <xsl:for-each select="*[local-name() = 'td' or local-name() = 'th']">
3744
+ <xsl:variable name="is_dt" select="position() = 1"/>
3745
+
3746
+ <xsl:for-each select="*">
3747
+ <!-- <test><xsl:copy-of select="."/></test> -->
3748
+ <fo:table-row number-columns-spanned="{$col_count}">
3749
+ <xsl:choose>
3750
+ <xsl:when test="$is_dt">
3751
+ <xsl:call-template name="insert_dt_cell"/>
3752
+ </xsl:when>
3753
+ <xsl:otherwise>
3754
+ <xsl:call-template name="insert_dd_cell"/>
3755
+ </xsl:otherwise>
3756
+ </xsl:choose>
3757
+ </fo:table-row>
3758
+ </xsl:for-each>
3759
+ </xsl:for-each>
3760
+ </xsl:otherwise>
3761
+ </xsl:choose>
3762
+
3763
+ </xsl:for-each>
3764
+ </fo:table-body>
3765
+ </xsl:template><xsl:template match="*[local-name()='thead']/*[local-name()='tr']" priority="2">
3766
+ <fo:table-row xsl:use-attribute-sets="table-header-row-style">
3767
+
3768
+
3769
+
3770
+
3771
+
3772
+
3773
+
3774
+ <xsl:call-template name="setTableRowAttributes"/>
3775
+
3776
+ <xsl:apply-templates/>
3777
+ </fo:table-row>
3778
+ </xsl:template><xsl:template match="*[local-name()='tfoot']/*[local-name()='tr']" priority="2">
3779
+ <fo:table-row xsl:use-attribute-sets="table-footer-row-style">
3780
+
3781
+ <xsl:call-template name="setTableRowAttributes"/>
3300
3782
  <xsl:apply-templates/>
3301
3783
  </fo:table-row>
3302
3784
  </xsl:template><xsl:template match="*[local-name()='tr']">
@@ -3371,7 +3853,7 @@
3371
3853
  </xsl:choose>
3372
3854
  </xsl:attribute>
3373
3855
  </xsl:if>
3374
- </xsl:template><xsl:template match="*[local-name()='td']">
3856
+ </xsl:template><xsl:template match="*[local-name()='td']" name="td">
3375
3857
  <fo:table-cell xsl:use-attribute-sets="table-cell-style"> <!-- text-align="{@align}" -->
3376
3858
  <xsl:call-template name="setTextAlignment">
3377
3859
  <xsl:with-param name="default">left</xsl:with-param>
@@ -3405,11 +3887,24 @@
3405
3887
 
3406
3888
  <xsl:call-template name="setTableCellAttributes"/>
3407
3889
 
3890
+ <xsl:if test="$isGenerateTableIF = 'true'">
3891
+ <xsl:attribute name="border">1pt solid black</xsl:attribute> <!-- border is mandatory, to determine page width -->
3892
+ <xsl:attribute name="text-align">left</xsl:attribute>
3893
+ </xsl:if>
3894
+
3408
3895
  <fo:block>
3409
3896
 
3897
+ <xsl:if test="$isGenerateTableIF = 'true'">
3898
+ <xsl:attribute name="id"><xsl:value-of select="@id"/></xsl:attribute>
3899
+ </xsl:if>
3900
+
3901
+
3410
3902
 
3411
3903
 
3412
3904
  <xsl:apply-templates/>
3905
+
3906
+ <xsl:if test="$isGenerateTableIF = 'true'"><fo:inline id="{@id}_end">end</fo:inline></xsl:if> <!-- to determine width of text --> <!-- <xsl:value-of select="$hair_space"/> -->
3907
+
3413
3908
  </fo:block>
3414
3909
  </fo:table-cell>
3415
3910
  </xsl:template><xsl:template match="*[local-name()='table']/*[local-name()='note']" priority="2">
@@ -3606,9 +4101,9 @@
3606
4101
  <!-- current hierarchy is 'figure' element -->
3607
4102
  <xsl:variable name="following_dl_colwidths">
3608
4103
  <xsl:if test="*[local-name() = 'dl']"><!-- if there is a 'dl', then set the same columns width as for 'dl' -->
3609
- <xsl:variable name="html-table">
3610
- <xsl:variable name="doc_ns">
3611
-
4104
+ <xsl:variable name="simple-table">
4105
+ <!-- <xsl:variable name="doc_ns">
4106
+ <xsl:if test="$namespace = 'bipm'">bipm</xsl:if>
3612
4107
  </xsl:variable>
3613
4108
  <xsl:variable name="ns">
3614
4109
  <xsl:choose>
@@ -3619,7 +4114,7 @@
3619
4114
  <xsl:value-of select="substring-before(name(/*), '-')"/>
3620
4115
  </xsl:otherwise>
3621
4116
  </xsl:choose>
3622
- </xsl:variable>
4117
+ </xsl:variable> -->
3623
4118
 
3624
4119
  <xsl:for-each select="*[local-name() = 'dl'][1]">
3625
4120
  <tbody>
@@ -3630,7 +4125,7 @@
3630
4125
 
3631
4126
  <xsl:call-template name="calculate-column-widths">
3632
4127
  <xsl:with-param name="cols-count" select="2"/>
3633
- <xsl:with-param name="table" select="$html-table"/>
4128
+ <xsl:with-param name="table" select="$simple-table"/>
3634
4129
  </xsl:call-template>
3635
4130
 
3636
4131
  </xsl:if>
@@ -3749,8 +4244,10 @@
3749
4244
  <!-- and (not(../@class) or ../@class !='pseudocode') -->
3750
4245
  </xsl:variable>
3751
4246
 
4247
+ <xsl:variable name="onlyOneComponent" select="normalize-space($parent = 'formula' and count(*[local-name()='dt']) = 1)"/>
4248
+
3752
4249
  <xsl:choose>
3753
- <xsl:when test="$parent = 'formula' and count(*[local-name()='dt']) = 1"> <!-- only one component -->
4250
+ <xsl:when test="$onlyOneComponent = 'true'"> <!-- only one component -->
3754
4251
 
3755
4252
  <fo:block margin-bottom="12pt" text-align="left">
3756
4253
 
@@ -3765,7 +4262,7 @@
3765
4262
  <xsl:apply-templates select="*[local-name()='dd']/*" mode="inline"/>
3766
4263
  </fo:block>
3767
4264
 
3768
- </xsl:when>
4265
+ </xsl:when> <!-- END: only one component -->
3769
4266
  <xsl:when test="$parent = 'formula'"> <!-- a few components -->
3770
4267
  <fo:block margin-bottom="12pt" text-align="left">
3771
4268
 
@@ -3779,8 +4276,8 @@
3779
4276
  </xsl:variable>
3780
4277
  <xsl:value-of select="$title-where"/>
3781
4278
  </fo:block>
3782
- </xsl:when>
3783
- <xsl:when test="$parent = 'figure' and (not(../@class) or ../@class !='pseudocode')">
4279
+ </xsl:when> <!-- END: a few components -->
4280
+ <xsl:when test="$parent = 'figure' and (not(../@class) or ../@class !='pseudocode')"> <!-- definition list in a figure -->
3784
4281
  <fo:block font-weight="bold" text-align="left" margin-bottom="12pt" keep-with-next="always">
3785
4282
 
3786
4283
 
@@ -3796,11 +4293,11 @@
3796
4293
  </xsl:variable>
3797
4294
  <xsl:value-of select="$title-key"/>
3798
4295
  </fo:block>
3799
- </xsl:when>
4296
+ </xsl:when> <!-- END: definition list in a figure -->
3800
4297
  </xsl:choose>
3801
4298
 
3802
4299
  <!-- a few components -->
3803
- <xsl:if test="not($parent = 'formula' and count(*[local-name()='dt']) = 1)">
4300
+ <xsl:if test="$onlyOneComponent = 'false'">
3804
4301
  <fo:block>
3805
4302
 
3806
4303
 
@@ -3811,7 +4308,18 @@
3811
4308
 
3812
4309
 
3813
4310
 
4311
+
4312
+ <xsl:if test="$isGenerateTableIF = 'true'">
4313
+ <!-- to determine start of table -->
4314
+ <fo:block id="{concat('table_if_start_',@id)}" keep-with-next="always" font-size="1pt">Start table '<xsl:value-of select="@id"/>'.</fo:block>
4315
+ </xsl:if>
4316
+
3814
4317
  <fo:table width="95%" table-layout="fixed">
4318
+
4319
+ <xsl:if test="$isGenerateTableIF = 'true'">
4320
+ <xsl:attribute name="wrap-option">no-wrap</xsl:attribute>
4321
+ </xsl:if>
4322
+
3815
4323
 
3816
4324
  <xsl:choose>
3817
4325
  <xsl:when test="normalize-space($key_iso) = 'true' and $parent = 'formula'"/>
@@ -3820,54 +4328,143 @@
3820
4328
 
3821
4329
  </xsl:when>
3822
4330
  </xsl:choose>
3823
- <!-- create virtual html table for dl/[dt and dd] -->
3824
- <xsl:variable name="html-table">
3825
- <xsl:variable name="doc_ns">
4331
+
4332
+
4333
+ <xsl:choose>
4334
+ <xsl:when test="$isGenerateTableIF = 'true'">
4335
+ <!-- generate IF for table widths -->
4336
+ <!-- example:
4337
+ <tr>
4338
+ <td valign="top" align="left" id="tab-symdu_1_1">
4339
+ <p>Symbol</p>
4340
+ <word id="tab-symdu_1_1_word_1">Symbol</word>
4341
+ </td>
4342
+ <td valign="top" align="left" id="tab-symdu_1_2">
4343
+ <p>Description</p>
4344
+ <word id="tab-symdu_1_2_word_1">Description</word>
4345
+ </td>
4346
+ </tr>
4347
+ -->
3826
4348
 
3827
- </xsl:variable>
3828
- <xsl:variable name="ns">
3829
- <xsl:choose>
3830
- <xsl:when test="normalize-space($doc_ns) != ''">
3831
- <xsl:value-of select="normalize-space($doc_ns)"/>
3832
- </xsl:when>
3833
- <xsl:otherwise>
3834
- <xsl:value-of select="substring-before(name(/*), '-')"/>
3835
- </xsl:otherwise>
3836
- </xsl:choose>
3837
- </xsl:variable>
3838
- <tbody>
3839
- <xsl:apply-templates mode="dl"/>
3840
- </tbody>
3841
- </xsl:variable>
3842
- <!-- html-table<xsl:copy-of select="$html-table"/> -->
3843
- <xsl:variable name="colwidths">
3844
- <xsl:call-template name="calculate-column-widths">
3845
- <xsl:with-param name="cols-count" select="2"/>
3846
- <xsl:with-param name="table" select="$html-table"/>
3847
- </xsl:call-template>
3848
- </xsl:variable>
3849
- <!-- colwidths=<xsl:copy-of select="$colwidths"/> -->
3850
- <xsl:variable name="maxlength_dt">
3851
- <xsl:call-template name="getMaxLength_dt"/>
3852
- </xsl:variable>
3853
- <xsl:call-template name="setColumnWidth_dl">
3854
- <xsl:with-param name="colwidths" select="$colwidths"/>
3855
- <xsl:with-param name="maxlength_dt" select="$maxlength_dt"/>
3856
- </xsl:call-template>
3857
- <fo:table-body>
3858
- <xsl:apply-templates>
3859
- <xsl:with-param name="key_iso" select="normalize-space($key_iso)"/>
3860
- </xsl:apply-templates>
3861
- </fo:table-body>
4349
+ <!-- create virtual html table for dl/[dt and dd] -->
4350
+ <xsl:variable name="simple-table">
4351
+
4352
+ <xsl:variable name="dl_table">
4353
+ <tbody>
4354
+ <xsl:apply-templates mode="dl_if">
4355
+ <xsl:with-param name="id" select="@id"/>
4356
+ </xsl:apply-templates>
4357
+ </tbody>
4358
+ </xsl:variable>
4359
+
4360
+ <!-- dl_table='<xsl:copy-of select="$dl_table"/>' -->
4361
+
4362
+ <!-- Step: replace <br/> to <p>...</p> -->
4363
+ <xsl:variable name="table_without_br">
4364
+ <xsl:apply-templates select="xalan:nodeset($dl_table)" mode="table-without-br"/>
4365
+ </xsl:variable>
4366
+
4367
+ <!-- table_without_br='<xsl:copy-of select="$table_without_br"/>' -->
4368
+
4369
+ <!-- Step: add id to each cell -->
4370
+ <!-- add <word>...</word> for each word, image, math -->
4371
+ <xsl:variable name="simple-table-id">
4372
+ <xsl:apply-templates select="xalan:nodeset($table_without_br)" mode="simple-table-id">
4373
+ <xsl:with-param name="id" select="@id"/>
4374
+ </xsl:apply-templates>
4375
+ </xsl:variable>
4376
+
4377
+ <!-- simple-table-id='<xsl:copy-of select="$simple-table-id"/>' -->
4378
+
4379
+ <xsl:copy-of select="xalan:nodeset($simple-table-id)"/>
4380
+
4381
+ </xsl:variable>
4382
+
4383
+ <!-- DEBUG: simple-table<xsl:copy-of select="$simple-table"/> -->
4384
+
4385
+ <xsl:apply-templates select="xalan:nodeset($simple-table)" mode="process_table-if">
4386
+ <xsl:with-param name="table_or_dl">dl</xsl:with-param>
4387
+ </xsl:apply-templates>
4388
+
4389
+ </xsl:when>
4390
+ <xsl:otherwise>
4391
+
4392
+ <xsl:variable name="simple-table">
4393
+
4394
+ <xsl:variable name="dl_table">
4395
+ <tbody>
4396
+ <xsl:apply-templates mode="dl">
4397
+ <xsl:with-param name="id" select="@id"/>
4398
+ </xsl:apply-templates>
4399
+ </tbody>
4400
+ </xsl:variable>
4401
+
4402
+ <xsl:copy-of select="$dl_table"/>
4403
+ </xsl:variable>
4404
+
4405
+ <xsl:variable name="colwidths">
4406
+ <xsl:call-template name="calculate-column-widths">
4407
+ <xsl:with-param name="cols-count" select="2"/>
4408
+ <xsl:with-param name="table" select="$simple-table"/>
4409
+ </xsl:call-template>
4410
+ </xsl:variable>
4411
+
4412
+ <!-- <xsl:text disable-output-escaping="yes">&lt;!- -</xsl:text>
4413
+ DEBUG
4414
+ colwidths=<xsl:copy-of select="$colwidths"/>
4415
+ <xsl:text disable-output-escaping="yes">- -&gt;</xsl:text> -->
4416
+
4417
+ <!-- colwidths=<xsl:copy-of select="$colwidths"/> -->
4418
+
4419
+ <xsl:variable name="maxlength_dt">
4420
+ <xsl:call-template name="getMaxLength_dt"/>
4421
+ </xsl:variable>
4422
+
4423
+ <xsl:variable name="isContainsKeepTogetherTag_">
4424
+ false
4425
+ </xsl:variable>
4426
+ <xsl:variable name="isContainsKeepTogetherTag" select="normalize-space($isContainsKeepTogetherTag_)"/>
4427
+ <!-- isContainsExpressReference=<xsl:value-of select="$isContainsExpressReference"/> -->
4428
+
4429
+
4430
+ <xsl:call-template name="setColumnWidth_dl">
4431
+ <xsl:with-param name="colwidths" select="$colwidths"/>
4432
+ <xsl:with-param name="maxlength_dt" select="$maxlength_dt"/>
4433
+ <xsl:with-param name="isContainsKeepTogetherTag" select="$isContainsKeepTogetherTag"/>
4434
+ </xsl:call-template>
4435
+
4436
+ <fo:table-body>
4437
+
4438
+ <!-- DEBUG -->
4439
+ <xsl:if test="$table_if_debug = 'true'">
4440
+ <fo:table-row>
4441
+ <fo:table-cell number-columns-spanned="2" font-size="60%">
4442
+ <xsl:apply-templates select="xalan:nodeset($colwidths)" mode="print_as_xml"/>
4443
+ </fo:table-cell>
4444
+ </fo:table-row>
4445
+ </xsl:if>
4446
+
4447
+ <xsl:apply-templates>
4448
+ <xsl:with-param name="key_iso" select="normalize-space($key_iso)"/>
4449
+ <xsl:with-param name="split_keep-within-line" select="xalan:nodeset($colwidths)/split_keep-within-line"/>
4450
+ </xsl:apply-templates>
4451
+
4452
+ </fo:table-body>
4453
+ </xsl:otherwise>
4454
+ </xsl:choose>
3862
4455
  </fo:table>
3863
4456
  </fo:block>
3864
4457
  </fo:block>
3865
- </xsl:if>
4458
+ </xsl:if> <!-- END: a few components -->
3866
4459
  </fo:block-container>
3867
4460
  </fo:block-container>
3868
4461
  </xsl:template><xsl:template name="setColumnWidth_dl">
3869
4462
  <xsl:param name="colwidths"/>
3870
4463
  <xsl:param name="maxlength_dt"/>
4464
+ <xsl:param name="isContainsKeepTogetherTag"/>
4465
+
4466
+ <!-- <colwidths><xsl:copy-of select="$colwidths"/></colwidths> -->
4467
+
3871
4468
  <xsl:choose>
3872
4469
  <xsl:when test="ancestor::*[local-name()='dl']"><!-- second level, i.e. inlined table -->
3873
4470
  <fo:table-column column-width="50%"/>
@@ -3875,6 +4472,16 @@
3875
4472
  </xsl:when>
3876
4473
  <xsl:otherwise>
3877
4474
  <xsl:choose>
4475
+ <xsl:when test="xalan:nodeset($colwidths)/autolayout">
4476
+ <xsl:call-template name="insertTableColumnWidth">
4477
+ <xsl:with-param name="colwidths" select="$colwidths"/>
4478
+ </xsl:call-template>
4479
+ </xsl:when>
4480
+ <xsl:when test="$isContainsKeepTogetherTag">
4481
+ <xsl:call-template name="insertTableColumnWidth">
4482
+ <xsl:with-param name="colwidths" select="$colwidths"/>
4483
+ </xsl:call-template>
4484
+ </xsl:when>
3878
4485
  <!-- to set width check most wide chars like `W` -->
3879
4486
  <xsl:when test="normalize-space($maxlength_dt) != '' and number($maxlength_dt) &lt;= 2"> <!-- if dt contains short text like t90, a, etc -->
3880
4487
  <fo:table-column column-width="7%"/>
@@ -3905,20 +4512,31 @@
3905
4512
  <fo:table-column column-width="60%"/>
3906
4513
  </xsl:when>
3907
4514
  <xsl:otherwise>
3908
- <xsl:for-each select="xalan:nodeset($colwidths)//column">
3909
- <xsl:choose>
3910
- <xsl:when test=". = 1 or . = 0">
3911
- <fo:table-column column-width="proportional-column-width(2)"/>
3912
- </xsl:when>
3913
- <xsl:otherwise>
3914
- <fo:table-column column-width="proportional-column-width({.})"/>
3915
- </xsl:otherwise>
3916
- </xsl:choose>
3917
- </xsl:for-each>
4515
+ <xsl:call-template name="insertTableColumnWidth">
4516
+ <xsl:with-param name="colwidths" select="$colwidths"/>
4517
+ </xsl:call-template>
3918
4518
  </xsl:otherwise>
3919
4519
  </xsl:choose>
3920
4520
  </xsl:otherwise>
3921
4521
  </xsl:choose>
4522
+ </xsl:template><xsl:template name="insertTableColumnWidth">
4523
+ <xsl:param name="colwidths"/>
4524
+
4525
+ <xsl:for-each select="xalan:nodeset($colwidths)//column">
4526
+ <xsl:choose>
4527
+ <xsl:when test=". = 1 or . = 0">
4528
+ <fo:table-column column-width="proportional-column-width(2)"/>
4529
+ </xsl:when>
4530
+ <xsl:otherwise>
4531
+ <!-- <fo:table-column column-width="proportional-column-width({.})"/> -->
4532
+ <xsl:variable name="divider">
4533
+ <xsl:value-of select="@divider"/>
4534
+ <xsl:if test="not(@divider)">1</xsl:if>
4535
+ </xsl:variable>
4536
+ <fo:table-column column-width="proportional-column-width({round(. div $divider)})"/>
4537
+ </xsl:otherwise>
4538
+ </xsl:choose>
4539
+ </xsl:for-each>
3922
4540
  </xsl:template><xsl:template name="getMaxLength_dt">
3923
4541
  <xsl:variable name="lengths">
3924
4542
  <xsl:for-each select="*[local-name()='dt']">
@@ -3942,7 +4560,6 @@
3942
4560
  <xsl:value-of select="$maxLength"/>
3943
4561
  </xsl:template><xsl:template match="*[local-name()='dl']/*[local-name()='note']" priority="2">
3944
4562
  <xsl:param name="key_iso"/>
3945
-
3946
4563
  <!-- <tr>
3947
4564
  <td>NOTE</td>
3948
4565
  <td>
@@ -3950,27 +4567,47 @@
3950
4567
  </td>
3951
4568
  </tr>
3952
4569
  -->
3953
- <fo:table-row>
4570
+ <!-- OLD Variant -->
4571
+ <!-- <fo:table-row>
3954
4572
  <fo:table-cell>
3955
4573
  <fo:block margin-top="6pt">
3956
4574
  <xsl:if test="normalize-space($key_iso) = 'true'">
3957
4575
  <xsl:attribute name="margin-top">0</xsl:attribute>
3958
4576
  </xsl:if>
3959
- <xsl:apply-templates select="*[local-name() = 'name']"/>
4577
+ <xsl:apply-templates select="*[local-name() = 'name']" />
3960
4578
  </fo:block>
3961
4579
  </fo:table-cell>
3962
4580
  <fo:table-cell>
3963
4581
  <fo:block>
3964
- <xsl:apply-templates select="node()[not(local-name() = 'name')]"/>
4582
+ <xsl:apply-templates select="node()[not(local-name() = 'name')]" />
4583
+ </fo:block>
4584
+ </fo:table-cell>
4585
+ </fo:table-row> -->
4586
+ <!-- <tr>
4587
+ <td number-columns-spanned="2">NOTE <xsl:apply-templates /> </td>
4588
+ </tr>
4589
+ -->
4590
+ <fo:table-row>
4591
+ <fo:table-cell number-columns-spanned="2">
4592
+ <fo:block>
4593
+ <xsl:call-template name="note"/>
3965
4594
  </fo:block>
3966
4595
  </fo:table-cell>
3967
4596
  </fo:table-row>
3968
4597
  </xsl:template><xsl:template match="*[local-name()='dt']" mode="dl">
4598
+ <xsl:param name="id"/>
4599
+ <xsl:variable name="row_number" select="count(preceding-sibling::*[local-name()='dt']) + 1"/>
3969
4600
  <tr>
3970
4601
  <td>
4602
+ <xsl:attribute name="id">
4603
+ <xsl:value-of select="concat($id,'_',$row_number,'_1')"/>
4604
+ </xsl:attribute>
3971
4605
  <xsl:apply-templates/>
3972
4606
  </td>
3973
4607
  <td>
4608
+ <xsl:attribute name="id">
4609
+ <xsl:value-of select="concat($id,'_',$row_number,'_2')"/>
4610
+ </xsl:attribute>
3974
4611
 
3975
4612
  <xsl:apply-templates select="following-sibling::*[local-name()='dd'][1]">
3976
4613
  <xsl:with-param name="process">true</xsl:with-param>
@@ -3981,47 +4618,117 @@
3981
4618
 
3982
4619
  </xsl:template><xsl:template match="*[local-name()='dt']">
3983
4620
  <xsl:param name="key_iso"/>
4621
+ <xsl:param name="split_keep-within-line"/>
3984
4622
 
3985
4623
  <fo:table-row xsl:use-attribute-sets="dt-row-style">
3986
- <fo:table-cell>
4624
+ <xsl:call-template name="insert_dt_cell">
4625
+ <xsl:with-param name="key_iso" select="$key_iso"/>
4626
+ <xsl:with-param name="split_keep-within-line" select="$split_keep-within-line"/>
4627
+ </xsl:call-template>
4628
+ <xsl:for-each select="following-sibling::*[local-name()='dd'][1]">
4629
+ <xsl:call-template name="insert_dd_cell">
4630
+ <xsl:with-param name="split_keep-within-line" select="$split_keep-within-line"/>
4631
+ </xsl:call-template>
4632
+ </xsl:for-each>
4633
+ </fo:table-row>
4634
+ </xsl:template><xsl:template name="insert_dt_cell">
4635
+ <xsl:param name="key_iso"/>
4636
+ <xsl:param name="split_keep-within-line"/>
4637
+ <fo:table-cell xsl:use-attribute-sets="dt-cell-style">
4638
+
4639
+ <xsl:if test="$isGenerateTableIF = 'true'">
4640
+ <!-- border is mandatory, to calculate real width -->
4641
+ <xsl:attribute name="border">0.1pt solid black</xsl:attribute>
4642
+ <xsl:attribute name="text-align">left</xsl:attribute>
4643
+ </xsl:if>
4644
+
4645
+
4646
+ <fo:block xsl:use-attribute-sets="dt-block-style">
4647
+ <xsl:copy-of select="@id"/>
4648
+
4649
+ <xsl:if test="normalize-space($key_iso) = 'true'">
4650
+ <xsl:attribute name="margin-top">0</xsl:attribute>
4651
+ </xsl:if>
4652
+
4653
+
4654
+
4655
+ <xsl:apply-templates>
4656
+ <xsl:with-param name="split_keep-within-line" select="$split_keep-within-line"/>
4657
+ </xsl:apply-templates>
4658
+
4659
+ <xsl:if test="$isGenerateTableIF = 'true'"><fo:inline id="{@id}_end">end</fo:inline></xsl:if> <!-- to determine width of text --> <!-- <xsl:value-of select="$hair_space"/> -->
4660
+
4661
+ </fo:block>
4662
+ </fo:table-cell>
4663
+ </xsl:template><xsl:template name="insert_dd_cell">
4664
+ <xsl:param name="split_keep-within-line"/>
4665
+ <fo:table-cell xsl:use-attribute-sets="dd-cell-style">
4666
+
4667
+ <xsl:if test="$isGenerateTableIF = 'true'">
4668
+ <!-- border is mandatory, to calculate real width -->
4669
+ <xsl:attribute name="border">0.1pt solid black</xsl:attribute>
4670
+ </xsl:if>
4671
+
4672
+ <fo:block>
4673
+
4674
+ <xsl:if test="$isGenerateTableIF = 'true'">
4675
+ <xsl:attribute name="id"><xsl:value-of select="@id"/></xsl:attribute>
4676
+ </xsl:if>
4677
+
3987
4678
 
3988
- <fo:block xsl:use-attribute-sets="dt-style">
3989
- <xsl:copy-of select="@id"/>
3990
-
3991
- <xsl:if test="normalize-space($key_iso) = 'true'">
3992
- <xsl:attribute name="margin-top">0</xsl:attribute>
3993
- </xsl:if>
3994
-
3995
-
3996
-
3997
- <xsl:apply-templates/>
3998
- </fo:block>
3999
- </fo:table-cell>
4000
- <fo:table-cell>
4001
- <fo:block>
4002
-
4003
4679
 
4004
- <xsl:apply-templates select="following-sibling::*[local-name()='dd'][1]">
4005
- <xsl:with-param name="process">true</xsl:with-param>
4006
- </xsl:apply-templates>
4007
- </fo:block>
4008
- </fo:table-cell>
4009
- </fo:table-row>
4680
+ <xsl:choose>
4681
+ <xsl:when test="$isGenerateTableIF = 'true'">
4682
+ <xsl:apply-templates> <!-- following-sibling::*[local-name()='dd'][1] -->
4683
+ <xsl:with-param name="process">true</xsl:with-param>
4684
+ </xsl:apply-templates>
4685
+ </xsl:when>
4686
+ <xsl:otherwise>
4687
+ <xsl:apply-templates select="."> <!-- following-sibling::*[local-name()='dd'][1] -->
4688
+ <xsl:with-param name="process">true</xsl:with-param>
4689
+ <xsl:with-param name="split_keep-within-line" select="$split_keep-within-line"/>
4690
+ </xsl:apply-templates>
4691
+ </xsl:otherwise>
4692
+
4693
+ </xsl:choose>
4694
+
4695
+ <xsl:if test="$isGenerateTableIF = 'true'"><fo:inline id="{@id}_end">end</fo:inline></xsl:if> <!-- to determine width of text --> <!-- <xsl:value-of select="$hair_space"/> -->
4696
+
4697
+ </fo:block>
4698
+ </fo:table-cell>
4010
4699
  </xsl:template><xsl:template match="*[local-name()='dd']" mode="dl"/><xsl:template match="*[local-name()='dd']" mode="dl_process">
4011
4700
  <xsl:apply-templates/>
4012
4701
  </xsl:template><xsl:template match="*[local-name()='dd']">
4013
4702
  <xsl:param name="process">false</xsl:param>
4703
+ <xsl:param name="split_keep-within-line"/>
4014
4704
  <xsl:if test="$process = 'true'">
4015
4705
  <xsl:apply-templates select="@language"/>
4016
- <xsl:apply-templates/>
4706
+ <xsl:apply-templates>
4707
+ <xsl:with-param name="split_keep-within-line" select="$split_keep-within-line"/>
4708
+ </xsl:apply-templates>
4017
4709
  </xsl:if>
4018
4710
  </xsl:template><xsl:template match="*[local-name()='dd']/*[local-name()='p']" mode="inline">
4019
4711
  <fo:inline><xsl:text> </xsl:text><xsl:apply-templates/></fo:inline>
4020
- </xsl:template><xsl:template match="*[local-name()='em']">
4712
+ </xsl:template><xsl:template match="*[local-name()='dt']" mode="dl_if">
4713
+ <xsl:param name="id"/>
4714
+ <xsl:variable name="row_number" select="count(preceding-sibling::*[local-name()='dt']) + 1"/>
4715
+ <tr>
4716
+ <td>
4717
+ <xsl:copy-of select="node()"/>
4718
+ </td>
4719
+ <td>
4720
+
4721
+ <xsl:copy-of select="following-sibling::*[local-name()='dd'][1]/node()"/>
4722
+
4723
+ </td>
4724
+ </tr>
4725
+
4726
+ </xsl:template><xsl:template match="*[local-name()='dd']" mode="dl_if"/><xsl:template match="*[local-name()='em']">
4021
4727
  <fo:inline font-style="italic">
4022
4728
  <xsl:apply-templates/>
4023
4729
  </fo:inline>
4024
4730
  </xsl:template><xsl:template match="*[local-name()='strong'] | *[local-name()='b']">
4731
+ <xsl:param name="split_keep-within-line"/>
4025
4732
  <fo:inline font-weight="bold">
4026
4733
 
4027
4734
  <xsl:if test="not(parent::*[local-name() = 'termsource'])">
@@ -4029,7 +4736,9 @@
4029
4736
  <xsl:attribute name="color">black</xsl:attribute>
4030
4737
  </xsl:if>
4031
4738
 
4032
- <xsl:apply-templates/>
4739
+ <xsl:apply-templates>
4740
+ <xsl:with-param name="split_keep-within-line" select="$split_keep-within-line"/>
4741
+ </xsl:apply-templates>
4033
4742
  </fo:inline>
4034
4743
  </xsl:template><xsl:template match="*[local-name()='padding']">
4035
4744
  <fo:inline padding-right="{@value}"> </fo:inline>
@@ -4073,13 +4782,15 @@
4073
4782
  <xsl:choose>
4074
4783
  <xsl:when test="$font-size = 'inherit'"><xsl:value-of select="$font-size"/></xsl:when>
4075
4784
  <xsl:when test="contains($font-size, '%')"><xsl:value-of select="$font-size"/></xsl:when>
4076
- <xsl:when test="ancestor::*[local-name()='note']"><xsl:value-of select="$font-size * 0.91"/>pt</xsl:when>
4785
+ <xsl:when test="ancestor::*[local-name()='note'] or ancestor::*[local-name()='example']"><xsl:value-of select="$font-size * 0.91"/>pt</xsl:when>
4077
4786
  <xsl:otherwise><xsl:value-of select="$font-size"/>pt</xsl:otherwise>
4078
4787
  </xsl:choose>
4079
4788
  </xsl:attribute>
4080
4789
  </xsl:if>
4081
4790
  <xsl:apply-templates/>
4082
4791
  </fo:inline>
4792
+ </xsl:template><xsl:template match="*[local-name()='tt']/text()" priority="2">
4793
+ <xsl:call-template name="add_spaces_to_sourcecode"/>
4083
4794
  </xsl:template><xsl:template match="*[local-name()='underline']">
4084
4795
  <fo:inline text-decoration="underline">
4085
4796
  <xsl:apply-templates/>
@@ -4227,54 +4938,120 @@
4227
4938
  <fo:block break-after="page"/>
4228
4939
  <fo:block> </fo:block>
4229
4940
  <fo:block break-after="page"/>
4941
+ </xsl:template><xsl:template match="*[local-name() = 'span']">
4942
+ <xsl:apply-templates/>
4230
4943
  </xsl:template><xsl:template name="tokenize">
4231
4944
  <xsl:param name="text"/>
4232
4945
  <xsl:param name="separator" select="' '"/>
4233
4946
  <xsl:choose>
4947
+
4948
+ <xsl:when test="$isGenerateTableIF = 'true' and not(contains($text, $separator))">
4949
+ <word><xsl:value-of select="normalize-space($text)"/></word>
4950
+ </xsl:when>
4234
4951
  <xsl:when test="not(contains($text, $separator))">
4235
4952
  <word>
4236
- <xsl:variable name="str_no_en_chars" select="normalize-space(translate($text, $en_chars, ''))"/>
4237
- <xsl:variable name="len_str_no_en_chars" select="string-length($str_no_en_chars)"/>
4238
4953
  <xsl:variable name="len_str_tmp" select="string-length(normalize-space($text))"/>
4239
- <xsl:variable name="len_str">
4240
- <xsl:choose>
4241
- <xsl:when test="normalize-space(translate($text, $upper, '')) = ''"> <!-- english word in CAPITAL letters -->
4242
- <xsl:value-of select="$len_str_tmp * 1.5"/>
4243
- </xsl:when>
4244
- <xsl:otherwise>
4245
- <xsl:value-of select="$len_str_tmp"/>
4246
- </xsl:otherwise>
4247
- </xsl:choose>
4248
- </xsl:variable>
4249
-
4250
- <!-- <xsl:if test="$len_str_no_en_chars div $len_str &gt; 0.8">
4251
- <xsl:message>
4252
- div=<xsl:value-of select="$len_str_no_en_chars div $len_str"/>
4253
- len_str=<xsl:value-of select="$len_str"/>
4254
- len_str_no_en_chars=<xsl:value-of select="$len_str_no_en_chars"/>
4255
- </xsl:message>
4256
- </xsl:if> -->
4257
- <!-- <len_str_no_en_chars><xsl:value-of select="$len_str_no_en_chars"/></len_str_no_en_chars>
4258
- <len_str><xsl:value-of select="$len_str"/></len_str> -->
4259
4954
  <xsl:choose>
4260
- <xsl:when test="$len_str_no_en_chars div $len_str &gt; 0.8"> <!-- means non-english string -->
4261
- <xsl:value-of select="$len_str - $len_str_no_en_chars"/>
4955
+ <xsl:when test="normalize-space(translate($text, 'X', '')) = ''"> <!-- special case for keep-together.within-line -->
4956
+ <xsl:value-of select="$len_str_tmp"/>
4262
4957
  </xsl:when>
4263
4958
  <xsl:otherwise>
4264
- <xsl:value-of select="$len_str"/>
4959
+ <xsl:variable name="str_no_en_chars" select="normalize-space(translate($text, $en_chars, ''))"/>
4960
+ <xsl:variable name="len_str_no_en_chars" select="string-length($str_no_en_chars)"/>
4961
+ <xsl:variable name="len_str">
4962
+ <xsl:choose>
4963
+ <xsl:when test="normalize-space(translate($text, $upper, '')) = ''"> <!-- english word in CAPITAL letters -->
4964
+ <xsl:value-of select="$len_str_tmp * 1.5"/>
4965
+ </xsl:when>
4966
+ <xsl:otherwise>
4967
+ <xsl:value-of select="$len_str_tmp"/>
4968
+ </xsl:otherwise>
4969
+ </xsl:choose>
4970
+ </xsl:variable>
4971
+
4972
+ <!-- <xsl:if test="$len_str_no_en_chars div $len_str &gt; 0.8">
4973
+ <xsl:message>
4974
+ div=<xsl:value-of select="$len_str_no_en_chars div $len_str"/>
4975
+ len_str=<xsl:value-of select="$len_str"/>
4976
+ len_str_no_en_chars=<xsl:value-of select="$len_str_no_en_chars"/>
4977
+ </xsl:message>
4978
+ </xsl:if> -->
4979
+ <!-- <len_str_no_en_chars><xsl:value-of select="$len_str_no_en_chars"/></len_str_no_en_chars>
4980
+ <len_str><xsl:value-of select="$len_str"/></len_str> -->
4981
+ <xsl:choose>
4982
+ <xsl:when test="$len_str_no_en_chars div $len_str &gt; 0.8"> <!-- means non-english string -->
4983
+ <xsl:value-of select="$len_str - $len_str_no_en_chars"/>
4984
+ </xsl:when>
4985
+ <xsl:otherwise>
4986
+ <xsl:value-of select="$len_str"/>
4987
+ </xsl:otherwise>
4988
+ </xsl:choose>
4265
4989
  </xsl:otherwise>
4266
4990
  </xsl:choose>
4267
4991
  </word>
4268
4992
  </xsl:when>
4269
4993
  <xsl:otherwise>
4270
4994
  <word>
4271
- <xsl:value-of select="string-length(normalize-space(substring-before($text, $separator)))"/>
4995
+ <xsl:variable name="word" select="normalize-space(substring-before($text, $separator))"/>
4996
+ <xsl:choose>
4997
+ <xsl:when test="$isGenerateTableIF = 'true'">
4998
+ <xsl:value-of select="$word"/>
4999
+ </xsl:when>
5000
+ <xsl:otherwise>
5001
+ <xsl:value-of select="string-length($word)"/>
5002
+ </xsl:otherwise>
5003
+ </xsl:choose>
4272
5004
  </word>
4273
5005
  <xsl:call-template name="tokenize">
4274
5006
  <xsl:with-param name="text" select="substring-after($text, $separator)"/>
4275
5007
  </xsl:call-template>
4276
5008
  </xsl:otherwise>
4277
5009
  </xsl:choose>
5010
+ </xsl:template><xsl:template name="tokenize_with_tags">
5011
+ <xsl:param name="tags"/>
5012
+ <xsl:param name="text"/>
5013
+ <xsl:param name="separator" select="' '"/>
5014
+ <xsl:choose>
5015
+
5016
+ <xsl:when test="not(contains($text, $separator))">
5017
+ <word>
5018
+ <xsl:call-template name="enclose_text_in_tags">
5019
+ <xsl:with-param name="text" select="normalize-space($text)"/>
5020
+ <xsl:with-param name="tags" select="$tags"/>
5021
+ </xsl:call-template>
5022
+ </word>
5023
+ </xsl:when>
5024
+ <xsl:otherwise>
5025
+ <word>
5026
+ <xsl:call-template name="enclose_text_in_tags">
5027
+ <xsl:with-param name="text" select="normalize-space(substring-before($text, $separator))"/>
5028
+ <xsl:with-param name="tags" select="$tags"/>
5029
+ </xsl:call-template>
5030
+ </word>
5031
+ <xsl:call-template name="tokenize_with_tags">
5032
+ <xsl:with-param name="text" select="substring-after($text, $separator)"/>
5033
+ </xsl:call-template>
5034
+ </xsl:otherwise>
5035
+ </xsl:choose>
5036
+ </xsl:template><xsl:template name="enclose_text_in_tags">
5037
+ <xsl:param name="text"/>
5038
+ <xsl:param name="tags"/>
5039
+ <xsl:param name="num">1</xsl:param> <!-- default (start) value -->
5040
+
5041
+ <xsl:variable name="tag_name" select="normalize-space(xalan:nodeset($tags)//tag[$num])"/>
5042
+
5043
+ <xsl:choose>
5044
+ <xsl:when test="$tag_name = ''"><xsl:value-of select="$text"/></xsl:when>
5045
+ <xsl:otherwise>
5046
+ <xsl:element name="{$tag_name}">
5047
+ <xsl:call-template name="enclose_text_in_tags">
5048
+ <xsl:with-param name="text" select="$text"/>
5049
+ <xsl:with-param name="tags" select="$tags"/>
5050
+ <xsl:with-param name="num" select="$num + 1"/>
5051
+ </xsl:call-template>
5052
+ </xsl:element>
5053
+ </xsl:otherwise>
5054
+ </xsl:choose>
4278
5055
  </xsl:template><xsl:template name="max_length">
4279
5056
  <xsl:param name="words"/>
4280
5057
  <xsl:for-each select="$words//word">
@@ -4347,36 +5124,47 @@
4347
5124
  </xsl:template><xsl:template name="add-zero-spaces-equal">
4348
5125
  <xsl:param name="text" select="."/>
4349
5126
  <xsl:variable name="zero-space-after-equals">==========</xsl:variable>
5127
+ <xsl:variable name="regex_zero-space-after-equals">(==========)</xsl:variable>
4350
5128
  <xsl:variable name="zero-space-after-equal">=</xsl:variable>
5129
+ <xsl:variable name="regex_zero-space-after-equal">(=)</xsl:variable>
4351
5130
  <xsl:variable name="zero-space">​</xsl:variable>
4352
5131
  <xsl:choose>
4353
5132
  <xsl:when test="contains($text, $zero-space-after-equals)">
4354
- <xsl:value-of select="substring-before($text, $zero-space-after-equals)"/>
5133
+ <!-- <xsl:value-of select="substring-before($text, $zero-space-after-equals)"/>
4355
5134
  <xsl:value-of select="$zero-space-after-equals"/>
4356
5135
  <xsl:value-of select="$zero-space"/>
4357
5136
  <xsl:call-template name="add-zero-spaces-equal">
4358
5137
  <xsl:with-param name="text" select="substring-after($text, $zero-space-after-equals)"/>
4359
- </xsl:call-template>
5138
+ </xsl:call-template> -->
5139
+ <xsl:value-of select="java:replaceAll(java:java.lang.String.new(.),$regex_zero-space-after-equals,concat('$1',$zero_width_space))"/>
4360
5140
  </xsl:when>
4361
5141
  <xsl:when test="contains($text, $zero-space-after-equal)">
4362
- <xsl:value-of select="substring-before($text, $zero-space-after-equal)"/>
5142
+ <!-- <xsl:value-of select="substring-before($text, $zero-space-after-equal)"/>
4363
5143
  <xsl:value-of select="$zero-space-after-equal"/>
4364
5144
  <xsl:value-of select="$zero-space"/>
4365
5145
  <xsl:call-template name="add-zero-spaces-equal">
4366
5146
  <xsl:with-param name="text" select="substring-after($text, $zero-space-after-equal)"/>
4367
- </xsl:call-template>
5147
+ </xsl:call-template> -->
5148
+ <xsl:value-of select="java:replaceAll(java:java.lang.String.new(.),$regex_zero-space-after-equal,concat('$1',$zero_width_space))"/>
4368
5149
  </xsl:when>
4369
5150
  <xsl:otherwise>
4370
5151
  <xsl:value-of select="$text"/>
4371
5152
  </xsl:otherwise>
4372
5153
  </xsl:choose>
4373
5154
  </xsl:template><xsl:template name="getSimpleTable">
5155
+ <xsl:param name="id"/>
5156
+
4374
5157
  <xsl:variable name="simple-table">
4375
5158
 
5159
+ <!-- Step 0. replace <br/> to <p>...</p> -->
5160
+ <xsl:variable name="table_without_br">
5161
+ <xsl:apply-templates mode="table-without-br"/>
5162
+ </xsl:variable>
5163
+
4376
5164
  <!-- Step 1. colspan processing -->
4377
5165
  <xsl:variable name="simple-table-colspan">
4378
5166
  <tbody>
4379
- <xsl:apply-templates mode="simple-table-colspan"/>
5167
+ <xsl:apply-templates select="xalan:nodeset($table_without_br)" mode="simple-table-colspan"/>
4380
5168
  </tbody>
4381
5169
  </xsl:variable>
4382
5170
 
@@ -4385,10 +5173,67 @@
4385
5173
  <xsl:apply-templates select="xalan:nodeset($simple-table-colspan)" mode="simple-table-rowspan"/>
4386
5174
  </xsl:variable>
4387
5175
 
4388
- <xsl:copy-of select="xalan:nodeset($simple-table-rowspan)"/>
4389
-
5176
+ <!-- Step 3: add id to each cell -->
5177
+ <!-- add <word>...</word> for each word, image, math -->
5178
+ <xsl:variable name="simple-table-id">
5179
+ <xsl:apply-templates select="xalan:nodeset($simple-table-rowspan)" mode="simple-table-id">
5180
+ <xsl:with-param name="id" select="$id"/>
5181
+ </xsl:apply-templates>
5182
+ </xsl:variable>
5183
+
5184
+ <xsl:copy-of select="xalan:nodeset($simple-table-id)"/>
5185
+
4390
5186
  </xsl:variable>
4391
5187
  <xsl:copy-of select="$simple-table"/>
5188
+ </xsl:template><xsl:template match="@*|node()" mode="table-without-br">
5189
+ <xsl:copy>
5190
+ <xsl:apply-templates select="@*|node()" mode="table-without-br"/>
5191
+ </xsl:copy>
5192
+ </xsl:template><xsl:template match="*[local-name()='th' or local-name() = 'td'][not(*[local-name()='br']) and not(*[local-name()='p'])]" mode="table-without-br">
5193
+ <xsl:copy>
5194
+ <xsl:copy-of select="@*"/>
5195
+ <p>
5196
+ <xsl:copy-of select="node()"/>
5197
+ </p>
5198
+ </xsl:copy>
5199
+ </xsl:template><xsl:template match="*[local-name()='th' or local-name()='td'][*[local-name()='br']]" mode="table-without-br">
5200
+ <xsl:copy>
5201
+ <xsl:copy-of select="@*"/>
5202
+ <xsl:for-each select="*[local-name()='br']">
5203
+ <xsl:variable name="current_id" select="generate-id()"/>
5204
+ <p>
5205
+ <xsl:for-each select="preceding-sibling::node()[following-sibling::*[local-name() = 'br'][1][generate-id() = $current_id]][not(local-name() = 'br')]">
5206
+ <xsl:copy-of select="."/>
5207
+ </xsl:for-each>
5208
+ </p>
5209
+ <xsl:if test="not(following-sibling::*[local-name() = 'br'])">
5210
+ <p>
5211
+ <xsl:for-each select="following-sibling::node()">
5212
+ <xsl:copy-of select="."/>
5213
+ </xsl:for-each>
5214
+ </p>
5215
+ </xsl:if>
5216
+ </xsl:for-each>
5217
+ </xsl:copy>
5218
+ </xsl:template><xsl:template match="*[local-name()='th' or local-name()='td']/*[local-name() = 'p'][*[local-name()='br']]" mode="table-without-br">
5219
+ <xsl:for-each select="*[local-name()='br']">
5220
+ <xsl:variable name="current_id" select="generate-id()"/>
5221
+ <p>
5222
+ <xsl:for-each select="preceding-sibling::node()[following-sibling::*[local-name() = 'br'][1][generate-id() = $current_id]][not(local-name() = 'br')]">
5223
+ <xsl:copy-of select="."/>
5224
+ </xsl:for-each>
5225
+ </p>
5226
+ <xsl:if test="not(following-sibling::*[local-name() = 'br'])">
5227
+ <p>
5228
+ <xsl:for-each select="following-sibling::node()">
5229
+ <xsl:copy-of select="."/>
5230
+ </xsl:for-each>
5231
+ </p>
5232
+ </xsl:if>
5233
+ </xsl:for-each>
5234
+ </xsl:template><xsl:template match="text()[not(ancestor::*[local-name() = 'sourcecode'])]" mode="table-without-br">
5235
+ <xsl:variable name="text" select="translate(.,'&#9;&#10;&#13;','')"/>
5236
+ <xsl:value-of select="java:replaceAll(java:java.lang.String.new($text),' {2,}',' ')"/>
4392
5237
  </xsl:template><xsl:template match="*[local-name()='thead'] | *[local-name()='tbody']" mode="simple-table-colspan">
4393
5238
  <xsl:apply-templates mode="simple-table-colspan"/>
4394
5239
  </xsl:template><xsl:template match="*[local-name()='fn']" mode="simple-table-colspan"/><xsl:template match="*[local-name()='th'] | *[local-name()='td']" mode="simple-table-colspan">
@@ -4437,47 +5282,167 @@
4437
5282
  <xsl:copy>
4438
5283
  <xsl:apply-templates select="@*|node()" mode="simple-table-rowspan"/>
4439
5284
  </xsl:copy>
4440
- </xsl:template><xsl:template match="tbody" mode="simple-table-rowspan">
5285
+ </xsl:template><xsl:template match="tbody" mode="simple-table-rowspan">
5286
+ <xsl:copy>
5287
+ <xsl:copy-of select="tr[1]"/>
5288
+ <xsl:apply-templates select="tr[2]" mode="simple-table-rowspan">
5289
+ <xsl:with-param name="previousRow" select="tr[1]"/>
5290
+ </xsl:apply-templates>
5291
+ </xsl:copy>
5292
+ </xsl:template><xsl:template match="tr" mode="simple-table-rowspan">
5293
+ <xsl:param name="previousRow"/>
5294
+ <xsl:variable name="currentRow" select="."/>
5295
+
5296
+ <xsl:variable name="normalizedTDs">
5297
+ <xsl:for-each select="xalan:nodeset($previousRow)//td">
5298
+ <xsl:choose>
5299
+ <xsl:when test="@rowspan &gt; 1">
5300
+ <xsl:copy>
5301
+ <xsl:attribute name="rowspan">
5302
+ <xsl:value-of select="@rowspan - 1"/>
5303
+ </xsl:attribute>
5304
+ <xsl:copy-of select="@*[not(name() = 'rowspan')]"/>
5305
+ <xsl:copy-of select="node()"/>
5306
+ </xsl:copy>
5307
+ </xsl:when>
5308
+ <xsl:otherwise>
5309
+ <xsl:copy-of select="$currentRow/td[1 + count(current()/preceding-sibling::td[not(@rowspan) or (@rowspan = 1)])]"/>
5310
+ </xsl:otherwise>
5311
+ </xsl:choose>
5312
+ </xsl:for-each>
5313
+ </xsl:variable>
5314
+
5315
+ <xsl:variable name="newRow">
5316
+ <xsl:copy>
5317
+ <xsl:copy-of select="$currentRow/@*"/>
5318
+ <xsl:copy-of select="xalan:nodeset($normalizedTDs)"/>
5319
+ </xsl:copy>
5320
+ </xsl:variable>
5321
+ <xsl:copy-of select="$newRow"/>
5322
+
5323
+ <xsl:apply-templates select="following-sibling::tr[1]" mode="simple-table-rowspan">
5324
+ <xsl:with-param name="previousRow" select="$newRow"/>
5325
+ </xsl:apply-templates>
5326
+ </xsl:template><xsl:template match="/" mode="simple-table-id">
5327
+ <xsl:param name="id"/>
5328
+ <xsl:variable name="id_prefixed" select="concat('table_if_',$id)"/> <!-- table id prefixed by 'table_if_' to simple search in IF -->
5329
+ <xsl:apply-templates select="@*|node()" mode="simple-table-id">
5330
+ <xsl:with-param name="id" select="$id_prefixed"/>
5331
+ </xsl:apply-templates>
5332
+ </xsl:template><xsl:template match="@*|node()" mode="simple-table-id">
5333
+ <xsl:param name="id"/>
5334
+ <xsl:copy>
5335
+ <xsl:apply-templates select="@*|node()" mode="simple-table-id">
5336
+ <xsl:with-param name="id" select="$id"/>
5337
+ </xsl:apply-templates>
5338
+ </xsl:copy>
5339
+ </xsl:template><xsl:template match="*[local-name()='tbody']" mode="simple-table-id">
5340
+ <xsl:param name="id"/>
5341
+ <xsl:copy>
5342
+ <xsl:copy-of select="@*"/>
5343
+ <xsl:attribute name="id"><xsl:value-of select="$id"/></xsl:attribute>
5344
+ <xsl:apply-templates select="node()" mode="simple-table-id">
5345
+ <xsl:with-param name="id" select="$id"/>
5346
+ </xsl:apply-templates>
5347
+ </xsl:copy>
5348
+ </xsl:template><xsl:template match="*[local-name()='th' or local-name()='td']" mode="simple-table-id">
5349
+ <xsl:param name="id"/>
5350
+ <xsl:copy>
5351
+ <xsl:copy-of select="@*"/>
5352
+ <xsl:variable name="row_number" select="count(../preceding-sibling::*) + 1"/>
5353
+ <xsl:variable name="col_number" select="count(preceding-sibling::*) + 1"/>
5354
+ <xsl:attribute name="id">
5355
+ <xsl:value-of select="concat($id,'_',$row_number,'_',$col_number)"/>
5356
+ </xsl:attribute>
5357
+
5358
+ <xsl:for-each select="*[local-name() = 'p']">
5359
+ <xsl:copy>
5360
+ <xsl:copy-of select="@*"/>
5361
+ <xsl:variable name="p_num" select="count(preceding-sibling::*[local-name() = 'p']) + 1"/>
5362
+ <xsl:attribute name="id">
5363
+ <xsl:value-of select="concat($id,'_',$row_number,'_',$col_number,'_p_',$p_num)"/>
5364
+ </xsl:attribute>
5365
+
5366
+ <xsl:copy-of select="node()"/>
5367
+ </xsl:copy>
5368
+ </xsl:for-each>
5369
+
5370
+
5371
+ <xsl:if test="$isGenerateTableIF = 'true'"> <!-- split each paragraph to words, image, math -->
5372
+
5373
+ <xsl:variable name="td_text">
5374
+ <xsl:apply-templates select="." mode="td_text_with_formatting"/>
5375
+ </xsl:variable>
5376
+
5377
+ <!-- td_text='<xsl:copy-of select="$td_text"/>' -->
5378
+
5379
+ <xsl:variable name="words">
5380
+ <xsl:for-each select=".//*[local-name() = 'image' or local-name() = 'stem']">
5381
+ <word>
5382
+ <xsl:copy-of select="."/>
5383
+ </word>
5384
+ </xsl:for-each>
5385
+
5386
+ <xsl:for-each select="xalan:nodeset($td_text)//*[local-name() = 'word'][normalize-space() != '']">
5387
+ <xsl:copy-of select="."/>
5388
+ </xsl:for-each>
5389
+
5390
+ </xsl:variable>
5391
+
5392
+ <xsl:for-each select="xalan:nodeset($words)/word">
5393
+ <xsl:variable name="num" select="count(preceding-sibling::word) + 1"/>
5394
+ <xsl:copy>
5395
+ <xsl:attribute name="id">
5396
+ <xsl:value-of select="concat($id,'_',$row_number,'_',$col_number,'_word_',$num)"/>
5397
+ </xsl:attribute>
5398
+ <xsl:copy-of select="node()"/>
5399
+ </xsl:copy>
5400
+ </xsl:for-each>
5401
+ </xsl:if>
5402
+ </xsl:copy>
5403
+
5404
+ </xsl:template><xsl:template match="@*|node()" mode="td_text_with_formatting">
4441
5405
  <xsl:copy>
4442
- <xsl:copy-of select="tr[1]"/>
4443
- <xsl:apply-templates select="tr[2]" mode="simple-table-rowspan">
4444
- <xsl:with-param name="previousRow" select="tr[1]"/>
4445
- </xsl:apply-templates>
5406
+ <xsl:apply-templates select="@*|node()" mode="td_text_with_formatting"/>
4446
5407
  </xsl:copy>
4447
- </xsl:template><xsl:template match="tr" mode="simple-table-rowspan">
4448
- <xsl:param name="previousRow"/>
4449
- <xsl:variable name="currentRow" select="."/>
4450
-
4451
- <xsl:variable name="normalizedTDs">
4452
- <xsl:for-each select="xalan:nodeset($previousRow)//td">
4453
- <xsl:choose>
4454
- <xsl:when test="@rowspan &gt; 1">
4455
- <xsl:copy>
4456
- <xsl:attribute name="rowspan">
4457
- <xsl:value-of select="@rowspan - 1"/>
4458
- </xsl:attribute>
4459
- <xsl:copy-of select="@*[not(name() = 'rowspan')]"/>
4460
- <xsl:copy-of select="node()"/>
4461
- </xsl:copy>
4462
- </xsl:when>
4463
- <xsl:otherwise>
4464
- <xsl:copy-of select="$currentRow/td[1 + count(current()/preceding-sibling::td[not(@rowspan) or (@rowspan = 1)])]"/>
4465
- </xsl:otherwise>
4466
- </xsl:choose>
4467
- </xsl:for-each>
5408
+ </xsl:template><xsl:template match="*[local-name() = 'stem' or local-name() = 'image']" mode="td_text_with_formatting"/><xsl:template match="*[local-name() = 'keep-together_within-line']/text()" mode="td_text_with_formatting">
5409
+ <xsl:variable name="formatting_tags">
5410
+ <xsl:call-template name="getFormattingTags"/>
4468
5411
  </xsl:variable>
4469
-
4470
- <xsl:variable name="newRow">
4471
- <xsl:copy>
4472
- <xsl:copy-of select="$currentRow/@*"/>
4473
- <xsl:copy-of select="xalan:nodeset($normalizedTDs)"/>
4474
- </xsl:copy>
5412
+ <word>
5413
+ <xsl:call-template name="enclose_text_in_tags">
5414
+ <xsl:with-param name="text" select="normalize-space(.)"/>
5415
+ <xsl:with-param name="tags" select="$formatting_tags"/>
5416
+ </xsl:call-template>
5417
+ </word>
5418
+ </xsl:template><xsl:template match="*[local-name() != 'keep-together_within-line']/text()" mode="td_text_with_formatting">
5419
+
5420
+ <xsl:variable name="td_text" select="."/>
5421
+
5422
+ <xsl:variable name="string_with_added_zerospaces">
5423
+ <xsl:call-template name="add-zero-spaces-java">
5424
+ <xsl:with-param name="text" select="$td_text"/>
5425
+ </xsl:call-template>
4475
5426
  </xsl:variable>
4476
- <xsl:copy-of select="$newRow"/>
4477
-
4478
- <xsl:apply-templates select="following-sibling::tr[1]" mode="simple-table-rowspan">
4479
- <xsl:with-param name="previousRow" select="$newRow"/>
4480
- </xsl:apply-templates>
5427
+
5428
+ <xsl:variable name="formatting_tags">
5429
+ <xsl:call-template name="getFormattingTags"/>
5430
+ </xsl:variable>
5431
+
5432
+ <!-- <word>text</word> -->
5433
+ <xsl:call-template name="tokenize_with_tags">
5434
+ <xsl:with-param name="tags" select="$formatting_tags"/>
5435
+ <xsl:with-param name="text" select="normalize-space(translate($string_with_added_zerospaces, '​­', ' '))"/> <!-- replace zero-width-space and soft-hyphen to space -->
5436
+ </xsl:call-template>
5437
+ </xsl:template><xsl:template name="getFormattingTags">
5438
+ <tags>
5439
+ <xsl:if test="ancestor::*[local-name() = 'strong']"><tag>strong</tag></xsl:if>
5440
+ <xsl:if test="ancestor::*[local-name() = 'em']"><tag>em</tag></xsl:if>
5441
+ <xsl:if test="ancestor::*[local-name() = 'sub']"><tag>sub</tag></xsl:if>
5442
+ <xsl:if test="ancestor::*[local-name() = 'sup']"><tag>sup</tag></xsl:if>
5443
+ <xsl:if test="ancestor::*[local-name() = 'tt']"><tag>tt</tag></xsl:if>
5444
+ <xsl:if test="ancestor::*[local-name() = 'keep-together_within-line']"><tag>keep-together_within-line</tag></xsl:if>
5445
+ </tags>
4481
5446
  </xsl:template><xsl:template name="getLang">
4482
5447
  <xsl:variable name="language_current" select="normalize-space(//*[local-name()='bibdata']//*[local-name()='language'][@current = 'true'])"/>
4483
5448
  <xsl:variable name="language">
@@ -4532,6 +5497,9 @@
4532
5497
  <xsl:variable name="isDeleted" select="@deleted"/>
4533
5498
 
4534
5499
  <fo:inline xsl:use-attribute-sets="mathml-style">
5500
+
5501
+
5502
+
4535
5503
 
4536
5504
 
4537
5505
  <xsl:call-template name="setTrackChangesStyles">
@@ -4539,48 +5507,80 @@
4539
5507
  <xsl:with-param name="isDeleted" select="$isDeleted"/>
4540
5508
  </xsl:call-template>
4541
5509
 
5510
+ <xsl:if test="$add_math_as_text = 'true'">
5511
+ <!-- insert helper tag -->
5512
+ <!-- set unique font-size (fiction) -->
5513
+ <xsl:variable name="font-size_sfx"><xsl:number level="any"/></xsl:variable>
5514
+ <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 -->
5515
+ </xsl:if>
4542
5516
 
4543
-
4544
- <xsl:variable name="mathml">
4545
- <xsl:apply-templates select="." mode="mathml"/>
5517
+ <xsl:variable name="mathml_content">
5518
+ <xsl:apply-templates select="." mode="mathml_actual_text"/>
4546
5519
  </xsl:variable>
4547
- <fo:instream-foreign-object fox:alt-text="Math">
4548
5520
 
5521
+
5522
+ <xsl:call-template name="mathml_instream_object">
5523
+ <xsl:with-param name="mathml_content" select="$mathml_content"/>
5524
+ </xsl:call-template>
4549
5525
 
4550
-
4551
- <xsl:variable name="comment_text_following" select="following-sibling::node()[1][self::comment()]"/>
4552
- <xsl:variable name="comment_text_">
4553
- <xsl:choose>
4554
- <xsl:when test="normalize-space($comment_text_following) != ''">
4555
- <xsl:value-of select="$comment_text_following"/>
4556
- </xsl:when>
4557
- <xsl:otherwise>
4558
- <xsl:value-of select="normalize-space(translate(.,' ⁢',' '))"/>
4559
- </xsl:otherwise>
4560
- </xsl:choose>
4561
- </xsl:variable>
4562
- <xsl:variable name="comment_text" select="java:org.metanorma.fop.Util.unescape($comment_text_)"/>
4563
-
4564
- <xsl:if test="normalize-space($comment_text) != ''">
4565
- <!-- put Mathin Alternate Text -->
4566
- <xsl:attribute name="fox:alt-text">
4567
- <xsl:value-of select="java:org.metanorma.fop.Util.unescape($comment_text)"/>
4568
- </xsl:attribute>
4569
- </xsl:if>
4570
-
4571
- <xsl:variable name="mathml_content">
4572
- <xsl:apply-templates select="." mode="mathml_actual_text"/>
4573
- </xsl:variable>
4574
- <!-- put MathML in Actual Text -->
4575
- <xsl:attribute name="fox:actual-text">
4576
- <xsl:value-of select="$mathml_content"/>
4577
- </xsl:attribute>
4578
-
4579
-
4580
-
4581
- <xsl:copy-of select="xalan:nodeset($mathml)"/>
4582
- </fo:instream-foreign-object>
5526
+
4583
5527
  </fo:inline>
5528
+ </xsl:template><xsl:template name="getMathml_comment_text">
5529
+ <xsl:variable name="comment_text_following" select="following-sibling::node()[1][self::comment()]"/>
5530
+ <xsl:variable name="comment_text_">
5531
+ <xsl:choose>
5532
+ <xsl:when test="normalize-space($comment_text_following) != ''">
5533
+ <xsl:value-of select="$comment_text_following"/>
5534
+ </xsl:when>
5535
+ <xsl:otherwise>
5536
+ <xsl:value-of select="normalize-space(translate(.,' ⁢',' '))"/>
5537
+ </xsl:otherwise>
5538
+ </xsl:choose>
5539
+ </xsl:variable>
5540
+ <xsl:variable name="comment_text_2" select="java:org.metanorma.fop.Util.unescape($comment_text_)"/>
5541
+ <xsl:variable name="comment_text" select="java:trim(java:java.lang.String.new($comment_text_2))"/>
5542
+ <xsl:value-of select="$comment_text"/>
5543
+ </xsl:template><xsl:template name="mathml_instream_object">
5544
+ <xsl:param name="comment_text"/>
5545
+ <xsl:param name="mathml_content"/>
5546
+
5547
+ <xsl:variable name="comment_text_">
5548
+ <xsl:choose>
5549
+ <xsl:when test="normalize-space($comment_text) != ''"><xsl:value-of select="$comment_text"/></xsl:when>
5550
+ <xsl:otherwise><xsl:call-template name="getMathml_comment_text"/></xsl:otherwise>
5551
+ </xsl:choose>
5552
+ </xsl:variable>
5553
+
5554
+ <xsl:variable name="mathml">
5555
+ <xsl:apply-templates select="." mode="mathml"/>
5556
+ </xsl:variable>
5557
+
5558
+ <fo:instream-foreign-object fox:alt-text="Math">
5559
+
5560
+
5561
+
5562
+
5563
+
5564
+
5565
+
5566
+ <!-- put MathML in Actual Text -->
5567
+ <!-- DEBUG: mathml_content=<xsl:value-of select="$mathml_content"/> -->
5568
+ <xsl:attribute name="fox:actual-text">
5569
+ <xsl:value-of select="$mathml_content"/>
5570
+ </xsl:attribute>
5571
+
5572
+ <!-- <xsl:if test="$add_math_as_text = 'true'"> -->
5573
+ <xsl:if test="normalize-space($comment_text_) != ''">
5574
+ <!-- put Mathin Alternate Text -->
5575
+ <xsl:attribute name="fox:alt-text">
5576
+ <xsl:value-of select="$comment_text_"/>
5577
+ </xsl:attribute>
5578
+ </xsl:if>
5579
+ <!-- </xsl:if> -->
5580
+
5581
+ <xsl:copy-of select="xalan:nodeset($mathml)"/>
5582
+
5583
+ </fo:instream-foreign-object>
4584
5584
  </xsl:template><xsl:template match="mathml:*" mode="mathml_actual_text">
4585
5585
  <!-- <xsl:text>a+b</xsl:text> -->
4586
5586
  <xsl:text>&lt;</xsl:text>
@@ -4611,7 +5611,9 @@
4611
5611
  <!-- replace start and end spaces to non-break space -->
4612
5612
  <xsl:value-of select="java:replaceAll(java:java.lang.String.new(.),'(^ )|( $)',' ')"/>
4613
5613
  </xsl:copy>
4614
- </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">
5614
+ </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">
5615
+ <xsl:value-of select="."/><xsl:value-of select="$zero_width_space"/>
5616
+ </xsl:template><xsl:template match="*[local-name()='localityStack']"/><xsl:template match="*[local-name()='link']" name="link">
4615
5617
  <xsl:variable name="target">
4616
5618
  <xsl:choose>
4617
5619
  <xsl:when test="@updatetype = 'true'">
@@ -4851,7 +5853,12 @@
4851
5853
 
4852
5854
  <fo:inline xsl:use-attribute-sets="termnote-name-style">
4853
5855
 
5856
+ <xsl:if test="not(*[local-name() = 'name']/following-sibling::node()[1][self::text()][normalize-space()=''])">
5857
+ <xsl:attribute name="padding-right">1mm</xsl:attribute>
5858
+ </xsl:if>
5859
+
4854
5860
 
5861
+
4855
5862
 
4856
5863
  <!-- if 'p' contains all text in 'add' first and last elements in first p are 'add' -->
4857
5864
  <!-- <xsl:if test="*[not(local-name()='name')][1][node()[normalize-space() != ''][1][local-name() = 'add'] and node()[normalize-space() != ''][last()][local-name() = 'add']]"> -->
@@ -5212,18 +6219,33 @@
5212
6219
  </xsl:template><xsl:template match="*[local-name() = 'svg'][not(@width and @height)]" mode="svg_update">
5213
6220
  <xsl:copy>
5214
6221
  <xsl:apply-templates select="@*" mode="svg_update"/>
5215
- <xsl:variable name="viewbox">
6222
+ <xsl:variable name="viewbox_">
5216
6223
  <xsl:call-template name="split">
5217
6224
  <xsl:with-param name="pText" select="@viewBox"/>
5218
6225
  <xsl:with-param name="sep" select="' '"/>
5219
6226
  </xsl:call-template>
5220
6227
  </xsl:variable>
6228
+ <xsl:variable name="viewbox" select="xalan:nodeset($viewbox_)"/>
6229
+ <xsl:variable name="width" select="normalize-space($viewbox//item[3])"/>
6230
+ <xsl:variable name="height" select="normalize-space($viewbox//item[4])"/>
6231
+
5221
6232
  <xsl:attribute name="width">
5222
- <xsl:value-of select="round(xalan:nodeset($viewbox)//item[3])"/>
6233
+ <xsl:choose>
6234
+ <xsl:when test="$width != ''">
6235
+ <xsl:value-of select="round($width)"/>
6236
+ </xsl:when>
6237
+ <xsl:otherwise>400</xsl:otherwise> <!-- default width -->
6238
+ </xsl:choose>
5223
6239
  </xsl:attribute>
5224
6240
  <xsl:attribute name="height">
5225
- <xsl:value-of select="round(xalan:nodeset($viewbox)//item[4])"/>
6241
+ <xsl:choose>
6242
+ <xsl:when test="$height != ''">
6243
+ <xsl:value-of select="round($height)"/>
6244
+ </xsl:when>
6245
+ <xsl:otherwise>400</xsl:otherwise> <!-- default height -->
6246
+ </xsl:choose>
5226
6247
  </xsl:attribute>
6248
+
5227
6249
  <xsl:apply-templates mode="svg_update"/>
5228
6250
  </xsl:copy>
5229
6251
  </xsl:template><xsl:template match="*[local-name() = 'figure']/*[local-name() = 'image'][*[local-name() = 'svg']]" priority="3">
@@ -5418,7 +6440,11 @@
5418
6440
  <xsl:apply-templates mode="bookmarks"/>
5419
6441
  </xsl:template><xsl:template match="*[local-name() = 'title' or local-name() = 'name']//*[local-name() = 'stem']" mode="contents">
5420
6442
  <xsl:apply-templates select="."/>
5421
- </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">
6443
+ </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">
6444
+ <xsl:apply-templates mode="contents"/>
6445
+ </xsl:template><xsl:template match="*[local-name() = 'stem']" mode="bookmarks">
6446
+ <xsl:apply-templates mode="bookmarks"/>
6447
+ </xsl:template><xsl:template match="*[local-name() = 'span']" mode="bookmarks">
5422
6448
  <xsl:apply-templates mode="bookmarks"/>
5423
6449
  </xsl:template><xsl:template name="addBookmarks">
5424
6450
  <xsl:param name="contents"/>
@@ -5700,7 +6726,9 @@
5700
6726
  <xsl:apply-templates/>
5701
6727
  </xsl:otherwise>
5702
6728
  </xsl:choose>
5703
- </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">
6729
+ </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">
6730
+ <xsl:value-of select="."/>
6731
+ </xsl:template><xsl:template match="*[local-name() = 'tab']" mode="contents_item">
5704
6732
  <xsl:text> </xsl:text>
5705
6733
  </xsl:template><xsl:template match="*[local-name() = 'strong']" mode="contents_item">
5706
6734
  <xsl:copy>
@@ -5731,9 +6759,22 @@
5731
6759
  </xsl:when>
5732
6760
  <xsl:otherwise><xsl:apply-templates mode="contents_item"/></xsl:otherwise>
5733
6761
  </xsl:choose>
6762
+ </xsl:template><xsl:template match="text()" mode="contents_item">
6763
+ <xsl:call-template name="keep_together_standard_number"/>
6764
+ </xsl:template><xsl:template match="*[local-name() = 'span']" mode="contents_item">
6765
+ <xsl:apply-templates mode="contents_item"/>
5734
6766
  </xsl:template><xsl:template match="*[local-name()='sourcecode']" name="sourcecode">
5735
6767
 
5736
6768
  <fo:block-container xsl:use-attribute-sets="sourcecode-container-style">
6769
+
6770
+ <xsl:if test="not(ancestor::*[local-name() = 'li']) or ancestor::*[local-name() = 'example']">
6771
+ <xsl:attribute name="margin-left">0mm</xsl:attribute>
6772
+ </xsl:if>
6773
+
6774
+ <xsl:if test="ancestor::*[local-name() = 'example']">
6775
+ <xsl:attribute name="margin-right">0mm</xsl:attribute>
6776
+ </xsl:if>
6777
+
5737
6778
  <xsl:copy-of select="@id"/>
5738
6779
 
5739
6780
  <xsl:if test="parent::*[local-name() = 'note']">
@@ -5851,17 +6892,15 @@
5851
6892
 
5852
6893
  <!-- split text by zero-width space -->
5853
6894
  <xsl:variable name="text_step4">
5854
- <xsl:call-template name="split">
6895
+ <xsl:call-template name="split_for_interspers">
5855
6896
  <xsl:with-param name="pText" select="$text_step3"/>
5856
6897
  <xsl:with-param name="sep" select="$zero_width_space"/>
5857
- <xsl:with-param name="normalize-space">false</xsl:with-param>
5858
- <xsl:with-param name="keep_sep">true</xsl:with-param>
5859
6898
  </xsl:call-template>
5860
6899
  </xsl:variable>
5861
6900
 
5862
- <xsl:for-each select="xalan:nodeset($text_step4)/item">
6901
+ <xsl:for-each select="xalan:nodeset($text_step4)/node()">
5863
6902
  <xsl:choose>
5864
- <xsl:when test="string-length() &gt; 30"> <!-- word with length more than 30 will be interspersed with zero-width space -->
6903
+ <xsl:when test="local-name() = 'interspers'"> <!-- word with length more than 30 will be interspersed with zero-width space -->
5865
6904
  <xsl:call-template name="interspers">
5866
6905
  <xsl:with-param name="str" select="."/>
5867
6906
  </xsl:call-template>
@@ -5872,6 +6911,30 @@
5872
6911
  </xsl:choose>
5873
6912
  </xsl:for-each>
5874
6913
 
6914
+ </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">
6915
+ <xsl:param name="pText" select="."/>
6916
+ <xsl:param name="sep" select="','"/>
6917
+ <!-- word with length more than 30 will be interspersed with zero-width space -->
6918
+ <xsl:variable name="regex" select="concat('([^', $zero_width_space, ']{31,})')"/> <!-- sequence of characters (more 31), that doesn't contains zero-width space -->
6919
+ <xsl:variable name="text" select="java:replaceAll(java:java.lang.String.new($pText),$regex,concat($interspers_tag_open,'$1',$interspers_tag_close))"/>
6920
+ <xsl:call-template name="replace_tag_interspers">
6921
+ <xsl:with-param name="text" select="$text"/>
6922
+ </xsl:call-template>
6923
+ </xsl:template><xsl:template name="replace_tag_interspers">
6924
+ <xsl:param name="text"/>
6925
+ <xsl:choose>
6926
+ <xsl:when test="contains($text, $interspers_tag_open)">
6927
+ <xsl:value-of select="substring-before($text, $interspers_tag_open)"/>
6928
+ <xsl:variable name="text_after" select="substring-after($text, $interspers_tag_open)"/>
6929
+ <interspers>
6930
+ <xsl:value-of select="substring-before($text_after, $interspers_tag_close)"/>
6931
+ </interspers>
6932
+ <xsl:call-template name="replace_tag_interspers">
6933
+ <xsl:with-param name="text" select="substring-after($text_after, $interspers_tag_close)"/>
6934
+ </xsl:call-template>
6935
+ </xsl:when>
6936
+ <xsl:otherwise><xsl:value-of select="$text"/></xsl:otherwise>
6937
+ </xsl:choose>
5875
6938
  </xsl:template><xsl:template name="interspers">
5876
6939
  <xsl:param name="str"/>
5877
6940
  <xsl:param name="char" select="$zero_width_space"/>
@@ -6100,7 +7163,9 @@
6100
7163
  <!-- <xsl:attribute name="border">0.5pt solid black</xsl:attribute> -->
6101
7164
  </xsl:if>
6102
7165
  <xsl:variable name="simple-table">
6103
- <xsl:call-template name="getSimpleTable"/>
7166
+ <xsl:call-template name="getSimpleTable">
7167
+ <xsl:with-param name="id" select="@id"/>
7168
+ </xsl:call-template>
6104
7169
  </xsl:variable>
6105
7170
  <xsl:variable name="cols-count" select="count(xalan:nodeset($simple-table)//tr[1]/td)"/>
6106
7171
  <xsl:if test="$cols-count = 2 and not(ancestor::*[local-name()='table'])">
@@ -6207,44 +7272,72 @@
6207
7272
  </xsl:otherwise>
6208
7273
  </xsl:choose>
6209
7274
  </xsl:template><xsl:template match="*[local-name() = 'example']">
6210
- <fo:block id="{@id}" xsl:use-attribute-sets="example-style">
7275
+
7276
+ <fo:block-container id="{@id}" xsl:use-attribute-sets="example-style">
7277
+
6211
7278
 
6212
7279
  <xsl:if test="ancestor::rsd:ul or ancestor::rsd:ol">
6213
7280
  <xsl:attribute name="margin-top">6pt</xsl:attribute>
6214
7281
  <xsl:attribute name="margin-bottom">6pt</xsl:attribute>
6215
7282
  </xsl:if>
6216
7283
 
6217
-
7284
+
6218
7285
  <xsl:variable name="fo_element">
6219
- <xsl:if test=".//*[local-name() = 'table'] or .//*[local-name() = 'dl']">block</xsl:if>
7286
+ <xsl:if test=".//*[local-name() = 'table'] or .//*[local-name() = 'dl'] or *[not(local-name() = 'name')][1][local-name() = 'sourcecode']">block</xsl:if>
6220
7287
  inline
6221
7288
  </xsl:variable>
6222
7289
 
6223
- <!-- display 'EXAMPLE' -->
6224
- <xsl:apply-templates select="*[local-name()='name']">
6225
- <xsl:with-param name="fo_element" select="$fo_element"/>
6226
- </xsl:apply-templates>
7290
+ <fo:block-container margin-left="0mm">
6227
7291
 
6228
- <xsl:choose>
6229
- <xsl:when test="contains(normalize-space($fo_element), 'block')">
6230
- <fo:block-container xsl:use-attribute-sets="example-body-style">
6231
- <fo:block-container margin-left="0mm" margin-right="0mm">
6232
- <xsl:apply-templates select="node()[not(local-name() = 'name')]">
7292
+ <xsl:choose>
7293
+
7294
+ <xsl:when test="contains(normalize-space($fo_element), 'block')">
7295
+
7296
+ <!-- display name 'EXAMPLE' in a separate block -->
7297
+ <fo:block>
7298
+ <xsl:apply-templates select="*[local-name()='name']">
6233
7299
  <xsl:with-param name="fo_element" select="$fo_element"/>
6234
7300
  </xsl:apply-templates>
7301
+ </fo:block>
7302
+
7303
+ <fo:block-container xsl:use-attribute-sets="example-body-style">
7304
+ <fo:block-container margin-left="0mm" margin-right="0mm">
7305
+ <xsl:apply-templates select="node()[not(local-name() = 'name')]">
7306
+ <xsl:with-param name="fo_element" select="$fo_element"/>
7307
+ </xsl:apply-templates>
7308
+ </fo:block-container>
6235
7309
  </fo:block-container>
6236
- </fo:block-container>
6237
- </xsl:when>
6238
- <xsl:otherwise>
6239
- <fo:inline>
6240
- <xsl:apply-templates select="node()[not(local-name() = 'name')]">
6241
- <xsl:with-param name="fo_element" select="$fo_element"/>
6242
- </xsl:apply-templates>
6243
- </fo:inline>
6244
- </xsl:otherwise>
6245
- </xsl:choose>
6246
-
6247
- </fo:block>
7310
+ </xsl:when> <!-- end block -->
7311
+
7312
+ <xsl:otherwise> <!-- inline -->
7313
+
7314
+ <!-- display 'EXAMPLE' and first element in the same line -->
7315
+ <fo:block>
7316
+ <xsl:apply-templates select="*[local-name()='name']">
7317
+ <xsl:with-param name="fo_element" select="$fo_element"/>
7318
+ </xsl:apply-templates>
7319
+ <fo:inline>
7320
+ <xsl:apply-templates select="*[not(local-name() = 'name')][1]">
7321
+ <xsl:with-param name="fo_element" select="$fo_element"/>
7322
+ </xsl:apply-templates>
7323
+ </fo:inline>
7324
+ </fo:block>
7325
+
7326
+ <xsl:if test="*[not(local-name() = 'name')][position() &gt; 1]">
7327
+ <!-- display further elements in blocks -->
7328
+ <fo:block-container xsl:use-attribute-sets="example-body-style">
7329
+ <fo:block-container margin-left="0mm" margin-right="0mm">
7330
+ <xsl:apply-templates select="*[not(local-name() = 'name')][position() &gt; 1]">
7331
+ <xsl:with-param name="fo_element" select="'block'"/>
7332
+ </xsl:apply-templates>
7333
+ </fo:block-container>
7334
+ </fo:block-container>
7335
+ </xsl:if>
7336
+ </xsl:otherwise> <!-- end inline -->
7337
+
7338
+ </xsl:choose>
7339
+ </fo:block-container>
7340
+ </fo:block-container>
6248
7341
  </xsl:template><xsl:template match="*[local-name() = 'example']/*[local-name() = 'name']">
6249
7342
  <xsl:param name="fo_element">block</xsl:param>
6250
7343
 
@@ -6281,10 +7374,16 @@
6281
7374
  </xsl:variable>
6282
7375
  <xsl:choose>
6283
7376
  <xsl:when test="starts-with(normalize-space($element), 'block')">
6284
- <fo:block xsl:use-attribute-sets="example-p-style">
6285
-
6286
- <xsl:apply-templates/>
6287
- </fo:block>
7377
+ <fo:block-container>
7378
+ <xsl:if test="ancestor::*[local-name() = 'li'] and contains(normalize-space($fo_element), 'block')">
7379
+ <xsl:attribute name="margin-left">0mm</xsl:attribute>
7380
+ <xsl:attribute name="margin-right">0mm</xsl:attribute>
7381
+ </xsl:if>
7382
+ <fo:block xsl:use-attribute-sets="example-p-style">
7383
+
7384
+ <xsl:apply-templates/>
7385
+ </fo:block>
7386
+ </fo:block-container>
6288
7387
  </xsl:when>
6289
7388
  <xsl:otherwise>
6290
7389
  <fo:inline xsl:use-attribute-sets="example-p-style">
@@ -6329,7 +7428,7 @@
6329
7428
  </xsl:otherwise>
6330
7429
  </xsl:choose> -->
6331
7430
  </fo:block>
6332
- </xsl:template><xsl:template match="*[local-name() = 'termsource']/text()[starts-with(., '[SOURCE: Adapted from: ')]" priority="2">
7431
+ </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">
6333
7432
  <xsl:text>[</xsl:text><xsl:value-of select="substring-after(., '[SOURCE: ')"/>
6334
7433
  </xsl:template><xsl:template match="*[local-name() = 'termsource']/text()">
6335
7434
  <xsl:if test="normalize-space() != ''">
@@ -6463,7 +7562,16 @@
6463
7562
  </fo:inline>
6464
7563
  </xsl:when>
6465
7564
  <xsl:otherwise> <!-- if there is key('bibitems_hidden', $current_bibitemid) -->
6466
- <fo:inline><xsl:apply-templates/></fo:inline>
7565
+
7566
+ <!-- if in bibitem[@hidden='true'] there is url[@type='src'], then create hyperlink -->
7567
+ <xsl:variable name="uri_src" select="normalize-space($bibitems_hidden/*[local-name() ='bibitem'][@id = $current_bibitemid]/*[local-name() = 'uri'][@type = 'src'])"/>
7568
+ <xsl:choose>
7569
+ <xsl:when test="$uri_src != ''">
7570
+ <fo:basic-link external-destination="{$uri_src}" fox:alt-text="{$uri_src}"><xsl:apply-templates/></fo:basic-link>
7571
+ </xsl:when>
7572
+ <xsl:otherwise><fo:inline><xsl:apply-templates/></fo:inline></xsl:otherwise>
7573
+ </xsl:choose>
7574
+
6467
7575
  </xsl:otherwise>
6468
7576
  </xsl:choose>
6469
7577
  </xsl:template><xsl:template match="*[local-name() = 'tab']">
@@ -6634,10 +7742,24 @@
6634
7742
 
6635
7743
  </fo:block>
6636
7744
  <xsl:apply-templates/>
6637
- </xsl:template><xsl:template match="*[local-name() = 'review']">
7745
+ </xsl:template><xsl:template match="*[local-name() = 'review']"> <!-- 'review' will be processed in mn2pdf/review.xsl -->
6638
7746
  <!-- comment 2019-11-29 -->
6639
7747
  <!-- <fo:block font-weight="bold">Review:</fo:block>
6640
7748
  <xsl:apply-templates /> -->
7749
+
7750
+ <xsl:variable name="id_from" select="normalize-space(current()/@from)"/>
7751
+
7752
+ <xsl:choose>
7753
+ <!-- if there isn't the attribute '@from', then -->
7754
+ <xsl:when test="$id_from = ''">
7755
+ <fo:block id="{@id}" font-size="1pt"><xsl:value-of select="$hair_space"/></fo:block>
7756
+ </xsl:when>
7757
+ <!-- if there isn't element with id 'from', then create 'bookmark' here -->
7758
+ <xsl:when test="not(ancestor::*[contains(local-name(), '-standard')]//*[@id = $id_from])">
7759
+ <fo:block id="{@from}" font-size="1pt"><xsl:value-of select="$hair_space"/></fo:block>
7760
+ </xsl:when>
7761
+ </xsl:choose>
7762
+
6641
7763
  </xsl:template><xsl:template match="*[local-name() = 'name']/text()">
6642
7764
  <!-- 0xA0 to space replacement -->
6643
7765
  <xsl:value-of select="java:replaceAll(java:java.lang.String.new(.),' ',' ')"/>
@@ -6996,7 +8118,10 @@
6996
8118
  <!-- to split by '_' and other chars -->
6997
8119
  <xsl:call-template name="add-zero-spaces-java"/>
6998
8120
  </xsl:template><xsl:template match="*[local-name() = 'bookmark']" name="bookmark">
6999
- <fo:inline id="{@id}" font-size="1pt"/>
8121
+ <!-- <fo:inline id="{@id}" font-size="1pt"/> -->
8122
+ <fo:inline id="{@id}" font-size="1pt"><xsl:value-of select="$hair_space"/></fo:inline>
8123
+ <!-- we need to add zero-width space, otherwise this fo:inline is missing in IF xml -->
8124
+ <xsl:if test="not(following-sibling::node()[normalize-space() != ''])"><fo:inline font-size="1pt"> </fo:inline></xsl:if>
7000
8125
  </xsl:template><xsl:template match="*[local-name() = 'errata']">
7001
8126
  <!-- <row>
7002
8127
  <date>05-07-2013</date>
@@ -7567,6 +8692,120 @@
7567
8692
  <xsl:apply-templates select="." mode="update_xml_step1"/>
7568
8693
  </xsl:for-each>
7569
8694
  </xsl:copy>
8695
+ </xsl:template><xsl:template match="*[local-name() = 'span']" mode="update_xml_step1">
8696
+ <xsl:apply-templates mode="update_xml_step1"/>
8697
+ </xsl:template><xsl:template match="@*|node()" mode="update_xml_enclose_keep-together_within-line">
8698
+ <xsl:copy>
8699
+ <xsl:apply-templates select="@*|node()" mode="update_xml_enclose_keep-together_within-line"/>
8700
+ </xsl:copy>
8701
+ </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">
8702
+
8703
+ <!-- enclose standard's number into tag 'keep-together_within-line' -->
8704
+ <xsl:variable name="regex_standard_reference">([A-Z]{2,}(/[A-Z]{2,})* \d+(-\d+)*(:\d{4})?)</xsl:variable>
8705
+ <xsl:variable name="tag_keep-together_within-line_open">###<xsl:value-of select="$element_name_keep-together_within-line"/>###</xsl:variable>
8706
+ <xsl:variable name="tag_keep-together_within-line_close">###/<xsl:value-of select="$element_name_keep-together_within-line"/>###</xsl:variable>
8707
+ <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))"/>
8708
+ <xsl:variable name="text"><text><xsl:call-template name="replace_text_tags">
8709
+ <xsl:with-param name="tag_open" select="$tag_keep-together_within-line_open"/>
8710
+ <xsl:with-param name="tag_close" select="$tag_keep-together_within-line_close"/>
8711
+ <xsl:with-param name="text" select="$text_"/>
8712
+ </xsl:call-template></text></xsl:variable>
8713
+
8714
+ <xsl:variable name="parent" select="local-name(..)"/>
8715
+
8716
+ <xsl:variable name="text2">
8717
+ <text><xsl:for-each select="xalan:nodeset($text)/text/node()">
8718
+ <xsl:copy-of select="."/>
8719
+ </xsl:for-each></text>
8720
+ </xsl:variable>
8721
+
8722
+ <!-- keep-together_within-line for: a/b, aaa/b, a/bbb, /b -->
8723
+ <xsl:variable name="regex_solidus_units">((\b((\S{1,3}\/\S+)|(\S+\/\S{1,3}))\b)|(\/\S{1,3})\b)</xsl:variable>
8724
+ <xsl:variable name="text3">
8725
+ <text><xsl:for-each select="xalan:nodeset($text2)/text/node()">
8726
+ <xsl:choose>
8727
+ <xsl:when test="self::text()">
8728
+ <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))"/>
8729
+ <xsl:variable name="text_units"><text><xsl:call-template name="replace_text_tags">
8730
+ <xsl:with-param name="tag_open" select="$tag_keep-together_within-line_open"/>
8731
+ <xsl:with-param name="tag_close" select="$tag_keep-together_within-line_close"/>
8732
+ <xsl:with-param name="text" select="$text_units_"/>
8733
+ </xsl:call-template></text></xsl:variable>
8734
+ <xsl:copy-of select="xalan:nodeset($text_units)/text/node()"/>
8735
+ </xsl:when>
8736
+ <xsl:otherwise><xsl:copy-of select="."/></xsl:otherwise> <!-- copy 'as-is' for <fo:inline keep-together.within-line="always" ... -->
8737
+ </xsl:choose>
8738
+ </xsl:for-each></text>
8739
+ </xsl:variable>
8740
+
8741
+ <xsl:choose>
8742
+ <xsl:when test="ancestor::*[local-name() = 'td' or local-name() = 'th']">
8743
+ <!-- keep-together_within-line for: a.b, aaa.b, a.bbb, .b in table's cell ONLY -->
8744
+ <xsl:variable name="regex_dots_units">((\b((\S{1,3}\.\S+)|(\S+\.\S{1,3}))\b)|(\.\S{1,3})\b)</xsl:variable>
8745
+ <xsl:for-each select="xalan:nodeset($text3)/text/node()">
8746
+ <xsl:choose>
8747
+ <xsl:when test="self::text()">
8748
+ <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))"/>
8749
+ <xsl:variable name="text_dots"><text><xsl:call-template name="replace_text_tags">
8750
+ <xsl:with-param name="tag_open" select="$tag_keep-together_within-line_open"/>
8751
+ <xsl:with-param name="tag_close" select="$tag_keep-together_within-line_close"/>
8752
+ <xsl:with-param name="text" select="$text_dots_"/>
8753
+ </xsl:call-template></text></xsl:variable>
8754
+ <xsl:copy-of select="xalan:nodeset($text_dots)/text/node()"/>
8755
+ </xsl:when>
8756
+ <xsl:otherwise><xsl:copy-of select="."/></xsl:otherwise> <!-- copy 'as-is' for <fo:inline keep-together.within-line="always" ... -->
8757
+ </xsl:choose>
8758
+ </xsl:for-each>
8759
+ </xsl:when>
8760
+ <xsl:otherwise><xsl:copy-of select="xalan:nodeset($text3)/text/node()"/></xsl:otherwise>
8761
+ </xsl:choose>
8762
+
8763
+ </xsl:template><xsl:template name="replace_text_tags">
8764
+ <xsl:param name="tag_open"/>
8765
+ <xsl:param name="tag_close"/>
8766
+ <xsl:param name="text"/>
8767
+ <xsl:choose>
8768
+ <xsl:when test="contains($text, $tag_open)">
8769
+ <xsl:value-of select="substring-before($text, $tag_open)"/>
8770
+ <xsl:variable name="text_after" select="substring-after($text, $tag_open)"/>
8771
+
8772
+ <xsl:element name="{substring-before(substring-after($tag_open, '###'),'###')}">
8773
+ <xsl:value-of select="substring-before($text_after, $tag_close)"/>
8774
+ </xsl:element>
8775
+
8776
+ <xsl:call-template name="replace_text_tags">
8777
+ <xsl:with-param name="tag_open" select="$tag_open"/>
8778
+ <xsl:with-param name="tag_close" select="$tag_close"/>
8779
+ <xsl:with-param name="text" select="substring-after($text_after, $tag_close)"/>
8780
+ </xsl:call-template>
8781
+ </xsl:when>
8782
+ <xsl:otherwise><xsl:value-of select="$text"/></xsl:otherwise>
8783
+ </xsl:choose>
8784
+ </xsl:template><xsl:template name="printEdition">
8785
+ <xsl:variable name="edition_i18n" select="normalize-space((//*[contains(local-name(), '-standard')])[1]/*[local-name() = 'bibdata']/*[local-name() = 'edition'][normalize-space(@language) != ''])"/>
8786
+ <xsl:text> </xsl:text>
8787
+ <xsl:choose>
8788
+ <xsl:when test="$edition_i18n != ''">
8789
+ <!-- Example: <edition language="fr">deuxième édition</edition> -->
8790
+ <xsl:call-template name="capitalize">
8791
+ <xsl:with-param name="str" select="$edition_i18n"/>
8792
+ </xsl:call-template>
8793
+ </xsl:when>
8794
+ <xsl:otherwise>
8795
+ <xsl:variable name="edition" select="normalize-space((//*[contains(local-name(), '-standard')])[1]/*[local-name() = 'bibdata']/*[local-name() = 'edition'])"/>
8796
+ <xsl:if test="$edition != ''"> <!-- Example: 1.3 -->
8797
+ <xsl:call-template name="capitalize">
8798
+ <xsl:with-param name="str">
8799
+ <xsl:call-template name="getLocalizedString">
8800
+ <xsl:with-param name="key">edition</xsl:with-param>
8801
+ </xsl:call-template>
8802
+ </xsl:with-param>
8803
+ </xsl:call-template>
8804
+ <xsl:text> </xsl:text>
8805
+ <xsl:value-of select="$edition"/>
8806
+ </xsl:if>
8807
+ </xsl:otherwise>
8808
+ </xsl:choose>
7570
8809
  </xsl:template><xsl:template name="convertDate">
7571
8810
  <xsl:param name="date"/>
7572
8811
  <xsl:param name="format" select="'short'"/>
@@ -8254,4 +9493,40 @@
8254
9493
  <xsl:value-of select="$value"/>
8255
9494
  </xsl:otherwise>
8256
9495
  </xsl:choose>
9496
+ </xsl:template><xsl:template match="*" mode="print_as_xml">
9497
+ <xsl:param name="level">0</xsl:param>
9498
+
9499
+ <fo:block margin-left="{2*$level}mm">
9500
+ <xsl:text>
9501
+ &lt;</xsl:text>
9502
+ <xsl:value-of select="local-name()"/>
9503
+ <xsl:for-each select="@*">
9504
+ <xsl:text> </xsl:text>
9505
+ <xsl:value-of select="local-name()"/>
9506
+ <xsl:text>="</xsl:text>
9507
+ <xsl:value-of select="."/>
9508
+ <xsl:text>"</xsl:text>
9509
+ </xsl:for-each>
9510
+ <xsl:text>&gt;</xsl:text>
9511
+
9512
+ <xsl:if test="not(*)">
9513
+ <fo:inline font-weight="bold"><xsl:value-of select="."/></fo:inline>
9514
+ <xsl:text>&lt;/</xsl:text>
9515
+ <xsl:value-of select="local-name()"/>
9516
+ <xsl:text>&gt;</xsl:text>
9517
+ </xsl:if>
9518
+ </fo:block>
9519
+
9520
+ <xsl:if test="*">
9521
+ <fo:block>
9522
+ <xsl:apply-templates mode="print_as_xml">
9523
+ <xsl:with-param name="level" select="$level + 1"/>
9524
+ </xsl:apply-templates>
9525
+ </fo:block>
9526
+ <fo:block margin-left="{2*$level}mm">
9527
+ <xsl:text>&lt;/</xsl:text>
9528
+ <xsl:value-of select="local-name()"/>
9529
+ <xsl:text>&gt;</xsl:text>
9530
+ </fo:block>
9531
+ </xsl:if>
8257
9532
  </xsl:template></xsl:stylesheet>