metanorma 2.0.0 → 2.1.2
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.
- checksums.yaml +4 -4
- data/lib/metanorma/collection/collection.rb +43 -14
- data/lib/metanorma/collection/config/bibdata.rb +2 -2
- data/lib/metanorma/collection/config/compile_options.rb +4 -5
- data/lib/metanorma/collection/config/config.rb +41 -73
- data/lib/metanorma/collection/config/converters.rb +27 -1
- data/lib/metanorma/collection/config/directive.rb +9 -3
- data/lib/metanorma/collection/config/manifest.rb +33 -27
- data/lib/metanorma/collection/document/document.rb +12 -10
- data/lib/metanorma/collection/filelookup/filelookup.rb +25 -13
- data/lib/metanorma/collection/filelookup/filelookup_sectionsplit.rb +57 -20
- data/lib/metanorma/collection/manifest/manifest.rb +22 -10
- data/lib/metanorma/collection/multilingual/multilingual.rb +660 -0
- data/lib/metanorma/collection/renderer/fileparse.rb +119 -104
- data/lib/metanorma/collection/renderer/fileprocess.rb +6 -2
- data/lib/metanorma/collection/renderer/navigation.rb +1 -1
- data/lib/metanorma/collection/renderer/render_word.rb +8 -7
- data/lib/metanorma/collection/renderer/renderer.rb +41 -20
- data/lib/metanorma/collection/renderer/svg.rb +52 -0
- data/lib/metanorma/collection/renderer/utils.rb +55 -18
- data/lib/metanorma/collection/sectionsplit/collection.rb +100 -0
- data/lib/metanorma/collection/sectionsplit/sectionsplit.rb +104 -101
- data/lib/metanorma/collection/util/util.rb +25 -10
- data/lib/metanorma/collection/xrefprocess/xrefprocess.rb +42 -28
- data/lib/metanorma/compile/compile.rb +12 -2
- data/lib/metanorma/compile/compile_options.rb +2 -0
- data/lib/metanorma/compile/compile_validate.rb +4 -4
- data/lib/metanorma/compile/extract.rb +2 -4
- data/lib/metanorma/input/asciidoc.rb +11 -30
- data/lib/metanorma/registry/registry.rb +2 -2
- data/lib/metanorma/version.rb +1 -1
- data/metanorma.gemspec +5 -4
- metadata +41 -25
- data/lib/metanorma/shale_monkeypatch.rb +0 -15
|
@@ -0,0 +1,660 @@
|
|
|
1
|
+
module Metanorma
|
|
2
|
+
class Collection
|
|
3
|
+
class Multilingual
|
|
4
|
+
def to_xml(node)
|
|
5
|
+
node&.to_xml(encoding: "UTF-8", indent: 0,
|
|
6
|
+
save_with: Nokogiri::XML::Node::SaveOptions::AS_XML)
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def xmldoc(node)
|
|
10
|
+
ret = Nokogiri::XML::Document.new
|
|
11
|
+
ret.root = node.dup
|
|
12
|
+
ret
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def flatxml_step1(param, elements)
|
|
16
|
+
<<~XSLT
|
|
17
|
+
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
|
|
18
|
+
xmlns:fo="http://www.w3.org/1999/XSL/Format"
|
|
19
|
+
xmlns:jcgm="https://www.metanorma.org/ns/bipm"
|
|
20
|
+
xmlns:bipm="https://www.metanorma.org/ns/bipm"
|
|
21
|
+
xmlns:mathml="http://www.w3.org/1998/Math/MathML"
|
|
22
|
+
xmlns:xalan="http://xml.apache.org/xalan"
|
|
23
|
+
xmlns:exsl="http://exslt.org/common"
|
|
24
|
+
xmlns:fox="http://xmlgraphics.apache.org/fop/extensions"
|
|
25
|
+
xmlns:java="http://xml.apache.org/xalan/java"
|
|
26
|
+
exclude-result-prefixes="java"
|
|
27
|
+
version="1.0">
|
|
28
|
+
|
|
29
|
+
<xsl:output method="xml" encoding="UTF-8" indent="no"/>
|
|
30
|
+
|
|
31
|
+
<xsl:template match="@* | node()">
|
|
32
|
+
<xsl:copy>
|
|
33
|
+
<xsl:apply-templates select="@* | node()"/>
|
|
34
|
+
</xsl:copy>
|
|
35
|
+
</xsl:template>
|
|
36
|
+
|
|
37
|
+
<xsl:template match="/*[local-name()='doc-container']">
|
|
38
|
+
<xsl:copy>
|
|
39
|
+
<xsl:apply-templates select="@* | node()" mode="flatxml_step1">
|
|
40
|
+
<xsl:with-param name="num" select="'#{param}'"/>
|
|
41
|
+
</xsl:apply-templates>
|
|
42
|
+
</xsl:copy>
|
|
43
|
+
</xsl:template>
|
|
44
|
+
|
|
45
|
+
<xsl:param name="align-cross-elements">#{elements}</xsl:param>
|
|
46
|
+
|
|
47
|
+
<xsl:variable name="align_cross_elements_default">clause</xsl:variable>
|
|
48
|
+
<xsl:variable name="align_cross_elements_doc">
|
|
49
|
+
<xsl:choose>
|
|
50
|
+
<xsl:when test="normalize-space($align-cross-elements) != ''"><xsl:value-of select="$align-cross-elements"/></xsl:when>
|
|
51
|
+
<xsl:otherwise>
|
|
52
|
+
<xsl:value-of select="normalize-space((//jcgm:bipm-standard)[1]/jcgm:bibdata/jcgm:ext/jcgm:parallel-align-element)"/>
|
|
53
|
+
</xsl:otherwise>
|
|
54
|
+
</xsl:choose>
|
|
55
|
+
</xsl:variable>
|
|
56
|
+
<xsl:variable name="align_cross_elements_">
|
|
57
|
+
<xsl:choose>
|
|
58
|
+
<xsl:when test="$align_cross_elements_doc != ''">
|
|
59
|
+
<xsl:value-of select="$align_cross_elements_doc"/>
|
|
60
|
+
</xsl:when>
|
|
61
|
+
<xsl:otherwise>
|
|
62
|
+
<xsl:value-of select="$align_cross_elements_default"/>
|
|
63
|
+
</xsl:otherwise>
|
|
64
|
+
</xsl:choose>
|
|
65
|
+
</xsl:variable>
|
|
66
|
+
<xsl:variable name="align_cross_elements">
|
|
67
|
+
<xsl:text>#</xsl:text><xsl:value-of select="translate(normalize-space($align_cross_elements_), ' ', '#')"/><xsl:text>#</xsl:text>
|
|
68
|
+
</xsl:variable>
|
|
69
|
+
|
|
70
|
+
<!-- ================================= -->
|
|
71
|
+
<!-- First step -->
|
|
72
|
+
<!-- ================================= -->
|
|
73
|
+
|
|
74
|
+
<xsl:template match="@*|node()" mode="flatxml_step1">
|
|
75
|
+
<xsl:copy>
|
|
76
|
+
<xsl:apply-templates select="@*|node()" mode="flatxml_step1"/>
|
|
77
|
+
</xsl:copy>
|
|
78
|
+
</xsl:template>
|
|
79
|
+
<xsl:template match="/*[local-name()='doc-container']/*[1]" mode="flatxml_step1">
|
|
80
|
+
<xsl:param name="num"/>
|
|
81
|
+
<xsl:copy>
|
|
82
|
+
<xsl:attribute name="cross-align">true</xsl:attribute>
|
|
83
|
+
<xsl:attribute name="{$num}"/>
|
|
84
|
+
<xsl:apply-templates select="@*"/>
|
|
85
|
+
<xsl:apply-templates select="node()" mode="flatxml_step1"/>
|
|
86
|
+
</xsl:copy>
|
|
87
|
+
</xsl:template>
|
|
88
|
+
|
|
89
|
+
<!-- enclose clause[@type='scope'] into scope -->
|
|
90
|
+
<xsl:template match="*[local-name()='sections']/*[local-name()='clause'][@type='scope']" mode="flatxml_step1" priority="2">
|
|
91
|
+
<!-- <section_scope>
|
|
92
|
+
<clause @type=scope>...
|
|
93
|
+
</section_scope> -->
|
|
94
|
+
<xsl:element name="section_scope" namespace="https://www.metanorma.org/ns/bipm">
|
|
95
|
+
<xsl:call-template name="clause"/>
|
|
96
|
+
</xsl:element>
|
|
97
|
+
</xsl:template>
|
|
98
|
+
|
|
99
|
+
<xsl:template match="jcgm:sections//jcgm:clause | jcgm:annex//jcgm:clause" mode="flatxml_step1" name="clause">
|
|
100
|
+
<!-- From:
|
|
101
|
+
<clause>
|
|
102
|
+
<title>...</title>
|
|
103
|
+
<p>...</p>
|
|
104
|
+
</clause>
|
|
105
|
+
To:
|
|
106
|
+
<clause/>
|
|
107
|
+
<title>...</title>
|
|
108
|
+
<p>...</p>
|
|
109
|
+
-->
|
|
110
|
+
<xsl:copy>
|
|
111
|
+
<xsl:apply-templates select="@*" mode="flatxml_step1"/>
|
|
112
|
+
<xsl:call-template name="setCrossAlignAttributes"/>
|
|
113
|
+
</xsl:copy>
|
|
114
|
+
<xsl:apply-templates mode="flatxml_step1"/>
|
|
115
|
+
</xsl:template>
|
|
116
|
+
|
|
117
|
+
<!-- allow cross-align for element title -->
|
|
118
|
+
<xsl:template match="jcgm:sections//jcgm:title | jcgm:annex//jcgm:title" mode="flatxml_step1">
|
|
119
|
+
<xsl:copy>
|
|
120
|
+
<xsl:apply-templates select="@*" mode="flatxml_step1"/>
|
|
121
|
+
<xsl:call-template name="setCrossAlignAttributes"/>
|
|
122
|
+
<xsl:attribute name="keep-with-next">always</xsl:attribute>
|
|
123
|
+
<xsl:if test="parent::jcgm:annex">
|
|
124
|
+
<xsl:attribute name="depth">1</xsl:attribute>
|
|
125
|
+
</xsl:if>
|
|
126
|
+
<xsl:if test="../@inline-header = 'true'">
|
|
127
|
+
<xsl:copy-of select="../@inline-header"/>
|
|
128
|
+
</xsl:if>
|
|
129
|
+
<xsl:apply-templates mode="flatxml_step1"/>
|
|
130
|
+
</xsl:copy>
|
|
131
|
+
</xsl:template>
|
|
132
|
+
|
|
133
|
+
<xsl:template match="*[local-name()='annex']" mode="flatxml_step1">
|
|
134
|
+
<xsl:copy>
|
|
135
|
+
<xsl:apply-templates select="@*" mode="flatxml_step1"/>
|
|
136
|
+
<!-- create empty element for case if first element isn't cross-align -->
|
|
137
|
+
<xsl:element name="empty" namespace="https://www.metanorma.org/ns/bipm">
|
|
138
|
+
<xsl:attribute name="cross-align">true</xsl:attribute>
|
|
139
|
+
<xsl:attribute name="element-number">empty_annex<xsl:number/></xsl:attribute>
|
|
140
|
+
</xsl:element>
|
|
141
|
+
<xsl:apply-templates mode="flatxml_step1"/>
|
|
142
|
+
</xsl:copy>
|
|
143
|
+
</xsl:template>
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
<xsl:template match="*[local-name()='sections']//*[local-name()='terms']" mode="flatxml_step1" priority="2">
|
|
147
|
+
<!-- From:
|
|
148
|
+
<terms>
|
|
149
|
+
<term>...</term>
|
|
150
|
+
<term>...</term>
|
|
151
|
+
</terms>
|
|
152
|
+
To:
|
|
153
|
+
<section_terms>
|
|
154
|
+
<terms>...</terms>
|
|
155
|
+
</section_terms> -->
|
|
156
|
+
<xsl:element name="section_terms" namespace="https://www.metanorma.org/ns/bipm">
|
|
157
|
+
<!-- create empty element for case if first element isn't cross-align -->
|
|
158
|
+
<xsl:element name="empty" namespace="https://www.metanorma.org/ns/bipm">
|
|
159
|
+
<xsl:attribute name="cross-align">true</xsl:attribute>
|
|
160
|
+
<xsl:attribute name="element-number">empty_terms_<xsl:number/></xsl:attribute>
|
|
161
|
+
</xsl:element>
|
|
162
|
+
<xsl:call-template name="terms"/>
|
|
163
|
+
</xsl:element>
|
|
164
|
+
</xsl:template>
|
|
165
|
+
<xsl:template match="*[local-name()='sections']//*[local-name()='definitions']" mode="flatxml_step1" priority="2">
|
|
166
|
+
<xsl:element name="section_terms" namespace="https://www.metanorma.org/ns/bipm">
|
|
167
|
+
<xsl:call-template name="terms"/>
|
|
168
|
+
</xsl:element>
|
|
169
|
+
</xsl:template>
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
<!-- From:
|
|
173
|
+
<terms>
|
|
174
|
+
<term>...</term>
|
|
175
|
+
<term>...</term>
|
|
176
|
+
</terms>
|
|
177
|
+
To:
|
|
178
|
+
<terms/>
|
|
179
|
+
<term>...</term>
|
|
180
|
+
<term>...</term>-->
|
|
181
|
+
<!-- And
|
|
182
|
+
From:
|
|
183
|
+
<term>
|
|
184
|
+
<name>...</name>
|
|
185
|
+
<preferred>...</preferred>
|
|
186
|
+
<definition>...</definition>
|
|
187
|
+
<termsource>...</termsource>
|
|
188
|
+
</term>
|
|
189
|
+
To:
|
|
190
|
+
<term/>
|
|
191
|
+
<term_name>...</term_name>
|
|
192
|
+
<preferred>...</preferred>
|
|
193
|
+
<definition>...</definition>
|
|
194
|
+
<termsource>...</termsource>
|
|
195
|
+
-->
|
|
196
|
+
<xsl:template match="jcgm:sections//jcgm:terms | jcgm:annex//jcgm:terms |
|
|
197
|
+
jcgm:sections//jcgm:term | jcgm:annex//jcgm:term" mode="flatxml_step1" name="terms">
|
|
198
|
+
<xsl:copy>
|
|
199
|
+
<xsl:apply-templates select="@*" mode="flatxml_step1"/>
|
|
200
|
+
<xsl:attribute name="keep-with-next">always</xsl:attribute>
|
|
201
|
+
<xsl:call-template name="setCrossAlignAttributes"/>
|
|
202
|
+
</xsl:copy>
|
|
203
|
+
<xsl:apply-templates mode="flatxml_step1"/>
|
|
204
|
+
</xsl:template>
|
|
205
|
+
|
|
206
|
+
<!-- From:
|
|
207
|
+
<term><name>...</name></term>
|
|
208
|
+
To:
|
|
209
|
+
<term><term_name>...</term_name></term> -->
|
|
210
|
+
<xsl:template match="jcgm:term/jcgm:name" mode="flatxml_step1">
|
|
211
|
+
<xsl:element name="term_name" namespace="https://www.metanorma.org/ns/bipm">
|
|
212
|
+
<xsl:apply-templates select="@*" mode="flatxml_step1"/>
|
|
213
|
+
<xsl:call-template name="setCrossAlignAttributes"/>
|
|
214
|
+
<xsl:apply-templates mode="flatxml_step1"/>
|
|
215
|
+
</xsl:element>
|
|
216
|
+
</xsl:template>
|
|
217
|
+
|
|
218
|
+
<!-- From:
|
|
219
|
+
<ul>
|
|
220
|
+
<li>...</li>
|
|
221
|
+
<li>...</li>
|
|
222
|
+
</ul>
|
|
223
|
+
To:
|
|
224
|
+
<ul/
|
|
225
|
+
<li>...</li>
|
|
226
|
+
<li>...</li> -->
|
|
227
|
+
<xsl:template match="jcgm:sections//jcgm:ul | jcgm:annex//jcgm:ul | jcgm:sections//jcgm:ol | jcgm:annex//jcgm:ol" mode="flatxml_step1">
|
|
228
|
+
<xsl:copy>
|
|
229
|
+
<xsl:apply-templates select="@*" mode="flatxml_step1"/>
|
|
230
|
+
<xsl:attribute name="keep-with-next">always</xsl:attribute>
|
|
231
|
+
<xsl:call-template name="setCrossAlignAttributes"/>
|
|
232
|
+
</xsl:copy>
|
|
233
|
+
<xsl:apply-templates mode="flatxml_step1"/>
|
|
234
|
+
</xsl:template>
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
<!-- allow cross-align for element p, note, termsource, table, figure, li (and set label) -->
|
|
238
|
+
<xsl:template match="jcgm:sections//jcgm:p |
|
|
239
|
+
jcgm:sections//jcgm:note |
|
|
240
|
+
jcgm:sections//jcgm:termsource |
|
|
241
|
+
jcgm:sections//jcgm:li |
|
|
242
|
+
jcgm:table |
|
|
243
|
+
jcgm:figure |
|
|
244
|
+
jcgm:annex//jcgm:p |
|
|
245
|
+
jcgm:annex//jcgm:note |
|
|
246
|
+
jcgm:annex//jcgm:termsource |
|
|
247
|
+
jcgm:annex//jcgm:li" mode="flatxml_step1">
|
|
248
|
+
<xsl:copy>
|
|
249
|
+
<xsl:apply-templates select="@*" mode="flatxml_step1"/>
|
|
250
|
+
<xsl:call-template name="setCrossAlignAttributes"/>
|
|
251
|
+
<xsl:choose>
|
|
252
|
+
<xsl:when test="*[local-name() = 'ul']/*[local-name() = 'li']">
|
|
253
|
+
<xsl:element name="ul" namespace="https://www.metanorma.org/ns/bipm">
|
|
254
|
+
<xsl:apply-templates mode="flatxml_step1"/>
|
|
255
|
+
</xsl:element>
|
|
256
|
+
</xsl:when>
|
|
257
|
+
<xsl:otherwise>
|
|
258
|
+
<xsl:apply-templates mode="flatxml_step1"/>
|
|
259
|
+
</xsl:otherwise>
|
|
260
|
+
</xsl:choose>
|
|
261
|
+
</xsl:copy>
|
|
262
|
+
</xsl:template>
|
|
263
|
+
|
|
264
|
+
|
|
265
|
+
<xsl:template name="setCrossAlignAttributes">
|
|
266
|
+
<xsl:variable name="is_cross_aligned">
|
|
267
|
+
<xsl:call-template name="isCrossAligned"/>
|
|
268
|
+
</xsl:variable>
|
|
269
|
+
<xsl:if test="normalize-space($is_cross_aligned) = 'true'">
|
|
270
|
+
<xsl:attribute name="cross-align">true</xsl:attribute>
|
|
271
|
+
<!-- <xsl:attribute name="keep-with-next">always</xsl:attribute> -->
|
|
272
|
+
</xsl:if>
|
|
273
|
+
<xsl:call-template name="setElementNumber"/>
|
|
274
|
+
</xsl:template>
|
|
275
|
+
|
|
276
|
+
<!--
|
|
277
|
+
Elements that should be aligned:
|
|
278
|
+
- name of element presents in field align-cross-elements="clause note"
|
|
279
|
+
- marked with attribute name
|
|
280
|
+
- table/figure with attribute @multilingual-rendering = 'common' or @multilingual-rendering = 'all-columns'
|
|
281
|
+
- marked with attribute cross-align
|
|
282
|
+
-->
|
|
283
|
+
<xsl:template name="isCrossAligned">
|
|
284
|
+
<xsl:variable name="element_name" select="local-name()"/>
|
|
285
|
+
<xsl:choose>
|
|
286
|
+
<!-- if element`s name is presents in array align_cross_elements -->
|
|
287
|
+
<xsl:when test="contains($align_cross_elements, concat('#',$element_name,'#'))">true</xsl:when>
|
|
288
|
+
<!-- if element has attribute name/bookmark -->
|
|
289
|
+
<xsl:when test="normalize-space(@name) != '' and @multilingual-rendering = 'name'">true</xsl:when>
|
|
290
|
+
<xsl:when test="($element_name = 'table' or $element_name = 'figure') and (@multilingual-rendering = 'common' or @multilingual-rendering = 'all-columns')">true</xsl:when>
|
|
291
|
+
<!-- element marked as cross-align -->
|
|
292
|
+
<xsl:when test="@multilingual-rendering='parallel'">true</xsl:when>
|
|
293
|
+
<xsl:otherwise>false</xsl:otherwise>
|
|
294
|
+
</xsl:choose>
|
|
295
|
+
</xsl:template>
|
|
296
|
+
|
|
297
|
+
<!-- calculate element number in tree to find a match between documents -->
|
|
298
|
+
<xsl:template name="setElementNumber">
|
|
299
|
+
<xsl:variable name="element-number">
|
|
300
|
+
<xsl:choose>
|
|
301
|
+
<!-- if name set, then use it -->
|
|
302
|
+
<xsl:when test="@name and @multilingual-rendering = 'name'"><xsl:value-of select="@name"/></xsl:when>
|
|
303
|
+
<xsl:otherwise>
|
|
304
|
+
<xsl:for-each select="ancestor-or-self::*[ancestor-or-self::*[local-name() = 'sections' or local-name() = 'annex']]">
|
|
305
|
+
<xsl:value-of select="local-name()"/>
|
|
306
|
+
<xsl:choose>
|
|
307
|
+
<xsl:when test="local-name() = 'terms'"></xsl:when>
|
|
308
|
+
<xsl:when test="local-name() = 'sections'"></xsl:when>
|
|
309
|
+
<xsl:otherwise><xsl:number /></xsl:otherwise>
|
|
310
|
+
</xsl:choose>
|
|
311
|
+
<xsl:text>_</xsl:text>
|
|
312
|
+
</xsl:for-each>
|
|
313
|
+
</xsl:otherwise>
|
|
314
|
+
</xsl:choose>
|
|
315
|
+
</xsl:variable>
|
|
316
|
+
<xsl:attribute name="element-number">
|
|
317
|
+
<xsl:value-of select="normalize-space($element-number)"/>
|
|
318
|
+
</xsl:attribute>
|
|
319
|
+
</xsl:template>
|
|
320
|
+
<!-- ================================= -->
|
|
321
|
+
<!-- ================================= -->
|
|
322
|
+
<!-- End First step -->
|
|
323
|
+
<!-- ================================= -->
|
|
324
|
+
|
|
325
|
+
</xsl:stylesheet>
|
|
326
|
+
XSLT
|
|
327
|
+
end
|
|
328
|
+
|
|
329
|
+
def flatxml_step2
|
|
330
|
+
<<~XSLT
|
|
331
|
+
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
|
|
332
|
+
xmlns:fo="http://www.w3.org/1999/XSL/Format"
|
|
333
|
+
xmlns:jcgm="https://www.metanorma.org/ns/bipm"
|
|
334
|
+
xmlns:bipm="https://www.metanorma.org/ns/bipm"
|
|
335
|
+
xmlns:mathml="http://www.w3.org/1998/Math/MathML"
|
|
336
|
+
xmlns:xalan="http://xml.apache.org/xalan"
|
|
337
|
+
xmlns:exsl="http://exslt.org/common"
|
|
338
|
+
xmlns:fox="http://xmlgraphics.apache.org/fop/extensions"
|
|
339
|
+
xmlns:java="http://xml.apache.org/xalan/java"
|
|
340
|
+
exclude-result-prefixes="java"
|
|
341
|
+
version="1.0">
|
|
342
|
+
|
|
343
|
+
<xsl:output method="xml" encoding="UTF-8" indent="no"/>
|
|
344
|
+
|
|
345
|
+
<xsl:template match="@* | node()">
|
|
346
|
+
<xsl:copy>
|
|
347
|
+
<xsl:apply-templates select="@* | node()"/>
|
|
348
|
+
</xsl:copy>
|
|
349
|
+
</xsl:template>
|
|
350
|
+
|
|
351
|
+
<xsl:template match="/*[local-name()='doc-container']/*[1]">
|
|
352
|
+
<xsl:copy>
|
|
353
|
+
<xsl:apply-templates select="@*|node()" mode="flatxml_step2"/>
|
|
354
|
+
</xsl:copy>
|
|
355
|
+
</xsl:template>
|
|
356
|
+
|
|
357
|
+
<!-- ================================= -->
|
|
358
|
+
<!-- Second step -->
|
|
359
|
+
<!-- ================================= -->
|
|
360
|
+
<xsl:template match="@*|node()" mode="flatxml_step2">
|
|
361
|
+
<xsl:copy>
|
|
362
|
+
<xsl:apply-templates select="@*|node()" mode="flatxml_step2"/>
|
|
363
|
+
</xsl:copy>
|
|
364
|
+
</xsl:template>
|
|
365
|
+
<!-- enclose elements after table/figure with @multilingual-rendering = 'common' and @multilingual-rendering = 'all-columns' in a separate element cross-align -->
|
|
366
|
+
<xsl:template match="*[@multilingual-rendering = 'common' or @multilingual-rendering = 'all-columns']" mode="flatxml_step2" priority="2">
|
|
367
|
+
<xsl:variable name="curr_id" select="generate-id()"/>
|
|
368
|
+
<xsl:element name="cross-align" namespace="https://www.metanorma.org/ns/bipm">
|
|
369
|
+
<xsl:copy-of select="@element-number"/>
|
|
370
|
+
<xsl:copy-of select="@multilingual-rendering"/>
|
|
371
|
+
<xsl:copy-of select="@displayorder"/>
|
|
372
|
+
<xsl:copy-of select="."/>
|
|
373
|
+
</xsl:element>
|
|
374
|
+
<xsl:if test="following-sibling::*[(not(@cross-align) or not(@cross-align='true')) and preceding-sibling::*[@cross-align='true'][1][generate-id() = $curr_id]]">
|
|
375
|
+
<xsl:element name="cross-align" namespace="https://www.metanorma.org/ns/bipm">
|
|
376
|
+
<!-- <xsl:copy-of select="following-sibling::*[(not(@cross-align) or not(@cross-align='true')) and preceding-sibling::*[@cross-align='true'][1][generate-id() = $curr_id]][1]/@element-number"/> -->
|
|
377
|
+
<xsl:for-each select="following-sibling::*[(not(@cross-align) or not(@cross-align='true')) and preceding-sibling::*[@cross-align='true'][1][generate-id() = $curr_id]]">
|
|
378
|
+
<xsl:if test="position() = 1">
|
|
379
|
+
<xsl:copy-of select="@element-number"/>
|
|
380
|
+
</xsl:if>
|
|
381
|
+
<xsl:copy-of select="@displayorder"/>
|
|
382
|
+
<xsl:copy-of select="."/>
|
|
383
|
+
</xsl:for-each>
|
|
384
|
+
</xsl:element>
|
|
385
|
+
</xsl:if>
|
|
386
|
+
</xsl:template>
|
|
387
|
+
|
|
388
|
+
<xsl:template match="*[@cross-align='true']" mode="flatxml_step2">
|
|
389
|
+
<xsl:variable name="curr_id" select="generate-id()"/>
|
|
390
|
+
<xsl:element name="cross-align" namespace="https://www.metanorma.org/ns/bipm">
|
|
391
|
+
<xsl:copy-of select="@element-number"/>
|
|
392
|
+
<xsl:copy-of select="@displayorder"/>
|
|
393
|
+
<xsl:if test="local-name() = 'clause'">
|
|
394
|
+
<xsl:copy-of select="@keep-with-next"/>
|
|
395
|
+
</xsl:if>
|
|
396
|
+
<xsl:if test="local-name() = 'title'">
|
|
397
|
+
<xsl:copy-of select="@keep-with-next"/>
|
|
398
|
+
</xsl:if>
|
|
399
|
+
<xsl:copy-of select="@multilingual-rendering"/>
|
|
400
|
+
<xsl:copy-of select="."/>
|
|
401
|
+
|
|
402
|
+
<!-- copy next elements until next element with cross-align=true -->
|
|
403
|
+
<xsl:for-each select="following-sibling::*[(not(@cross-align) or not(@cross-align='true')) and preceding-sibling::*[@cross-align='true'][1][generate-id() = $curr_id]]">
|
|
404
|
+
<xsl:copy-of select="."/>
|
|
405
|
+
</xsl:for-each>
|
|
406
|
+
</xsl:element>
|
|
407
|
+
</xsl:template>
|
|
408
|
+
|
|
409
|
+
<xsl:template match="*" mode="flatxml_step2">
|
|
410
|
+
<xsl:choose>
|
|
411
|
+
<xsl:when test="preceding-sibling::*[@cross-align='true'] and (not(@cross-align) or not(@cross-align='true'))"/>
|
|
412
|
+
<xsl:otherwise>
|
|
413
|
+
<xsl:copy>
|
|
414
|
+
<xsl:apply-templates select="@*|node()" mode="flatxml_step2"/>
|
|
415
|
+
</xsl:copy>
|
|
416
|
+
</xsl:otherwise>
|
|
417
|
+
</xsl:choose>
|
|
418
|
+
</xsl:template>
|
|
419
|
+
|
|
420
|
+
<!-- ================================= -->
|
|
421
|
+
<!-- End Second step -->
|
|
422
|
+
<!-- ================================= -->
|
|
423
|
+
|
|
424
|
+
</xsl:stylesheet>
|
|
425
|
+
XSLT
|
|
426
|
+
end
|
|
427
|
+
|
|
428
|
+
def two_column
|
|
429
|
+
<<~XSLT
|
|
430
|
+
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
|
|
431
|
+
xmlns:fo="http://www.w3.org/1999/XSL/Format"
|
|
432
|
+
xmlns:jcgm="https://www.metanorma.org/ns/bipm"
|
|
433
|
+
xmlns:bipm="https://www.metanorma.org/ns/bipm"
|
|
434
|
+
xmlns:mathml="http://www.w3.org/1998/Math/MathML"
|
|
435
|
+
xmlns:xalan="http://xml.apache.org/xalan"
|
|
436
|
+
xmlns:exsl="http://exslt.org/common"
|
|
437
|
+
xmlns:fox="http://xmlgraphics.apache.org/fop/extensions"
|
|
438
|
+
xmlns:java="http://xml.apache.org/xalan/java"
|
|
439
|
+
exclude-result-prefixes="java"
|
|
440
|
+
version="1.0">
|
|
441
|
+
|
|
442
|
+
<xsl:output method="xml" encoding="UTF-8" indent="no"/>
|
|
443
|
+
|
|
444
|
+
<xsl:template match="@* | node()">
|
|
445
|
+
<xsl:copy>
|
|
446
|
+
<xsl:apply-templates select="@* | node()"/>
|
|
447
|
+
</xsl:copy>
|
|
448
|
+
</xsl:template>
|
|
449
|
+
|
|
450
|
+
<xsl:template match="//*[local-name()='doc-container'][1]">
|
|
451
|
+
<xsl:copy>
|
|
452
|
+
<xsl:apply-templates select="@* | node()" mode="multi_columns"/>
|
|
453
|
+
</xsl:copy>
|
|
454
|
+
</xsl:template>
|
|
455
|
+
|
|
456
|
+
<xsl:template match="@* | node()" mode="multi_columns">
|
|
457
|
+
<xsl:copy>
|
|
458
|
+
<xsl:apply-templates select="@* | node()" mode="multi_columns"/>
|
|
459
|
+
</xsl:copy>
|
|
460
|
+
</xsl:template>
|
|
461
|
+
|
|
462
|
+
<xsl:template match="//*[local-name()='doc-container'][position() > 1]">
|
|
463
|
+
</xsl:template>
|
|
464
|
+
|
|
465
|
+
<!-- =================== -->
|
|
466
|
+
<!-- Two columns layout -->
|
|
467
|
+
<!-- =================== -->
|
|
468
|
+
|
|
469
|
+
<!-- <xsl:template match="*[@first]/*[local-name()='sections']//*[not(@cross-align) or not(@cross-align='true')]"/> -->
|
|
470
|
+
|
|
471
|
+
<xsl:template match="*[@first]/*[local-name()='sections']//*[local-name() = 'cross-align'] | *[@first]/*[local-name()='annex']//*[local-name() = 'cross-align']" mode="multi_columns">
|
|
472
|
+
<xsl:variable name="element-number" select="@element-number"/>
|
|
473
|
+
<xsl:element name="cross-align" namespace="https://www.metanorma.org/ns/bipm">
|
|
474
|
+
|
|
475
|
+
<xsl:copy-of select="@keep-with-next"/>
|
|
476
|
+
<xsl:copy-of select="@displayorder"/>
|
|
477
|
+
<xsl:element name="align-cell" namespace="https://www.metanorma.org/ns/bipm">
|
|
478
|
+
<xsl:copy-of select="@keep-with-next"/>
|
|
479
|
+
<xsl:apply-templates select="." />
|
|
480
|
+
</xsl:element>
|
|
481
|
+
<xsl:variable name="keep-with-next" select="@keep-with-next"/>
|
|
482
|
+
<xsl:for-each select="//*[local-name()='doc-container'][position() > 1]">
|
|
483
|
+
<xsl:element name="align-cell" namespace="https://www.metanorma.org/ns/bipm">
|
|
484
|
+
<xsl:if test="$keep-with-next != ''">
|
|
485
|
+
<xsl:attribute name="keep-with-next"><xsl:value-of select="$keep-with-next"/></xsl:attribute>
|
|
486
|
+
</xsl:if>
|
|
487
|
+
<xsl:apply-templates select=".//*[local-name() = 'cross-align' and @element-number=$element-number]"/>
|
|
488
|
+
</xsl:element>
|
|
489
|
+
</xsl:for-each>
|
|
490
|
+
</xsl:element>
|
|
491
|
+
</xsl:template>
|
|
492
|
+
|
|
493
|
+
<xsl:template match="*[local-name() = 'cross-align']" priority="3">
|
|
494
|
+
<xsl:apply-templates />
|
|
495
|
+
</xsl:template>
|
|
496
|
+
|
|
497
|
+
<!-- no display table/figure from slave documents if @multilingual-rendering="common" or @multilingual-rendering = 'all-columns' -->
|
|
498
|
+
<xsl:template match="*[@slave]//*[local-name()='table'][@multilingual-rendering= 'common']" priority="2"/>
|
|
499
|
+
<xsl:template match="*[@slave]//*[local-name()='table'][@multilingual-rendering = 'all-columns']" priority="2"/>
|
|
500
|
+
<xsl:template match="*[@slave]//*[local-name()='figure'][@multilingual-rendering = 'common']" priority="2"/>
|
|
501
|
+
<xsl:template match="*[@slave]//*[local-name()='figure'][@multilingual-rendering = 'all-columns']" priority="2"/>
|
|
502
|
+
|
|
503
|
+
<!-- for table and figure with @multilingual-rendering="common" -->
|
|
504
|
+
<!-- display only element from first document -->
|
|
505
|
+
<xsl:template match="*[@first]//*[local-name() = 'cross-align'][@multilingual-rendering = 'common']" mode="multi_columns">
|
|
506
|
+
<xsl:apply-templates />
|
|
507
|
+
</xsl:template>
|
|
508
|
+
|
|
509
|
+
<!-- for table and figure with @multilingual-rendering = 'all-columns' -->
|
|
510
|
+
<!-- display element from first document, then (after) from 2nd one, then 3rd, etc. -->
|
|
511
|
+
<xsl:template match="*[@first]//*[local-name() = 'cross-align'][@multilingual-rendering = 'all-columns']" mode="multi_columns">
|
|
512
|
+
<xsl:variable name="element-number" select="@element-number"/>
|
|
513
|
+
<xsl:apply-templates />
|
|
514
|
+
<xsl:choose>
|
|
515
|
+
<xsl:when test="local-name(*[@multilingual-rendering = 'all-columns']) = 'table'">
|
|
516
|
+
<xsl:for-each select="//*[local-name()='doc-container'][position() > 1]">
|
|
517
|
+
<xsl:for-each select=".//*[local-name() = 'table' and @element-number=$element-number]">
|
|
518
|
+
<xsl:call-template name="table"/>
|
|
519
|
+
</xsl:for-each>
|
|
520
|
+
</xsl:for-each>
|
|
521
|
+
</xsl:when>
|
|
522
|
+
<xsl:when test="local-name(*[@multilingual-rendering = 'all-columns']) = 'figure'">
|
|
523
|
+
<xsl:for-each select="//*[local-name()='doc-container'][position() > 1]">
|
|
524
|
+
|
|
525
|
+
<xsl:for-each select=".//*[local-name() = 'figure' and @element-number=$element-number]">
|
|
526
|
+
<xsl:call-template name="figure"/>
|
|
527
|
+
</xsl:for-each>
|
|
528
|
+
</xsl:for-each>
|
|
529
|
+
</xsl:when>
|
|
530
|
+
</xsl:choose>
|
|
531
|
+
</xsl:template>
|
|
532
|
+
|
|
533
|
+
<!-- =========== -->
|
|
534
|
+
<!-- References -->
|
|
535
|
+
<xsl:template match="*[@first]//*[local-name()='references'][@normative='true']" mode="multi_columns">
|
|
536
|
+
<xsl:for-each select="//*[local-name()='doc-container'][position() > 1]">
|
|
537
|
+
<xsl:element name="bookmark" namespace="https://www.metanorma.org/ns/bipm">
|
|
538
|
+
<xsl:attribute name="id"><xsl:value-of select=".//*[local-name()='references'][@normative='true']/@id"/></xsl:attribute>
|
|
539
|
+
</xsl:element>
|
|
540
|
+
</xsl:for-each>
|
|
541
|
+
<xsl:apply-templates mode="multi_columns"/>
|
|
542
|
+
</xsl:template>
|
|
543
|
+
|
|
544
|
+
<xsl:template match="*[@first]//*[local-name()='references'][@normative='true']/*" mode="multi_columns">
|
|
545
|
+
<xsl:variable name="number_"><xsl:number count="*"/></xsl:variable>
|
|
546
|
+
<xsl:variable name="number" select="number(normalize-space($number_))"/>
|
|
547
|
+
<xsl:element name="cross-align" namespace="https://www.metanorma.org/ns/bipm">
|
|
548
|
+
<xsl:copy-of select="@displayorder"/>
|
|
549
|
+
<xsl:element name="align-cell" namespace="https://www.metanorma.org/ns/bipm">
|
|
550
|
+
<xsl:apply-templates select="." />
|
|
551
|
+
</xsl:element>
|
|
552
|
+
|
|
553
|
+
<xsl:for-each select="//*[local-name()='doc-container'][position() > 1]">
|
|
554
|
+
<xsl:element name="align-cell" namespace="https://www.metanorma.org/ns/bipm">
|
|
555
|
+
<xsl:apply-templates select="(.//*[local-name()='references'][@normative='true']/*)[$number]"/>
|
|
556
|
+
</xsl:element>
|
|
557
|
+
</xsl:for-each>
|
|
558
|
+
</xsl:element>
|
|
559
|
+
</xsl:template>
|
|
560
|
+
|
|
561
|
+
<xsl:template match="*[@first]//*[local-name()='references'][not(@normative='true')]" mode="multi_columns">
|
|
562
|
+
<xsl:for-each select="//*[local-name()='doc-container'][position() > 1]">
|
|
563
|
+
<!--<bookmark id="{.//*[local-name()='references'][not(@normative='true')]/@id}"/>-->
|
|
564
|
+
<xsl:element name="bookmark" namespace="https://www.metanorma.org/ns/bipm">
|
|
565
|
+
<xsl:attribute name="id"><xsl:value-of select=".//*[local-name()='references'][not(@normative='true')]/@id"/></xsl:attribute>
|
|
566
|
+
</xsl:element>
|
|
567
|
+
</xsl:for-each>
|
|
568
|
+
<xsl:apply-templates mode="multi_columns"/>
|
|
569
|
+
</xsl:template>
|
|
570
|
+
|
|
571
|
+
<xsl:template match="*[@first]//*[local-name()='references'][not(@normative='true')]/*" mode="multi_columns">
|
|
572
|
+
<xsl:variable name="number_"><xsl:number count="*"/></xsl:variable>
|
|
573
|
+
<xsl:variable name="number" select="number(normalize-space($number_))"/>
|
|
574
|
+
<xsl:element name="cross-align" namespace="https://www.metanorma.org/ns/bipm">
|
|
575
|
+
<xsl:copy-of select="@displayorder"/>
|
|
576
|
+
<xsl:element name="align-cell" namespace="https://www.metanorma.org/ns/bipm">
|
|
577
|
+
<xsl:apply-templates select="." />
|
|
578
|
+
</xsl:element>
|
|
579
|
+
|
|
580
|
+
<xsl:for-each select="//*[local-name()='doc-container'][position() > 1]">
|
|
581
|
+
|
|
582
|
+
<xsl:element name="align-cell" namespace="https://www.metanorma.org/ns/bipm">
|
|
583
|
+
<xsl:apply-templates select="(.//*[local-name()='references'][not(@normative='true')]/*)[$number]"/>
|
|
584
|
+
</xsl:element>
|
|
585
|
+
</xsl:for-each>
|
|
586
|
+
</xsl:element>
|
|
587
|
+
</xsl:template>
|
|
588
|
+
<!-- End of References -->
|
|
589
|
+
|
|
590
|
+
<xsl:template match="*[@first]//*[local-name()='annex']" mode="multi_columns">
|
|
591
|
+
<xsl:variable name="number_"><xsl:number /></xsl:variable>
|
|
592
|
+
<xsl:variable name="number" select="number(normalize-space($number_))"/>
|
|
593
|
+
<xsl:for-each select="//*[local-name()='doc-container'][position() > 1]">
|
|
594
|
+
|
|
595
|
+
<!--<bookmark id="{(.//*[local-name()='annex'])[$number]/@id}"/>-->
|
|
596
|
+
<xsl:element name="bookmark" namespace="https://www.metanorma.org/ns/bipm">
|
|
597
|
+
<xsl:attribute name="id"><xsl:value-of select=".//*[local-name()='annex'][$number]/@id"/></xsl:attribute>
|
|
598
|
+
</xsl:element>
|
|
599
|
+
</xsl:for-each>
|
|
600
|
+
<xsl:apply-templates mode="multi_columns"/>
|
|
601
|
+
</xsl:template>
|
|
602
|
+
|
|
603
|
+
<!-- =================== -->
|
|
604
|
+
<!-- End Two columns layout -->
|
|
605
|
+
<!-- =================== -->
|
|
606
|
+
|
|
607
|
+
</xsl:stylesheet>
|
|
608
|
+
XSLT
|
|
609
|
+
end
|
|
610
|
+
|
|
611
|
+
def initialize(options)
|
|
612
|
+
options[:align_cross_elements] ||= %w(note p)
|
|
613
|
+
@align_cross_elements = " #{options[:align_cross_elements].join(' ')} "
|
|
614
|
+
@flavor = options[:flavor]
|
|
615
|
+
@outdir = options[:outdir]
|
|
616
|
+
@converter_opt = options[:converter_options]
|
|
617
|
+
end
|
|
618
|
+
|
|
619
|
+
def htmlconv
|
|
620
|
+
x = Asciidoctor.load nil, backend: @flavor
|
|
621
|
+
x.converter.html_converter(@converter_opt)
|
|
622
|
+
end
|
|
623
|
+
|
|
624
|
+
def to_bilingual(input)
|
|
625
|
+
presxml = Nokogiri::XML(input)
|
|
626
|
+
doc_first_input = xmldoc(presxml.at("//xmlns:doc-container[1]"))
|
|
627
|
+
doc_first_step1 =
|
|
628
|
+
Nokogiri::XSLT(flatxml_step1("first", @align_cross_elements))
|
|
629
|
+
.transform(doc_first_input)
|
|
630
|
+
doc_first = Nokogiri::XSLT(flatxml_step2).transform(doc_first_step1)
|
|
631
|
+
docs_slave_input = presxml.xpath("//xmlns:doc-container[position() > 1]")
|
|
632
|
+
.map do |x|
|
|
633
|
+
xmldoc(x)
|
|
634
|
+
end
|
|
635
|
+
docs_slave_step1 = docs_slave_input.map do |x|
|
|
636
|
+
Nokogiri::XSLT(flatxml_step1("slave",
|
|
637
|
+
@align_cross_elements)).transform(x)
|
|
638
|
+
end
|
|
639
|
+
docs_slave = docs_slave_step1.map do |x|
|
|
640
|
+
Nokogiri::XSLT(flatxml_step2).transform(x)
|
|
641
|
+
end
|
|
642
|
+
doc = Nokogiri::XML("<root xmlns='http://metanorma.org'/>")
|
|
643
|
+
doc.root << doc_first.root
|
|
644
|
+
docs_slave.each { |x| doc.root << x.root }
|
|
645
|
+
ret = Nokogiri::XSLT(two_column).transform(doc)
|
|
646
|
+
presxml.at("//xmlns:doc-container[1]").replace(ret.root.children)
|
|
647
|
+
to_xml(presxml)
|
|
648
|
+
end
|
|
649
|
+
|
|
650
|
+
def to_html(presxml)
|
|
651
|
+
xml = Nokogiri::XML(File.read(presxml))
|
|
652
|
+
doc = xml.at("//xmlns:doc-container[1]/*")
|
|
653
|
+
# will need to concatenate preface if present
|
|
654
|
+
out = File.join(@outdir, "collection.bilingual.presentation.xml")
|
|
655
|
+
File.open(out, "w:utf-8") { |f| f.write to_xml(doc) }
|
|
656
|
+
htmlconv.convert(out)
|
|
657
|
+
end
|
|
658
|
+
end
|
|
659
|
+
end
|
|
660
|
+
end
|