require_relative "init" require "roman-numerals" require "isodoc" module IsoDoc module ITU class PresentationXMLConvert < IsoDoc::PresentationXMLConvert def initialize(options) @hierarchical_assets = options[:hierarchical_assets] super end def prefix_container(container, linkend, _target) l10n("#{linkend} #{@i18n.get['in']} #{@xrefs.anchor(container, :xref)}") end def eref(docxml) docxml.xpath(ns("//eref")).each do |f| eref1(f) end end def origin(docxml) docxml.xpath(ns("//origin[not(termref)]")).each do |f| eref1(f) end end def quotesource(docxml) docxml.xpath(ns("//quote/source")).each do |f| eref1(f) end end def eref1(elem) get_eref_linkend(elem) end def note1(elem) return if elem["type"] == "title-footnote" super end def get_eref_linkend(node) contents = non_locality_elems(node).select do |c| !c.text? || /\S/.match(c) end return unless contents.empty? link = anchor_linkend(node, docid_l10n(node["target"] || node["citeas"])) link && !/^\[.*\]$/.match(link) and link = "[#{link}]" link += eref_localities(node.xpath(ns("./locality | ./localityStack")), link, node) non_locality_elems(node).each(&:remove) node.add_child(link) end def bibdata_i18n(bib) super bibdata_dates(bib) bibdata_title(bib) amendment_id(bib) end def bibdata_dates(bib) bib.xpath(ns("./date")).each do |d| d.next = d.dup d.next["format"] = "ddMMMyyyy" d.next.children = ddMMMyyyy(d.text) end end def bibdata_title(bib) case bib&.at(ns("./ext/doctype"))&.text when "service-publication" then bibdata_title_service_population(bib) when "resolution" then bibdata_title_resolution(bib) end end def bibdata_title_resolution(bib) place = bib&.at(ns("./ext/meeting-place"))&.text ed = bib&.at(ns("./edition"))&.text rev = ed && ed != "1" ? "#{@i18n.get['revision_abbreviation']} " : "" year = bib&.at(ns("./ext/meeting-date/from | ./ext/meeting-date/on")) &.text&.gsub(/-.*$/, "") num = bib&.at(ns("./docnumber"))&.text text = @i18n.l10n("#{@i18n.get['doctype_dict']['resolution'].upcase} "\ "#{num} (#{rev}#{place}, #{year})") ins = bib.at(ns("./title")) ins.next = <<~INS
"\ "#{@i18n.get['section'].upcase} #{lbl}
" end def annex1(elem) return super unless elem&.at(ns("//bibdata/ext/doctype"))&.text == "resolution" lbl = @xrefs.anchor(elem["id"], :label) subhead = (@i18n.l10n("(#{@i18n.get['to']} ") + elem.at(ns("//bibdata/title[@type = 'resolution']")) .children.to_xml + @i18n.l10n(")")) elem.elements.first.previous = "#{lbl}
#{subhead}