metanorma-un 0.8.4 → 0.8.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -10,7 +10,7 @@
10
10
 
11
11
  <xsl:variable name="debug">false</xsl:variable>
12
12
 
13
- <xsl:variable name="contents">
13
+ <xsl:variable name="contents_">
14
14
  <contents>
15
15
  <xsl:apply-templates select="/*/*[local-name()='preface']/*[local-name()='foreword']" mode="contents"/>
16
16
  <xsl:apply-templates select="/*/*[local-name()='preface']/*[local-name()='introduction']" mode="contents"/>
@@ -20,9 +20,11 @@
20
20
  <xsl:apply-templates select="/un:un-standard/un:sections/*" mode="contents"/>
21
21
  <xsl:apply-templates select="/un:un-standard/un:annex" mode="contents"/>
22
22
  <xsl:apply-templates select="/un:un-standard/un:bibliography/un:references" mode="contents"/>
23
+
24
+ <xsl:call-template name="processTablesFigures_Contents"/>
23
25
  </contents>
24
26
  </xsl:variable>
25
-
27
+ <xsl:variable name="contents" select="xalan:nodeset($contents_)"/>
26
28
 
27
29
  <xsl:variable name="title" select="/un:un-standard/un:bibdata/un:title[@language = 'en' and @type = 'main']"/>
28
30
 
@@ -276,7 +278,7 @@
276
278
  <xsl:if test="$debug = 'true'">
277
279
  <xsl:text disable-output-escaping="yes">&lt;!--</xsl:text>
278
280
  DEBUG
279
- contents=<xsl:copy-of select="xalan:nodeset($contents)"/>
281
+ contents=<xsl:copy-of select="$contents"/>
280
282
  <xsl:text disable-output-escaping="yes">--&gt;</xsl:text>
281
283
  </xsl:if>
282
284
 
@@ -869,7 +871,7 @@
869
871
  <xsl:text>Contents</xsl:text>
870
872
 
871
873
  </title-toc>
872
-
874
+
873
875
  <title-descriptors lang="en">Descriptors</title-descriptors>
874
876
 
875
877
  <title-part lang="en">
@@ -905,7 +907,31 @@
905
907
  <title-continued lang="en">(continued)</title-continued>
906
908
  <title-continued lang="fr">(continué)</title-continued>
907
909
 
908
- </xsl:variable><xsl:variable name="titles" select="xalan:nodeset($titles_)"/><xsl:variable name="bibdata">
910
+ </xsl:variable><xsl:variable name="titles" select="xalan:nodeset($titles_)"/><xsl:variable name="title-list-tables">
911
+ <xsl:variable name="toc_table_title" select="//*[contains(local-name(), '-standard')]/*[local-name() = 'misc-container']/*[local-name() = 'toc'][@type='table']/*[local-name() = 'title']"/>
912
+ <xsl:value-of select="$toc_table_title"/>
913
+ <xsl:if test="normalize-space($toc_table_title) = ''">
914
+ <xsl:call-template name="getTitle">
915
+ <xsl:with-param name="name" select="'title-list-tables'"/>
916
+ </xsl:call-template>
917
+ </xsl:if>
918
+ </xsl:variable><xsl:variable name="title-list-figures">
919
+ <xsl:variable name="toc_figure_title" select="//*[contains(local-name(), '-standard')]/*[local-name() = 'misc-container']/*[local-name() = 'toc'][@type='figure']/*[local-name() = 'title']"/>
920
+ <xsl:value-of select="$toc_figure_title"/>
921
+ <xsl:if test="normalize-space($toc_figure_title) = ''">
922
+ <xsl:call-template name="getTitle">
923
+ <xsl:with-param name="name" select="'title-list-figures'"/>
924
+ </xsl:call-template>
925
+ </xsl:if>
926
+ </xsl:variable><xsl:variable name="title-list-recommendations">
927
+ <xsl:variable name="toc_requirement_title" select="//*[contains(local-name(), '-standard')]/*[local-name() = 'misc-container']/*[local-name() = 'toc'][@type='requirement']/*[local-name() = 'title']"/>
928
+ <xsl:value-of select="$toc_requirement_title"/>
929
+ <xsl:if test="normalize-space($toc_requirement_title) = ''">
930
+ <xsl:call-template name="getTitle">
931
+ <xsl:with-param name="name" select="'title-list-recommendations'"/>
932
+ </xsl:call-template>
933
+ </xsl:if>
934
+ </xsl:variable><xsl:variable name="bibdata">
909
935
  <xsl:copy-of select="//*[contains(local-name(), '-standard')]/*[local-name() = 'bibdata']"/>
910
936
  <xsl:copy-of select="//*[contains(local-name(), '-standard')]/*[local-name() = 'localized-strings']"/>
911
937
  </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">
@@ -2117,6 +2143,30 @@
2117
2143
  <xsl:sort select="@displayorder" data-type="number"/>
2118
2144
  <xsl:apply-templates select="." mode="contents"/>
2119
2145
  </xsl:for-each>
2146
+ </xsl:template><xsl:template name="processTablesFigures_Contents">
2147
+ <xsl:param name="always"/>
2148
+ <xsl:if test="(//*[contains(local-name(), '-standard')]/*[local-name() = 'misc-container']/*[local-name() = 'toc'][@type='table']/*[local-name() = 'title']) or normalize-space($always) = 'true'">
2149
+ <xsl:call-template name="processTables_Contents"/>
2150
+ </xsl:if>
2151
+ <xsl:if test="(//*[contains(local-name(), '-standard')]/*[local-name() = 'misc-container']/*[local-name() = 'toc'][@type='figure']/*[local-name() = 'title']) or normalize-space($always) = 'true'">
2152
+ <xsl:call-template name="processFigures_Contents"/>
2153
+ </xsl:if>
2154
+ </xsl:template><xsl:template name="processTables_Contents">
2155
+ <tables>
2156
+ <xsl:for-each select="//*[local-name() = 'table'][@id and *[local-name() = 'name'] and normalize-space(@id) != '']">
2157
+ <table id="{@id}" alt-text="{*[local-name() = 'name']}">
2158
+ <xsl:copy-of select="*[local-name() = 'name']"/>
2159
+ </table>
2160
+ </xsl:for-each>
2161
+ </tables>
2162
+ </xsl:template><xsl:template name="processFigures_Contents">
2163
+ <figures>
2164
+ <xsl:for-each select="//*[local-name() = 'figure'][@id and *[local-name() = 'name'] and not(@unnumbered = 'true') and normalize-space(@id) != ''] | //*[@id and starts-with(*[local-name() = 'name'], 'Figure ') and normalize-space(@id) != '']">
2165
+ <figure id="{@id}" alt-text="{*[local-name() = 'name']}">
2166
+ <xsl:copy-of select="*[local-name() = 'name']"/>
2167
+ </figure>
2168
+ </xsl:for-each>
2169
+ </figures>
2120
2170
  </xsl:template><xsl:template name="processPrefaceSectionsDefault">
2121
2171
  <xsl:for-each select="/*/*[local-name()='preface']/*">
2122
2172
  <xsl:sort select="@displayorder" data-type="number"/>
@@ -2138,8 +2188,27 @@
2138
2188
  <xsl:sort select="@displayorder" data-type="number"/>
2139
2189
  <xsl:apply-templates select="."/>
2140
2190
  </xsl:for-each>
2141
- </xsl:template><xsl:template match="text()">
2142
- <xsl:value-of select="."/>
2191
+ </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">
2192
+ <xsl:variable name="regex_standard_reference">([A-Z]{2,}(/[A-Z]{2,})* \d+(-\d+)*(:\d{4})?)</xsl:variable>
2193
+ <xsl:variable name="text" select="java:replaceAll(java:java.lang.String.new(.),$regex_standard_reference,concat($tag_open,'$1',$tag_close))"/>
2194
+ <xsl:call-template name="replace_fo_inline">
2195
+ <xsl:with-param name="text" select="$text"/>
2196
+ </xsl:call-template>
2197
+ </xsl:template><xsl:template name="replace_fo_inline">
2198
+ <xsl:param name="text"/>
2199
+ <xsl:choose>
2200
+ <xsl:when test="contains($text, $tag_open)">
2201
+ <xsl:value-of select="substring-before($text, $tag_open)"/>
2202
+ <xsl:text disable-output-escaping="yes">&lt;fo:inline keep-together.within-line="always"&gt;</xsl:text>
2203
+ <xsl:variable name="text_after" select="substring-after($text, $tag_open)"/>
2204
+ <xsl:value-of select="substring-before($text_after, $tag_close)"/>
2205
+ <xsl:text disable-output-escaping="yes">&lt;/fo:inline&gt;</xsl:text>
2206
+ <xsl:call-template name="replace_fo_inline">
2207
+ <xsl:with-param name="text" select="substring-after($text_after, $tag_close)"/>
2208
+ </xsl:call-template>
2209
+ </xsl:when>
2210
+ <xsl:otherwise><xsl:value-of select="$text"/></xsl:otherwise>
2211
+ </xsl:choose>
2143
2212
  </xsl:template><xsl:template match="*[local-name()='br']">
2144
2213
  <xsl:value-of select="$linebreak"/>
2145
2214
  </xsl:template><xsl:template match="*[local-name()='copyright-statement']">
@@ -2905,37 +2974,7 @@
2905
2974
 
2906
2975
  <!-- list of footnotes to calculate actual footnotes number -->
2907
2976
  <xsl:variable name="p_fn_">
2908
- <xsl:choose>
2909
- <xsl:when test="@current_fn_number"> <!-- for BSI, footnote reference number calculated already -->
2910
- <fn gen_id="{generate-id(.)}">
2911
- <xsl:copy-of select="@*"/>
2912
- <xsl:copy-of select="node()"/>
2913
- </fn>
2914
- </xsl:when>
2915
- <xsl:otherwise>
2916
- <!-- itetation for:
2917
- footnotes in bibdata/title
2918
- footnotes in bibliography
2919
- footnotes in document's body (except table's head/body/foot and figure text)
2920
- -->
2921
- <xsl:for-each select="ancestor::*[contains(local-name(), '-standard')]/*[local-name() = 'bibdata']/*[local-name() = 'note'][@type='title-footnote']">
2922
- <fn gen_id="{generate-id(.)}">
2923
- <xsl:copy-of select="@*"/>
2924
- <xsl:copy-of select="node()"/>
2925
- </fn>
2926
- </xsl:for-each>
2927
- <xsl:for-each select="ancestor::*[contains(local-name(), '-standard')]/*[local-name()='preface']/* | ancestor::*[contains(local-name(), '-standard')]/*[local-name()='sections']/* | ancestor::*[contains(local-name(), '-standard')]/*[local-name()='annex'] | ancestor::*[contains(local-name(), '-standard')]/*[local-name()='bibliography']/*">
2928
- <xsl:sort select="@displayorder" data-type="number"/>
2929
- <xsl:for-each select=".//*[local-name() = 'bibitem'][ancestor::*[local-name() = 'references']]/*[local-name() = 'note'] | .//*[local-name() = 'fn'][not(ancestor::*[(local-name() = 'table' or local-name() = 'figure') and not(ancestor::*[local-name() = 'name'])])][generate-id(.)=generate-id(key('kfn',@reference)[1])]">
2930
- <!-- copy unique fn -->
2931
- <fn gen_id="{generate-id(.)}">
2932
- <xsl:copy-of select="@*"/>
2933
- <xsl:copy-of select="node()"/>
2934
- </fn>
2935
- </xsl:for-each>
2936
- </xsl:for-each>
2937
- </xsl:otherwise>
2938
- </xsl:choose>
2977
+ <xsl:call-template name="get_fn_list"/>
2939
2978
  </xsl:variable>
2940
2979
  <xsl:variable name="p_fn" select="xalan:nodeset($p_fn_)"/>
2941
2980
 
@@ -2996,6 +3035,38 @@
2996
3035
  <xsl:copy-of select="$footnote_inline"/>
2997
3036
  </xsl:otherwise>
2998
3037
  </xsl:choose>
3038
+ </xsl:template><xsl:template name="get_fn_list">
3039
+ <xsl:choose>
3040
+ <xsl:when test="@current_fn_number"> <!-- for BSI, footnote reference number calculated already -->
3041
+ <fn gen_id="{generate-id(.)}">
3042
+ <xsl:copy-of select="@*"/>
3043
+ <xsl:copy-of select="node()"/>
3044
+ </fn>
3045
+ </xsl:when>
3046
+ <xsl:otherwise>
3047
+ <!-- itetation for:
3048
+ footnotes in bibdata/title
3049
+ footnotes in bibliography
3050
+ footnotes in document's body (except table's head/body/foot and figure text)
3051
+ -->
3052
+ <xsl:for-each select="ancestor::*[contains(local-name(), '-standard')]/*[local-name() = 'bibdata']/*[local-name() = 'note'][@type='title-footnote']">
3053
+ <fn gen_id="{generate-id(.)}">
3054
+ <xsl:copy-of select="@*"/>
3055
+ <xsl:copy-of select="node()"/>
3056
+ </fn>
3057
+ </xsl:for-each>
3058
+ <xsl:for-each select="ancestor::*[contains(local-name(), '-standard')]/*[local-name()='preface']/* | ancestor::*[contains(local-name(), '-standard')]/*[local-name()='sections']/* | ancestor::*[contains(local-name(), '-standard')]/*[local-name()='annex'] | ancestor::*[contains(local-name(), '-standard')]/*[local-name()='bibliography']/*">
3059
+ <xsl:sort select="@displayorder" data-type="number"/>
3060
+ <xsl:for-each select=".//*[local-name() = 'bibitem'][ancestor::*[local-name() = 'references']]/*[local-name() = 'note'] | .//*[local-name() = 'fn'][not(ancestor::*[(local-name() = 'table' or local-name() = 'figure') and not(ancestor::*[local-name() = 'name'])])][generate-id(.)=generate-id(key('kfn',@reference)[1])]">
3061
+ <!-- copy unique fn -->
3062
+ <fn gen_id="{generate-id(.)}">
3063
+ <xsl:copy-of select="@*"/>
3064
+ <xsl:copy-of select="node()"/>
3065
+ </fn>
3066
+ </xsl:for-each>
3067
+ </xsl:for-each>
3068
+ </xsl:otherwise>
3069
+ </xsl:choose>
2999
3070
  </xsl:template><xsl:template name="table_fn_display">
3000
3071
  <xsl:variable name="references">
3001
3072
 
@@ -3167,7 +3238,7 @@
3167
3238
  </fo:inline>
3168
3239
  </xsl:template><xsl:template match="*[local-name()='fn']/text()[normalize-space() != '']">
3169
3240
  <fo:inline><xsl:value-of select="."/></fo:inline>
3170
- </xsl:template><xsl:template match="*[local-name()='fn']/*[local-name()='p']">
3241
+ </xsl:template><xsl:template match="*[local-name()='fn']//*[local-name()='p']">
3171
3242
  <fo:inline>
3172
3243
  <xsl:apply-templates/>
3173
3244
  </fo:inline>
@@ -4871,13 +4942,14 @@
4871
4942
  <xsl:apply-templates mode="bookmarks"/>
4872
4943
  </xsl:template><xsl:template name="addBookmarks">
4873
4944
  <xsl:param name="contents"/>
4874
- <xsl:if test="xalan:nodeset($contents)//item">
4945
+ <xsl:variable name="contents_nodes" select="xalan:nodeset($contents)"/>
4946
+ <xsl:if test="$contents_nodes//item">
4875
4947
  <fo:bookmark-tree>
4876
4948
  <xsl:choose>
4877
- <xsl:when test="xalan:nodeset($contents)/doc">
4949
+ <xsl:when test="$contents_nodes/doc">
4878
4950
  <xsl:choose>
4879
- <xsl:when test="count(xalan:nodeset($contents)/doc) &gt; 1">
4880
- <xsl:for-each select="xalan:nodeset($contents)/doc">
4951
+ <xsl:when test="count($contents_nodes/doc) &gt; 1">
4952
+ <xsl:for-each select="$contents_nodes/doc">
4881
4953
  <fo:bookmark internal-destination="{contents/item[1]/@id}" starting-state="hide">
4882
4954
  <xsl:if test="@bundle = 'true'">
4883
4955
  <xsl:attribute name="internal-destination"><xsl:value-of select="@firstpage_id"/></xsl:attribute>
@@ -4928,7 +5000,7 @@
4928
5000
  </xsl:for-each>
4929
5001
  </xsl:when>
4930
5002
  <xsl:otherwise>
4931
- <xsl:for-each select="xalan:nodeset($contents)/doc">
5003
+ <xsl:for-each select="$contents_nodes/doc">
4932
5004
 
4933
5005
  <xsl:apply-templates select="contents/item" mode="bookmark"/>
4934
5006
 
@@ -4946,25 +5018,36 @@
4946
5018
  </xsl:choose>
4947
5019
  </xsl:when>
4948
5020
  <xsl:otherwise>
4949
- <xsl:apply-templates select="xalan:nodeset($contents)/contents/item" mode="bookmark"/>
5021
+ <xsl:apply-templates select="$contents_nodes/contents/item" mode="bookmark"/>
5022
+
5023
+ <xsl:call-template name="insertFigureBookmarks">
5024
+ <xsl:with-param name="contents" select="$contents_nodes/contents"/>
5025
+ </xsl:call-template>
5026
+
5027
+ <xsl:call-template name="insertTableBookmarks">
5028
+ <xsl:with-param name="contents" select="$contents_nodes/contents"/>
5029
+ <xsl:with-param name="lang" select="@lang"/>
5030
+ </xsl:call-template>
5031
+
4950
5032
  </xsl:otherwise>
4951
5033
  </xsl:choose>
4952
5034
 
5035
+
4953
5036
 
4954
5037
 
4955
5038
 
4956
5039
 
4957
-
4958
-
5040
+
4959
5041
 
4960
5042
  </fo:bookmark-tree>
4961
5043
  </xsl:if>
4962
5044
  </xsl:template><xsl:template name="insertFigureBookmarks">
4963
5045
  <xsl:param name="contents"/>
4964
- <xsl:if test="xalan:nodeset($contents)/figure">
4965
- <fo:bookmark internal-destination="{xalan:nodeset($contents)/figure[1]/@id}" starting-state="hide">
5046
+ <xsl:variable name="contents_nodes" select="xalan:nodeset($contents)"/>
5047
+ <xsl:if test="$contents_nodes/figure">
5048
+ <fo:bookmark internal-destination="{$contents_nodes/figure[1]/@id}" starting-state="hide">
4966
5049
  <fo:bookmark-title>Figures</fo:bookmark-title>
4967
- <xsl:for-each select="xalan:nodeset($contents)/figure">
5050
+ <xsl:for-each select="$contents_nodes/figure">
4968
5051
  <fo:bookmark internal-destination="{@id}">
4969
5052
  <fo:bookmark-title>
4970
5053
  <xsl:value-of select="normalize-space(title)"/>
@@ -4973,18 +5056,40 @@
4973
5056
  </xsl:for-each>
4974
5057
  </fo:bookmark>
4975
5058
  </xsl:if>
5059
+
5060
+
5061
+ <xsl:if test="$contents_nodes//figures/figure">
5062
+ <fo:bookmark internal-destination="empty_bookmark" starting-state="hide">
5063
+
5064
+
5065
+
5066
+ <xsl:variable name="bookmark-title">
5067
+
5068
+ <xsl:value-of select="$title-list-figures"/>
5069
+
5070
+ </xsl:variable>
5071
+ <fo:bookmark-title><xsl:value-of select="normalize-space($bookmark-title)"/></fo:bookmark-title>
5072
+ <xsl:for-each select="$contents_nodes//figures/figure">
5073
+ <fo:bookmark internal-destination="{@id}">
5074
+ <fo:bookmark-title><xsl:value-of select="normalize-space(.)"/></fo:bookmark-title>
5075
+ </fo:bookmark>
5076
+ </xsl:for-each>
5077
+ </fo:bookmark>
5078
+ </xsl:if>
5079
+
4976
5080
  </xsl:template><xsl:template name="insertTableBookmarks">
4977
5081
  <xsl:param name="contents"/>
4978
5082
  <xsl:param name="lang"/>
4979
- <xsl:if test="xalan:nodeset($contents)/table">
4980
- <fo:bookmark internal-destination="{xalan:nodeset($contents)/table[1]/@id}" starting-state="hide">
5083
+ <xsl:variable name="contents_nodes" select="xalan:nodeset($contents)"/>
5084
+ <xsl:if test="$contents_nodes/table">
5085
+ <fo:bookmark internal-destination="{$contents_nodes/table[1]/@id}" starting-state="hide">
4981
5086
  <fo:bookmark-title>
4982
5087
  <xsl:choose>
4983
5088
  <xsl:when test="$lang = 'fr'">Tableaux</xsl:when>
4984
5089
  <xsl:otherwise>Tables</xsl:otherwise>
4985
5090
  </xsl:choose>
4986
5091
  </fo:bookmark-title>
4987
- <xsl:for-each select="xalan:nodeset($contents)/table">
5092
+ <xsl:for-each select="$contents_nodes/table">
4988
5093
  <fo:bookmark internal-destination="{@id}">
4989
5094
  <fo:bookmark-title>
4990
5095
  <xsl:value-of select="normalize-space(title)"/>
@@ -4993,6 +5098,29 @@
4993
5098
  </xsl:for-each>
4994
5099
  </fo:bookmark>
4995
5100
  </xsl:if>
5101
+
5102
+
5103
+ <xsl:if test="$contents_nodes//tables/table">
5104
+ <fo:bookmark internal-destination="empty_bookmark" starting-state="hide">
5105
+
5106
+
5107
+
5108
+ <xsl:variable name="bookmark-title">
5109
+
5110
+ <xsl:value-of select="$title-list-tables"/>
5111
+
5112
+ </xsl:variable>
5113
+
5114
+ <fo:bookmark-title><xsl:value-of select="$bookmark-title"/></fo:bookmark-title>
5115
+
5116
+ <xsl:for-each select="$contents_nodes//tables/table">
5117
+ <fo:bookmark internal-destination="{@id}">
5118
+ <fo:bookmark-title><xsl:value-of select="normalize-space(.)"/></fo:bookmark-title>
5119
+ </fo:bookmark>
5120
+ </xsl:for-each>
5121
+ </fo:bookmark>
5122
+ </xsl:if>
5123
+
4996
5124
  </xsl:template><xsl:template name="getLangVersion">
4997
5125
  <xsl:param name="lang"/>
4998
5126
  <xsl:param name="doctype" select="''"/>
@@ -5217,7 +5345,51 @@
5217
5345
  <xsl:with-param name="text" select="$text_step1"/>
5218
5346
  </xsl:call-template>
5219
5347
  </xsl:variable>
5220
- <xsl:value-of select="$text_step2"/>
5348
+
5349
+ <!-- <xsl:value-of select="$text_step2"/> -->
5350
+
5351
+ <!-- add zero-width space after space -->
5352
+ <xsl:variable name="text_step3" select="java:replaceAll(java:java.lang.String.new($text_step2),' ',' ​')"/>
5353
+
5354
+ <!-- split text by zero-width space -->
5355
+ <xsl:variable name="text_step4">
5356
+ <xsl:call-template name="split">
5357
+ <xsl:with-param name="pText" select="$text_step3"/>
5358
+ <xsl:with-param name="sep" select="$zero_width_space"/>
5359
+ <xsl:with-param name="normalize-space">false</xsl:with-param>
5360
+ <xsl:with-param name="keep_sep">true</xsl:with-param>
5361
+ </xsl:call-template>
5362
+ </xsl:variable>
5363
+
5364
+ <xsl:for-each select="xalan:nodeset($text_step4)/item">
5365
+ <xsl:choose>
5366
+ <xsl:when test="string-length() &gt; 30"> <!-- word with length more than 30 will be interspersed with zero-width space -->
5367
+ <xsl:call-template name="interspers">
5368
+ <xsl:with-param name="str" select="."/>
5369
+ </xsl:call-template>
5370
+ </xsl:when>
5371
+ <xsl:otherwise>
5372
+ <xsl:value-of select="."/>
5373
+ </xsl:otherwise>
5374
+ </xsl:choose>
5375
+ </xsl:for-each>
5376
+
5377
+ </xsl:template><xsl:template name="interspers">
5378
+ <xsl:param name="str"/>
5379
+ <xsl:param name="char" select="$zero_width_space"/>
5380
+ <xsl:if test="$str != ''">
5381
+ <xsl:value-of select="substring($str, 1, 1)"/>
5382
+
5383
+ <xsl:variable name="next_char" select="substring($str, 2, 1)"/>
5384
+ <xsl:if test="not(contains(concat(' -.:=_— ', $char), $next_char))">
5385
+ <xsl:value-of select="$char"/>
5386
+ </xsl:if>
5387
+
5388
+ <xsl:call-template name="interspers">
5389
+ <xsl:with-param name="str" select="substring($str, 2)"/>
5390
+ <xsl:with-param name="char" select="$char"/>
5391
+ </xsl:call-template>
5392
+ </xsl:if>
5221
5393
  </xsl:template><xsl:template match="*" mode="syntax_highlight">
5222
5394
  <xsl:apply-templates mode="syntax_highlight"/>
5223
5395
  </xsl:template><xsl:variable name="syntax_highlight_styles_">
@@ -5653,6 +5825,8 @@
5653
5825
  </xsl:otherwise>
5654
5826
  </xsl:choose> -->
5655
5827
  </fo:block>
5828
+ </xsl:template><xsl:template match="*[local-name() = 'termsource']/text()[starts-with(., '[SOURCE: Adapted from: ')]" priority="2">
5829
+ <xsl:text>[</xsl:text><xsl:value-of select="substring-after(., '[SOURCE: ')"/>
5656
5830
  </xsl:template><xsl:template match="*[local-name() = 'termsource']/text()">
5657
5831
  <xsl:if test="normalize-space() != ''">
5658
5832
  <xsl:value-of select="."/>
@@ -5687,7 +5861,8 @@
5687
5861
  <fo:inline><xsl:apply-templates/></fo:inline>
5688
5862
  </xsl:template><xsl:template match="*[local-name() = 'modification']/text()">
5689
5863
  <xsl:if test="normalize-space() != ''">
5690
- <xsl:value-of select="."/>
5864
+ <!-- <xsl:value-of select="."/> -->
5865
+ <xsl:call-template name="text"/>
5691
5866
  </xsl:if>
5692
5867
  </xsl:template><xsl:template match="*[local-name() = 'quote']">
5693
5868
  <fo:block-container margin-left="0mm">
@@ -5727,26 +5902,24 @@
5727
5902
  </xsl:template><xsl:template match="*[local-name() = 'author']">
5728
5903
  <xsl:text>— </xsl:text>
5729
5904
  <xsl:apply-templates/>
5730
- </xsl:template><xsl:variable name="bibitem_hidden_">
5905
+ </xsl:template><xsl:variable name="bibitems_">
5906
+ <xsl:for-each select="//*[local-name() = 'bibitem']">
5907
+ <xsl:copy-of select="."/>
5908
+ </xsl:for-each>
5909
+ </xsl:variable><xsl:variable name="bibitems" select="xalan:nodeset($bibitems_)"/><xsl:variable name="bibitems_hidden_">
5731
5910
  <xsl:for-each select="//*[local-name() = 'bibitem'][@hidden='true']">
5732
5911
  <xsl:copy-of select="."/>
5733
5912
  </xsl:for-each>
5734
- <xsl:for-each select="//*[local-name() = 'references'][@hidden='true']/*[local-name() = 'bibitem']">
5913
+ <xsl:for-each select="//*[local-name() = 'references'][@hidden='true']//*[local-name() = 'bibitem']">
5735
5914
  <xsl:copy-of select="."/>
5736
5915
  </xsl:for-each>
5737
- </xsl:variable><xsl:variable name="bibitem_hidden" select="xalan:nodeset($bibitem_hidden_)"/><xsl:template match="*[local-name() = 'eref']">
5738
-
5739
- <xsl:variable name="bibitemid">
5740
- <xsl:choose>
5741
- <!-- <xsl:when test="//*[local-name() = 'bibitem'][@hidden='true' and @id = current()/@bibitemid]"></xsl:when>
5742
- <xsl:when test="//*[local-name() = 'references'][@hidden='true']/*[local-name() = 'bibitem'][@id = current()/@bibitemid]"></xsl:when> -->
5743
- <xsl:when test="$bibitem_hidden/*[local-name() = 'bibitem'][@id = current()/@bibitemid]"/>
5744
- <xsl:otherwise><xsl:value-of select="@bibitemid"/></xsl:otherwise>
5745
- </xsl:choose>
5746
- </xsl:variable>
5747
-
5916
+ </xsl:variable><xsl:variable name="bibitems_hidden" select="xalan:nodeset($bibitems_hidden_)"/><xsl:template match="*[local-name() = 'eref']">
5917
+ <xsl:variable name="current_bibitemid" select="@bibitemid"/>
5918
+ <!-- <xsl:variable name="external-destination" select="normalize-space(key('bibitems', $current_bibitemid)/*[local-name() = 'uri'][@type = 'citation'])"/> -->
5919
+ <xsl:variable name="external-destination" select="normalize-space($bibitems/*[local-name() ='bibitem'][@id = $current_bibitemid]/*[local-name() = 'uri'][@type = 'citation'])"/>
5748
5920
  <xsl:choose>
5749
- <xsl:when test="normalize-space($bibitemid) != ''"> <!-- if in the bibliography there is the item with @bibitemid (and not hidden), then create link -->
5921
+ <!-- <xsl:when test="$external-destination != '' or not(key('bibitems_hidden', $current_bibitemid))"> --> <!-- if in the bibliography there is the item with @bibitemid (and not hidden), then create link (internal to the bibitem or external) -->
5922
+ <xsl:when test="$external-destination != '' or not($bibitems_hidden/*[local-name() ='bibitem'][@id = $current_bibitemid])"> <!-- if in the bibliography there is the item with @bibitemid (and not hidden), then create link (internal to the bibitem or external) -->
5750
5923
  <fo:inline xsl:use-attribute-sets="eref-style">
5751
5924
  <xsl:if test="@type = 'footnote'">
5752
5925
  <xsl:attribute name="keep-together.within-line">always</xsl:attribute>
@@ -5760,8 +5933,8 @@
5760
5933
  <xsl:variable name="text" select="normalize-space()"/>
5761
5934
 
5762
5935
 
5763
-
5764
- <fo:basic-link internal-destination="{@bibitemid}" fox:alt-text="{@citeas}">
5936
+
5937
+ <fo:basic-link fox:alt-text="{@citeas}">
5765
5938
  <xsl:if test="normalize-space(@citeas) = ''">
5766
5939
  <xsl:attribute name="fox:alt-text"><xsl:value-of select="."/></xsl:attribute>
5767
5940
  </xsl:if>
@@ -5773,14 +5946,21 @@
5773
5946
 
5774
5947
  </xsl:if>
5775
5948
 
5776
-
5949
+ <xsl:choose>
5950
+ <xsl:when test="$external-destination != ''"> <!-- external hyperlink -->
5951
+ <xsl:attribute name="external-destination"><xsl:value-of select="$external-destination"/></xsl:attribute>
5952
+ </xsl:when>
5953
+ <xsl:otherwise>
5954
+ <xsl:attribute name="internal-destination"><xsl:value-of select="@bibitemid"/></xsl:attribute>
5955
+ </xsl:otherwise>
5956
+ </xsl:choose>
5777
5957
 
5778
5958
  <xsl:apply-templates/>
5779
5959
  </fo:basic-link>
5780
-
5960
+
5781
5961
  </fo:inline>
5782
5962
  </xsl:when>
5783
- <xsl:otherwise>
5963
+ <xsl:otherwise> <!-- if there is key('bibitems_hidden', $current_bibitemid) -->
5784
5964
  <fo:inline><xsl:apply-templates/></fo:inline>
5785
5965
  </xsl:otherwise>
5786
5966
  </xsl:choose>
@@ -6479,23 +6659,45 @@
6479
6659
  <xsl:apply-templates/>
6480
6660
  </fo:inline>
6481
6661
  </xsl:template><xsl:template match="*[local-name() = 'bibitem']/*[local-name() = 'note']" priority="2">
6662
+
6663
+ <!-- list of footnotes to calculate actual footnotes number -->
6664
+ <xsl:variable name="p_fn_">
6665
+ <xsl:call-template name="get_fn_list"/>
6666
+ </xsl:variable>
6667
+ <xsl:variable name="p_fn" select="xalan:nodeset($p_fn_)"/>
6668
+ <xsl:variable name="gen_id" select="generate-id(.)"/>
6669
+ <xsl:variable name="lang" select="ancestor::*[contains(local-name(), '-standard')]/*[local-name()='bibdata']//*[local-name()='language'][@current = 'true']"/>
6670
+ <!-- fn sequence number in document -->
6671
+ <xsl:variable name="current_fn_number">
6672
+ <xsl:choose>
6673
+ <xsl:when test="@current_fn_number"><xsl:value-of select="@current_fn_number"/></xsl:when> <!-- for BSI -->
6674
+ <xsl:otherwise>
6675
+ <!-- <xsl:value-of select="count($p_fn//fn[@reference = $reference]/preceding-sibling::fn) + 1" /> -->
6676
+ <xsl:value-of select="count($p_fn//fn[@gen_id = $gen_id]/preceding-sibling::fn) + 1"/>
6677
+ </xsl:otherwise>
6678
+ </xsl:choose>
6679
+ </xsl:variable>
6482
6680
  <fo:footnote>
6483
6681
  <xsl:variable name="number">
6484
6682
 
6485
- <xsl:number level="any" count="*[local-name() = 'bibitem']/*[local-name() = 'note']"/>
6683
+ <xsl:value-of select="$current_fn_number"/>
6486
6684
 
6487
6685
  </xsl:variable>
6686
+
6687
+ <xsl:variable name="current_fn_number_text">
6688
+ <xsl:value-of select="$number"/>
6689
+
6690
+ </xsl:variable>
6691
+
6488
6692
  <fo:inline xsl:use-attribute-sets="bibitem-note-fn-style">
6489
- <fo:basic-link internal-destination="{generate-id()}" fox:alt-text="footnote {$number}">
6490
- <xsl:value-of select="$number"/>
6491
-
6693
+ <fo:basic-link internal-destination="{$gen_id}" fox:alt-text="footnote {$number}">
6694
+ <xsl:value-of select="$current_fn_number_text"/>
6492
6695
  </fo:basic-link>
6493
6696
  </fo:inline>
6494
6697
  <fo:footnote-body>
6495
6698
  <fo:block xsl:use-attribute-sets="bibitem-note-fn-body-style">
6496
- <fo:inline id="{generate-id()}" xsl:use-attribute-sets="bibitem-note-fn-number-style">
6497
- <xsl:value-of select="$number"/>
6498
-
6699
+ <fo:inline id="{$gen_id}" xsl:use-attribute-sets="bibitem-note-fn-number-style">
6700
+ <xsl:value-of select="$current_fn_number_text"/>
6499
6701
  </fo:inline>
6500
6702
  <xsl:apply-templates/>
6501
6703
  </fo:block>
@@ -6746,6 +6948,78 @@
6746
6948
  <xsl:apply-templates/>
6747
6949
  </fo:block>
6748
6950
 
6951
+ </xsl:template><xsl:template match="@*|node()" mode="update_xml_step1">
6952
+ <xsl:copy>
6953
+ <xsl:apply-templates select="@*|node()" mode="update_xml_step1"/>
6954
+ </xsl:copy>
6955
+ </xsl:template><xsl:template match="*[local-name() = 'preface']" mode="update_xml_step1">
6956
+ <xsl:copy>
6957
+ <xsl:copy-of select="@*"/>
6958
+
6959
+ <xsl:variable name="nodes_preface_">
6960
+ <xsl:for-each select="*">
6961
+ <node id="{@id}"/>
6962
+ </xsl:for-each>
6963
+ </xsl:variable>
6964
+ <xsl:variable name="nodes_preface" select="xalan:nodeset($nodes_preface_)"/>
6965
+
6966
+ <xsl:for-each select="*">
6967
+ <xsl:sort select="@displayorder" data-type="number"/>
6968
+
6969
+ <!-- process Section's title -->
6970
+ <xsl:variable name="preceding-sibling_id" select="$nodes_preface/node[@id = current()/@id]/preceding-sibling::node[1]/@id"/>
6971
+ <xsl:if test="$preceding-sibling_id != ''">
6972
+ <xsl:apply-templates select="parent::*/*[@type = 'section-title' and @id = $preceding-sibling_id and not(@displayorder)]" mode="update_xml_step1"/>
6973
+ </xsl:if>
6974
+
6975
+ <xsl:choose>
6976
+ <xsl:when test="@type = 'section-title' and not(@displayorder)"><!-- skip, don't copy, because copied in above 'apply-templates' --></xsl:when>
6977
+ <xsl:otherwise>
6978
+ <xsl:apply-templates select="." mode="update_xml_step1"/>
6979
+ </xsl:otherwise>
6980
+ </xsl:choose>
6981
+
6982
+ </xsl:for-each>
6983
+ </xsl:copy>
6984
+ </xsl:template><xsl:template match="*[local-name() = 'sections']" mode="update_xml_step1">
6985
+ <xsl:copy>
6986
+ <xsl:copy-of select="@*"/>
6987
+
6988
+ <xsl:variable name="nodes_sections_">
6989
+ <xsl:for-each select="*">
6990
+ <node id="{@id}"/>
6991
+ </xsl:for-each>
6992
+ </xsl:variable>
6993
+ <xsl:variable name="nodes_sections" select="xalan:nodeset($nodes_sections_)"/>
6994
+
6995
+ <!-- move section 'Normative references' inside 'sections' -->
6996
+ <xsl:for-each select="* | ancestor::*[contains(local-name(), '-standard')]/*[local-name()='bibliography']/*[local-name()='references'][@normative='true'] | ancestor::*[contains(local-name(), '-standard')]/*[local-name()='bibliography']/*[local-name()='clause'][*[local-name()='references'][@normative='true']]">
6997
+ <xsl:sort select="@displayorder" data-type="number"/>
6998
+
6999
+ <!-- process Section's title -->
7000
+ <xsl:variable name="preceding-sibling_id" select="$nodes_sections/node[@id = current()/@id]/preceding-sibling::node[1]/@id"/>
7001
+ <xsl:if test="$preceding-sibling_id != ''">
7002
+ <xsl:apply-templates select="parent::*/*[@type = 'section-title' and @id = $preceding-sibling_id and not(@displayorder)]" mode="update_xml_step1"/>
7003
+ </xsl:if>
7004
+
7005
+ <xsl:choose>
7006
+ <xsl:when test="@type = 'section-title' and not(@displayorder)"><!-- skip, don't copy, because copied in above 'apply-templates' --></xsl:when>
7007
+ <xsl:otherwise>
7008
+ <xsl:apply-templates select="." mode="update_xml_step1"/>
7009
+ </xsl:otherwise>
7010
+ </xsl:choose>
7011
+
7012
+ </xsl:for-each>
7013
+ </xsl:copy>
7014
+ </xsl:template><xsl:template match="*[local-name() = 'bibliography']" mode="update_xml_step1">
7015
+ <xsl:copy>
7016
+ <xsl:copy-of select="@*"/>
7017
+ <!-- copy all elements from bibliography except 'Normative references' (moved to 'sections') -->
7018
+ <xsl:for-each select="*[not(@normative='true') and not(*[@normative='true'])]">
7019
+ <xsl:sort select="@displayorder" data-type="number"/>
7020
+ <xsl:apply-templates select="." mode="update_xml_step1"/>
7021
+ </xsl:for-each>
7022
+ </xsl:copy>
6749
7023
  </xsl:template><xsl:template name="convertDate">
6750
7024
  <xsl:param name="date"/>
6751
7025
  <xsl:param name="format" select="'short'"/>
@@ -6990,22 +7264,25 @@
6990
7264
  <xsl:param name="pText" select="."/>
6991
7265
  <xsl:param name="sep" select="','"/>
6992
7266
  <xsl:param name="normalize-space" select="'true'"/>
7267
+ <xsl:param name="keep_sep" select="'false'"/>
6993
7268
  <xsl:if test="string-length($pText) &gt;0">
6994
- <item>
6995
- <xsl:choose>
6996
- <xsl:when test="$normalize-space = 'true'">
6997
- <xsl:value-of select="normalize-space(substring-before(concat($pText, $sep), $sep))"/>
6998
- </xsl:when>
6999
- <xsl:otherwise>
7000
- <xsl:value-of select="substring-before(concat($pText, $sep), $sep)"/>
7001
- </xsl:otherwise>
7002
- </xsl:choose>
7003
- </item>
7004
- <xsl:call-template name="split">
7005
- <xsl:with-param name="pText" select="substring-after($pText, $sep)"/>
7006
- <xsl:with-param name="sep" select="$sep"/>
7007
- <xsl:with-param name="normalize-space" select="$normalize-space"/>
7008
- </xsl:call-template>
7269
+ <item>
7270
+ <xsl:choose>
7271
+ <xsl:when test="$normalize-space = 'true'">
7272
+ <xsl:value-of select="normalize-space(substring-before(concat($pText, $sep), $sep))"/>
7273
+ </xsl:when>
7274
+ <xsl:otherwise>
7275
+ <xsl:value-of select="substring-before(concat($pText, $sep), $sep)"/>
7276
+ </xsl:otherwise>
7277
+ </xsl:choose>
7278
+ </item>
7279
+ <xsl:if test="$keep_sep = 'true' and contains($pText, $sep)"><item><xsl:value-of select="$sep"/></item></xsl:if>
7280
+ <xsl:call-template name="split">
7281
+ <xsl:with-param name="pText" select="substring-after($pText, $sep)"/>
7282
+ <xsl:with-param name="sep" select="$sep"/>
7283
+ <xsl:with-param name="normalize-space" select="$normalize-space"/>
7284
+ <xsl:with-param name="keep_sep" select="$keep_sep"/>
7285
+ </xsl:call-template>
7009
7286
  </xsl:if>
7010
7287
  </xsl:template><xsl:template name="getDocumentId">
7011
7288
  <xsl:call-template name="getLang"/><xsl:value-of select="//*[local-name() = 'p'][1]/@id"/>