metanorma-mpfa 0.8.4 → 0.8.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -32,7 +32,7 @@
32
32
  <item level="1" id="Foreword" display="true">Foreword</item>
33
33
  <item id="term-script" display="false">3.2</item>
34
34
  -->
35
- <xsl:variable name="contents">
35
+ <xsl:variable name="contents_">
36
36
  <contents>
37
37
  <xsl:apply-templates select="/mpfd:mpfd-standard/mpfd:preface/*[not(local-name() = 'terms')]" mode="contents"/>
38
38
  <xsl:apply-templates select="/mpfd:mpfd-standard/mpfd:preface/mpfd:terms" mode="contents"/>
@@ -41,11 +41,12 @@
41
41
 
42
42
  <xsl:apply-templates select="/mpfd:mpfd-standard/mpfd:annex" mode="contents"/>
43
43
 
44
- <xsl:apply-templates select="/mpfd:mpfd-standard/mpfd:bibliography" mode="contents"/>
44
+ <xsl:apply-templates select="/mpfd:mpfd-standard/mpfd:bibliography" mode="contents"/>
45
45
 
46
+ <xsl:call-template name="processTablesFigures_Contents"/>
46
47
  </contents>
47
48
  </xsl:variable>
48
-
49
+ <xsl:variable name="contents" select="xalan:nodeset($contents_)"/>
49
50
 
50
51
  <xsl:template match="/">
51
52
  <xsl:call-template name="namespaceCheck"/>
@@ -159,7 +160,7 @@
159
160
  <xsl:if test="$debug = 'true'">
160
161
  <xsl:text disable-output-escaping="yes">&lt;!--</xsl:text>
161
162
  DEBUG
162
- contents=<xsl:copy-of select="xalan:nodeset($contents)"/>
163
+ contents=<xsl:copy-of select="$contents"/>
163
164
  <xsl:text disable-output-escaping="yes">--&gt;</xsl:text>
164
165
  </xsl:if>
165
166
  <!-- Table of content -->
@@ -171,7 +172,7 @@
171
172
  </xsl:variable>
172
173
  <fo:block font-size="14pt" margin-bottom="15.5pt" role="H1"><xsl:value-of select="$title-toc"/></fo:block>
173
174
  <fo:block line-height="115%" role="TOC">
174
- <xsl:for-each select="xalan:nodeset($contents)//item[@display = 'true']">
175
+ <xsl:for-each select="$contents//item[@display = 'true']">
175
176
  <fo:block role="TOCI">
176
177
  <xsl:if test="@level = 1">
177
178
  <xsl:attribute name="margin-top">6pt</xsl:attribute>
@@ -191,21 +192,43 @@
191
192
  </xsl:if>
192
193
  </fo:block>
193
194
  </fo:list-item-label>
194
- <fo:list-item-body start-indent="body-start()">
195
- <fo:block text-align-last="justify">
196
- <fo:basic-link internal-destination="{@id}" fox:alt-text="{title}">
197
- <xsl:apply-templates select="title"/>
198
- <fo:inline keep-together.within-line="always">
199
- <fo:leader leader-pattern="dots"/>
200
- <fo:page-number-citation ref-id="{@id}"/>
201
- </fo:inline>
202
- </fo:basic-link>
203
- </fo:block>
204
- </fo:list-item-body>
195
+ <fo:list-item-body start-indent="body-start()">
196
+ <fo:block text-align-last="justify">
197
+ <fo:basic-link internal-destination="{@id}" fox:alt-text="{title}">
198
+ <xsl:apply-templates select="title"/>
199
+ <fo:inline keep-together.within-line="always">
200
+ <fo:leader leader-pattern="dots"/>
201
+ <fo:page-number-citation ref-id="{@id}"/>
202
+ </fo:inline>
203
+ </fo:basic-link>
204
+ </fo:block>
205
+ </fo:list-item-body>
205
206
  </fo:list-item>
206
207
  </fo:list-block>
207
208
  </fo:block>
208
209
  </xsl:for-each>
210
+
211
+
212
+ <!-- List of Tables -->
213
+ <xsl:if test="$contents//tables/table">
214
+ <xsl:call-template name="insertListOf_Title">
215
+ <xsl:with-param name="title" select="$title-list-tables"/>
216
+ </xsl:call-template>
217
+ <xsl:for-each select="$contents//tables/table">
218
+ <xsl:call-template name="insertListOf_Item"/>
219
+ </xsl:for-each>
220
+ </xsl:if>
221
+
222
+ <!-- List of Figures -->
223
+ <xsl:if test="$contents//figures/figure">
224
+ <xsl:call-template name="insertListOf_Title">
225
+ <xsl:with-param name="title" select="$title-list-figures"/>
226
+ </xsl:call-template>
227
+ <xsl:for-each select="$contents//figures/figure">
228
+ <xsl:call-template name="insertListOf_Item"/>
229
+ </xsl:for-each>
230
+ </xsl:if>
231
+
209
232
  </fo:block>
210
233
  </fo:block-container>
211
234
  <xsl:if test="/mpfd:mpfd-standard/mpfd:preface/*">
@@ -246,6 +269,28 @@
246
269
  </fo:root>
247
270
  </xsl:template>
248
271
 
272
+ <xsl:template name="insertListOf_Title">
273
+ <xsl:param name="title"/>
274
+ <fo:block margin-top="6pt" keep-with-next="always">
275
+ <xsl:value-of select="$title"/>
276
+ </fo:block>
277
+ </xsl:template>
278
+
279
+ <xsl:template name="insertListOf_Item">
280
+ <fo:block role="TOCI" text-align-last="justify">
281
+ <fo:basic-link internal-destination="{@id}">
282
+ <xsl:call-template name="setAltText">
283
+ <xsl:with-param name="value" select="@alt-text"/>
284
+ </xsl:call-template>
285
+ <xsl:apply-templates select="." mode="contents"/>
286
+ <fo:inline keep-together.within-line="always">
287
+ <fo:leader leader-pattern="dots"/>
288
+ <fo:page-number-citation ref-id="{@id}"/>
289
+ </fo:inline>
290
+ </fo:basic-link>
291
+ </fo:block>
292
+ </xsl:template>
293
+
249
294
  <xsl:template match="node()">
250
295
  <xsl:apply-templates/>
251
296
  </xsl:template>
@@ -571,7 +616,7 @@
571
616
  <xsl:text>Contents</xsl:text>
572
617
 
573
618
  </title-toc>
574
-
619
+
575
620
  <title-descriptors lang="en">Descriptors</title-descriptors>
576
621
 
577
622
  <title-part lang="en">
@@ -607,7 +652,31 @@
607
652
  <title-continued lang="en">(continued)</title-continued>
608
653
  <title-continued lang="fr">(continué)</title-continued>
609
654
 
610
- </xsl:variable><xsl:variable name="titles" select="xalan:nodeset($titles_)"/><xsl:variable name="bibdata">
655
+ </xsl:variable><xsl:variable name="titles" select="xalan:nodeset($titles_)"/><xsl:variable name="title-list-tables">
656
+ <xsl:variable name="toc_table_title" select="//*[contains(local-name(), '-standard')]/*[local-name() = 'misc-container']/*[local-name() = 'toc'][@type='table']/*[local-name() = 'title']"/>
657
+ <xsl:value-of select="$toc_table_title"/>
658
+ <xsl:if test="normalize-space($toc_table_title) = ''">
659
+ <xsl:call-template name="getTitle">
660
+ <xsl:with-param name="name" select="'title-list-tables'"/>
661
+ </xsl:call-template>
662
+ </xsl:if>
663
+ </xsl:variable><xsl:variable name="title-list-figures">
664
+ <xsl:variable name="toc_figure_title" select="//*[contains(local-name(), '-standard')]/*[local-name() = 'misc-container']/*[local-name() = 'toc'][@type='figure']/*[local-name() = 'title']"/>
665
+ <xsl:value-of select="$toc_figure_title"/>
666
+ <xsl:if test="normalize-space($toc_figure_title) = ''">
667
+ <xsl:call-template name="getTitle">
668
+ <xsl:with-param name="name" select="'title-list-figures'"/>
669
+ </xsl:call-template>
670
+ </xsl:if>
671
+ </xsl:variable><xsl:variable name="title-list-recommendations">
672
+ <xsl:variable name="toc_requirement_title" select="//*[contains(local-name(), '-standard')]/*[local-name() = 'misc-container']/*[local-name() = 'toc'][@type='requirement']/*[local-name() = 'title']"/>
673
+ <xsl:value-of select="$toc_requirement_title"/>
674
+ <xsl:if test="normalize-space($toc_requirement_title) = ''">
675
+ <xsl:call-template name="getTitle">
676
+ <xsl:with-param name="name" select="'title-list-recommendations'"/>
677
+ </xsl:call-template>
678
+ </xsl:if>
679
+ </xsl:variable><xsl:variable name="bibdata">
611
680
  <xsl:copy-of select="//*[contains(local-name(), '-standard')]/*[local-name() = 'bibdata']"/>
612
681
  <xsl:copy-of select="//*[contains(local-name(), '-standard')]/*[local-name() = 'localized-strings']"/>
613
682
  </xsl:variable><xsl:variable name="linebreak">&#8232;</xsl:variable><xsl:variable name="tab_zh"> </xsl:variable><xsl:variable name="non_breaking_hyphen">‑</xsl:variable><xsl:variable name="thin_space"> </xsl:variable><xsl:variable name="zero_width_space">​</xsl:variable><xsl:variable name="en_dash">–</xsl:variable><xsl:template name="getTitle">
@@ -1784,6 +1853,30 @@
1784
1853
  <xsl:sort select="@displayorder" data-type="number"/>
1785
1854
  <xsl:apply-templates select="." mode="contents"/>
1786
1855
  </xsl:for-each>
1856
+ </xsl:template><xsl:template name="processTablesFigures_Contents">
1857
+ <xsl:param name="always"/>
1858
+ <xsl:if test="(//*[contains(local-name(), '-standard')]/*[local-name() = 'misc-container']/*[local-name() = 'toc'][@type='table']/*[local-name() = 'title']) or normalize-space($always) = 'true'">
1859
+ <xsl:call-template name="processTables_Contents"/>
1860
+ </xsl:if>
1861
+ <xsl:if test="(//*[contains(local-name(), '-standard')]/*[local-name() = 'misc-container']/*[local-name() = 'toc'][@type='figure']/*[local-name() = 'title']) or normalize-space($always) = 'true'">
1862
+ <xsl:call-template name="processFigures_Contents"/>
1863
+ </xsl:if>
1864
+ </xsl:template><xsl:template name="processTables_Contents">
1865
+ <tables>
1866
+ <xsl:for-each select="//*[local-name() = 'table'][@id and *[local-name() = 'name'] and normalize-space(@id) != '']">
1867
+ <table id="{@id}" alt-text="{*[local-name() = 'name']}">
1868
+ <xsl:copy-of select="*[local-name() = 'name']"/>
1869
+ </table>
1870
+ </xsl:for-each>
1871
+ </tables>
1872
+ </xsl:template><xsl:template name="processFigures_Contents">
1873
+ <figures>
1874
+ <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) != '']">
1875
+ <figure id="{@id}" alt-text="{*[local-name() = 'name']}">
1876
+ <xsl:copy-of select="*[local-name() = 'name']"/>
1877
+ </figure>
1878
+ </xsl:for-each>
1879
+ </figures>
1787
1880
  </xsl:template><xsl:template name="processPrefaceSectionsDefault">
1788
1881
  <xsl:for-each select="/*/*[local-name()='preface']/*">
1789
1882
  <xsl:sort select="@displayorder" data-type="number"/>
@@ -1805,8 +1898,27 @@
1805
1898
  <xsl:sort select="@displayorder" data-type="number"/>
1806
1899
  <xsl:apply-templates select="."/>
1807
1900
  </xsl:for-each>
1808
- </xsl:template><xsl:template match="text()">
1809
- <xsl:value-of select="."/>
1901
+ </xsl:template><xsl:variable name="tag_open">###fo:inline###</xsl:variable><xsl:variable name="tag_close">###/fo:inline###</xsl:variable><xsl:template match="text()" name="text">
1902
+ <xsl:variable name="regex_standard_reference">([A-Z]{2,}(/[A-Z]{2,})* \d+(-\d+)*(:\d{4})?)</xsl:variable>
1903
+ <xsl:variable name="text" select="java:replaceAll(java:java.lang.String.new(.),$regex_standard_reference,concat($tag_open,'$1',$tag_close))"/>
1904
+ <xsl:call-template name="replace_fo_inline">
1905
+ <xsl:with-param name="text" select="$text"/>
1906
+ </xsl:call-template>
1907
+ </xsl:template><xsl:template name="replace_fo_inline">
1908
+ <xsl:param name="text"/>
1909
+ <xsl:choose>
1910
+ <xsl:when test="contains($text, $tag_open)">
1911
+ <xsl:value-of select="substring-before($text, $tag_open)"/>
1912
+ <xsl:text disable-output-escaping="yes">&lt;fo:inline keep-together.within-line="always"&gt;</xsl:text>
1913
+ <xsl:variable name="text_after" select="substring-after($text, $tag_open)"/>
1914
+ <xsl:value-of select="substring-before($text_after, $tag_close)"/>
1915
+ <xsl:text disable-output-escaping="yes">&lt;/fo:inline&gt;</xsl:text>
1916
+ <xsl:call-template name="replace_fo_inline">
1917
+ <xsl:with-param name="text" select="substring-after($text_after, $tag_close)"/>
1918
+ </xsl:call-template>
1919
+ </xsl:when>
1920
+ <xsl:otherwise><xsl:value-of select="$text"/></xsl:otherwise>
1921
+ </xsl:choose>
1810
1922
  </xsl:template><xsl:template match="*[local-name()='br']">
1811
1923
  <xsl:value-of select="$linebreak"/>
1812
1924
  </xsl:template><xsl:template match="*[local-name()='copyright-statement']">
@@ -2556,37 +2668,7 @@
2556
2668
 
2557
2669
  <!-- list of footnotes to calculate actual footnotes number -->
2558
2670
  <xsl:variable name="p_fn_">
2559
- <xsl:choose>
2560
- <xsl:when test="@current_fn_number"> <!-- for BSI, footnote reference number calculated already -->
2561
- <fn gen_id="{generate-id(.)}">
2562
- <xsl:copy-of select="@*"/>
2563
- <xsl:copy-of select="node()"/>
2564
- </fn>
2565
- </xsl:when>
2566
- <xsl:otherwise>
2567
- <!-- itetation for:
2568
- footnotes in bibdata/title
2569
- footnotes in bibliography
2570
- footnotes in document's body (except table's head/body/foot and figure text)
2571
- -->
2572
- <xsl:for-each select="ancestor::*[contains(local-name(), '-standard')]/*[local-name() = 'bibdata']/*[local-name() = 'note'][@type='title-footnote']">
2573
- <fn gen_id="{generate-id(.)}">
2574
- <xsl:copy-of select="@*"/>
2575
- <xsl:copy-of select="node()"/>
2576
- </fn>
2577
- </xsl:for-each>
2578
- <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']/*">
2579
- <xsl:sort select="@displayorder" data-type="number"/>
2580
- <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])]">
2581
- <!-- copy unique fn -->
2582
- <fn gen_id="{generate-id(.)}">
2583
- <xsl:copy-of select="@*"/>
2584
- <xsl:copy-of select="node()"/>
2585
- </fn>
2586
- </xsl:for-each>
2587
- </xsl:for-each>
2588
- </xsl:otherwise>
2589
- </xsl:choose>
2671
+ <xsl:call-template name="get_fn_list"/>
2590
2672
  </xsl:variable>
2591
2673
  <xsl:variable name="p_fn" select="xalan:nodeset($p_fn_)"/>
2592
2674
 
@@ -2647,6 +2729,38 @@
2647
2729
  <xsl:copy-of select="$footnote_inline"/>
2648
2730
  </xsl:otherwise>
2649
2731
  </xsl:choose>
2732
+ </xsl:template><xsl:template name="get_fn_list">
2733
+ <xsl:choose>
2734
+ <xsl:when test="@current_fn_number"> <!-- for BSI, footnote reference number calculated already -->
2735
+ <fn gen_id="{generate-id(.)}">
2736
+ <xsl:copy-of select="@*"/>
2737
+ <xsl:copy-of select="node()"/>
2738
+ </fn>
2739
+ </xsl:when>
2740
+ <xsl:otherwise>
2741
+ <!-- itetation for:
2742
+ footnotes in bibdata/title
2743
+ footnotes in bibliography
2744
+ footnotes in document's body (except table's head/body/foot and figure text)
2745
+ -->
2746
+ <xsl:for-each select="ancestor::*[contains(local-name(), '-standard')]/*[local-name() = 'bibdata']/*[local-name() = 'note'][@type='title-footnote']">
2747
+ <fn gen_id="{generate-id(.)}">
2748
+ <xsl:copy-of select="@*"/>
2749
+ <xsl:copy-of select="node()"/>
2750
+ </fn>
2751
+ </xsl:for-each>
2752
+ <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']/*">
2753
+ <xsl:sort select="@displayorder" data-type="number"/>
2754
+ <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])]">
2755
+ <!-- copy unique fn -->
2756
+ <fn gen_id="{generate-id(.)}">
2757
+ <xsl:copy-of select="@*"/>
2758
+ <xsl:copy-of select="node()"/>
2759
+ </fn>
2760
+ </xsl:for-each>
2761
+ </xsl:for-each>
2762
+ </xsl:otherwise>
2763
+ </xsl:choose>
2650
2764
  </xsl:template><xsl:template name="table_fn_display">
2651
2765
  <xsl:variable name="references">
2652
2766
 
@@ -2818,7 +2932,7 @@
2818
2932
  </fo:inline>
2819
2933
  </xsl:template><xsl:template match="*[local-name()='fn']/text()[normalize-space() != '']">
2820
2934
  <fo:inline><xsl:value-of select="."/></fo:inline>
2821
- </xsl:template><xsl:template match="*[local-name()='fn']/*[local-name()='p']">
2935
+ </xsl:template><xsl:template match="*[local-name()='fn']//*[local-name()='p']">
2822
2936
  <fo:inline>
2823
2937
  <xsl:apply-templates/>
2824
2938
  </fo:inline>
@@ -4504,13 +4618,14 @@
4504
4618
  <xsl:apply-templates mode="bookmarks"/>
4505
4619
  </xsl:template><xsl:template name="addBookmarks">
4506
4620
  <xsl:param name="contents"/>
4507
- <xsl:if test="xalan:nodeset($contents)//item">
4621
+ <xsl:variable name="contents_nodes" select="xalan:nodeset($contents)"/>
4622
+ <xsl:if test="$contents_nodes//item">
4508
4623
  <fo:bookmark-tree>
4509
4624
  <xsl:choose>
4510
- <xsl:when test="xalan:nodeset($contents)/doc">
4625
+ <xsl:when test="$contents_nodes/doc">
4511
4626
  <xsl:choose>
4512
- <xsl:when test="count(xalan:nodeset($contents)/doc) &gt; 1">
4513
- <xsl:for-each select="xalan:nodeset($contents)/doc">
4627
+ <xsl:when test="count($contents_nodes/doc) &gt; 1">
4628
+ <xsl:for-each select="$contents_nodes/doc">
4514
4629
  <fo:bookmark internal-destination="{contents/item[1]/@id}" starting-state="hide">
4515
4630
  <xsl:if test="@bundle = 'true'">
4516
4631
  <xsl:attribute name="internal-destination"><xsl:value-of select="@firstpage_id"/></xsl:attribute>
@@ -4561,7 +4676,7 @@
4561
4676
  </xsl:for-each>
4562
4677
  </xsl:when>
4563
4678
  <xsl:otherwise>
4564
- <xsl:for-each select="xalan:nodeset($contents)/doc">
4679
+ <xsl:for-each select="$contents_nodes/doc">
4565
4680
 
4566
4681
  <xsl:apply-templates select="contents/item" mode="bookmark"/>
4567
4682
 
@@ -4579,25 +4694,36 @@
4579
4694
  </xsl:choose>
4580
4695
  </xsl:when>
4581
4696
  <xsl:otherwise>
4582
- <xsl:apply-templates select="xalan:nodeset($contents)/contents/item" mode="bookmark"/>
4697
+ <xsl:apply-templates select="$contents_nodes/contents/item" mode="bookmark"/>
4698
+
4699
+ <xsl:call-template name="insertFigureBookmarks">
4700
+ <xsl:with-param name="contents" select="$contents_nodes/contents"/>
4701
+ </xsl:call-template>
4702
+
4703
+ <xsl:call-template name="insertTableBookmarks">
4704
+ <xsl:with-param name="contents" select="$contents_nodes/contents"/>
4705
+ <xsl:with-param name="lang" select="@lang"/>
4706
+ </xsl:call-template>
4707
+
4583
4708
  </xsl:otherwise>
4584
4709
  </xsl:choose>
4585
4710
 
4711
+
4586
4712
 
4587
4713
 
4588
4714
 
4589
4715
 
4590
-
4591
-
4716
+
4592
4717
 
4593
4718
  </fo:bookmark-tree>
4594
4719
  </xsl:if>
4595
4720
  </xsl:template><xsl:template name="insertFigureBookmarks">
4596
4721
  <xsl:param name="contents"/>
4597
- <xsl:if test="xalan:nodeset($contents)/figure">
4598
- <fo:bookmark internal-destination="{xalan:nodeset($contents)/figure[1]/@id}" starting-state="hide">
4722
+ <xsl:variable name="contents_nodes" select="xalan:nodeset($contents)"/>
4723
+ <xsl:if test="$contents_nodes/figure">
4724
+ <fo:bookmark internal-destination="{$contents_nodes/figure[1]/@id}" starting-state="hide">
4599
4725
  <fo:bookmark-title>Figures</fo:bookmark-title>
4600
- <xsl:for-each select="xalan:nodeset($contents)/figure">
4726
+ <xsl:for-each select="$contents_nodes/figure">
4601
4727
  <fo:bookmark internal-destination="{@id}">
4602
4728
  <fo:bookmark-title>
4603
4729
  <xsl:value-of select="normalize-space(title)"/>
@@ -4606,18 +4732,40 @@
4606
4732
  </xsl:for-each>
4607
4733
  </fo:bookmark>
4608
4734
  </xsl:if>
4735
+
4736
+
4737
+ <xsl:if test="$contents_nodes//figures/figure">
4738
+ <fo:bookmark internal-destination="empty_bookmark" starting-state="hide">
4739
+
4740
+
4741
+
4742
+ <xsl:variable name="bookmark-title">
4743
+
4744
+ <xsl:value-of select="$title-list-figures"/>
4745
+
4746
+ </xsl:variable>
4747
+ <fo:bookmark-title><xsl:value-of select="normalize-space($bookmark-title)"/></fo:bookmark-title>
4748
+ <xsl:for-each select="$contents_nodes//figures/figure">
4749
+ <fo:bookmark internal-destination="{@id}">
4750
+ <fo:bookmark-title><xsl:value-of select="normalize-space(.)"/></fo:bookmark-title>
4751
+ </fo:bookmark>
4752
+ </xsl:for-each>
4753
+ </fo:bookmark>
4754
+ </xsl:if>
4755
+
4609
4756
  </xsl:template><xsl:template name="insertTableBookmarks">
4610
4757
  <xsl:param name="contents"/>
4611
4758
  <xsl:param name="lang"/>
4612
- <xsl:if test="xalan:nodeset($contents)/table">
4613
- <fo:bookmark internal-destination="{xalan:nodeset($contents)/table[1]/@id}" starting-state="hide">
4759
+ <xsl:variable name="contents_nodes" select="xalan:nodeset($contents)"/>
4760
+ <xsl:if test="$contents_nodes/table">
4761
+ <fo:bookmark internal-destination="{$contents_nodes/table[1]/@id}" starting-state="hide">
4614
4762
  <fo:bookmark-title>
4615
4763
  <xsl:choose>
4616
4764
  <xsl:when test="$lang = 'fr'">Tableaux</xsl:when>
4617
4765
  <xsl:otherwise>Tables</xsl:otherwise>
4618
4766
  </xsl:choose>
4619
4767
  </fo:bookmark-title>
4620
- <xsl:for-each select="xalan:nodeset($contents)/table">
4768
+ <xsl:for-each select="$contents_nodes/table">
4621
4769
  <fo:bookmark internal-destination="{@id}">
4622
4770
  <fo:bookmark-title>
4623
4771
  <xsl:value-of select="normalize-space(title)"/>
@@ -4626,6 +4774,29 @@
4626
4774
  </xsl:for-each>
4627
4775
  </fo:bookmark>
4628
4776
  </xsl:if>
4777
+
4778
+
4779
+ <xsl:if test="$contents_nodes//tables/table">
4780
+ <fo:bookmark internal-destination="empty_bookmark" starting-state="hide">
4781
+
4782
+
4783
+
4784
+ <xsl:variable name="bookmark-title">
4785
+
4786
+ <xsl:value-of select="$title-list-tables"/>
4787
+
4788
+ </xsl:variable>
4789
+
4790
+ <fo:bookmark-title><xsl:value-of select="$bookmark-title"/></fo:bookmark-title>
4791
+
4792
+ <xsl:for-each select="$contents_nodes//tables/table">
4793
+ <fo:bookmark internal-destination="{@id}">
4794
+ <fo:bookmark-title><xsl:value-of select="normalize-space(.)"/></fo:bookmark-title>
4795
+ </fo:bookmark>
4796
+ </xsl:for-each>
4797
+ </fo:bookmark>
4798
+ </xsl:if>
4799
+
4629
4800
  </xsl:template><xsl:template name="getLangVersion">
4630
4801
  <xsl:param name="lang"/>
4631
4802
  <xsl:param name="doctype" select="''"/>
@@ -4850,7 +5021,51 @@
4850
5021
  <xsl:with-param name="text" select="$text_step1"/>
4851
5022
  </xsl:call-template>
4852
5023
  </xsl:variable>
4853
- <xsl:value-of select="$text_step2"/>
5024
+
5025
+ <!-- <xsl:value-of select="$text_step2"/> -->
5026
+
5027
+ <!-- add zero-width space after space -->
5028
+ <xsl:variable name="text_step3" select="java:replaceAll(java:java.lang.String.new($text_step2),' ',' ​')"/>
5029
+
5030
+ <!-- split text by zero-width space -->
5031
+ <xsl:variable name="text_step4">
5032
+ <xsl:call-template name="split">
5033
+ <xsl:with-param name="pText" select="$text_step3"/>
5034
+ <xsl:with-param name="sep" select="$zero_width_space"/>
5035
+ <xsl:with-param name="normalize-space">false</xsl:with-param>
5036
+ <xsl:with-param name="keep_sep">true</xsl:with-param>
5037
+ </xsl:call-template>
5038
+ </xsl:variable>
5039
+
5040
+ <xsl:for-each select="xalan:nodeset($text_step4)/item">
5041
+ <xsl:choose>
5042
+ <xsl:when test="string-length() &gt; 30"> <!-- word with length more than 30 will be interspersed with zero-width space -->
5043
+ <xsl:call-template name="interspers">
5044
+ <xsl:with-param name="str" select="."/>
5045
+ </xsl:call-template>
5046
+ </xsl:when>
5047
+ <xsl:otherwise>
5048
+ <xsl:value-of select="."/>
5049
+ </xsl:otherwise>
5050
+ </xsl:choose>
5051
+ </xsl:for-each>
5052
+
5053
+ </xsl:template><xsl:template name="interspers">
5054
+ <xsl:param name="str"/>
5055
+ <xsl:param name="char" select="$zero_width_space"/>
5056
+ <xsl:if test="$str != ''">
5057
+ <xsl:value-of select="substring($str, 1, 1)"/>
5058
+
5059
+ <xsl:variable name="next_char" select="substring($str, 2, 1)"/>
5060
+ <xsl:if test="not(contains(concat(' -.:=_— ', $char), $next_char))">
5061
+ <xsl:value-of select="$char"/>
5062
+ </xsl:if>
5063
+
5064
+ <xsl:call-template name="interspers">
5065
+ <xsl:with-param name="str" select="substring($str, 2)"/>
5066
+ <xsl:with-param name="char" select="$char"/>
5067
+ </xsl:call-template>
5068
+ </xsl:if>
4854
5069
  </xsl:template><xsl:template match="*" mode="syntax_highlight">
4855
5070
  <xsl:apply-templates mode="syntax_highlight"/>
4856
5071
  </xsl:template><xsl:variable name="syntax_highlight_styles_">
@@ -5282,6 +5497,8 @@
5282
5497
  </xsl:otherwise>
5283
5498
  </xsl:choose> -->
5284
5499
  </fo:block>
5500
+ </xsl:template><xsl:template match="*[local-name() = 'termsource']/text()[starts-with(., '[SOURCE: Adapted from: ')]" priority="2">
5501
+ <xsl:text>[</xsl:text><xsl:value-of select="substring-after(., '[SOURCE: ')"/>
5285
5502
  </xsl:template><xsl:template match="*[local-name() = 'termsource']/text()">
5286
5503
  <xsl:if test="normalize-space() != ''">
5287
5504
  <xsl:value-of select="."/>
@@ -5316,7 +5533,8 @@
5316
5533
  <fo:inline><xsl:apply-templates/></fo:inline>
5317
5534
  </xsl:template><xsl:template match="*[local-name() = 'modification']/text()">
5318
5535
  <xsl:if test="normalize-space() != ''">
5319
- <xsl:value-of select="."/>
5536
+ <!-- <xsl:value-of select="."/> -->
5537
+ <xsl:call-template name="text"/>
5320
5538
  </xsl:if>
5321
5539
  </xsl:template><xsl:template match="*[local-name() = 'quote']">
5322
5540
  <fo:block-container margin-left="0mm">
@@ -5356,26 +5574,24 @@
5356
5574
  </xsl:template><xsl:template match="*[local-name() = 'author']">
5357
5575
  <xsl:text>— </xsl:text>
5358
5576
  <xsl:apply-templates/>
5359
- </xsl:template><xsl:variable name="bibitem_hidden_">
5577
+ </xsl:template><xsl:variable name="bibitems_">
5578
+ <xsl:for-each select="//*[local-name() = 'bibitem']">
5579
+ <xsl:copy-of select="."/>
5580
+ </xsl:for-each>
5581
+ </xsl:variable><xsl:variable name="bibitems" select="xalan:nodeset($bibitems_)"/><xsl:variable name="bibitems_hidden_">
5360
5582
  <xsl:for-each select="//*[local-name() = 'bibitem'][@hidden='true']">
5361
5583
  <xsl:copy-of select="."/>
5362
5584
  </xsl:for-each>
5363
- <xsl:for-each select="//*[local-name() = 'references'][@hidden='true']/*[local-name() = 'bibitem']">
5585
+ <xsl:for-each select="//*[local-name() = 'references'][@hidden='true']//*[local-name() = 'bibitem']">
5364
5586
  <xsl:copy-of select="."/>
5365
5587
  </xsl:for-each>
5366
- </xsl:variable><xsl:variable name="bibitem_hidden" select="xalan:nodeset($bibitem_hidden_)"/><xsl:template match="*[local-name() = 'eref']">
5367
-
5368
- <xsl:variable name="bibitemid">
5369
- <xsl:choose>
5370
- <!-- <xsl:when test="//*[local-name() = 'bibitem'][@hidden='true' and @id = current()/@bibitemid]"></xsl:when>
5371
- <xsl:when test="//*[local-name() = 'references'][@hidden='true']/*[local-name() = 'bibitem'][@id = current()/@bibitemid]"></xsl:when> -->
5372
- <xsl:when test="$bibitem_hidden/*[local-name() = 'bibitem'][@id = current()/@bibitemid]"/>
5373
- <xsl:otherwise><xsl:value-of select="@bibitemid"/></xsl:otherwise>
5374
- </xsl:choose>
5375
- </xsl:variable>
5376
-
5588
+ </xsl:variable><xsl:variable name="bibitems_hidden" select="xalan:nodeset($bibitems_hidden_)"/><xsl:template match="*[local-name() = 'eref']">
5589
+ <xsl:variable name="current_bibitemid" select="@bibitemid"/>
5590
+ <!-- <xsl:variable name="external-destination" select="normalize-space(key('bibitems', $current_bibitemid)/*[local-name() = 'uri'][@type = 'citation'])"/> -->
5591
+ <xsl:variable name="external-destination" select="normalize-space($bibitems/*[local-name() ='bibitem'][@id = $current_bibitemid]/*[local-name() = 'uri'][@type = 'citation'])"/>
5377
5592
  <xsl:choose>
5378
- <xsl:when test="normalize-space($bibitemid) != ''"> <!-- if in the bibliography there is the item with @bibitemid (and not hidden), then create link -->
5593
+ <!-- <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) -->
5594
+ <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) -->
5379
5595
  <fo:inline xsl:use-attribute-sets="eref-style">
5380
5596
  <xsl:if test="@type = 'footnote'">
5381
5597
  <xsl:attribute name="keep-together.within-line">always</xsl:attribute>
@@ -5389,8 +5605,8 @@
5389
5605
  <xsl:variable name="text" select="normalize-space()"/>
5390
5606
 
5391
5607
 
5392
-
5393
- <fo:basic-link internal-destination="{@bibitemid}" fox:alt-text="{@citeas}">
5608
+
5609
+ <fo:basic-link fox:alt-text="{@citeas}">
5394
5610
  <xsl:if test="normalize-space(@citeas) = ''">
5395
5611
  <xsl:attribute name="fox:alt-text"><xsl:value-of select="."/></xsl:attribute>
5396
5612
  </xsl:if>
@@ -5403,14 +5619,21 @@
5403
5619
 
5404
5620
  </xsl:if>
5405
5621
 
5406
-
5622
+ <xsl:choose>
5623
+ <xsl:when test="$external-destination != ''"> <!-- external hyperlink -->
5624
+ <xsl:attribute name="external-destination"><xsl:value-of select="$external-destination"/></xsl:attribute>
5625
+ </xsl:when>
5626
+ <xsl:otherwise>
5627
+ <xsl:attribute name="internal-destination"><xsl:value-of select="@bibitemid"/></xsl:attribute>
5628
+ </xsl:otherwise>
5629
+ </xsl:choose>
5407
5630
 
5408
5631
  <xsl:apply-templates/>
5409
5632
  </fo:basic-link>
5410
-
5633
+
5411
5634
  </fo:inline>
5412
5635
  </xsl:when>
5413
- <xsl:otherwise>
5636
+ <xsl:otherwise> <!-- if there is key('bibitems_hidden', $current_bibitemid) -->
5414
5637
  <fo:inline><xsl:apply-templates/></fo:inline>
5415
5638
  </xsl:otherwise>
5416
5639
  </xsl:choose>
@@ -6130,23 +6353,45 @@
6130
6353
  <xsl:apply-templates/>
6131
6354
  </fo:inline>
6132
6355
  </xsl:template><xsl:template match="*[local-name() = 'bibitem']/*[local-name() = 'note']" priority="2">
6356
+
6357
+ <!-- list of footnotes to calculate actual footnotes number -->
6358
+ <xsl:variable name="p_fn_">
6359
+ <xsl:call-template name="get_fn_list"/>
6360
+ </xsl:variable>
6361
+ <xsl:variable name="p_fn" select="xalan:nodeset($p_fn_)"/>
6362
+ <xsl:variable name="gen_id" select="generate-id(.)"/>
6363
+ <xsl:variable name="lang" select="ancestor::*[contains(local-name(), '-standard')]/*[local-name()='bibdata']//*[local-name()='language'][@current = 'true']"/>
6364
+ <!-- fn sequence number in document -->
6365
+ <xsl:variable name="current_fn_number">
6366
+ <xsl:choose>
6367
+ <xsl:when test="@current_fn_number"><xsl:value-of select="@current_fn_number"/></xsl:when> <!-- for BSI -->
6368
+ <xsl:otherwise>
6369
+ <!-- <xsl:value-of select="count($p_fn//fn[@reference = $reference]/preceding-sibling::fn) + 1" /> -->
6370
+ <xsl:value-of select="count($p_fn//fn[@gen_id = $gen_id]/preceding-sibling::fn) + 1"/>
6371
+ </xsl:otherwise>
6372
+ </xsl:choose>
6373
+ </xsl:variable>
6133
6374
  <fo:footnote>
6134
6375
  <xsl:variable name="number">
6135
6376
 
6136
- <xsl:number level="any" count="*[local-name() = 'bibitem']/*[local-name() = 'note']"/>
6377
+ <xsl:value-of select="$current_fn_number"/>
6137
6378
 
6138
6379
  </xsl:variable>
6380
+
6381
+ <xsl:variable name="current_fn_number_text">
6382
+ <xsl:value-of select="$number"/>
6383
+
6384
+ </xsl:variable>
6385
+
6139
6386
  <fo:inline xsl:use-attribute-sets="bibitem-note-fn-style">
6140
- <fo:basic-link internal-destination="{generate-id()}" fox:alt-text="footnote {$number}">
6141
- <xsl:value-of select="$number"/>
6142
-
6387
+ <fo:basic-link internal-destination="{$gen_id}" fox:alt-text="footnote {$number}">
6388
+ <xsl:value-of select="$current_fn_number_text"/>
6143
6389
  </fo:basic-link>
6144
6390
  </fo:inline>
6145
6391
  <fo:footnote-body>
6146
6392
  <fo:block xsl:use-attribute-sets="bibitem-note-fn-body-style">
6147
- <fo:inline id="{generate-id()}" xsl:use-attribute-sets="bibitem-note-fn-number-style">
6148
- <xsl:value-of select="$number"/>
6149
-
6393
+ <fo:inline id="{$gen_id}" xsl:use-attribute-sets="bibitem-note-fn-number-style">
6394
+ <xsl:value-of select="$current_fn_number_text"/>
6150
6395
  </fo:inline>
6151
6396
  <xsl:apply-templates/>
6152
6397
  </fo:block>
@@ -6387,6 +6632,78 @@
6387
6632
  <!-- processing for admonition/p found in the template for 'p' -->
6388
6633
  <xsl:call-template name="paragraph"/>
6389
6634
 
6635
+ </xsl:template><xsl:template match="@*|node()" mode="update_xml_step1">
6636
+ <xsl:copy>
6637
+ <xsl:apply-templates select="@*|node()" mode="update_xml_step1"/>
6638
+ </xsl:copy>
6639
+ </xsl:template><xsl:template match="*[local-name() = 'preface']" mode="update_xml_step1">
6640
+ <xsl:copy>
6641
+ <xsl:copy-of select="@*"/>
6642
+
6643
+ <xsl:variable name="nodes_preface_">
6644
+ <xsl:for-each select="*">
6645
+ <node id="{@id}"/>
6646
+ </xsl:for-each>
6647
+ </xsl:variable>
6648
+ <xsl:variable name="nodes_preface" select="xalan:nodeset($nodes_preface_)"/>
6649
+
6650
+ <xsl:for-each select="*">
6651
+ <xsl:sort select="@displayorder" data-type="number"/>
6652
+
6653
+ <!-- process Section's title -->
6654
+ <xsl:variable name="preceding-sibling_id" select="$nodes_preface/node[@id = current()/@id]/preceding-sibling::node[1]/@id"/>
6655
+ <xsl:if test="$preceding-sibling_id != ''">
6656
+ <xsl:apply-templates select="parent::*/*[@type = 'section-title' and @id = $preceding-sibling_id and not(@displayorder)]" mode="update_xml_step1"/>
6657
+ </xsl:if>
6658
+
6659
+ <xsl:choose>
6660
+ <xsl:when test="@type = 'section-title' and not(@displayorder)"><!-- skip, don't copy, because copied in above 'apply-templates' --></xsl:when>
6661
+ <xsl:otherwise>
6662
+ <xsl:apply-templates select="." mode="update_xml_step1"/>
6663
+ </xsl:otherwise>
6664
+ </xsl:choose>
6665
+
6666
+ </xsl:for-each>
6667
+ </xsl:copy>
6668
+ </xsl:template><xsl:template match="*[local-name() = 'sections']" mode="update_xml_step1">
6669
+ <xsl:copy>
6670
+ <xsl:copy-of select="@*"/>
6671
+
6672
+ <xsl:variable name="nodes_sections_">
6673
+ <xsl:for-each select="*">
6674
+ <node id="{@id}"/>
6675
+ </xsl:for-each>
6676
+ </xsl:variable>
6677
+ <xsl:variable name="nodes_sections" select="xalan:nodeset($nodes_sections_)"/>
6678
+
6679
+ <!-- move section 'Normative references' inside 'sections' -->
6680
+ <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']]">
6681
+ <xsl:sort select="@displayorder" data-type="number"/>
6682
+
6683
+ <!-- process Section's title -->
6684
+ <xsl:variable name="preceding-sibling_id" select="$nodes_sections/node[@id = current()/@id]/preceding-sibling::node[1]/@id"/>
6685
+ <xsl:if test="$preceding-sibling_id != ''">
6686
+ <xsl:apply-templates select="parent::*/*[@type = 'section-title' and @id = $preceding-sibling_id and not(@displayorder)]" mode="update_xml_step1"/>
6687
+ </xsl:if>
6688
+
6689
+ <xsl:choose>
6690
+ <xsl:when test="@type = 'section-title' and not(@displayorder)"><!-- skip, don't copy, because copied in above 'apply-templates' --></xsl:when>
6691
+ <xsl:otherwise>
6692
+ <xsl:apply-templates select="." mode="update_xml_step1"/>
6693
+ </xsl:otherwise>
6694
+ </xsl:choose>
6695
+
6696
+ </xsl:for-each>
6697
+ </xsl:copy>
6698
+ </xsl:template><xsl:template match="*[local-name() = 'bibliography']" mode="update_xml_step1">
6699
+ <xsl:copy>
6700
+ <xsl:copy-of select="@*"/>
6701
+ <!-- copy all elements from bibliography except 'Normative references' (moved to 'sections') -->
6702
+ <xsl:for-each select="*[not(@normative='true') and not(*[@normative='true'])]">
6703
+ <xsl:sort select="@displayorder" data-type="number"/>
6704
+ <xsl:apply-templates select="." mode="update_xml_step1"/>
6705
+ </xsl:for-each>
6706
+ </xsl:copy>
6390
6707
  </xsl:template><xsl:template name="convertDate">
6391
6708
  <xsl:param name="date"/>
6392
6709
  <xsl:param name="format" select="'short'"/>
@@ -6631,22 +6948,25 @@
6631
6948
  <xsl:param name="pText" select="."/>
6632
6949
  <xsl:param name="sep" select="','"/>
6633
6950
  <xsl:param name="normalize-space" select="'true'"/>
6951
+ <xsl:param name="keep_sep" select="'false'"/>
6634
6952
  <xsl:if test="string-length($pText) &gt;0">
6635
- <item>
6636
- <xsl:choose>
6637
- <xsl:when test="$normalize-space = 'true'">
6638
- <xsl:value-of select="normalize-space(substring-before(concat($pText, $sep), $sep))"/>
6639
- </xsl:when>
6640
- <xsl:otherwise>
6641
- <xsl:value-of select="substring-before(concat($pText, $sep), $sep)"/>
6642
- </xsl:otherwise>
6643
- </xsl:choose>
6644
- </item>
6645
- <xsl:call-template name="split">
6646
- <xsl:with-param name="pText" select="substring-after($pText, $sep)"/>
6647
- <xsl:with-param name="sep" select="$sep"/>
6648
- <xsl:with-param name="normalize-space" select="$normalize-space"/>
6649
- </xsl:call-template>
6953
+ <item>
6954
+ <xsl:choose>
6955
+ <xsl:when test="$normalize-space = 'true'">
6956
+ <xsl:value-of select="normalize-space(substring-before(concat($pText, $sep), $sep))"/>
6957
+ </xsl:when>
6958
+ <xsl:otherwise>
6959
+ <xsl:value-of select="substring-before(concat($pText, $sep), $sep)"/>
6960
+ </xsl:otherwise>
6961
+ </xsl:choose>
6962
+ </item>
6963
+ <xsl:if test="$keep_sep = 'true' and contains($pText, $sep)"><item><xsl:value-of select="$sep"/></item></xsl:if>
6964
+ <xsl:call-template name="split">
6965
+ <xsl:with-param name="pText" select="substring-after($pText, $sep)"/>
6966
+ <xsl:with-param name="sep" select="$sep"/>
6967
+ <xsl:with-param name="normalize-space" select="$normalize-space"/>
6968
+ <xsl:with-param name="keep_sep" select="$keep_sep"/>
6969
+ </xsl:call-template>
6650
6970
  </xsl:if>
6651
6971
  </xsl:template><xsl:template name="getDocumentId">
6652
6972
  <xsl:call-template name="getLang"/><xsl:value-of select="//*[local-name() = 'p'][1]/@id"/>