metanorma-iso 2.7.10 → 2.8.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -382,7 +382,6 @@
382
382
  <xsl:variable name="revision_date" select="normalize-space(/iso:iso-standard/iso:bibdata/iso:version/iso:revision-date)"/>
383
383
  <xsl:variable name="revision_date_num" select="number(translate($revision_date,'-',''))"/>
384
384
 
385
- <xsl:variable name="document_scheme" select="normalize-space(/iso:iso-standard/iso:metanorma-extension/iso:presentation-metadata[iso:name = 'document-scheme']/iso:value)"/>
386
385
  <xsl:variable name="layoutVersion_">
387
386
  <xsl:choose>
388
387
  <xsl:when test="$document_scheme = ''">2024</xsl:when>
@@ -811,12 +810,36 @@
811
810
 
812
811
  <xsl:call-template name="insertCoverPage"/>
813
812
 
813
+ <xsl:if test="$debug = 'true'">
814
+ <xsl:message>START updated_xml</xsl:message>
815
+ </xsl:if>
816
+ <xsl:variable name="startTime0" select="java:getTime(java:java.util.Date.new())"/>
817
+
814
818
  <xsl:variable name="updated_xml">
815
819
  <xsl:call-template name="updateXML"/>
816
820
  </xsl:variable>
817
821
 
822
+ <xsl:if test="$debug = 'true'">
823
+ <xsl:message>End updated_xml</xsl:message>
824
+ <xsl:message>DEBUG: processing time <xsl:value-of select="java:getTime(java:java.util.Date.new()) - $startTime0"/> msec.</xsl:message>
825
+ </xsl:if>
826
+
818
827
  <xsl:for-each select="xalan:nodeset($updated_xml)/*">
819
828
 
829
+ <xsl:if test="$debug = 'true'">
830
+ <xsl:message>START updated_xml_with_pages</xsl:message>
831
+ </xsl:if>
832
+ <xsl:variable name="startTimeA" select="java:getTime(java:java.util.Date.new())"/>
833
+
834
+ <xsl:variable name="updated_xml_with_pages">
835
+ <xsl:call-template name="processPrefaceAndMainSectionsISO_items"/>
836
+ </xsl:variable>
837
+
838
+ <xsl:if test="$debug = 'true'">
839
+ <xsl:message>END updated_xml_with_pages</xsl:message>
840
+ <xsl:message>DEBUG: processing time <xsl:value-of select="java:getTime(java:java.util.Date.new()) - $startTimeA"/> msec.</xsl:message>
841
+ </xsl:if>
842
+
820
843
  <xsl:choose>
821
844
  <xsl:when test="$layoutVersion = '1951'">
822
845
  <fo:page-sequence master-reference="document{$document-master-reference}" initial-page-number="auto" force-page-count="no-force">
@@ -960,25 +983,13 @@
960
983
  </xsl:when> <!-- $layoutVersion = '1987' and $doctype = 'technical-report' -->
961
984
  <xsl:otherwise>
962
985
 
963
- <xsl:variable name="update_xml_step4_with_pages_preface">
964
- <xsl:call-template name="processPrefaceSectionsDefault_items"/>
965
- </xsl:variable>
966
-
967
- <xsl:if test="$debug = 'true'">
968
- <xsl:message>start redirect</xsl:message>
969
- <redirect:write file="update_xml_step4_with_pages_preface.xml">
970
- <xsl:copy-of select="$update_xml_step4_with_pages_preface"/>
971
- </redirect:write>
972
- <xsl:message>end redirect</xsl:message>
973
- </xsl:if>
974
-
975
986
  <xsl:variable name="copyright-statement">
976
987
  <xsl:apply-templates select="/iso:iso-standard/iso:boilerplate/iso:copyright-statement"/>
977
988
  </xsl:variable>
978
989
 
979
- <xsl:for-each select="xalan:nodeset($update_xml_step4_with_pages_preface)"> <!-- set context to preface -->
990
+ <xsl:for-each select="xalan:nodeset($updated_xml_with_pages)"> <!-- set context to preface/sections -->
980
991
 
981
- <xsl:for-each select=".//*[local-name() = 'page_sequence'][normalize-space() != '' or .//image or .//svg]">
992
+ <xsl:for-each select=".//*[local-name() = 'page_sequence'][parent::*[local-name() = 'preface']][normalize-space() != '' or .//image or .//svg]">
982
993
 
983
994
  <fo:page-sequence format="i" force-page-count="no-force">
984
995
 
@@ -1120,28 +1131,14 @@
1120
1131
  <xsl:apply-templates select="/*/*[local-name()='preface']/*[local-name() = 'introduction']"/>
1121
1132
  </xsl:variable>
1122
1133
 
1123
- <xsl:variable name="update_xml_step4_with_pages_main">
1124
- <xsl:choose>
1125
- <xsl:when test="$doctype = 'amendment'">
1126
- <xsl:call-template name="processMainSectionsAmendmentDefault_items"/>
1127
- </xsl:when>
1128
- <xsl:otherwise>
1129
- <xsl:call-template name="processMainSectionsDefault_items"/>
1130
- </xsl:otherwise>
1131
- </xsl:choose>
1132
- </xsl:variable>
1133
-
1134
1134
  <xsl:if test="$debug = 'true'">
1135
- <xsl:message>start redirect</xsl:message>
1136
- <redirect:write file="update_xml_step4_with_pages_main.xml">
1137
- <xsl:copy-of select="$update_xml_step4_with_pages_main"/>
1138
- </redirect:write>
1139
- <xsl:message>end redirect</xsl:message>
1135
+ <xsl:message>START xalan:nodeset($updated_xml_with_pages) for sections</xsl:message>
1140
1136
  </xsl:if>
1137
+ <xsl:variable name="startTimeC" select="java:getTime(java:java.util.Date.new())"/>
1141
1138
 
1142
- <xsl:for-each select="xalan:nodeset($update_xml_step4_with_pages_main)"> <!-- set context to sections, if top element in 'sections' -->
1139
+ <xsl:for-each select="xalan:nodeset($updated_xml_with_pages)"> <!-- set context to sections, if top element in 'sections' -->
1143
1140
 
1144
- <xsl:for-each select=".//*[local-name() = 'page_sequence'][normalize-space() != '' or .//image or .//svg]">
1141
+ <xsl:for-each select=".//*[local-name() = 'page_sequence'][not(parent::*[local-name() = 'preface'])][normalize-space() != '' or .//image or .//svg]">
1145
1142
 
1146
1143
  <!-- BODY -->
1147
1144
  <fo:page-sequence force-page-count="no-force">
@@ -1302,6 +1299,11 @@
1302
1299
  </xsl:for-each>
1303
1300
  </xsl:for-each>
1304
1301
 
1302
+ <xsl:if test="$debug = 'true'">
1303
+ <xsl:message>END xalan:nodeset($updated_xml_with_pages) for sections</xsl:message>
1304
+ <xsl:message>DEBUG: processing time <xsl:value-of select="java:getTime(java:java.util.Date.new()) - $startTimeC"/> msec.</xsl:message>
1305
+ </xsl:if>
1306
+
1305
1307
  <!-- Index -->
1306
1308
  <!-- <xsl:message>START current_document_index_id</xsl:message> -->
1307
1309
 
@@ -1353,33 +1355,77 @@
1353
1355
 
1354
1356
  </xsl:template>
1355
1357
 
1356
- <xsl:template name="processMainSectionsAmendmentDefault_items">
1357
- <xsl:variable name="updated_xml_step_move_pagebreak_">
1358
- <xsl:element name="{$root_element}" namespace="{$namespace_full}">
1359
- <xsl:element name="sections" namespace="{$namespace_full}"> <!-- save context element -->
1360
- <xsl:element name="page_sequence" namespace="{$namespace_full}">
1361
- <xsl:for-each select="/*/*[local-name()='sections']/*">
1362
- <xsl:sort select="@displayorder" data-type="number"/>
1363
- <xsl:apply-templates select="." mode="update_xml_step_move_pagebreak"/>
1358
+ <xsl:template name="insertMainSectionsAmendmentPageSequences">
1359
+ <xsl:element name="sections" namespace="{$namespace_full}"> <!-- save context element -->
1360
+ <xsl:element name="page_sequence" namespace="{$namespace_full}">
1361
+ <xsl:for-each select="/*/*[local-name()='sections']/*">
1362
+ <xsl:sort select="@displayorder" data-type="number"/>
1363
+ <xsl:apply-templates select="." mode="update_xml_step_move_pagebreak"/>
1364
1364
 
1365
- </xsl:for-each>
1366
- </xsl:element>
1367
- </xsl:element>
1365
+ </xsl:for-each>
1366
+ </xsl:element>
1367
+ </xsl:element>
1368
+ </xsl:template> <!-- END: processMainSectionsAmendmentDefault_items -->
1369
+
1370
+ <xsl:template name="processPrefaceAndMainSectionsISO_items">
1371
+
1372
+ <!-- <xsl:if test="$debug = 'true'"><xsl:message>START updated_xml_step_move_pagebreak</xsl:message></xsl:if>
1373
+ <xsl:variable name="startTime1" select="java:getTime(java:java.util.Date.new())"/> -->
1374
+
1375
+ <xsl:variable name="updated_xml_step_move_pagebreak">
1376
+ <xsl:element name="{$root_element}" namespace="{$namespace_full}">
1377
+ <xsl:call-template name="copyCommonElements"/>
1378
+ <xsl:call-template name="insertPrefaceSectionsPageSequences"/>
1379
+ <xsl:choose>
1380
+ <xsl:when test="$doctype = 'amendment'">
1381
+ <xsl:call-template name="insertMainSectionsAmendmentPageSequences"/>
1382
+ </xsl:when>
1383
+ <xsl:otherwise>
1384
+ <xsl:call-template name="insertMainSectionsPageSequences"/>
1385
+ </xsl:otherwise>
1386
+ </xsl:choose>
1368
1387
  </xsl:element>
1369
1388
  </xsl:variable>
1389
+ <!-- <xsl:variable name="endTime1" select="java:getTime(java:java.util.Date.new())"/>
1390
+ <xsl:if test="$debug = 'true'">
1391
+ <xsl:message>DEBUG: processing time <xsl:value-of select="$endTime1 - $startTime1"/> msec.</xsl:message>
1392
+ <xsl:message>END updated_xml_step_move_pagebreak</xsl:message>
1393
+ </xsl:if> -->
1370
1394
 
1371
1395
  <xsl:variable name="updated_xml_step_move_pagebreak_filename" select="concat($output_path,'_main_', java:getTime(java:java.util.Date.new()), '.xml')"/>
1372
1396
 
1397
+ <!-- <xsl:if test="$debug = 'true'"><xsl:message>START write updated_xml_step_move_pagebreak</xsl:message></xsl:if>
1398
+ <xsl:variable name="startTime2" select="java:getTime(java:java.util.Date.new())"/> -->
1373
1399
  <redirect:write file="{$updated_xml_step_move_pagebreak_filename}">
1374
- <xsl:copy-of select="$updated_xml_step_move_pagebreak_"/>
1400
+ <xsl:copy-of select="$updated_xml_step_move_pagebreak"/>
1375
1401
  </redirect:write>
1402
+ <!-- <xsl:variable name="endTime2" select="java:getTime(java:java.util.Date.new())"/>
1403
+ <xsl:if test="$debug = 'true'">
1404
+ <xsl:message>DEBUG: processing time <xsl:value-of select="$endTime2 - $startTime2"/> msec.</xsl:message>
1405
+ <xsl:message>END write updated_xml_step_move_pagebreak</xsl:message>
1406
+ </xsl:if> -->
1376
1407
 
1408
+ <!-- <xsl:if test="$debug = 'true'"><xsl:message>START loading document() updated_xml_step_move_pagebreak</xsl:message></xsl:if>
1409
+ <xsl:variable name="startTime3" select="java:getTime(java:java.util.Date.new())"/> -->
1377
1410
  <xsl:copy-of select="document($updated_xml_step_move_pagebreak_filename)"/>
1378
1411
 
1412
+ <!-- <xsl:variable name="endTime3" select="java:getTime(java:java.util.Date.new())"/>
1413
+ <xsl:if test="$debug = 'true'">
1414
+ <xsl:message>DEBUG: processing time <xsl:value-of select="$endTime3 - $startTime3"/> msec.</xsl:message>
1415
+ <xsl:message>END loading document() updated_xml_step_move_pagebreak</xsl:message>
1416
+ </xsl:if>
1417
+ -->
1418
+
1419
+ <xsl:if test="$debug = 'true'">
1420
+ <redirect:write file="page_sequence_preface_and_main.xml">
1421
+ <xsl:copy-of select="$updated_xml_step_move_pagebreak"/>
1422
+ </redirect:write>
1423
+ </xsl:if>
1424
+
1379
1425
  <xsl:call-template name="deleteFile">
1380
1426
  <xsl:with-param name="filepath" select="$updated_xml_step_move_pagebreak_filename"/>
1381
1427
  </xsl:call-template>
1382
- </xsl:template> <!-- END: processMainSectionsAmendmentDefault_items -->
1428
+ </xsl:template> <!-- END: processPrefaceAndMainSectionsISO_items -->
1383
1429
 
1384
1430
  <xsl:template name="insertCoverPage">
1385
1431
  <xsl:if test="$isGenerateTableIF = 'false'"> <!-- no need cover page for auto-layout algorithm -->
@@ -4800,6 +4846,8 @@
4800
4846
  <xsl:variable name="namespace_full" select="namespace-uri(/*)"/> <!-- example: https://www.metanorma.org/ns/iso -->
4801
4847
  <xsl:variable name="root_element" select="local-name(/*)"/> <!-- example: iso-standard -->
4802
4848
 
4849
+ <xsl:variable 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'])"/>
4850
+
4803
4851
  <!-- external parameters -->
4804
4852
 
4805
4853
  <xsl:param name="svg_images"/> <!-- svg images array -->
@@ -6712,56 +6760,9 @@
6712
6760
  </xsl:for-each>
6713
6761
  </xsl:template>
6714
6762
 
6715
- <xsl:template name="processPrefaceSectionsDefault_items">
6716
-
6717
- <xsl:variable name="updated_xml_step_move_pagebreak">
6718
-
6719
- <xsl:element name="{$root_element}" namespace="{$namespace_full}">
6720
-
6721
- <xsl:call-template name="copyCommonElements"/>
6722
-
6723
- <xsl:element name="preface" namespace="{$namespace_full}"> <!-- save context element -->
6724
- <xsl:element name="page_sequence" namespace="{$namespace_full}">
6725
- <xsl:for-each select="/*/*[local-name()='preface']/*[not(local-name() = 'note' or local-name() = 'admonition')]">
6726
- <xsl:sort select="@displayorder" data-type="number"/>
6727
- <xsl:apply-templates select="." mode="update_xml_step_move_pagebreak"/>
6728
- </xsl:for-each>
6729
- </xsl:element>
6730
- </xsl:element>
6731
- </xsl:element>
6732
- </xsl:variable>
6733
-
6734
- <xsl:variable name="updated_xml_step_move_pagebreak_filename" select="concat($output_path,'_preface_', java:getTime(java:java.util.Date.new()), '.xml')"/>
6735
- <!-- <xsl:message>updated_xml_step_move_pagebreak_filename=<xsl:value-of select="$updated_xml_step_move_pagebreak_filename"/></xsl:message>
6736
- <xsl:message>start write updated_xml_step_move_pagebreak_filename</xsl:message> -->
6737
- <redirect:write file="{$updated_xml_step_move_pagebreak_filename}">
6738
- <xsl:copy-of select="$updated_xml_step_move_pagebreak"/>
6739
- </redirect:write>
6740
- <!-- <xsl:message>end write updated_xml_step_move_pagebreak_filename</xsl:message> -->
6741
-
6742
- <xsl:copy-of select="document($updated_xml_step_move_pagebreak_filename)"/>
6743
-
6744
- <!-- TODO: instead of
6745
- <xsl:for-each select=".//*[local-name() = 'page_sequence'][normalize-space() != '' or .//image or .//svg]">
6746
- in each template, add removing empty page_sequence here
6747
- -->
6748
-
6749
- <xsl:if test="$debug = 'true'">
6750
- <redirect:write file="page_sequence_preface.xml">
6751
- <xsl:copy-of select="document($updated_xml_step_move_pagebreak_filename)"/>
6752
- </redirect:write>
6753
- </xsl:if>
6754
-
6755
- <!-- <xsl:message>start delete updated_xml_step_move_pagebreak_filename</xsl:message> -->
6756
- <xsl:call-template name="deleteFile">
6757
- <xsl:with-param name="filepath" select="$updated_xml_step_move_pagebreak_filename"/>
6758
- </xsl:call-template>
6759
- <!-- <xsl:message>end delete updated_xml_step_move_pagebreak_filename</xsl:message> -->
6760
- </xsl:template> <!-- END: processPrefaceSectionsDefault_items -->
6761
-
6762
6763
  <xsl:template name="copyCommonElements">
6763
6764
  <!-- copy bibdata, localized-strings, metanorma-extension and boilerplate -->
6764
- <xsl:copy-of select="/*/*[local-name() != 'preface' and local-name() != 'sections' and local-name() != 'annex' and local-name() != 'bibliography']"/>
6765
+ <xsl:copy-of select="/*/*[local-name() != 'preface' and local-name() != 'sections' and local-name() != 'annex' and local-name() != 'bibliography' and local-name() != 'indexsect']"/>
6765
6766
  </xsl:template>
6766
6767
 
6767
6768
  <xsl:template name="processMainSectionsDefault">
@@ -6782,8 +6783,16 @@
6782
6783
  </xsl:for-each>
6783
6784
  </xsl:template><!-- END: processMainSectionsDefault -->
6784
6785
 
6785
- <!-- Example:
6786
+ <!-- Example:
6786
6787
  <iso-standard>
6788
+ <preface>
6789
+ <page_sequence>
6790
+ <clause...
6791
+ </page_sequence>
6792
+ <page_sequence>
6793
+ <clause...
6794
+ </page_sequence>
6795
+ </preface>
6787
6796
  <sections>
6788
6797
  <page_sequence>
6789
6798
  <clause...
@@ -6800,60 +6809,200 @@
6800
6809
  </page_sequence>
6801
6810
  </iso-standard>
6802
6811
  -->
6803
- <xsl:template name="processMainSectionsDefault_items">
6812
+ <xsl:template name="processPrefaceAndMainSectionsDefault_items">
6804
6813
 
6805
6814
  <xsl:variable name="updated_xml_step_move_pagebreak">
6806
-
6807
6815
  <xsl:element name="{$root_element}" namespace="{$namespace_full}">
6808
-
6809
6816
  <xsl:call-template name="copyCommonElements"/>
6817
+ <xsl:call-template name="insertPrefaceSectionsPageSequences"/>
6818
+ <xsl:call-template name="insertMainSectionsPageSequences"/>
6819
+ </xsl:element>
6820
+ </xsl:variable>
6810
6821
 
6811
- <xsl:element name="sections" namespace="{$namespace_full}"> <!-- save context element -->
6812
- <xsl:element name="page_sequence" namespace="{$namespace_full}">
6813
- <xsl:for-each select="/*/*[local-name()='sections']/* | /*/*[local-name()='bibliography']/*[local-name()='references'][@normative='true']">
6814
- <xsl:sort select="@displayorder" data-type="number"/>
6815
- <xsl:apply-templates select="." mode="update_xml_step_move_pagebreak"/>
6822
+ <xsl:variable name="updated_xml_step_move_pagebreak_filename" select="concat($output_path,'_main_', java:getTime(java:java.util.Date.new()), '.xml')"/>
6816
6823
 
6817
- </xsl:for-each>
6818
- </xsl:element>
6824
+ <redirect:write file="{$updated_xml_step_move_pagebreak_filename}">
6825
+ <xsl:copy-of select="$updated_xml_step_move_pagebreak"/>
6826
+ </redirect:write>
6827
+
6828
+ <xsl:copy-of select="document($updated_xml_step_move_pagebreak_filename)"/>
6829
+
6830
+ <xsl:if test="$debug = 'true'">
6831
+ <redirect:write file="page_sequence_preface_and_main.xml">
6832
+ <xsl:copy-of select="$updated_xml_step_move_pagebreak"/>
6833
+ </redirect:write>
6834
+ </xsl:if>
6835
+
6836
+ <xsl:call-template name="deleteFile">
6837
+ <xsl:with-param name="filepath" select="$updated_xml_step_move_pagebreak_filename"/>
6838
+ </xsl:call-template>
6839
+ </xsl:template> <!-- END: processPrefaceAndMainSectionsDefault_items -->
6840
+
6841
+ <xsl:template name="insertPrefaceSectionsPageSequences">
6842
+ <xsl:element name="preface" namespace="{$namespace_full}"> <!-- save context element -->
6843
+ <xsl:element name="page_sequence" namespace="{$namespace_full}">
6844
+ <xsl:for-each select="/*/*[local-name()='preface']/*[not(local-name() = 'note' or local-name() = 'admonition')]">
6845
+ <xsl:sort select="@displayorder" data-type="number"/>
6846
+ <xsl:apply-templates select="." mode="update_xml_step_move_pagebreak"/>
6847
+ </xsl:for-each>
6848
+ </xsl:element>
6849
+ </xsl:element>
6850
+ </xsl:template> <!-- END: insertPrefaceSectionsPageSequences -->
6851
+
6852
+ <xsl:template name="insertMainSectionsPageSequences">
6853
+ <xsl:element name="sections" namespace="{$namespace_full}"> <!-- save context element -->
6854
+ <xsl:element name="page_sequence" namespace="{$namespace_full}">
6855
+ <xsl:for-each select="/*/*[local-name()='sections']/* | /*/*[local-name()='bibliography']/*[local-name()='references'][@normative='true']">
6856
+ <xsl:sort select="@displayorder" data-type="number"/>
6857
+ <xsl:apply-templates select="." mode="update_xml_step_move_pagebreak"/>
6858
+
6859
+ </xsl:for-each>
6860
+ </xsl:element>
6861
+ </xsl:element>
6862
+
6863
+ <xsl:element name="page_sequence" namespace="{$namespace_full}">
6864
+ <xsl:for-each select="/*/*[local-name()='annex']">
6865
+ <xsl:sort select="@displayorder" data-type="number"/>
6866
+ <xsl:apply-templates select="." mode="update_xml_step_move_pagebreak"/>
6867
+ </xsl:for-each>
6868
+ </xsl:element>
6869
+
6870
+ <xsl:element name="page_sequence" namespace="{$namespace_full}">
6871
+ <xsl:element name="bibliography" namespace="{$namespace_full}"> <!-- save context element -->
6872
+ <xsl:for-each select="/*/*[local-name()='bibliography']/*[not(@normative='true')] | /*/*[local-name()='bibliography']/*[local-name()='clause'][*[local-name()='references'][not(@normative='true')]]">
6873
+ <xsl:sort select="@displayorder" data-type="number"/>
6874
+ <xsl:apply-templates select="." mode="update_xml_step_move_pagebreak"/>
6875
+ </xsl:for-each>
6876
+ </xsl:element>
6877
+ </xsl:element>
6878
+ </xsl:template> <!-- END: insertMainSectionsPageSequences -->
6879
+
6880
+ <xsl:template name="insertMainSectionsInSeparatePageSequences">
6881
+ <xsl:element name="sections" namespace="{$namespace_full}"> <!-- save context element -->
6882
+ <xsl:for-each select="/*/*[local-name()='sections']/* | /*/*[local-name()='bibliography']/*[local-name()='references'][@normative='true']">
6883
+ <xsl:sort select="@displayorder" data-type="number"/>
6884
+ <xsl:element name="page_sequence" namespace="{$namespace_full}">
6885
+ <xsl:attribute name="main_page_sequence"/>
6886
+ <xsl:apply-templates select="." mode="update_xml_step_move_pagebreak"/>
6819
6887
  </xsl:element>
6888
+ </xsl:for-each>
6889
+ </xsl:element>
6890
+
6891
+ <xsl:call-template name="insertAnnexInSeparatePageSequences"/>
6892
+
6893
+ <xsl:call-template name="insertBibliographyInSeparatePageSequences"/>
6820
6894
 
6895
+ <!-- <xsl:call-template name="insertIndexInSeparatePageSequences"/> -->
6896
+ </xsl:template> <!-- END: insertMainSectionsInSeparatePageSequences -->
6897
+
6898
+ <xsl:template name="insertAnnexInSeparatePageSequences">
6899
+ <xsl:for-each select="/*/*[local-name()='annex']">
6900
+ <xsl:sort select="@displayorder" data-type="number"/>
6901
+ <xsl:element name="page_sequence" namespace="{$namespace_full}">
6902
+ <xsl:attribute name="main_page_sequence"/>
6903
+ <xsl:apply-templates select="." mode="update_xml_step_move_pagebreak"/>
6904
+ </xsl:element>
6905
+ </xsl:for-each>
6906
+ </xsl:template>
6907
+ <xsl:template name="insertBibliographyInSeparatePageSequences">
6908
+ <xsl:element name="bibliography" namespace="{$namespace_full}"> <!-- save context element -->
6909
+ <xsl:for-each select="/*/*[local-name()='bibliography']/*[not(@normative='true')] | /*/*[local-name()='bibliography']/*[local-name()='clause'][*[local-name()='references'][not(@normative='true')]]">
6910
+ <xsl:sort select="@displayorder" data-type="number"/>
6821
6911
  <xsl:element name="page_sequence" namespace="{$namespace_full}">
6822
- <xsl:for-each select="/*/*[local-name()='annex']">
6823
- <xsl:sort select="@displayorder" data-type="number"/>
6824
- <xsl:apply-templates select="." mode="update_xml_step_move_pagebreak"/>
6825
- </xsl:for-each>
6912
+ <xsl:attribute name="main_page_sequence"/>
6913
+ <xsl:apply-templates select="." mode="update_xml_step_move_pagebreak"/>
6826
6914
  </xsl:element>
6915
+ </xsl:for-each>
6916
+ </xsl:element>
6917
+ </xsl:template>
6918
+ <xsl:template name="insertIndexInSeparatePageSequences">
6919
+ <xsl:for-each select="/*/*[local-name()='indexsect']">
6920
+ <xsl:sort select="@displayorder" data-type="number"/>
6921
+ <xsl:element name="page_sequence" namespace="{$namespace_full}">
6922
+ <xsl:attribute name="main_page_sequence"/>
6923
+ <xsl:apply-templates select="." mode="update_xml_step_move_pagebreak"/>
6924
+ </xsl:element>
6925
+ </xsl:for-each>
6926
+ </xsl:template>
6827
6927
 
6928
+ <xsl:template name="processAllSectionsDefault_items">
6929
+ <xsl:variable name="updated_xml_step_move_pagebreak">
6930
+ <xsl:element name="{$root_element}" namespace="{$namespace_full}">
6931
+ <xsl:call-template name="copyCommonElements"/>
6828
6932
  <xsl:element name="page_sequence" namespace="{$namespace_full}">
6829
- <xsl:element name="bibliography" namespace="{$namespace_full}"> <!-- save context element -->
6830
- <xsl:for-each select="/*/*[local-name()='bibliography']/*[not(@normative='true')] | /*/*[local-name()='bibliography']/*[local-name()='clause'][*[local-name()='references'][not(@normative='true')]]">
6831
- <xsl:sort select="@displayorder" data-type="number"/>
6832
- <xsl:apply-templates select="." mode="update_xml_step_move_pagebreak"/>
6833
- </xsl:for-each>
6834
- </xsl:element>
6933
+ <xsl:call-template name="insertPrefaceSections"/>
6934
+ <xsl:call-template name="insertMainSections"/>
6835
6935
  </xsl:element>
6836
6936
  </xsl:element>
6837
6937
  </xsl:variable>
6838
6938
 
6839
- <xsl:variable name="updated_xml_step_move_pagebreak_filename" select="concat($output_path,'_main_', java:getTime(java:java.util.Date.new()), '.xml')"/>
6840
-
6939
+ <xsl:variable name="updated_xml_step_move_pagebreak_filename" select="concat($output_path,'_preface_and_main_', java:getTime(java:java.util.Date.new()), '.xml')"/>
6940
+ <!-- <xsl:message>updated_xml_step_move_pagebreak_filename=<xsl:value-of select="$updated_xml_step_move_pagebreak_filename"/></xsl:message>
6941
+ <xsl:message>start write updated_xml_step_move_pagebreak_filename</xsl:message> -->
6841
6942
  <redirect:write file="{$updated_xml_step_move_pagebreak_filename}">
6842
6943
  <xsl:copy-of select="$updated_xml_step_move_pagebreak"/>
6843
6944
  </redirect:write>
6945
+ <!-- <xsl:message>end write updated_xml_step_move_pagebreak_filename</xsl:message> -->
6844
6946
 
6845
6947
  <xsl:copy-of select="document($updated_xml_step_move_pagebreak_filename)"/>
6846
6948
 
6949
+ <!-- TODO: instead of
6950
+ <xsl:for-each select=".//*[local-name() = 'page_sequence'][normalize-space() != '' or .//image or .//svg]">
6951
+ in each template, add removing empty page_sequence here
6952
+ -->
6953
+
6847
6954
  <xsl:if test="$debug = 'true'">
6848
- <redirect:write file="page_sequence_main.xml">
6849
- <xsl:copy-of select="document($updated_xml_step_move_pagebreak_filename)"/>
6955
+ <redirect:write file="page_sequence_preface_and_main.xml">
6956
+ <xsl:copy-of select="$updated_xml_step_move_pagebreak"/>
6850
6957
  </redirect:write>
6851
6958
  </xsl:if>
6852
6959
 
6960
+ <!-- <xsl:message>start delete updated_xml_step_move_pagebreak_filename</xsl:message> -->
6853
6961
  <xsl:call-template name="deleteFile">
6854
6962
  <xsl:with-param name="filepath" select="$updated_xml_step_move_pagebreak_filename"/>
6855
6963
  </xsl:call-template>
6856
- </xsl:template> <!-- END: processMainSectionsDefault_items -->
6964
+ <!-- <xsl:message>end delete updated_xml_step_move_pagebreak_filename</xsl:message> -->
6965
+ </xsl:template> <!-- END: processAllSectionsDefault_items -->
6966
+
6967
+ <xsl:template name="insertPrefaceSections">
6968
+ <xsl:element name="preface" namespace="{$namespace_full}"> <!-- save context element -->
6969
+ <xsl:for-each select="/*/*[local-name()='preface']/*[not(local-name() = 'note' or local-name() = 'admonition')]">
6970
+ <xsl:sort select="@displayorder" data-type="number"/>
6971
+ <xsl:apply-templates select="." mode="update_xml_step_move_pagebreak">
6972
+ <xsl:with-param name="page_sequence_at_top">true</xsl:with-param>
6973
+ </xsl:apply-templates>
6974
+ </xsl:for-each>
6975
+ </xsl:element>
6976
+ </xsl:template>
6977
+
6978
+ <xsl:template name="insertMainSections">
6979
+ <xsl:element name="sections" namespace="{$namespace_full}"> <!-- save context element -->
6980
+
6981
+ <xsl:for-each select="/*/*[local-name()='sections']/* | /*/*[local-name()='bibliography']/*[local-name()='references'][@normative='true']">
6982
+ <xsl:sort select="@displayorder" data-type="number"/>
6983
+ <xsl:apply-templates select="." mode="update_xml_step_move_pagebreak">
6984
+ <xsl:with-param name="page_sequence_at_top">true</xsl:with-param>
6985
+ </xsl:apply-templates>
6986
+
6987
+ </xsl:for-each>
6988
+ </xsl:element>
6989
+
6990
+ <xsl:for-each select="/*/*[local-name()='annex']">
6991
+ <xsl:sort select="@displayorder" data-type="number"/>
6992
+ <xsl:apply-templates select="." mode="update_xml_step_move_pagebreak">
6993
+ <xsl:with-param name="page_sequence_at_top">true</xsl:with-param>
6994
+ </xsl:apply-templates>
6995
+ </xsl:for-each>
6996
+
6997
+ <xsl:element name="bibliography" namespace="{$namespace_full}"> <!-- save context element -->
6998
+ <xsl:for-each select="/*/*[local-name()='bibliography']/*[not(@normative='true')] | /*/*[local-name()='bibliography']/*[local-name()='clause'][*[local-name()='references'][not(@normative='true')]]">
6999
+ <xsl:sort select="@displayorder" data-type="number"/>
7000
+ <xsl:apply-templates select="." mode="update_xml_step_move_pagebreak">
7001
+ <xsl:with-param name="page_sequence_at_top">true</xsl:with-param>
7002
+ </xsl:apply-templates>
7003
+ </xsl:for-each>
7004
+ </xsl:element>
7005
+ </xsl:template>
6857
7006
 
6858
7007
  <xsl:template name="deleteFile">
6859
7008
  <xsl:param name="filepath"/>
@@ -6886,9 +7035,16 @@
6886
7035
  <xsl:value-of select="substring-before($text, $tag_open)"/>
6887
7036
  <!-- <xsl:text disable-output-escaping="yes">&lt;fo:inline keep-together.within-line="always"&gt;</xsl:text> -->
6888
7037
  <xsl:variable name="text_after" select="substring-after($text, $tag_open)"/>
6889
- <fo:inline keep-together.within-line="always">
6890
- <xsl:value-of select="substring-before($text_after, $tag_close)"/>
6891
- </fo:inline>
7038
+ <xsl:choose>
7039
+ <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" -->
7040
+ <xsl:value-of select="substring-before($text_after, $tag_close)"/>
7041
+ </xsl:when>
7042
+ <xsl:otherwise>
7043
+ <fo:inline keep-together.within-line="always" role="SKIP">
7044
+ <xsl:value-of select="substring-before($text_after, $tag_close)"/>
7045
+ </fo:inline>
7046
+ </xsl:otherwise>
7047
+ </xsl:choose>
6892
7048
  <!-- <xsl:text disable-output-escaping="yes">&lt;/fo:inline&gt;</xsl:text> -->
6893
7049
  <xsl:call-template name="replace_fo_inline_tags">
6894
7050
  <xsl:with-param name="tag_open" select="$tag_open"/>
@@ -8142,6 +8298,8 @@
8142
8298
  <xsl:with-param name="default">center</xsl:with-param>
8143
8299
  </xsl:call-template>
8144
8300
 
8301
+ <xsl:copy-of select="@keep-together.within-line"/>
8302
+
8145
8303
  <xsl:call-template name="refine_table-header-cell-style"/>
8146
8304
 
8147
8305
  <!-- experimental feature, see https://github.com/metanorma/metanorma-plateau/issues/30#issuecomment-2145461828 -->
@@ -8200,6 +8358,8 @@
8200
8358
  <xsl:with-param name="default">left</xsl:with-param>
8201
8359
  </xsl:call-template>
8202
8360
 
8361
+ <xsl:copy-of select="@keep-together.within-line"/>
8362
+
8203
8363
  <xsl:call-template name="refine_table-cell-style"/>
8204
8364
 
8205
8365
  <xsl:if test=".//*[local-name() = 'table']"> <!-- if there is nested table -->
@@ -8230,6 +8390,7 @@
8230
8390
  <xsl:template match="*[local-name()='table']/*[local-name()='note' or local-name() = 'example']" priority="2">
8231
8391
 
8232
8392
  <fo:block xsl:use-attribute-sets="table-note-style">
8393
+ <xsl:copy-of select="@id"/>
8233
8394
 
8234
8395
  <xsl:call-template name="refine_table-note-style"/>
8235
8396
 
@@ -8325,7 +8486,7 @@
8325
8486
  <xsl:copy-of select="."/>
8326
8487
  </xsl:for-each>
8327
8488
 
8328
- <xsl:if test="following-sibling::*[1][local-name() = 'fn']">
8489
+ <xsl:if test="following-sibling::node()[normalize-space() != ''][1][local-name() = 'fn']">
8329
8490
  <xsl:attribute name="padding-right">0.5mm</xsl:attribute>
8330
8491
  </xsl:if>
8331
8492
 
@@ -8396,7 +8557,7 @@
8396
8557
  <xsl:copy-of select="node()"/>
8397
8558
  </fn>
8398
8559
  </xsl:for-each>
8399
- <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']/*">
8560
+ <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']/*">
8400
8561
  <xsl:sort select="@displayorder" data-type="number"/>
8401
8562
  <!-- commented:
8402
8563
  .//*[local-name() = 'bibitem'][ancestor::*[local-name() = 'references']]/*[local-name() = 'note'] |
@@ -8470,6 +8631,11 @@
8470
8631
 
8471
8632
  <xsl:template name="create_fn">
8472
8633
  <fn reference="{@reference}" id="{@reference}_{ancestor::*[@id][1]/@id}">
8634
+ <xsl:if test="ancestor::*[local-name()='table'][1]/@id"> <!-- for footnotes in tables -->
8635
+ <xsl:attribute name="id">
8636
+ <xsl:value-of select="concat(@reference, '_', ancestor::*[local-name()='table'][1]/@id)"/>
8637
+ </xsl:attribute>
8638
+ </xsl:if>
8473
8639
 
8474
8640
  <xsl:apply-templates/>
8475
8641
  </fn>
@@ -8613,6 +8779,11 @@
8613
8779
  <xsl:call-template name="refine_fn-reference-style"/>
8614
8780
 
8615
8781
  <fo:basic-link internal-destination="{@reference}_{ancestor::*[@id][1]/@id}" fox:alt-text="{@reference}"> <!-- @reference | ancestor::*[local-name()='clause'][1]/@id-->
8782
+ <xsl:if test="ancestor::*[local-name()='table'][1]/@id"> <!-- for footnotes in tables -->
8783
+ <xsl:attribute name="internal-destination">
8784
+ <xsl:value-of select="concat(@reference, '_', ancestor::*[local-name()='table'][1]/@id)"/>
8785
+ </xsl:attribute>
8786
+ </xsl:if>
8616
8787
 
8617
8788
  <xsl:value-of select="@reference"/>
8618
8789
 
@@ -9685,7 +9856,7 @@
9685
9856
 
9686
9857
  <xsl:template name="recursiveSmallCaps">
9687
9858
  <xsl:param name="text"/>
9688
- <xsl:param name="ratio"/>
9859
+ <xsl:param name="ratio">0.75</xsl:param>
9689
9860
  <xsl:variable name="char" select="substring($text,1,1)"/>
9690
9861
  <!-- <xsl:variable name="upperCase" select="translate($char, $lower, $upper)"/> -->
9691
9862
  <xsl:variable name="upperCase" select="java:toUpperCase(java:java.lang.String.new($char))"/>
@@ -11869,6 +12040,8 @@
11869
12040
  </xsl:choose>
11870
12041
  </xsl:variable>
11871
12042
 
12043
+ <xsl:variable name="isPrecedingTitle" select="normalize-space(ancestor::*[local-name() = 'figure']/preceding-sibling::*[1][local-name() = 'title'] and 1 = 1)"/>
12044
+
11872
12045
  <xsl:choose>
11873
12046
  <xsl:when test=".//*[local-name() = 'a'][*[local-name() = 'rect'] or *[local-name() = 'polygon'] or *[local-name() = 'circle'] or *[local-name() = 'ellipse']]">
11874
12047
  <fo:block>
@@ -12015,7 +12188,14 @@
12015
12188
  <xsl:variable name="scale_y">
12016
12189
  <xsl:choose>
12017
12190
  <xsl:when test="$svg_height * $scale_x &gt; $height_effective_px">
12018
- <xsl:value-of select="$height_effective_px div ($svg_height * $scale_x)"/>
12191
+ <xsl:variable name="height_effective_px_">
12192
+ <xsl:choose>
12193
+ <!-- title is 'keep-with-next' with following figure -->
12194
+ <xsl:when test="$isPrecedingTitle = 'true'"><xsl:value-of select="$height_effective_px - 80"/></xsl:when>
12195
+ <xsl:otherwise><xsl:value-of select="$height_effective_px"/></xsl:otherwise>
12196
+ </xsl:choose>
12197
+ </xsl:variable>
12198
+ <xsl:value-of select="$height_effective_px_ div ($svg_height * $scale_x)"/>
12019
12199
  </xsl:when>
12020
12200
  <xsl:otherwise>1</xsl:otherwise>
12021
12201
  </xsl:choose>
@@ -12434,7 +12614,7 @@
12434
12614
  </xsl:if>
12435
12615
 
12436
12616
  <xsl:for-each select="$contents_nodes/doc">
12437
- <fo:bookmark internal-destination="{contents/item[1]/@id}" starting-state="hide">
12617
+ <fo:bookmark internal-destination="{contents/item[@display = 'true'][1]/@id}" starting-state="hide">
12438
12618
  <xsl:if test="@bundle = 'true'">
12439
12619
  <xsl:attribute name="internal-destination"><xsl:value-of select="@firstpage_id"/></xsl:attribute>
12440
12620
  </xsl:if>
@@ -13646,9 +13826,17 @@
13646
13826
 
13647
13827
  <fo:block-container xsl:use-attribute-sets="example-body-style" role="SKIP">
13648
13828
  <fo:block-container margin-left="0mm" margin-right="0mm" role="SKIP">
13649
- <xsl:apply-templates select="node()[not(local-name() = 'name')]">
13650
- <xsl:with-param name="fo_element" select="$fo_element"/>
13651
- </xsl:apply-templates>
13829
+ <xsl:variable name="example_body">
13830
+ <xsl:apply-templates select="node()[not(local-name() = 'name')]">
13831
+ <xsl:with-param name="fo_element" select="$fo_element"/>
13832
+ </xsl:apply-templates>
13833
+ </xsl:variable>
13834
+ <xsl:choose>
13835
+ <xsl:when test="xalan:nodeset($example_body)/*">
13836
+ <xsl:copy-of select="$example_body"/>
13837
+ </xsl:when>
13838
+ <xsl:otherwise><fo:block/><!-- prevent empty block-container --></xsl:otherwise>
13839
+ </xsl:choose>
13652
13840
  </fo:block-container>
13653
13841
  </fo:block-container>
13654
13842
  </xsl:when> <!-- end block -->
@@ -14190,7 +14378,22 @@
14190
14378
 
14191
14379
  <!-- note: @top-level added in mode=" update_xml_step_move_pagebreak" -->
14192
14380
  <xsl:template match="*[local-name() = 'sections']/*[local-name() = 'page_sequence']/*[not(@top-level)]" priority="2">
14193
- <xsl:call-template name="sections_node"/>
14381
+ <xsl:choose>
14382
+ <xsl:when test="local-name() = 'clause' and normalize-space() = '' and count(*) = 0"/>
14383
+ <xsl:otherwise>
14384
+ <xsl:call-template name="sections_node"/>
14385
+ </xsl:otherwise>
14386
+ </xsl:choose>
14387
+ </xsl:template>
14388
+
14389
+ <!-- page_sequence/sections/clause -->
14390
+ <xsl:template match="*[local-name() = 'page_sequence']/*[local-name() = 'sections']/*[not(@top-level)]" priority="2">
14391
+ <xsl:choose>
14392
+ <xsl:when test="local-name() = 'clause' and normalize-space() = '' and count(*) = 0"/>
14393
+ <xsl:otherwise>
14394
+ <xsl:call-template name="sections_node"/>
14395
+ </xsl:otherwise>
14396
+ </xsl:choose>
14194
14397
  </xsl:template>
14195
14398
 
14196
14399
  <xsl:template name="sections_element_style">
@@ -14218,8 +14421,24 @@
14218
14421
  </fo:block>
14219
14422
  </xsl:template>
14220
14423
 
14221
- <xsl:template match="*[local-name() = 'preface']/*[local-name() = 'page_sequence']/*" priority="2"> <!-- /*/*[local-name() = 'preface']/* -->
14222
- <xsl:call-template name="preface_node"/>
14424
+ <!-- preface/ page_sequence/clause -->
14425
+ <xsl:template match="*[local-name() = 'preface']/*[local-name() = 'page_sequence']/*[not(@top-level)]" priority="2"> <!-- /*/*[local-name() = 'preface']/* -->
14426
+ <xsl:choose>
14427
+ <xsl:when test="local-name() = 'clause' and normalize-space() = '' and count(*) = 0"/>
14428
+ <xsl:otherwise>
14429
+ <xsl:call-template name="preface_node"/>
14430
+ </xsl:otherwise>
14431
+ </xsl:choose>
14432
+ </xsl:template>
14433
+
14434
+ <!-- page_sequence/preface/clause -->
14435
+ <xsl:template match="*[local-name() = 'page_sequence']/*[local-name() = 'preface']/*[not(@top-level)]" priority="2"> <!-- /*/*[local-name() = 'preface']/* -->
14436
+ <xsl:choose>
14437
+ <xsl:when test="local-name() = 'clause' and normalize-space() = '' and count(*) = 0"/>
14438
+ <xsl:otherwise>
14439
+ <xsl:call-template name="preface_node"/>
14440
+ </xsl:otherwise>
14441
+ </xsl:choose>
14223
14442
  </xsl:template>
14224
14443
 
14225
14444
  <xsl:template match="*[local-name() = 'clause'][normalize-space() != '' or *[local-name() = 'figure'] or @id]" name="template_clause"> <!-- if clause isn't empty -->
@@ -15536,7 +15755,14 @@
15536
15755
  </redirect:write> -->
15537
15756
  </xsl:if>
15538
15757
 
15758
+ <!-- <xsl:if test="$debug = 'true'"><xsl:message>START copying updated_xml_step3</xsl:message></xsl:if>
15759
+ <xsl:variable name="startTime4" select="java:getTime(java:java.util.Date.new())"/> -->
15539
15760
  <xsl:copy-of select="$updated_xml_step3"/>
15761
+ <!-- <xsl:variable name="endTime4" select="java:getTime(java:java.util.Date.new())"/>
15762
+ <xsl:if test="$debug = 'true'">
15763
+ <xsl:message>DEBUG: processing time <xsl:value-of select="$endTime4 - $startTime4"/> msec.</xsl:message>
15764
+ <xsl:message>END copying updated_xml_step3</xsl:message>
15765
+ </xsl:if> -->
15540
15766
 
15541
15767
  </xsl:template>
15542
15768
 
@@ -15718,14 +15944,17 @@
15718
15944
  <!-- STEP MOVE PAGEBREAK: move <pagebreak/> at top level under 'preface' and 'sections' -->
15719
15945
  <!-- =========================================================================== -->
15720
15946
  <xsl:template match="@*|node()" mode="update_xml_step_move_pagebreak">
15947
+ <xsl:param name="page_sequence_at_top">false</xsl:param>
15721
15948
  <xsl:copy>
15722
- <xsl:apply-templates select="@*|node()" mode="update_xml_step_move_pagebreak"/>
15949
+ <xsl:apply-templates select="@*|node()" mode="update_xml_step_move_pagebreak">
15950
+ <xsl:with-param name="page_sequence_at_top" select="$page_sequence_at_top"/>
15951
+ </xsl:apply-templates>
15723
15952
  </xsl:copy>
15724
15953
  </xsl:template>
15725
15954
 
15726
15955
  <!-- replace 'pagebreak' by closing tags + page_sequence and opening page_sequence + tags -->
15727
15956
  <xsl:template match="*[local-name() = 'pagebreak'][not(following-sibling::*[1][local-name() = 'pagebreak'])]" mode="update_xml_step_move_pagebreak">
15728
-
15957
+ <xsl:param name="page_sequence_at_top"/>
15729
15958
  <!-- <xsl:choose>
15730
15959
  <xsl:when test="ancestor::*[local-name() = 'sections']">
15731
15960
 
@@ -15749,7 +15978,9 @@
15749
15978
  <xsl:variable name="orientation" select="normalize-space(@orientation)"/>
15750
15979
 
15751
15980
  <xsl:variable name="tree_">
15752
- <xsl:call-template name="makeAncestorsElementsTree"/>
15981
+ <xsl:call-template name="makeAncestorsElementsTree">
15982
+ <xsl:with-param name="page_sequence_at_top" select="$page_sequence_at_top"/>
15983
+ </xsl:call-template>
15753
15984
  </xsl:variable>
15754
15985
  <xsl:variable name="tree" select="xalan:nodeset($tree_)"/>
15755
15986
 
@@ -15771,12 +16002,26 @@
15771
16002
  </xsl:template>
15772
16003
 
15773
16004
  <xsl:template name="makeAncestorsElementsTree">
15774
- <xsl:for-each select="ancestor::*[ancestor::*[local-name() = 'preface'] or ancestor::*[local-name() = 'sections'] or ancestor-or-self::*[local-name() = 'annex']]">
15775
- <element pos="{position()}">
15776
- <xsl:copy-of select="@*[local-name() != 'id']"/>
15777
- <xsl:value-of select="name()"/>
15778
- </element>
15779
- </xsl:for-each>
16005
+ <xsl:param name="page_sequence_at_top"/>
16006
+
16007
+ <xsl:choose>
16008
+ <xsl:when test="$page_sequence_at_top = 'true'">
16009
+ <xsl:for-each select="ancestor::*[ancestor::*[contains(local-name(), '-standard')]]">
16010
+ <element pos="{position()}">
16011
+ <xsl:copy-of select="@*[local-name() != 'id']"/>
16012
+ <xsl:value-of select="name()"/>
16013
+ </element>
16014
+ </xsl:for-each>
16015
+ </xsl:when>
16016
+ <xsl:otherwise>
16017
+ <xsl:for-each select="ancestor::*[ancestor::*[local-name() = 'preface'] or ancestor::*[local-name() = 'sections'] or ancestor-or-self::*[local-name() = 'annex']]">
16018
+ <element pos="{position()}">
16019
+ <xsl:copy-of select="@*[local-name() != 'id']"/>
16020
+ <xsl:value-of select="name()"/>
16021
+ </element>
16022
+ </xsl:for-each>
16023
+ </xsl:otherwise>
16024
+ </xsl:choose>
15780
16025
  </xsl:template>
15781
16026
 
15782
16027
  <xsl:template name="insertClosingElements">
@@ -15814,11 +16059,14 @@
15814
16059
 
15815
16060
  <!-- move full page width figures, tables at top level -->
15816
16061
  <xsl:template match="*[local-name() = 'figure' or local-name() = 'table'][normalize-space(@width) != 'text-width']" mode="update_xml_step_move_pagebreak">
16062
+ <xsl:param name="page_sequence_at_top">false</xsl:param>
15817
16063
  <xsl:choose>
15818
16064
  <xsl:when test="$layout_columns != 1">
15819
16065
 
15820
16066
  <xsl:variable name="tree_">
15821
- <xsl:call-template name="makeAncestorsElementsTree"/>
16067
+ <xsl:call-template name="makeAncestorsElementsTree">
16068
+ <xsl:with-param name="page_sequence_at_top" select="$page_sequence_at_top"/>
16069
+ </xsl:call-template>
15822
16070
  </xsl:variable>
15823
16071
  <xsl:variable name="tree" select="xalan:nodeset($tree_)"/>
15824
16072
 
@@ -15966,89 +16214,159 @@
15966
16214
 
15967
16215
  <xsl:variable name="express_reference_separators">_.\</xsl:variable>
15968
16216
  <xsl:variable name="express_reference_characters" select="concat($upper,$lower,'1234567890',$express_reference_separators)"/>
16217
+ <xsl:variable name="regex_express_reference">(^([A-Za-z0-9_.\\]+)$)</xsl:variable>
15969
16218
 
15970
16219
  <xsl:variable name="element_name_keep-together_within-line">keep-together_within-line</xsl:variable>
16220
+ <xsl:variable name="tag_keep-together_within-line_open">###<xsl:value-of select="$element_name_keep-together_within-line"/>###</xsl:variable>
16221
+ <xsl:variable name="tag_keep-together_within-line_close">###/<xsl:value-of select="$element_name_keep-together_within-line"/>###</xsl:variable>
15971
16222
 
15972
- <xsl:template 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">
16223
+ <!-- \S matches any non-whitespace character (equivalent to [^\r\n\t\f\v ]) -->
16224
+ <!-- <xsl:variable name="regex_solidus_units">((\b((\S{1,3}\/\S+)|(\S+\/\S{1,3}))\b)|(\/\S{1,3})\b)</xsl:variable> -->
16225
+ <!-- add &lt; and &gt; to \S -->
16226
+ <xsl:variable name="regex_S">[^\r\n\t\f\v \&lt;&gt;\u3000-\u9FFF]</xsl:variable>
16227
+ <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>
15973
16228
 
15974
- <!-- enclose standard's number into tag 'keep-together_within-line' -->
15975
- <xsl:variable name="tag_keep-together_within-line_open">###<xsl:value-of select="$element_name_keep-together_within-line"/>###</xsl:variable>
15976
- <xsl:variable name="tag_keep-together_within-line_close">###/<xsl:value-of select="$element_name_keep-together_within-line"/>###</xsl:variable>
15977
- <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))"/>
15978
- <xsl:variable name="text_">
15979
- <xsl:choose>
15980
- <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 -->
15981
- <xsl:otherwise><xsl:value-of select="$text__"/></xsl:otherwise>
15982
- </xsl:choose>
15983
- </xsl:variable>
15984
- <xsl:variable name="text"><text><xsl:call-template name="replace_text_tags">
16229
+ <xsl:variable name="non_white_space">[^\s\u3000-\u9FFF]</xsl:variable>
16230
+ <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>
16231
+
16232
+ <xsl:template 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">
16233
+
16234
+ <xsl:variable name="parent" select="local-name(..)"/>
16235
+
16236
+ <xsl:if test="1 = 2"> <!-- alternative variant -->
16237
+
16238
+ <xsl:variable name="regexs">
16239
+ <!-- enclose standard's number into tag 'keep-together_within-line' -->
16240
+ <xsl:if test="not(ancestor::*[local-name() = 'table'])"><regex><xsl:value-of select="$regex_standard_reference"/></regex></xsl:if>
16241
+ <!-- if EXPRESS reference -->
16242
+
16243
+ <xsl:if test="$parent = 'strong'"><regex><xsl:value-of select="$regex_express_reference"/></regex></xsl:if>
16244
+
16245
+ <!-- keep-together_within-line for: a/b, aaa/b, a/bbb, /b -->
16246
+ <regex><xsl:value-of select="$regex_solidus_units"/></regex>
16247
+ <!-- keep-together_within-line for: a.b, aaa.b, a.bbb, .b in table's cell ONLY -->
16248
+ <xsl:if test="ancestor::*[local-name() = 'td' or local-name() = 'th']">
16249
+ <regex><xsl:value-of select="$regex_dots_units"/></regex>
16250
+ </xsl:if>
16251
+ </xsl:variable>
16252
+
16253
+ <xsl:variable name="regex_replacement"><xsl:text>(</xsl:text>
16254
+ <xsl:for-each select="xalan:nodeset($regexs)/regex">
16255
+ <xsl:value-of select="."/>
16256
+ <xsl:if test="position() != last()">|</xsl:if>
16257
+ </xsl:for-each>
16258
+ <xsl:text>)</xsl:text>
16259
+ </xsl:variable>
16260
+
16261
+ <!-- regex_replacement='<xsl:value-of select="$regex_replacement"/>' -->
16262
+
16263
+ <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))"/>
16264
+
16265
+ <!-- text_replaced='<xsl:value-of select="$text_replaced"/>' -->
16266
+
16267
+ <xsl:call-template name="replace_text_tags">
15985
16268
  <xsl:with-param name="tag_open" select="$tag_keep-together_within-line_open"/>
15986
16269
  <xsl:with-param name="tag_close" select="$tag_keep-together_within-line_close"/>
15987
- <xsl:with-param name="text" select="$text_"/>
15988
- </xsl:call-template></text></xsl:variable>
16270
+ <xsl:with-param name="text" select="$text_replaced"/>
16271
+ </xsl:call-template>
16272
+ </xsl:if>
15989
16273
 
15990
- <xsl:variable name="parent" select="local-name(..)"/>
16274
+ <xsl:if test="1 = 1">
16275
+
16276
+ <!-- enclose standard's number into tag 'keep-together_within-line' -->
16277
+ <xsl:variable name="text">
16278
+ <xsl:element name="text" namespace="{$namespace_full}">
16279
+ <xsl:choose>
16280
+ <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 -->
16281
+ <xsl:otherwise>
16282
+ <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))"/>
16283
+ <!-- <xsl:value-of select="$text__"/> -->
16284
+
16285
+ <xsl:call-template name="replace_text_tags">
16286
+ <xsl:with-param name="tag_open" select="$tag_keep-together_within-line_open"/>
16287
+ <xsl:with-param name="tag_close" select="$tag_keep-together_within-line_close"/>
16288
+ <xsl:with-param name="text" select="$text_"/>
16289
+ </xsl:call-template>
16290
+
16291
+ </xsl:otherwise>
16292
+ </xsl:choose>
16293
+ </xsl:element>
16294
+ </xsl:variable>
15991
16295
 
15992
16296
  <xsl:variable name="text2">
15993
- <text><xsl:for-each select="xalan:nodeset($text)/text/node()">
16297
+ <xsl:element name="text" namespace="{$namespace_full}">
16298
+ <xsl:for-each select="xalan:nodeset($text)/*[local-name() = 'text']/node()">
15994
16299
 
15995
16300
  <xsl:choose>
15996
16301
  <!-- if EXPRESS reference -->
15997
16302
  <xsl:when test="self::text() and $parent = 'strong' and translate(., $express_reference_characters, '') = ''">
15998
- <xsl:element name="{$element_name_keep-together_within-line}"><xsl:value-of select="."/></xsl:element>
16303
+ <xsl:variable name="text_express" select="java:replaceAll(java:java.lang.String.new(.),$regex_express_reference,concat($tag_keep-together_within-line_open,'$1',$tag_keep-together_within-line_close))"/>
16304
+
16305
+ <!-- <xsl:element name="{$element_name_keep-together_within-line}"><xsl:value-of select="."/></xsl:element> -->
16306
+
16307
+ <xsl:call-template name="replace_text_tags">
16308
+ <xsl:with-param name="tag_open" select="$tag_keep-together_within-line_open"/>
16309
+ <xsl:with-param name="tag_close" select="$tag_keep-together_within-line_close"/>
16310
+ <xsl:with-param name="text" select="$text_express"/>
16311
+ </xsl:call-template>
16312
+
15999
16313
  </xsl:when>
16000
16314
  <xsl:otherwise><xsl:copy-of select="."/></xsl:otherwise> <!-- copy 'as-is' for <fo:inline keep-together.within-line="always" ... -->
16001
16315
  </xsl:choose>
16002
16316
 
16003
- </xsl:for-each></text>
16317
+ </xsl:for-each>
16318
+ </xsl:element>
16004
16319
  </xsl:variable>
16005
16320
 
16006
16321
  <!-- keep-together_within-line for: a/b, aaa/b, a/bbb, /b -->
16007
- <!-- \S matches any non-whitespace character (equivalent to [^\r\n\t\f\v ]) -->
16008
- <!-- <xsl:variable name="regex_solidus_units">((\b((\S{1,3}\/\S+)|(\S+\/\S{1,3}))\b)|(\/\S{1,3})\b)</xsl:variable> -->
16009
- <!-- add &lt; and &gt; to \S -->
16010
- <xsl:variable name="regex_S">[^\r\n\t\f\v \&lt;&gt;\u3000-\u9FFF]</xsl:variable>
16011
- <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>
16012
16322
  <xsl:variable name="text3">
16013
- <text><xsl:for-each select="xalan:nodeset($text2)/text/node()">
16014
- <xsl:choose>
16015
- <xsl:when test="self::text()">
16016
- <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))"/>
16017
- <xsl:variable name="text_units"><text><xsl:call-template name="replace_text_tags">
16018
- <xsl:with-param name="tag_open" select="$tag_keep-together_within-line_open"/>
16019
- <xsl:with-param name="tag_close" select="$tag_keep-together_within-line_close"/>
16020
- <xsl:with-param name="text" select="$text_units_"/>
16021
- </xsl:call-template></text></xsl:variable>
16022
- <xsl:copy-of select="xalan:nodeset($text_units)/text/node()"/>
16023
- </xsl:when>
16024
- <xsl:otherwise><xsl:copy-of select="."/></xsl:otherwise> <!-- copy 'as-is' for <fo:inline keep-together.within-line="always" ... -->
16025
- </xsl:choose>
16026
- </xsl:for-each></text>
16323
+ <xsl:element name="text" namespace="{$namespace_full}">
16324
+ <xsl:for-each select="xalan:nodeset($text2)/*[local-name() = 'text']/node()">
16325
+ <xsl:choose>
16326
+ <xsl:when test="self::text()">
16327
+ <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))"/>
16328
+ <!-- <xsl:variable name="text_units">
16329
+ <xsl:element name="text" namespace="{$namespace_full}"> -->
16330
+ <xsl:call-template name="replace_text_tags">
16331
+ <xsl:with-param name="tag_open" select="$tag_keep-together_within-line_open"/>
16332
+ <xsl:with-param name="tag_close" select="$tag_keep-together_within-line_close"/>
16333
+ <xsl:with-param name="text" select="$text_units"/>
16334
+ </xsl:call-template>
16335
+ <!-- </xsl:element>
16336
+ </xsl:variable>
16337
+ <xsl:copy-of select="xalan:nodeset($text_units)/*[local-name() = 'text']/node()"/> -->
16338
+ </xsl:when>
16339
+ <xsl:otherwise><xsl:copy-of select="."/></xsl:otherwise> <!-- copy 'as-is' for <fo:inline keep-together.within-line="always" ... -->
16340
+ </xsl:choose>
16341
+ </xsl:for-each>
16342
+ </xsl:element>
16027
16343
  </xsl:variable>
16028
16344
 
16029
16345
  <xsl:choose>
16030
16346
  <xsl:when test="ancestor::*[local-name() = 'td' or local-name() = 'th']">
16031
16347
  <!-- keep-together_within-line for: a.b, aaa.b, a.bbb, .b in table's cell ONLY -->
16032
- <xsl:variable name="non_white_space">[^\s\u3000-\u9FFF]</xsl:variable>
16033
- <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>
16034
- <xsl:for-each select="xalan:nodeset($text3)/text/node()">
16348
+ <xsl:for-each select="xalan:nodeset($text3)/*[local-name() = 'text']/node()">
16035
16349
  <xsl:choose>
16036
16350
  <xsl:when test="self::text()">
16037
- <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))"/>
16038
- <xsl:variable name="text_dots"><text><xsl:call-template name="replace_text_tags">
16039
- <xsl:with-param name="tag_open" select="$tag_keep-together_within-line_open"/>
16040
- <xsl:with-param name="tag_close" select="$tag_keep-together_within-line_close"/>
16041
- <xsl:with-param name="text" select="$text_dots_"/>
16042
- </xsl:call-template></text></xsl:variable>
16043
- <xsl:copy-of select="xalan:nodeset($text_dots)/text/node()"/>
16351
+ <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))"/>
16352
+ <!-- <xsl:variable name="text_dots">
16353
+ <xsl:element name="text" namespace="{$namespace_full}"> -->
16354
+ <xsl:call-template name="replace_text_tags">
16355
+ <xsl:with-param name="tag_open" select="$tag_keep-together_within-line_open"/>
16356
+ <xsl:with-param name="tag_close" select="$tag_keep-together_within-line_close"/>
16357
+ <xsl:with-param name="text" select="$text_dots"/>
16358
+ </xsl:call-template>
16359
+ <!-- </xsl:element>
16360
+ </xsl:variable>
16361
+ <xsl:copy-of select="xalan:nodeset($text_dots)/*[local-name() = 'text']/node()"/> -->
16044
16362
  </xsl:when>
16045
16363
  <xsl:otherwise><xsl:copy-of select="."/></xsl:otherwise> <!-- copy 'as-is' for <fo:inline keep-together.within-line="always" ... -->
16046
16364
  </xsl:choose>
16047
16365
  </xsl:for-each>
16048
16366
  </xsl:when>
16049
- <xsl:otherwise><xsl:copy-of select="xalan:nodeset($text3)/text/node()"/></xsl:otherwise>
16367
+ <xsl:otherwise><xsl:copy-of select="xalan:nodeset($text3)/*[local-name() = 'text']/node()"/></xsl:otherwise>
16050
16368
  </xsl:choose>
16051
-
16369
+ </xsl:if>
16052
16370
  </xsl:template>
16053
16371
 
16054
16372
  <xsl:template match="*[local-name() = 'stem'] | *[local-name() = 'image']" mode="update_xml_enclose_keep-together_within-line">
@@ -16575,6 +16893,15 @@
16575
16893
  </xsl:otherwise>
16576
16894
  </xsl:choose>
16577
16895
  </xsl:for-each>
16896
+ <!-- references to external attachments (no binary-encoded within the Metanorma XML file) -->
16897
+ <xsl:if test="not(//*[contains(local-name(), '-standard')]/*[local-name() = 'metanorma-extension']/*[local-name() = 'attachment'])">
16898
+ <xsl:for-each select="//*[local-name() = 'bibitem'][@hidden = 'true'][*[local-name() = 'uri'][@type = 'attachment']]">
16899
+ <xsl:variable name="attachment_path" select="*[local-name() = 'uri'][@type = 'attachment']"/>
16900
+ <xsl:variable name="url" select="concat('url(file:///',$inputxml_basepath, $attachment_path, ')')"/>
16901
+ <xsl:variable name="filename_embedded" select="substring-after($attachment_path, concat('_', $inputxml_filename_prefix, '_attachments', '/'))"/>
16902
+ <pdf:embedded-file src="{$url}" filename="{$filename_embedded}"/>
16903
+ </xsl:for-each>
16904
+ </xsl:if>
16578
16905
  </xsl:template> <!-- addPDFUAmeta -->
16579
16906
 
16580
16907
  <xsl:template name="getId">