
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"
    xmlns:dd884="https://dd.eionet.europa.eu/namespace.jsp?ns_id=884" xmlns:dd887="https://dd.eionet.europa.eu/namespace.jsp?ns_id=887">
    <xsl:output method="xml"/>

    <xsl:template match="/">
<delivery>        <xsl:apply-templates select="dd884:sectionASpecies/dd884:Row"/>
</delivery>    </xsl:template>

    <xsl:template match="dd884:sectionASpecies/dd884: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>reportID</name>
<type>string</type>
<length>100</length>
<precision></precision>
<multiValueDelim></multiValueDelim>
</elem><elem>
<name>EASINCode</name>
<type>string</type>
<length>6</length>
<precision></precision>
<multiValueDelim></multiValueDelim>
</elem><elem>
<name>common_name_naltional</name>
<type>string</type>
<length>2500</length>
<precision></precision>
<multiValueDelim></multiValueDelim>
</elem><elem>
<name>present_in_MS</name>
<type></type>
<length></length>
<precision></precision>
<multiValueDelim></multiValueDelim>
</elem><elem>
<name>reproduction_pattern</name>
<type></type>
<length></length>
<precision></precision>
<multiValueDelim></multiValueDelim>
</elem><elem>
<name>additional_information</name>
<type>string</type>
<length>2500</length>
<precision></precision>
<multiValueDelim></multiValueDelim>
</elem><elem>
<name>permits_issued</name>
<type></type>
<length></length>
<precision></precision>
<multiValueDelim></multiValueDelim>
</elem><elem>
<name>additional_information_permits_issued</name>
<type>string</type>
<length>2500</length>
<precision></precision>
<multiValueDelim></multiValueDelim>
</elem><elem>
<name>no_inspections_reported</name>
<type></type>
<length></length>
<precision></precision>
<multiValueDelim></multiValueDelim>
</elem><elem>
<name>additional_information_inspections</name>
<type>string</type>
<length>2500</length>
<precision></precision>
<multiValueDelim></multiValueDelim>
</elem><elem>
<name>eradication_measures</name>
<type></type>
<length></length>
<precision></precision>
<multiValueDelim></multiValueDelim>
</elem><elem>
<name>subject_management_measures</name>
<type></type>
<length></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>97094</elementid>
      <identifier>reportID</identifier>
      <parentNS>887</parentNS>
      <type>string</type>
      <length>100</length>
      <precision></precision>
   </element>
   <element>
      <elementid>97095</elementid>
      <identifier>EASINCode</identifier>
      <parentNS>887</parentNS>
      <type>string</type>
      <length>6</length>
      <precision></precision>
   </element>
   <element>
      <elementid>97096</elementid>
      <identifier>common_name_naltional</identifier>
      <parentNS>887</parentNS>
      <type>string</type>
      <length>2500</length>
      <precision></precision>
   </element>
   <element>
      <elementid>97098</elementid>
      <identifier>present_in_MS</identifier>
      <parentNS>887</parentNS>
      <type></type>
      <length></length>
      <precision></precision>
   </element>
   <element>
      <elementid>97099</elementid>
      <identifier>reproduction_pattern</identifier>
      <parentNS>887</parentNS>
      <type></type>
      <length></length>
      <precision></precision>
   </element>
   <element>
      <elementid>97100</elementid>
      <identifier>additional_information</identifier>
      <parentNS>887</parentNS>
      <type>string</type>
      <length>2500</length>
      <precision></precision>
   </element>
   <element>
      <elementid>97102</elementid>
      <identifier>permits_issued</identifier>
      <parentNS>887</parentNS>
      <type></type>
      <length></length>
      <precision></precision>
   </element>
   <element>
      <elementid>97103</elementid>
      <identifier>additional_information_permits_issued</identifier>
      <parentNS>887</parentNS>
      <type>string</type>
      <length>2500</length>
      <precision></precision>
   </element>
   <element>
      <elementid>97104</elementid>
      <identifier>no_inspections_reported</identifier>
      <parentNS>887</parentNS>
      <type></type>
      <length></length>
      <precision></precision>
   </element>
   <element>
      <elementid>97105</elementid>
      <identifier>additional_information_inspections</identifier>
      <parentNS>887</parentNS>
      <type>string</type>
      <length>2500</length>
      <precision></precision>
   </element>
   <element>
      <elementid>97106</elementid>
      <identifier>eradication_measures</identifier>
      <parentNS>887</parentNS>
      <type></type>
      <length></length>
      <precision></precision>
   </element>
   <element>
      <elementid>97107</elementid>
      <identifier>subject_management_measures</identifier>
      <parentNS>887</parentNS>
      <type></type>
      <length></length>
      <precision></precision>
   </element>
</xsl:variable>
</xsl:stylesheet>
