View stylesheet

XML schema http://dd.eionet.europa.eu/schemas/ods-2023/ODSReport.xsd
Output type XML
Description Convert ODS submission from 2024 to 2025 format
XSL file ODS_2024-2025.xsl (Last modified: 10 Feb 2025 10:18 )
<xsl:stylesheet
  version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  >

  <xsl:output method="xml" indent="yes" encoding="UTF-8"/>
  <xsl:strip-space elements="*" />


  <xsl:template match="node()|@*" name="identity">
    <xsl:copy>
      <xsl:apply-templates select="node()|@*"/>
    </xsl:copy>
  </xsl:template>
 

  <xsl:template match="@*[name() = 'xsi:noNamespaceSchemaLocation']">
    <xsl:attribute name="{name()}">http://dd.eionet.europa.eu/schemas/ods-2024/ODSReport.xsd</xsl:attribute>
  </xsl:template>



  <xsl:template match="@* | node()">
    <xsl:copy>
      <xsl:apply-templates select="@* | node()"/>
    </xsl:copy>
  </xsl:template>

  <!-- <xsl:template match="ODSReporting/ODSQuantities/TotalProduction/Comments"/> --> <!-- commented on 20241210 -->
  <xsl:template match="ODSReporting/ODSQuantities/TotalProduction">
    <xsl:copy>
      <xsl:copy-of select="@*"/>
      <xsl:copy-of select="node()"/>
      <xsl:if test="count(./ProductionQuantity) > 1 and not(./ProductionQuantity//Subject[@usetype='emissions linked to production'])">
        <ProductionQuantity>
          <Subject usetype="emissions linked to production"/>
          <!-- Generate <Quantity> for each SubstanceCode -->
          <xsl:for-each select="./ProductionQuantity[position() = 1]//SubstanceCode[string-length(normalize-space(.)) > 0]">
            <Quantity>
              <SubstanceCode>
                <xsl:attribute name="virgin">
                    <xsl:value-of select="@virgin"/>
                </xsl:attribute>
                <xsl:value-of select="."/>
              </SubstanceCode>
              <Value/>
            </Quantity>
          </xsl:for-each>
        </ProductionQuantity>
      </xsl:if>
	  <xsl:if test="not(./Comments)">
        <Comments/>
      </xsl:if>
    </xsl:copy>
  </xsl:template>

  
  <xsl:template match="ODSReporting/ODSQuantities/TotalImports">
    <xsl:copy>
      <xsl:copy-of select="@*"/>
      <xsl:copy-of select="node()"/>
      <xsl:if test="not(./Comments)">
        <Comments/>
      </xsl:if>
    </xsl:copy>
  </xsl:template>



  <xsl:template match="ODSReporting/ODSQuantities/ExportFromEU">
    <xsl:copy>
      <xsl:copy-of select="@*"/>
      <xsl:copy-of select="node()"/>
      <xsl:if test="not(./Comments)">
        <Comments/>
      </xsl:if>
    </xsl:copy>
  </xsl:template>

  
  
  <xsl:template match="ODSReporting/ODSQuantities/ExportFromEU/ExportQuantity">
    <xsl:if test="(./CustomsProcedure) and (./CustomsProcedure) != ''">      
      <xsl:copy>
        <xsl:apply-templates select="node()|@*"/>
      </xsl:copy>
    </xsl:if>
  </xsl:template>



  <xsl:template match="ODSReporting/ODSQuantities/PauFdst/ProcessQuantity/Process">
    <Process alternatives="">
        <xsl:apply-templates select="@*|node()"/>
    </Process>
  </xsl:template>



  <xsl:template match="ODSReporting/ODSQuantities/Destruction/DestructionQuantity/Quantity">
    <xsl:copy>
      <xsl:copy-of select="@*"/>
      <xsl:copy-of select="node()"/>
      <xsl:if test="not(../../Comments)">
        <Comments/>
      </xsl:if>
      <xsl:if test="not(./Table14Emissions)">
        <Table14Emissions/>
      </xsl:if>
      <xsl:if test="not(./ByP)">
        <ByP/>
      </xsl:if>
      <xsl:if test="not(./Eq)">
        <Eq/>
      </xsl:if>
    </xsl:copy>
  </xsl:template>
  
  
  <xsl:template match="ODSReporting/ODSQuantities/TotalStocks">
    <xsl:copy>
      <xsl:copy-of select="@*"/>
      <xsl:copy-of select="node()"/>
      <xsl:if test="count(./StockQuantity) > 1 and not(./Emissions)">
        <Emissions>
          <Subject usetype="Emissions from storage"/>
          <!-- Generate <Quantity> for each existing <SubstanceCode> in TotalStocks -->
          <xsl:for-each select="./StockQuantity[@date='01-01' and position() = 1]//SubstanceCode[string-length(normalize-space(.)) > 0]">
            <Quantity>
              <SubstanceCode>
                <xsl:attribute name="virgin">
                    <xsl:value-of select="@virgin"/>
                </xsl:attribute>
                <xsl:value-of select="."/>
              </SubstanceCode>
              <Value/>
              <Description/>
            </Quantity>
          </xsl:for-each>
        </Emissions>
        <Emissions>
          <Subject usetype="Emissions from transport"/>
          <!-- Generate <Quantity> for each existing <SubstanceCode> in TotalStocks -->
          <xsl:for-each select="./StockQuantity[@date='01-01' and position() = 1]//SubstanceCode[string-length(normalize-space(.)) > 0]">
            <Quantity>
              <SubstanceCode>
                <xsl:attribute name="virgin">
                    <xsl:value-of select="@virgin"/>
                </xsl:attribute>
                <xsl:value-of select="."/>
              </SubstanceCode>
              <Value/>
              <Description/>
            </Quantity>
          </xsl:for-each>
        </Emissions>
      </xsl:if>
    </xsl:copy>
  </xsl:template>
 

</xsl:stylesheet>