metanorma-itu 2.4.7 → 2.4.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,11 +1,9 @@
1
- <?xml version="1.0" encoding="UTF-8"?><xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:itu="https://www.metanorma.org/ns/itu" xmlns:mathml="http://www.w3.org/1998/Math/MathML" xmlns:xalan="http://xml.apache.org/xalan" xmlns:fox="http://xmlgraphics.apache.org/fop/extensions" xmlns:java="http://xml.apache.org/xalan/java" exclude-result-prefixes="java" version="1.0">
1
+ <?xml version="1.0" encoding="UTF-8"?><xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:itu="https://www.metanorma.org/ns/itu" xmlns:mathml="http://www.w3.org/1998/Math/MathML" xmlns:xalan="http://xml.apache.org/xalan" xmlns:fox="http://xmlgraphics.apache.org/fop/extensions" xmlns:redirect="http://xml.apache.org/xalan/redirect" xmlns:java="http://xml.apache.org/xalan/java" exclude-result-prefixes="java redirect" version="1.0">
2
2
 
3
3
  <xsl:output method="xml" encoding="UTF-8" indent="no"/>
4
4
 
5
5
  <xsl:key name="kfn" match="*[local-name() = 'fn'][not(ancestor::*[(local-name() = 'table' or local-name() = 'figure' or local-name() = 'localized-strings')] and not(ancestor::*[local-name() = 'name']))]" use="@reference"/>
6
6
 
7
- <xsl:variable name="namespace_full">https://www.metanorma.org/ns/itu</xsl:variable>
8
-
9
7
  <xsl:variable name="debug">false</xsl:variable>
10
8
 
11
9
  <xsl:variable name="docidentifier_ITU" select="/itu:itu-standard/itu:bibdata/itu:docidentifier[@type = 'ITU']"/>
@@ -1898,9 +1896,9 @@
1898
1896
  </xsl:variable>
1899
1897
  <xsl:element name="{$element-name}">
1900
1898
  <xsl:attribute name="margin-top">6pt</xsl:attribute>
1901
- <xsl:if test="@keep-with-next = 'true'">
1902
- <xsl:attribute name="keep-with-next">always</xsl:attribute>
1903
- </xsl:if>
1899
+
1900
+ <xsl:call-template name="setKeepAttributes"/>
1901
+
1904
1902
  <xsl:if test="@class='supertitle'">
1905
1903
  <xsl:attribute name="space-before">36pt</xsl:attribute>
1906
1904
  <xsl:attribute name="margin-bottom">24pt</xsl:attribute>
@@ -2670,71 +2668,11 @@
2670
2668
  </xsl:if>
2671
2669
  </xsl:template>
2672
2670
 
2673
- <!-- background cover image -->
2674
- <xsl:template name="insertBackgroundPageImage">
2675
- <xsl:param name="number">1</xsl:param>
2676
- <xsl:param name="name">coverpage-image</xsl:param>
2677
- <xsl:variable name="num" select="number($number)"/>
2678
- <!-- background image -->
2679
- <fo:block-container absolute-position="fixed" left="0mm" top="0mm" font-size="0" id="__internal_layout__coverpage_{$name}_{$number}_{generate-id()}">
2680
- <fo:block>
2681
- <xsl:for-each select="/itu:itu-standard/itu:metanorma-extension/itu:presentation-metadata[itu:name = $name][1]/itu:value/itu:image[$num]">
2682
- <xsl:choose>
2683
- <xsl:when test="*[local-name() = 'svg'] or java:endsWith(java:java.lang.String.new(@src), '.svg')">
2684
- <fo:instream-foreign-object fox:alt-text="Image Front">
2685
- <xsl:attribute name="content-height"><xsl:value-of select="$pageHeight"/>mm</xsl:attribute>
2686
- <xsl:call-template name="getSVG"/>
2687
- </fo:instream-foreign-object>
2688
- </xsl:when>
2689
- <xsl:when test="starts-with(@src, 'data:application/pdf;base64')">
2690
- <fo:external-graphic src="{@src}" fox:alt-text="Image Front"/>
2691
- </xsl:when>
2692
- <xsl:otherwise> <!-- bitmap image -->
2693
- <xsl:variable name="coverimage_src" select="normalize-space(@src)"/>
2694
- <xsl:if test="$coverimage_src != ''">
2695
- <xsl:variable name="coverpage">
2696
- <xsl:call-template name="getImageURL">
2697
- <xsl:with-param name="src" select="$coverimage_src"/>
2698
- </xsl:call-template>
2699
- </xsl:variable>
2700
- <!-- <xsl:variable name="coverpage" select="concat('url(file:',$basepath, 'coverpage1.png', ')')"/> --> <!-- for DEBUG -->
2701
- <fo:external-graphic src="{$coverpage}" width="{$pageWidth}mm" content-height="scale-to-fit" scaling="uniform" fox:alt-text="Image Front"/>
2702
- </xsl:if>
2703
- </xsl:otherwise>
2704
- </xsl:choose>
2705
- </xsl:for-each>
2706
- </fo:block>
2707
- </fo:block-container>
2708
- </xsl:template>
2709
-
2710
- <xsl:template name="getImageURL">
2711
- <xsl:param name="src"/>
2712
- <xsl:choose>
2713
- <xsl:when test="starts-with($src, 'data:image')">
2714
- <xsl:value-of select="$src"/>
2715
- </xsl:when>
2716
- <xsl:otherwise>
2717
- <xsl:value-of select="concat('url(file:///',$basepath, $src, ')')"/>
2718
- </xsl:otherwise>
2719
- </xsl:choose>
2720
- </xsl:template>
2721
-
2722
- <xsl:template name="getSVG">
2723
- <xsl:choose>
2724
- <xsl:when test="*[local-name() = 'svg']">
2725
- <xsl:apply-templates select="*[local-name() = 'svg']" mode="svg_update"/>
2726
- </xsl:when>
2727
- <xsl:otherwise>
2728
- <xsl:variable name="svg_content" select="document(@src)"/>
2729
- <xsl:for-each select="xalan:nodeset($svg_content)/node()">
2730
- <xsl:apply-templates select="." mode="svg_update"/>
2731
- </xsl:for-each>
2732
- </xsl:otherwise>
2733
- </xsl:choose>
2734
- </xsl:template>
2735
-
2736
2671
  <xsl:strip-space elements="itu:xref"/>
2737
2672
 
2673
+ <xsl:variable name="namespace_full" select="namespace-uri(/*)"/> <!-- example: https://www.metanorma.org/ns/iso -->
2674
+ <xsl:variable name="root_element" select="local-name(/*)"/> <!-- example: iso-standard -->
2675
+
2738
2676
  <!-- external parameters -->
2739
2677
 
2740
2678
  <xsl:param name="svg_images"/> <!-- svg images array -->
@@ -2742,6 +2680,7 @@
2742
2680
  <xsl:param name="basepath"/> <!-- base path for images -->
2743
2681
  <xsl:param name="inputxml_basepath"/> <!-- input xml file path -->
2744
2682
  <xsl:param name="inputxml_filename"/> <!-- input xml file name -->
2683
+ <xsl:param name="output_path"/> <!-- output PDF file name -->
2745
2684
  <xsl:param name="external_index"/><!-- path to index xml, generated on 1st pass, based on FOP Intermediate Format -->
2746
2685
  <xsl:param name="syntax-highlight">false</xsl:param> <!-- syntax highlighting feature, default - off -->
2747
2686
  <xsl:param name="add_math_as_text">true</xsl:param> <!-- add math in text behind svg formula, to copy-paste formula from PDF as text -->
@@ -2894,6 +2833,15 @@
2894
2833
  </xsl:variable>
2895
2834
  <xsl:variable name="marginBottom" select="normalize-space($marginBottom_)"/>
2896
2835
 
2836
+ <xsl:variable name="layout_columns_default">1</xsl:variable>
2837
+ <xsl:variable name="layout_columns_" select="normalize-space((//*[contains(local-name(), '-standard')])[1]/*[local-name() = 'metanorma-extension']/*[local-name() = 'presentation-metadata']/*[local-name() = 'layout-columns'])"/>
2838
+ <xsl:variable name="layout_columns">
2839
+ <xsl:choose>
2840
+ <xsl:when test="$layout_columns_ != ''"><xsl:value-of select="$layout_columns_"/></xsl:when>
2841
+ <xsl:otherwise><xsl:value-of select="$layout_columns_default"/></xsl:otherwise>
2842
+ </xsl:choose>
2843
+ </xsl:variable>
2844
+
2897
2845
  <!-- Note 2: almost all localized string determined in the element //localized-strings in metanorma xml, but there are a few cases when:
2898
2846
  - string didn't determined yet
2899
2847
  - we need to put the string on two-languages (for instance, on English and French both), but xml contains only localized strings for one language
@@ -3858,9 +3806,10 @@
3858
3806
  <xsl:attribute name="content-height">100%</xsl:attribute>
3859
3807
  <xsl:attribute name="scaling">uniform</xsl:attribute>
3860
3808
 
3861
- <xsl:attribute name="width">75%</xsl:attribute>
3862
3809
  <xsl:attribute name="content-width">scale-to-fit</xsl:attribute>
3863
3810
 
3811
+ <xsl:attribute name="width">75%</xsl:attribute>
3812
+
3864
3813
  </xsl:attribute-set>
3865
3814
 
3866
3815
  <xsl:attribute-set name="tt-style">
@@ -4429,6 +4378,58 @@
4429
4378
  </xsl:for-each>
4430
4379
  </xsl:template>
4431
4380
 
4381
+ <xsl:template name="processPrefaceSectionsDefault_items">
4382
+
4383
+ <xsl:variable name="updated_xml_step_move_pagebreak">
4384
+
4385
+ <xsl:element name="{$root_element}" namespace="{$namespace_full}">
4386
+
4387
+ <xsl:call-template name="copyCommonElements"/>
4388
+
4389
+ <xsl:element name="preface" namespace="{$namespace_full}"> <!-- save context element -->
4390
+ <xsl:element name="page_sequence" namespace="{$namespace_full}">
4391
+ <xsl:for-each select="/*/*[local-name()='preface']/*[not(local-name() = 'note' or local-name() = 'admonition')]">
4392
+ <xsl:sort select="@displayorder" data-type="number"/>
4393
+ <xsl:apply-templates select="." mode="update_xml_step_move_pagebreak"/>
4394
+ </xsl:for-each>
4395
+ </xsl:element>
4396
+ </xsl:element>
4397
+ </xsl:element>
4398
+ </xsl:variable>
4399
+
4400
+ <xsl:variable name="updated_xml_step_move_pagebreak_filename" select="concat($output_path,'_preface_', java:getTime(java:java.util.Date.new()), '.xml')"/>
4401
+ <!-- <xsl:message>updated_xml_step_move_pagebreak_filename=<xsl:value-of select="$updated_xml_step_move_pagebreak_filename"/></xsl:message>
4402
+ <xsl:message>start write updated_xml_step_move_pagebreak_filename</xsl:message> -->
4403
+ <redirect:write file="{$updated_xml_step_move_pagebreak_filename}">
4404
+ <xsl:copy-of select="$updated_xml_step_move_pagebreak"/>
4405
+ </redirect:write>
4406
+ <!-- <xsl:message>end write updated_xml_step_move_pagebreak_filename</xsl:message> -->
4407
+
4408
+ <xsl:copy-of select="document($updated_xml_step_move_pagebreak_filename)"/>
4409
+
4410
+ <!-- TODO: instead of
4411
+ <xsl:for-each select=".//*[local-name() = 'page_sequence'][normalize-space() != '' or .//image or .//svg]">
4412
+ in each template, add removing empty page_sequence here
4413
+ -->
4414
+
4415
+ <xsl:if test="$debug = 'true'">
4416
+ <redirect:write file="page_sequence_preface.xml">
4417
+ <xsl:copy-of select="document($updated_xml_step_move_pagebreak_filename)"/>
4418
+ </redirect:write>
4419
+ </xsl:if>
4420
+
4421
+ <!-- <xsl:message>start delete updated_xml_step_move_pagebreak_filename</xsl:message> -->
4422
+ <xsl:call-template name="deleteFile">
4423
+ <xsl:with-param name="filepath" select="$updated_xml_step_move_pagebreak_filename"/>
4424
+ </xsl:call-template>
4425
+ <!-- <xsl:message>end delete updated_xml_step_move_pagebreak_filename</xsl:message> -->
4426
+ </xsl:template> <!-- END: processPrefaceSectionsDefault_items -->
4427
+
4428
+ <xsl:template name="copyCommonElements">
4429
+ <!-- copy bibdata, localized-strings, metanorma-extension and boilerplate -->
4430
+ <xsl:copy-of select="/*/*[local-name() != 'preface' and local-name() != 'sections' and local-name() != 'annex' and local-name() != 'bibliography']"/>
4431
+ </xsl:template>
4432
+
4432
4433
  <xsl:template name="processMainSectionsDefault">
4433
4434
  <xsl:for-each select="/*/*[local-name()='sections']/* | /*/*[local-name()='bibliography']/*[local-name()='references'][@normative='true']">
4434
4435
  <xsl:sort select="@displayorder" data-type="number"/>
@@ -4445,36 +4446,94 @@
4445
4446
  <xsl:sort select="@displayorder" data-type="number"/>
4446
4447
  <xsl:apply-templates select="."/>
4447
4448
  </xsl:for-each>
4448
- </xsl:template>
4449
+ </xsl:template><!-- END: processMainSectionsDefault -->
4450
+
4451
+ <!-- Example:
4452
+ <iso-standard>
4453
+ <sections>
4454
+ <page_sequence>
4455
+ <clause...
4456
+ </page_sequence>
4457
+ <page_sequence>
4458
+ <clause...
4459
+ </page_sequence>
4460
+ </sections>
4461
+ <page_sequence>
4462
+ <annex ..
4463
+ </page_sequence>
4464
+ <page_sequence>
4465
+ <annex ..
4466
+ </page_sequence>
4467
+ </iso-standard>
4468
+ -->
4469
+ <xsl:template name="processMainSectionsDefault_items">
4449
4470
 
4450
- <xsl:template name="processMainSectionsDefault_flatxml">
4451
- <xsl:for-each select="/*/*[local-name()='sections']/* | /*/*[local-name()='bibliography']/*[local-name()='references'][@normative='true']">
4452
- <xsl:sort select="@displayorder" data-type="number"/>
4453
- <xsl:variable name="flatxml">
4454
- <xsl:apply-templates select="." mode="flatxml"/>
4455
- </xsl:variable>
4456
- <!-- debug_flatxml='<xsl:copy-of select="$flatxml"/>' -->
4457
- <xsl:apply-templates select="xalan:nodeset($flatxml)/*"/>
4471
+ <xsl:variable name="updated_xml_step_move_pagebreak">
4458
4472
 
4459
- </xsl:for-each>
4473
+ <xsl:element name="{$root_element}" namespace="{$namespace_full}">
4460
4474
 
4461
- <xsl:for-each select="/*/*[local-name()='annex']">
4462
- <xsl:sort select="@displayorder" data-type="number"/>
4463
- <xsl:variable name="flatxml">
4464
- <xsl:apply-templates select="." mode="flatxml"/>
4465
- </xsl:variable>
4466
- <!-- debug_flatxml='<xsl:copy-of select="$flatxml"/>' -->
4467
- <xsl:apply-templates select="xalan:nodeset($flatxml)/*"/>
4468
- </xsl:for-each>
4475
+ <xsl:call-template name="copyCommonElements"/>
4469
4476
 
4470
- <xsl:for-each select="/*/*[local-name()='bibliography']/*[not(@normative='true')] | /*/*[local-name()='bibliography']/*[local-name()='clause'][*[local-name()='references'][not(@normative='true')]]">
4471
- <xsl:sort select="@displayorder" data-type="number"/>
4472
- <xsl:variable name="flatxml">
4473
- <xsl:apply-templates select="." mode="flatxml"/>
4474
- </xsl:variable>
4475
- <!-- debug_flatxml='<xsl:copy-of select="$flatxml"/>' -->
4476
- <xsl:apply-templates select="xalan:nodeset($flatxml)/*"/>
4477
- </xsl:for-each>
4477
+ <xsl:element name="sections" namespace="{$namespace_full}"> <!-- save context element -->
4478
+ <xsl:element name="page_sequence" namespace="{$namespace_full}">
4479
+ <xsl:for-each select="/*/*[local-name()='sections']/* | /*/*[local-name()='bibliography']/*[local-name()='references'][@normative='true']">
4480
+ <xsl:sort select="@displayorder" data-type="number"/>
4481
+ <xsl:apply-templates select="." mode="update_xml_step_move_pagebreak"/>
4482
+
4483
+ </xsl:for-each>
4484
+ </xsl:element>
4485
+ </xsl:element>
4486
+
4487
+ <xsl:element name="page_sequence" namespace="{$namespace_full}">
4488
+ <xsl:for-each select="/*/*[local-name()='annex']">
4489
+ <xsl:sort select="@displayorder" data-type="number"/>
4490
+ <xsl:apply-templates select="." mode="update_xml_step_move_pagebreak"/>
4491
+ </xsl:for-each>
4492
+ </xsl:element>
4493
+
4494
+ <xsl:element name="page_sequence" namespace="{$namespace_full}">
4495
+ <xsl:element name="bibliography" namespace="{$namespace_full}"> <!-- save context element -->
4496
+ <xsl:for-each select="/*/*[local-name()='bibliography']/*[not(@normative='true')] | /*/*[local-name()='bibliography']/*[local-name()='clause'][*[local-name()='references'][not(@normative='true')]]">
4497
+ <xsl:sort select="@displayorder" data-type="number"/>
4498
+ <xsl:apply-templates select="." mode="update_xml_step_move_pagebreak"/>
4499
+ </xsl:for-each>
4500
+ </xsl:element>
4501
+ </xsl:element>
4502
+ </xsl:element>
4503
+ </xsl:variable>
4504
+
4505
+ <xsl:variable name="updated_xml_step_move_pagebreak_filename" select="concat($output_path,'_main_', java:getTime(java:java.util.Date.new()), '.xml')"/>
4506
+
4507
+ <redirect:write file="{$updated_xml_step_move_pagebreak_filename}">
4508
+ <xsl:copy-of select="$updated_xml_step_move_pagebreak"/>
4509
+ </redirect:write>
4510
+
4511
+ <xsl:copy-of select="document($updated_xml_step_move_pagebreak_filename)"/>
4512
+
4513
+ <xsl:if test="$debug = 'true'">
4514
+ <redirect:write file="page_sequence_main.xml">
4515
+ <xsl:copy-of select="document($updated_xml_step_move_pagebreak_filename)"/>
4516
+ </redirect:write>
4517
+ </xsl:if>
4518
+
4519
+ <xsl:call-template name="deleteFile">
4520
+ <xsl:with-param name="filepath" select="$updated_xml_step_move_pagebreak_filename"/>
4521
+ </xsl:call-template>
4522
+ </xsl:template> <!-- END: processMainSectionsDefault_items -->
4523
+
4524
+ <xsl:template name="deleteFile">
4525
+ <xsl:param name="filepath"/>
4526
+ <xsl:variable name="xml_file" select="java:java.io.File.new($filepath)"/>
4527
+ <xsl:variable name="xml_file_path" select="java:toPath($xml_file)"/>
4528
+ <xsl:variable name="deletefile" select="java:java.nio.file.Files.deleteIfExists($xml_file_path)"/>
4529
+ </xsl:template>
4530
+
4531
+ <xsl:template name="getPageSequenceOrientation">
4532
+ <xsl:variable name="previous_orientation" select="preceding-sibling::*[local-name() = 'page_sequence'][@orientation][1]/@orientation"/>
4533
+ <xsl:choose>
4534
+ <xsl:when test="@orientation = 'landscape'">-<xsl:value-of select="@orientation"/></xsl:when>
4535
+ <xsl:when test="$previous_orientation = 'landscape' and not(@orientation = 'portrait')">-<xsl:value-of select="$previous_orientation"/></xsl:when>
4536
+ </xsl:choose>
4478
4537
  </xsl:template>
4479
4538
 
4480
4539
  <xsl:variable name="regex_standard_reference">([A-Z]{2,}(/[A-Z]{2,})* \d+(-\d+)*(:\d{4})?)</xsl:variable>
@@ -4686,7 +4745,9 @@
4686
4745
  </xsl:for-each>
4687
4746
  </xsl:template>
4688
4747
 
4689
- <xsl:param name="table_only_with_id"/><!-- Example: table1, for table auto-layout algorithm -->
4748
+ <!-- for table auto-layout algorithm -->
4749
+ <xsl:param name="table_only_with_id"/> <!-- Example: 'table1' -->
4750
+ <xsl:param name="table_only_with_ids"/> <!-- Example: 'table1 table2 table3 ' -->
4690
4751
 
4691
4752
  <xsl:template match="*[local-name()='table']" priority="2">
4692
4753
  <xsl:choose>
@@ -4694,6 +4755,10 @@
4694
4755
  <xsl:call-template name="table"/>
4695
4756
  </xsl:when>
4696
4757
  <xsl:when test="$table_only_with_id != ''"><fo:block/><!-- to prevent empty fo:block-container --></xsl:when>
4758
+ <xsl:when test="$table_only_with_ids != '' and contains($table_only_with_ids, concat(@id, ' '))">
4759
+ <xsl:call-template name="table"/>
4760
+ </xsl:when>
4761
+ <xsl:when test="$table_only_with_ids != ''"><fo:block/><!-- to prevent empty fo:block-container --></xsl:when>
4697
4762
  <xsl:otherwise>
4698
4763
  <xsl:call-template name="table"/>
4699
4764
  </xsl:otherwise>
@@ -4759,6 +4824,7 @@
4759
4824
  <xsl:variable name="margin-side">
4760
4825
  <xsl:choose>
4761
4826
  <xsl:when test="$isApplyAutolayoutAlgorithm = 'true'">0</xsl:when>
4827
+ <xsl:when test="$isApplyAutolayoutAlgorithm = 'skip'">0</xsl:when>
4762
4828
  <xsl:when test="sum(xalan:nodeset($colwidths)//column) &gt; 75">15</xsl:when>
4763
4829
  <xsl:otherwise>0</xsl:otherwise>
4764
4830
  </xsl:choose>
@@ -4815,7 +4881,9 @@
4815
4881
 
4816
4882
  <xsl:variable name="isNoteOrFnExist" select="./*[local-name()='note'][not(@type = 'units')] or ./*[local-name()='example'] or .//*[local-name()='fn'][local-name(..) != 'name'] or ./*[local-name()='source']"/>
4817
4883
  <xsl:if test="$isNoteOrFnExist = 'true'">
4818
- <xsl:attribute name="border-bottom">0pt solid black</xsl:attribute><!-- set 0pt border, because there is a separete table below for footer -->
4884
+
4885
+ <xsl:attribute name="border-bottom">0pt solid black</xsl:attribute><!-- set 0pt border, because there is a separete table below for footer -->
4886
+
4819
4887
  </xsl:if>
4820
4888
 
4821
4889
  <xsl:choose>
@@ -4872,13 +4940,14 @@
4872
4940
  </fo:table>
4873
4941
 
4874
4942
  <xsl:variable name="colgroup" select="*[local-name()='colgroup']"/>
4875
- <xsl:for-each select="*[local-name()='tbody']"><!-- select context to tbody -->
4876
- <xsl:call-template name="insertTableFooterInSeparateTable">
4877
- <xsl:with-param name="table_attributes" select="$table_attributes"/>
4878
- <xsl:with-param name="colwidths" select="$colwidths"/>
4879
- <xsl:with-param name="colgroup" select="$colgroup"/>
4880
- </xsl:call-template>
4881
- </xsl:for-each>
4943
+
4944
+ <xsl:for-each select="*[local-name()='tbody']"><!-- select context to tbody -->
4945
+ <xsl:call-template name="insertTableFooterInSeparateTable">
4946
+ <xsl:with-param name="table_attributes" select="$table_attributes"/>
4947
+ <xsl:with-param name="colwidths" select="$colwidths"/>
4948
+ <xsl:with-param name="colgroup" select="$colgroup"/>
4949
+ </xsl:call-template>
4950
+ </xsl:for-each>
4882
4951
 
4883
4952
  <xsl:if test="*[local-name()='bookmark']"> <!-- special case: table/bookmark -->
4884
4953
  <fo:block keep-with-previous="always" line-height="0.1">
@@ -5010,6 +5079,7 @@
5010
5079
  <xsl:when test="$isApplyAutolayoutAlgorithm = 'true'">
5011
5080
  <xsl:call-template name="get-calculated-column-widths-autolayout-algorithm"/>
5012
5081
  </xsl:when>
5082
+ <xsl:when test="$isApplyAutolayoutAlgorithm = 'skip'"/>
5013
5083
  <xsl:otherwise>
5014
5084
  <xsl:call-template name="calculate-column-widths-proportional">
5015
5085
  <xsl:with-param name="cols-count" select="$cols-count"/>
@@ -5267,8 +5337,10 @@
5267
5337
  <width_min><xsl:value-of select="@width_min"/></width_min>
5268
5338
  <e><xsl:value-of select="$d * $W div $D"/></e>
5269
5339
  <!-- set the column's width to the minimum width plus d times W over D. -->
5340
+ <xsl:variable name="column_width_" select="round(@width_min + $d * $W div $D)"/> <!-- * 10 -->
5341
+ <xsl:variable name="column_width" select="$column_width_*($column_width_ &gt;= 0) - $column_width_*($column_width_ &lt; 0)"/> <!-- absolute value -->
5270
5342
  <column divider="100">
5271
- <xsl:value-of select="round(@width_min + $d * $W div $D)"/> <!-- * 10 -->
5343
+ <xsl:value-of select="$column_width"/>
5272
5344
  </column>
5273
5345
  </xsl:for-each>
5274
5346
 
@@ -5690,6 +5762,22 @@
5690
5762
 
5691
5763
  <xsl:call-template name="refine_table-header-cell-style"/>
5692
5764
 
5765
+ <!-- experimental feature, see https://github.com/metanorma/metanorma-plateau/issues/30#issuecomment-2145461828 -->
5766
+ <!-- <xsl:choose>
5767
+ <xsl:when test="count(node()) = 1 and *[local-name() = 'span'][contains(@style, 'text-orientation')]">
5768
+ <fo:block-container reference-orientation="270">
5769
+ <fo:block role="SKIP" text-align="start">
5770
+ <xsl:apply-templates />
5771
+ </fo:block>
5772
+ </fo:block-container>
5773
+ </xsl:when>
5774
+ <xsl:otherwise>
5775
+ <fo:block role="SKIP">
5776
+ <xsl:apply-templates />
5777
+ </fo:block>
5778
+ </xsl:otherwise>
5779
+ </xsl:choose> -->
5780
+
5693
5781
  <fo:block role="SKIP">
5694
5782
  <xsl:apply-templates/>
5695
5783
  </fo:block>
@@ -5920,7 +6008,7 @@
5920
6008
  <xsl:copy-of select="node()"/>
5921
6009
  </fn>
5922
6010
  </xsl:for-each>
5923
- <xsl:for-each select="ancestor::*[contains(local-name(), '-standard')]/*[local-name()='boilerplate']/* | 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']/*">
6011
+ <xsl:for-each select="ancestor::*[contains(local-name(), '-standard')]/*[local-name()='boilerplate']/* | 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']/*">
5924
6012
  <xsl:sort select="@displayorder" data-type="number"/>
5925
6013
  <!-- commented:
5926
6014
  .//*[local-name() = 'bibitem'][ancestor::*[local-name() = 'references']]/*[local-name() = 'note'] |
@@ -6208,6 +6296,10 @@
6208
6296
  <xsl:call-template name="dl"/>
6209
6297
  </xsl:when>
6210
6298
  <xsl:when test="$table_only_with_id != ''"><fo:block/><!-- to prevent empty fo:block-container --></xsl:when>
6299
+ <xsl:when test="$table_only_with_ids != '' and contains($table_only_with_ids, concat(@id, ' '))">
6300
+ <xsl:call-template name="dl"/>
6301
+ </xsl:when>
6302
+ <xsl:when test="$table_only_with_ids != ''"><fo:block/><!-- to prevent empty fo:block-container --></xsl:when>
6211
6303
  <xsl:otherwise>
6212
6304
  <xsl:call-template name="dl"/>
6213
6305
  </xsl:otherwise>
@@ -6371,7 +6463,7 @@
6371
6463
 
6372
6464
  <!-- create virtual html table for dl/[dt and dd] -->
6373
6465
  <xsl:variable name="simple-table">
6374
-
6466
+ <!-- initial='<xsl:copy-of select="."/>' -->
6375
6467
  <xsl:variable name="dl_table">
6376
6468
  <tbody>
6377
6469
  <xsl:apply-templates mode="dl_if">
@@ -9114,17 +9206,19 @@
9114
9206
  </xsl:variable>
9115
9207
  <xsl:value-of select="concat('scale=', $scale,', indent=', $indent)"/>
9116
9208
  </fo:block> -->
9117
- <fo:external-graphic src="{$src}" fox:alt-text="Image {@alt}" xsl:use-attribute-sets="image-graphic-style">
9118
- <xsl:if test="not(@mimetype = 'image/svg+xml') and (../*[local-name() = 'name'] or parent::*[local-name() = 'figure'][@unnumbered = 'true']) and not(ancestor::*[local-name() = 'table'])">
9119
9209
 
9120
- <xsl:call-template name="setImageWidthHeight"/>
9210
+ <fo:external-graphic src="{$src}" fox:alt-text="Image {@alt}">
9121
9211
 
9122
- <xsl:choose>
9123
- <xsl:when test="@width != '' and @width != 'auto' and @height != '' and @height != 'auto'">
9124
- <xsl:attribute name="scaling">non-uniform</xsl:attribute>
9125
- </xsl:when>
9126
- <xsl:otherwise>
9212
+ <xsl:choose>
9213
+ <!-- default -->
9214
+ <xsl:when test="((@width = 'auto' or @width = 'text-width' or @width = 'full-page-width' or @width = 'narrow') and @height = 'auto') or (normalize-space(@width) = '' and normalize-space(@height) = '') ">
9215
+ <!-- add attribute for automatic scaling -->
9216
+ <xsl:variable name="image-graphic-style_attributes">
9217
+ <attributes xsl:use-attribute-sets="image-graphic-style"/>
9218
+ </xsl:variable>
9219
+ <xsl:copy-of select="xalan:nodeset($image-graphic-style_attributes)/attributes/@*"/>
9127
9220
 
9221
+ <xsl:if test="not(@mimetype = 'image/svg+xml') and not(ancestor::*[local-name() = 'table'])">
9128
9222
  <xsl:variable name="scale">
9129
9223
  <xsl:call-template name="getImageScale">
9130
9224
  <xsl:with-param name="indent" select="$indent"/>
@@ -9138,10 +9232,30 @@
9138
9232
  <xsl:if test="number($scale) &lt; 100">
9139
9233
  <xsl:attribute name="content-width"><xsl:value-of select="number($scale) * number($scaleRatio)"/>%</xsl:attribute>
9140
9234
  </xsl:if>
9141
- </xsl:otherwise>
9142
- </xsl:choose>
9235
+ </xsl:if>
9143
9236
 
9144
- </xsl:if>
9237
+ </xsl:when> <!-- default -->
9238
+ <xsl:otherwise>
9239
+
9240
+ <xsl:variable name="width_height_">
9241
+ <attributes>
9242
+ <xsl:call-template name="setImageWidthHeight"/>
9243
+ </attributes>
9244
+ </xsl:variable>
9245
+ <xsl:variable name="width_height" select="xalan:nodeset($width_height_)"/>
9246
+
9247
+ <xsl:copy-of select="$width_height/attributes/@*"/>
9248
+
9249
+ <xsl:if test="$width_height/attributes/@content-width != '' and $width_height/attributes/@content-height != ''">
9250
+ <xsl:attribute name="scaling">non-uniform</xsl:attribute>
9251
+ </xsl:if>
9252
+
9253
+ </xsl:otherwise>
9254
+ </xsl:choose>
9255
+
9256
+ <!--
9257
+ <xsl:if test="not(@mimetype = 'image/svg+xml') and (../*[local-name() = 'name'] or parent::*[local-name() = 'figure'][@unnumbered = 'true']) and not(ancestor::*[local-name() = 'table'])">
9258
+ -->
9145
9259
 
9146
9260
  </fo:external-graphic>
9147
9261
  </xsl:otherwise>
@@ -9167,7 +9281,7 @@
9167
9281
  <xsl:call-template name="setImageWidth"/>
9168
9282
  </xsl:variable>
9169
9283
  <xsl:if test="$width != ''">
9170
- <xsl:attribute name="width">
9284
+ <xsl:attribute name="content-width">
9171
9285
  <xsl:value-of select="$width"/>
9172
9286
  </xsl:attribute>
9173
9287
  </xsl:if>
@@ -9175,7 +9289,7 @@
9175
9289
  <xsl:call-template name="setImageHeight"/>
9176
9290
  </xsl:variable>
9177
9291
  <xsl:if test="$height != ''">
9178
- <xsl:attribute name="height">
9292
+ <xsl:attribute name="content-height">
9179
9293
  <xsl:value-of select="$height"/>
9180
9294
  </xsl:attribute>
9181
9295
  </xsl:if>
@@ -9213,6 +9327,15 @@
9213
9327
  <xsl:when test="@mimetype = 'image/svg+xml' and $images/images/image[@id = current()/@id]">
9214
9328
  <xsl:value-of select="$images/images/image[@id = current()/@id]/@src"/>
9215
9329
  </xsl:when>
9330
+ <!-- in WebP format, then convert image into PNG -->
9331
+ <xsl:when test="starts-with(@src, 'data:image/webp')">
9332
+ <xsl:variable name="src_png" select="java:org.metanorma.fop.utils.ImageUtils.convertWebPtoPNG(@src)"/>
9333
+ <xsl:value-of select="$src_png"/>
9334
+ </xsl:when>
9335
+ <xsl:when test="not(starts-with(@src, 'data:')) and (java:endsWith(java:java.lang.String.new(@src), '.webp') or java:endsWith(java:java.lang.String.new(@src), '.WEBP'))">
9336
+ <xsl:variable name="src_png" select="java:org.metanorma.fop.utils.ImageUtils.convertWebPtoPNG(@src)"/>
9337
+ <xsl:value-of select="concat('url(file:///',$basepath, $src_png, ')')"/>
9338
+ </xsl:when>
9216
9339
  <xsl:when test="not(starts-with(@src, 'data:'))">
9217
9340
  <xsl:value-of select="concat('url(file:///',$basepath, @src, ')')"/>
9218
9341
  </xsl:when>
@@ -11606,7 +11729,7 @@
11606
11729
  <!-- ========== -->
11607
11730
 
11608
11731
  <!-- main sections -->
11609
- <xsl:template match="/*/*[local-name() = 'sections']/*" priority="2">
11732
+ <xsl:template match="/*/*[local-name() = 'sections']/*" name="sections_node" priority="2">
11610
11733
 
11611
11734
  <fo:block>
11612
11735
  <xsl:call-template name="setId"/>
@@ -11618,6 +11741,11 @@
11618
11741
 
11619
11742
  </xsl:template>
11620
11743
 
11744
+ <!-- note: @top-level added in mode=" update_xml_step_move_pagebreak" -->
11745
+ <xsl:template match="*[local-name() = 'sections']/*[local-name() = 'page_sequence']/*[not(@top-level)]" priority="2">
11746
+ <xsl:call-template name="sections_node"/>
11747
+ </xsl:template>
11748
+
11621
11749
  <xsl:template name="sections_element_style">
11622
11750
 
11623
11751
  <xsl:if test="*[1][@class='supertitle']">
@@ -11629,7 +11757,7 @@
11629
11757
 
11630
11758
  </xsl:template> <!-- sections_element_style -->
11631
11759
 
11632
- <xsl:template match="//*[contains(local-name(), '-standard')]/*[local-name() = 'preface']/*" priority="2"> <!-- /*/*[local-name() = 'preface']/* -->
11760
+ <xsl:template match="//*[contains(local-name(), '-standard')]/*[local-name() = 'preface']/*" priority="2" name="preface_node"> <!-- /*/*[local-name() = 'preface']/* -->
11633
11761
 
11634
11762
  <fo:block break-after="page"/>
11635
11763
 
@@ -11639,7 +11767,11 @@
11639
11767
  </fo:block>
11640
11768
  </xsl:template>
11641
11769
 
11642
- <xsl:template match="*[local-name() = 'clause']">
11770
+ <xsl:template match="*[local-name() = 'preface']/*[local-name() = 'page_sequence']/*" priority="2"> <!-- /*/*[local-name() = 'preface']/* -->
11771
+ <xsl:call-template name="preface_node"/>
11772
+ </xsl:template>
11773
+
11774
+ <xsl:template match="*[local-name() = 'clause'][normalize-space() != '' or *[local-name() = 'figure'] or @id]" name="template_clause"> <!-- if clause isn't empty -->
11643
11775
  <fo:block>
11644
11776
  <xsl:if test="parent::*[local-name() = 'copyright-statement']">
11645
11777
  <xsl:attribute name="role">SKIP</xsl:attribute>
@@ -11669,18 +11801,31 @@
11669
11801
  </fo:block>
11670
11802
  </xsl:template>
11671
11803
 
11672
- <xsl:template match="*[local-name() = 'annex']">
11673
- <fo:block break-after="page"/>
11674
- <fo:block>
11804
+ <xsl:template match="*[local-name() = 'annex'][normalize-space() != '']">
11805
+ <xsl:choose>
11806
+ <xsl:when test="@continue = 'true'"> <!-- it's using for figure/table on top level for block span -->
11807
+ <fo:block>
11808
+ <xsl:apply-templates/>
11809
+ </fo:block>
11810
+ </xsl:when>
11811
+ <xsl:otherwise>
11675
11812
 
11676
- <xsl:call-template name="setBlockSpanAll"/>
11813
+ <fo:block break-after="page"/>
11814
+ <fo:block id="{@id}">
11677
11815
 
11678
- <xsl:call-template name="refine_annex_style"/>
11816
+ <xsl:call-template name="setBlockSpanAll"/>
11679
11817
 
11680
- </fo:block>
11681
- <fo:block id="{@id}">
11682
- <xsl:apply-templates/>
11683
- </fo:block>
11818
+ <xsl:call-template name="refine_annex_style"/>
11819
+
11820
+ </fo:block>
11821
+
11822
+ <xsl:apply-templates select="*[local-name() = 'title'][@columns = 1]"/>
11823
+
11824
+ <fo:block>
11825
+ <xsl:apply-templates select="node()[not(local-name() = 'title' and @columns = 1)]"/>
11826
+ </fo:block>
11827
+ </xsl:otherwise>
11828
+ </xsl:choose>
11684
11829
  </xsl:template>
11685
11830
 
11686
11831
  <xsl:template name="refine_annex_style">
@@ -12376,8 +12521,12 @@
12376
12521
  </xsl:if>
12377
12522
  </xsl:if> -->
12378
12523
 
12379
- <fo:block id="{@id}" xsl:use-attribute-sets="references-non-normative-style">
12380
- <xsl:apply-templates/>
12524
+ <fo:block id="{@id}"/>
12525
+
12526
+ <xsl:apply-templates select="*[local-name() = 'title'][@columns = 1]"/>
12527
+
12528
+ <fo:block xsl:use-attribute-sets="references-non-normative-style">
12529
+ <xsl:apply-templates select="node()[not(local-name() = 'title' and @columns = 1)]"/>
12381
12530
 
12382
12531
  </fo:block>
12383
12532
 
@@ -12894,10 +13043,83 @@
12894
13043
  <!-- ===================================== -->
12895
13044
  <!-- Update xml -->
12896
13045
  <!-- ===================================== -->
13046
+
13047
+ <xsl:template name="updateXML">
13048
+ <xsl:if test="$debug = 'true'"><xsl:message>START updated_xml_step1</xsl:message></xsl:if>
13049
+ <xsl:variable name="startTime1" select="java:getTime(java:java.util.Date.new())"/>
13050
+
13051
+ <!-- STEP1: Re-order elements in 'preface', 'sections' based on @displayorder -->
13052
+ <xsl:variable name="updated_xml_step1">
13053
+ <xsl:if test="$table_if = 'false'">
13054
+ <xsl:apply-templates mode="update_xml_step1"/>
13055
+ </xsl:if>
13056
+ </xsl:variable>
13057
+
13058
+ <xsl:variable name="endTime1" select="java:getTime(java:java.util.Date.new())"/>
13059
+ <xsl:if test="$debug = 'true'">
13060
+ <xsl:message>DEBUG: processing time <xsl:value-of select="$endTime1 - $startTime1"/> msec.</xsl:message>
13061
+ <xsl:message>END updated_xml_step1</xsl:message>
13062
+ <!-- <redirect:write file="updated_xml_step1_{java:getTime(java:java.util.Date.new())}.xml">
13063
+ <xsl:copy-of select="$updated_xml_step1"/>
13064
+ </redirect:write> -->
13065
+ </xsl:if>
13066
+
13067
+ <xsl:if test="$debug = 'true'"><xsl:message>START updated_xml_step2</xsl:message></xsl:if>
13068
+ <xsl:variable name="startTime2" select="java:getTime(java:java.util.Date.new())"/>
13069
+
13070
+ <!-- STEP2: add 'fn' after 'eref' and 'origin', if referenced to bibitem with 'note' = Withdrawn.' or 'Cancelled and replaced...' -->
13071
+ <xsl:variable name="updated_xml_step2">
13072
+
13073
+ <xsl:if test="$table_if = 'false'">
13074
+ <xsl:copy-of select="$updated_xml_step1"/>
13075
+ </xsl:if>
13076
+
13077
+ </xsl:variable>
13078
+
13079
+ <xsl:variable name="endTime2" select="java:getTime(java:java.util.Date.new())"/>
13080
+ <xsl:if test="$debug = 'true'">
13081
+ <xsl:message>DEBUG: processing time <xsl:value-of select="$endTime2 - $startTime2"/> msec.</xsl:message>
13082
+ <xsl:message>END updated_xml_step2</xsl:message>
13083
+ <!-- <redirect:write file="updated_xml_step2_{java:getTime(java:java.util.Date.new())}.xml">
13084
+ <xsl:copy-of select="$updated_xml_step2"/>
13085
+ </redirect:write> -->
13086
+ </xsl:if>
13087
+
13088
+ <xsl:if test="$debug = 'true'"><xsl:message>START updated_xml_step3</xsl:message></xsl:if>
13089
+ <xsl:variable name="startTime3" select="java:getTime(java:java.util.Date.new())"/>
13090
+
13091
+ <xsl:variable name="updated_xml_step3">
13092
+ <xsl:choose>
13093
+ <xsl:when test="$table_if = 'false'">
13094
+ <xsl:apply-templates select="xalan:nodeset($updated_xml_step2)" mode="update_xml_enclose_keep-together_within-line"/>
13095
+ </xsl:when>
13096
+ <xsl:otherwise>
13097
+ <xsl:apply-templates select="." mode="update_xml_enclose_keep-together_within-line"/>
13098
+ </xsl:otherwise>
13099
+ </xsl:choose>
13100
+ </xsl:variable>
13101
+
13102
+ <xsl:variable name="endTime3" select="java:getTime(java:java.util.Date.new())"/>
13103
+ <xsl:if test="$debug = 'true'">
13104
+ <xsl:message>DEBUG: processing time <xsl:value-of select="$endTime3 - $startTime3"/> msec.</xsl:message>
13105
+ <xsl:message>END updated_xml_step3</xsl:message>
13106
+ <!-- <redirect:write file="updated_xml_step3_{java:getTime(java:java.util.Date.new())}.xml">
13107
+ <xsl:copy-of select="$updated_xml_step3"/>
13108
+ </redirect:write> -->
13109
+ </xsl:if>
13110
+
13111
+ <xsl:copy-of select="$updated_xml_step3"/>
13112
+
13113
+ </xsl:template>
13114
+
12897
13115
  <!-- =========================================================================== -->
12898
13116
  <!-- STEP1: -->
12899
13117
  <!-- - Re-order elements in 'preface', 'sections' based on @displayorder -->
13118
+ <!-- - Put Section title in the correct position -->
12900
13119
  <!-- - Ignore 'span' without style -->
13120
+ <!-- - Remove semantic xml part -->
13121
+ <!-- - Remove image/emf (EMF vector image for Word) -->
13122
+ <!-- - add @id, redundant for table auto-layout algorithm -->
12901
13123
  <!-- =========================================================================== -->
12902
13124
  <xsl:template match="@*|node()" mode="update_xml_step1">
12903
13125
  <xsl:copy>
@@ -13004,11 +13226,14 @@
13004
13226
  <!-- remove image/emf -->
13005
13227
  <xsl:template match="*[local-name() = 'image']/*[local-name() = 'emf']" mode="update_xml_step1"/>
13006
13228
 
13007
- <xsl:template match="*[local-name() = 'stem'] | *[local-name() = 'image']" mode="update_xml_step1">
13229
+ <!-- remove preprocess-xslt -->
13230
+ <xsl:template match="*[local-name() = 'preprocess-xslt']" mode="update_xml_step1"/>
13231
+
13232
+ <xsl:template match="*[local-name() = 'stem'] | *[local-name() = 'image'] | *[local-name() = 'sourcecode'] | *[local-name() = 'bibdata'] | *[local-name() = 'localized-strings']" mode="update_xml_step1">
13008
13233
  <xsl:copy-of select="."/>
13009
13234
  </xsl:template>
13010
13235
 
13011
- <!-- add @id, redundant for table auto-layout algorithm -->
13236
+ <!-- add @id, mandatory for table auto-layout algorithm -->
13012
13237
  <xsl:template match="*[local-name() = 'dl' or local-name() = 'table'][not(@id)]" mode="update_xml_step1">
13013
13238
  <xsl:copy>
13014
13239
  <xsl:copy-of select="@*"/>
@@ -13027,10 +13252,174 @@
13027
13252
  </xsl:if>
13028
13253
  </xsl:template>
13029
13254
 
13255
+ <!-- optimization: remove clause if table_only_with_id isn't empty and clause doesn't contain table or dl with table_only_with_id -->
13256
+ <xsl:template match="*[local-name() = 'clause' or local-name() = 'p' or local-name() = 'definitions' or local-name() = 'annex']" mode="update_xml_step1">
13257
+ <xsl:choose>
13258
+ <xsl:when test="($table_only_with_id != '' or $table_only_with_ids != '') and local-name() = 'p' and (ancestor::*[local-name() = 'table' or local-name() = 'dl' or local-name() = 'toc'])">
13259
+ <xsl:copy>
13260
+ <xsl:copy-of select="@*"/>
13261
+ <xsl:apply-templates mode="update_xml_step1"/>
13262
+ </xsl:copy>
13263
+ </xsl:when>
13264
+ <!-- for table auto-layout algorithm -->
13265
+ <xsl:when test="$table_only_with_id != '' and not(.//*[local-name() = 'table' or local-name() = 'dl'][@id = $table_only_with_id])">
13266
+ <xsl:copy>
13267
+ <xsl:copy-of select="@*"/>
13268
+ </xsl:copy>
13269
+ </xsl:when>
13270
+ <!-- for table auto-layout algorithm -->
13271
+ <xsl:when test="$table_only_with_ids != '' and not(.//*[local-name() = 'table' or local-name() = 'dl'][contains($table_only_with_ids, concat(@id, ' '))])">
13272
+ <xsl:copy>
13273
+ <xsl:copy-of select="@*"/>
13274
+ </xsl:copy>
13275
+ </xsl:when>
13276
+ <xsl:otherwise>
13277
+ <xsl:copy>
13278
+ <xsl:copy-of select="@*"/>
13279
+ <xsl:apply-templates mode="update_xml_step1"/>
13280
+ </xsl:copy>
13281
+ </xsl:otherwise>
13282
+ </xsl:choose>
13283
+ </xsl:template>
13284
+
13030
13285
  <!-- =========================================================================== -->
13031
13286
  <!-- END STEP1: Re-order elements in 'preface', 'sections' based on @displayorder -->
13032
13287
  <!-- =========================================================================== -->
13033
13288
 
13289
+ <!-- =========================================================================== -->
13290
+ <!-- STEP MOVE PAGEBREAK: move <pagebreak/> at top level under 'preface' and 'sections' -->
13291
+ <!-- =========================================================================== -->
13292
+ <xsl:template match="@*|node()" mode="update_xml_step_move_pagebreak">
13293
+ <xsl:copy>
13294
+ <xsl:apply-templates select="@*|node()" mode="update_xml_step_move_pagebreak"/>
13295
+ </xsl:copy>
13296
+ </xsl:template>
13297
+
13298
+ <!-- replace 'pagebreak' by closing tags + page_sequence and opening page_sequence + tags -->
13299
+ <xsl:template match="*[local-name() = 'pagebreak'][not(following-sibling::*[1][local-name() = 'pagebreak'])]" mode="update_xml_step_move_pagebreak">
13300
+
13301
+ <!-- <xsl:choose>
13302
+ <xsl:when test="ancestor::*[local-name() = 'sections']">
13303
+
13304
+ </xsl:when>
13305
+ <xsl:when test="ancestor::*[local-name() = 'annex']">
13306
+ </xsl:when>
13307
+ <xsl:otherwise>
13308
+ <xsl:copy-of select="."/>
13309
+ </xsl:otherwise>
13310
+ </xsl:choose> -->
13311
+
13312
+ <!-- determine pagebreak is last element before </fo:flow> or not -->
13313
+ <xsl:variable name="isLast">
13314
+ <xsl:for-each select="ancestor-or-self::*[ancestor::*[local-name() = 'preface'] or ancestor::*[local-name() = 'sections'] or ancestor-or-self::*[local-name() = 'annex']]">
13315
+ <xsl:if test="following-sibling::*">false</xsl:if>
13316
+ </xsl:for-each>
13317
+ </xsl:variable>
13318
+
13319
+ <xsl:if test="contains($isLast, 'false')">
13320
+
13321
+ <xsl:variable name="orientation" select="normalize-space(@orientation)"/>
13322
+
13323
+ <xsl:variable name="tree_">
13324
+ <xsl:call-template name="makeAncestorsElementsTree"/>
13325
+ </xsl:variable>
13326
+ <xsl:variable name="tree" select="xalan:nodeset($tree_)"/>
13327
+
13328
+ <!-- close fo:page-sequence (closing preceding fo elements) -->
13329
+ <xsl:call-template name="insertClosingElements">
13330
+ <xsl:with-param name="tree" select="$tree"/>
13331
+ </xsl:call-template>
13332
+
13333
+ <xsl:text disable-output-escaping="yes">&lt;/page_sequence&gt;</xsl:text>
13334
+
13335
+ <!-- create a new page_sequence (opening elements) -->
13336
+ <xsl:text disable-output-escaping="yes">&lt;page_sequence xmlns="</xsl:text><xsl:value-of select="$namespace_full"/>"<xsl:if test="$orientation != ''"> orientation="<xsl:value-of select="$orientation"/>"</xsl:if><xsl:text disable-output-escaping="yes">&gt;</xsl:text>
13337
+
13338
+ <xsl:call-template name="insertOpeningElements">
13339
+ <xsl:with-param name="tree" select="$tree"/>
13340
+ </xsl:call-template>
13341
+
13342
+ </xsl:if>
13343
+ </xsl:template>
13344
+
13345
+ <xsl:template name="makeAncestorsElementsTree">
13346
+ <xsl:for-each select="ancestor::*[ancestor::*[local-name() = 'preface'] or ancestor::*[local-name() = 'sections'] or ancestor-or-self::*[local-name() = 'annex']]">
13347
+ <element pos="{position()}">
13348
+ <xsl:copy-of select="@*[local-name() != 'id']"/>
13349
+ <xsl:value-of select="name()"/>
13350
+ </element>
13351
+ </xsl:for-each>
13352
+ </xsl:template>
13353
+
13354
+ <xsl:template name="insertClosingElements">
13355
+ <xsl:param name="tree"/>
13356
+ <xsl:for-each select="$tree//element">
13357
+ <xsl:sort data-type="number" order="descending" select="@pos"/>
13358
+ <xsl:text disable-output-escaping="yes">&lt;/</xsl:text>
13359
+ <xsl:value-of select="."/>
13360
+ <xsl:text disable-output-escaping="yes">&gt;</xsl:text>
13361
+ <xsl:if test="$debug = 'true'">
13362
+ <xsl:message>&lt;/<xsl:value-of select="."/>&gt;</xsl:message>
13363
+ </xsl:if>
13364
+ </xsl:for-each>
13365
+ </xsl:template>
13366
+
13367
+ <xsl:template name="insertOpeningElements">
13368
+ <xsl:param name="tree"/>
13369
+ <xsl:for-each select="$tree//element">
13370
+ <xsl:text disable-output-escaping="yes">&lt;</xsl:text>
13371
+ <xsl:value-of select="."/>
13372
+ <xsl:for-each select="@*[local-name() != 'pos']">
13373
+ <xsl:text> </xsl:text>
13374
+ <xsl:value-of select="local-name()"/>
13375
+ <xsl:text>="</xsl:text>
13376
+ <xsl:value-of select="."/>
13377
+ <xsl:text>"</xsl:text>
13378
+ </xsl:for-each>
13379
+ <xsl:if test="position() = 1"> continue="true"</xsl:if>
13380
+ <xsl:text disable-output-escaping="yes">&gt;</xsl:text>
13381
+ <xsl:if test="$debug = 'true'">
13382
+ <xsl:message>&lt;<xsl:value-of select="."/>&gt;</xsl:message>
13383
+ </xsl:if>
13384
+ </xsl:for-each>
13385
+ </xsl:template>
13386
+
13387
+ <!-- move full page width figures, tables at top level -->
13388
+ <xsl:template match="*[local-name() = 'figure' or local-name() = 'table'][normalize-space(@width) != 'text-width']" mode="update_xml_step_move_pagebreak">
13389
+ <xsl:choose>
13390
+ <xsl:when test="$layout_columns != 1">
13391
+
13392
+ <xsl:variable name="tree_">
13393
+ <xsl:call-template name="makeAncestorsElementsTree"/>
13394
+ </xsl:variable>
13395
+ <xsl:variable name="tree" select="xalan:nodeset($tree_)"/>
13396
+
13397
+ <xsl:call-template name="insertClosingElements">
13398
+ <xsl:with-param name="tree" select="$tree"/>
13399
+ </xsl:call-template>
13400
+
13401
+ <!-- <xsl:copy-of select="."/> -->
13402
+ <xsl:copy>
13403
+ <xsl:copy-of select="@*"/>
13404
+ <xsl:attribute name="top-level">true</xsl:attribute>
13405
+ <xsl:copy-of select="node()"/>
13406
+ </xsl:copy>
13407
+
13408
+ <xsl:call-template name="insertOpeningElements">
13409
+ <xsl:with-param name="tree" select="$tree"/>
13410
+ </xsl:call-template>
13411
+
13412
+ </xsl:when>
13413
+ <xsl:otherwise>
13414
+ <xsl:copy-of select="."/>
13415
+ </xsl:otherwise>
13416
+ </xsl:choose>
13417
+ </xsl:template>
13418
+
13419
+ <!-- =========================================================================== -->
13420
+ <!-- END STEP MOVE PAGEBREAK: move <pagebreak/> at top level under 'preface' and 'sections' -->
13421
+ <!-- =========================================================================== -->
13422
+
13034
13423
  <!-- =========================================================================== -->
13035
13424
  <!-- XML UPDATE STEP: enclose standard's name into tag 'keep-together_within-line' -->
13036
13425
  <!-- keep-together_within-line for: a/b, aaa/b, a/bbb, /b -->
@@ -13135,7 +13524,7 @@
13135
13524
  <xsl:value-of select="substring-before($text, $tag_open)"/>
13136
13525
  <xsl:variable name="text_after" select="substring-after($text, $tag_open)"/>
13137
13526
 
13138
- <xsl:element name="{substring-before(substring-after($tag_open, '###'),'###')}">
13527
+ <xsl:element name="{substring-before(substring-after($tag_open, '###'),'###')}" namespace="{$namespace_full}">
13139
13528
  <xsl:value-of select="substring-before($text_after, $tag_close)"/>
13140
13529
  </xsl:element>
13141
13530
 
@@ -13206,7 +13595,7 @@
13206
13595
  <xsl:apply-templates select="*[local-name() = 'term']" mode="linear_xml"/>
13207
13596
  </xsl:template>
13208
13597
 
13209
- <xsl:template match="*[local-name() = 'introduction']//*[local-name() = 'title'] | *[local-name() = 'foreword']//*[local-name() = 'title'] | *[local-name() = 'sections']//*[local-name() = 'title'] | *[local-name() = 'annex']//*[local-name() = 'title'] | *[local-name() = 'bibliography']/*[local-name() = 'clause']/*[local-name() = 'title'] | *[local-name() = 'references']/*[local-name() = 'title'] | *[local-name() = 'colophon']//*[local-name() = 'title']" mode="linear_xml" priority="2">
13598
+ <xsl:template match="*[local-name() = 'introduction']//*[local-name() = 'title'] | *[local-name() = 'foreword']//*[local-name() = 'title'] | *[local-name() = 'preface']//*[local-name() = 'title'] | *[local-name() = 'sections']//*[local-name() = 'title'] | *[local-name() = 'annex']//*[local-name() = 'title'] | *[local-name() = 'bibliography']/*[local-name() = 'clause']/*[local-name() = 'title'] | *[local-name() = 'references']/*[local-name() = 'title'] | *[local-name() = 'colophon']//*[local-name() = 'title']" mode="linear_xml" priority="2">
13210
13599
  <xsl:copy>
13211
13600
  <xsl:apply-templates select="@*" mode="linear_xml"/>
13212
13601
 
@@ -13225,7 +13614,7 @@
13225
13614
  <xsl:copy-of select="../@inline-header"/>
13226
13615
  </xsl:if>
13227
13616
 
13228
- <xsl:attribute name="ancestor">
13617
+ <xsl:variable name="ancestor">
13229
13618
  <xsl:choose>
13230
13619
  <xsl:when test="ancestor::*[local-name() = 'foreword']">foreword</xsl:when>
13231
13620
  <xsl:when test="ancestor::*[local-name() = 'introduction']">introduction</xsl:when>
@@ -13233,6 +13622,35 @@
13233
13622
  <xsl:when test="ancestor::*[local-name() = 'annex']">annex</xsl:when>
13234
13623
  <xsl:when test="ancestor::*[local-name() = 'bibliography']">bibliography</xsl:when>
13235
13624
  </xsl:choose>
13625
+ </xsl:variable>
13626
+ <xsl:attribute name="ancestor">
13627
+ <xsl:value-of select="$ancestor"/>
13628
+ </xsl:attribute>
13629
+
13630
+ <xsl:attribute name="parent">
13631
+ <xsl:choose>
13632
+ <xsl:when test="ancestor::*[local-name() = 'preface']">preface</xsl:when>
13633
+ <xsl:otherwise><xsl:value-of select="$ancestor"/></xsl:otherwise>
13634
+ </xsl:choose>
13635
+ </xsl:attribute>
13636
+
13637
+ <xsl:apply-templates mode="linear_xml"/>
13638
+ </xsl:copy>
13639
+ </xsl:template>
13640
+
13641
+ <xsl:template match="*[local-name() = 'li']" mode="linear_xml" priority="2">
13642
+ <xsl:copy>
13643
+ <xsl:apply-templates select="@*" mode="linear_xml"/>
13644
+
13645
+ <xsl:variable name="ancestor">
13646
+ <xsl:choose>
13647
+ <xsl:when test="ancestor::*[local-name() = 'preface']">preface</xsl:when>
13648
+ <xsl:when test="ancestor::*[local-name() = 'sections']">sections</xsl:when>
13649
+ <xsl:when test="ancestor::*[local-name() = 'annex']">annex</xsl:when>
13650
+ </xsl:choose>
13651
+ </xsl:variable>
13652
+ <xsl:attribute name="ancestor">
13653
+ <xsl:value-of select="$ancestor"/>
13236
13654
  </xsl:attribute>
13237
13655
 
13238
13656
  <xsl:apply-templates mode="linear_xml"/>
@@ -13637,7 +14055,7 @@
13637
14055
  <xsl:value-of select="$depth"/>
13638
14056
  </xsl:when>
13639
14057
  <xsl:otherwise>
13640
- <xsl:variable name="level_total" select="count(ancestor::*)"/>
14058
+ <xsl:variable name="level_total" select="count(ancestor::*[local-name() != 'page_sequence'])"/>
13641
14059
  <xsl:variable name="level">
13642
14060
  <xsl:choose>
13643
14061
  <xsl:when test="parent::*[local-name() = 'preface']">
@@ -13928,7 +14346,10 @@
13928
14346
  <xsl:call-template name="setTextAlignment">
13929
14347
  <xsl:with-param name="default" select="$text_align_default"/>
13930
14348
  </xsl:call-template>
14349
+ <xsl:call-template name="setKeepAttributes"/>
14350
+ </xsl:template>
13931
14351
 
14352
+ <xsl:template name="setKeepAttributes">
13932
14353
  <!-- https://www.metanorma.org/author/topics/document-format/text/#avoiding-page-breaks -->
13933
14354
  <!-- Example: keep-lines-together="true" -->
13934
14355
  <xsl:if test="@keep-lines-together = 'true'">
@@ -13940,6 +14361,72 @@
13940
14361
  </xsl:if>
13941
14362
  </xsl:template>
13942
14363
 
14364
+ <!-- insert cover page image -->
14365
+ <!-- background cover image -->
14366
+ <xsl:template name="insertBackgroundPageImage">
14367
+ <xsl:param name="number">1</xsl:param>
14368
+ <xsl:param name="name">coverpage-image</xsl:param>
14369
+ <xsl:variable name="num" select="number($number)"/>
14370
+ <!-- background image -->
14371
+ <fo:block-container absolute-position="fixed" left="0mm" top="0mm" font-size="0" id="__internal_layout__coverpage_{$name}_{$number}_{generate-id()}">
14372
+ <fo:block>
14373
+ <xsl:for-each select="/*[contains(local-name(), '-standard')]/*[local-name() = 'metanorma-extension']/*[local-name() = 'presentation-metadata'][*[local-name() = 'name'] = $name][1]/*[local-name() = 'value']/*[local-name() = 'image'][$num]">
14374
+ <xsl:choose>
14375
+ <xsl:when test="*[local-name() = 'svg'] or java:endsWith(java:java.lang.String.new(@src), '.svg')">
14376
+ <fo:instream-foreign-object fox:alt-text="Image Front">
14377
+ <xsl:attribute name="content-height"><xsl:value-of select="$pageHeight"/>mm</xsl:attribute>
14378
+ <xsl:call-template name="getSVG"/>
14379
+ </fo:instream-foreign-object>
14380
+ </xsl:when>
14381
+ <xsl:when test="starts-with(@src, 'data:application/pdf;base64')">
14382
+ <fo:external-graphic src="{@src}" fox:alt-text="Image Front"/>
14383
+ </xsl:when>
14384
+ <xsl:otherwise> <!-- bitmap image -->
14385
+ <xsl:variable name="coverimage_src" select="normalize-space(@src)"/>
14386
+ <xsl:if test="$coverimage_src != ''">
14387
+ <xsl:variable name="coverpage">
14388
+ <xsl:call-template name="getImageURL">
14389
+ <xsl:with-param name="src" select="$coverimage_src"/>
14390
+ </xsl:call-template>
14391
+ </xsl:variable>
14392
+ <!-- <xsl:variable name="coverpage" select="concat('url(file:',$basepath, 'coverpage1.png', ')')"/> --> <!-- for DEBUG -->
14393
+ <fo:external-graphic src="{$coverpage}" width="{$pageWidth}mm" content-height="scale-to-fit" scaling="uniform" fox:alt-text="Image Front"/>
14394
+ </xsl:if>
14395
+ </xsl:otherwise>
14396
+ </xsl:choose>
14397
+ </xsl:for-each>
14398
+ </fo:block>
14399
+ </fo:block-container>
14400
+ </xsl:template>
14401
+
14402
+ <xsl:template name="getImageURL">
14403
+ <xsl:param name="src"/>
14404
+ <xsl:choose>
14405
+ <xsl:when test="starts-with($src, 'data:image')">
14406
+ <xsl:value-of select="$src"/>
14407
+ </xsl:when>
14408
+ <xsl:otherwise>
14409
+ <xsl:value-of select="concat('url(file:///',$basepath, $src, ')')"/>
14410
+ </xsl:otherwise>
14411
+ </xsl:choose>
14412
+ </xsl:template>
14413
+
14414
+ <xsl:template name="getSVG">
14415
+ <xsl:choose>
14416
+ <xsl:when test="*[local-name() = 'svg']">
14417
+ <xsl:apply-templates select="*[local-name() = 'svg']" mode="svg_update"/>
14418
+ </xsl:when>
14419
+ <xsl:otherwise>
14420
+ <xsl:variable name="svg_content" select="document(@src)"/>
14421
+ <xsl:for-each select="xalan:nodeset($svg_content)/node()">
14422
+ <xsl:apply-templates select="." mode="svg_update"/>
14423
+ </xsl:for-each>
14424
+ </xsl:otherwise>
14425
+ </xsl:choose>
14426
+ </xsl:template>
14427
+
14428
+ <!-- END: insert cover page image -->
14429
+
13943
14430
  <xsl:template name="number-to-words">
13944
14431
  <xsl:param name="number"/>
13945
14432
  <xsl:param name="first"/>