metanorma-m3aawg 2.0.4 → 2.0.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -16,12 +16,15 @@
16
16
  <item level="1" id="Foreword" display="true">Foreword</item>
17
17
  <item id="term-script" display="false">3.2</item>
18
18
  -->
19
- <xsl:variable name="contents">
19
+ <xsl:variable name="contents_">
20
20
  <contents>
21
21
  <xsl:call-template name="processPrefaceSectionsDefault_Contents"/>
22
22
  <xsl:call-template name="processMainSectionsDefault_Contents"/>
23
+
24
+ <xsl:call-template name="processTablesFigures_Contents"/>
23
25
  </contents>
24
26
  </xsl:variable>
27
+ <xsl:variable name="contents" select="xalan:nodeset($contents_)"/>
25
28
 
26
29
  <xsl:template match="/">
27
30
  <xsl:call-template name="namespaceCheck"/>
@@ -200,7 +203,7 @@
200
203
  <xsl:if test="$debug = 'true'">
201
204
  <xsl:text disable-output-escaping="yes">&lt;!--</xsl:text>
202
205
  DEBUG
203
- contents=<xsl:copy-of select="xalan:nodeset($contents)"/>
206
+ contents=<xsl:copy-of select="$contents"/>
204
207
  <xsl:text disable-output-escaping="yes">--&gt;</xsl:text>
205
208
  </xsl:if>
206
209
 
@@ -213,7 +216,7 @@
213
216
  </xsl:variable>
214
217
  <fo:block font-size="12pt" font-weight="bold" text-decoration="underline" margin-bottom="4pt" role="H1"><xsl:value-of select="$title-toc"/></fo:block>
215
218
  <fo:block font-size="10pt" role="TOC">
216
- <xsl:for-each select="xalan:nodeset($contents)//item[@display = 'true']"><!-- [not(@level = 2 and starts-with(@section, '0'))] skip clause from preface -->
219
+ <xsl:for-each select="$contents//item[@display = 'true']"><!-- [not(@level = 2 and starts-with(@section, '0'))] skip clause from preface -->
217
220
  <xsl:choose>
218
221
  <xsl:when test="@section = ''">
219
222
  <fo:table table-layout="fixed" width="100%">
@@ -290,10 +293,30 @@
290
293
  </xsl:otherwise>
291
294
 
292
295
  </xsl:choose>
296
+
297
+ </xsl:for-each>
293
298
 
299
+ <!-- List of Tables -->
300
+ <xsl:if test="$contents//tables/table">
301
+ <xsl:call-template name="insertListOf_Title">
302
+ <xsl:with-param name="title" select="$title-list-tables"/>
303
+ </xsl:call-template>
304
+ <xsl:for-each select="$contents//tables/table">
305
+ <xsl:call-template name="insertListOf_Item"/>
306
+ </xsl:for-each>
307
+ </xsl:if>
294
308
 
309
+ <!-- List of Figures -->
310
+ <xsl:if test="$contents//figures/figure">
311
+ <xsl:call-template name="insertListOf_Title">
312
+ <xsl:with-param name="title" select="$title-list-figures"/>
313
+ </xsl:call-template>
314
+ <xsl:for-each select="$contents//figures/figure">
315
+ <xsl:call-template name="insertListOf_Item"/>
316
+ </xsl:for-each>
317
+ </xsl:if>
295
318
 
296
- </xsl:for-each>
319
+
297
320
  </fo:block>
298
321
  </fo:block-container>
299
322
 
@@ -318,6 +341,49 @@
318
341
  </fo:root>
319
342
  </xsl:template>
320
343
 
344
+ <xsl:template name="insertListOf_Title">
345
+ <xsl:param name="title"/>
346
+ <fo:table table-layout="fixed" width="100%">
347
+ <fo:table-column column-width="180mm"/>
348
+ <fo:table-body>
349
+ <fo:table-row height="6mm">
350
+ <fo:table-cell>
351
+ <fo:block role="TOCI" font-weight="bold">
352
+ <xsl:value-of select="$title"/>
353
+ </fo:block>
354
+ </fo:table-cell>
355
+ </fo:table-row>
356
+ </fo:table-body>
357
+ </fo:table>
358
+ </xsl:template>
359
+
360
+ <xsl:template name="insertListOf_Item">
361
+ <fo:table table-layout="fixed" width="100%">
362
+ <fo:table-column column-width="5mm"/>
363
+ <fo:table-column column-width="175mm"/>
364
+ <fo:table-body>
365
+ <fo:table-row height="6mm">
366
+ <fo:table-cell>
367
+ <fo:block> </fo:block>
368
+ </fo:table-cell>
369
+ <fo:table-cell>
370
+ <fo:block text-align-last="justify" role="TOCI" font-weight="bold">
371
+ <fo:basic-link internal-destination="{@id}">
372
+ <xsl:call-template name="setAltText">
373
+ <xsl:with-param name="value" select="@alt-text"/>
374
+ </xsl:call-template>
375
+ <xsl:apply-templates select="." mode="contents"/><xsl:text> </xsl:text>
376
+ <fo:inline keep-together.within-line="always">
377
+ <fo:leader font-weight="normal" leader-pattern="dots"/>
378
+ <fo:inline><fo:page-number-citation ref-id="{@id}"/></fo:inline>
379
+ </fo:inline>
380
+ </fo:basic-link>
381
+ </fo:block>
382
+ </fo:table-cell>
383
+ </fo:table-row>
384
+ </fo:table-body>
385
+ </fo:table>
386
+ </xsl:template>
321
387
 
322
388
  <xsl:template match="m3d:boilerplate//m3d:p" priority="2">
323
389
  <fo:block font-size="11pt" margin-bottom="12pt">
@@ -640,7 +706,7 @@
640
706
  <xsl:text>Contents</xsl:text>
641
707
 
642
708
  </title-toc>
643
-
709
+
644
710
  <title-descriptors lang="en">Descriptors</title-descriptors>
645
711
 
646
712
  <title-part lang="en">
@@ -676,7 +742,31 @@
676
742
  <title-continued lang="en">(continued)</title-continued>
677
743
  <title-continued lang="fr">(continué)</title-continued>
678
744
 
679
- </xsl:variable><xsl:variable name="titles" select="xalan:nodeset($titles_)"/><xsl:variable name="bibdata">
745
+ </xsl:variable><xsl:variable name="titles" select="xalan:nodeset($titles_)"/><xsl:variable name="title-list-tables">
746
+ <xsl:variable name="toc_table_title" select="//*[contains(local-name(), '-standard')]/*[local-name() = 'misc-container']/*[local-name() = 'toc'][@type='table']/*[local-name() = 'title']"/>
747
+ <xsl:value-of select="$toc_table_title"/>
748
+ <xsl:if test="normalize-space($toc_table_title) = ''">
749
+ <xsl:call-template name="getTitle">
750
+ <xsl:with-param name="name" select="'title-list-tables'"/>
751
+ </xsl:call-template>
752
+ </xsl:if>
753
+ </xsl:variable><xsl:variable name="title-list-figures">
754
+ <xsl:variable name="toc_figure_title" select="//*[contains(local-name(), '-standard')]/*[local-name() = 'misc-container']/*[local-name() = 'toc'][@type='figure']/*[local-name() = 'title']"/>
755
+ <xsl:value-of select="$toc_figure_title"/>
756
+ <xsl:if test="normalize-space($toc_figure_title) = ''">
757
+ <xsl:call-template name="getTitle">
758
+ <xsl:with-param name="name" select="'title-list-figures'"/>
759
+ </xsl:call-template>
760
+ </xsl:if>
761
+ </xsl:variable><xsl:variable name="title-list-recommendations">
762
+ <xsl:variable name="toc_requirement_title" select="//*[contains(local-name(), '-standard')]/*[local-name() = 'misc-container']/*[local-name() = 'toc'][@type='requirement']/*[local-name() = 'title']"/>
763
+ <xsl:value-of select="$toc_requirement_title"/>
764
+ <xsl:if test="normalize-space($toc_requirement_title) = ''">
765
+ <xsl:call-template name="getTitle">
766
+ <xsl:with-param name="name" select="'title-list-recommendations'"/>
767
+ </xsl:call-template>
768
+ </xsl:if>
769
+ </xsl:variable><xsl:variable name="bibdata">
680
770
  <xsl:copy-of select="//*[contains(local-name(), '-standard')]/*[local-name() = 'bibdata']"/>
681
771
  <xsl:copy-of select="//*[contains(local-name(), '-standard')]/*[local-name() = 'localized-strings']"/>
682
772
  </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">
@@ -1880,6 +1970,30 @@
1880
1970
  <xsl:sort select="@displayorder" data-type="number"/>
1881
1971
  <xsl:apply-templates select="." mode="contents"/>
1882
1972
  </xsl:for-each>
1973
+ </xsl:template><xsl:template name="processTablesFigures_Contents">
1974
+ <xsl:param name="always"/>
1975
+ <xsl:if test="(//*[contains(local-name(), '-standard')]/*[local-name() = 'misc-container']/*[local-name() = 'toc'][@type='table']/*[local-name() = 'title']) or normalize-space($always) = 'true'">
1976
+ <xsl:call-template name="processTables_Contents"/>
1977
+ </xsl:if>
1978
+ <xsl:if test="(//*[contains(local-name(), '-standard')]/*[local-name() = 'misc-container']/*[local-name() = 'toc'][@type='figure']/*[local-name() = 'title']) or normalize-space($always) = 'true'">
1979
+ <xsl:call-template name="processFigures_Contents"/>
1980
+ </xsl:if>
1981
+ </xsl:template><xsl:template name="processTables_Contents">
1982
+ <tables>
1983
+ <xsl:for-each select="//*[local-name() = 'table'][@id and *[local-name() = 'name'] and normalize-space(@id) != '']">
1984
+ <table id="{@id}" alt-text="{*[local-name() = 'name']}">
1985
+ <xsl:copy-of select="*[local-name() = 'name']"/>
1986
+ </table>
1987
+ </xsl:for-each>
1988
+ </tables>
1989
+ </xsl:template><xsl:template name="processFigures_Contents">
1990
+ <figures>
1991
+ <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) != '']">
1992
+ <figure id="{@id}" alt-text="{*[local-name() = 'name']}">
1993
+ <xsl:copy-of select="*[local-name() = 'name']"/>
1994
+ </figure>
1995
+ </xsl:for-each>
1996
+ </figures>
1883
1997
  </xsl:template><xsl:template name="processPrefaceSectionsDefault">
1884
1998
  <xsl:for-each select="/*/*[local-name()='preface']/*">
1885
1999
  <xsl:sort select="@displayorder" data-type="number"/>
@@ -1907,8 +2021,27 @@
1907
2021
  <xsl:sort select="@displayorder" data-type="number"/>
1908
2022
  <xsl:apply-templates select="."/>
1909
2023
  </xsl:for-each>
1910
- </xsl:template><xsl:template match="text()">
1911
- <xsl:value-of select="."/>
2024
+ </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">
2025
+ <xsl:variable name="regex_standard_reference">([A-Z]{2,}(/[A-Z]{2,})* \d+(-\d+)*(:\d{4})?)</xsl:variable>
2026
+ <xsl:variable name="text" select="java:replaceAll(java:java.lang.String.new(.),$regex_standard_reference,concat($tag_open,'$1',$tag_close))"/>
2027
+ <xsl:call-template name="replace_fo_inline">
2028
+ <xsl:with-param name="text" select="$text"/>
2029
+ </xsl:call-template>
2030
+ </xsl:template><xsl:template name="replace_fo_inline">
2031
+ <xsl:param name="text"/>
2032
+ <xsl:choose>
2033
+ <xsl:when test="contains($text, $tag_open)">
2034
+ <xsl:value-of select="substring-before($text, $tag_open)"/>
2035
+ <xsl:text disable-output-escaping="yes">&lt;fo:inline keep-together.within-line="always"&gt;</xsl:text>
2036
+ <xsl:variable name="text_after" select="substring-after($text, $tag_open)"/>
2037
+ <xsl:value-of select="substring-before($text_after, $tag_close)"/>
2038
+ <xsl:text disable-output-escaping="yes">&lt;/fo:inline&gt;</xsl:text>
2039
+ <xsl:call-template name="replace_fo_inline">
2040
+ <xsl:with-param name="text" select="substring-after($text_after, $tag_close)"/>
2041
+ </xsl:call-template>
2042
+ </xsl:when>
2043
+ <xsl:otherwise><xsl:value-of select="$text"/></xsl:otherwise>
2044
+ </xsl:choose>
1912
2045
  </xsl:template><xsl:template match="*[local-name()='br']">
1913
2046
  <xsl:value-of select="$linebreak"/>
1914
2047
  </xsl:template><xsl:template match="*[local-name()='copyright-statement']">
@@ -2664,37 +2797,7 @@
2664
2797
 
2665
2798
  <!-- list of footnotes to calculate actual footnotes number -->
2666
2799
  <xsl:variable name="p_fn_">
2667
- <xsl:choose>
2668
- <xsl:when test="@current_fn_number"> <!-- for BSI, footnote reference number calculated already -->
2669
- <fn gen_id="{generate-id(.)}">
2670
- <xsl:copy-of select="@*"/>
2671
- <xsl:copy-of select="node()"/>
2672
- </fn>
2673
- </xsl:when>
2674
- <xsl:otherwise>
2675
- <!-- itetation for:
2676
- footnotes in bibdata/title
2677
- footnotes in bibliography
2678
- footnotes in document's body (except table's head/body/foot and figure text)
2679
- -->
2680
- <xsl:for-each select="ancestor::*[contains(local-name(), '-standard')]/*[local-name() = 'bibdata']/*[local-name() = 'note'][@type='title-footnote']">
2681
- <fn gen_id="{generate-id(.)}">
2682
- <xsl:copy-of select="@*"/>
2683
- <xsl:copy-of select="node()"/>
2684
- </fn>
2685
- </xsl:for-each>
2686
- <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']/*">
2687
- <xsl:sort select="@displayorder" data-type="number"/>
2688
- <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])]">
2689
- <!-- copy unique fn -->
2690
- <fn gen_id="{generate-id(.)}">
2691
- <xsl:copy-of select="@*"/>
2692
- <xsl:copy-of select="node()"/>
2693
- </fn>
2694
- </xsl:for-each>
2695
- </xsl:for-each>
2696
- </xsl:otherwise>
2697
- </xsl:choose>
2800
+ <xsl:call-template name="get_fn_list"/>
2698
2801
  </xsl:variable>
2699
2802
  <xsl:variable name="p_fn" select="xalan:nodeset($p_fn_)"/>
2700
2803
 
@@ -2755,6 +2858,38 @@
2755
2858
  <xsl:copy-of select="$footnote_inline"/>
2756
2859
  </xsl:otherwise>
2757
2860
  </xsl:choose>
2861
+ </xsl:template><xsl:template name="get_fn_list">
2862
+ <xsl:choose>
2863
+ <xsl:when test="@current_fn_number"> <!-- for BSI, footnote reference number calculated already -->
2864
+ <fn gen_id="{generate-id(.)}">
2865
+ <xsl:copy-of select="@*"/>
2866
+ <xsl:copy-of select="node()"/>
2867
+ </fn>
2868
+ </xsl:when>
2869
+ <xsl:otherwise>
2870
+ <!-- itetation for:
2871
+ footnotes in bibdata/title
2872
+ footnotes in bibliography
2873
+ footnotes in document's body (except table's head/body/foot and figure text)
2874
+ -->
2875
+ <xsl:for-each select="ancestor::*[contains(local-name(), '-standard')]/*[local-name() = 'bibdata']/*[local-name() = 'note'][@type='title-footnote']">
2876
+ <fn gen_id="{generate-id(.)}">
2877
+ <xsl:copy-of select="@*"/>
2878
+ <xsl:copy-of select="node()"/>
2879
+ </fn>
2880
+ </xsl:for-each>
2881
+ <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']/*">
2882
+ <xsl:sort select="@displayorder" data-type="number"/>
2883
+ <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])]">
2884
+ <!-- copy unique fn -->
2885
+ <fn gen_id="{generate-id(.)}">
2886
+ <xsl:copy-of select="@*"/>
2887
+ <xsl:copy-of select="node()"/>
2888
+ </fn>
2889
+ </xsl:for-each>
2890
+ </xsl:for-each>
2891
+ </xsl:otherwise>
2892
+ </xsl:choose>
2758
2893
  </xsl:template><xsl:template name="table_fn_display">
2759
2894
  <xsl:variable name="references">
2760
2895
 
@@ -2926,7 +3061,7 @@
2926
3061
  </fo:inline>
2927
3062
  </xsl:template><xsl:template match="*[local-name()='fn']/text()[normalize-space() != '']">
2928
3063
  <fo:inline><xsl:value-of select="."/></fo:inline>
2929
- </xsl:template><xsl:template match="*[local-name()='fn']/*[local-name()='p']">
3064
+ </xsl:template><xsl:template match="*[local-name()='fn']//*[local-name()='p']">
2930
3065
  <fo:inline>
2931
3066
  <xsl:apply-templates/>
2932
3067
  </fo:inline>
@@ -4623,13 +4758,14 @@
4623
4758
  <xsl:apply-templates mode="bookmarks"/>
4624
4759
  </xsl:template><xsl:template name="addBookmarks">
4625
4760
  <xsl:param name="contents"/>
4626
- <xsl:if test="xalan:nodeset($contents)//item">
4761
+ <xsl:variable name="contents_nodes" select="xalan:nodeset($contents)"/>
4762
+ <xsl:if test="$contents_nodes//item">
4627
4763
  <fo:bookmark-tree>
4628
4764
  <xsl:choose>
4629
- <xsl:when test="xalan:nodeset($contents)/doc">
4765
+ <xsl:when test="$contents_nodes/doc">
4630
4766
  <xsl:choose>
4631
- <xsl:when test="count(xalan:nodeset($contents)/doc) &gt; 1">
4632
- <xsl:for-each select="xalan:nodeset($contents)/doc">
4767
+ <xsl:when test="count($contents_nodes/doc) &gt; 1">
4768
+ <xsl:for-each select="$contents_nodes/doc">
4633
4769
  <fo:bookmark internal-destination="{contents/item[1]/@id}" starting-state="hide">
4634
4770
  <xsl:if test="@bundle = 'true'">
4635
4771
  <xsl:attribute name="internal-destination"><xsl:value-of select="@firstpage_id"/></xsl:attribute>
@@ -4680,7 +4816,7 @@
4680
4816
  </xsl:for-each>
4681
4817
  </xsl:when>
4682
4818
  <xsl:otherwise>
4683
- <xsl:for-each select="xalan:nodeset($contents)/doc">
4819
+ <xsl:for-each select="$contents_nodes/doc">
4684
4820
 
4685
4821
  <xsl:apply-templates select="contents/item" mode="bookmark"/>
4686
4822
 
@@ -4698,25 +4834,36 @@
4698
4834
  </xsl:choose>
4699
4835
  </xsl:when>
4700
4836
  <xsl:otherwise>
4701
- <xsl:apply-templates select="xalan:nodeset($contents)/contents/item" mode="bookmark"/>
4837
+ <xsl:apply-templates select="$contents_nodes/contents/item" mode="bookmark"/>
4838
+
4839
+ <xsl:call-template name="insertFigureBookmarks">
4840
+ <xsl:with-param name="contents" select="$contents_nodes/contents"/>
4841
+ </xsl:call-template>
4842
+
4843
+ <xsl:call-template name="insertTableBookmarks">
4844
+ <xsl:with-param name="contents" select="$contents_nodes/contents"/>
4845
+ <xsl:with-param name="lang" select="@lang"/>
4846
+ </xsl:call-template>
4847
+
4702
4848
  </xsl:otherwise>
4703
4849
  </xsl:choose>
4704
4850
 
4851
+
4705
4852
 
4706
4853
 
4707
4854
 
4708
4855
 
4709
-
4710
-
4856
+
4711
4857
 
4712
4858
  </fo:bookmark-tree>
4713
4859
  </xsl:if>
4714
4860
  </xsl:template><xsl:template name="insertFigureBookmarks">
4715
4861
  <xsl:param name="contents"/>
4716
- <xsl:if test="xalan:nodeset($contents)/figure">
4717
- <fo:bookmark internal-destination="{xalan:nodeset($contents)/figure[1]/@id}" starting-state="hide">
4862
+ <xsl:variable name="contents_nodes" select="xalan:nodeset($contents)"/>
4863
+ <xsl:if test="$contents_nodes/figure">
4864
+ <fo:bookmark internal-destination="{$contents_nodes/figure[1]/@id}" starting-state="hide">
4718
4865
  <fo:bookmark-title>Figures</fo:bookmark-title>
4719
- <xsl:for-each select="xalan:nodeset($contents)/figure">
4866
+ <xsl:for-each select="$contents_nodes/figure">
4720
4867
  <fo:bookmark internal-destination="{@id}">
4721
4868
  <fo:bookmark-title>
4722
4869
  <xsl:value-of select="normalize-space(title)"/>
@@ -4725,18 +4872,40 @@
4725
4872
  </xsl:for-each>
4726
4873
  </fo:bookmark>
4727
4874
  </xsl:if>
4875
+
4876
+
4877
+ <xsl:if test="$contents_nodes//figures/figure">
4878
+ <fo:bookmark internal-destination="empty_bookmark" starting-state="hide">
4879
+
4880
+
4881
+
4882
+ <xsl:variable name="bookmark-title">
4883
+
4884
+ <xsl:value-of select="$title-list-figures"/>
4885
+
4886
+ </xsl:variable>
4887
+ <fo:bookmark-title><xsl:value-of select="normalize-space($bookmark-title)"/></fo:bookmark-title>
4888
+ <xsl:for-each select="$contents_nodes//figures/figure">
4889
+ <fo:bookmark internal-destination="{@id}">
4890
+ <fo:bookmark-title><xsl:value-of select="normalize-space(.)"/></fo:bookmark-title>
4891
+ </fo:bookmark>
4892
+ </xsl:for-each>
4893
+ </fo:bookmark>
4894
+ </xsl:if>
4895
+
4728
4896
  </xsl:template><xsl:template name="insertTableBookmarks">
4729
4897
  <xsl:param name="contents"/>
4730
4898
  <xsl:param name="lang"/>
4731
- <xsl:if test="xalan:nodeset($contents)/table">
4732
- <fo:bookmark internal-destination="{xalan:nodeset($contents)/table[1]/@id}" starting-state="hide">
4899
+ <xsl:variable name="contents_nodes" select="xalan:nodeset($contents)"/>
4900
+ <xsl:if test="$contents_nodes/table">
4901
+ <fo:bookmark internal-destination="{$contents_nodes/table[1]/@id}" starting-state="hide">
4733
4902
  <fo:bookmark-title>
4734
4903
  <xsl:choose>
4735
4904
  <xsl:when test="$lang = 'fr'">Tableaux</xsl:when>
4736
4905
  <xsl:otherwise>Tables</xsl:otherwise>
4737
4906
  </xsl:choose>
4738
4907
  </fo:bookmark-title>
4739
- <xsl:for-each select="xalan:nodeset($contents)/table">
4908
+ <xsl:for-each select="$contents_nodes/table">
4740
4909
  <fo:bookmark internal-destination="{@id}">
4741
4910
  <fo:bookmark-title>
4742
4911
  <xsl:value-of select="normalize-space(title)"/>
@@ -4745,6 +4914,29 @@
4745
4914
  </xsl:for-each>
4746
4915
  </fo:bookmark>
4747
4916
  </xsl:if>
4917
+
4918
+
4919
+ <xsl:if test="$contents_nodes//tables/table">
4920
+ <fo:bookmark internal-destination="empty_bookmark" starting-state="hide">
4921
+
4922
+
4923
+
4924
+ <xsl:variable name="bookmark-title">
4925
+
4926
+ <xsl:value-of select="$title-list-tables"/>
4927
+
4928
+ </xsl:variable>
4929
+
4930
+ <fo:bookmark-title><xsl:value-of select="$bookmark-title"/></fo:bookmark-title>
4931
+
4932
+ <xsl:for-each select="$contents_nodes//tables/table">
4933
+ <fo:bookmark internal-destination="{@id}">
4934
+ <fo:bookmark-title><xsl:value-of select="normalize-space(.)"/></fo:bookmark-title>
4935
+ </fo:bookmark>
4936
+ </xsl:for-each>
4937
+ </fo:bookmark>
4938
+ </xsl:if>
4939
+
4748
4940
  </xsl:template><xsl:template name="getLangVersion">
4749
4941
  <xsl:param name="lang"/>
4750
4942
  <xsl:param name="doctype" select="''"/>
@@ -4969,7 +5161,51 @@
4969
5161
  <xsl:with-param name="text" select="$text_step1"/>
4970
5162
  </xsl:call-template>
4971
5163
  </xsl:variable>
4972
- <xsl:value-of select="$text_step2"/>
5164
+
5165
+ <!-- <xsl:value-of select="$text_step2"/> -->
5166
+
5167
+ <!-- add zero-width space after space -->
5168
+ <xsl:variable name="text_step3" select="java:replaceAll(java:java.lang.String.new($text_step2),' ',' ​')"/>
5169
+
5170
+ <!-- split text by zero-width space -->
5171
+ <xsl:variable name="text_step4">
5172
+ <xsl:call-template name="split">
5173
+ <xsl:with-param name="pText" select="$text_step3"/>
5174
+ <xsl:with-param name="sep" select="$zero_width_space"/>
5175
+ <xsl:with-param name="normalize-space">false</xsl:with-param>
5176
+ <xsl:with-param name="keep_sep">true</xsl:with-param>
5177
+ </xsl:call-template>
5178
+ </xsl:variable>
5179
+
5180
+ <xsl:for-each select="xalan:nodeset($text_step4)/item">
5181
+ <xsl:choose>
5182
+ <xsl:when test="string-length() &gt; 30"> <!-- word with length more than 30 will be interspersed with zero-width space -->
5183
+ <xsl:call-template name="interspers">
5184
+ <xsl:with-param name="str" select="."/>
5185
+ </xsl:call-template>
5186
+ </xsl:when>
5187
+ <xsl:otherwise>
5188
+ <xsl:value-of select="."/>
5189
+ </xsl:otherwise>
5190
+ </xsl:choose>
5191
+ </xsl:for-each>
5192
+
5193
+ </xsl:template><xsl:template name="interspers">
5194
+ <xsl:param name="str"/>
5195
+ <xsl:param name="char" select="$zero_width_space"/>
5196
+ <xsl:if test="$str != ''">
5197
+ <xsl:value-of select="substring($str, 1, 1)"/>
5198
+
5199
+ <xsl:variable name="next_char" select="substring($str, 2, 1)"/>
5200
+ <xsl:if test="not(contains(concat(' -.:=_— ', $char), $next_char))">
5201
+ <xsl:value-of select="$char"/>
5202
+ </xsl:if>
5203
+
5204
+ <xsl:call-template name="interspers">
5205
+ <xsl:with-param name="str" select="substring($str, 2)"/>
5206
+ <xsl:with-param name="char" select="$char"/>
5207
+ </xsl:call-template>
5208
+ </xsl:if>
4973
5209
  </xsl:template><xsl:template match="*" mode="syntax_highlight">
4974
5210
  <xsl:apply-templates mode="syntax_highlight"/>
4975
5211
  </xsl:template><xsl:variable name="syntax_highlight_styles_">
@@ -5401,6 +5637,8 @@
5401
5637
  </xsl:otherwise>
5402
5638
  </xsl:choose> -->
5403
5639
  </fo:block>
5640
+ </xsl:template><xsl:template match="*[local-name() = 'termsource']/text()[starts-with(., '[SOURCE: Adapted from: ')]" priority="2">
5641
+ <xsl:text>[</xsl:text><xsl:value-of select="substring-after(., '[SOURCE: ')"/>
5404
5642
  </xsl:template><xsl:template match="*[local-name() = 'termsource']/text()">
5405
5643
  <xsl:if test="normalize-space() != ''">
5406
5644
  <xsl:value-of select="."/>
@@ -5435,7 +5673,8 @@
5435
5673
  <fo:inline><xsl:apply-templates/></fo:inline>
5436
5674
  </xsl:template><xsl:template match="*[local-name() = 'modification']/text()">
5437
5675
  <xsl:if test="normalize-space() != ''">
5438
- <xsl:value-of select="."/>
5676
+ <!-- <xsl:value-of select="."/> -->
5677
+ <xsl:call-template name="text"/>
5439
5678
  </xsl:if>
5440
5679
  </xsl:template><xsl:template match="*[local-name() = 'quote']">
5441
5680
  <fo:block-container margin-left="0mm">
@@ -5475,26 +5714,24 @@
5475
5714
  </xsl:template><xsl:template match="*[local-name() = 'author']">
5476
5715
  <xsl:text>— </xsl:text>
5477
5716
  <xsl:apply-templates/>
5478
- </xsl:template><xsl:variable name="bibitem_hidden_">
5717
+ </xsl:template><xsl:variable name="bibitems_">
5718
+ <xsl:for-each select="//*[local-name() = 'bibitem']">
5719
+ <xsl:copy-of select="."/>
5720
+ </xsl:for-each>
5721
+ </xsl:variable><xsl:variable name="bibitems" select="xalan:nodeset($bibitems_)"/><xsl:variable name="bibitems_hidden_">
5479
5722
  <xsl:for-each select="//*[local-name() = 'bibitem'][@hidden='true']">
5480
5723
  <xsl:copy-of select="."/>
5481
5724
  </xsl:for-each>
5482
- <xsl:for-each select="//*[local-name() = 'references'][@hidden='true']/*[local-name() = 'bibitem']">
5725
+ <xsl:for-each select="//*[local-name() = 'references'][@hidden='true']//*[local-name() = 'bibitem']">
5483
5726
  <xsl:copy-of select="."/>
5484
5727
  </xsl:for-each>
5485
- </xsl:variable><xsl:variable name="bibitem_hidden" select="xalan:nodeset($bibitem_hidden_)"/><xsl:template match="*[local-name() = 'eref']">
5486
-
5487
- <xsl:variable name="bibitemid">
5488
- <xsl:choose>
5489
- <!-- <xsl:when test="//*[local-name() = 'bibitem'][@hidden='true' and @id = current()/@bibitemid]"></xsl:when>
5490
- <xsl:when test="//*[local-name() = 'references'][@hidden='true']/*[local-name() = 'bibitem'][@id = current()/@bibitemid]"></xsl:when> -->
5491
- <xsl:when test="$bibitem_hidden/*[local-name() = 'bibitem'][@id = current()/@bibitemid]"/>
5492
- <xsl:otherwise><xsl:value-of select="@bibitemid"/></xsl:otherwise>
5493
- </xsl:choose>
5494
- </xsl:variable>
5495
-
5728
+ </xsl:variable><xsl:variable name="bibitems_hidden" select="xalan:nodeset($bibitems_hidden_)"/><xsl:template match="*[local-name() = 'eref']">
5729
+ <xsl:variable name="current_bibitemid" select="@bibitemid"/>
5730
+ <!-- <xsl:variable name="external-destination" select="normalize-space(key('bibitems', $current_bibitemid)/*[local-name() = 'uri'][@type = 'citation'])"/> -->
5731
+ <xsl:variable name="external-destination" select="normalize-space($bibitems/*[local-name() ='bibitem'][@id = $current_bibitemid]/*[local-name() = 'uri'][@type = 'citation'])"/>
5496
5732
  <xsl:choose>
5497
- <xsl:when test="normalize-space($bibitemid) != ''"> <!-- if in the bibliography there is the item with @bibitemid (and not hidden), then create link -->
5733
+ <!-- <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) -->
5734
+ <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) -->
5498
5735
  <fo:inline xsl:use-attribute-sets="eref-style">
5499
5736
  <xsl:if test="@type = 'footnote'">
5500
5737
  <xsl:attribute name="keep-together.within-line">always</xsl:attribute>
@@ -5510,8 +5747,8 @@
5510
5747
  <xsl:variable name="text" select="normalize-space()"/>
5511
5748
 
5512
5749
 
5513
-
5514
- <fo:basic-link internal-destination="{@bibitemid}" fox:alt-text="{@citeas}">
5750
+
5751
+ <fo:basic-link fox:alt-text="{@citeas}">
5515
5752
  <xsl:if test="normalize-space(@citeas) = ''">
5516
5753
  <xsl:attribute name="fox:alt-text"><xsl:value-of select="."/></xsl:attribute>
5517
5754
  </xsl:if>
@@ -5521,14 +5758,21 @@
5521
5758
 
5522
5759
  </xsl:if>
5523
5760
 
5524
-
5761
+ <xsl:choose>
5762
+ <xsl:when test="$external-destination != ''"> <!-- external hyperlink -->
5763
+ <xsl:attribute name="external-destination"><xsl:value-of select="$external-destination"/></xsl:attribute>
5764
+ </xsl:when>
5765
+ <xsl:otherwise>
5766
+ <xsl:attribute name="internal-destination"><xsl:value-of select="@bibitemid"/></xsl:attribute>
5767
+ </xsl:otherwise>
5768
+ </xsl:choose>
5525
5769
 
5526
5770
  <xsl:apply-templates/>
5527
5771
  </fo:basic-link>
5528
-
5772
+
5529
5773
  </fo:inline>
5530
5774
  </xsl:when>
5531
- <xsl:otherwise>
5775
+ <xsl:otherwise> <!-- if there is key('bibitems_hidden', $current_bibitemid) -->
5532
5776
  <fo:inline><xsl:apply-templates/></fo:inline>
5533
5777
  </xsl:otherwise>
5534
5778
  </xsl:choose>
@@ -6270,23 +6514,45 @@
6270
6514
  <xsl:apply-templates/>
6271
6515
  </fo:inline>
6272
6516
  </xsl:template><xsl:template match="*[local-name() = 'bibitem']/*[local-name() = 'note']" priority="2">
6517
+
6518
+ <!-- list of footnotes to calculate actual footnotes number -->
6519
+ <xsl:variable name="p_fn_">
6520
+ <xsl:call-template name="get_fn_list"/>
6521
+ </xsl:variable>
6522
+ <xsl:variable name="p_fn" select="xalan:nodeset($p_fn_)"/>
6523
+ <xsl:variable name="gen_id" select="generate-id(.)"/>
6524
+ <xsl:variable name="lang" select="ancestor::*[contains(local-name(), '-standard')]/*[local-name()='bibdata']//*[local-name()='language'][@current = 'true']"/>
6525
+ <!-- fn sequence number in document -->
6526
+ <xsl:variable name="current_fn_number">
6527
+ <xsl:choose>
6528
+ <xsl:when test="@current_fn_number"><xsl:value-of select="@current_fn_number"/></xsl:when> <!-- for BSI -->
6529
+ <xsl:otherwise>
6530
+ <!-- <xsl:value-of select="count($p_fn//fn[@reference = $reference]/preceding-sibling::fn) + 1" /> -->
6531
+ <xsl:value-of select="count($p_fn//fn[@gen_id = $gen_id]/preceding-sibling::fn) + 1"/>
6532
+ </xsl:otherwise>
6533
+ </xsl:choose>
6534
+ </xsl:variable>
6273
6535
  <fo:footnote>
6274
6536
  <xsl:variable name="number">
6275
6537
 
6276
- <xsl:number level="any" count="*[local-name() = 'bibitem']/*[local-name() = 'note']"/>
6538
+ <xsl:value-of select="$current_fn_number"/>
6277
6539
 
6278
6540
  </xsl:variable>
6541
+
6542
+ <xsl:variable name="current_fn_number_text">
6543
+ <xsl:value-of select="$number"/>
6544
+
6545
+ </xsl:variable>
6546
+
6279
6547
  <fo:inline xsl:use-attribute-sets="bibitem-note-fn-style">
6280
- <fo:basic-link internal-destination="{generate-id()}" fox:alt-text="footnote {$number}">
6281
- <xsl:value-of select="$number"/>
6282
-
6548
+ <fo:basic-link internal-destination="{$gen_id}" fox:alt-text="footnote {$number}">
6549
+ <xsl:value-of select="$current_fn_number_text"/>
6283
6550
  </fo:basic-link>
6284
6551
  </fo:inline>
6285
6552
  <fo:footnote-body>
6286
6553
  <fo:block xsl:use-attribute-sets="bibitem-note-fn-body-style">
6287
- <fo:inline id="{generate-id()}" xsl:use-attribute-sets="bibitem-note-fn-number-style">
6288
- <xsl:value-of select="$number"/>
6289
-
6554
+ <fo:inline id="{$gen_id}" xsl:use-attribute-sets="bibitem-note-fn-number-style">
6555
+ <xsl:value-of select="$current_fn_number_text"/>
6290
6556
  </fo:inline>
6291
6557
  <xsl:apply-templates/>
6292
6558
  </fo:block>
@@ -6527,6 +6793,78 @@
6527
6793
  <!-- processing for admonition/p found in the template for 'p' -->
6528
6794
  <xsl:call-template name="paragraph"/>
6529
6795
 
6796
+ </xsl:template><xsl:template match="@*|node()" mode="update_xml_step1">
6797
+ <xsl:copy>
6798
+ <xsl:apply-templates select="@*|node()" mode="update_xml_step1"/>
6799
+ </xsl:copy>
6800
+ </xsl:template><xsl:template match="*[local-name() = 'preface']" mode="update_xml_step1">
6801
+ <xsl:copy>
6802
+ <xsl:copy-of select="@*"/>
6803
+
6804
+ <xsl:variable name="nodes_preface_">
6805
+ <xsl:for-each select="*">
6806
+ <node id="{@id}"/>
6807
+ </xsl:for-each>
6808
+ </xsl:variable>
6809
+ <xsl:variable name="nodes_preface" select="xalan:nodeset($nodes_preface_)"/>
6810
+
6811
+ <xsl:for-each select="*">
6812
+ <xsl:sort select="@displayorder" data-type="number"/>
6813
+
6814
+ <!-- process Section's title -->
6815
+ <xsl:variable name="preceding-sibling_id" select="$nodes_preface/node[@id = current()/@id]/preceding-sibling::node[1]/@id"/>
6816
+ <xsl:if test="$preceding-sibling_id != ''">
6817
+ <xsl:apply-templates select="parent::*/*[@type = 'section-title' and @id = $preceding-sibling_id and not(@displayorder)]" mode="update_xml_step1"/>
6818
+ </xsl:if>
6819
+
6820
+ <xsl:choose>
6821
+ <xsl:when test="@type = 'section-title' and not(@displayorder)"><!-- skip, don't copy, because copied in above 'apply-templates' --></xsl:when>
6822
+ <xsl:otherwise>
6823
+ <xsl:apply-templates select="." mode="update_xml_step1"/>
6824
+ </xsl:otherwise>
6825
+ </xsl:choose>
6826
+
6827
+ </xsl:for-each>
6828
+ </xsl:copy>
6829
+ </xsl:template><xsl:template match="*[local-name() = 'sections']" mode="update_xml_step1">
6830
+ <xsl:copy>
6831
+ <xsl:copy-of select="@*"/>
6832
+
6833
+ <xsl:variable name="nodes_sections_">
6834
+ <xsl:for-each select="*">
6835
+ <node id="{@id}"/>
6836
+ </xsl:for-each>
6837
+ </xsl:variable>
6838
+ <xsl:variable name="nodes_sections" select="xalan:nodeset($nodes_sections_)"/>
6839
+
6840
+ <!-- move section 'Normative references' inside 'sections' -->
6841
+ <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']]">
6842
+ <xsl:sort select="@displayorder" data-type="number"/>
6843
+
6844
+ <!-- process Section's title -->
6845
+ <xsl:variable name="preceding-sibling_id" select="$nodes_sections/node[@id = current()/@id]/preceding-sibling::node[1]/@id"/>
6846
+ <xsl:if test="$preceding-sibling_id != ''">
6847
+ <xsl:apply-templates select="parent::*/*[@type = 'section-title' and @id = $preceding-sibling_id and not(@displayorder)]" mode="update_xml_step1"/>
6848
+ </xsl:if>
6849
+
6850
+ <xsl:choose>
6851
+ <xsl:when test="@type = 'section-title' and not(@displayorder)"><!-- skip, don't copy, because copied in above 'apply-templates' --></xsl:when>
6852
+ <xsl:otherwise>
6853
+ <xsl:apply-templates select="." mode="update_xml_step1"/>
6854
+ </xsl:otherwise>
6855
+ </xsl:choose>
6856
+
6857
+ </xsl:for-each>
6858
+ </xsl:copy>
6859
+ </xsl:template><xsl:template match="*[local-name() = 'bibliography']" mode="update_xml_step1">
6860
+ <xsl:copy>
6861
+ <xsl:copy-of select="@*"/>
6862
+ <!-- copy all elements from bibliography except 'Normative references' (moved to 'sections') -->
6863
+ <xsl:for-each select="*[not(@normative='true') and not(*[@normative='true'])]">
6864
+ <xsl:sort select="@displayorder" data-type="number"/>
6865
+ <xsl:apply-templates select="." mode="update_xml_step1"/>
6866
+ </xsl:for-each>
6867
+ </xsl:copy>
6530
6868
  </xsl:template><xsl:template name="convertDate">
6531
6869
  <xsl:param name="date"/>
6532
6870
  <xsl:param name="format" select="'short'"/>
@@ -6771,22 +7109,25 @@
6771
7109
  <xsl:param name="pText" select="."/>
6772
7110
  <xsl:param name="sep" select="','"/>
6773
7111
  <xsl:param name="normalize-space" select="'true'"/>
7112
+ <xsl:param name="keep_sep" select="'false'"/>
6774
7113
  <xsl:if test="string-length($pText) &gt;0">
6775
- <item>
6776
- <xsl:choose>
6777
- <xsl:when test="$normalize-space = 'true'">
6778
- <xsl:value-of select="normalize-space(substring-before(concat($pText, $sep), $sep))"/>
6779
- </xsl:when>
6780
- <xsl:otherwise>
6781
- <xsl:value-of select="substring-before(concat($pText, $sep), $sep)"/>
6782
- </xsl:otherwise>
6783
- </xsl:choose>
6784
- </item>
6785
- <xsl:call-template name="split">
6786
- <xsl:with-param name="pText" select="substring-after($pText, $sep)"/>
6787
- <xsl:with-param name="sep" select="$sep"/>
6788
- <xsl:with-param name="normalize-space" select="$normalize-space"/>
6789
- </xsl:call-template>
7114
+ <item>
7115
+ <xsl:choose>
7116
+ <xsl:when test="$normalize-space = 'true'">
7117
+ <xsl:value-of select="normalize-space(substring-before(concat($pText, $sep), $sep))"/>
7118
+ </xsl:when>
7119
+ <xsl:otherwise>
7120
+ <xsl:value-of select="substring-before(concat($pText, $sep), $sep)"/>
7121
+ </xsl:otherwise>
7122
+ </xsl:choose>
7123
+ </item>
7124
+ <xsl:if test="$keep_sep = 'true' and contains($pText, $sep)"><item><xsl:value-of select="$sep"/></item></xsl:if>
7125
+ <xsl:call-template name="split">
7126
+ <xsl:with-param name="pText" select="substring-after($pText, $sep)"/>
7127
+ <xsl:with-param name="sep" select="$sep"/>
7128
+ <xsl:with-param name="normalize-space" select="$normalize-space"/>
7129
+ <xsl:with-param name="keep_sep" select="$keep_sep"/>
7130
+ </xsl:call-template>
6790
7131
  </xsl:if>
6791
7132
  </xsl:template><xsl:template name="getDocumentId">
6792
7133
  <xsl:call-template name="getLang"/><xsl:value-of select="//*[local-name() = 'p'][1]/@id"/>