metanorma-bipm 2.6.3 → 2.6.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2617,6 +2617,7 @@
2617
2617
  </xsl:template> <!-- refine_table-style -->
2618
2618
 
2619
2619
  <xsl:attribute-set name="table-name-style">
2620
+ <xsl:attribute name="role">Caption</xsl:attribute>
2620
2621
  <xsl:attribute name="keep-with-next">always</xsl:attribute>
2621
2622
 
2622
2623
  <xsl:attribute name="font-size">11pt</xsl:attribute>
@@ -2628,6 +2629,9 @@
2628
2629
 
2629
2630
  <xsl:template name="refine_table-name-style">
2630
2631
  <xsl:param name="continued"/>
2632
+ <xsl:if test="$continued = 'true'">
2633
+ <xsl:attribute name="role">SKIP</xsl:attribute>
2634
+ </xsl:if>
2631
2635
 
2632
2636
  </xsl:template> <!-- refine_table-name-style -->
2633
2637
 
@@ -4430,7 +4434,7 @@
4430
4434
  </xsl:if>
4431
4435
 
4432
4436
  </fo:block-container>
4433
- </xsl:variable>
4437
+ </xsl:variable> <!-- END: variable name="table" -->
4434
4438
 
4435
4439
  <xsl:variable name="isAdded" select="@added"/>
4436
4440
  <xsl:variable name="isDeleted" select="@deleted"/>
@@ -4440,14 +4444,14 @@
4440
4444
 
4441
4445
  <!-- centered table when table name is centered (see table-name-style) -->
4442
4446
 
4443
- <fo:table table-layout="fixed" width="100%" xsl:use-attribute-sets="table-container-style">
4447
+ <fo:table table-layout="fixed" width="100%" xsl:use-attribute-sets="table-container-style" role="SKIP">
4444
4448
 
4445
4449
  <fo:table-column column-width="proportional-column-width(1)"/>
4446
4450
  <fo:table-column column-width="{@width}"/>
4447
4451
  <fo:table-column column-width="proportional-column-width(1)"/>
4448
- <fo:table-body>
4449
- <fo:table-row>
4450
- <fo:table-cell column-number="2">
4452
+ <fo:table-body role="SKIP">
4453
+ <fo:table-row role="SKIP">
4454
+ <fo:table-cell column-number="2" role="SKIP">
4451
4455
  <xsl:copy-of select="$table-preamble"/>
4452
4456
  <fo:block role="SKIP">
4453
4457
  <xsl:call-template name="setTrackChangesStyles">
@@ -4488,11 +4492,12 @@
4488
4492
 
4489
4493
  </xsl:template>
4490
4494
 
4495
+ <!-- table/name-->
4491
4496
  <xsl:template match="*[local-name()='table']/*[local-name() = 'name']">
4492
4497
  <xsl:param name="continued"/>
4493
4498
  <xsl:if test="normalize-space() != ''">
4494
4499
 
4495
- <fo:block xsl:use-attribute-sets="table-name-style" role="SKIP">
4500
+ <fo:block xsl:use-attribute-sets="table-name-style">
4496
4501
 
4497
4502
  <xsl:call-template name="refine_table-name-style">
4498
4503
  <xsl:with-param name="continued" select="$continued"/>
@@ -4984,7 +4989,7 @@
4984
4989
 
4985
4990
  <xsl:variable name="tableWithNotesAndFootnotes">
4986
4991
 
4987
- <fo:table keep-with-previous="always">
4992
+ <fo:table keep-with-previous="always" role="SKIP">
4988
4993
  <xsl:for-each select="xalan:nodeset($table_attributes)/table_attributes/@*">
4989
4994
  <xsl:variable name="name" select="local-name()"/>
4990
4995
  <xsl:choose>
@@ -5015,9 +5020,9 @@
5015
5020
  </xsl:otherwise>
5016
5021
  </xsl:choose>
5017
5022
 
5018
- <fo:table-body>
5019
- <fo:table-row>
5020
- <fo:table-cell xsl:use-attribute-sets="table-footer-cell-style" number-columns-spanned="{$cols-count}">
5023
+ <fo:table-body role="SKIP">
5024
+ <fo:table-row role="SKIP">
5025
+ <fo:table-cell xsl:use-attribute-sets="table-footer-cell-style" number-columns-spanned="{$cols-count}" role="SKIP">
5021
5026
 
5022
5027
  <xsl:call-template name="refine_table-footer-cell-style"/>
5023
5028
 
@@ -5090,7 +5095,7 @@
5090
5095
 
5091
5096
  <!-- if there isn't 'thead' and there is a table's title -->
5092
5097
  <xsl:if test="not(ancestor::*[local-name()='table']/*[local-name()='thead']) and ancestor::*[local-name()='table']/*[local-name()='name']">
5093
- <fo:table-header>
5098
+ <fo:table-header role="Caption">
5094
5099
  <xsl:call-template name="table-header-title">
5095
5100
  <xsl:with-param name="cols-count" select="$cols-count"/>
5096
5101
  </xsl:call-template>
@@ -5456,6 +5461,7 @@
5456
5461
  <!-- footnotes in text (title, bibliography, main body), not for tables, figures and names --> <!-- table's, figure's names -->
5457
5462
  <!-- fn in text -->
5458
5463
  <xsl:template match="*[local-name() = 'fn'][not(ancestor::*[(local-name() = 'table' or local-name() = 'figure')] and not(ancestor::*[local-name() = 'name']))]" priority="2" name="fn">
5464
+ <xsl:param name="footnote_body_from_table">false</xsl:param>
5459
5465
 
5460
5466
  <!-- list of unique footnotes -->
5461
5467
  <xsl:variable name="p_fn_">
@@ -5521,7 +5527,7 @@
5521
5527
  <xsl:copy-of select="$footnote_inline"/>
5522
5528
  </xsl:when>
5523
5529
  <!-- <xsl:when test="$footnotes//*[local-name() = 'fmt-fn-body'][@id = $ref_id] or normalize-space(@skip_footnote_body) = 'false'"> -->
5524
- <xsl:when test="$p_fn//fn[@gen_id = $gen_id] or normalize-space(@skip_footnote_body) = 'false'">
5530
+ <xsl:when test="$p_fn//fn[@gen_id = $gen_id] or normalize-space(@skip_footnote_body) = 'false' or $footnote_body_from_table = 'true'">
5525
5531
 
5526
5532
  <fo:footnote xsl:use-attribute-sets="fn-style" role="SKIP">
5527
5533
  <xsl:copy-of select="$footnote_inline"/>
@@ -5930,39 +5936,51 @@
5930
5936
  <!-- fn reference in the table rendering (for instance, 'some text 1) some text' ) -->
5931
5937
  <!-- fn --> <!-- in table --> <!-- for figure see <xsl:template match="*[local-name() = 'figure']/*[local-name() = 'fn']" priority="2"/> -->
5932
5938
  <xsl:template match="*[local-name()='fn']">
5933
- <fo:inline xsl:use-attribute-sets="fn-reference-style">
5934
-
5935
- <xsl:call-template name="refine_fn-reference-style"/>
5939
+ <xsl:variable name="target" select="@target"/>
5940
+ <xsl:choose>
5941
+ <!-- case for footnotes in Requirement tables (https://github.com/metanorma/metanorma-ogc/issues/791) -->
5942
+ <xsl:when test="not(ancestor::*[local-name() = 'table'][1]/*[local-name() = 'fmt-footnote-container']/*[local-name() = 'fmt-fn-body'][@id = $target]) and $footnotes/*[local-name() = 'fmt-fn-body'][@id = $target]">
5943
+ <xsl:call-template name="fn">
5944
+ <xsl:with-param name="footnote_body_from_table">true</xsl:with-param>
5945
+ </xsl:call-template>
5946
+ </xsl:when>
5947
+ <xsl:otherwise>
5936
5948
 
5937
- <!-- <fo:basic-link internal-destination="{@reference}_{ancestor::*[@id][1]/@id}" fox:alt-text="footnote {@reference}"> --> <!-- @reference | ancestor::*[local-name()='clause'][1]/@id-->
5938
- <fo:basic-link internal-destination="{@target}" fox:alt-text="footnote {@reference}">
5939
- <!-- <xsl:if test="ancestor::*[local-name()='table'][1]/@id"> --> <!-- for footnotes in tables -->
5940
- <!-- <xsl:attribute name="internal-destination">
5941
- <xsl:value-of select="concat(@reference, '_', ancestor::*[local-name()='table'][1]/@id)"/>
5942
- </xsl:attribute>
5943
- </xsl:if>
5944
- <xsl:if test="$namespace = 'ogc' or $namespace = 'ogc-white-paper'">
5945
- <xsl:attribute name="internal-destination">
5946
- <xsl:value-of select="@reference"/><xsl:text>_</xsl:text>
5947
- <xsl:value-of select="ancestor::*[local-name()='table'][1]/@id"/>
5948
- </xsl:attribute>
5949
- </xsl:if> -->
5950
- <!-- <xsl:if test="$namespace = 'plateau'">
5951
- <xsl:text>※</xsl:text>
5952
- </xsl:if> -->
5953
- <!-- <xsl:value-of select="@reference"/> -->
5949
+ <fo:inline xsl:use-attribute-sets="fn-reference-style">
5954
5950
 
5955
- <xsl:value-of select="normalize-space(*[local-name() = 'fmt-fn-label'])"/>
5951
+ <xsl:call-template name="refine_fn-reference-style"/>
5956
5952
 
5957
- <!-- <xsl:if test="$namespace = 'bsi'">
5958
- <xsl:text>)</xsl:text>
5959
- </xsl:if> -->
5960
- <!-- commented, https://github.com/metanorma/isodoc/issues/614 -->
5961
- <!-- <xsl:if test="$namespace = 'jis'">
5962
- <fo:inline font-weight="normal">)</fo:inline>
5963
- </xsl:if> -->
5964
- </fo:basic-link>
5965
- </fo:inline>
5953
+ <!-- <fo:basic-link internal-destination="{@reference}_{ancestor::*[@id][1]/@id}" fox:alt-text="footnote {@reference}"> --> <!-- @reference | ancestor::*[local-name()='clause'][1]/@id-->
5954
+ <fo:basic-link internal-destination="{@target}" fox:alt-text="footnote {@reference}">
5955
+ <!-- <xsl:if test="ancestor::*[local-name()='table'][1]/@id"> --> <!-- for footnotes in tables -->
5956
+ <!-- <xsl:attribute name="internal-destination">
5957
+ <xsl:value-of select="concat(@reference, '_', ancestor::*[local-name()='table'][1]/@id)"/>
5958
+ </xsl:attribute>
5959
+ </xsl:if>
5960
+ <xsl:if test="$namespace = 'ogc' or $namespace = 'ogc-white-paper'">
5961
+ <xsl:attribute name="internal-destination">
5962
+ <xsl:value-of select="@reference"/><xsl:text>_</xsl:text>
5963
+ <xsl:value-of select="ancestor::*[local-name()='table'][1]/@id"/>
5964
+ </xsl:attribute>
5965
+ </xsl:if> -->
5966
+ <!-- <xsl:if test="$namespace = 'plateau'">
5967
+ <xsl:text>※</xsl:text>
5968
+ </xsl:if> -->
5969
+ <!-- <xsl:value-of select="@reference"/> -->
5970
+
5971
+ <xsl:value-of select="normalize-space(*[local-name() = 'fmt-fn-label'])"/>
5972
+
5973
+ <!-- <xsl:if test="$namespace = 'bsi'">
5974
+ <xsl:text>)</xsl:text>
5975
+ </xsl:if> -->
5976
+ <!-- commented, https://github.com/metanorma/isodoc/issues/614 -->
5977
+ <!-- <xsl:if test="$namespace = 'jis'">
5978
+ <fo:inline font-weight="normal">)</fo:inline>
5979
+ </xsl:if> -->
5980
+ </fo:basic-link>
5981
+ </fo:inline>
5982
+ </xsl:otherwise>
5983
+ </xsl:choose>
5966
5984
  </xsl:template> <!-- fn -->
5967
5985
 
5968
5986
  <!-- fn/text() -->
@@ -9980,6 +9998,13 @@
9980
9998
  <xsl:apply-templates select="."/>
9981
9999
  </xsl:template>
9982
10000
 
10001
+ <!-- prevent missing stem for table and figures in ToC -->
10002
+ <xsl:template match="*[local-name() = 'name' or local-name() = 'fmt-name']//*[local-name() = 'stem']" mode="contents">
10003
+ <xsl:if test="not(following-sibling::*[1][local-name() = 'fmt-stem'])">
10004
+ <xsl:apply-templates select="."/>
10005
+ </xsl:if>
10006
+ </xsl:template>
10007
+
9983
10008
  <xsl:template match="*[local-name() = 'references'][@hidden='true']" mode="contents" priority="3"/>
9984
10009
 
9985
10010
  <xsl:template match="*[local-name() = 'references']/*[local-name() = 'bibitem']" mode="contents"/>
@@ -10203,7 +10228,8 @@
10203
10228
 
10204
10229
  <xsl:for-each select="$contents_nodes//tables/table">
10205
10230
  <fo:bookmark internal-destination="{@id}">
10206
- <fo:bookmark-title><xsl:value-of select="normalize-space(.)"/></fo:bookmark-title>
10231
+ <!-- <fo:bookmark-title><xsl:value-of select="normalize-space(.)"/></fo:bookmark-title> -->
10232
+ <fo:bookmark-title><xsl:apply-templates mode="bookmark_clean"/></fo:bookmark-title>
10207
10233
  </fo:bookmark>
10208
10234
  </xsl:for-each>
10209
10235
  </fo:bookmark>
@@ -10212,6 +10238,26 @@
10212
10238
  </xsl:template> <!-- insertTableBookmarks -->
10213
10239
  <!-- End Bookmarks -->
10214
10240
 
10241
+ <!-- ============================ -->
10242
+ <!-- mode="bookmark_clean" -->
10243
+ <!-- ============================ -->
10244
+ <xsl:template match="node()" mode="bookmark_clean">
10245
+ <xsl:apply-templates select="node()" mode="bookmark_clean"/>
10246
+ </xsl:template>
10247
+
10248
+ <xsl:template match="text()" mode="bookmark_clean">
10249
+ <xsl:value-of select="."/>
10250
+ </xsl:template>
10251
+
10252
+ <xsl:template match="*[local-name() = 'math']" mode="bookmark_clean">
10253
+ <xsl:value-of select="normalize-space(.)"/>
10254
+ </xsl:template>
10255
+
10256
+ <xsl:template match="*[local-name() = 'asciimath']" mode="bookmark_clean"/>
10257
+ <!-- ============================ -->
10258
+ <!-- END: mode="bookmark_clean" -->
10259
+ <!-- ============================ -->
10260
+
10215
10261
  <xsl:template name="getLangVersion">
10216
10262
  <xsl:param name="lang"/>
10217
10263
  <xsl:param name="doctype" select="''"/>
@@ -12228,9 +12274,15 @@
12228
12274
  <xsl:when test="local-name(..) = 'ul'">
12229
12275
  <xsl:choose>
12230
12276
  <xsl:when test="normalize-space($processing_instruction_type) = 'simple'"/>
12277
+ <!-- https://github.com/metanorma/isodoc/issues/675 -->
12278
+ <xsl:when test="@label"><xsl:value-of select="@label"/></xsl:when>
12231
12279
  <xsl:otherwise><xsl:call-template name="setULLabel"/></xsl:otherwise>
12232
12280
  </xsl:choose>
12233
12281
  </xsl:when>
12282
+ <!-- https://github.com/metanorma/isodoc/issues/675 -->
12283
+ <xsl:when test="local-name(..) = 'ol' and @label and @full = 'true'"> <!-- @full added in the template li/fmt-name -->
12284
+ <xsl:value-of select="@label"/>
12285
+ </xsl:when>
12234
12286
  <xsl:when test="local-name(..) = 'ol' and @label"> <!-- for ordered lists 'ol', and if there is @label, for instance label="1.1.2" -->
12235
12287
 
12236
12288
  <xsl:variable name="type" select="../@type"/>
@@ -12355,7 +12407,7 @@
12355
12407
 
12356
12408
  </xsl:otherwise>
12357
12409
  </xsl:choose>
12358
- </xsl:template>
12410
+ </xsl:template> <!-- getListItemFormat -->
12359
12411
 
12360
12412
  <xsl:template match="*[local-name() = 'ul'] | *[local-name() = 'ol']">
12361
12413
  <xsl:param name="indent">0</xsl:param>
@@ -12487,6 +12539,11 @@
12487
12539
 
12488
12540
  <xsl:call-template name="refine_list-item-label-style"/>
12489
12541
 
12542
+ <xsl:if test="local-name(..) = 'ul'">
12543
+ <xsl:variable name="li_label" select="@label"/>
12544
+ <xsl:copy-of select="$ul_labels//label[. = $li_label]/@*[not(local-name() = 'level')]"/>
12545
+ </xsl:if>
12546
+
12490
12547
  <!-- if 'p' contains all text in 'add' first and last elements in first p are 'add' -->
12491
12548
  <xsl:if test="*[1][count(node()[normalize-space() != '']) = 1 and *[local-name() = 'add']]">
12492
12549
  <xsl:call-template name="append_add-style"/>
@@ -13893,6 +13950,16 @@
13893
13950
  </xsl:choose>
13894
13951
  </xsl:template>
13895
13952
 
13953
+ <!-- li/fmt-name -->
13954
+ <xsl:template match="*[local-name() = 'li']/*[local-name() = 'fmt-name']" priority="2" mode="update_xml_step1">
13955
+ <xsl:attribute name="label"><xsl:value-of select="."/></xsl:attribute>
13956
+ <xsl:attribute name="full">true</xsl:attribute>
13957
+ </xsl:template>
13958
+ <xsl:template match="*[local-name() = 'li']/*[local-name() = 'fmt-name']" priority="2" mode="update_xml_pres">
13959
+ <xsl:attribute name="label"><xsl:value-of select="."/></xsl:attribute>
13960
+ <xsl:attribute name="full">true</xsl:attribute>
13961
+ </xsl:template>
13962
+
13896
13963
  <xsl:template match="*[local-name() = 'fmt-preferred']"/>
13897
13964
  <xsl:template match="*[local-name() = 'fmt-preferred'][*[local-name() = 'p']]" mode="update_xml_step1">
13898
13965
  <xsl:apply-templates mode="update_xml_step1"/>
@@ -14707,6 +14774,64 @@
14707
14774
  <fo:inline xml:lang="none"><xsl:value-of select="."/></fo:inline>
14708
14775
  </xsl:template>
14709
14776
 
14777
+ <!-- ===================================== -->
14778
+ <!-- ===================================== -->
14779
+ <!-- Ruby text (CJK languages) rendering -->
14780
+ <!-- ===================================== -->
14781
+ <!-- ===================================== -->
14782
+ <xsl:template match="*[local-name() = 'ruby']">
14783
+ <fo:inline-container text-indent="0mm" last-line-end-indent="0mm">
14784
+ <xsl:if test="not(ancestor::*[local-name() = 'ruby'])">
14785
+ <xsl:attribute name="alignment-baseline">central</xsl:attribute>
14786
+ </xsl:if>
14787
+ <xsl:variable name="rt_text" select="*[local-name() = 'rt']"/>
14788
+ <xsl:variable name="rb_text" select=".//*[local-name() = 'rb'][not(*[local-name() = 'ruby'])]"/>
14789
+ <!-- Example: width="2em" -->
14790
+ <xsl:variable name="text_rt_width" select="java:org.metanorma.fop.Util.getStringWidthByFontSize($rt_text, $font_main, 6)"/>
14791
+ <xsl:variable name="text_rb_width" select="java:org.metanorma.fop.Util.getStringWidthByFontSize($rb_text, $font_main, 10)"/>
14792
+ <xsl:variable name="text_width">
14793
+ <xsl:choose>
14794
+ <xsl:when test="$text_rt_width &gt;= $text_rb_width"><xsl:value-of select="$text_rt_width"/></xsl:when>
14795
+ <xsl:otherwise><xsl:value-of select="$text_rb_width"/></xsl:otherwise>
14796
+ </xsl:choose>
14797
+ </xsl:variable>
14798
+ <xsl:attribute name="width"><xsl:value-of select="$text_width div 10"/>em</xsl:attribute>
14799
+
14800
+ <xsl:choose>
14801
+ <xsl:when test="ancestor::*[local-name() = 'ruby']">
14802
+ <xsl:apply-templates select="*[local-name() = 'rb']"/>
14803
+ <xsl:apply-templates select="*[local-name() = 'rt']"/>
14804
+ </xsl:when>
14805
+ <xsl:otherwise>
14806
+ <xsl:apply-templates select="*[local-name() = 'rt']"/>
14807
+ <xsl:apply-templates select="*[local-name() = 'rb']"/>
14808
+ </xsl:otherwise>
14809
+ </xsl:choose>
14810
+
14811
+ <xsl:apply-templates select="node()[not(local-name() = 'rt') and not(local-name() = 'rb')]"/>
14812
+ </fo:inline-container>
14813
+ </xsl:template>
14814
+
14815
+ <xsl:template match="*[local-name() = 'rb']">
14816
+ <fo:block line-height="1em" text-align="center"><xsl:apply-templates/></fo:block>
14817
+ </xsl:template>
14818
+
14819
+ <xsl:template match="*[local-name() = 'rt']">
14820
+ <fo:block font-size="0.5em" text-align="center" line-height="1.2em" space-before="-1.4em" space-before.conditionality="retain"> <!-- -->
14821
+ <xsl:if test="ancestor::*[local-name() = 'ruby'][last()]//*[local-name() = 'ruby'] or ancestor::*[local-name() = 'rb']">
14822
+ <xsl:attribute name="space-before">0em</xsl:attribute>
14823
+ </xsl:if>
14824
+ <xsl:apply-templates/>
14825
+ </fo:block>
14826
+
14827
+ </xsl:template>
14828
+
14829
+ <!-- ===================================== -->
14830
+ <!-- ===================================== -->
14831
+ <!-- END: Ruby text (CJK languages) rendering -->
14832
+ <!-- ===================================== -->
14833
+ <!-- ===================================== -->
14834
+
14710
14835
  <xsl:template name="printEdition">
14711
14836
  <xsl:variable name="edition_i18n" select="normalize-space((//*[local-name() = 'metanorma'])[1]/*[local-name() = 'bibdata']/*[local-name() = 'edition'][normalize-space(@language) != ''])"/>
14712
14837
  <xsl:text> </xsl:text>
@@ -6,15 +6,6 @@ module IsoDoc
6
6
  @iso.middle_title(docxml)
7
7
  end
8
8
 
9
- # KILL
10
- def table1x(elem)
11
- table_fn(elem)
12
- labelled_ancestor(elem) || elem["unnumbered"] and return
13
- n = @xrefs.anchor(elem["id"], :label, false)
14
- prefix_name(elem, ".<tab/>",
15
- l10n("#{@i18n.table.capitalize} #{n}"), "name")
16
- end
17
-
18
9
  def table_delim
19
10
  l10n("x.<tab/>").sub("x", "") # force French " .</tab>"
20
11
  end
@@ -46,6 +37,46 @@ module IsoDoc
46
37
  else @i18n.prefacenote
47
38
  end
48
39
  end
40
+
41
+ def termsource_label(elem, sources)
42
+ elem.replace(l10n("[#{termsource_adapt(elem['status'])} #{sources}]"))
43
+ end
44
+
45
+ def termsource_adapt(status)
46
+ case status
47
+ when "adapted" then @i18n.adapted_from
48
+ when "modified" then @i18n.modified_from
49
+ else ""
50
+ end
51
+ end
52
+
53
+ def termsource(docxml)
54
+ termsource_insert_empty_modification(docxml)
55
+ super
56
+ end
57
+
58
+ def termsource_insert_empty_modification(docxml)
59
+ docxml.xpath("//xmlns:termsource[@status = 'modified']" \
60
+ "[not(xmlns:modification)]").each do |f|
61
+ f << "<modification/>"
62
+ end
63
+ end
64
+
65
+ def termsource_modification(elem)
66
+ termsource_add_modification_text(elem.at(ns("./modification")))
67
+ end
68
+
69
+ def ul_label_list(_elem)
70
+ %w(&#x2022; &#x2212; &#x6f;)
71
+ end
72
+
73
+ def ol_label_template(_elem)
74
+ super
75
+ .merge({
76
+ roman: %{<span class="fmt-label-delim">(</span>%<span class="fmt-label-delim">)</span>},
77
+ arabic: %{%<span class="fmt-label-delim">.</span>},
78
+ })
79
+ end
49
80
  end
50
81
  end
51
82
  end
@@ -0,0 +1,112 @@
1
+ module IsoDoc
2
+ module Bipm
3
+ class PresentationXMLConvert < IsoDoc::Generic::PresentationXMLConvert
4
+ def fn_label_brackets(fnote)
5
+ "<sup><span class='fmt-label-delim'>(</span>" \
6
+ "#{fn_label(fnote)}" \
7
+ "<span class='fmt-label-delim'>)</span></sup>"
8
+ end
9
+
10
+ def fn_ref_label(fnote)
11
+ if @jcgm then iso_fn_ref_label(fnote)
12
+ else fn_label_brackets(fnote)
13
+ end
14
+ end
15
+
16
+ # copied from ISO
17
+ def iso_fn_ref_label(fnote)
18
+ if fnote.ancestors("table, figure").empty? ||
19
+ !fnote.ancestors("name, fmt-name").empty?
20
+ "<sup>#{fn_label(fnote)}" \
21
+ "<span class='fmt-label-delim'>)</span></sup>"
22
+ else
23
+ "<sup>#{fn_label(fnote)}</sup>"
24
+ end
25
+ end
26
+
27
+ def fn_body_label(fnote)
28
+ if @jcgm then super
29
+ else fn_label_brackets(fnote)
30
+ end
31
+ end
32
+
33
+ # explode out all the subclauses into separate entries
34
+ # assume no hanging clauses
35
+ def sort_footnote_sections(docxml)
36
+ ret = super
37
+ ret.flat_map do |x|
38
+ explode_subclauses(x)
39
+ end
40
+ end
41
+
42
+ def explode_subclauses(clause)
43
+ clause.at(ns(".//clause")) or return [clause]
44
+ (clause.xpath(ns(".//clause")) - clause.xpath(ns(".//clause//clause")))
45
+ .map { |x| explode_subclauses(x) }
46
+ .flatten.unshift(clause)
47
+ end
48
+
49
+ # quote/table/fn references are not unique within quote
50
+ # if there are multiple tables
51
+ def renumber_document_footnote_key(fnote)
52
+ key = fnote["reference"]
53
+ !@jcgm && (t = fnote.at("./ancestor::xmlns:table")) and
54
+ key = "#{t['id']} #{key}"
55
+ key
56
+ end
57
+
58
+ def renumber_document_footnote(fnote, idx, seen)
59
+ fnote["original-reference"] = fnote["reference"]
60
+ key = renumber_document_footnote_key(fnote)
61
+ if seen[key]
62
+ fnote["reference"] = seen[fnote["reference"]]
63
+ else
64
+ seen[key] = idx
65
+ fnote["reference"] = idx
66
+ idx += 1
67
+ end
68
+ idx
69
+ end
70
+
71
+ def document_footnotes(docxml)
72
+ @jcgm and return super
73
+ sects = sort_footnote_sections(docxml)
74
+ excl = non_document_footnotes(docxml)
75
+ fns = filter_document_footnotes(sects, excl)
76
+ sects.each_with_index do |s, i|
77
+ ret = footnote_collect(renumber_document_footnotes(fns[i], 1))
78
+ f = footnote_container(fns[i], ret) and s << f
79
+ end
80
+ end
81
+
82
+ def filter_document_footnotes(sects, excl)
83
+ sects.each_with_object([]) do |s, m|
84
+ docfns = s.xpath(ns(".//fn")) - excl - s.xpath(ns(".//clause//fn"))
85
+ m << docfns
86
+ end
87
+ end
88
+
89
+ def renumber_document_footnotes(fns, idx)
90
+ @jcgm and return super
91
+ fns.each_with_object({}) do |f, seen|
92
+ idx = renumber_document_footnote(f, idx, seen)
93
+ end
94
+ fns
95
+ end
96
+
97
+ def table_fn(elem)
98
+ !@jcgm && !elem.ancestors("quote").empty? and return
99
+ super
100
+ end
101
+
102
+ def non_document_footnotes(docxml)
103
+ table_fns = docxml.xpath(ns("//table//fn")) -
104
+ docxml.xpath(ns("//table/name//fn"))
105
+ @jcgm or table_fns -= docxml.xpath(ns("//quote//table//fn"))
106
+ fig_fns = docxml.xpath(ns("//figure//fn")) -
107
+ docxml.xpath(ns("//figure/name//fn"))
108
+ table_fns + fig_fns
109
+ end
110
+ end
111
+ end
112
+ end
@@ -6,6 +6,7 @@ require_relative "doccontrol"
6
6
  require_relative "../../relaton/render/general"
7
7
  require_relative "presentation_blocks"
8
8
  require_relative "presentation_biblio"
9
+ require_relative "presentation_footnotes"
9
10
 
10
11
  module IsoDoc
11
12
  module Bipm
@@ -139,34 +140,6 @@ module IsoDoc
139
140
  end
140
141
  end
141
142
 
142
- def termsource_label(elem, sources)
143
- elem.replace(l10n("[#{termsource_adapt(elem['status'])} #{sources}]"))
144
- end
145
-
146
- def termsource_adapt(status)
147
- case status
148
- when "adapted" then @i18n.adapted_from
149
- when "modified" then @i18n.modified_from
150
- else ""
151
- end
152
- end
153
-
154
- def termsource(docxml)
155
- termsource_insert_empty_modification(docxml)
156
- super
157
- end
158
-
159
- def termsource_insert_empty_modification(docxml)
160
- docxml.xpath("//xmlns:termsource[@status = 'modified']" \
161
- "[not(xmlns:modification)]").each do |f|
162
- f << "<modification/>"
163
- end
164
- end
165
-
166
- def termsource_modification(elem)
167
- termsource_add_modification_text(elem.at(ns("./modification")))
168
- end
169
-
170
143
  def enable_indexsect
171
144
  true
172
145
  end
@@ -185,101 +158,6 @@ module IsoDoc
185
158
  @xrefs.bookmark_anchor_names(docxml)
186
159
  end
187
160
 
188
- def fn_label_brackets(fnote)
189
- "<sup><span class='fmt-label-delim'>(</span>" \
190
- "#{fn_label(fnote)}" \
191
- "<span class='fmt-label-delim'>)</span></sup>"
192
- end
193
-
194
- def fn_ref_label(fnote)
195
- if @jcgm then iso_fn_ref_label(fnote)
196
- else fn_label_brackets(fnote)
197
- end
198
- end
199
-
200
- # copied from ISO
201
- def iso_fn_ref_label(fnote)
202
- if fnote.ancestors("table, figure").empty? ||
203
- !fnote.ancestors("name, fmt-name").empty?
204
- "<sup>#{fn_label(fnote)}" \
205
- "<span class='fmt-label-delim'>)</span></sup>"
206
- else
207
- "<sup>#{fn_label(fnote)}</sup>"
208
- end
209
- end
210
-
211
- def fn_body_label(fnote)
212
- if @jcgm then super
213
- else fn_label_brackets(fnote)
214
- end
215
- end
216
-
217
- # explode out all the subclauses into separate entries
218
- # assume no hanging clauses
219
- def sort_footnote_sections(docxml)
220
- ret = super
221
- ret.flat_map do |x|
222
- clauses = x.xpath(ns(".//clause[not(./clause)]"))
223
- clauses.empty? ? [x] : clauses.to_a
224
- end
225
- end
226
-
227
- # quote/table/fn references are not unique within quote
228
- # if there are multiple tables
229
- def renumber_document_footnote_key(fnote)
230
- key = fnote["reference"]
231
- !@jcgm && (t = fnote.at("./ancestor::xmlns:table")) and
232
- key = "#{t['id']} #{key}"
233
- key
234
- end
235
-
236
- def renumber_document_footnote(fnote, idx, seen)
237
- fnote["original-reference"] = fnote["reference"]
238
- key = renumber_document_footnote_key(fnote)
239
- if seen[key]
240
- fnote["reference"] = seen[fnote["reference"]]
241
- else
242
- seen[key] = idx
243
- fnote["reference"] = idx
244
- idx += 1
245
- end
246
- idx
247
- end
248
-
249
- def document_footnotes(docxml)
250
- @jcgm and return super
251
- sects = sort_footnote_sections(docxml)
252
- excl = non_document_footnotes(docxml)
253
- fns = filter_document_footnotes(sects, excl)
254
- #sects.select { |s| s.at(ns(".//fn")) }.each_with_index do |s, i|
255
- sects.each_with_index do |s, i|
256
- ret = footnote_collect(renumber_document_footnotes(fns[i], 1))
257
- f = footnote_container(fns[i], ret) and s << f
258
- end
259
- end
260
-
261
- def renumber_document_footnotes(fns, idx)
262
- @jcgm and return super
263
- fns.each_with_object({}) do |f, seen|
264
- idx = renumber_document_footnote(f, idx, seen)
265
- end
266
- fns
267
- end
268
-
269
- def table_fn(elem)
270
- !@jcgm && !elem.ancestors("quote").empty? and return
271
- super
272
- end
273
-
274
- def non_document_footnotes(docxml)
275
- table_fns = docxml.xpath(ns("//table//fn")) -
276
- docxml.xpath(ns("//table/name//fn"))
277
- @jcgm or table_fns -= docxml.xpath(ns("//quote//table//fn"))
278
- fig_fns = docxml.xpath(ns("//figure//fn")) -
279
- docxml.xpath(ns("//figure/name//fn"))
280
- table_fns + fig_fns
281
- end
282
-
283
161
  include Init
284
162
  end
285
163
  end