metanorma-bipm 2.4.8 → 2.4.10

Sign up to get free protection for your applications and to get access to all the features.
@@ -2737,6 +2737,7 @@
2737
2737
  <xsl:otherwise>justify</xsl:otherwise>
2738
2738
  </xsl:choose>
2739
2739
  </xsl:attribute>
2740
+ <xsl:call-template name="setKeepAttributes"/>
2740
2741
  <xsl:copy-of select="@font-family"/>
2741
2742
  <xsl:if test="not(ancestor::bipm:table)">
2742
2743
  <xsl:attribute name="margin-bottom">6pt</xsl:attribute>
@@ -3872,7 +3873,9 @@
3872
3873
  <xsl:strip-space xmlns:redirect="http://xml.apache.org/xalan/redirect" elements="bipm:xref"/>
3873
3874
 
3874
3875
  <xsl:variable xmlns:redirect="http://xml.apache.org/xalan/redirect" name="namespace_full" select="namespace-uri(/*)"/> <!-- example: https://www.metanorma.org/ns/iso -->
3875
- <xsl:variable xmlns:redirect="http://xml.apache.org/xalan/redirect" name="root_element" select="local-name(/*)"/>
3876
+ <xsl:variable xmlns:redirect="http://xml.apache.org/xalan/redirect" name="root_element" select="local-name(/*)"/> <!-- example: iso-standard -->
3877
+
3878
+ <xsl:variable xmlns:redirect="http://xml.apache.org/xalan/redirect" name="document_scheme" select="normalize-space(//*[contains(local-name(), '-standard')]/*[local-name() = 'metanorma-extension']/*[local-name() = 'presentation-metadata'][*[local-name() = 'name'] = 'document-scheme']/*[local-name() = 'value'])"/>
3876
3879
 
3877
3880
  <!-- external parameters -->
3878
3881
 
@@ -5594,41 +5597,9 @@
5594
5597
  </xsl:for-each>
5595
5598
  </xsl:template>
5596
5599
 
5597
- <xsl:template xmlns:redirect="http://xml.apache.org/xalan/redirect" name="processPrefaceSectionsDefault_items">
5598
-
5599
- <xsl:variable name="updated_xml_step_move_pagebreak_">
5600
-
5601
- <xsl:element name="{$root_element}" namespace="{$namespace_full}">
5602
-
5603
- <xsl:call-template name="copyCommonElements"/>
5604
-
5605
- <xsl:element name="preface" namespace="{$namespace_full}"> <!-- save context element -->
5606
- <xsl:element name="page_sequence" namespace="{$namespace_full}">
5607
- <xsl:for-each select="/*/*[local-name()='preface']/*[not(local-name() = 'note' or local-name() = 'admonition')]">
5608
- <xsl:sort select="@displayorder" data-type="number"/>
5609
- <xsl:apply-templates select="." mode="update_xml_step_move_pagebreak"/>
5610
- </xsl:for-each>
5611
- </xsl:element>
5612
- </xsl:element>
5613
- </xsl:element>
5614
- </xsl:variable>
5615
-
5616
- <xsl:variable name="updated_xml_step_move_pagebreak_filename" select="concat($output_path,'_preface_', java:getTime(java:java.util.Date.new()), '.xml')"/>
5617
-
5618
- <redirect:write file="{$updated_xml_step_move_pagebreak_filename}">
5619
- <xsl:copy-of select="$updated_xml_step_move_pagebreak_"/>
5620
- </redirect:write>
5621
-
5622
- <xsl:copy-of select="document($updated_xml_step_move_pagebreak_filename)"/>
5623
-
5624
- <xsl:call-template name="deleteFile">
5625
- <xsl:with-param name="filepath" select="$updated_xml_step_move_pagebreak_filename"/>
5626
- </xsl:call-template>
5627
- </xsl:template>
5628
-
5629
5600
  <xsl:template xmlns:redirect="http://xml.apache.org/xalan/redirect" name="copyCommonElements">
5630
5601
  <!-- copy bibdata, localized-strings, metanorma-extension and boilerplate -->
5631
- <xsl:copy-of select="/*/*[local-name() != 'preface' and local-name() != 'sections' and local-name() != 'annex' and local-name() != 'bibliography']"/>
5602
+ <xsl:copy-of select="/*/*[local-name() != 'preface' and local-name() != 'sections' and local-name() != 'annex' and local-name() != 'bibliography' and local-name() != 'indexsect']"/>
5632
5603
  </xsl:template>
5633
5604
 
5634
5605
  <xsl:template xmlns:redirect="http://xml.apache.org/xalan/redirect" name="processMainSectionsDefault">
@@ -5649,38 +5620,16 @@
5649
5620
  </xsl:for-each>
5650
5621
  </xsl:template><!-- END: processMainSectionsDefault -->
5651
5622
 
5652
- <xsl:template xmlns:redirect="http://xml.apache.org/xalan/redirect" name="processMainSectionsDefault_flatxml">
5653
- <xsl:for-each select="/*/*[local-name()='sections']/* | /*/*[local-name()='bibliography']/*[local-name()='references'][@normative='true']">
5654
- <xsl:sort select="@displayorder" data-type="number"/>
5655
- <xsl:variable name="flatxml">
5656
- <xsl:apply-templates select="." mode="flatxml"/>
5657
- </xsl:variable>
5658
- <!-- debug_flatxml='<xsl:copy-of select="$flatxml"/>' -->
5659
- <xsl:apply-templates select="xalan:nodeset($flatxml)/*"/>
5660
-
5661
- </xsl:for-each>
5662
-
5663
- <xsl:for-each select="/*/*[local-name()='annex']">
5664
- <xsl:sort select="@displayorder" data-type="number"/>
5665
- <xsl:variable name="flatxml">
5666
- <xsl:apply-templates select="." mode="flatxml"/>
5667
- </xsl:variable>
5668
- <!-- debug_flatxml='<xsl:copy-of select="$flatxml"/>' -->
5669
- <xsl:apply-templates select="xalan:nodeset($flatxml)/*"/>
5670
- </xsl:for-each>
5671
-
5672
- <xsl:for-each select="/*/*[local-name()='bibliography']/*[not(@normative='true')] | /*/*[local-name()='bibliography']/*[local-name()='clause'][*[local-name()='references'][not(@normative='true')]]">
5673
- <xsl:sort select="@displayorder" data-type="number"/>
5674
- <xsl:variable name="flatxml">
5675
- <xsl:apply-templates select="." mode="flatxml"/>
5676
- </xsl:variable>
5677
- <!-- debug_flatxml='<xsl:copy-of select="$flatxml"/>' -->
5678
- <xsl:apply-templates select="xalan:nodeset($flatxml)/*"/>
5679
- </xsl:for-each>
5680
- </xsl:template>
5681
-
5682
5623
  <!-- Example:
5683
5624
  <iso-standard>
5625
+ <preface>
5626
+ <page_sequence>
5627
+ <clause...
5628
+ </page_sequence>
5629
+ <page_sequence>
5630
+ <clause...
5631
+ </page_sequence>
5632
+ </preface>
5684
5633
  <sections>
5685
5634
  <page_sequence>
5686
5635
  <clause...
@@ -5697,54 +5646,200 @@
5697
5646
  </page_sequence>
5698
5647
  </iso-standard>
5699
5648
  -->
5700
- <xsl:template xmlns:redirect="http://xml.apache.org/xalan/redirect" name="processMainSectionsDefault_items">
5701
-
5702
- <xsl:variable name="updated_xml_step_move_pagebreak_">
5649
+ <xsl:template xmlns:redirect="http://xml.apache.org/xalan/redirect" name="processPrefaceAndMainSectionsDefault_items">
5703
5650
 
5651
+ <xsl:variable name="updated_xml_step_move_pagebreak">
5704
5652
  <xsl:element name="{$root_element}" namespace="{$namespace_full}">
5705
-
5706
5653
  <xsl:call-template name="copyCommonElements"/>
5654
+ <xsl:call-template name="insertPrefaceSectionsPageSequences"/>
5655
+ <xsl:call-template name="insertMainSectionsPageSequences"/>
5656
+ </xsl:element>
5657
+ </xsl:variable>
5707
5658
 
5708
- <xsl:element name="sections" namespace="{$namespace_full}"> <!-- save context element -->
5709
- <xsl:element name="page_sequence" namespace="{$namespace_full}">
5710
- <xsl:for-each select="/*/*[local-name()='sections']/* | /*/*[local-name()='bibliography']/*[local-name()='references'][@normative='true']">
5711
- <xsl:sort select="@displayorder" data-type="number"/>
5712
- <xsl:apply-templates select="." mode="update_xml_step_move_pagebreak"/>
5659
+ <xsl:variable name="updated_xml_step_move_pagebreak_filename" select="concat($output_path,'_main_', java:getTime(java:java.util.Date.new()), '.xml')"/>
5713
5660
 
5714
- </xsl:for-each>
5715
- </xsl:element>
5661
+ <redirect:write file="{$updated_xml_step_move_pagebreak_filename}">
5662
+ <xsl:copy-of select="$updated_xml_step_move_pagebreak"/>
5663
+ </redirect:write>
5664
+
5665
+ <xsl:copy-of select="document($updated_xml_step_move_pagebreak_filename)"/>
5666
+
5667
+ <xsl:if test="$debug = 'true'">
5668
+ <redirect:write file="page_sequence_preface_and_main.xml">
5669
+ <xsl:copy-of select="$updated_xml_step_move_pagebreak"/>
5670
+ </redirect:write>
5671
+ </xsl:if>
5672
+
5673
+ <xsl:call-template name="deleteFile">
5674
+ <xsl:with-param name="filepath" select="$updated_xml_step_move_pagebreak_filename"/>
5675
+ </xsl:call-template>
5676
+ </xsl:template> <!-- END: processPrefaceAndMainSectionsDefault_items -->
5677
+
5678
+ <xsl:template xmlns:redirect="http://xml.apache.org/xalan/redirect" name="insertPrefaceSectionsPageSequences">
5679
+ <xsl:element name="preface" namespace="{$namespace_full}"> <!-- save context element -->
5680
+ <xsl:element name="page_sequence" namespace="{$namespace_full}">
5681
+ <xsl:for-each select="/*/*[local-name()='preface']/*[not(local-name() = 'note' or local-name() = 'admonition')]">
5682
+ <xsl:sort select="@displayorder" data-type="number"/>
5683
+ <xsl:apply-templates select="." mode="update_xml_step_move_pagebreak"/>
5684
+ </xsl:for-each>
5685
+ </xsl:element>
5686
+ </xsl:element>
5687
+ </xsl:template> <!-- END: insertPrefaceSectionsPageSequences -->
5688
+
5689
+ <xsl:template xmlns:redirect="http://xml.apache.org/xalan/redirect" name="insertMainSectionsPageSequences">
5690
+ <xsl:element name="sections" namespace="{$namespace_full}"> <!-- save context element -->
5691
+ <xsl:element name="page_sequence" namespace="{$namespace_full}">
5692
+ <xsl:for-each select="/*/*[local-name()='sections']/* | /*/*[local-name()='bibliography']/*[local-name()='references'][@normative='true']">
5693
+ <xsl:sort select="@displayorder" data-type="number"/>
5694
+ <xsl:apply-templates select="." mode="update_xml_step_move_pagebreak"/>
5695
+
5696
+ </xsl:for-each>
5697
+ </xsl:element>
5698
+ </xsl:element>
5699
+
5700
+ <xsl:element name="page_sequence" namespace="{$namespace_full}">
5701
+ <xsl:for-each select="/*/*[local-name()='annex']">
5702
+ <xsl:sort select="@displayorder" data-type="number"/>
5703
+ <xsl:apply-templates select="." mode="update_xml_step_move_pagebreak"/>
5704
+ </xsl:for-each>
5705
+ </xsl:element>
5706
+
5707
+ <xsl:element name="page_sequence" namespace="{$namespace_full}">
5708
+ <xsl:element name="bibliography" namespace="{$namespace_full}"> <!-- save context element -->
5709
+ <xsl:for-each select="/*/*[local-name()='bibliography']/*[not(@normative='true')] | /*/*[local-name()='bibliography']/*[local-name()='clause'][*[local-name()='references'][not(@normative='true')]]">
5710
+ <xsl:sort select="@displayorder" data-type="number"/>
5711
+ <xsl:apply-templates select="." mode="update_xml_step_move_pagebreak"/>
5712
+ </xsl:for-each>
5713
+ </xsl:element>
5714
+ </xsl:element>
5715
+ </xsl:template> <!-- END: insertMainSectionsPageSequences -->
5716
+
5717
+ <xsl:template xmlns:redirect="http://xml.apache.org/xalan/redirect" name="insertMainSectionsInSeparatePageSequences">
5718
+ <xsl:element name="sections" namespace="{$namespace_full}"> <!-- save context element -->
5719
+ <xsl:for-each select="/*/*[local-name()='sections']/* | /*/*[local-name()='bibliography']/*[local-name()='references'][@normative='true']">
5720
+ <xsl:sort select="@displayorder" data-type="number"/>
5721
+ <xsl:element name="page_sequence" namespace="{$namespace_full}">
5722
+ <xsl:attribute name="main_page_sequence"/>
5723
+ <xsl:apply-templates select="." mode="update_xml_step_move_pagebreak"/>
5716
5724
  </xsl:element>
5725
+ </xsl:for-each>
5726
+ </xsl:element>
5727
+
5728
+ <xsl:call-template name="insertAnnexInSeparatePageSequences"/>
5717
5729
 
5730
+ <xsl:call-template name="insertBibliographyInSeparatePageSequences"/>
5731
+
5732
+ <!-- <xsl:call-template name="insertIndexInSeparatePageSequences"/> -->
5733
+ </xsl:template> <!-- END: insertMainSectionsInSeparatePageSequences -->
5734
+
5735
+ <xsl:template xmlns:redirect="http://xml.apache.org/xalan/redirect" name="insertAnnexInSeparatePageSequences">
5736
+ <xsl:for-each select="/*/*[local-name()='annex']">
5737
+ <xsl:sort select="@displayorder" data-type="number"/>
5738
+ <xsl:element name="page_sequence" namespace="{$namespace_full}">
5739
+ <xsl:attribute name="main_page_sequence"/>
5740
+ <xsl:apply-templates select="." mode="update_xml_step_move_pagebreak"/>
5741
+ </xsl:element>
5742
+ </xsl:for-each>
5743
+ </xsl:template>
5744
+ <xsl:template xmlns:redirect="http://xml.apache.org/xalan/redirect" name="insertBibliographyInSeparatePageSequences">
5745
+ <xsl:element name="bibliography" namespace="{$namespace_full}"> <!-- save context element -->
5746
+ <xsl:for-each select="/*/*[local-name()='bibliography']/*[not(@normative='true')] | /*/*[local-name()='bibliography']/*[local-name()='clause'][*[local-name()='references'][not(@normative='true')]]">
5747
+ <xsl:sort select="@displayorder" data-type="number"/>
5718
5748
  <xsl:element name="page_sequence" namespace="{$namespace_full}">
5719
- <xsl:for-each select="/*/*[local-name()='annex']">
5720
- <xsl:sort select="@displayorder" data-type="number"/>
5721
- <xsl:apply-templates select="." mode="update_xml_step_move_pagebreak"/>
5722
- </xsl:for-each>
5749
+ <xsl:attribute name="main_page_sequence"/>
5750
+ <xsl:apply-templates select="." mode="update_xml_step_move_pagebreak"/>
5723
5751
  </xsl:element>
5752
+ </xsl:for-each>
5753
+ </xsl:element>
5754
+ </xsl:template>
5755
+ <xsl:template xmlns:redirect="http://xml.apache.org/xalan/redirect" name="insertIndexInSeparatePageSequences">
5756
+ <xsl:for-each select="/*/*[local-name()='indexsect']">
5757
+ <xsl:sort select="@displayorder" data-type="number"/>
5758
+ <xsl:element name="page_sequence" namespace="{$namespace_full}">
5759
+ <xsl:attribute name="main_page_sequence"/>
5760
+ <xsl:apply-templates select="." mode="update_xml_step_move_pagebreak"/>
5761
+ </xsl:element>
5762
+ </xsl:for-each>
5763
+ </xsl:template>
5724
5764
 
5765
+ <xsl:template xmlns:redirect="http://xml.apache.org/xalan/redirect" name="processAllSectionsDefault_items">
5766
+ <xsl:variable name="updated_xml_step_move_pagebreak">
5767
+ <xsl:element name="{$root_element}" namespace="{$namespace_full}">
5768
+ <xsl:call-template name="copyCommonElements"/>
5725
5769
  <xsl:element name="page_sequence" namespace="{$namespace_full}">
5726
- <xsl:element name="bibliography" namespace="{$namespace_full}"> <!-- save context element -->
5727
- <xsl:for-each select="/*/*[local-name()='bibliography']/*[not(@normative='true')] | /*/*[local-name()='bibliography']/*[local-name()='clause'][*[local-name()='references'][not(@normative='true')]]">
5728
- <xsl:sort select="@displayorder" data-type="number"/>
5729
- <xsl:apply-templates select="." mode="update_xml_step_move_pagebreak"/>
5730
- </xsl:for-each>
5731
- </xsl:element>
5770
+ <xsl:call-template name="insertPrefaceSections"/>
5771
+ <xsl:call-template name="insertMainSections"/>
5732
5772
  </xsl:element>
5733
5773
  </xsl:element>
5734
5774
  </xsl:variable>
5735
5775
 
5736
- <xsl:variable name="updated_xml_step_move_pagebreak_filename" select="concat($output_path,'_main_', java:getTime(java:java.util.Date.new()), '.xml')"/>
5737
-
5776
+ <xsl:variable name="updated_xml_step_move_pagebreak_filename" select="concat($output_path,'_preface_and_main_', java:getTime(java:java.util.Date.new()), '.xml')"/>
5777
+ <!-- <xsl:message>updated_xml_step_move_pagebreak_filename=<xsl:value-of select="$updated_xml_step_move_pagebreak_filename"/></xsl:message>
5778
+ <xsl:message>start write updated_xml_step_move_pagebreak_filename</xsl:message> -->
5738
5779
  <redirect:write file="{$updated_xml_step_move_pagebreak_filename}">
5739
- <xsl:copy-of select="$updated_xml_step_move_pagebreak_"/>
5780
+ <xsl:copy-of select="$updated_xml_step_move_pagebreak"/>
5740
5781
  </redirect:write>
5782
+ <!-- <xsl:message>end write updated_xml_step_move_pagebreak_filename</xsl:message> -->
5741
5783
 
5742
5784
  <xsl:copy-of select="document($updated_xml_step_move_pagebreak_filename)"/>
5743
5785
 
5786
+ <!-- TODO: instead of
5787
+ <xsl:for-each select=".//*[local-name() = 'page_sequence'][normalize-space() != '' or .//image or .//svg]">
5788
+ in each template, add removing empty page_sequence here
5789
+ -->
5790
+
5791
+ <xsl:if test="$debug = 'true'">
5792
+ <redirect:write file="page_sequence_preface_and_main.xml">
5793
+ <xsl:copy-of select="$updated_xml_step_move_pagebreak"/>
5794
+ </redirect:write>
5795
+ </xsl:if>
5796
+
5797
+ <!-- <xsl:message>start delete updated_xml_step_move_pagebreak_filename</xsl:message> -->
5744
5798
  <xsl:call-template name="deleteFile">
5745
5799
  <xsl:with-param name="filepath" select="$updated_xml_step_move_pagebreak_filename"/>
5746
5800
  </xsl:call-template>
5747
- </xsl:template> <!-- END: processMainSectionsDefault_items -->
5801
+ <!-- <xsl:message>end delete updated_xml_step_move_pagebreak_filename</xsl:message> -->
5802
+ </xsl:template> <!-- END: processAllSectionsDefault_items -->
5803
+
5804
+ <xsl:template xmlns:redirect="http://xml.apache.org/xalan/redirect" name="insertPrefaceSections">
5805
+ <xsl:element name="preface" namespace="{$namespace_full}"> <!-- save context element -->
5806
+ <xsl:for-each select="/*/*[local-name()='preface']/*[not(local-name() = 'note' or local-name() = 'admonition')]">
5807
+ <xsl:sort select="@displayorder" data-type="number"/>
5808
+ <xsl:apply-templates select="." mode="update_xml_step_move_pagebreak">
5809
+ <xsl:with-param name="page_sequence_at_top">true</xsl:with-param>
5810
+ </xsl:apply-templates>
5811
+ </xsl:for-each>
5812
+ </xsl:element>
5813
+ </xsl:template>
5814
+
5815
+ <xsl:template xmlns:redirect="http://xml.apache.org/xalan/redirect" name="insertMainSections">
5816
+ <xsl:element name="sections" namespace="{$namespace_full}"> <!-- save context element -->
5817
+
5818
+ <xsl:for-each select="/*/*[local-name()='sections']/* | /*/*[local-name()='bibliography']/*[local-name()='references'][@normative='true']">
5819
+ <xsl:sort select="@displayorder" data-type="number"/>
5820
+ <xsl:apply-templates select="." mode="update_xml_step_move_pagebreak">
5821
+ <xsl:with-param name="page_sequence_at_top">true</xsl:with-param>
5822
+ </xsl:apply-templates>
5823
+
5824
+ </xsl:for-each>
5825
+ </xsl:element>
5826
+
5827
+ <xsl:for-each select="/*/*[local-name()='annex']">
5828
+ <xsl:sort select="@displayorder" data-type="number"/>
5829
+ <xsl:apply-templates select="." mode="update_xml_step_move_pagebreak">
5830
+ <xsl:with-param name="page_sequence_at_top">true</xsl:with-param>
5831
+ </xsl:apply-templates>
5832
+ </xsl:for-each>
5833
+
5834
+ <xsl:element name="bibliography" namespace="{$namespace_full}"> <!-- save context element -->
5835
+ <xsl:for-each select="/*/*[local-name()='bibliography']/*[not(@normative='true')] | /*/*[local-name()='bibliography']/*[local-name()='clause'][*[local-name()='references'][not(@normative='true')]]">
5836
+ <xsl:sort select="@displayorder" data-type="number"/>
5837
+ <xsl:apply-templates select="." mode="update_xml_step_move_pagebreak">
5838
+ <xsl:with-param name="page_sequence_at_top">true</xsl:with-param>
5839
+ </xsl:apply-templates>
5840
+ </xsl:for-each>
5841
+ </xsl:element>
5842
+ </xsl:template>
5748
5843
 
5749
5844
  <xsl:template xmlns:redirect="http://xml.apache.org/xalan/redirect" name="deleteFile">
5750
5845
  <xsl:param name="filepath"/>
@@ -5753,6 +5848,14 @@
5753
5848
  <xsl:variable name="deletefile" select="java:java.nio.file.Files.deleteIfExists($xml_file_path)"/>
5754
5849
  </xsl:template>
5755
5850
 
5851
+ <xsl:template xmlns:redirect="http://xml.apache.org/xalan/redirect" name="getPageSequenceOrientation">
5852
+ <xsl:variable name="previous_orientation" select="preceding-sibling::*[local-name() = 'page_sequence'][@orientation][1]/@orientation"/>
5853
+ <xsl:choose>
5854
+ <xsl:when test="@orientation = 'landscape'">-<xsl:value-of select="@orientation"/></xsl:when>
5855
+ <xsl:when test="$previous_orientation = 'landscape' and not(@orientation = 'portrait')">-<xsl:value-of select="$previous_orientation"/></xsl:when>
5856
+ </xsl:choose>
5857
+ </xsl:template>
5858
+
5756
5859
  <xsl:variable xmlns:redirect="http://xml.apache.org/xalan/redirect" name="regex_standard_reference">([A-Z]{2,}(/[A-Z]{2,})* \d+(-\d+)*(:\d{4})?)</xsl:variable>
5757
5860
  <xsl:variable xmlns:redirect="http://xml.apache.org/xalan/redirect" name="tag_fo_inline_keep-together_within-line_open">###fo:inline keep-together_within-line###</xsl:variable>
5758
5861
  <xsl:variable xmlns:redirect="http://xml.apache.org/xalan/redirect" name="tag_fo_inline_keep-together_within-line_close">###/fo:inline keep-together_within-line###</xsl:variable>
@@ -5781,9 +5884,16 @@
5781
5884
  <xsl:value-of select="substring-before($text, $tag_open)"/>
5782
5885
  <!-- <xsl:text disable-output-escaping="yes">&lt;fo:inline keep-together.within-line="always"&gt;</xsl:text> -->
5783
5886
  <xsl:variable name="text_after" select="substring-after($text, $tag_open)"/>
5784
- <fo:inline keep-together.within-line="always">
5785
- <xsl:value-of select="substring-before($text_after, $tag_close)"/>
5786
- </fo:inline>
5887
+ <xsl:choose>
5888
+ <xsl:when test="local-name(..) = 'keep-together_within-line'"> <!-- prevent two nested <fo:inline keep-together.within-line="always"><fo:inline keep-together.within-line="always" -->
5889
+ <xsl:value-of select="substring-before($text_after, $tag_close)"/>
5890
+ </xsl:when>
5891
+ <xsl:otherwise>
5892
+ <fo:inline keep-together.within-line="always" role="SKIP">
5893
+ <xsl:value-of select="substring-before($text_after, $tag_close)"/>
5894
+ </fo:inline>
5895
+ </xsl:otherwise>
5896
+ </xsl:choose>
5787
5897
  <!-- <xsl:text disable-output-escaping="yes">&lt;/fo:inline&gt;</xsl:text> -->
5788
5898
  <xsl:call-template name="replace_fo_inline_tags">
5789
5899
  <xsl:with-param name="tag_open" select="$tag_open"/>
@@ -6097,7 +6207,9 @@
6097
6207
 
6098
6208
  <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']"/>
6099
6209
  <xsl:if test="$isNoteOrFnExist = 'true'">
6100
- <xsl:attribute name="border-bottom">0pt solid black</xsl:attribute><!-- set 0pt border, because there is a separete table below for footer -->
6210
+
6211
+ <xsl:attribute name="border-bottom">0pt solid black</xsl:attribute><!-- set 0pt border, because there is a separete table below for footer -->
6212
+
6101
6213
  </xsl:if>
6102
6214
 
6103
6215
  <xsl:choose>
@@ -6154,13 +6266,14 @@
6154
6266
  </fo:table>
6155
6267
 
6156
6268
  <xsl:variable name="colgroup" select="*[local-name()='colgroup']"/>
6157
- <xsl:for-each select="*[local-name()='tbody']"><!-- select context to tbody -->
6158
- <xsl:call-template name="insertTableFooterInSeparateTable">
6159
- <xsl:with-param name="table_attributes" select="$table_attributes"/>
6160
- <xsl:with-param name="colwidths" select="$colwidths"/>
6161
- <xsl:with-param name="colgroup" select="$colgroup"/>
6162
- </xsl:call-template>
6163
- </xsl:for-each>
6269
+
6270
+ <xsl:for-each select="*[local-name()='tbody']"><!-- select context to tbody -->
6271
+ <xsl:call-template name="insertTableFooterInSeparateTable">
6272
+ <xsl:with-param name="table_attributes" select="$table_attributes"/>
6273
+ <xsl:with-param name="colwidths" select="$colwidths"/>
6274
+ <xsl:with-param name="colgroup" select="$colgroup"/>
6275
+ </xsl:call-template>
6276
+ </xsl:for-each>
6164
6277
 
6165
6278
  <xsl:if test="*[local-name()='bookmark']"> <!-- special case: table/bookmark -->
6166
6279
  <fo:block keep-with-previous="always" line-height="0.1">
@@ -6554,8 +6667,10 @@
6554
6667
  <width_min><xsl:value-of select="@width_min"/></width_min>
6555
6668
  <e><xsl:value-of select="$d * $W div $D"/></e>
6556
6669
  <!-- set the column's width to the minimum width plus d times W over D. -->
6670
+ <xsl:variable name="column_width_" select="round(@width_min + $d * $W div $D)"/> <!-- * 10 -->
6671
+ <xsl:variable name="column_width" select="$column_width_*($column_width_ &gt;= 0) - $column_width_*($column_width_ &lt; 0)"/> <!-- absolute value -->
6557
6672
  <column divider="100">
6558
- <xsl:value-of select="round(@width_min + $d * $W div $D)"/> <!-- * 10 -->
6673
+ <xsl:value-of select="$column_width"/>
6559
6674
  </column>
6560
6675
  </xsl:for-each>
6561
6676
 
@@ -6978,8 +7093,26 @@
6978
7093
  <xsl:with-param name="default">center</xsl:with-param>
6979
7094
  </xsl:call-template>
6980
7095
 
7096
+ <xsl:copy-of select="@keep-together.within-line"/>
7097
+
6981
7098
  <xsl:call-template name="refine_table-header-cell-style"/>
6982
7099
 
7100
+ <!-- experimental feature, see https://github.com/metanorma/metanorma-plateau/issues/30#issuecomment-2145461828 -->
7101
+ <!-- <xsl:choose>
7102
+ <xsl:when test="count(node()) = 1 and *[local-name() = 'span'][contains(@style, 'text-orientation')]">
7103
+ <fo:block-container reference-orientation="270">
7104
+ <fo:block role="SKIP" text-align="start">
7105
+ <xsl:apply-templates />
7106
+ </fo:block>
7107
+ </fo:block-container>
7108
+ </xsl:when>
7109
+ <xsl:otherwise>
7110
+ <fo:block role="SKIP">
7111
+ <xsl:apply-templates />
7112
+ </fo:block>
7113
+ </xsl:otherwise>
7114
+ </xsl:choose> -->
7115
+
6983
7116
  <fo:block role="SKIP">
6984
7117
  <xsl:apply-templates/>
6985
7118
  </fo:block>
@@ -7020,6 +7153,8 @@
7020
7153
  <xsl:with-param name="default">left</xsl:with-param>
7021
7154
  </xsl:call-template>
7022
7155
 
7156
+ <xsl:copy-of select="@keep-together.within-line"/>
7157
+
7023
7158
  <xsl:call-template name="refine_table-cell-style"/>
7024
7159
 
7025
7160
  <xsl:if test=".//*[local-name() = 'table']"> <!-- if there is nested table -->
@@ -7059,6 +7194,7 @@
7059
7194
  <xsl:template xmlns:redirect="http://xml.apache.org/xalan/redirect" match="*[local-name()='table']/*[local-name()='note' or local-name() = 'example']" priority="2">
7060
7195
 
7061
7196
  <fo:block xsl:use-attribute-sets="table-note-style">
7197
+ <xsl:copy-of select="@id"/>
7062
7198
 
7063
7199
  <xsl:call-template name="refine_table-note-style"/>
7064
7200
 
@@ -7156,7 +7292,7 @@
7156
7292
  <xsl:copy-of select="."/>
7157
7293
  </xsl:for-each>
7158
7294
 
7159
- <xsl:if test="following-sibling::*[1][local-name() = 'fn']">
7295
+ <xsl:if test="following-sibling::node()[normalize-space() != ''][1][local-name() = 'fn']">
7160
7296
  <xsl:attribute name="padding-right">0.5mm</xsl:attribute>
7161
7297
  </xsl:if>
7162
7298
 
@@ -7223,7 +7359,7 @@
7223
7359
  <xsl:copy-of select="node()"/>
7224
7360
  </fn>
7225
7361
  </xsl:for-each>
7226
- <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']/*">
7362
+ <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']/*">
7227
7363
  <xsl:sort select="@displayorder" data-type="number"/>
7228
7364
  <!-- commented:
7229
7365
  .//*[local-name() = 'bibitem'][ancestor::*[local-name() = 'references']]/*[local-name() = 'note'] |
@@ -7301,6 +7437,11 @@
7301
7437
 
7302
7438
  <xsl:template xmlns:redirect="http://xml.apache.org/xalan/redirect" name="create_fn">
7303
7439
  <fn reference="{@reference}" id="{@reference}_{ancestor::*[@id][1]/@id}">
7440
+ <xsl:if test="ancestor::*[local-name()='table'][1]/@id"> <!-- for footnotes in tables -->
7441
+ <xsl:attribute name="id">
7442
+ <xsl:value-of select="concat(@reference, '_', ancestor::*[local-name()='table'][1]/@id)"/>
7443
+ </xsl:attribute>
7444
+ </xsl:if>
7304
7445
 
7305
7446
  <xsl:apply-templates/>
7306
7447
  </fn>
@@ -7444,6 +7585,11 @@
7444
7585
  <xsl:call-template name="refine_fn-reference-style"/>
7445
7586
 
7446
7587
  <fo:basic-link internal-destination="{@reference}_{ancestor::*[@id][1]/@id}" fox:alt-text="{@reference}"> <!-- @reference | ancestor::*[local-name()='clause'][1]/@id-->
7588
+ <xsl:if test="ancestor::*[local-name()='table'][1]/@id"> <!-- for footnotes in tables -->
7589
+ <xsl:attribute name="internal-destination">
7590
+ <xsl:value-of select="concat(@reference, '_', ancestor::*[local-name()='table'][1]/@id)"/>
7591
+ </xsl:attribute>
7592
+ </xsl:if>
7447
7593
 
7448
7594
  <fo:inline font-style="normal"> (</fo:inline>
7449
7595
 
@@ -8490,7 +8636,7 @@
8490
8636
 
8491
8637
  <xsl:template xmlns:redirect="http://xml.apache.org/xalan/redirect" name="recursiveSmallCaps">
8492
8638
  <xsl:param name="text"/>
8493
- <xsl:param name="ratio"/>
8639
+ <xsl:param name="ratio">0.75</xsl:param>
8494
8640
  <xsl:variable name="char" select="substring($text,1,1)"/>
8495
8641
  <!-- <xsl:variable name="upperCase" select="translate($char, $lower, $upper)"/> -->
8496
8642
  <xsl:variable name="upperCase" select="java:toUpperCase(java:java.lang.String.new($char))"/>
@@ -10544,6 +10690,15 @@
10544
10690
  <xsl:when test="@mimetype = 'image/svg+xml' and $images/images/image[@id = current()/@id]">
10545
10691
  <xsl:value-of select="$images/images/image[@id = current()/@id]/@src"/>
10546
10692
  </xsl:when>
10693
+ <!-- in WebP format, then convert image into PNG -->
10694
+ <xsl:when test="starts-with(@src, 'data:image/webp')">
10695
+ <xsl:variable name="src_png" select="java:org.metanorma.fop.utils.ImageUtils.convertWebPtoPNG(@src)"/>
10696
+ <xsl:value-of select="$src_png"/>
10697
+ </xsl:when>
10698
+ <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'))">
10699
+ <xsl:variable name="src_png" select="java:org.metanorma.fop.utils.ImageUtils.convertWebPtoPNG(@src)"/>
10700
+ <xsl:value-of select="concat('url(file:///',$basepath, $src_png, ')')"/>
10701
+ </xsl:when>
10547
10702
  <xsl:when test="not(starts-with(@src, 'data:'))">
10548
10703
  <xsl:value-of select="concat('url(file:///',$basepath, @src, ')')"/>
10549
10704
  </xsl:when>
@@ -10634,6 +10789,8 @@
10634
10789
  </xsl:choose>
10635
10790
  </xsl:variable>
10636
10791
 
10792
+ <xsl:variable name="isPrecedingTitle" select="normalize-space(ancestor::*[local-name() = 'figure']/preceding-sibling::*[1][local-name() = 'title'] and 1 = 1)"/>
10793
+
10637
10794
  <xsl:choose>
10638
10795
  <xsl:when test=".//*[local-name() = 'a'][*[local-name() = 'rect'] or *[local-name() = 'polygon'] or *[local-name() = 'circle'] or *[local-name() = 'ellipse']]">
10639
10796
  <fo:block>
@@ -10780,7 +10937,14 @@
10780
10937
  <xsl:variable name="scale_y">
10781
10938
  <xsl:choose>
10782
10939
  <xsl:when test="$svg_height * $scale_x &gt; $height_effective_px">
10783
- <xsl:value-of select="$height_effective_px div ($svg_height * $scale_x)"/>
10940
+ <xsl:variable name="height_effective_px_">
10941
+ <xsl:choose>
10942
+ <!-- title is 'keep-with-next' with following figure -->
10943
+ <xsl:when test="$isPrecedingTitle = 'true'"><xsl:value-of select="$height_effective_px - 80"/></xsl:when>
10944
+ <xsl:otherwise><xsl:value-of select="$height_effective_px"/></xsl:otherwise>
10945
+ </xsl:choose>
10946
+ </xsl:variable>
10947
+ <xsl:value-of select="$height_effective_px_ div ($svg_height * $scale_x)"/>
10784
10948
  </xsl:when>
10785
10949
  <xsl:otherwise>1</xsl:otherwise>
10786
10950
  </xsl:choose>
@@ -11199,7 +11363,7 @@
11199
11363
  </xsl:if>
11200
11364
 
11201
11365
  <xsl:for-each select="$contents_nodes/doc">
11202
- <fo:bookmark internal-destination="{contents/item[1]/@id}" starting-state="hide">
11366
+ <fo:bookmark internal-destination="{contents/item[@display = 'true'][1]/@id}" starting-state="hide">
11203
11367
  <xsl:if test="@bundle = 'true'">
11204
11368
  <xsl:attribute name="internal-destination"><xsl:value-of select="@firstpage_id"/></xsl:attribute>
11205
11369
  </xsl:if>
@@ -12423,9 +12587,17 @@
12423
12587
 
12424
12588
  <fo:block-container xsl:use-attribute-sets="example-body-style" role="SKIP">
12425
12589
  <fo:block-container margin-left="0mm" margin-right="0mm" role="SKIP">
12426
- <xsl:apply-templates select="node()[not(local-name() = 'name')]">
12427
- <xsl:with-param name="fo_element" select="$fo_element"/>
12428
- </xsl:apply-templates>
12590
+ <xsl:variable name="example_body">
12591
+ <xsl:apply-templates select="node()[not(local-name() = 'name')]">
12592
+ <xsl:with-param name="fo_element" select="$fo_element"/>
12593
+ </xsl:apply-templates>
12594
+ </xsl:variable>
12595
+ <xsl:choose>
12596
+ <xsl:when test="xalan:nodeset($example_body)/*">
12597
+ <xsl:copy-of select="$example_body"/>
12598
+ </xsl:when>
12599
+ <xsl:otherwise><fo:block/><!-- prevent empty block-container --></xsl:otherwise>
12600
+ </xsl:choose>
12429
12601
  </fo:block-container>
12430
12602
  </fo:block-container>
12431
12603
  </xsl:when> <!-- end block -->
@@ -12969,7 +13141,22 @@
12969
13141
 
12970
13142
  <!-- note: @top-level added in mode=" update_xml_step_move_pagebreak" -->
12971
13143
  <xsl:template xmlns:redirect="http://xml.apache.org/xalan/redirect" match="*[local-name() = 'sections']/*[local-name() = 'page_sequence']/*[not(@top-level)]" priority="2">
12972
- <xsl:call-template name="sections_node"/>
13144
+ <xsl:choose>
13145
+ <xsl:when test="local-name() = 'clause' and normalize-space() = '' and count(*) = 0"/>
13146
+ <xsl:otherwise>
13147
+ <xsl:call-template name="sections_node"/>
13148
+ </xsl:otherwise>
13149
+ </xsl:choose>
13150
+ </xsl:template>
13151
+
13152
+ <!-- page_sequence/sections/clause -->
13153
+ <xsl:template xmlns:redirect="http://xml.apache.org/xalan/redirect" match="*[local-name() = 'page_sequence']/*[local-name() = 'sections']/*[not(@top-level)]" priority="2">
13154
+ <xsl:choose>
13155
+ <xsl:when test="local-name() = 'clause' and normalize-space() = '' and count(*) = 0"/>
13156
+ <xsl:otherwise>
13157
+ <xsl:call-template name="sections_node"/>
13158
+ </xsl:otherwise>
13159
+ </xsl:choose>
12973
13160
  </xsl:template>
12974
13161
 
12975
13162
  <xsl:template xmlns:redirect="http://xml.apache.org/xalan/redirect" name="sections_element_style">
@@ -12986,8 +13173,24 @@
12986
13173
  </fo:block>
12987
13174
  </xsl:template>
12988
13175
 
12989
- <xsl:template xmlns:redirect="http://xml.apache.org/xalan/redirect" match="*[local-name() = 'preface']/*[local-name() = 'page_sequence']/*" priority="2"> <!-- /*/*[local-name() = 'preface']/* -->
12990
- <xsl:call-template name="preface_node"/>
13176
+ <!-- preface/ page_sequence/clause -->
13177
+ <xsl:template xmlns:redirect="http://xml.apache.org/xalan/redirect" match="*[local-name() = 'preface']/*[local-name() = 'page_sequence']/*[not(@top-level)]" priority="2"> <!-- /*/*[local-name() = 'preface']/* -->
13178
+ <xsl:choose>
13179
+ <xsl:when test="local-name() = 'clause' and normalize-space() = '' and count(*) = 0"/>
13180
+ <xsl:otherwise>
13181
+ <xsl:call-template name="preface_node"/>
13182
+ </xsl:otherwise>
13183
+ </xsl:choose>
13184
+ </xsl:template>
13185
+
13186
+ <!-- page_sequence/preface/clause -->
13187
+ <xsl:template xmlns:redirect="http://xml.apache.org/xalan/redirect" match="*[local-name() = 'page_sequence']/*[local-name() = 'preface']/*[not(@top-level)]" priority="2"> <!-- /*/*[local-name() = 'preface']/* -->
13188
+ <xsl:choose>
13189
+ <xsl:when test="local-name() = 'clause' and normalize-space() = '' and count(*) = 0"/>
13190
+ <xsl:otherwise>
13191
+ <xsl:call-template name="preface_node"/>
13192
+ </xsl:otherwise>
13193
+ </xsl:choose>
12991
13194
  </xsl:template>
12992
13195
 
12993
13196
  <xsl:template xmlns:redirect="http://xml.apache.org/xalan/redirect" match="*[local-name() = 'clause'][normalize-space() != '' or *[local-name() = 'figure'] or @id]" name="template_clause"> <!-- if clause isn't empty -->
@@ -14232,6 +14435,82 @@
14232
14435
  <!-- ===================================== -->
14233
14436
  <!-- Update xml -->
14234
14437
  <!-- ===================================== -->
14438
+
14439
+ <xsl:template xmlns:redirect="http://xml.apache.org/xalan/redirect" name="updateXML">
14440
+ <xsl:if test="$debug = 'true'"><xsl:message>START updated_xml_step1</xsl:message></xsl:if>
14441
+ <xsl:variable name="startTime1" select="java:getTime(java:java.util.Date.new())"/>
14442
+
14443
+ <!-- STEP1: Re-order elements in 'preface', 'sections' based on @displayorder -->
14444
+ <xsl:variable name="updated_xml_step1">
14445
+ <xsl:if test="$table_if = 'false'">
14446
+ <xsl:apply-templates mode="update_xml_step1"/>
14447
+ </xsl:if>
14448
+ </xsl:variable>
14449
+
14450
+ <xsl:variable name="endTime1" select="java:getTime(java:java.util.Date.new())"/>
14451
+ <xsl:if test="$debug = 'true'">
14452
+ <xsl:message>DEBUG: processing time <xsl:value-of select="$endTime1 - $startTime1"/> msec.</xsl:message>
14453
+ <xsl:message>END updated_xml_step1</xsl:message>
14454
+ <!-- <redirect:write file="updated_xml_step1_{java:getTime(java:java.util.Date.new())}.xml">
14455
+ <xsl:copy-of select="$updated_xml_step1"/>
14456
+ </redirect:write> -->
14457
+ </xsl:if>
14458
+
14459
+ <xsl:if test="$debug = 'true'"><xsl:message>START updated_xml_step2</xsl:message></xsl:if>
14460
+ <xsl:variable name="startTime2" select="java:getTime(java:java.util.Date.new())"/>
14461
+
14462
+ <!-- STEP2: add 'fn' after 'eref' and 'origin', if referenced to bibitem with 'note' = Withdrawn.' or 'Cancelled and replaced...' -->
14463
+ <xsl:variable name="updated_xml_step2">
14464
+
14465
+ <xsl:if test="$table_if = 'false'">
14466
+ <xsl:copy-of select="$updated_xml_step1"/>
14467
+ </xsl:if>
14468
+
14469
+ </xsl:variable>
14470
+
14471
+ <xsl:variable name="endTime2" select="java:getTime(java:java.util.Date.new())"/>
14472
+ <xsl:if test="$debug = 'true'">
14473
+ <xsl:message>DEBUG: processing time <xsl:value-of select="$endTime2 - $startTime2"/> msec.</xsl:message>
14474
+ <xsl:message>END updated_xml_step2</xsl:message>
14475
+ <!-- <redirect:write file="updated_xml_step2_{java:getTime(java:java.util.Date.new())}.xml">
14476
+ <xsl:copy-of select="$updated_xml_step2"/>
14477
+ </redirect:write> -->
14478
+ </xsl:if>
14479
+
14480
+ <xsl:if test="$debug = 'true'"><xsl:message>START updated_xml_step3</xsl:message></xsl:if>
14481
+ <xsl:variable name="startTime3" select="java:getTime(java:java.util.Date.new())"/>
14482
+
14483
+ <xsl:variable name="updated_xml_step3">
14484
+ <xsl:choose>
14485
+ <xsl:when test="$table_if = 'false'">
14486
+ <xsl:apply-templates select="xalan:nodeset($updated_xml_step2)" mode="update_xml_enclose_keep-together_within-line"/>
14487
+ </xsl:when>
14488
+ <xsl:otherwise>
14489
+ <xsl:apply-templates select="." mode="update_xml_enclose_keep-together_within-line"/>
14490
+ </xsl:otherwise>
14491
+ </xsl:choose>
14492
+ </xsl:variable>
14493
+
14494
+ <xsl:variable name="endTime3" select="java:getTime(java:java.util.Date.new())"/>
14495
+ <xsl:if test="$debug = 'true'">
14496
+ <xsl:message>DEBUG: processing time <xsl:value-of select="$endTime3 - $startTime3"/> msec.</xsl:message>
14497
+ <xsl:message>END updated_xml_step3</xsl:message>
14498
+ <!-- <redirect:write file="updated_xml_step3_{java:getTime(java:java.util.Date.new())}.xml">
14499
+ <xsl:copy-of select="$updated_xml_step3"/>
14500
+ </redirect:write> -->
14501
+ </xsl:if>
14502
+
14503
+ <!-- <xsl:if test="$debug = 'true'"><xsl:message>START copying updated_xml_step3</xsl:message></xsl:if>
14504
+ <xsl:variable name="startTime4" select="java:getTime(java:java.util.Date.new())"/> -->
14505
+ <xsl:copy-of select="$updated_xml_step3"/>
14506
+ <!-- <xsl:variable name="endTime4" select="java:getTime(java:java.util.Date.new())"/>
14507
+ <xsl:if test="$debug = 'true'">
14508
+ <xsl:message>DEBUG: processing time <xsl:value-of select="$endTime4 - $startTime4"/> msec.</xsl:message>
14509
+ <xsl:message>END copying updated_xml_step3</xsl:message>
14510
+ </xsl:if> -->
14511
+
14512
+ </xsl:template>
14513
+
14235
14514
  <!-- =========================================================================== -->
14236
14515
  <!-- STEP1: -->
14237
14516
  <!-- - Re-order elements in 'preface', 'sections' based on @displayorder -->
@@ -14410,14 +14689,17 @@
14410
14689
  <!-- STEP MOVE PAGEBREAK: move <pagebreak/> at top level under 'preface' and 'sections' -->
14411
14690
  <!-- =========================================================================== -->
14412
14691
  <xsl:template xmlns:redirect="http://xml.apache.org/xalan/redirect" match="@*|node()" mode="update_xml_step_move_pagebreak">
14692
+ <xsl:param name="page_sequence_at_top">false</xsl:param>
14413
14693
  <xsl:copy>
14414
- <xsl:apply-templates select="@*|node()" mode="update_xml_step_move_pagebreak"/>
14694
+ <xsl:apply-templates select="@*|node()" mode="update_xml_step_move_pagebreak">
14695
+ <xsl:with-param name="page_sequence_at_top" select="$page_sequence_at_top"/>
14696
+ </xsl:apply-templates>
14415
14697
  </xsl:copy>
14416
14698
  </xsl:template>
14417
14699
 
14418
14700
  <!-- replace 'pagebreak' by closing tags + page_sequence and opening page_sequence + tags -->
14419
14701
  <xsl:template xmlns:redirect="http://xml.apache.org/xalan/redirect" match="*[local-name() = 'pagebreak'][not(following-sibling::*[1][local-name() = 'pagebreak'])]" mode="update_xml_step_move_pagebreak">
14420
-
14702
+ <xsl:param name="page_sequence_at_top"/>
14421
14703
  <!-- <xsl:choose>
14422
14704
  <xsl:when test="ancestor::*[local-name() = 'sections']">
14423
14705
 
@@ -14431,7 +14713,7 @@
14431
14713
 
14432
14714
  <!-- determine pagebreak is last element before </fo:flow> or not -->
14433
14715
  <xsl:variable name="isLast">
14434
- <xsl:for-each select="ancestor-or-self::*[ancestor::*[local-name() = 'sections'] or ancestor-or-self::*[local-name() = 'annex']]">
14716
+ <xsl:for-each select="ancestor-or-self::*[ancestor::*[local-name() = 'preface'] or ancestor::*[local-name() = 'sections'] or ancestor-or-self::*[local-name() = 'annex']]">
14435
14717
  <xsl:if test="following-sibling::*">false</xsl:if>
14436
14718
  </xsl:for-each>
14437
14719
  </xsl:variable>
@@ -14441,7 +14723,9 @@
14441
14723
  <xsl:variable name="orientation" select="normalize-space(@orientation)"/>
14442
14724
 
14443
14725
  <xsl:variable name="tree_">
14444
- <xsl:call-template name="makeAncestorsElementsTree"/>
14726
+ <xsl:call-template name="makeAncestorsElementsTree">
14727
+ <xsl:with-param name="page_sequence_at_top" select="$page_sequence_at_top"/>
14728
+ </xsl:call-template>
14445
14729
  </xsl:variable>
14446
14730
  <xsl:variable name="tree" select="xalan:nodeset($tree_)"/>
14447
14731
 
@@ -14453,7 +14737,7 @@
14453
14737
  <xsl:text disable-output-escaping="yes">&lt;/page_sequence&gt;</xsl:text>
14454
14738
 
14455
14739
  <!-- create a new page_sequence (opening elements) -->
14456
- <xsl:text disable-output-escaping="yes">&lt;page_sequence namespace="</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>
14740
+ <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>
14457
14741
 
14458
14742
  <xsl:call-template name="insertOpeningElements">
14459
14743
  <xsl:with-param name="tree" select="$tree"/>
@@ -14463,12 +14747,26 @@
14463
14747
  </xsl:template>
14464
14748
 
14465
14749
  <xsl:template xmlns:redirect="http://xml.apache.org/xalan/redirect" name="makeAncestorsElementsTree">
14466
- <xsl:for-each select="ancestor::*[ancestor::*[local-name() = 'sections'] or ancestor-or-self::*[local-name() = 'annex']]">
14467
- <element pos="{position()}">
14468
- <xsl:copy-of select="@*[local-name() != 'id']"/>
14469
- <xsl:value-of select="name()"/>
14470
- </element>
14471
- </xsl:for-each>
14750
+ <xsl:param name="page_sequence_at_top"/>
14751
+
14752
+ <xsl:choose>
14753
+ <xsl:when test="$page_sequence_at_top = 'true'">
14754
+ <xsl:for-each select="ancestor::*[ancestor::*[contains(local-name(), '-standard')]]">
14755
+ <element pos="{position()}">
14756
+ <xsl:copy-of select="@*[local-name() != 'id']"/>
14757
+ <xsl:value-of select="name()"/>
14758
+ </element>
14759
+ </xsl:for-each>
14760
+ </xsl:when>
14761
+ <xsl:otherwise>
14762
+ <xsl:for-each select="ancestor::*[ancestor::*[local-name() = 'preface'] or ancestor::*[local-name() = 'sections'] or ancestor-or-self::*[local-name() = 'annex']]">
14763
+ <element pos="{position()}">
14764
+ <xsl:copy-of select="@*[local-name() != 'id']"/>
14765
+ <xsl:value-of select="name()"/>
14766
+ </element>
14767
+ </xsl:for-each>
14768
+ </xsl:otherwise>
14769
+ </xsl:choose>
14472
14770
  </xsl:template>
14473
14771
 
14474
14772
  <xsl:template xmlns:redirect="http://xml.apache.org/xalan/redirect" name="insertClosingElements">
@@ -14506,11 +14804,14 @@
14506
14804
 
14507
14805
  <!-- move full page width figures, tables at top level -->
14508
14806
  <xsl:template xmlns:redirect="http://xml.apache.org/xalan/redirect" match="*[local-name() = 'figure' or local-name() = 'table'][normalize-space(@width) != 'text-width']" mode="update_xml_step_move_pagebreak">
14807
+ <xsl:param name="page_sequence_at_top">false</xsl:param>
14509
14808
  <xsl:choose>
14510
14809
  <xsl:when test="$layout_columns != 1">
14511
14810
 
14512
14811
  <xsl:variable name="tree_">
14513
- <xsl:call-template name="makeAncestorsElementsTree"/>
14812
+ <xsl:call-template name="makeAncestorsElementsTree">
14813
+ <xsl:with-param name="page_sequence_at_top" select="$page_sequence_at_top"/>
14814
+ </xsl:call-template>
14514
14815
  </xsl:variable>
14515
14816
  <xsl:variable name="tree" select="xalan:nodeset($tree_)"/>
14516
14817
 
@@ -14554,81 +14855,140 @@
14554
14855
 
14555
14856
  <xsl:variable xmlns:redirect="http://xml.apache.org/xalan/redirect" name="express_reference_separators">_.\</xsl:variable>
14556
14857
  <xsl:variable xmlns:redirect="http://xml.apache.org/xalan/redirect" name="express_reference_characters" select="concat($upper,$lower,'1234567890',$express_reference_separators)"/>
14858
+ <xsl:variable xmlns:redirect="http://xml.apache.org/xalan/redirect" name="regex_express_reference">(^([A-Za-z0-9_.\\]+)$)</xsl:variable>
14557
14859
 
14558
14860
  <xsl:variable xmlns:redirect="http://xml.apache.org/xalan/redirect" name="element_name_keep-together_within-line">keep-together_within-line</xsl:variable>
14861
+ <xsl:variable xmlns:redirect="http://xml.apache.org/xalan/redirect" name="tag_keep-together_within-line_open">###<xsl:value-of select="$element_name_keep-together_within-line"/>###</xsl:variable>
14862
+ <xsl:variable xmlns:redirect="http://xml.apache.org/xalan/redirect" name="tag_keep-together_within-line_close">###/<xsl:value-of select="$element_name_keep-together_within-line"/>###</xsl:variable>
14559
14863
 
14560
- <xsl:template xmlns:redirect="http://xml.apache.org/xalan/redirect" match="text()[not(ancestor::*[local-name() = 'bibdata'] or ancestor::*[local-name() = 'link'][not(contains(.,' '))] or ancestor::*[local-name() = 'sourcecode'] or ancestor::*[local-name() = 'math'] or ancestor::*[local-name() = 'svg'] or starts-with(., 'http://') or starts-with(., 'https://') or starts-with(., 'www.') )]" name="keep_together_standard_number" mode="update_xml_enclose_keep-together_within-line">
14864
+ <!-- \S matches any non-whitespace character (equivalent to [^\r\n\t\f\v ]) -->
14865
+ <!-- <xsl:variable name="regex_solidus_units">((\b((\S{1,3}\/\S+)|(\S+\/\S{1,3}))\b)|(\/\S{1,3})\b)</xsl:variable> -->
14866
+ <!-- add &lt; and &gt; to \S -->
14867
+ <xsl:variable xmlns:redirect="http://xml.apache.org/xalan/redirect" name="regex_S">[^\r\n\t\f\v \&lt;&gt;\u3000-\u9FFF]</xsl:variable>
14868
+ <xsl:variable xmlns:redirect="http://xml.apache.org/xalan/redirect" name="regex_solidus_units">((\b((<xsl:value-of select="$regex_S"/>{1,3}\/<xsl:value-of select="$regex_S"/>+)|(<xsl:value-of select="$regex_S"/>+\/<xsl:value-of select="$regex_S"/>{1,3}))\b)|(\/<xsl:value-of select="$regex_S"/>{1,3})\b)</xsl:variable>
14561
14869
 
14562
- <!-- enclose standard's number into tag 'keep-together_within-line' -->
14563
- <xsl:variable name="tag_keep-together_within-line_open">###<xsl:value-of select="$element_name_keep-together_within-line"/>###</xsl:variable>
14564
- <xsl:variable name="tag_keep-together_within-line_close">###/<xsl:value-of select="$element_name_keep-together_within-line"/>###</xsl:variable>
14565
- <xsl:variable name="text__" select="java:replaceAll(java:java.lang.String.new(.), $regex_standard_reference, concat($tag_keep-together_within-line_open,'$1',$tag_keep-together_within-line_close))"/>
14566
- <xsl:variable name="text_">
14567
- <xsl:choose>
14568
- <xsl:when test="ancestor::*[local-name() = 'table']"><xsl:value-of select="."/></xsl:when> <!-- no need enclose standard's number into tag 'keep-together_within-line' in table cells -->
14569
- <xsl:otherwise><xsl:value-of select="$text__"/></xsl:otherwise>
14570
- </xsl:choose>
14571
- </xsl:variable>
14572
- <xsl:variable name="text"><text><xsl:call-template name="replace_text_tags">
14870
+ <xsl:variable xmlns:redirect="http://xml.apache.org/xalan/redirect" name="non_white_space">[^\s\u3000-\u9FFF]</xsl:variable>
14871
+ <xsl:variable xmlns:redirect="http://xml.apache.org/xalan/redirect" name="regex_dots_units">((\b((<xsl:value-of select="$non_white_space"/>{1,3}\.<xsl:value-of select="$non_white_space"/>+)|(<xsl:value-of select="$non_white_space"/>+\.<xsl:value-of select="$non_white_space"/>{1,3}))\b)|(\.<xsl:value-of select="$non_white_space"/>{1,3})\b)</xsl:variable>
14872
+
14873
+ <xsl:template xmlns:redirect="http://xml.apache.org/xalan/redirect" match="text()[not(ancestor::*[local-name() = 'bibdata'] or ancestor::*[local-name() = 'link'][not(contains(.,' '))] or ancestor::*[local-name() = 'sourcecode'] or ancestor::*[local-name() = 'math'] or ancestor::*[local-name() = 'svg'] or starts-with(., 'http://') or starts-with(., 'https://') or starts-with(., 'www.') or normalize-space() = '' )]" name="keep_together_standard_number" mode="update_xml_enclose_keep-together_within-line">
14874
+
14875
+ <xsl:variable name="parent" select="local-name(..)"/>
14876
+
14877
+ <xsl:if test="1 = 2"> <!-- alternative variant -->
14878
+
14879
+ <xsl:variable name="regexs">
14880
+ <!-- enclose standard's number into tag 'keep-together_within-line' -->
14881
+ <xsl:if test="not(ancestor::*[local-name() = 'table'])"><regex><xsl:value-of select="$regex_standard_reference"/></regex></xsl:if>
14882
+ <!-- if EXPRESS reference -->
14883
+
14884
+ <!-- keep-together_within-line for: a/b, aaa/b, a/bbb, /b -->
14885
+ <regex><xsl:value-of select="$regex_solidus_units"/></regex>
14886
+ <!-- keep-together_within-line for: a.b, aaa.b, a.bbb, .b in table's cell ONLY -->
14887
+ <xsl:if test="ancestor::*[local-name() = 'td' or local-name() = 'th']">
14888
+ <regex><xsl:value-of select="$regex_dots_units"/></regex>
14889
+ </xsl:if>
14890
+ </xsl:variable>
14891
+
14892
+ <xsl:variable name="regex_replacement"><xsl:text>(</xsl:text>
14893
+ <xsl:for-each select="xalan:nodeset($regexs)/regex">
14894
+ <xsl:value-of select="."/>
14895
+ <xsl:if test="position() != last()">|</xsl:if>
14896
+ </xsl:for-each>
14897
+ <xsl:text>)</xsl:text>
14898
+ </xsl:variable>
14899
+
14900
+ <!-- regex_replacement='<xsl:value-of select="$regex_replacement"/>' -->
14901
+
14902
+ <xsl:variable name="text_replaced" select="java:replaceAll(java:java.lang.String.new(.), $regex_replacement, concat($tag_keep-together_within-line_open,'$1',$tag_keep-together_within-line_close))"/>
14903
+
14904
+ <!-- text_replaced='<xsl:value-of select="$text_replaced"/>' -->
14905
+
14906
+ <xsl:call-template name="replace_text_tags">
14573
14907
  <xsl:with-param name="tag_open" select="$tag_keep-together_within-line_open"/>
14574
14908
  <xsl:with-param name="tag_close" select="$tag_keep-together_within-line_close"/>
14575
- <xsl:with-param name="text" select="$text_"/>
14576
- </xsl:call-template></text></xsl:variable>
14909
+ <xsl:with-param name="text" select="$text_replaced"/>
14910
+ </xsl:call-template>
14911
+ </xsl:if>
14577
14912
 
14578
- <xsl:variable name="parent" select="local-name(..)"/>
14913
+ <xsl:if test="1 = 1">
14914
+
14915
+ <!-- enclose standard's number into tag 'keep-together_within-line' -->
14916
+ <xsl:variable name="text">
14917
+ <xsl:element name="text" namespace="{$namespace_full}">
14918
+ <xsl:choose>
14919
+ <xsl:when test="ancestor::*[local-name() = 'table']"><xsl:value-of select="."/></xsl:when> <!-- no need enclose standard's number into tag 'keep-together_within-line' in table cells -->
14920
+ <xsl:otherwise>
14921
+ <xsl:variable name="text_" select="java:replaceAll(java:java.lang.String.new(.), $regex_standard_reference, concat($tag_keep-together_within-line_open,'$1',$tag_keep-together_within-line_close))"/>
14922
+ <!-- <xsl:value-of select="$text__"/> -->
14923
+
14924
+ <xsl:call-template name="replace_text_tags">
14925
+ <xsl:with-param name="tag_open" select="$tag_keep-together_within-line_open"/>
14926
+ <xsl:with-param name="tag_close" select="$tag_keep-together_within-line_close"/>
14927
+ <xsl:with-param name="text" select="$text_"/>
14928
+ </xsl:call-template>
14929
+
14930
+ </xsl:otherwise>
14931
+ </xsl:choose>
14932
+ </xsl:element>
14933
+ </xsl:variable>
14579
14934
 
14580
14935
  <xsl:variable name="text2">
14581
- <text><xsl:for-each select="xalan:nodeset($text)/text/node()">
14936
+ <xsl:element name="text" namespace="{$namespace_full}">
14937
+ <xsl:for-each select="xalan:nodeset($text)/*[local-name() = 'text']/node()">
14582
14938
  <xsl:copy-of select="."/>
14583
- </xsl:for-each></text>
14939
+ </xsl:for-each>
14940
+ </xsl:element>
14584
14941
  </xsl:variable>
14585
14942
 
14586
14943
  <!-- keep-together_within-line for: a/b, aaa/b, a/bbb, /b -->
14587
- <!-- \S matches any non-whitespace character (equivalent to [^\r\n\t\f\v ]) -->
14588
- <!-- <xsl:variable name="regex_solidus_units">((\b((\S{1,3}\/\S+)|(\S+\/\S{1,3}))\b)|(\/\S{1,3})\b)</xsl:variable> -->
14589
- <!-- add &lt; and &gt; to \S -->
14590
- <xsl:variable name="regex_S">[^\r\n\t\f\v \&lt;&gt;\u3000-\u9FFF]</xsl:variable>
14591
- <xsl:variable name="regex_solidus_units">((\b((<xsl:value-of select="$regex_S"/>{1,3}\/<xsl:value-of select="$regex_S"/>+)|(<xsl:value-of select="$regex_S"/>+\/<xsl:value-of select="$regex_S"/>{1,3}))\b)|(\/<xsl:value-of select="$regex_S"/>{1,3})\b)</xsl:variable>
14592
14944
  <xsl:variable name="text3">
14593
- <text><xsl:for-each select="xalan:nodeset($text2)/text/node()">
14594
- <xsl:choose>
14595
- <xsl:when test="self::text()">
14596
- <xsl:variable name="text_units_" select="java:replaceAll(java:java.lang.String.new(.),$regex_solidus_units,concat($tag_keep-together_within-line_open,'$1',$tag_keep-together_within-line_close))"/>
14597
- <xsl:variable name="text_units"><text><xsl:call-template name="replace_text_tags">
14598
- <xsl:with-param name="tag_open" select="$tag_keep-together_within-line_open"/>
14599
- <xsl:with-param name="tag_close" select="$tag_keep-together_within-line_close"/>
14600
- <xsl:with-param name="text" select="$text_units_"/>
14601
- </xsl:call-template></text></xsl:variable>
14602
- <xsl:copy-of select="xalan:nodeset($text_units)/text/node()"/>
14603
- </xsl:when>
14604
- <xsl:otherwise><xsl:copy-of select="."/></xsl:otherwise> <!-- copy 'as-is' for <fo:inline keep-together.within-line="always" ... -->
14605
- </xsl:choose>
14606
- </xsl:for-each></text>
14945
+ <xsl:element name="text" namespace="{$namespace_full}">
14946
+ <xsl:for-each select="xalan:nodeset($text2)/*[local-name() = 'text']/node()">
14947
+ <xsl:choose>
14948
+ <xsl:when test="self::text()">
14949
+ <xsl:variable name="text_units" select="java:replaceAll(java:java.lang.String.new(.),$regex_solidus_units,concat($tag_keep-together_within-line_open,'$1',$tag_keep-together_within-line_close))"/>
14950
+ <!-- <xsl:variable name="text_units">
14951
+ <xsl:element name="text" namespace="{$namespace_full}"> -->
14952
+ <xsl:call-template name="replace_text_tags">
14953
+ <xsl:with-param name="tag_open" select="$tag_keep-together_within-line_open"/>
14954
+ <xsl:with-param name="tag_close" select="$tag_keep-together_within-line_close"/>
14955
+ <xsl:with-param name="text" select="$text_units"/>
14956
+ </xsl:call-template>
14957
+ <!-- </xsl:element>
14958
+ </xsl:variable>
14959
+ <xsl:copy-of select="xalan:nodeset($text_units)/*[local-name() = 'text']/node()"/> -->
14960
+ </xsl:when>
14961
+ <xsl:otherwise><xsl:copy-of select="."/></xsl:otherwise> <!-- copy 'as-is' for <fo:inline keep-together.within-line="always" ... -->
14962
+ </xsl:choose>
14963
+ </xsl:for-each>
14964
+ </xsl:element>
14607
14965
  </xsl:variable>
14608
14966
 
14609
14967
  <xsl:choose>
14610
14968
  <xsl:when test="ancestor::*[local-name() = 'td' or local-name() = 'th']">
14611
14969
  <!-- keep-together_within-line for: a.b, aaa.b, a.bbb, .b in table's cell ONLY -->
14612
- <xsl:variable name="non_white_space">[^\s\u3000-\u9FFF]</xsl:variable>
14613
- <xsl:variable name="regex_dots_units">((\b((<xsl:value-of select="$non_white_space"/>{1,3}\.<xsl:value-of select="$non_white_space"/>+)|(<xsl:value-of select="$non_white_space"/>+\.<xsl:value-of select="$non_white_space"/>{1,3}))\b)|(\.<xsl:value-of select="$non_white_space"/>{1,3})\b)</xsl:variable>
14614
- <xsl:for-each select="xalan:nodeset($text3)/text/node()">
14970
+ <xsl:for-each select="xalan:nodeset($text3)/*[local-name() = 'text']/node()">
14615
14971
  <xsl:choose>
14616
14972
  <xsl:when test="self::text()">
14617
- <xsl:variable name="text_dots_" select="java:replaceAll(java:java.lang.String.new(.),$regex_dots_units,concat($tag_keep-together_within-line_open,'$1',$tag_keep-together_within-line_close))"/>
14618
- <xsl:variable name="text_dots"><text><xsl:call-template name="replace_text_tags">
14619
- <xsl:with-param name="tag_open" select="$tag_keep-together_within-line_open"/>
14620
- <xsl:with-param name="tag_close" select="$tag_keep-together_within-line_close"/>
14621
- <xsl:with-param name="text" select="$text_dots_"/>
14622
- </xsl:call-template></text></xsl:variable>
14623
- <xsl:copy-of select="xalan:nodeset($text_dots)/text/node()"/>
14973
+ <xsl:variable name="text_dots" select="java:replaceAll(java:java.lang.String.new(.),$regex_dots_units,concat($tag_keep-together_within-line_open,'$1',$tag_keep-together_within-line_close))"/>
14974
+ <!-- <xsl:variable name="text_dots">
14975
+ <xsl:element name="text" namespace="{$namespace_full}"> -->
14976
+ <xsl:call-template name="replace_text_tags">
14977
+ <xsl:with-param name="tag_open" select="$tag_keep-together_within-line_open"/>
14978
+ <xsl:with-param name="tag_close" select="$tag_keep-together_within-line_close"/>
14979
+ <xsl:with-param name="text" select="$text_dots"/>
14980
+ </xsl:call-template>
14981
+ <!-- </xsl:element>
14982
+ </xsl:variable>
14983
+ <xsl:copy-of select="xalan:nodeset($text_dots)/*[local-name() = 'text']/node()"/> -->
14624
14984
  </xsl:when>
14625
14985
  <xsl:otherwise><xsl:copy-of select="."/></xsl:otherwise> <!-- copy 'as-is' for <fo:inline keep-together.within-line="always" ... -->
14626
14986
  </xsl:choose>
14627
14987
  </xsl:for-each>
14628
14988
  </xsl:when>
14629
- <xsl:otherwise><xsl:copy-of select="xalan:nodeset($text3)/text/node()"/></xsl:otherwise>
14989
+ <xsl:otherwise><xsl:copy-of select="xalan:nodeset($text3)/*[local-name() = 'text']/node()"/></xsl:otherwise>
14630
14990
  </xsl:choose>
14631
-
14991
+ </xsl:if>
14632
14992
  </xsl:template>
14633
14993
 
14634
14994
  <xsl:template xmlns:redirect="http://xml.apache.org/xalan/redirect" match="*[local-name() = 'stem'] | *[local-name() = 'image']" mode="update_xml_enclose_keep-together_within-line">
@@ -14644,7 +15004,7 @@
14644
15004
  <xsl:value-of select="substring-before($text, $tag_open)"/>
14645
15005
  <xsl:variable name="text_after" select="substring-after($text, $tag_open)"/>
14646
15006
 
14647
- <xsl:element name="{substring-before(substring-after($tag_open, '###'),'###')}">
15007
+ <xsl:element name="{substring-before(substring-after($tag_open, '###'),'###')}" namespace="{$namespace_full}">
14648
15008
  <xsl:value-of select="substring-before($text_after, $tag_close)"/>
14649
15009
  </xsl:element>
14650
15010
 
@@ -15151,6 +15511,15 @@
15151
15511
  </xsl:otherwise>
15152
15512
  </xsl:choose>
15153
15513
  </xsl:for-each>
15514
+ <!-- references to external attachments (no binary-encoded within the Metanorma XML file) -->
15515
+ <xsl:if test="not(//*[contains(local-name(), '-standard')]/*[local-name() = 'metanorma-extension']/*[local-name() = 'attachment'])">
15516
+ <xsl:for-each select="//*[local-name() = 'bibitem'][@hidden = 'true'][*[local-name() = 'uri'][@type = 'attachment']]">
15517
+ <xsl:variable name="attachment_path" select="*[local-name() = 'uri'][@type = 'attachment']"/>
15518
+ <xsl:variable name="url" select="concat('url(file:///',$inputxml_basepath, $attachment_path, ')')"/>
15519
+ <xsl:variable name="filename_embedded" select="substring-after($attachment_path, concat('_', $inputxml_filename_prefix, '_attachments', '/'))"/>
15520
+ <pdf:embedded-file src="{$url}" filename="{$filename_embedded}"/>
15521
+ </xsl:for-each>
15522
+ </xsl:if>
15154
15523
  </xsl:template> <!-- addPDFUAmeta -->
15155
15524
 
15156
15525
  <xsl:template xmlns:redirect="http://xml.apache.org/xalan/redirect" name="getId">
@@ -15466,7 +15835,10 @@
15466
15835
  <xsl:call-template name="setTextAlignment">
15467
15836
  <xsl:with-param name="default" select="$text_align_default"/>
15468
15837
  </xsl:call-template>
15838
+ <xsl:call-template name="setKeepAttributes"/>
15839
+ </xsl:template>
15469
15840
 
15841
+ <xsl:template xmlns:redirect="http://xml.apache.org/xalan/redirect" name="setKeepAttributes">
15470
15842
  <!-- https://www.metanorma.org/author/topics/document-format/text/#avoiding-page-breaks -->
15471
15843
  <!-- Example: keep-lines-together="true" -->
15472
15844
  <xsl:if test="@keep-lines-together = 'true'">
@@ -15478,6 +15850,72 @@
15478
15850
  </xsl:if>
15479
15851
  </xsl:template>
15480
15852
 
15853
+ <!-- insert cover page image -->
15854
+ <!-- background cover image -->
15855
+ <xsl:template xmlns:redirect="http://xml.apache.org/xalan/redirect" name="insertBackgroundPageImage">
15856
+ <xsl:param name="number">1</xsl:param>
15857
+ <xsl:param name="name">coverpage-image</xsl:param>
15858
+ <xsl:variable name="num" select="number($number)"/>
15859
+ <!-- background image -->
15860
+ <fo:block-container absolute-position="fixed" left="0mm" top="0mm" font-size="0" id="__internal_layout__coverpage_{$name}_{$number}_{generate-id()}">
15861
+ <fo:block>
15862
+ <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]">
15863
+ <xsl:choose>
15864
+ <xsl:when test="*[local-name() = 'svg'] or java:endsWith(java:java.lang.String.new(@src), '.svg')">
15865
+ <fo:instream-foreign-object fox:alt-text="Image Front">
15866
+ <xsl:attribute name="content-height"><xsl:value-of select="$pageHeight"/>mm</xsl:attribute>
15867
+ <xsl:call-template name="getSVG"/>
15868
+ </fo:instream-foreign-object>
15869
+ </xsl:when>
15870
+ <xsl:when test="starts-with(@src, 'data:application/pdf;base64')">
15871
+ <fo:external-graphic src="{@src}" fox:alt-text="Image Front"/>
15872
+ </xsl:when>
15873
+ <xsl:otherwise> <!-- bitmap image -->
15874
+ <xsl:variable name="coverimage_src" select="normalize-space(@src)"/>
15875
+ <xsl:if test="$coverimage_src != ''">
15876
+ <xsl:variable name="coverpage">
15877
+ <xsl:call-template name="getImageURL">
15878
+ <xsl:with-param name="src" select="$coverimage_src"/>
15879
+ </xsl:call-template>
15880
+ </xsl:variable>
15881
+ <!-- <xsl:variable name="coverpage" select="concat('url(file:',$basepath, 'coverpage1.png', ')')"/> --> <!-- for DEBUG -->
15882
+ <fo:external-graphic src="{$coverpage}" width="{$pageWidth}mm" content-height="scale-to-fit" scaling="uniform" fox:alt-text="Image Front"/>
15883
+ </xsl:if>
15884
+ </xsl:otherwise>
15885
+ </xsl:choose>
15886
+ </xsl:for-each>
15887
+ </fo:block>
15888
+ </fo:block-container>
15889
+ </xsl:template>
15890
+
15891
+ <xsl:template xmlns:redirect="http://xml.apache.org/xalan/redirect" name="getImageURL">
15892
+ <xsl:param name="src"/>
15893
+ <xsl:choose>
15894
+ <xsl:when test="starts-with($src, 'data:image')">
15895
+ <xsl:value-of select="$src"/>
15896
+ </xsl:when>
15897
+ <xsl:otherwise>
15898
+ <xsl:value-of select="concat('url(file:///',$basepath, $src, ')')"/>
15899
+ </xsl:otherwise>
15900
+ </xsl:choose>
15901
+ </xsl:template>
15902
+
15903
+ <xsl:template xmlns:redirect="http://xml.apache.org/xalan/redirect" name="getSVG">
15904
+ <xsl:choose>
15905
+ <xsl:when test="*[local-name() = 'svg']">
15906
+ <xsl:apply-templates select="*[local-name() = 'svg']" mode="svg_update"/>
15907
+ </xsl:when>
15908
+ <xsl:otherwise>
15909
+ <xsl:variable name="svg_content" select="document(@src)"/>
15910
+ <xsl:for-each select="xalan:nodeset($svg_content)/node()">
15911
+ <xsl:apply-templates select="." mode="svg_update"/>
15912
+ </xsl:for-each>
15913
+ </xsl:otherwise>
15914
+ </xsl:choose>
15915
+ </xsl:template>
15916
+
15917
+ <!-- END: insert cover page image -->
15918
+
15481
15919
  <xsl:template xmlns:redirect="http://xml.apache.org/xalan/redirect" name="number-to-words">
15482
15920
  <xsl:param name="number"/>
15483
15921
  <xsl:param name="first"/>