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.
@@ -11,13 +11,15 @@
11
11
 
12
12
  <xsl:variable name="debug">false</xsl:variable>
13
13
 
14
- <xsl:variable name="contents">
14
+ <xsl:variable name="contents_">
15
15
  <contents>
16
16
  <xsl:apply-templates select="/un:un-standard/un:sections/*" mode="contents"/>
17
17
  <xsl:apply-templates select="/un:un-standard/un:annex" mode="contents"/>
18
18
  <xsl:apply-templates select="/un:un-standard/un:bibliography/un:references" mode="contents"/>
19
+ <xsl:call-template name="processTablesFigures_Contents"/>
19
20
  </contents>
20
21
  </xsl:variable>
22
+ <xsl:variable name="contents" select="xalan:nodeset($contents_)"/>
21
23
 
22
24
 
23
25
  <xsl:variable name="title" select="/un:un-standard/un:bibdata/un:title[@language = 'en' and @type = 'main']"/>
@@ -198,7 +200,7 @@
198
200
  </xsl:variable>
199
201
  <fo:block font-size="9pt" text-align="right" font-style="italic" margin-bottom="6pt"><xsl:value-of select="$title-page"/></fo:block>
200
202
  <fo:block role="TOC">
201
- <xsl:for-each select="xalan:nodeset($contents)//item[not (@type = 'annex' or @parent = 'annex') and @display = 'true']">
203
+ <xsl:for-each select="$contents//item[not (@type = 'annex' or @parent = 'annex') and @display = 'true']">
202
204
 
203
205
  <fo:block role="TOCI">
204
206
 
@@ -236,9 +238,9 @@
236
238
 
237
239
  </xsl:for-each>
238
240
 
239
- <xsl:if test="xalan:nodeset($contents)//item[@type = 'annex' and @display = 'true']">
240
- <fo:block text-align="center" margin-top="12pt" margin-bottom="12pt">ANNEXES</fo:block>
241
- <xsl:for-each select="xalan:nodeset($contents)//item[@type = 'annex' and @display = 'true']">
241
+ <xsl:if test="$contents//item[@type = 'annex' and @display = 'true']">
242
+ <fo:block text-align="center" margin-top="12pt" margin-bottom="12pt" keep-with-next="always">ANNEXES</fo:block>
243
+ <xsl:for-each select="$contents//item[@type = 'annex' and @display = 'true']">
242
244
  <fo:block role="TOCI">
243
245
  <fo:block text-align-last="justify" margin-left="12mm" text-indent="-12mm">
244
246
  <fo:basic-link internal-destination="{@id}" fox:alt-text="{@section}">
@@ -268,6 +270,26 @@
268
270
  </xsl:for-each>
269
271
  </xsl:if>
270
272
 
273
+ <!-- List of Tables -->
274
+ <xsl:if test="$contents//tables/table">
275
+ <xsl:call-template name="insertListOf_Title">
276
+ <xsl:with-param name="title" select="$title-list-tables"/>
277
+ </xsl:call-template>
278
+ <xsl:for-each select="$contents//tables/table">
279
+ <xsl:call-template name="insertListOf_Item"/>
280
+ </xsl:for-each>
281
+ </xsl:if>
282
+
283
+ <!-- List of Figures -->
284
+ <xsl:if test="$contents//figures/figure">
285
+ <xsl:call-template name="insertListOf_Title">
286
+ <xsl:with-param name="title" select="$title-list-figures"/>
287
+ </xsl:call-template>
288
+ <xsl:for-each select="$contents//figures/figure">
289
+ <xsl:call-template name="insertListOf_Item"/>
290
+ </xsl:for-each>
291
+ </xsl:if>
292
+
271
293
  </fo:block>
272
294
  </fo:flow>
273
295
  </fo:page-sequence>
@@ -289,7 +311,7 @@
289
311
  <xsl:if test="$debug = 'true'">
290
312
  <xsl:text disable-output-escaping="yes">&lt;!--</xsl:text>
291
313
  DEBUG
292
- contents=<xsl:copy-of select="xalan:nodeset($contents)"/>
314
+ contents=<xsl:copy-of select="$contents"/>
293
315
  <xsl:text disable-output-escaping="yes">--&gt;</xsl:text>
294
316
  </xsl:if>
295
317
 
@@ -327,6 +349,30 @@
327
349
  </fo:page-sequence>
328
350
  </fo:root>
329
351
  </xsl:template>
352
+
353
+ <xsl:template name="insertListOf_Title">
354
+ <xsl:param name="title"/>
355
+ <fo:block text-align="center" margin-top="12pt" margin-bottom="12pt" keep-with-next="always">
356
+ <xsl:value-of select="$title"/>
357
+ </fo:block>
358
+ </xsl:template>
359
+
360
+ <xsl:template name="insertListOf_Item">
361
+ <fo:block role="TOCI">
362
+ <fo:block text-align-last="justify" margin-left="12mm" text-indent="-12mm">
363
+ <fo:basic-link internal-destination="{@id}">
364
+ <xsl:call-template name="setAltText">
365
+ <xsl:with-param name="value" select="@alt-text"/>
366
+ </xsl:call-template>
367
+ <xsl:apply-templates select="." mode="contents"/>
368
+ <fo:inline keep-together.within-line="always">
369
+ <fo:leader leader-pattern="dots"/>
370
+ <fo:page-number-citation ref-id="{@id}"/>
371
+ </fo:inline>
372
+ </fo:basic-link>
373
+ </fo:block>
374
+ </fo:block>
375
+ </xsl:template>
330
376
 
331
377
  <!-- ============================= -->
332
378
  <!-- CONTENTS -->
@@ -896,7 +942,7 @@
896
942
  <xsl:text>Contents</xsl:text>
897
943
 
898
944
  </title-toc>
899
-
945
+
900
946
  <title-descriptors lang="en">Descriptors</title-descriptors>
901
947
 
902
948
  <title-part lang="en">
@@ -932,7 +978,31 @@
932
978
  <title-continued lang="en">(continued)</title-continued>
933
979
  <title-continued lang="fr">(continué)</title-continued>
934
980
 
935
- </xsl:variable><xsl:variable name="titles" select="xalan:nodeset($titles_)"/><xsl:variable name="bibdata">
981
+ </xsl:variable><xsl:variable name="titles" select="xalan:nodeset($titles_)"/><xsl:variable name="title-list-tables">
982
+ <xsl:variable name="toc_table_title" select="//*[contains(local-name(), '-standard')]/*[local-name() = 'misc-container']/*[local-name() = 'toc'][@type='table']/*[local-name() = 'title']"/>
983
+ <xsl:value-of select="$toc_table_title"/>
984
+ <xsl:if test="normalize-space($toc_table_title) = ''">
985
+ <xsl:call-template name="getTitle">
986
+ <xsl:with-param name="name" select="'title-list-tables'"/>
987
+ </xsl:call-template>
988
+ </xsl:if>
989
+ </xsl:variable><xsl:variable name="title-list-figures">
990
+ <xsl:variable name="toc_figure_title" select="//*[contains(local-name(), '-standard')]/*[local-name() = 'misc-container']/*[local-name() = 'toc'][@type='figure']/*[local-name() = 'title']"/>
991
+ <xsl:value-of select="$toc_figure_title"/>
992
+ <xsl:if test="normalize-space($toc_figure_title) = ''">
993
+ <xsl:call-template name="getTitle">
994
+ <xsl:with-param name="name" select="'title-list-figures'"/>
995
+ </xsl:call-template>
996
+ </xsl:if>
997
+ </xsl:variable><xsl:variable name="title-list-recommendations">
998
+ <xsl:variable name="toc_requirement_title" select="//*[contains(local-name(), '-standard')]/*[local-name() = 'misc-container']/*[local-name() = 'toc'][@type='requirement']/*[local-name() = 'title']"/>
999
+ <xsl:value-of select="$toc_requirement_title"/>
1000
+ <xsl:if test="normalize-space($toc_requirement_title) = ''">
1001
+ <xsl:call-template name="getTitle">
1002
+ <xsl:with-param name="name" select="'title-list-recommendations'"/>
1003
+ </xsl:call-template>
1004
+ </xsl:if>
1005
+ </xsl:variable><xsl:variable name="bibdata">
936
1006
  <xsl:copy-of select="//*[contains(local-name(), '-standard')]/*[local-name() = 'bibdata']"/>
937
1007
  <xsl:copy-of select="//*[contains(local-name(), '-standard')]/*[local-name() = 'localized-strings']"/>
938
1008
  </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">
@@ -2132,6 +2202,30 @@
2132
2202
  <xsl:sort select="@displayorder" data-type="number"/>
2133
2203
  <xsl:apply-templates select="." mode="contents"/>
2134
2204
  </xsl:for-each>
2205
+ </xsl:template><xsl:template name="processTablesFigures_Contents">
2206
+ <xsl:param name="always"/>
2207
+ <xsl:if test="(//*[contains(local-name(), '-standard')]/*[local-name() = 'misc-container']/*[local-name() = 'toc'][@type='table']/*[local-name() = 'title']) or normalize-space($always) = 'true'">
2208
+ <xsl:call-template name="processTables_Contents"/>
2209
+ </xsl:if>
2210
+ <xsl:if test="(//*[contains(local-name(), '-standard')]/*[local-name() = 'misc-container']/*[local-name() = 'toc'][@type='figure']/*[local-name() = 'title']) or normalize-space($always) = 'true'">
2211
+ <xsl:call-template name="processFigures_Contents"/>
2212
+ </xsl:if>
2213
+ </xsl:template><xsl:template name="processTables_Contents">
2214
+ <tables>
2215
+ <xsl:for-each select="//*[local-name() = 'table'][@id and *[local-name() = 'name'] and normalize-space(@id) != '']">
2216
+ <table id="{@id}" alt-text="{*[local-name() = 'name']}">
2217
+ <xsl:copy-of select="*[local-name() = 'name']"/>
2218
+ </table>
2219
+ </xsl:for-each>
2220
+ </tables>
2221
+ </xsl:template><xsl:template name="processFigures_Contents">
2222
+ <figures>
2223
+ <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) != '']">
2224
+ <figure id="{@id}" alt-text="{*[local-name() = 'name']}">
2225
+ <xsl:copy-of select="*[local-name() = 'name']"/>
2226
+ </figure>
2227
+ </xsl:for-each>
2228
+ </figures>
2135
2229
  </xsl:template><xsl:template name="processPrefaceSectionsDefault">
2136
2230
  <xsl:for-each select="/*/*[local-name()='preface']/*">
2137
2231
  <xsl:sort select="@displayorder" data-type="number"/>
@@ -2153,8 +2247,27 @@
2153
2247
  <xsl:sort select="@displayorder" data-type="number"/>
2154
2248
  <xsl:apply-templates select="."/>
2155
2249
  </xsl:for-each>
2156
- </xsl:template><xsl:template match="text()">
2157
- <xsl:value-of select="."/>
2250
+ </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">
2251
+ <xsl:variable name="regex_standard_reference">([A-Z]{2,}(/[A-Z]{2,})* \d+(-\d+)*(:\d{4})?)</xsl:variable>
2252
+ <xsl:variable name="text" select="java:replaceAll(java:java.lang.String.new(.),$regex_standard_reference,concat($tag_open,'$1',$tag_close))"/>
2253
+ <xsl:call-template name="replace_fo_inline">
2254
+ <xsl:with-param name="text" select="$text"/>
2255
+ </xsl:call-template>
2256
+ </xsl:template><xsl:template name="replace_fo_inline">
2257
+ <xsl:param name="text"/>
2258
+ <xsl:choose>
2259
+ <xsl:when test="contains($text, $tag_open)">
2260
+ <xsl:value-of select="substring-before($text, $tag_open)"/>
2261
+ <xsl:text disable-output-escaping="yes">&lt;fo:inline keep-together.within-line="always"&gt;</xsl:text>
2262
+ <xsl:variable name="text_after" select="substring-after($text, $tag_open)"/>
2263
+ <xsl:value-of select="substring-before($text_after, $tag_close)"/>
2264
+ <xsl:text disable-output-escaping="yes">&lt;/fo:inline&gt;</xsl:text>
2265
+ <xsl:call-template name="replace_fo_inline">
2266
+ <xsl:with-param name="text" select="substring-after($text_after, $tag_close)"/>
2267
+ </xsl:call-template>
2268
+ </xsl:when>
2269
+ <xsl:otherwise><xsl:value-of select="$text"/></xsl:otherwise>
2270
+ </xsl:choose>
2158
2271
  </xsl:template><xsl:template match="*[local-name()='br']">
2159
2272
  <xsl:value-of select="$linebreak"/>
2160
2273
  </xsl:template><xsl:template match="*[local-name()='copyright-statement']">
@@ -2945,37 +3058,7 @@
2945
3058
 
2946
3059
  <!-- list of footnotes to calculate actual footnotes number -->
2947
3060
  <xsl:variable name="p_fn_">
2948
- <xsl:choose>
2949
- <xsl:when test="@current_fn_number"> <!-- for BSI, footnote reference number calculated already -->
2950
- <fn gen_id="{generate-id(.)}">
2951
- <xsl:copy-of select="@*"/>
2952
- <xsl:copy-of select="node()"/>
2953
- </fn>
2954
- </xsl:when>
2955
- <xsl:otherwise>
2956
- <!-- itetation for:
2957
- footnotes in bibdata/title
2958
- footnotes in bibliography
2959
- footnotes in document's body (except table's head/body/foot and figure text)
2960
- -->
2961
- <xsl:for-each select="ancestor::*[contains(local-name(), '-standard')]/*[local-name() = 'bibdata']/*[local-name() = 'note'][@type='title-footnote']">
2962
- <fn gen_id="{generate-id(.)}">
2963
- <xsl:copy-of select="@*"/>
2964
- <xsl:copy-of select="node()"/>
2965
- </fn>
2966
- </xsl:for-each>
2967
- <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']/*">
2968
- <xsl:sort select="@displayorder" data-type="number"/>
2969
- <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])]">
2970
- <!-- copy unique fn -->
2971
- <fn gen_id="{generate-id(.)}">
2972
- <xsl:copy-of select="@*"/>
2973
- <xsl:copy-of select="node()"/>
2974
- </fn>
2975
- </xsl:for-each>
2976
- </xsl:for-each>
2977
- </xsl:otherwise>
2978
- </xsl:choose>
3061
+ <xsl:call-template name="get_fn_list"/>
2979
3062
  </xsl:variable>
2980
3063
  <xsl:variable name="p_fn" select="xalan:nodeset($p_fn_)"/>
2981
3064
 
@@ -3036,6 +3119,38 @@
3036
3119
  <xsl:copy-of select="$footnote_inline"/>
3037
3120
  </xsl:otherwise>
3038
3121
  </xsl:choose>
3122
+ </xsl:template><xsl:template name="get_fn_list">
3123
+ <xsl:choose>
3124
+ <xsl:when test="@current_fn_number"> <!-- for BSI, footnote reference number calculated already -->
3125
+ <fn gen_id="{generate-id(.)}">
3126
+ <xsl:copy-of select="@*"/>
3127
+ <xsl:copy-of select="node()"/>
3128
+ </fn>
3129
+ </xsl:when>
3130
+ <xsl:otherwise>
3131
+ <!-- itetation for:
3132
+ footnotes in bibdata/title
3133
+ footnotes in bibliography
3134
+ footnotes in document's body (except table's head/body/foot and figure text)
3135
+ -->
3136
+ <xsl:for-each select="ancestor::*[contains(local-name(), '-standard')]/*[local-name() = 'bibdata']/*[local-name() = 'note'][@type='title-footnote']">
3137
+ <fn gen_id="{generate-id(.)}">
3138
+ <xsl:copy-of select="@*"/>
3139
+ <xsl:copy-of select="node()"/>
3140
+ </fn>
3141
+ </xsl:for-each>
3142
+ <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']/*">
3143
+ <xsl:sort select="@displayorder" data-type="number"/>
3144
+ <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])]">
3145
+ <!-- copy unique fn -->
3146
+ <fn gen_id="{generate-id(.)}">
3147
+ <xsl:copy-of select="@*"/>
3148
+ <xsl:copy-of select="node()"/>
3149
+ </fn>
3150
+ </xsl:for-each>
3151
+ </xsl:for-each>
3152
+ </xsl:otherwise>
3153
+ </xsl:choose>
3039
3154
  </xsl:template><xsl:template name="table_fn_display">
3040
3155
  <xsl:variable name="references">
3041
3156
 
@@ -3207,7 +3322,7 @@
3207
3322
  </fo:inline>
3208
3323
  </xsl:template><xsl:template match="*[local-name()='fn']/text()[normalize-space() != '']">
3209
3324
  <fo:inline><xsl:value-of select="."/></fo:inline>
3210
- </xsl:template><xsl:template match="*[local-name()='fn']/*[local-name()='p']">
3325
+ </xsl:template><xsl:template match="*[local-name()='fn']//*[local-name()='p']">
3211
3326
  <fo:inline>
3212
3327
  <xsl:apply-templates/>
3213
3328
  </fo:inline>
@@ -4920,13 +5035,14 @@
4920
5035
  <xsl:apply-templates mode="bookmarks"/>
4921
5036
  </xsl:template><xsl:template name="addBookmarks">
4922
5037
  <xsl:param name="contents"/>
4923
- <xsl:if test="xalan:nodeset($contents)//item">
5038
+ <xsl:variable name="contents_nodes" select="xalan:nodeset($contents)"/>
5039
+ <xsl:if test="$contents_nodes//item">
4924
5040
  <fo:bookmark-tree>
4925
5041
  <xsl:choose>
4926
- <xsl:when test="xalan:nodeset($contents)/doc">
5042
+ <xsl:when test="$contents_nodes/doc">
4927
5043
  <xsl:choose>
4928
- <xsl:when test="count(xalan:nodeset($contents)/doc) &gt; 1">
4929
- <xsl:for-each select="xalan:nodeset($contents)/doc">
5044
+ <xsl:when test="count($contents_nodes/doc) &gt; 1">
5045
+ <xsl:for-each select="$contents_nodes/doc">
4930
5046
  <fo:bookmark internal-destination="{contents/item[1]/@id}" starting-state="hide">
4931
5047
  <xsl:if test="@bundle = 'true'">
4932
5048
  <xsl:attribute name="internal-destination"><xsl:value-of select="@firstpage_id"/></xsl:attribute>
@@ -4977,7 +5093,7 @@
4977
5093
  </xsl:for-each>
4978
5094
  </xsl:when>
4979
5095
  <xsl:otherwise>
4980
- <xsl:for-each select="xalan:nodeset($contents)/doc">
5096
+ <xsl:for-each select="$contents_nodes/doc">
4981
5097
 
4982
5098
  <xsl:apply-templates select="contents/item" mode="bookmark"/>
4983
5099
 
@@ -4995,25 +5111,36 @@
4995
5111
  </xsl:choose>
4996
5112
  </xsl:when>
4997
5113
  <xsl:otherwise>
4998
- <xsl:apply-templates select="xalan:nodeset($contents)/contents/item" mode="bookmark"/>
5114
+ <xsl:apply-templates select="$contents_nodes/contents/item" mode="bookmark"/>
5115
+
5116
+ <xsl:call-template name="insertFigureBookmarks">
5117
+ <xsl:with-param name="contents" select="$contents_nodes/contents"/>
5118
+ </xsl:call-template>
5119
+
5120
+ <xsl:call-template name="insertTableBookmarks">
5121
+ <xsl:with-param name="contents" select="$contents_nodes/contents"/>
5122
+ <xsl:with-param name="lang" select="@lang"/>
5123
+ </xsl:call-template>
5124
+
4999
5125
  </xsl:otherwise>
5000
5126
  </xsl:choose>
5001
5127
 
5128
+
5002
5129
 
5003
5130
 
5004
5131
 
5005
5132
 
5006
-
5007
-
5133
+
5008
5134
 
5009
5135
  </fo:bookmark-tree>
5010
5136
  </xsl:if>
5011
5137
  </xsl:template><xsl:template name="insertFigureBookmarks">
5012
5138
  <xsl:param name="contents"/>
5013
- <xsl:if test="xalan:nodeset($contents)/figure">
5014
- <fo:bookmark internal-destination="{xalan:nodeset($contents)/figure[1]/@id}" starting-state="hide">
5139
+ <xsl:variable name="contents_nodes" select="xalan:nodeset($contents)"/>
5140
+ <xsl:if test="$contents_nodes/figure">
5141
+ <fo:bookmark internal-destination="{$contents_nodes/figure[1]/@id}" starting-state="hide">
5015
5142
  <fo:bookmark-title>Figures</fo:bookmark-title>
5016
- <xsl:for-each select="xalan:nodeset($contents)/figure">
5143
+ <xsl:for-each select="$contents_nodes/figure">
5017
5144
  <fo:bookmark internal-destination="{@id}">
5018
5145
  <fo:bookmark-title>
5019
5146
  <xsl:value-of select="normalize-space(title)"/>
@@ -5022,18 +5149,40 @@
5022
5149
  </xsl:for-each>
5023
5150
  </fo:bookmark>
5024
5151
  </xsl:if>
5152
+
5153
+
5154
+ <xsl:if test="$contents_nodes//figures/figure">
5155
+ <fo:bookmark internal-destination="empty_bookmark" starting-state="hide">
5156
+
5157
+
5158
+
5159
+ <xsl:variable name="bookmark-title">
5160
+
5161
+ <xsl:value-of select="$title-list-figures"/>
5162
+
5163
+ </xsl:variable>
5164
+ <fo:bookmark-title><xsl:value-of select="normalize-space($bookmark-title)"/></fo:bookmark-title>
5165
+ <xsl:for-each select="$contents_nodes//figures/figure">
5166
+ <fo:bookmark internal-destination="{@id}">
5167
+ <fo:bookmark-title><xsl:value-of select="normalize-space(.)"/></fo:bookmark-title>
5168
+ </fo:bookmark>
5169
+ </xsl:for-each>
5170
+ </fo:bookmark>
5171
+ </xsl:if>
5172
+
5025
5173
  </xsl:template><xsl:template name="insertTableBookmarks">
5026
5174
  <xsl:param name="contents"/>
5027
5175
  <xsl:param name="lang"/>
5028
- <xsl:if test="xalan:nodeset($contents)/table">
5029
- <fo:bookmark internal-destination="{xalan:nodeset($contents)/table[1]/@id}" starting-state="hide">
5176
+ <xsl:variable name="contents_nodes" select="xalan:nodeset($contents)"/>
5177
+ <xsl:if test="$contents_nodes/table">
5178
+ <fo:bookmark internal-destination="{$contents_nodes/table[1]/@id}" starting-state="hide">
5030
5179
  <fo:bookmark-title>
5031
5180
  <xsl:choose>
5032
5181
  <xsl:when test="$lang = 'fr'">Tableaux</xsl:when>
5033
5182
  <xsl:otherwise>Tables</xsl:otherwise>
5034
5183
  </xsl:choose>
5035
5184
  </fo:bookmark-title>
5036
- <xsl:for-each select="xalan:nodeset($contents)/table">
5185
+ <xsl:for-each select="$contents_nodes/table">
5037
5186
  <fo:bookmark internal-destination="{@id}">
5038
5187
  <fo:bookmark-title>
5039
5188
  <xsl:value-of select="normalize-space(title)"/>
@@ -5042,6 +5191,29 @@
5042
5191
  </xsl:for-each>
5043
5192
  </fo:bookmark>
5044
5193
  </xsl:if>
5194
+
5195
+
5196
+ <xsl:if test="$contents_nodes//tables/table">
5197
+ <fo:bookmark internal-destination="empty_bookmark" starting-state="hide">
5198
+
5199
+
5200
+
5201
+ <xsl:variable name="bookmark-title">
5202
+
5203
+ <xsl:value-of select="$title-list-tables"/>
5204
+
5205
+ </xsl:variable>
5206
+
5207
+ <fo:bookmark-title><xsl:value-of select="$bookmark-title"/></fo:bookmark-title>
5208
+
5209
+ <xsl:for-each select="$contents_nodes//tables/table">
5210
+ <fo:bookmark internal-destination="{@id}">
5211
+ <fo:bookmark-title><xsl:value-of select="normalize-space(.)"/></fo:bookmark-title>
5212
+ </fo:bookmark>
5213
+ </xsl:for-each>
5214
+ </fo:bookmark>
5215
+ </xsl:if>
5216
+
5045
5217
  </xsl:template><xsl:template name="getLangVersion">
5046
5218
  <xsl:param name="lang"/>
5047
5219
  <xsl:param name="doctype" select="''"/>
@@ -5266,7 +5438,51 @@
5266
5438
  <xsl:with-param name="text" select="$text_step1"/>
5267
5439
  </xsl:call-template>
5268
5440
  </xsl:variable>
5269
- <xsl:value-of select="$text_step2"/>
5441
+
5442
+ <!-- <xsl:value-of select="$text_step2"/> -->
5443
+
5444
+ <!-- add zero-width space after space -->
5445
+ <xsl:variable name="text_step3" select="java:replaceAll(java:java.lang.String.new($text_step2),' ',' ​')"/>
5446
+
5447
+ <!-- split text by zero-width space -->
5448
+ <xsl:variable name="text_step4">
5449
+ <xsl:call-template name="split">
5450
+ <xsl:with-param name="pText" select="$text_step3"/>
5451
+ <xsl:with-param name="sep" select="$zero_width_space"/>
5452
+ <xsl:with-param name="normalize-space">false</xsl:with-param>
5453
+ <xsl:with-param name="keep_sep">true</xsl:with-param>
5454
+ </xsl:call-template>
5455
+ </xsl:variable>
5456
+
5457
+ <xsl:for-each select="xalan:nodeset($text_step4)/item">
5458
+ <xsl:choose>
5459
+ <xsl:when test="string-length() &gt; 30"> <!-- word with length more than 30 will be interspersed with zero-width space -->
5460
+ <xsl:call-template name="interspers">
5461
+ <xsl:with-param name="str" select="."/>
5462
+ </xsl:call-template>
5463
+ </xsl:when>
5464
+ <xsl:otherwise>
5465
+ <xsl:value-of select="."/>
5466
+ </xsl:otherwise>
5467
+ </xsl:choose>
5468
+ </xsl:for-each>
5469
+
5470
+ </xsl:template><xsl:template name="interspers">
5471
+ <xsl:param name="str"/>
5472
+ <xsl:param name="char" select="$zero_width_space"/>
5473
+ <xsl:if test="$str != ''">
5474
+ <xsl:value-of select="substring($str, 1, 1)"/>
5475
+
5476
+ <xsl:variable name="next_char" select="substring($str, 2, 1)"/>
5477
+ <xsl:if test="not(contains(concat(' -.:=_— ', $char), $next_char))">
5478
+ <xsl:value-of select="$char"/>
5479
+ </xsl:if>
5480
+
5481
+ <xsl:call-template name="interspers">
5482
+ <xsl:with-param name="str" select="substring($str, 2)"/>
5483
+ <xsl:with-param name="char" select="$char"/>
5484
+ </xsl:call-template>
5485
+ </xsl:if>
5270
5486
  </xsl:template><xsl:template match="*" mode="syntax_highlight">
5271
5487
  <xsl:apply-templates mode="syntax_highlight"/>
5272
5488
  </xsl:template><xsl:variable name="syntax_highlight_styles_">
@@ -5702,6 +5918,8 @@
5702
5918
  </xsl:otherwise>
5703
5919
  </xsl:choose> -->
5704
5920
  </fo:block>
5921
+ </xsl:template><xsl:template match="*[local-name() = 'termsource']/text()[starts-with(., '[SOURCE: Adapted from: ')]" priority="2">
5922
+ <xsl:text>[</xsl:text><xsl:value-of select="substring-after(., '[SOURCE: ')"/>
5705
5923
  </xsl:template><xsl:template match="*[local-name() = 'termsource']/text()">
5706
5924
  <xsl:if test="normalize-space() != ''">
5707
5925
  <xsl:value-of select="."/>
@@ -5736,7 +5954,8 @@
5736
5954
  <fo:inline><xsl:apply-templates/></fo:inline>
5737
5955
  </xsl:template><xsl:template match="*[local-name() = 'modification']/text()">
5738
5956
  <xsl:if test="normalize-space() != ''">
5739
- <xsl:value-of select="."/>
5957
+ <!-- <xsl:value-of select="."/> -->
5958
+ <xsl:call-template name="text"/>
5740
5959
  </xsl:if>
5741
5960
  </xsl:template><xsl:template match="*[local-name() = 'quote']">
5742
5961
  <fo:block-container margin-left="0mm">
@@ -5776,26 +5995,24 @@
5776
5995
  </xsl:template><xsl:template match="*[local-name() = 'author']">
5777
5996
  <xsl:text>— </xsl:text>
5778
5997
  <xsl:apply-templates/>
5779
- </xsl:template><xsl:variable name="bibitem_hidden_">
5998
+ </xsl:template><xsl:variable name="bibitems_">
5999
+ <xsl:for-each select="//*[local-name() = 'bibitem']">
6000
+ <xsl:copy-of select="."/>
6001
+ </xsl:for-each>
6002
+ </xsl:variable><xsl:variable name="bibitems" select="xalan:nodeset($bibitems_)"/><xsl:variable name="bibitems_hidden_">
5780
6003
  <xsl:for-each select="//*[local-name() = 'bibitem'][@hidden='true']">
5781
6004
  <xsl:copy-of select="."/>
5782
6005
  </xsl:for-each>
5783
- <xsl:for-each select="//*[local-name() = 'references'][@hidden='true']/*[local-name() = 'bibitem']">
6006
+ <xsl:for-each select="//*[local-name() = 'references'][@hidden='true']//*[local-name() = 'bibitem']">
5784
6007
  <xsl:copy-of select="."/>
5785
6008
  </xsl:for-each>
5786
- </xsl:variable><xsl:variable name="bibitem_hidden" select="xalan:nodeset($bibitem_hidden_)"/><xsl:template match="*[local-name() = 'eref']">
5787
-
5788
- <xsl:variable name="bibitemid">
5789
- <xsl:choose>
5790
- <!-- <xsl:when test="//*[local-name() = 'bibitem'][@hidden='true' and @id = current()/@bibitemid]"></xsl:when>
5791
- <xsl:when test="//*[local-name() = 'references'][@hidden='true']/*[local-name() = 'bibitem'][@id = current()/@bibitemid]"></xsl:when> -->
5792
- <xsl:when test="$bibitem_hidden/*[local-name() = 'bibitem'][@id = current()/@bibitemid]"/>
5793
- <xsl:otherwise><xsl:value-of select="@bibitemid"/></xsl:otherwise>
5794
- </xsl:choose>
5795
- </xsl:variable>
5796
-
6009
+ </xsl:variable><xsl:variable name="bibitems_hidden" select="xalan:nodeset($bibitems_hidden_)"/><xsl:template match="*[local-name() = 'eref']">
6010
+ <xsl:variable name="current_bibitemid" select="@bibitemid"/>
6011
+ <!-- <xsl:variable name="external-destination" select="normalize-space(key('bibitems', $current_bibitemid)/*[local-name() = 'uri'][@type = 'citation'])"/> -->
6012
+ <xsl:variable name="external-destination" select="normalize-space($bibitems/*[local-name() ='bibitem'][@id = $current_bibitemid]/*[local-name() = 'uri'][@type = 'citation'])"/>
5797
6013
  <xsl:choose>
5798
- <xsl:when test="normalize-space($bibitemid) != ''"> <!-- if in the bibliography there is the item with @bibitemid (and not hidden), then create link -->
6014
+ <!-- <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) -->
6015
+ <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) -->
5799
6016
  <fo:inline xsl:use-attribute-sets="eref-style">
5800
6017
  <xsl:if test="@type = 'footnote'">
5801
6018
  <xsl:attribute name="keep-together.within-line">always</xsl:attribute>
@@ -5809,8 +6026,8 @@
5809
6026
  <xsl:variable name="text" select="normalize-space()"/>
5810
6027
 
5811
6028
 
5812
-
5813
- <fo:basic-link internal-destination="{@bibitemid}" fox:alt-text="{@citeas}">
6029
+
6030
+ <fo:basic-link fox:alt-text="{@citeas}">
5814
6031
  <xsl:if test="normalize-space(@citeas) = ''">
5815
6032
  <xsl:attribute name="fox:alt-text"><xsl:value-of select="."/></xsl:attribute>
5816
6033
  </xsl:if>
@@ -5820,14 +6037,21 @@
5820
6037
 
5821
6038
  </xsl:if>
5822
6039
 
5823
-
6040
+ <xsl:choose>
6041
+ <xsl:when test="$external-destination != ''"> <!-- external hyperlink -->
6042
+ <xsl:attribute name="external-destination"><xsl:value-of select="$external-destination"/></xsl:attribute>
6043
+ </xsl:when>
6044
+ <xsl:otherwise>
6045
+ <xsl:attribute name="internal-destination"><xsl:value-of select="@bibitemid"/></xsl:attribute>
6046
+ </xsl:otherwise>
6047
+ </xsl:choose>
5824
6048
 
5825
6049
  <xsl:apply-templates/>
5826
6050
  </fo:basic-link>
5827
-
6051
+
5828
6052
  </fo:inline>
5829
6053
  </xsl:when>
5830
- <xsl:otherwise>
6054
+ <xsl:otherwise> <!-- if there is key('bibitems_hidden', $current_bibitemid) -->
5831
6055
  <fo:inline><xsl:apply-templates/></fo:inline>
5832
6056
  </xsl:otherwise>
5833
6057
  </xsl:choose>
@@ -6528,23 +6752,45 @@
6528
6752
  <xsl:apply-templates/>
6529
6753
  </fo:inline>
6530
6754
  </xsl:template><xsl:template match="*[local-name() = 'bibitem']/*[local-name() = 'note']" priority="2">
6755
+
6756
+ <!-- list of footnotes to calculate actual footnotes number -->
6757
+ <xsl:variable name="p_fn_">
6758
+ <xsl:call-template name="get_fn_list"/>
6759
+ </xsl:variable>
6760
+ <xsl:variable name="p_fn" select="xalan:nodeset($p_fn_)"/>
6761
+ <xsl:variable name="gen_id" select="generate-id(.)"/>
6762
+ <xsl:variable name="lang" select="ancestor::*[contains(local-name(), '-standard')]/*[local-name()='bibdata']//*[local-name()='language'][@current = 'true']"/>
6763
+ <!-- fn sequence number in document -->
6764
+ <xsl:variable name="current_fn_number">
6765
+ <xsl:choose>
6766
+ <xsl:when test="@current_fn_number"><xsl:value-of select="@current_fn_number"/></xsl:when> <!-- for BSI -->
6767
+ <xsl:otherwise>
6768
+ <!-- <xsl:value-of select="count($p_fn//fn[@reference = $reference]/preceding-sibling::fn) + 1" /> -->
6769
+ <xsl:value-of select="count($p_fn//fn[@gen_id = $gen_id]/preceding-sibling::fn) + 1"/>
6770
+ </xsl:otherwise>
6771
+ </xsl:choose>
6772
+ </xsl:variable>
6531
6773
  <fo:footnote>
6532
6774
  <xsl:variable name="number">
6533
6775
 
6534
- <xsl:number level="any" count="*[local-name() = 'bibitem']/*[local-name() = 'note']"/>
6776
+ <xsl:value-of select="$current_fn_number"/>
6535
6777
 
6536
6778
  </xsl:variable>
6779
+
6780
+ <xsl:variable name="current_fn_number_text">
6781
+ <xsl:value-of select="$number"/>
6782
+
6783
+ </xsl:variable>
6784
+
6537
6785
  <fo:inline xsl:use-attribute-sets="bibitem-note-fn-style">
6538
- <fo:basic-link internal-destination="{generate-id()}" fox:alt-text="footnote {$number}">
6539
- <xsl:value-of select="$number"/>
6540
-
6786
+ <fo:basic-link internal-destination="{$gen_id}" fox:alt-text="footnote {$number}">
6787
+ <xsl:value-of select="$current_fn_number_text"/>
6541
6788
  </fo:basic-link>
6542
6789
  </fo:inline>
6543
6790
  <fo:footnote-body>
6544
6791
  <fo:block xsl:use-attribute-sets="bibitem-note-fn-body-style">
6545
- <fo:inline id="{generate-id()}" xsl:use-attribute-sets="bibitem-note-fn-number-style">
6546
- <xsl:value-of select="$number"/>
6547
-
6792
+ <fo:inline id="{$gen_id}" xsl:use-attribute-sets="bibitem-note-fn-number-style">
6793
+ <xsl:value-of select="$current_fn_number_text"/>
6548
6794
  </fo:inline>
6549
6795
  <xsl:apply-templates/>
6550
6796
  </fo:block>
@@ -6797,6 +7043,78 @@
6797
7043
  <xsl:apply-templates/>
6798
7044
  </fo:block>
6799
7045
 
7046
+ </xsl:template><xsl:template match="@*|node()" mode="update_xml_step1">
7047
+ <xsl:copy>
7048
+ <xsl:apply-templates select="@*|node()" mode="update_xml_step1"/>
7049
+ </xsl:copy>
7050
+ </xsl:template><xsl:template match="*[local-name() = 'preface']" mode="update_xml_step1">
7051
+ <xsl:copy>
7052
+ <xsl:copy-of select="@*"/>
7053
+
7054
+ <xsl:variable name="nodes_preface_">
7055
+ <xsl:for-each select="*">
7056
+ <node id="{@id}"/>
7057
+ </xsl:for-each>
7058
+ </xsl:variable>
7059
+ <xsl:variable name="nodes_preface" select="xalan:nodeset($nodes_preface_)"/>
7060
+
7061
+ <xsl:for-each select="*">
7062
+ <xsl:sort select="@displayorder" data-type="number"/>
7063
+
7064
+ <!-- process Section's title -->
7065
+ <xsl:variable name="preceding-sibling_id" select="$nodes_preface/node[@id = current()/@id]/preceding-sibling::node[1]/@id"/>
7066
+ <xsl:if test="$preceding-sibling_id != ''">
7067
+ <xsl:apply-templates select="parent::*/*[@type = 'section-title' and @id = $preceding-sibling_id and not(@displayorder)]" mode="update_xml_step1"/>
7068
+ </xsl:if>
7069
+
7070
+ <xsl:choose>
7071
+ <xsl:when test="@type = 'section-title' and not(@displayorder)"><!-- skip, don't copy, because copied in above 'apply-templates' --></xsl:when>
7072
+ <xsl:otherwise>
7073
+ <xsl:apply-templates select="." mode="update_xml_step1"/>
7074
+ </xsl:otherwise>
7075
+ </xsl:choose>
7076
+
7077
+ </xsl:for-each>
7078
+ </xsl:copy>
7079
+ </xsl:template><xsl:template match="*[local-name() = 'sections']" mode="update_xml_step1">
7080
+ <xsl:copy>
7081
+ <xsl:copy-of select="@*"/>
7082
+
7083
+ <xsl:variable name="nodes_sections_">
7084
+ <xsl:for-each select="*">
7085
+ <node id="{@id}"/>
7086
+ </xsl:for-each>
7087
+ </xsl:variable>
7088
+ <xsl:variable name="nodes_sections" select="xalan:nodeset($nodes_sections_)"/>
7089
+
7090
+ <!-- move section 'Normative references' inside 'sections' -->
7091
+ <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']]">
7092
+ <xsl:sort select="@displayorder" data-type="number"/>
7093
+
7094
+ <!-- process Section's title -->
7095
+ <xsl:variable name="preceding-sibling_id" select="$nodes_sections/node[@id = current()/@id]/preceding-sibling::node[1]/@id"/>
7096
+ <xsl:if test="$preceding-sibling_id != ''">
7097
+ <xsl:apply-templates select="parent::*/*[@type = 'section-title' and @id = $preceding-sibling_id and not(@displayorder)]" mode="update_xml_step1"/>
7098
+ </xsl:if>
7099
+
7100
+ <xsl:choose>
7101
+ <xsl:when test="@type = 'section-title' and not(@displayorder)"><!-- skip, don't copy, because copied in above 'apply-templates' --></xsl:when>
7102
+ <xsl:otherwise>
7103
+ <xsl:apply-templates select="." mode="update_xml_step1"/>
7104
+ </xsl:otherwise>
7105
+ </xsl:choose>
7106
+
7107
+ </xsl:for-each>
7108
+ </xsl:copy>
7109
+ </xsl:template><xsl:template match="*[local-name() = 'bibliography']" mode="update_xml_step1">
7110
+ <xsl:copy>
7111
+ <xsl:copy-of select="@*"/>
7112
+ <!-- copy all elements from bibliography except 'Normative references' (moved to 'sections') -->
7113
+ <xsl:for-each select="*[not(@normative='true') and not(*[@normative='true'])]">
7114
+ <xsl:sort select="@displayorder" data-type="number"/>
7115
+ <xsl:apply-templates select="." mode="update_xml_step1"/>
7116
+ </xsl:for-each>
7117
+ </xsl:copy>
6800
7118
  </xsl:template><xsl:template name="convertDate">
6801
7119
  <xsl:param name="date"/>
6802
7120
  <xsl:param name="format" select="'short'"/>
@@ -7041,22 +7359,25 @@
7041
7359
  <xsl:param name="pText" select="."/>
7042
7360
  <xsl:param name="sep" select="','"/>
7043
7361
  <xsl:param name="normalize-space" select="'true'"/>
7362
+ <xsl:param name="keep_sep" select="'false'"/>
7044
7363
  <xsl:if test="string-length($pText) &gt;0">
7045
- <item>
7046
- <xsl:choose>
7047
- <xsl:when test="$normalize-space = 'true'">
7048
- <xsl:value-of select="normalize-space(substring-before(concat($pText, $sep), $sep))"/>
7049
- </xsl:when>
7050
- <xsl:otherwise>
7051
- <xsl:value-of select="substring-before(concat($pText, $sep), $sep)"/>
7052
- </xsl:otherwise>
7053
- </xsl:choose>
7054
- </item>
7055
- <xsl:call-template name="split">
7056
- <xsl:with-param name="pText" select="substring-after($pText, $sep)"/>
7057
- <xsl:with-param name="sep" select="$sep"/>
7058
- <xsl:with-param name="normalize-space" select="$normalize-space"/>
7059
- </xsl:call-template>
7364
+ <item>
7365
+ <xsl:choose>
7366
+ <xsl:when test="$normalize-space = 'true'">
7367
+ <xsl:value-of select="normalize-space(substring-before(concat($pText, $sep), $sep))"/>
7368
+ </xsl:when>
7369
+ <xsl:otherwise>
7370
+ <xsl:value-of select="substring-before(concat($pText, $sep), $sep)"/>
7371
+ </xsl:otherwise>
7372
+ </xsl:choose>
7373
+ </item>
7374
+ <xsl:if test="$keep_sep = 'true' and contains($pText, $sep)"><item><xsl:value-of select="$sep"/></item></xsl:if>
7375
+ <xsl:call-template name="split">
7376
+ <xsl:with-param name="pText" select="substring-after($pText, $sep)"/>
7377
+ <xsl:with-param name="sep" select="$sep"/>
7378
+ <xsl:with-param name="normalize-space" select="$normalize-space"/>
7379
+ <xsl:with-param name="keep_sep" select="$keep_sep"/>
7380
+ </xsl:call-template>
7060
7381
  </xsl:if>
7061
7382
  </xsl:template><xsl:template name="getDocumentId">
7062
7383
  <xsl:call-template name="getLang"/><xsl:value-of select="//*[local-name() = 'p'][1]/@id"/>