metanorma-iso 2.7.4 → 2.7.6

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.
@@ -79,6 +79,10 @@ module IsoDoc
79
79
  node["inline-header"] = "true"
80
80
  end
81
81
  super
82
+ if node["type"] == "section"
83
+ t = node.at(ns("./title/tab")) and
84
+ t.previous = @i18n.l10n(": ").sub(/\p{Zs}$/, "")
85
+ end
82
86
  end
83
87
 
84
88
  def clause(docxml)
@@ -208,6 +212,11 @@ module IsoDoc
208
212
  end
209
213
  end
210
214
 
215
+ def twitter_cldr_localiser_symbols
216
+ { group: " ", fraction_group: " ",
217
+ fraction_group_digits: 3 }
218
+ end
219
+
211
220
  include Init
212
221
  end
213
222
  end
@@ -105,22 +105,6 @@ module IsoDoc
105
105
  locality_span_wrap(ret, opt[:type])
106
106
  end
107
107
 
108
- =begin
109
- def prefix_container(container, linkend, node, target)
110
- delim = ", "
111
- ref = if @xrefs.anchor(target, :type) == "listitem" &&
112
- !@xrefs.anchor(target, :refer_list)
113
- delim = " "
114
- @xrefs.anchor(container, :label)
115
- # 7 a) : Clause 7 a), but Clause 7 List 1 a)
116
- else anchor_xref(node, container)
117
- end
118
-
119
- ref and linkend = ref + delim + linkend
120
- l10n(linkend)
121
- end
122
- =end
123
-
124
108
  # 7 a) : Clause 7 a), but Clause 7 List 1 a)
125
109
  def prefix_container(container, linkend, node, target)
126
110
  prefix_container?(container, node) or return linkend
@@ -135,10 +119,11 @@ module IsoDoc
135
119
  def prefix_container_template(container, node, target)
136
120
  nested_xref = @i18n.nested_xref
137
121
  container_label = anchor_xref(node, container)
138
- if @xrefs.anchor(target, :type) == "listitem" &&
139
- !@xrefs.anchor(target, :refer_list)
122
+ if @xrefs.anchor(target, :type) == "listitem"
123
+ if !@xrefs.anchor(target, :refer_list)
140
124
  nested_xref = "%1 %2"
141
- n = @xrefs.anchor(container, :label) and container_label = n
125
+ # n = @xrefs.anchor(container, :label) and container_label = n
126
+ end
142
127
  end
143
128
  [nested_xref, container_label]
144
129
  end
@@ -52,18 +52,22 @@ module IsoDoc
52
52
 
53
53
  def convert(input_filename, file = nil, debug = false,
54
54
  output_filename = nil)
55
- file = File.read(input_filename, encoding: "utf-8") if file.nil?
56
- docxml = Nokogiri::XML(file) { |config| config.huge }
57
- stage = docxml&.at(ns("//bibdata/status/stage"))&.text
58
- if @dis &&
59
- ((/^[4569].$/.match?(stage) && @wordtemplate != "simple") ||
60
- (/^[0-3].$/.match?(stage) && @wordtemplate == "dis"))
55
+ if @dis && use_dis?(input_filename, file)
56
+ swap_renderer(self, @dis, file, input_filename, debug)
61
57
  @dis.convert(input_filename, file, debug, output_filename)
62
58
  else
63
59
  super
64
60
  end
65
61
  end
66
62
 
63
+ def use_dis?(input_filename, file)
64
+ file ||= File.read(input_filename, encoding: "utf-8")
65
+ stage = Nokogiri::XML(file, &:huge)
66
+ .at(ns("//bibdata/status/stage"))&.text
67
+ (/^[4569].$/.match?(stage) && @wordtemplate != "simple") ||
68
+ (/^[0-3].$/.match?(stage) && @wordtemplate == "dis")
69
+ end
70
+
67
71
  def make_body(xml, docxml)
68
72
  body_attr = { lang: "EN-US", link: "blue", vlink: "#954F72" }
69
73
  xml.body **body_attr do |body|
@@ -18,7 +18,7 @@ module IsoDoc
18
18
  end
19
19
 
20
20
  def word_section_end_empty_para(docxml)
21
- docxml.at("//div[@class='WordSection1']/p[last()]").remove
21
+ docxml.at("//div[@class='WordSection1']/p[last()]")&.remove
22
22
  end
23
23
 
24
24
  def word_table_cell_para(docxml)
@@ -61,8 +61,6 @@ module IsoDoc
61
61
  end
62
62
 
63
63
  def toWord(result, filename, dir, header)
64
- result = from_xhtml(word_cleanup(to_xhtml(result)))
65
- .gsub("-DOUBLE_HYPHEN_ESCAPE-", "--")
66
64
  @wordstylesheet = wordstylesheet_update
67
65
  ::Html2Doc::IsoDIS.new(
68
66
  filename: filename,
@@ -12,12 +12,12 @@ module IsoDoc
12
12
  if @klass.amd?(docxml)
13
13
  [{ path: "//sections/clause", multi: true }]
14
14
  else
15
- [{ path: "//clause[@type = 'scope']" },
15
+ [{ path: "//sections/clause[@type = 'scope']" },
16
16
  { path: @klass.norm_ref_xpath },
17
17
  { path:
18
18
  "#{@klass.middle_clause(docxml)} | //sections/terms | " \
19
- "//sections/clause[descendant::terms or descendant::definitions] " \
20
- "| //sections/definitions", multi: true }]
19
+ "//sections/clause[descendant::terms or descendant::definitions] | " \
20
+ "//sections/definitions | //sections/clause[@type = 'section']", multi: true }]
21
21
  end
22
22
  end
23
23
 
@@ -46,9 +46,7 @@ module IsoDoc
46
46
 
47
47
  def hierarchical_formula_names(clause, num)
48
48
  c = IsoDoc::XrefGen::Counter.new
49
- clause.xpath(ns(".//formula")).each do |t|
50
- next if blank?(t["id"])
51
-
49
+ clause.xpath(ns(".//formula")).noblank.each do |t|
52
50
  @anchors[t["id"]] = anchor_struct(
53
51
  "#{num}#{hiersep}#{c.increment(t).print}", t,
54
52
  t["inequality"] ? @labels["inequality"] : @labels["formula"],
@@ -130,7 +128,7 @@ module IsoDoc
130
128
  notes = s.xpath(ns(".//ol")) - s.xpath(ns(".//clause//ol")) -
131
129
  s.xpath(ns(".//appendix//ol")) - s.xpath(ns(".//ol//ol"))
132
130
  c = Counter.new
133
- notes.reject { |n| blank?(n["id"]) }.each do |n|
131
+ notes.noblank.each do |n|
134
132
  @anchors[n["id"]] = anchor_struct(increment_label(notes, n, c), n,
135
133
  @labels["list"], "list", false)
136
134
  list_item_anchor_names(n, @anchors[n["id"]], 1, "",
@@ -142,12 +140,10 @@ module IsoDoc
142
140
 
143
141
  # all li in the ol in lists are consecutively numbered through @start
144
142
  def single_ol_for_xrefs?(lists)
145
- return true if lists.size == 1
146
-
143
+ lists.size == 1 and return true
147
144
  start = 0
148
145
  lists.each_with_index do |l, i|
149
- next if i.zero?
150
-
146
+ i.zero? and next
151
147
  start += lists[i - 1].xpath(ns("./li")).size
152
148
  return false unless l["start"]&.to_i == start + 1
153
149
  end
@@ -47,9 +47,30 @@ module IsoDoc
47
47
  end
48
48
  end
49
49
 
50
+ def section_name_anchors(clause, num, level)
51
+ if clause["type"] == "section"
52
+ @anchors[clause["id"]] =
53
+ { label: l10n("#{@labels['section']} #{num}"),
54
+ xref: l10n("#{@labels['section']} #{num}"),
55
+ title: clause_title(clause), level: level, type: "clause",
56
+ elem: @labels["section"] }
57
+ else super
58
+ end
59
+ end
60
+
61
+ def annex_name_anchors1(clause, num, level)
62
+ ret = { label: num, level: level, subtype: "annex" }
63
+ ret2 = if level == 2
64
+ { xref: l10n("#{@labels['clause']} #{num}"),
65
+ elem: @labels["clause"] }
66
+ else
67
+ { xref: num }
68
+ end
69
+ @anchors[clause["id"]] = ret.merge(ret2)
70
+ end
71
+
50
72
  def annex_names1(clause, num, level)
51
- @anchors[clause["id"]] = { label: num, xref: num, level: level,
52
- subtype: "annex" }
73
+ annex_name_anchors1(clause, num, level)
53
74
  i = Counter.new(0, prefix: "#{num}.")
54
75
  clause.xpath(ns("./clause | ./references")).each do |c|
55
76
  annex_names1(c, i.increment(c).print, level + 1)
@@ -79,8 +79,16 @@ module Metanorma
79
79
  name
80
80
  end
81
81
 
82
+ DOCUMENT_SCHEMES = [1951, 1972, 1979, 1987, 1989, 2012, 2013, 2024].freeze
83
+
82
84
  def document_scheme(node)
83
- node.attr("document-scheme") || "2024"
85
+ r = node.attr("document-scheme") and return r
86
+ r = node.attr("copyright-year")&.to_i or return "2024"
87
+ DOCUMENT_SCHEMES.each_index do |i|
88
+ i.zero? and next
89
+ r < DOCUMENT_SCHEMES[i] and return DOCUMENT_SCHEMES[i - 1].to_s
90
+ end
91
+ "2024"
84
92
  end
85
93
 
86
94
  def outputs(node, ret)
@@ -208,7 +208,9 @@
208
208
  </define>
209
209
  <define name="roledescription">
210
210
  <element name="description">
211
- <ref name="FormattedString"/>
211
+ <oneOrMore>
212
+ <ref name="TextElement"/>
213
+ </oneOrMore>
212
214
  </element>
213
215
  </define>
214
216
  <define name="person">
@@ -333,7 +335,9 @@
333
335
  </define>
334
336
  <define name="affiliationdescription">
335
337
  <element name="description">
336
- <ref name="FormattedString"/>
338
+ <oneOrMore>
339
+ <ref name="TextElement"/>
340
+ </oneOrMore>
337
341
  </element>
338
342
  </define>
339
343
  <define name="organization">
@@ -897,7 +901,9 @@
897
901
  </define>
898
902
  <define name="formattedref">
899
903
  <element name="formattedref">
900
- <ref name="FormattedString"/>
904
+ <oneOrMore>
905
+ <ref name="TextElement"/>
906
+ </oneOrMore>
901
907
  </element>
902
908
  </define>
903
909
  <define name="license">
@@ -942,7 +948,9 @@
942
948
  <optional>
943
949
  <attribute name="type"/>
944
950
  </optional>
945
- <ref name="FormattedString"/>
951
+ <zeroOrMore>
952
+ <ref name="TextElement"/>
953
+ </zeroOrMore>
946
954
  </define>
947
955
  <!-- TitleType = ( "alternative" | "original" | "unofficial" | "subtitle" | "main" ) -->
948
956
  <define name="TypedUri">
@@ -1042,7 +1050,9 @@
1042
1050
  <optional>
1043
1051
  <attribute name="script"/>
1044
1052
  </optional>
1045
- <text/>
1053
+ <oneOrMore>
1054
+ <ref name="TextElement"/>
1055
+ </oneOrMore>
1046
1056
  </element>
1047
1057
  </define>
1048
1058
  <define name="docnumber">
@@ -1267,12 +1277,16 @@
1267
1277
  <optional>
1268
1278
  <attribute name="type"/>
1269
1279
  </optional>
1270
- <ref name="FormattedString"/>
1280
+ <oneOrMore>
1281
+ <ref name="TextElement"/>
1282
+ </oneOrMore>
1271
1283
  </element>
1272
1284
  </define>
1273
1285
  <define name="bibabstract">
1274
1286
  <element name="abstract">
1275
- <ref name="FormattedString"/>
1287
+ <oneOrMore>
1288
+ <ref name="TextElement"/>
1289
+ </oneOrMore>
1276
1290
  </element>
1277
1291
  </define>
1278
1292
  <define name="copyright">
@@ -1377,7 +1391,9 @@
1377
1391
  </attribute>
1378
1392
  <optional>
1379
1393
  <element name="description">
1380
- <ref name="FormattedString"/>
1394
+ <oneOrMore>
1395
+ <ref name="TextElement"/>
1396
+ </oneOrMore>
1381
1397
  </element>
1382
1398
  </optional>
1383
1399
  <element name="bibitem">
@@ -73,7 +73,7 @@ CP 401 &#x2022; Ch. de Blandonnet 8 +
73
73
  CH-1214 Vernier, Geneva +
74
74
  Tél: +41 22 749 01 11 +
75
75
  Email: copyright@iso.org +
76
- Website: www.iso.org
76
+ Website: {% if document_scheme == "2024" %}https://www.iso.org/[www.iso.org]{% else %}www.iso.org{% endif %}
77
77
 
78
78
  [[boilerplate-place]]
79
79
  Publié en Suisse
@@ -49,7 +49,7 @@ CP 401 &#x2022; Ch. de Blandonnet 8 +
49
49
  CH-1214 Vernier, Geneva +
50
50
  Тел: +41 22 749 01 11 +
51
51
  Электронная почта: copyright@iso.org +
52
- Сайт: www.iso.org
52
+ Сайт: {% if document_scheme == "2024" %}https://www.iso.org/[www.iso.org]{% else %}www.iso.org{% endif %}
53
53
 
54
54
  [[boilerplate-place]]
55
55
  Издано в Швейцарии
@@ -73,7 +73,7 @@ CP 401 &#x2022; Ch. de Blandonnet 8 +
73
73
  CH-1214 Vernier, Geneva +
74
74
  Phone: +41 22 749 01 11 +
75
75
  Email: copyright@iso.org +
76
- Website: www.iso.org
76
+ Website: {% if document_scheme == "2024" %}https://www.iso.org/[www.iso.org]{% else %}www.iso.org{% endif %}
77
77
 
78
78
  [[boilerplate-place]]
79
79
  Published in Switzerland
@@ -1,3 +1,5 @@
1
+ require_relative "cleanup_biblio"
2
+
1
3
  module Metanorma
2
4
  module ISO
3
5
  class Converter < Standoc::Converter
@@ -24,80 +26,20 @@ module Metanorma
24
26
  end
25
27
  end
26
28
 
27
- def id_prefix(prefix, id)
28
- # we're just inheriting the prefixes from parent doc
29
- @amd and return id.text
30
- prefix.join("/") + (id.text.match?(%{^/}) ? "" : " ") + id.text
31
- end
32
-
33
- def get_id_prefix(xmldoc)
34
- xmldoc.xpath("//bibdata/contributor[role/@type = 'publisher']" \
35
- "/organization").each_with_object([]) do |x, prefix|
36
- x1 = x.at("abbreviation")&.text || x.at("name")&.text
37
- prefix << x1
29
+ def ol_cleanup(doc)
30
+ doc.xpath("//ol[@explicit-type]").each do |x|
31
+ x["type"] = x["explicit-type"]
32
+ x.delete("explicit-type")
33
+ @log.add("Style", x,
34
+ "Style override set for ordered list")
38
35
  end
39
36
  end
40
37
 
41
- # ISO as a prefix goes first
42
- def docidentifier_cleanup(xmldoc)
43
- prefix = get_id_prefix(xmldoc)
44
- id = xmldoc.at("//bibdata/ext/structuredidentifier/project-number") and
45
- id.content = id_prefix(prefix, id)
46
- end
47
-
48
- def format_ref(ref, type)
49
- ref = ref.sub(/ \(All Parts\)/i, "")
50
- super
51
- end
52
-
53
38
  TERM_CLAUSE =
54
39
  "//sections//terms | " \
55
40
  "//sections//clause[descendant::terms][not(descendant::definitions)]"
56
41
  .freeze
57
42
 
58
- PUBLISHER = "./contributor[role/@type = 'publisher']/organization".freeze
59
-
60
- def pub_class(bib)
61
- return 1 if bib.at("#{PUBLISHER}[abbreviation = 'ISO']")
62
- return 1 if bib.at("#{PUBLISHER}[name = 'International Organization " \
63
- "for Standardization']")
64
- return 2 if bib.at("#{PUBLISHER}[abbreviation = 'IEC']")
65
- return 2 if bib.at("#{PUBLISHER}[name = 'International " \
66
- "Electrotechnical Commission']")
67
- return 3 if bib.at("./docidentifier[@type]" \
68
- "[not(#{skip_docid} or @type = 'metanorma')]") ||
69
- bib.at("./docidentifier[not(@type)]")
70
-
71
- 4
72
- end
73
-
74
- def sort_biblio(bib)
75
- bib.sort { |a, b| sort_biblio_key(a) <=> sort_biblio_key(b) }
76
- end
77
-
78
- # sort by: doc class (ISO, IEC, other standard (not DOI &c), other
79
- # then standard class (docid class other than DOI &c)
80
- # then docnumber if present, numeric sort
81
- # else alphanumeric metanorma id (abbreviation)
82
- # then doc part number if present, numeric sort
83
- # then doc id (not DOI &c)
84
- # then title
85
- def sort_biblio_key(bib)
86
- pubclass = pub_class(bib)
87
- num = bib.at("./docnumber")&.text
88
- id = bib.at("./docidentifier[@primary]") ||
89
- bib.at("./docidentifier[not(#{skip_docid} or @type = 'metanorma')]")
90
- metaid = bib.at("./docidentifier[@type = 'metanorma']")&.text
91
- abbrid = metaid unless /^\[\d+\]$/.match?(metaid)
92
- /\d-(?<partid>\d+)/ =~ id&.text
93
- type = id["type"] if id
94
- title = bib.at("./title[@type = 'main']")&.text ||
95
- bib.at("./title")&.text || bib&.at("./formattedref")&.text
96
- "#{pubclass} :: #{type} :: " \
97
- "#{num.nil? ? abbrid : sprintf('%09d', num.to_i)} :: " \
98
- "#{sprintf('%09d', partid.to_i)} :: #{id&.text} :: #{title}"
99
- end
100
-
101
43
  def sections_cleanup(xml)
102
44
  super
103
45
  @amd or return
@@ -127,52 +69,6 @@ module Metanorma
127
69
  end
128
70
  end
129
71
 
130
- def bibitem_cleanup(xmldoc)
131
- super
132
- unpublished_note(xmldoc)
133
- withdrawn_note(xmldoc)
134
- end
135
-
136
- def unpublished_note(xmldoc)
137
- xmldoc.xpath("//bibitem[not(./ancestor::bibitem)]" \
138
- "[not(note[@type = 'Unpublished-Status'])]").each do |b|
139
- pub_class(b) > 2 and next
140
- ((s = b.at("./status/stage")) && s.text.match?(/\d/) &&
141
- (s.text.to_i < 60)) or next
142
- insert_unpub_note(b, @i18n.under_preparation
143
- .sub("%", b.at("docidentifier").text))
144
- end
145
- end
146
-
147
- def withdrawn_note(xmldoc)
148
- xmldoc.xpath("//bibitem[not(note[@type = 'Unpublished-Status'])]")
149
- .each do |b|
150
- withdrawn_ref?(b) or next
151
- if id = replacement_standard(b)
152
- insert_unpub_note(b, @i18n.cancelled_and_replaced.sub("%", id))
153
- else insert_unpub_note(b, @i18n.withdrawn)
154
- end
155
- end
156
- end
157
-
158
- def withdrawn_ref?(biblio)
159
- pub_class(biblio) > 2 and return false
160
- (s = biblio.at("./status/stage")) && (s.text.to_i == 95) &&
161
- (t = biblio.at("./status/substage")) && (t.text.to_i == 99)
162
- end
163
-
164
- def replacement_standard(biblio)
165
- r = biblio.at("./relation[@type = 'updates']/bibitem") or return nil
166
- id = r.at("./formattedref | ./docidentifier[@primary = 'true'] | " \
167
- "./docidentifier | ./formattedref") or return nil
168
- id.text
169
- end
170
-
171
- def insert_unpub_note(biblio, msg)
172
- biblio.at("./language | ./script | ./abstract | ./status")
173
- .previous = %(<note type="Unpublished-Status"><p>#{msg}</p></note>)
174
- end
175
-
176
72
  def termdef_boilerplate_insert(xmldoc, isodoc, once = false)
177
73
  once = true
178
74
  super
@@ -0,0 +1,120 @@
1
+ module Metanorma
2
+ module ISO
3
+ class Converter < Standoc::Converter
4
+ def id_prefix(prefix, id)
5
+ # we're just inheriting the prefixes from parent doc
6
+ @amd and return id.text
7
+ prefix.join("/") + (id.text.match?(%{^/}) ? "" : " ") + id.text
8
+ end
9
+
10
+ def get_id_prefix(xmldoc)
11
+ xmldoc.xpath("//bibdata/contributor[role/@type = 'publisher']" \
12
+ "/organization").each_with_object([]) do |x, prefix|
13
+ x1 = x.at("abbreviation")&.text || x.at("name")&.text
14
+ prefix << x1
15
+ end
16
+ end
17
+
18
+ # ISO as a prefix goes first
19
+ def docidentifier_cleanup(xmldoc)
20
+ prefix = get_id_prefix(xmldoc)
21
+ id = xmldoc.at("//bibdata/ext/structuredidentifier/project-number") and
22
+ id.content = id_prefix(prefix, id)
23
+ end
24
+
25
+ def format_ref(ref, type)
26
+ ref = ref.sub(/ \(All Parts\)/i, "")
27
+ super
28
+ end
29
+
30
+ PUBLISHER = "./contributor[role/@type = 'publisher']/organization".freeze
31
+
32
+ def pub_class(bib)
33
+ return 1 if bib.at("#{PUBLISHER}[abbreviation = 'ISO']")
34
+ return 1 if bib.at("#{PUBLISHER}[name = 'International Organization " \
35
+ "for Standardization']")
36
+ return 2 if bib.at("#{PUBLISHER}[abbreviation = 'IEC']")
37
+ return 2 if bib.at("#{PUBLISHER}[name = 'International " \
38
+ "Electrotechnical Commission']")
39
+ return 3 if bib.at("./docidentifier[@type]" \
40
+ "[not(#{skip_docid} or @type = 'metanorma')]") ||
41
+ bib.at("./docidentifier[not(@type)]")
42
+
43
+ 4
44
+ end
45
+
46
+ def sort_biblio(bib)
47
+ bib.sort { |a, b| sort_biblio_key(a) <=> sort_biblio_key(b) }
48
+ end
49
+
50
+ # sort by: doc class (ISO, IEC, other standard (not DOI &c), other
51
+ # then standard class (docid class other than DOI &c)
52
+ # then docnumber if present, numeric sort
53
+ # else alphanumeric metanorma id (abbreviation)
54
+ # then doc part number if present, numeric sort
55
+ # then doc id (not DOI &c)
56
+ # then title
57
+ def sort_biblio_key(bib)
58
+ pubclass = pub_class(bib)
59
+ num = bib.at("./docnumber")&.text
60
+ id = bib.at("./docidentifier[@primary]") ||
61
+ bib.at("./docidentifier[not(#{skip_docid} or @type = 'metanorma')]")
62
+ metaid = bib.at("./docidentifier[@type = 'metanorma']")&.text
63
+ abbrid = metaid unless /^\[\d+\]$/.match?(metaid)
64
+ /\d-(?<partid>\d+)/ =~ id&.text
65
+ type = id["type"] if id
66
+ title = bib.at("./title[@type = 'main']")&.text ||
67
+ bib.at("./title")&.text || bib&.at("./formattedref")&.text
68
+ "#{pubclass} :: #{type} :: " \
69
+ "#{num.nil? ? abbrid : sprintf('%09d', num.to_i)} :: " \
70
+ "#{sprintf('%09d', partid.to_i)} :: #{id&.text} :: #{title}"
71
+ end
72
+
73
+ def bibitem_cleanup(xmldoc)
74
+ super
75
+ unpublished_note(xmldoc)
76
+ withdrawn_note(xmldoc)
77
+ end
78
+
79
+ def unpublished_note(xmldoc)
80
+ xmldoc.xpath("//bibitem[not(./ancestor::bibitem)]" \
81
+ "[not(note[@type = 'Unpublished-Status'])]").each do |b|
82
+ pub_class(b) > 2 and next
83
+ ((s = b.at("./status/stage")) && s.text.match?(/\d/) &&
84
+ (s.text.to_i < 60)) or next
85
+ insert_unpub_note(b, @i18n.under_preparation
86
+ .sub("%", b.at("docidentifier").text))
87
+ end
88
+ end
89
+
90
+ def withdrawn_note(xmldoc)
91
+ xmldoc.xpath("//bibitem[not(note[@type = 'Unpublished-Status'])]")
92
+ .each do |b|
93
+ withdrawn_ref?(b) or next
94
+ if id = replacement_standard(b)
95
+ insert_unpub_note(b, @i18n.cancelled_and_replaced.sub("%", id))
96
+ else insert_unpub_note(b, @i18n.withdrawn)
97
+ end
98
+ end
99
+ end
100
+
101
+ def withdrawn_ref?(biblio)
102
+ pub_class(biblio) > 2 and return false
103
+ (s = biblio.at("./status/stage")) && (s.text.to_i == 95) &&
104
+ (t = biblio.at("./status/substage")) && (t.text.to_i == 99)
105
+ end
106
+
107
+ def replacement_standard(biblio)
108
+ r = biblio.at("./relation[@type = 'updates']/bibitem") or return nil
109
+ id = r.at("./formattedref | ./docidentifier[@primary = 'true'] | " \
110
+ "./docidentifier | ./formattedref") or return nil
111
+ id.text
112
+ end
113
+
114
+ def insert_unpub_note(biblio, msg)
115
+ biblio.at("./language | ./script | ./abstract | ./status")
116
+ .previous = %(<note type="Unpublished-Status"><p>#{msg}</p></note>)
117
+ end
118
+ end
119
+ end
120
+ end
@@ -9,7 +9,7 @@ module Metanorma
9
9
  class Converter < Standoc::Converter
10
10
  def metadata_id(node, xml)
11
11
  if id = node.attr("docidentifier")
12
- xml.docidentifier id, **attr_code(type: "ISO")
12
+ xml.docidentifier id, **attr_code(type: "ISO", primary: "true")
13
13
  else iso_id(node, xml)
14
14
  end
15
15
  node.attr("tc-docnumber")&.split(/,\s*/)&.each do |n|
@@ -161,12 +161,13 @@ module Metanorma
161
161
  end
162
162
 
163
163
  def cen_id_out(xml, params)
164
- xml.docidentifier iso_id_default(params).to_s, **attr_code(type: "CEN")
164
+ xml.docidentifier iso_id_default(params).to_s,
165
+ **attr_code(type: "CEN", primary: "true")
165
166
  end
166
167
 
167
168
  def iso_id_out_common(xml, params, with_prf)
168
169
  xml.docidentifier iso_id_default(params).to_s(with_prf: with_prf),
169
- **attr_code(type: "ISO")
170
+ **attr_code(type: "ISO", primary: "true")
170
171
  xml.docidentifier iso_id_reference(params)
171
172
  .to_s(format: :ref_num_short, with_prf: with_prf),
172
173
  **attr_code(type: "iso-reference")
@@ -185,8 +186,7 @@ module Metanorma
185
186
  params_nolang = params.dup.tap { |hs| hs.delete(:language) }
186
187
  params1 = if params[:unpublished]
187
188
  params_nolang.dup.tap { |hs| hs.delete(:year) }
188
- else params_nolang
189
- end
189
+ else params_nolang end
190
190
  params1.delete(:unpublished)
191
191
  pubid_select(params1).create(**params1)
192
192
  end