
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"
    xmlns:dd753="https://dd.eionet.europa.eu/namespace.jsp?ns_id=753" xmlns:dd763="https://dd.eionet.europa.eu/namespace.jsp?ns_id=763">
    <xsl:output method="xml"/>

    <xsl:template match="/">
<delivery>        <xsl:apply-templates select="dd753:Hydr_bas_impr_san/dd753:Row"/>
</delivery>    </xsl:template>

    <xsl:template match="dd753:Hydr_bas_impr_san/dd753:Row">
        <xsl:if test="position()=1">
            <xsl:call-template name="table-def"/>
<xsl:text disable-output-escaping="yes">&lt;data&gt;</xsl:text>        </xsl:if>

<row>
   <xsl:variable xmlns:xsl="http://www.w3.org/1999/XSL/Transform" name="row" select="."></xsl:variable>
   <xsl:for-each xmlns:xsl="http://www.w3.org/1999/XSL/Transform" select="$elementsMetadata/element">
      <xsl:variable name="elemIdentifier">
         <xsl:value-of select="identifier"></xsl:value-of>
      </xsl:variable><xsl:text disable-output-escaping="yes">&lt;</xsl:text><xsl:value-of select="$elemIdentifier"/><xsl:text disable-output-escaping="yes">&gt;</xsl:text>
      <xsl:variable name="multiValueSeparator">
         <xsl:call-template name="getSeparator">
            <xsl:with-param name="element" select="$elemIdentifier"></xsl:with-param>
         </xsl:call-template>
      </xsl:variable>
      <xsl:choose>
         <xsl:when test="count($row/*[local-name()= $elemIdentifier])=0 or string-join($row/*[local-name()= $elemIdentifier ],'')=''"></xsl:when>
         <xsl:otherwise>
            <xsl:value-of select="string-join($row/*[local-name()= $elemIdentifier ],$multiValueSeparator)"></xsl:value-of>
         </xsl:otherwise>
      </xsl:choose><xsl:text disable-output-escaping="yes">&lt;/</xsl:text><xsl:value-of select="$elemIdentifier"/><xsl:text disable-output-escaping="yes">&gt;</xsl:text>
   </xsl:for-each>
</row>        <xsl:if test="position()=last()">
<xsl:text disable-output-escaping="yes">&lt;/data&gt;</xsl:text>        </xsl:if>
</xsl:template>

<xsl:template name="table-def">

<table><elem>
<name>CountryCode</name>
<type></type>
<length></length>
<precision></precision>
<multiValueDelim></multiValueDelim>
</elem><elem>
<name>Coastal_region</name>
<type></type>
<length></length>
<precision></precision>
<multiValueDelim></multiValueDelim>
</elem><elem>
<name>Year_H2020</name>
<type>integer</type>
<length>4</length>
<precision></precision>
<multiValueDelim></multiValueDelim>
</elem><elem>
<name>Tot_pop_impr_san</name>
<type>decimal</type>
<length>8</length>
<precision>2</precision>
<multiValueDelim></multiValueDelim>
</elem><elem>
<name>Urb_pop_impr_san</name>
<type>decimal</type>
<length>8</length>
<precision>2</precision>
<multiValueDelim></multiValueDelim>
</elem><elem>
<name>Rur_pop_impr_san</name>
<type>decimal</type>
<length>8</length>
<precision>2</precision>
<multiValueDelim></multiValueDelim>
</elem><elem>
<name>Data_collection_method</name>
<type></type>
<length></length>
<precision></precision>
<multiValueDelim></multiValueDelim>
</elem><elem>
<name>Remarks</name>
<type>string</type>
<length>255</length>
<precision></precision>
<multiValueDelim></multiValueDelim>
</elem></table></xsl:template>

<xsl:template xmlns:xsl="http://www.w3.org/1999/XSL/Transform" name="getSeparator">
   <xsl:param name="element" select="''"></xsl:param>
   <xsl:value-of select="','"></xsl:value-of>
</xsl:template>
<xsl:variable xmlns:xsl="http://www.w3.org/1999/XSL/Transform" name="elementsMetadata">
   <element>
      <elementid>67135</elementid>
      <identifier>CountryCode</identifier>
      <parentNS>null</parentNS>
      <type></type>
      <length></length>
      <precision></precision>
   </element>
   <element>
      <elementid>66588</elementid>
      <identifier>Coastal_region</identifier>
      <parentNS>null</parentNS>
      <type></type>
      <length></length>
      <precision></precision>
   </element>
   <element>
      <elementid>66533</elementid>
      <identifier>Year_H2020</identifier>
      <parentNS>null</parentNS>
      <type>integer</type>
      <length>4</length>
      <precision></precision>
   </element>
   <element>
      <elementid>67984</elementid>
      <identifier>Tot_pop_impr_san</identifier>
      <parentNS>763</parentNS>
      <type>decimal</type>
      <length>8</length>
      <precision>2</precision>
   </element>
   <element>
      <elementid>67985</elementid>
      <identifier>Urb_pop_impr_san</identifier>
      <parentNS>763</parentNS>
      <type>decimal</type>
      <length>8</length>
      <precision>2</precision>
   </element>
   <element>
      <elementid>67983</elementid>
      <identifier>Rur_pop_impr_san</identifier>
      <parentNS>763</parentNS>
      <type>decimal</type>
      <length>8</length>
      <precision>2</precision>
   </element>
   <element>
      <elementid>66534</elementid>
      <identifier>Data_collection_method</identifier>
      <parentNS>null</parentNS>
      <type></type>
      <length></length>
      <precision></precision>
   </element>
   <element>
      <elementid>63568</elementid>
      <identifier>Remarks</identifier>
      <parentNS>null</parentNS>
      <type>string</type>
      <length>255</length>
      <precision></precision>
   </element>
</xsl:variable>
</xsl:stylesheet>
