
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"
    xmlns:dd29="https://dd.info-rac.org/namespace.jsp?ns_id=29" xmlns:dd67="https://dd.info-rac.org/namespace.jsp?ns_id=67">
    <xsl:output method="xml"/>

    <xsl:template match="/">
<delivery>        <xsl:apply-templates select="dd29:ind_5_1_1_records/dd29:Row"/>
</delivery>    </xsl:template>

    <xsl:template match="dd29:ind_5_1_1_records/dd29: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>rowID</name>
<type>string</type>
<length>100</length>
<precision></precision>
<multiValueDelim></multiValueDelim>
</elem><elem>
<name>nationalStationID</name>
<type>string</type>
<length>255</length>
<precision></precision>
<multiValueDelim></multiValueDelim>
</elem><elem>
<name>nationalStationName</name>
<type>string</type>
<length>255</length>
<precision></precision>
<multiValueDelim></multiValueDelim>
</elem><elem>
<name>longitude</name>
<type></type>
<length></length>
<precision></precision>
<multiValueDelim></multiValueDelim>
</elem><elem>
<name>latitude</name>
<type></type>
<length></length>
<precision></precision>
<multiValueDelim></multiValueDelim>
</elem><elem>
<name>closestCoast</name>
<type></type>
<length></length>
<precision></precision>
<multiValueDelim></multiValueDelim>
</elem><elem>
<name>seaDepth</name>
<type></type>
<length></length>
<precision></precision>
<multiValueDelim></multiValueDelim>
</elem><elem>
<name>mixing</name>
<type>string</type>
<length>2</length>
<precision></precision>
<multiValueDelim></multiValueDelim>
</elem><elem>
<name>areaType</name>
<type>string</type>
<length>4</length>
<precision></precision>
<multiValueDelim></multiValueDelim>
</elem><elem>
<name>remarks</name>
<type>string</type>
<length>4096</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>615</elementid>
      <identifier>reportID</identifier>
      <parentNS>67</parentNS>
      <type>string</type>
      <length>100</length>
      <precision></precision>
   </element>
   <element>
      <elementid>616</elementid>
      <identifier>rowID</identifier>
      <parentNS>67</parentNS>
      <type>string</type>
      <length>100</length>
      <precision></precision>
   </element>
   <element>
      <elementid>677</elementid>
      <identifier>nationalStationID</identifier>
      <parentNS>67</parentNS>
      <type>string</type>
      <length>255</length>
      <precision></precision>
   </element>
   <element>
      <elementid>678</elementid>
      <identifier>nationalStationName</identifier>
      <parentNS>67</parentNS>
      <type>string</type>
      <length>255</length>
      <precision></precision>
   </element>
   <element>
      <elementid>679</elementid>
      <identifier>longitude</identifier>
      <parentNS>67</parentNS>
      <type></type>
      <length></length>
      <precision></precision>
   </element>
   <element>
      <elementid>680</elementid>
      <identifier>latitude</identifier>
      <parentNS>67</parentNS>
      <type></type>
      <length></length>
      <precision></precision>
   </element>
   <element>
      <elementid>681</elementid>
      <identifier>closestCoast</identifier>
      <parentNS>67</parentNS>
      <type></type>
      <length></length>
      <precision></precision>
   </element>
   <element>
      <elementid>682</elementid>
      <identifier>seaDepth</identifier>
      <parentNS>67</parentNS>
      <type></type>
      <length></length>
      <precision></precision>
   </element>
   <element>
      <elementid>683</elementid>
      <identifier>mixing</identifier>
      <parentNS>67</parentNS>
      <type>string</type>
      <length>2</length>
      <precision></precision>
   </element>
   <element>
      <elementid>684</elementid>
      <identifier>areaType</identifier>
      <parentNS>67</parentNS>
      <type>string</type>
      <length>4</length>
      <precision></precision>
   </element>
   <element>
      <elementid>685</elementid>
      <identifier>remarks</identifier>
      <parentNS>67</parentNS>
      <type>string</type>
      <length>4096</length>
      <precision></precision>
   </element>
</xsl:variable>
</xsl:stylesheet>
