
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"
    xmlns:dd802="https://dd.eionet.europa.eu/namespace.jsp?ns_id=802" xmlns:dd844="https://dd.eionet.europa.eu/namespace.jsp?ns_id=844">
    <xsl:output method="xml"/>

    <xsl:template match="/">
<delivery>        <xsl:apply-templates select="dd802:ReceivingAreasSAParameter/dd802:Row"/>
</delivery>    </xsl:template>

    <xsl:template match="dd802:ReceivingAreasSAParameter/dd802: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>repCode</name>
<type>string</type>
<length>16</length>
<precision></precision>
<multiValueDelim></multiValueDelim>
</elem><elem>
<name>rcaCode</name>
<type>string</type>
<length>32</length>
<precision></precision>
<multiValueDelim></multiValueDelim>
</elem><elem>
<name>rcaParameter</name>
<type></type>
<length></length>
<precision></precision>
<multiValueDelim></multiValueDelim>
</elem><elem>
<name>rcaDateDesignation</name>
<type></type>
<length></length>
<precision></precision>
<multiValueDelim></multiValueDelim>
</elem><elem>
<name>rcaStartDate</name>
<type></type>
<length></length>
<precision></precision>
<multiValueDelim></multiValueDelim>
</elem><elem>
<name>rcaCRelevantDirective</name>
<type>string</type>
<length>4096</length>
<precision></precision>
<multiValueDelim></multiValueDelim>
</elem><elem>
<name>rcaCIDOtherDirective</name>
<type>string</type>
<length>128</length>
<precision></precision>
<multiValueDelim></multiValueDelim>
</elem><elem>
<name>rcaCDateOtherDirective</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>95777</elementid>
      <identifier>repCode</identifier>
      <parentNS>null</parentNS>
      <type>string</type>
      <length>16</length>
      <precision></precision>
   </element>
   <element>
      <elementid>94163</elementid>
      <identifier>rcaCode</identifier>
      <parentNS>844</parentNS>
      <type>string</type>
      <length>32</length>
      <precision></precision>
   </element>
   <element>
      <elementid>94165</elementid>
      <identifier>rcaParameter</identifier>
      <parentNS>844</parentNS>
      <type></type>
      <length></length>
      <precision></precision>
   </element>
   <element>
      <elementid>94036</elementid>
      <identifier>rcaDateDesignation</identifier>
      <parentNS>844</parentNS>
      <type></type>
      <length></length>
      <precision></precision>
   </element>
   <element>
      <elementid>94049</elementid>
      <identifier>rcaStartDate</identifier>
      <parentNS>844</parentNS>
      <type></type>
      <length></length>
      <precision></precision>
   </element>
   <element>
      <elementid>94169</elementid>
      <identifier>rcaCRelevantDirective</identifier>
      <parentNS>844</parentNS>
      <type>string</type>
      <length>4096</length>
      <precision></precision>
   </element>
   <element>
      <elementid>94172</elementid>
      <identifier>rcaCIDOtherDirective</identifier>
      <parentNS>844</parentNS>
      <type>string</type>
      <length>128</length>
      <precision></precision>
   </element>
   <element>
      <elementid>94174</elementid>
      <identifier>rcaCDateOtherDirective</identifier>
      <parentNS>844</parentNS>
      <type></type>
      <length></length>
      <precision></precision>
   </element>
</xsl:variable>
</xsl:stylesheet>
