metanorma-iso 2.7.8 → 2.7.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -2103,7 +2103,7 @@
2103
2103
  <xsl:apply-templates select="xalan:nodeset($updated_xml_step2)" mode="update_xml_enclose_keep-together_within-line"/>
2104
2104
  </xsl:when>
2105
2105
  <xsl:otherwise>
2106
- <xsl:copy-of select="."/>
2106
+ <xsl:apply-templates select="." mode="update_xml_enclose_keep-together_within-line"/>
2107
2107
  </xsl:otherwise>
2108
2108
  </xsl:choose>
2109
2109
  </xsl:variable>
@@ -4826,6 +4826,9 @@
4826
4826
 
4827
4827
  <xsl:strip-space elements="iso:xref"/>
4828
4828
 
4829
+ <xsl:variable name="namespace_full" select="namespace-uri(/*)"/> <!-- example: https://www.metanorma.org/ns/iso -->
4830
+ <xsl:variable name="root_element" select="local-name(/*)"/>
4831
+
4829
4832
  <!-- external parameters -->
4830
4833
 
4831
4834
  <xsl:param name="svg_images"/> <!-- svg images array -->
@@ -4833,6 +4836,7 @@
4833
4836
  <xsl:param name="basepath"/> <!-- base path for images -->
4834
4837
  <xsl:param name="inputxml_basepath"/> <!-- input xml file path -->
4835
4838
  <xsl:param name="inputxml_filename"/> <!-- input xml file name -->
4839
+ <xsl:param name="output_path"/> <!-- output PDF file name -->
4836
4840
  <xsl:param name="external_index"/><!-- path to index xml, generated on 1st pass, based on FOP Intermediate Format -->
4837
4841
  <xsl:param name="syntax-highlight">false</xsl:param> <!-- syntax highlighting feature, default - off -->
4838
4842
  <xsl:param name="add_math_as_text">true</xsl:param> <!-- add math in text behind svg formula, to copy-paste formula from PDF as text -->
@@ -5008,6 +5012,15 @@
5008
5012
  </xsl:variable>
5009
5013
  <xsl:variable name="marginBottom" select="normalize-space($marginBottom_)"/>
5010
5014
 
5015
+ <xsl:variable name="layout_columns_default">1</xsl:variable>
5016
+ <xsl:variable name="layout_columns_" select="normalize-space((//*[contains(local-name(), '-standard')])[1]/*[local-name() = 'metanorma-extension']/*[local-name() = 'presentation-metadata']/*[local-name() = 'layout-columns'])"/>
5017
+ <xsl:variable name="layout_columns">
5018
+ <xsl:choose>
5019
+ <xsl:when test="$layout_columns_ != ''"><xsl:value-of select="$layout_columns_"/></xsl:when>
5020
+ <xsl:otherwise><xsl:value-of select="$layout_columns_default"/></xsl:otherwise>
5021
+ </xsl:choose>
5022
+ </xsl:variable>
5023
+
5011
5024
  <!-- Note 2: almost all localized string determined in the element //localized-strings in metanorma xml, but there are a few cases when:
5012
5025
  - string didn't determined yet
5013
5026
  - we need to put the string on two-languages (for instance, on English and French both), but xml contains only localized strings for one language
@@ -5501,11 +5514,13 @@
5501
5514
 
5502
5515
  1pt solid black
5503
5516
 
5517
+
5504
5518
  </xsl:variable>
5505
5519
  <xsl:variable name="table-border" select="normalize-space($table-border_)"/>
5506
5520
 
5507
5521
  <xsl:variable name="table-cell-border_">
5508
5522
  0.5pt solid black
5523
+
5509
5524
  </xsl:variable>
5510
5525
  <xsl:variable name="table-cell-border" select="normalize-space($table-cell-border_)"/>
5511
5526
 
@@ -6725,6 +6740,43 @@
6725
6740
  </xsl:for-each>
6726
6741
  </xsl:template>
6727
6742
 
6743
+ <xsl:template name="processPrefaceSectionsDefault_items">
6744
+
6745
+ <xsl:variable name="updated_xml_step_move_pagebreak_">
6746
+
6747
+ <xsl:element name="{$root_element}" namespace="{$namespace_full}">
6748
+
6749
+ <xsl:call-template name="copyCommonElements"/>
6750
+
6751
+ <xsl:element name="preface" namespace="{$namespace_full}"> <!-- save context element -->
6752
+ <xsl:element name="page_sequence" namespace="{$namespace_full}">
6753
+ <xsl:for-each select="/*/*[local-name()='preface']/*[not(local-name() = 'note' or local-name() = 'admonition')]">
6754
+ <xsl:sort select="@displayorder" data-type="number"/>
6755
+ <xsl:apply-templates select="." mode="update_xml_step_move_pagebreak"/>
6756
+ </xsl:for-each>
6757
+ </xsl:element>
6758
+ </xsl:element>
6759
+ </xsl:element>
6760
+ </xsl:variable>
6761
+
6762
+ <xsl:variable name="updated_xml_step_move_pagebreak_filename" select="concat($output_path,'_preface_', java:getTime(java:java.util.Date.new()), '.xml')"/>
6763
+
6764
+ <redirect:write file="{$updated_xml_step_move_pagebreak_filename}">
6765
+ <xsl:copy-of select="$updated_xml_step_move_pagebreak_"/>
6766
+ </redirect:write>
6767
+
6768
+ <xsl:copy-of select="document($updated_xml_step_move_pagebreak_filename)"/>
6769
+
6770
+ <xsl:call-template name="deleteFile">
6771
+ <xsl:with-param name="filepath" select="$updated_xml_step_move_pagebreak_filename"/>
6772
+ </xsl:call-template>
6773
+ </xsl:template>
6774
+
6775
+ <xsl:template name="copyCommonElements">
6776
+ <!-- copy bibdata, localized-strings, metanorma-extension and boilerplate -->
6777
+ <xsl:copy-of select="/*/*[local-name() != 'preface' and local-name() != 'sections' and local-name() != 'annex' and local-name() != 'bibliography']"/>
6778
+ </xsl:template>
6779
+
6728
6780
  <xsl:template name="processMainSectionsDefault">
6729
6781
  <xsl:for-each select="/*/*[local-name()='sections']/* | /*/*[local-name()='bibliography']/*[local-name()='references'][@normative='true']">
6730
6782
  <xsl:sort select="@displayorder" data-type="number"/>
@@ -6741,7 +6793,7 @@
6741
6793
  <xsl:sort select="@displayorder" data-type="number"/>
6742
6794
  <xsl:apply-templates select="."/>
6743
6795
  </xsl:for-each>
6744
- </xsl:template>
6796
+ </xsl:template><!-- END: processMainSectionsDefault -->
6745
6797
 
6746
6798
  <xsl:template name="processMainSectionsDefault_flatxml">
6747
6799
  <xsl:for-each select="/*/*[local-name()='sections']/* | /*/*[local-name()='bibliography']/*[local-name()='references'][@normative='true']">
@@ -6773,6 +6825,80 @@
6773
6825
  </xsl:for-each>
6774
6826
  </xsl:template>
6775
6827
 
6828
+ <!-- Example:
6829
+ <iso-standard>
6830
+ <sections>
6831
+ <page_sequence>
6832
+ <clause...
6833
+ </page_sequence>
6834
+ <page_sequence>
6835
+ <clause...
6836
+ </page_sequence>
6837
+ </sections>
6838
+ <page_sequence>
6839
+ <annex ..
6840
+ </page_sequence>
6841
+ <page_sequence>
6842
+ <annex ..
6843
+ </page_sequence>
6844
+ </iso-standard>
6845
+ -->
6846
+ <xsl:template name="processMainSectionsDefault_items">
6847
+
6848
+ <xsl:variable name="updated_xml_step_move_pagebreak_">
6849
+
6850
+ <xsl:element name="{$root_element}" namespace="{$namespace_full}">
6851
+
6852
+ <xsl:call-template name="copyCommonElements"/>
6853
+
6854
+ <xsl:element name="sections" namespace="{$namespace_full}"> <!-- save context element -->
6855
+ <xsl:element name="page_sequence" namespace="{$namespace_full}">
6856
+ <xsl:for-each select="/*/*[local-name()='sections']/* | /*/*[local-name()='bibliography']/*[local-name()='references'][@normative='true']">
6857
+ <xsl:sort select="@displayorder" data-type="number"/>
6858
+ <xsl:apply-templates select="." mode="update_xml_step_move_pagebreak"/>
6859
+
6860
+ </xsl:for-each>
6861
+ </xsl:element>
6862
+ </xsl:element>
6863
+
6864
+ <xsl:element name="page_sequence" namespace="{$namespace_full}">
6865
+ <xsl:for-each select="/*/*[local-name()='annex']">
6866
+ <xsl:sort select="@displayorder" data-type="number"/>
6867
+ <xsl:apply-templates select="." mode="update_xml_step_move_pagebreak"/>
6868
+ </xsl:for-each>
6869
+ </xsl:element>
6870
+
6871
+ <xsl:element name="page_sequence" namespace="{$namespace_full}">
6872
+ <xsl:element name="bibliography" namespace="{$namespace_full}"> <!-- save context element -->
6873
+ <xsl:for-each select="/*/*[local-name()='bibliography']/*[not(@normative='true')] | /*/*[local-name()='bibliography']/*[local-name()='clause'][*[local-name()='references'][not(@normative='true')]]">
6874
+ <xsl:sort select="@displayorder" data-type="number"/>
6875
+ <xsl:apply-templates select="." mode="update_xml_step_move_pagebreak"/>
6876
+ </xsl:for-each>
6877
+ </xsl:element>
6878
+ </xsl:element>
6879
+ </xsl:element>
6880
+ </xsl:variable>
6881
+
6882
+ <xsl:variable name="updated_xml_step_move_pagebreak_filename" select="concat($output_path,'_main_', java:getTime(java:java.util.Date.new()), '.xml')"/>
6883
+
6884
+ <redirect:write file="{$updated_xml_step_move_pagebreak_filename}">
6885
+ <xsl:copy-of select="$updated_xml_step_move_pagebreak_"/>
6886
+ </redirect:write>
6887
+
6888
+ <xsl:copy-of select="document($updated_xml_step_move_pagebreak_filename)"/>
6889
+
6890
+ <xsl:call-template name="deleteFile">
6891
+ <xsl:with-param name="filepath" select="$updated_xml_step_move_pagebreak_filename"/>
6892
+ </xsl:call-template>
6893
+ </xsl:template> <!-- END: processMainSectionsDefault_items -->
6894
+
6895
+ <xsl:template name="deleteFile">
6896
+ <xsl:param name="filepath"/>
6897
+ <xsl:variable name="xml_file" select="java:java.io.File.new($filepath)"/>
6898
+ <xsl:variable name="xml_file_path" select="java:toPath($xml_file)"/>
6899
+ <xsl:variable name="deletefile" select="java:java.nio.file.Files.deleteIfExists($xml_file_path)"/>
6900
+ </xsl:template>
6901
+
6776
6902
  <xsl:variable name="regex_standard_reference">([A-Z]{2,}(/[A-Z]{2,})* \d+(-\d+)*(:\d{4})?)</xsl:variable>
6777
6903
  <xsl:variable name="tag_fo_inline_keep-together_within-line_open">###fo:inline keep-together_within-line###</xsl:variable>
6778
6904
  <xsl:variable name="tag_fo_inline_keep-together_within-line_close">###/fo:inline keep-together_within-line###</xsl:variable>
@@ -6972,7 +7098,9 @@
6972
7098
  </xsl:for-each>
6973
7099
  </xsl:template>
6974
7100
 
6975
- <xsl:param name="table_only_with_id"/><!-- Example: table1, for table auto-layout algorithm -->
7101
+ <!-- for table auto-layout algorithm -->
7102
+ <xsl:param name="table_only_with_id"/> <!-- Example: 'table1' -->
7103
+ <xsl:param name="table_only_with_ids"/> <!-- Example: 'table1 table2 table3 ' -->
6976
7104
 
6977
7105
  <xsl:template match="*[local-name()='table']" priority="2">
6978
7106
  <xsl:choose>
@@ -6980,6 +7108,10 @@
6980
7108
  <xsl:call-template name="table"/>
6981
7109
  </xsl:when>
6982
7110
  <xsl:when test="$table_only_with_id != ''"><fo:block/><!-- to prevent empty fo:block-container --></xsl:when>
7111
+ <xsl:when test="$table_only_with_ids != '' and contains($table_only_with_ids, concat(@id, ' '))">
7112
+ <xsl:call-template name="table"/>
7113
+ </xsl:when>
7114
+ <xsl:when test="$table_only_with_ids != ''"><fo:block/><!-- to prevent empty fo:block-container --></xsl:when>
6983
7115
  <xsl:otherwise>
6984
7116
  <xsl:call-template name="table"/>
6985
7117
  </xsl:otherwise>
@@ -7039,6 +7171,7 @@
7039
7171
  <xsl:variable name="margin-side">
7040
7172
  <xsl:choose>
7041
7173
  <xsl:when test="$isApplyAutolayoutAlgorithm = 'true'">0</xsl:when>
7174
+ <xsl:when test="$isApplyAutolayoutAlgorithm = 'skip'">0</xsl:when>
7042
7175
  <xsl:when test="sum(xalan:nodeset($colwidths)//column) &gt; 75">15</xsl:when>
7043
7176
  <xsl:otherwise>0</xsl:otherwise>
7044
7177
  </xsl:choose>
@@ -7310,6 +7443,7 @@
7310
7443
  <xsl:when test="$isApplyAutolayoutAlgorithm = 'true'">
7311
7444
  <xsl:call-template name="get-calculated-column-widths-autolayout-algorithm"/>
7312
7445
  </xsl:when>
7446
+ <xsl:when test="$isApplyAutolayoutAlgorithm = 'skip'"/>
7313
7447
  <xsl:otherwise>
7314
7448
  <xsl:call-template name="calculate-column-widths-proportional">
7315
7449
  <xsl:with-param name="cols-count" select="$cols-count"/>
@@ -8270,7 +8404,7 @@
8270
8404
  <xsl:copy-of select="node()"/>
8271
8405
  </fn>
8272
8406
  </xsl:for-each>
8273
- <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']/*">
8407
+ <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']/*">
8274
8408
  <xsl:sort select="@displayorder" data-type="number"/>
8275
8409
  <!-- commented:
8276
8410
  .//*[local-name() = 'bibitem'][ancestor::*[local-name() = 'references']]/*[local-name() = 'note'] |
@@ -8518,6 +8652,10 @@
8518
8652
  <xsl:call-template name="dl"/>
8519
8653
  </xsl:when>
8520
8654
  <xsl:when test="$table_only_with_id != ''"><fo:block/><!-- to prevent empty fo:block-container --></xsl:when>
8655
+ <xsl:when test="$table_only_with_ids != '' and contains($table_only_with_ids, concat(@id, ' '))">
8656
+ <xsl:call-template name="dl"/>
8657
+ </xsl:when>
8658
+ <xsl:when test="$table_only_with_ids != ''"><fo:block/><!-- to prevent empty fo:block-container --></xsl:when>
8521
8659
  <xsl:otherwise>
8522
8660
  <xsl:call-template name="dl"/>
8523
8661
  </xsl:otherwise>
@@ -8687,7 +8825,7 @@
8687
8825
 
8688
8826
  <!-- create virtual html table for dl/[dt and dd] -->
8689
8827
  <xsl:variable name="simple-table">
8690
-
8828
+ <!-- initial='<xsl:copy-of select="."/>' -->
8691
8829
  <xsl:variable name="dl_table">
8692
8830
  <tbody>
8693
8831
  <xsl:apply-templates mode="dl_if">
@@ -11519,17 +11657,19 @@
11519
11657
  </xsl:variable>
11520
11658
  <xsl:value-of select="concat('scale=', $scale,', indent=', $indent)"/>
11521
11659
  </fo:block> -->
11522
- <fo:external-graphic src="{$src}" fox:alt-text="Image {@alt}" xsl:use-attribute-sets="image-graphic-style">
11523
- <xsl:if test="not(@mimetype = 'image/svg+xml') and (../*[local-name() = 'name'] or parent::*[local-name() = 'figure'][@unnumbered = 'true']) and not(ancestor::*[local-name() = 'table'])">
11524
11660
 
11525
- <xsl:call-template name="setImageWidthHeight"/>
11661
+ <fo:external-graphic src="{$src}" fox:alt-text="Image {@alt}">
11526
11662
 
11527
- <xsl:choose>
11528
- <xsl:when test="@width != '' and @width != 'auto' and @height != '' and @height != 'auto'">
11529
- <xsl:attribute name="scaling">non-uniform</xsl:attribute>
11530
- </xsl:when>
11531
- <xsl:otherwise>
11663
+ <xsl:choose>
11664
+ <!-- default -->
11665
+ <xsl:when test="((@width = 'auto' or @width = 'text-width' or @width = 'full-page-width' or @width = 'narrow') and @height = 'auto') or (normalize-space(@width) = '' and normalize-space(@height) = '') ">
11666
+ <!-- add attribute for automatic scaling -->
11667
+ <xsl:variable name="image-graphic-style_attributes">
11668
+ <attributes xsl:use-attribute-sets="image-graphic-style"/>
11669
+ </xsl:variable>
11670
+ <xsl:copy-of select="xalan:nodeset($image-graphic-style_attributes)/attributes/@*"/>
11532
11671
 
11672
+ <xsl:if test="not(@mimetype = 'image/svg+xml') and not(ancestor::*[local-name() = 'table'])">
11533
11673
  <xsl:variable name="scale">
11534
11674
  <xsl:call-template name="getImageScale">
11535
11675
  <xsl:with-param name="indent" select="$indent"/>
@@ -11543,10 +11683,30 @@
11543
11683
  <xsl:if test="number($scale) &lt; 100">
11544
11684
  <xsl:attribute name="content-width"><xsl:value-of select="number($scale) * number($scaleRatio)"/>%</xsl:attribute>
11545
11685
  </xsl:if>
11546
- </xsl:otherwise>
11547
- </xsl:choose>
11686
+ </xsl:if>
11548
11687
 
11549
- </xsl:if>
11688
+ </xsl:when> <!-- default -->
11689
+ <xsl:otherwise>
11690
+
11691
+ <xsl:variable name="width_height_">
11692
+ <attributes>
11693
+ <xsl:call-template name="setImageWidthHeight"/>
11694
+ </attributes>
11695
+ </xsl:variable>
11696
+ <xsl:variable name="width_height" select="xalan:nodeset($width_height_)"/>
11697
+
11698
+ <xsl:copy-of select="$width_height/attributes/@*"/>
11699
+
11700
+ <xsl:if test="$width_height/attributes/@content-width != '' and $width_height/attributes/@content-height != ''">
11701
+ <xsl:attribute name="scaling">non-uniform</xsl:attribute>
11702
+ </xsl:if>
11703
+
11704
+ </xsl:otherwise>
11705
+ </xsl:choose>
11706
+
11707
+ <!--
11708
+ <xsl:if test="not(@mimetype = 'image/svg+xml') and (../*[local-name() = 'name'] or parent::*[local-name() = 'figure'][@unnumbered = 'true']) and not(ancestor::*[local-name() = 'table'])">
11709
+ -->
11550
11710
 
11551
11711
  </fo:external-graphic>
11552
11712
  </xsl:otherwise>
@@ -11572,7 +11732,7 @@
11572
11732
  <xsl:call-template name="setImageWidth"/>
11573
11733
  </xsl:variable>
11574
11734
  <xsl:if test="$width != ''">
11575
- <xsl:attribute name="width">
11735
+ <xsl:attribute name="content-width">
11576
11736
  <xsl:value-of select="$width"/>
11577
11737
  </xsl:attribute>
11578
11738
  </xsl:if>
@@ -11580,7 +11740,7 @@
11580
11740
  <xsl:call-template name="setImageHeight"/>
11581
11741
  </xsl:variable>
11582
11742
  <xsl:if test="$height != ''">
11583
- <xsl:attribute name="height">
11743
+ <xsl:attribute name="content-height">
11584
11744
  <xsl:value-of select="$height"/>
11585
11745
  </xsl:attribute>
11586
11746
  </xsl:if>
@@ -14015,7 +14175,7 @@
14015
14175
  <!-- ========== -->
14016
14176
 
14017
14177
  <!-- main sections -->
14018
- <xsl:template match="/*/*[local-name() = 'sections']/*" priority="2">
14178
+ <xsl:template match="/*/*[local-name() = 'sections']/*" name="sections_node" priority="2">
14019
14179
 
14020
14180
  <fo:block>
14021
14181
  <xsl:call-template name="setId"/>
@@ -14027,6 +14187,11 @@
14027
14187
 
14028
14188
  </xsl:template>
14029
14189
 
14190
+ <!-- note: @top-level added in mode=" update_xml_step_move_pagebreak" -->
14191
+ <xsl:template match="*[local-name() = 'sections']/*[local-name() = 'page_sequence']/*[not(@top-level)]" priority="2">
14192
+ <xsl:call-template name="sections_node"/>
14193
+ </xsl:template>
14194
+
14030
14195
  <xsl:template name="sections_element_style">
14031
14196
 
14032
14197
  <xsl:variable name="pos"><xsl:number count="*"/></xsl:variable>
@@ -14036,7 +14201,7 @@
14036
14201
 
14037
14202
  </xsl:template> <!-- sections_element_style -->
14038
14203
 
14039
- <xsl:template match="//*[contains(local-name(), '-standard')]/*[local-name() = 'preface']/*" priority="2"> <!-- /*/*[local-name() = 'preface']/* -->
14204
+ <xsl:template match="//*[contains(local-name(), '-standard')]/*[local-name() = 'preface']/*" priority="2" name="preface_node"> <!-- /*/*[local-name() = 'preface']/* -->
14040
14205
 
14041
14206
  <xsl:choose>
14042
14207
  <xsl:when test="$layoutVersion = '1951' and (local-name() = 'clause' or local-name() = 'introduction')"/>
@@ -14052,7 +14217,11 @@
14052
14217
  </fo:block>
14053
14218
  </xsl:template>
14054
14219
 
14055
- <xsl:template match="*[local-name() = 'clause']">
14220
+ <xsl:template match="*[local-name() = 'preface']/*[local-name() = 'page_sequence']/*" priority="2"> <!-- /*/*[local-name() = 'preface']/* -->
14221
+ <xsl:call-template name="preface_node"/>
14222
+ </xsl:template>
14223
+
14224
+ <xsl:template match="*[local-name() = 'clause'][normalize-space() != '' or *[local-name() = 'figure'] or @id]" name="template_clause"> <!-- if clause isn't empty -->
14056
14225
  <fo:block>
14057
14226
  <xsl:if test="parent::*[local-name() = 'copyright-statement']">
14058
14227
  <xsl:attribute name="role">SKIP</xsl:attribute>
@@ -14078,18 +14247,31 @@
14078
14247
  </fo:block>
14079
14248
  </xsl:template>
14080
14249
 
14081
- <xsl:template match="*[local-name() = 'annex']">
14082
- <fo:block break-after="page"/>
14083
- <fo:block>
14250
+ <xsl:template match="*[local-name() = 'annex'][normalize-space() != '']">
14251
+ <xsl:choose>
14252
+ <xsl:when test="@continue = 'true'"> <!-- it's using for figure/table on top level for block span -->
14253
+ <fo:block>
14254
+ <xsl:apply-templates/>
14255
+ </fo:block>
14256
+ </xsl:when>
14257
+ <xsl:otherwise>
14084
14258
 
14085
- <xsl:call-template name="setBlockSpanAll"/>
14259
+ <fo:block break-after="page"/>
14260
+ <fo:block id="{@id}">
14086
14261
 
14087
- <xsl:call-template name="refine_annex_style"/>
14262
+ <xsl:call-template name="setBlockSpanAll"/>
14088
14263
 
14089
- </fo:block>
14090
- <fo:block id="{@id}">
14091
- <xsl:apply-templates/>
14092
- </fo:block>
14264
+ <xsl:call-template name="refine_annex_style"/>
14265
+
14266
+ </fo:block>
14267
+
14268
+ <xsl:apply-templates select="*[local-name() = 'title'][@columns = 1]"/>
14269
+
14270
+ <fo:block>
14271
+ <xsl:apply-templates select="node()[not(local-name() = 'title' and @columns = 1)]"/>
14272
+ </fo:block>
14273
+ </xsl:otherwise>
14274
+ </xsl:choose>
14093
14275
  </xsl:template>
14094
14276
 
14095
14277
  <xsl:template name="refine_annex_style">
@@ -14789,8 +14971,12 @@
14789
14971
  </xsl:if>
14790
14972
  </xsl:if> -->
14791
14973
 
14792
- <fo:block id="{@id}" xsl:use-attribute-sets="references-non-normative-style">
14793
- <xsl:apply-templates/>
14974
+ <fo:block id="{@id}"/>
14975
+
14976
+ <xsl:apply-templates select="*[local-name() = 'title'][@columns = 1]"/>
14977
+
14978
+ <fo:block xsl:use-attribute-sets="references-non-normative-style">
14979
+ <xsl:apply-templates select="node()[not(local-name() = 'title' and @columns = 1)]"/>
14794
14980
 
14795
14981
  </fo:block>
14796
14982
 
@@ -15287,7 +15473,11 @@
15287
15473
  <!-- =========================================================================== -->
15288
15474
  <!-- STEP1: -->
15289
15475
  <!-- - Re-order elements in 'preface', 'sections' based on @displayorder -->
15476
+ <!-- - Put Section title in the correct position -->
15290
15477
  <!-- - Ignore 'span' without style -->
15478
+ <!-- - Remove semantic xml part -->
15479
+ <!-- - Remove image/emf (EMF vector image for Word) -->
15480
+ <!-- - add @id, redundant for table auto-layout algorithm -->
15291
15481
  <!-- =========================================================================== -->
15292
15482
  <xsl:template match="@*|node()" mode="update_xml_step1">
15293
15483
  <xsl:copy>
@@ -15394,11 +15584,14 @@
15394
15584
  <!-- remove image/emf -->
15395
15585
  <xsl:template match="*[local-name() = 'image']/*[local-name() = 'emf']" mode="update_xml_step1"/>
15396
15586
 
15397
- <xsl:template match="*[local-name() = 'stem'] | *[local-name() = 'image']" mode="update_xml_step1">
15587
+ <!-- remove preprocess-xslt -->
15588
+ <xsl:template match="*[local-name() = 'preprocess-xslt']" mode="update_xml_step1"/>
15589
+
15590
+ <xsl:template match="*[local-name() = 'stem'] | *[local-name() = 'image'] | *[local-name() = 'sourcecode'] | *[local-name() = 'bibdata'] | *[local-name() = 'localized-strings']" mode="update_xml_step1">
15398
15591
  <xsl:copy-of select="."/>
15399
15592
  </xsl:template>
15400
15593
 
15401
- <!-- add @id, redundant for table auto-layout algorithm -->
15594
+ <!-- add @id, mandatory for table auto-layout algorithm -->
15402
15595
  <xsl:template match="*[local-name() = 'dl' or local-name() = 'table'][not(@id)]" mode="update_xml_step1">
15403
15596
  <xsl:copy>
15404
15597
  <xsl:copy-of select="@*"/>
@@ -15417,8 +15610,172 @@
15417
15610
  </xsl:if>
15418
15611
  </xsl:template>
15419
15612
 
15613
+ <!-- optimization: remove clause if table_only_with_id isn't empty and clause doesn't contain table or dl with table_only_with_id -->
15614
+ <xsl:template match="*[local-name() = 'clause' or local-name() = 'p' or local-name() = 'definitions' or local-name() = 'annex']" mode="update_xml_step1">
15615
+ <xsl:choose>
15616
+ <xsl:when test="($table_only_with_id != '' or $table_only_with_ids != '') and local-name() = 'p' and (ancestor::*[local-name() = 'table' or local-name() = 'dl' or local-name() = 'toc'])">
15617
+ <xsl:copy>
15618
+ <xsl:copy-of select="@*"/>
15619
+ <xsl:apply-templates mode="update_xml_step1"/>
15620
+ </xsl:copy>
15621
+ </xsl:when>
15622
+ <!-- for table auto-layout algorithm -->
15623
+ <xsl:when test="$table_only_with_id != '' and not(.//*[local-name() = 'table' or local-name() = 'dl'][@id = $table_only_with_id])">
15624
+ <xsl:copy>
15625
+ <xsl:copy-of select="@*"/>
15626
+ </xsl:copy>
15627
+ </xsl:when>
15628
+ <!-- for table auto-layout algorithm -->
15629
+ <xsl:when test="$table_only_with_ids != '' and not(.//*[local-name() = 'table' or local-name() = 'dl'][contains($table_only_with_ids, concat(@id, ' '))])">
15630
+ <xsl:copy>
15631
+ <xsl:copy-of select="@*"/>
15632
+ </xsl:copy>
15633
+ </xsl:when>
15634
+ <xsl:otherwise>
15635
+ <xsl:copy>
15636
+ <xsl:copy-of select="@*"/>
15637
+ <xsl:apply-templates mode="update_xml_step1"/>
15638
+ </xsl:copy>
15639
+ </xsl:otherwise>
15640
+ </xsl:choose>
15641
+ </xsl:template>
15642
+
15420
15643
  <!-- =========================================================================== -->
15421
15644
  <!-- END STEP1: Re-order elements in 'preface', 'sections' based on @displayorder -->
15645
+ <!-- =========================================================================== -->
15646
+
15647
+ <!-- =========================================================================== -->
15648
+ <!-- STEP MOVE PAGEBREAK: move <pagebreak/> at top level under 'preface' and 'sections' -->
15649
+ <!-- =========================================================================== -->
15650
+ <xsl:template match="@*|node()" mode="update_xml_step_move_pagebreak">
15651
+ <xsl:copy>
15652
+ <xsl:apply-templates select="@*|node()" mode="update_xml_step_move_pagebreak"/>
15653
+ </xsl:copy>
15654
+ </xsl:template>
15655
+
15656
+ <!-- replace 'pagebreak' by closing tags + page_sequence and opening page_sequence + tags -->
15657
+ <xsl:template match="*[local-name() = 'pagebreak'][not(following-sibling::*[1][local-name() = 'pagebreak'])]" mode="update_xml_step_move_pagebreak">
15658
+
15659
+ <!-- <xsl:choose>
15660
+ <xsl:when test="ancestor::*[local-name() = 'sections']">
15661
+
15662
+ </xsl:when>
15663
+ <xsl:when test="ancestor::*[local-name() = 'annex']">
15664
+ </xsl:when>
15665
+ <xsl:otherwise>
15666
+ <xsl:copy-of select="."/>
15667
+ </xsl:otherwise>
15668
+ </xsl:choose> -->
15669
+
15670
+ <!-- determine pagebreak is last element before </fo:flow> or not -->
15671
+ <xsl:variable name="isLast">
15672
+ <xsl:for-each select="ancestor-or-self::*[ancestor::*[local-name() = 'sections'] or ancestor-or-self::*[local-name() = 'annex']]">
15673
+ <xsl:if test="following-sibling::*">false</xsl:if>
15674
+ </xsl:for-each>
15675
+ </xsl:variable>
15676
+
15677
+ <xsl:if test="contains($isLast, 'false')">
15678
+
15679
+ <xsl:variable name="orientation" select="normalize-space(@orientation)"/>
15680
+
15681
+ <xsl:variable name="tree_">
15682
+ <xsl:call-template name="makeAncestorsElementsTree"/>
15683
+ </xsl:variable>
15684
+ <xsl:variable name="tree" select="xalan:nodeset($tree_)"/>
15685
+
15686
+ <!-- close fo:page-sequence (closing preceding fo elements) -->
15687
+ <xsl:call-template name="insertClosingElements">
15688
+ <xsl:with-param name="tree" select="$tree"/>
15689
+ </xsl:call-template>
15690
+
15691
+ <xsl:text disable-output-escaping="yes">&lt;/page_sequence&gt;</xsl:text>
15692
+
15693
+ <!-- create a new page_sequence (opening elements) -->
15694
+ <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>
15695
+
15696
+ <xsl:call-template name="insertOpeningElements">
15697
+ <xsl:with-param name="tree" select="$tree"/>
15698
+ </xsl:call-template>
15699
+
15700
+ </xsl:if>
15701
+ </xsl:template>
15702
+
15703
+ <xsl:template name="makeAncestorsElementsTree">
15704
+ <xsl:for-each select="ancestor::*[ancestor::*[local-name() = 'sections'] or ancestor-or-self::*[local-name() = 'annex']]">
15705
+ <element pos="{position()}">
15706
+ <xsl:copy-of select="@*[local-name() != 'id']"/>
15707
+ <xsl:value-of select="name()"/>
15708
+ </element>
15709
+ </xsl:for-each>
15710
+ </xsl:template>
15711
+
15712
+ <xsl:template name="insertClosingElements">
15713
+ <xsl:param name="tree"/>
15714
+ <xsl:for-each select="$tree//element">
15715
+ <xsl:sort data-type="number" order="descending" select="@pos"/>
15716
+ <xsl:text disable-output-escaping="yes">&lt;/</xsl:text>
15717
+ <xsl:value-of select="."/>
15718
+ <xsl:text disable-output-escaping="yes">&gt;</xsl:text>
15719
+ <xsl:if test="$debug = 'true'">
15720
+ <xsl:message>&lt;/<xsl:value-of select="."/>&gt;</xsl:message>
15721
+ </xsl:if>
15722
+ </xsl:for-each>
15723
+ </xsl:template>
15724
+
15725
+ <xsl:template name="insertOpeningElements">
15726
+ <xsl:param name="tree"/>
15727
+ <xsl:for-each select="$tree//element">
15728
+ <xsl:text disable-output-escaping="yes">&lt;</xsl:text>
15729
+ <xsl:value-of select="."/>
15730
+ <xsl:for-each select="@*[local-name() != 'pos']">
15731
+ <xsl:text> </xsl:text>
15732
+ <xsl:value-of select="local-name()"/>
15733
+ <xsl:text>="</xsl:text>
15734
+ <xsl:value-of select="."/>
15735
+ <xsl:text>"</xsl:text>
15736
+ </xsl:for-each>
15737
+ <xsl:if test="position() = 1"> continue="true"</xsl:if>
15738
+ <xsl:text disable-output-escaping="yes">&gt;</xsl:text>
15739
+ <xsl:if test="$debug = 'true'">
15740
+ <xsl:message>&lt;<xsl:value-of select="."/>&gt;</xsl:message>
15741
+ </xsl:if>
15742
+ </xsl:for-each>
15743
+ </xsl:template>
15744
+
15745
+ <!-- move full page width figures, tables at top level -->
15746
+ <xsl:template match="*[local-name() = 'figure' or local-name() = 'table'][normalize-space(@width) != 'text-width']" mode="update_xml_step_move_pagebreak">
15747
+ <xsl:choose>
15748
+ <xsl:when test="$layout_columns != 1">
15749
+
15750
+ <xsl:variable name="tree_">
15751
+ <xsl:call-template name="makeAncestorsElementsTree"/>
15752
+ </xsl:variable>
15753
+ <xsl:variable name="tree" select="xalan:nodeset($tree_)"/>
15754
+
15755
+ <xsl:call-template name="insertClosingElements">
15756
+ <xsl:with-param name="tree" select="$tree"/>
15757
+ </xsl:call-template>
15758
+
15759
+ <!-- <xsl:copy-of select="."/> -->
15760
+ <xsl:copy>
15761
+ <xsl:copy-of select="@*"/>
15762
+ <xsl:attribute name="top-level">true</xsl:attribute>
15763
+ <xsl:copy-of select="node()"/>
15764
+ </xsl:copy>
15765
+
15766
+ <xsl:call-template name="insertOpeningElements">
15767
+ <xsl:with-param name="tree" select="$tree"/>
15768
+ </xsl:call-template>
15769
+
15770
+ </xsl:when>
15771
+ <xsl:otherwise>
15772
+ <xsl:copy-of select="."/>
15773
+ </xsl:otherwise>
15774
+ </xsl:choose>
15775
+ </xsl:template>
15776
+
15777
+ <!-- =========================================================================== -->
15778
+ <!-- END STEP MOVE PAGEBREAK: move <pagebreak/> at top level under 'preface' and 'sections' -->
15422
15779
  <!-- =========================================================================== -->
15423
15780
 
15424
15781
  <!-- =========================================================================== -->
@@ -15708,7 +16065,7 @@
15708
16065
  <xsl:apply-templates select="*[local-name() = 'term']" mode="linear_xml"/>
15709
16066
  </xsl:template>
15710
16067
 
15711
- <xsl:template match="*[local-name() = 'introduction']//*[local-name() = 'title'] | *[local-name() = 'foreword']//*[local-name() = 'title'] | *[local-name() = 'sections']//*[local-name() = 'title'] | *[local-name() = 'annex']//*[local-name() = 'title'] | *[local-name() = 'bibliography']/*[local-name() = 'clause']/*[local-name() = 'title'] | *[local-name() = 'references']/*[local-name() = 'title'] | *[local-name() = 'colophon']//*[local-name() = 'title']" mode="linear_xml" priority="2">
16068
+ <xsl:template match="*[local-name() = 'introduction']//*[local-name() = 'title'] | *[local-name() = 'foreword']//*[local-name() = 'title'] | *[local-name() = 'preface']//*[local-name() = 'title'] | *[local-name() = 'sections']//*[local-name() = 'title'] | *[local-name() = 'annex']//*[local-name() = 'title'] | *[local-name() = 'bibliography']/*[local-name() = 'clause']/*[local-name() = 'title'] | *[local-name() = 'references']/*[local-name() = 'title'] | *[local-name() = 'colophon']//*[local-name() = 'title']" mode="linear_xml" priority="2">
15712
16069
  <xsl:copy>
15713
16070
  <xsl:apply-templates select="@*" mode="linear_xml"/>
15714
16071
 
@@ -15727,7 +16084,7 @@
15727
16084
  <xsl:copy-of select="../@inline-header"/>
15728
16085
  </xsl:if>
15729
16086
 
15730
- <xsl:attribute name="ancestor">
16087
+ <xsl:variable name="ancestor">
15731
16088
  <xsl:choose>
15732
16089
  <xsl:when test="ancestor::*[local-name() = 'foreword']">foreword</xsl:when>
15733
16090
  <xsl:when test="ancestor::*[local-name() = 'introduction']">introduction</xsl:when>
@@ -15735,6 +16092,35 @@
15735
16092
  <xsl:when test="ancestor::*[local-name() = 'annex']">annex</xsl:when>
15736
16093
  <xsl:when test="ancestor::*[local-name() = 'bibliography']">bibliography</xsl:when>
15737
16094
  </xsl:choose>
16095
+ </xsl:variable>
16096
+ <xsl:attribute name="ancestor">
16097
+ <xsl:value-of select="$ancestor"/>
16098
+ </xsl:attribute>
16099
+
16100
+ <xsl:attribute name="parent">
16101
+ <xsl:choose>
16102
+ <xsl:when test="ancestor::*[local-name() = 'preface']">preface</xsl:when>
16103
+ <xsl:otherwise><xsl:value-of select="$ancestor"/></xsl:otherwise>
16104
+ </xsl:choose>
16105
+ </xsl:attribute>
16106
+
16107
+ <xsl:apply-templates mode="linear_xml"/>
16108
+ </xsl:copy>
16109
+ </xsl:template>
16110
+
16111
+ <xsl:template match="*[local-name() = 'li']" mode="linear_xml" priority="2">
16112
+ <xsl:copy>
16113
+ <xsl:apply-templates select="@*" mode="linear_xml"/>
16114
+
16115
+ <xsl:variable name="ancestor">
16116
+ <xsl:choose>
16117
+ <xsl:when test="ancestor::*[local-name() = 'preface']">preface</xsl:when>
16118
+ <xsl:when test="ancestor::*[local-name() = 'sections']">sections</xsl:when>
16119
+ <xsl:when test="ancestor::*[local-name() = 'annex']">annex</xsl:when>
16120
+ </xsl:choose>
16121
+ </xsl:variable>
16122
+ <xsl:attribute name="ancestor">
16123
+ <xsl:value-of select="$ancestor"/>
15738
16124
  </xsl:attribute>
15739
16125
 
15740
16126
  <xsl:apply-templates mode="linear_xml"/>
@@ -16143,7 +16529,7 @@
16143
16529
  <xsl:value-of select="$depth"/>
16144
16530
  </xsl:when>
16145
16531
  <xsl:otherwise>
16146
- <xsl:variable name="level_total" select="count(ancestor::*)"/>
16532
+ <xsl:variable name="level_total" select="count(ancestor::*[local-name() != 'page_sequence'])"/>
16147
16533
  <xsl:variable name="level">
16148
16534
  <xsl:choose>
16149
16535
  <xsl:when test="parent::*[local-name() = 'preface']">