
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"
    xmlns:dd9="https://dd.info-rac.org/namespace.jsp?ns_id=9" xmlns:dd13="https://dd.info-rac.org/namespace.jsp?ns_id=13">
    <xsl:output method="xml"/>

    <xsl:template match="/">
<delivery>        <xsl:apply-templates select="dd9:lbsinventorydata/dd9:Row"/>
</delivery>    </xsl:template>

    <xsl:template match="dd9:lbsinventorydata/dd9: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>collection_id</name>
<type>integer</type>
<length>20</length>
<precision></precision>
<multiValueDelim></multiValueDelim>
</elem><elem>
<name>pollutantgroup</name>
<type>string</type>
<length>255</length>
<precision></precision>
<multiValueDelim></multiValueDelim>
</elem><elem>
<name>activitysector</name>
<type>string</type>
<length>255</length>
<precision></precision>
<multiValueDelim></multiValueDelim>
</elem><elem>
<name>activitysubsector</name>
<type>string</type>
<length>255</length>
<precision></precision>
<multiValueDelim></multiValueDelim>
</elem><elem>
<name>reportednbb</name>
<type>integer</type>
<length>1</length>
<precision></precision>
<multiValueDelim></multiValueDelim>
</elem><elem>
<name>airquantity</name>
<type></type>
<length></length>
<precision></precision>
<multiValueDelim></multiValueDelim>
</elem><elem>
<name>waterquantity</name>
<type></type>
<length></length>
<precision></precision>
<multiValueDelim></multiValueDelim>
</elem><elem>
<name>soilquantity</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>128</elementid>
      <identifier>collection_id</identifier>
      <parentNS>13</parentNS>
      <type>integer</type>
      <length>20</length>
      <precision></precision>
   </element>
   <element>
      <elementid>129</elementid>
      <identifier>pollutantgroup</identifier>
      <parentNS>13</parentNS>
      <type>string</type>
      <length>255</length>
      <precision></precision>
   </element>
   <element>
      <elementid>130</elementid>
      <identifier>activitysector</identifier>
      <parentNS>13</parentNS>
      <type>string</type>
      <length>255</length>
      <precision></precision>
   </element>
   <element>
      <elementid>131</elementid>
      <identifier>activitysubsector</identifier>
      <parentNS>13</parentNS>
      <type>string</type>
      <length>255</length>
      <precision></precision>
   </element>
   <element>
      <elementid>132</elementid>
      <identifier>reportednbb</identifier>
      <parentNS>13</parentNS>
      <type>integer</type>
      <length>1</length>
      <precision></precision>
   </element>
   <element>
      <elementid>133</elementid>
      <identifier>airquantity</identifier>
      <parentNS>13</parentNS>
      <type></type>
      <length></length>
      <precision></precision>
   </element>
   <element>
      <elementid>134</elementid>
      <identifier>waterquantity</identifier>
      <parentNS>13</parentNS>
      <type></type>
      <length></length>
      <precision></precision>
   </element>
   <element>
      <elementid>135</elementid>
      <identifier>soilquantity</identifier>
      <parentNS>13</parentNS>
      <type></type>
      <length></length>
      <precision></precision>
   </element>
</xsl:variable>
</xsl:stylesheet>
