namespace TM.Bosman.Transforms {
    
    
    [Microsoft.XLANGs.BaseTypes.SchemaReference(@"TM.Bosman.Schemas.EFACT_D96A_IFCSUM_BOSMAN", typeof(global::TM.Bosman.Schemas.EFACT_D96A_IFCSUM_BOSMAN))]
    [Microsoft.XLANGs.BaseTypes.SchemaReference(@"TM.Shared.Schemas.Order", typeof(global::TM.Shared.Schemas.Order))]
    public sealed class TM_Bosman_IFCSUM_to_TM_Shared_Order : global::Microsoft.XLANGs.BaseTypes.TransformBase {
        
        private const string _strMap = @"<xsl:stylesheet xmlns:xsl=""http://www.w3.org/1999/XSL/Transform"" version=""1.0""
                xmlns:ScriptNS0=""http://schemas.microsoft.com/BizTalk/2003/ScriptNS0""
                xmlns:ScriptNS1=""http://schemas.microsoft.com/BizTalk/2003/ScriptNS1""
                
                xmlns:Biztalk=""TM.Shared.Components.Biztalk""
                xmlns:DateTime=""TM.Shared.Components.DateTime""
                 xmlns:KeyList=""TM.Shared.Components.KeyList""
                     xmlns:SSO=""TM.Shared.Components.SSO""
                  xmlns:String=""TM.Shared.Components.String""
                
                xmlns:Bosman=""TM.Bosman.Components.MSsql""
                xmlns:Log=""TM.Bosman.Components.Logging""

                xmlns:s0=""http://schemas.microsoft.com/BizTalk/EDI/EDIFACT/2006""
                xmlns:ns0=""http://TM.KLG.com/KLG/Order""
                
                exclude-result-prefixes=""s0 ns0 ScriptNS0 ScriptNS1 DateTime KeyList SSO String Bosman Log"">

  <xsl:output omit-xml-declaration=""yes"" method=""xml"" version=""1.0"" indent=""yes"" />

  <!-- Region global variable initialization -->

  <xsl:variable name=""guid1"">
    <xsl:value-of select=""KeyList:NewGuid()""/>
  </xsl:variable>
  <xsl:variable name=""guid2"">
    <xsl:value-of select=""KeyList:NewGuid()""/>
  </xsl:variable>

  <xsl:variable name=""BosmanReference"" select=""/s0:EFACT_D96A_IFCSUM_BOSMAN/s0:BGM/BGM02"" />

  <xsl:variable name=""sender"">BOSMASHEER01</xsl:variable>

  <!-- region receiver -->
  <xsl:variable name=""receiver"">
    <xsl:choose>
      <xsl:when test=""count(//s0:CNILoop1/s0:NADLoop2[s0:NAD_3/NAD01 = 'DP']) &gt; 0"">
        <xsl:choose>
          <xsl:when test=""//s0:CNILoop1/s0:NADLoop2[s0:NAD_3/NAD01 = 'DP']/s0:NAD_3//NAD09 = 'FR'"">KLGEUEERSE01</xsl:when>
          <xsl:otherwise>KLGEUVENLO01</xsl:otherwise>
        </xsl:choose>
      </xsl:when>
      <xsl:otherwise>
        <xsl:choose>
          <xsl:when test=""//s0:CNILoop1/s0:NADLoop2[s0:NAD_3/NAD01 = 'CN']/s0:NAD_3//NAD09 = 'FR'"">KLGEUEERSE01</xsl:when>
          <xsl:otherwise>KLGEUVENLO01</xsl:otherwise>
        </xsl:choose>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:variable>
  <!-- end region -->

  <!-- region connectionString -->
  <xsl:variable name=""connectionString"" select=""SSO:GetValue('TM.Bosman', 'ESBLookupConnectionString2016')""/>
  <!-- end region -->

  <!-- region consolidationReference -->
  <xsl:variable name=""consolidationReference"" select=""/s0:EFACT_D96A_IFCSUM_BOSMAN/s0:RFFLoop1[s0:RFF/s0:C506/C50601 = 'PG']/s0:RFF/s0:C506/C50602"" />
  <!-- end region -->

  <!-- region constants -->
  <xsl:variable name=""lowerCase"" select=""'abcdefghijklmnopqrstuvwxyz'"" />
  <xsl:variable name=""upperCase"" select=""'ABCDEFGHIJKLMNOPQRSTUVWXYZ'"" />
  <!-- end region -->

  <!-- region kGoods -->
  <!-- Voor Venlo moeten goederenregels gesplitst worden op de combinatie van packing en Deliveryreference Voor Eersel alleen op packing -->
  <xsl:key name=""kGoodsVenlo"" match=""s0:GIDLoop1"" use=""concat(generate-id(..), '|', s0:GID/s0:C213/C21302, '|', s0:PCILoop1/s0:PCI/s0:C210/C21001)"" />
  <xsl:key name=""kGoodsEersel"" match=""s0:GIDLoop1"" use=""concat(generate-id(..), '|', s0:GID/s0:C213/C21302, '|')"" />
  <!-- end region -->

  <xsl:key name=""kLabel"" match=""s0:GIDLoop1/s0:PCILoop1/s0:PCI/s0:C210/C21001/text()"" use=""."" />

  <!-- region orderDate -->
  <xsl:variable name=""orderDate"" select=""DateTime:FormatDateTime(/s0:EFACT_D96A_IFCSUM_BOSMAN/s0:RFFLoop1/s0:DTM_2/s0:C507_2[C50701 = '171']/C50702, 'yyyyMMdd', 'yyyy-MM-dd', 'TM.BOSMAN.IFCSUM_to_TM.Shared.Order: orderDate')""/>
  <!-- end region -->

  <!-- region loadingDate loadingDateTimeFrom loadingDateTimeTo -->
  <xsl:variable name=""loadingDate189"">
    <xsl:choose>
      <xsl:when test=""/s0:EFACT_D96A_IFCSUM_BOSMAN/s0:TDTLoop1/s0:DTM_5/s0:C507_5[C50701 = '189']/C50702 and '0001-01-01' != DateTime:FormatDateTime(/s0:EFACT_D96A_IFCSUM_BOSMAN/s0:TDTLoop1/s0:DTM_5/s0:C507_5[C50701 = '189']/C50702, 'yyyyMMdd', 'yyyy-MM-dd', 'TM.BOSMAN.IFCSUM_to_TM.Shared.Order: loadingDate189 TEST')"">
        <xsl:value-of select=""DateTime:FormatDateTime(/s0:EFACT_D96A_IFCSUM_BOSMAN/s0:TDTLoop1/s0:DTM_5/s0:C507_5[C50701 = '189']/C50702, 'yyyyMMdd', 'yyyy-MM-dd', 'TM.BOSMAN.IFCSUM_to_TM.Shared.Order: loadingDate189')"" />
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select=""DateTime:GetWorkday($orderDate, 0, 'NL')""/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:variable>

  <xsl:variable name=""loadingDate189TimeFrom"">
    <xsl:choose>
      <xsl:when test=""$receiver = 'KLGEUEERSE01'"">
        <xsl:value-of select=""$loadingDate189"" />
      </xsl:when>
      <xsl:when test=""$receiver = 'KLGEUVENLO01'"">
        <xsl:value-of select=""concat($loadingDate189, 'T08:00:00')"" />
      </xsl:when>
    </xsl:choose>
  </xsl:variable>

  <xsl:variable name=""loadingDate189TimeTo"">
    <xsl:choose>
      <xsl:when test=""$receiver = 'KLGEUEERSE01'"">
        <xsl:value-of select=""$loadingDate189"" />
      </xsl:when>
      <xsl:when test=""$receiver = 'KLGEUVENLO01'"">
        <xsl:value-of select=""concat($loadingDate189, 'T16:00:00')"" />
      </xsl:when>
    </xsl:choose>
  </xsl:variable>
  <!-- end region -->

  <!-- end region -->

  <!-- region templates -->

  <xsl:template match=""/"">
    <xsl:apply-templates select=""/s0:EFACT_D96A_IFCSUM_BOSMAN"" />
  </xsl:template>

  <xsl:template match=""/s0:EFACT_D96A_IFCSUM_BOSMAN"">
    <ns0:Order>
      <xsl:variable name=""bosmanRoutine"">
        <xsl:for-each select=""s0:CNILoop1"">
          <!-- Count Shipments: Collection to Delivery country -->

          <xsl:variable name=""from"" select=""s0:NADLoop2[s0:NAD_3/NAD01 = 'CZ']/s0:NAD_3/NAD09""/>

          <xsl:variable name=""to"">

            <xsl:choose>
              <xsl:when test=""count(s0:NADLoop2[s0:NAD_3/NAD01 = 'DP']) &gt; 0"">
                <xsl:value-of select=""s0:NADLoop2[s0:NAD_3/NAD01 = 'DP']/s0:NAD_3//NAD09""/>
              </xsl:when>
              <xsl:otherwise>
                <xsl:value-of select=""s0:NADLoop2[s0:NAD_3/NAD01 = 'CN']/s0:NAD_3//NAD09""/>
              </xsl:otherwise>
            </xsl:choose>

          </xsl:variable>

          <xsl:variable name=""counter1"" select=""concat($from, ' to ', $to)""/>

          <xsl:value-of select=""KeyList:AddToCounter($guid1, $counter1)""/>

          <xsl:variable name=""referenceCheck"">
            <xsl:for-each select=""s0:NADLoop2/s0:NAD_3[NAD01='CZ']"">
              <xsl:if test=""not(normalize-space(../s0:RFFLoop4/s0:RFF_5/s0:C506_5[C50601='CU']/C50602)='')"">
                <xsl:value-of select=""../s0:RFFLoop4/s0:RFF_5/s0:C506_5[C50601='CU']/C50602""/>
                <xsl:text> / </xsl:text>
              </xsl:if>
            </xsl:for-each>
            <xsl:value-of select=""s0:CNI/s0:C503_3/C50301""/>
          </xsl:variable>

          <xsl:variable name=""checkResult"">
            <xsl:value-of select=""Bosman:CheckReference($referenceCheck)""/>
          </xsl:variable>

          <xsl:value-of select=""KeyList:AddToCounter($guid2, $checkResult)""/>

        </xsl:for-each>
      </xsl:variable>

      <xsl:variable name=""orderReference"" select=""concat('Bosman shipment(s): ', KeyList:ListCountersAsString($guid1), '(', KeyList:ListCountersAsString($guid2), ')')""/>

      <Sender>
        <xsl:value-of select=""$sender"" />
      </Sender>
      <Receiver>
        <xsl:value-of select=""$receiver"" />
      </Receiver>
      <GroupName>ORCHESTRATION</GroupName>

      <Consolidation>
        <xsl:choose>
          <xsl:when test=""$receiver = 'KLGEUEERSE01'"">YES</xsl:when>
          <xsl:otherwise>NO</xsl:otherwise>
        </xsl:choose>
      </Consolidation>

      <Reference>
        <xsl:value-of select=""$orderReference""/>
      </Reference>
      <TimeStamp>
        <xsl:value-of select=""DateTime:GetCurrentDateTime()"" />
      </TimeStamp>
      <Status>NEW</Status>
      <Date>
        <xsl:value-of select=""$orderDate"" />
      </Date>

      <xsl:apply-templates select=""./s0:CNILoop1"" />

    </ns0:Order>
  </xsl:template>

  <xsl:template match=""s0:CNILoop1"">

    <Shipment>

      <!-- region loadingDate loadingDateTimeFrom loadingDateTimeTo -->
      <xsl:variable name=""loadingDate200"">
        <xsl:choose>
          <xsl:when test=""s0:DTM_7/s0:C507_7[C50701 = '200']/C50702 and '0001-01-01' != DateTime:FormatDateTime(substring(s0:DTM_7/s0:C507_7[C50701 = '200']/C50702, 1, 8), 'yyyyMMdd', 'yyyy-MM-dd', 'TM.BOSMAN.IFCSUM_to_TM.Shared.Order: loadingDate200 TEST')"">
            <xsl:value-of select=""DateTime:FormatDateTime(substring(s0:DTM_7/s0:C507_7[C50701 = '200']/C50702, 1, 8), 'yyyyMMdd', 'yyyy-MM-dd', 'TM.BOSMAN.IFCSUM_to_TM.Shared.Order: loadingDate200')"" />
          </xsl:when>
          <xsl:otherwise>
            <xsl:value-of select=""DateTime:GetWorkday($orderDate, 0, 'NL')""/>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:variable>

      <xsl:variable name=""loadingDate200TimeFrom"">
        <xsl:choose>
          <xsl:when test=""$receiver = 'KLGEUEERSE01'"">
            <xsl:value-of select=""$loadingDate200"" />
          </xsl:when>
          <xsl:when test=""$receiver = 'KLGEUVENLO01'"">
            <xsl:value-of select=""concat($loadingDate200, 'T08:00:00')"" />
          </xsl:when>
        </xsl:choose>
      </xsl:variable>

      <xsl:variable name=""loadingDate200TimeTo"">
        <xsl:choose>
          <xsl:when test=""$receiver = 'KLGEUEERSE01'"">
            <xsl:value-of select=""$loadingDate200"" />
          </xsl:when>
          <xsl:when test=""$receiver = 'KLGEUVENLO01'"">
            <xsl:value-of select=""concat($loadingDate200, 'T16:00:00')"" />
          </xsl:when>
        </xsl:choose>
      </xsl:variable>
      <!-- end region -->

      <!--<debug>
        <xpath>
          <xsl:value-of select=""substring(s0:DTM_7/s0:C507_7[C50701 = '200']/C50702, 1, 8)""/>
        </xpath>
        <loadingDate200>
          <xsl:value-of select=""$loadingDate200""/>
        </loadingDate200>
      </debug>-->      
      
      <xsl:variable name=""ftl"">
        <xsl:choose>
          <xsl:when test=""number(./s0:CNT_2/s0:C270_2[C27001 = '34']/C27002) = 13.6"">true</xsl:when>
          <xsl:otherwise>false</xsl:otherwise>
        </xsl:choose>
      </xsl:variable>

      <!-- region collectionReference -->
      <xsl:variable name=""collectionReference"">
        <xsl:for-each select=""s0:NADLoop2/s0:NAD_3[NAD01 = 'PW']"">
          <xsl:if test=""not (normalize-space(../s0:RFFLoop4/s0:RFF_5/s0:C506_5[C50601 = 'AAK']/C50602) = '')"">
            <xsl:value-of select=""../s0:RFFLoop4/s0:RFF_5/s0:C506_5[C50601 = 'AAK']/C50602""/>
          </xsl:if>
        </xsl:for-each>
        <xsl:text>|</xsl:text>
        <xsl:for-each select=""s0:NADLoop2/s0:NAD_3[NAD01 = 'CZ']"">
          <xsl:if test=""not (normalize-space(../s0:RFFLoop4/s0:RFF_5/s0:C506_5[C50601 = 'CU']/C50602) = '')"">
            <xsl:value-of select=""../s0:RFFLoop4/s0:RFF_5/s0:C506_5[C50601 = 'CU']/C50602""/>
          </xsl:if>
        </xsl:for-each>
      </xsl:variable>
      <!-- end region -->

      <!-- region deliveryReference-->
      <xsl:variable name=""deliveryReference"">
        <xsl:choose>
          <xsl:when test=""not (normalize-space(s0:NADLoop2[s0:NAD_3/NAD01 = 'DP']/s0:RFFLoop4/s0:RFF_5/s0:C506_5[C50601 = 'AAJ']/C50602) = '')"">
            <xsl:for-each select=""s0:NADLoop2/s0:NAD_3[NAD01 = 'DP']"">
              <xsl:if test=""not (normalize-space(../s0:RFFLoop4/s0:RFF_5/s0:C506_5[C50601 = 'AAJ']/C50602) = '')"">
                <xsl:value-of select=""../s0:RFFLoop4/s0:RFF_5/s0:C506_5[C50601 = 'AAJ']/C50602""/>
              </xsl:if>
            </xsl:for-each>
          </xsl:when>
          <xsl:otherwise>
            <xsl:for-each select=""s0:NADLoop2/s0:NAD_3[NAD01 = 'CN']"">
              <xsl:if test=""not (normalize-space(../s0:RFFLoop4/s0:RFF_5/s0:C506_5[C50601 = 'AAO']/C50602) = '')"">
                <xsl:value-of select=""../s0:RFFLoop4/s0:RFF_5/s0:C506_5[C50601 = 'AAO']/C50602""/>
              </xsl:if>
            </xsl:for-each>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:variable>
      <!-- end region -->

      <!-- region deliveryDate deliveryDateTimeFrom deliveryDateTimeTo   AND   Check CNILoop for existence of a usable DTM_7 segment -->
      <xsl:variable name=""deliveryDate"">
        <xsl:choose>
          <xsl:when test=""./s0:DTM_7/s0:C507_7[C50701='2']"">
            <xsl:choose>
              <xsl:when test=""./s0:DTM_7/s0:C507_7[C50701='2']/C50703='102'"">
                <xsl:value-of select=""DateTime:FormatDateTime(./s0:DTM_7/s0:C507_7[C50701='2']/C50702, 'yyyyMMdd', 'yyyy-MM-dd', 'TM.BOSMAN.IFCSUM_to_TM.Shared.Order: deliveryDate::2:102')""/>
              </xsl:when>
              <xsl:when test=""./s0:DTM_7/s0:C507_7[C50701='2']/C50703='203'"">
                <xsl:value-of select=""DateTime:FormatDateTime(./s0:DTM_7/s0:C507_7[C50701='2']/C50702, 'yyyyMMddHHmm', 'yyyy-MM-dd', 'TM.BOSMAN.IFCSUM_to_TM.Shared.Order: deliveryDate::2:203')""/>
              </xsl:when>
              <xsl:otherwise>
                <xsl:value-of select=""DateTime:FormatDateTime(./s0:DTM_7/s0:C507_7[C50701='2']/C50702, 'yyyyMMdd', 'yyyy-MM-dd', 'TM.BOSMAN.IFCSUM_to_TM.Shared.Order: deliveryDate::2')""/>
              </xsl:otherwise>
            </xsl:choose>
          </xsl:when>
          <xsl:when test=""./s0:DTM_7/s0:C507_7[C50701='64']"">
            <xsl:choose>
              <xsl:when test=""./s0:DTM_7/s0:C507_7[C50701='64']/C50703='102'"">
                <xsl:value-of select=""DateTime:FormatDateTime(./s0:DTM_7/s0:C507_7[C50701='64']/C50702, 'yyyyMMdd', 'yyyy-MM-dd', 'TM.BOSMAN.IFCSUM_to_TM.Shared.Order: deliveryDate::64:102')""/>
              </xsl:when>
              <xsl:when test=""./s0:DTM_7/s0:C507_7[C50701='64']/C50703='203'"">
                <xsl:value-of select=""DateTime:FormatDateTime(./s0:DTM_7/s0:C507_7[C50701='64']/C50702, 'yyyyMMddHHmm', 'yyyy-MM-dd', 'TM.BOSMAN.IFCSUM_to_TM.Shared.Order: deliveryDate::64:203')""/>
              </xsl:when>
              <xsl:otherwise>
                <xsl:value-of select=""DateTime:FormatDateTime(./s0:DTM_7/s0:C507_7[C50701='64']/C50702, 'yyyyMMdd', 'yyyy-MM-dd', 'TM.BOSMAN.IFCSUM_to_TM.Shared.Order: deliveryDate::64')""/>
              </xsl:otherwise>
            </xsl:choose>
          </xsl:when>
          <xsl:otherwise>
            <xsl:value-of select=""Biztalk:SendErrorMessage('TM.Bosman.IFCSUM_to_TM.Shared.Order', concat('CNILoop ', ./s0:CNI/CNI01, ' is missing either a DTM_7 segment completely OR a DTM_7 segment with either a C50701=2 or C50701=64'), 'the DTM_7 segment needs to be present and needs to contain either a C50701=2 or C50701=64 segment', concat('Retrieve the original Bosman message with reference: ', $BosmanReference, ' and e-mail it to Bosman with explanation to update the message and resend it'))""/>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:variable>

      <xsl:variable name=""deliveryDateTimeFrom"">
        <xsl:choose>
          <xsl:when test=""$receiver = 'KLGEUEERSE01'"">
            <xsl:value-of select=""concat($deliveryDate, 'T00:00:00')"" />
          </xsl:when>
          <xsl:when test=""$receiver = 'KLGEUVENLO01'"">
            <xsl:value-of select=""concat($deliveryDate, 'T08:00:00')"" />
          </xsl:when>
        </xsl:choose>
      </xsl:variable>

      <xsl:variable name=""deliveryDateTimeTo"">
        <xsl:choose>
          <xsl:when test=""$receiver = 'KLGEUEERSE01'"">
            <xsl:value-of select=""concat($deliveryDate, 'T00:00:00')"" />
            <!--<xsl:value-of select=""concat($deliveryDate, 'T23:59:59')"" />-->
          </xsl:when>
          <xsl:when test=""$receiver = 'KLGEUVENLO01'"">
            <xsl:value-of select=""concat($deliveryDate, 'T16:00:00')"" />
          </xsl:when>
        </xsl:choose>
      </xsl:variable>
      <!-- end region-->

      <Consignor>
        <xsl:value-of select=""$sender"" />
      </Consignor>
      <ConsignorReference>
        <xsl:if test=""$receiver = 'KLGEUVENLO01'"">
          <xsl:for-each select=""s0:NADLoop2/s0:NAD_3[NAD01='CZ']"">
            <xsl:if test=""not(normalize-space(../s0:RFFLoop4/s0:RFF_5/s0:C506_5[C50601='CU']/C50602)='')"">
              <xsl:value-of select=""../s0:RFFLoop4/s0:RFF_5/s0:C506_5[C50601='CU']/C50602""/>
              <xsl:text> / </xsl:text>
            </xsl:if>
          </xsl:for-each>
        </xsl:if>
        <xsl:value-of select=""s0:CNI/s0:C503_3/C50301""/>
      </ConsignorReference>
      <Debtor>
        <xsl:value-of select=""$sender"" />
      </Debtor>
      <DebtorReference>
        <xsl:if test=""$receiver = 'KLGEUVENLO01'"">
          <xsl:for-each select=""s0:NADLoop2/s0:NAD_3[NAD01='CZ']"">
            <xsl:if test=""not(normalize-space(../s0:RFFLoop4/s0:RFF_5/s0:C506_5[C50601='CU']/C50602)='')"">
              <xsl:value-of select=""../s0:RFFLoop4/s0:RFF_5/s0:C506_5[C50601='CU']/C50602""/>
              <xsl:text> / </xsl:text>
            </xsl:if>
          </xsl:for-each>
        </xsl:if>
        <xsl:value-of select=""s0:CNI/s0:C503_3/C50301""/>
      </DebtorReference>
      <Incoterm>
        <xsl:value-of select=""s0:TODLoop1/s0:TOD[TOD01 = '6']/s0:C100/C10001""/>
      </Incoterm>
      <IncotermCity>
        <!-- Zonder bij behorende landcode geeft city in Ixolution een probleem -->
        <!--<xsl:value-of select=""s0:TODLoop1/s0:LOC_7[LOC01 = '1']/s0:C517_7/C51704/text()""/>-->
      </IncotermCity>
      <IncotermCountryCode />

      <Parametergroup>
        <Groupname/>
        <Parameter>
          <!-- TIJDELIJKE OPLOSSING! Uiteindelijk moeten IxSuite business rules de juiste waarde bepalen! -->
          <!-- NB In de mapping naar StandardBusinessDocumen wordt scenario alleen voor Venlo ingevuld. -->
          <Qualifier>Scenario</Qualifier>
          <Value>21</Value>
        </Parameter>
      </Parametergroup>

      <!-- region SF Address & ContactPerson -->
      <Address>

        <xsl:variable name=""PCI_identification"">
          <xsl:choose>
            <xsl:when test=""$receiver = 'KLGEUVENLO01'"">
              <!--unieke labels per shipment"">-->
              <xsl:for-each select=""s0:GIDLoop1/s0:PCILoop1/s0:PCI/s0:C210/C21001/text()[generate-id()
                                       = generate-id(key('kLabel',.)[1])]"">
                <xsl:sort select =""."" data-type=""text""/>
                <xsl:choose>
                  <xsl:when test=""position() = last()"">
                    <xsl:value-of select ="".""></xsl:value-of>
                  </xsl:when>
                  <xsl:otherwise>
                    <xsl:value-of select =""concat(., ', ')""></xsl:value-of>
                  </xsl:otherwise>
                </xsl:choose>
              </xsl:for-each>

            </xsl:when>
            <xsl:otherwise>
              <xsl:text></xsl:text>
            </xsl:otherwise>
          </xsl:choose>
        </xsl:variable>

        <xsl:choose>
          <xsl:when test=""count(s0:NADLoop2[s0:NAD_3/NAD01 = 'PW']) &gt; 0"">
            <xsl:for-each select=""s0:NADLoop2[s0:NAD_3/NAD01 = 'PW']"">
              <xsl:call-template name=""NADtoSF"">
                <xsl:with-param name=""loadingDate200TimeFrom"" select=""$loadingDate200TimeFrom"" />
                <xsl:with-param name=""loadingDate200TimeTo"" select=""$loadingDate200TimeTo""/>
                <xsl:with-param name=""collectionReference"" select=""$collectionReference""/>
                <xsl:with-param name=""internalRemark1"" select=""$PCI_identification""/>
              </xsl:call-template>
            </xsl:for-each>
          </xsl:when>
          <xsl:otherwise>
            <xsl:for-each select=""s0:NADLoop2[s0:NAD_3/NAD01 = 'CZ']"">
              <xsl:call-template name=""NADtoSF"">
                <xsl:with-param name=""loadingDate200TimeFrom"" select=""$loadingDate200TimeFrom"" />
                <xsl:with-param name=""loadingDate200TimeTo"" select=""$loadingDate200TimeTo""/>
                <xsl:with-param name=""collectionReference"" select=""$collectionReference""/>
                <xsl:with-param name=""internalRemark1"" select=""$PCI_identification""/>
              </xsl:call-template>
            </xsl:for-each>
          </xsl:otherwise>
        </xsl:choose>
      </Address>

      <!-- end region-->

      <!-- region ST Address & ContactPerson -->
      <Address>


        <xsl:choose>
          <xsl:when test=""count(s0:NADLoop2[s0:NAD_3/NAD01 = 'DP']) &gt; 0"">
            <xsl:for-each select=""s0:NADLoop2[s0:NAD_3/NAD01 = 'DP']"">
              <xsl:call-template name=""NADtoST"">
                <xsl:with-param name=""deliveryDateTimeFrom"" select=""$deliveryDateTimeFrom"" />
                <xsl:with-param name=""deliveryDateTimeTo"" select=""$deliveryDateTimeTo""/>
                <xsl:with-param name=""deliveryReference"" select=""$deliveryReference""/>
                <xsl:with-param name=""NAD01"" select=""'DP'""/>
              </xsl:call-template>
            </xsl:for-each>
          </xsl:when>
          <xsl:otherwise>
            <xsl:for-each select=""s0:NADLoop2[s0:NAD_3/NAD01 = 'CN']"">
              <xsl:call-template name=""NADtoST"">
                <xsl:with-param name=""deliveryDateTimeFrom"" select=""$deliveryDateTimeFrom"" />
                <xsl:with-param name=""deliveryDateTimeTo"" select=""$deliveryDateTimeTo""/>
                <xsl:with-param name=""deliveryReference"" select=""$deliveryReference""/>
                <xsl:with-param name=""NAD01"" select=""'CN'""/>
              </xsl:call-template>
            </xsl:for-each>
          </xsl:otherwise>
        </xsl:choose>
        <xsl:value-of select=""../s0:GIDLoop1[1]/s0:PCILoop1/s0:PCI/s0:C210/C21001""/>
        <xsl:if test=""$receiver = 'KLGEUVENLO01'"">
          <xsl:call-template name=""Feature"">
            <xsl:with-param name=""featureCode"" select = ""'DATE_FIXED'"" />
            <xsl:with-param name=""additionalValue"" select = ""''"" />
            <!-- $deliveryDate -->
          </xsl:call-template>
        </xsl:if>

      </Address>
      <!-- end region-->

      <!-- region Good and DengerousGood -->
      <!-- Voor Venlo moeten goederenregels gesplitst worden op de combinatie van packing en Deliveryreference Voor Eersel alleen op packing -->
      <xsl:choose>
        <xsl:when test=""$receiver = 'KLGEUEERSE01'"">
          <xsl:for-each select=""s0:GIDLoop1[generate-id() = generate-id(key('kGoodsEersel', concat(generate-id(..), '|', s0:GID/s0:C213/C21302, '|'))[1])]"">
            <!-- de EERSTE GIDLoop1 met PackingType als key  -->
            <xsl:call-template name=""Good"">
              <xsl:with-param name=""ftl"" select=""$ftl""/>
              <xsl:with-param name=""key"" select=""'kGoodsEersel'""/>
              <xsl:with-param name=""keyDeliveryRef"" select=""''""/>
            </xsl:call-template>
          </xsl:for-each>
        </xsl:when>
        <xsl:when test=""$receiver = 'KLGEUVENLO01'"">
          <xsl:for-each select=""s0:GIDLoop1[generate-id() = generate-id(key('kGoodsVenlo', concat(generate-id(..), '|', s0:GID/s0:C213/C21302, '|', s0:PCILoop1/s0:PCI/s0:C210/C21001 ))[1])]"">
            <!-- de EERSTE GIDLoop1 met PackingType en Deliveryreference als key   -->
            <xsl:call-template name=""Good"">
              <xsl:with-param name=""ftl"" select=""$ftl""/>
              <xsl:with-param name=""key"" select=""'kGoodsVenlo'""/>
              <xsl:with-param name=""keyDeliveryRef"" select=""s0:PCILoop1/s0:PCI/s0:C210/C21001""/>
            </xsl:call-template>
          </xsl:for-each>
        </xsl:when>
      </xsl:choose>

      <!-- end region -->

    </Shipment>
  </xsl:template>

  <xsl:template name=""NADtoSF"">
    <xsl:param name=""loadingDate200TimeFrom""/>
    <xsl:param name=""loadingDate200TimeTo""/>
    <xsl:param name=""collectionReference""/>
    <xsl:param name=""internalRemark1""/>
    <xsl:for-each select=""s0:NAD_3"">

      <xsl:variable name=""Remarks"">
        <xsl:for-each select=""../../s0:FTX_5[FTX01 = 'AAI']/s0:C108_5"">
          <xsl:if test=""not(contains(C10801, 'AFLEVERDATUM'))"">
            <xsl:if test=""not(contains(C10801, 'GE-UPDATED'))"">
              <xsl:value-of select=""C10801""/>
              <xsl:text>, </xsl:text>
            </xsl:if>
          </xsl:if>
        </xsl:for-each>
      </xsl:variable>

      <xsl:call-template name=""Address"">
        <xsl:with-param name=""addressType"" select = ""'SF'"" />
        <xsl:with-param name=""name1"" select = ""s0:C080_3[1]/C08001"" />
        <xsl:with-param name=""name2"" select = ""s0:C080_3[2]/C08001"" />
        <xsl:with-param name=""address1"" select = ""s0:C059_3[1]/C05901"" />
        <xsl:with-param name=""address2"" select = ""s0:C059_3[2]/C05901"" />
        <xsl:with-param name=""postalCode"" select = ""NAD08"" />
        <xsl:with-param name=""city"" select = ""NAD06"" />
        <xsl:with-param name=""region"" select = ""NAD07"" />
        <xsl:with-param name=""countryCode"" select = ""NAD09"" />
        <xsl:with-param name=""start"" select = ""$loadingDate200TimeFrom"" />
        <xsl:with-param name=""end"" select = ""$loadingDate200TimeTo"" />
        <xsl:with-param name=""reference"" select = ""$collectionReference"" />
        <xsl:with-param name=""externalRemark1"" select = ""$Remarks"" />
        <xsl:with-param name=""externalRemark2"" select = ""''"" />
        <xsl:with-param name=""internalRemark1"" select = ""$internalRemark1"" />
        <xsl:with-param name=""internalRemark2"" select = ""$Remarks"" />
      </xsl:call-template>
      <xsl:for-each select=""../s0:CTALoop3[s0:CTA_4/CTA01 = 'IC']"">
        <xsl:call-template name=""ContactPerson"">
          <xsl:with-param name=""name"" select = ""s0:CTA_4/s0:C056_4/C05602"" />
          <xsl:with-param name=""phone"" select = ""s0:COM_4/s0:C076_4[C07602 = 'TE']/C07601"" />
          <xsl:with-param name=""fax"" select = ""s0:COM_4/s0:C076_4[C07602 = 'FA']/C07601"" />
          <xsl:with-param name=""email"" select = ""s0:COM_4/s0:C076_4[C07602 = 'EM']/C07601"" />
        </xsl:call-template>
      </xsl:for-each>
    </xsl:for-each>
  </xsl:template>

  <xsl:template name=""NAD_ST_CN"">
    <xsl:for-each select=""../../s0:NADLoop2[s0:NAD_3/NAD01 = 'CN']/s0:NAD_3"">
      <xsl:text>CONSIGNEE: </xsl:text>
      <xsl:value-of select=""s0:C080_3[1]/C08001""/>
      <xsl:text> - </xsl:text>
      <xsl:value-of select=""NAD06""/>
      <xsl:text>, </xsl:text>
    </xsl:for-each>
  </xsl:template>

  <xsl:template name=""NADtoST"">
    <xsl:param name=""deliveryDateTimeFrom"" />
    <xsl:param name=""deliveryDateTimeTo"" />
    <xsl:param name=""deliveryReference"" />
    <xsl:param name=""NAD01"" />

    <xsl:for-each select=""s0:NAD_3"">

      <xsl:variable name=""Remarks"">
        <xsl:if test=""$NAD01 = 'DP'"">
          <xsl:call-template name=""NAD_ST_CN""/>
        </xsl:if>
        <xsl:for-each select=""../../s0:FTX_5[FTX01 = 'DEL']/s0:C108_5"">
          <xsl:value-of select=""C10801""/>
          <xsl:text>, </xsl:text>
        </xsl:for-each>
      </xsl:variable>

      <xsl:variable name=""countryCode"">
        <xsl:choose>
          <xsl:when test=""translate(substring(NAD08, 1, 2), $lowerCase, $upperCase) = 'BT'"">IE</xsl:when>
          <xsl:otherwise>
            <xsl:value-of select=""NAD09""/>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:variable>

      <xsl:call-template name=""Address"">
        <xsl:with-param name=""addressType"" select = ""'ST'"" />
        <xsl:with-param name=""name1"" select = ""s0:C080_3[1]/C08001"" />
        <xsl:with-param name=""name2"" select = ""s0:C080_3[2]/C08001"" />
        <xsl:with-param name=""address1"" select = ""s0:C059_3[1]/C05901"" />
        <xsl:with-param name=""address2"" select = ""s0:C059_3[2]/C05901"" />
        <xsl:with-param name=""postalCode"" select = ""NAD08"" />
        <xsl:with-param name=""city"" select = ""NAD06"" />
        <xsl:with-param name=""region"" select = ""NAD07"" />
        <xsl:with-param name=""countryCode"" select = ""$countryCode"" />
        <xsl:with-param name=""start"" select = ""$deliveryDateTimeFrom"" />
        <xsl:with-param name=""end"" select = ""$deliveryDateTimeTo"" />
        <xsl:with-param name=""reference"" select = ""$deliveryReference"" />
        <xsl:with-param name=""externalRemark1"" select = ""$Remarks"" />
        <xsl:with-param name=""externalRemark2"" select = ""''"" />
        <xsl:with-param name=""internalRemark1"" select = ""''"" />
        <xsl:with-param name=""internalRemark2"" select = ""''"" />
      </xsl:call-template>
      <xsl:for-each select=""../s0:CTALoop3[s0:CTA_4/CTA01 = 'IC']"">
        <xsl:call-template name=""ContactPerson"">
          <xsl:with-param name=""name"" select = ""s0:CTA_4/s0:C056_4/C05602"" />
          <xsl:with-param name=""phone"" select = ""s0:COM_4/s0:C076_4[C07602 = 'TE']/C07601"" />
          <xsl:with-param name=""fax"" select = ""s0:COM_4/s0:C076_4[C07602 = 'FA']/C07601"" />
          <xsl:with-param name=""email"" select = ""s0:COM_4/s0:C076_4[C07602 = 'EM']/C07601"" />
        </xsl:call-template>
      </xsl:for-each>
    </xsl:for-each>
  </xsl:template>

  <xsl:template name=""Address"">
    <xsl:param name=""addressType"" />
    <xsl:param name=""name1"" />
    <xsl:param name=""name2"" />
    <xsl:param name=""address1"" />
    <xsl:param name=""address2"" />
    <xsl:param name=""postalCode"" />
    <xsl:param name=""city"" />
    <xsl:param name=""region"" />
    <xsl:param name=""countryCode"" />
    <xsl:param name=""start"" />
    <xsl:param name=""end"" />
    <xsl:param name=""reference"" />
    <xsl:param name=""externalRemark1"" />
    <xsl:param name=""externalRemark2"" />
    <xsl:param name=""internalRemark1"" />
    <xsl:param name=""internalRemark2"" />
    <AddressType>
      <xsl:value-of select=""$addressType"" />
    </AddressType>
    <Name1>
      <xsl:value-of select=""$name1"" />
    </Name1>
    <Name2>
      <xsl:value-of select=""$name2"" />
    </Name2>
    <Address1>
      <xsl:value-of select=""$address1"" />
    </Address1>
    <Address2>
      <xsl:value-of select=""$address2"" />
    </Address2>
    <PostalCode>
      <xsl:value-of select=""$postalCode"" />
    </PostalCode>
    <City>
      <xsl:value-of select=""$city"" />
    </City>
    <Region>
      <xsl:value-of select=""$region"" />
    </Region>
    <CountryCode>
      <xsl:value-of select=""$countryCode"" />
    </CountryCode>
    <Start>
      <xsl:value-of select=""$start"" />
    </Start>
    <End>
      <xsl:value-of select=""$end"" />
    </End>
    <Reference>
      <xsl:value-of select=""$reference"" />
    </Reference>
    <ExternalRemark1>
      <xsl:value-of select=""$externalRemark1"" />
    </ExternalRemark1>
    <ExternalRemark2>
      <xsl:value-of select=""$externalRemark2"" />
    </ExternalRemark2>
    <InternalRemark1>
      <xsl:value-of select=""$internalRemark1"" />
    </InternalRemark1>
    <InternalRemark2>
      <xsl:value-of select=""$internalRemark2"" />
    </InternalRemark2>
  </xsl:template>

  <xsl:template name=""ContactPerson"">
    <xsl:param name=""name"" />
    <xsl:param name=""phone"" />
    <xsl:param name=""fax"" />
    <xsl:param name=""email"" />
    <ContactPerson>
      <Name>
        <xsl:value-of select=""$name"" />
      </Name>
      <Phone>
        <xsl:value-of select=""$phone"" />
      </Phone>
      <Fax>
        <xsl:value-of select=""$fax"" />
      </Fax>
      <Email>
        <xsl:value-of select=""$email"" />
      </Email>
    </ContactPerson>
  </xsl:template>

  <xsl:template name=""Parameter"">
    <xsl:param name=""qualifier"" />
    <xsl:param name=""value"" />
    <xsl:param name=""additionalValue"" />
    <Parameter>
      <Qualifier>
        <xsl:value-of select=""$qualifier"" />
      </Qualifier>
      <Value>
        <xsl:value-of select=""$value"" />
      </Value>
      <AdditionalValue>
        <xsl:value-of select=""$additionalValue"" />
      </AdditionalValue>
    </Parameter>
  </xsl:template>

  <xsl:template name=""Feature"">
    <xsl:param name=""featureCode"" />
    <xsl:param name=""additionalValue"" />
    <Feature>
      <FeatureCode>
        <xsl:value-of select=""$featureCode"" />
      </FeatureCode>
      <AdditionalValue>
        <xsl:value-of select=""$additionalValue"" />
      </AdditionalValue>
    </Feature>
  </xsl:template>

  <xsl:template name=""Good"">
    <xsl:param name=""ftl""/>
    <xsl:param name=""key""/>
    <xsl:param name=""keyDeliveryRef""/>

    <Good>

      <!--<DEBUG>
        <ftl>
          <xsl:value-of select=""$ftl""/>
        </ftl>
        <key>
          <xsl:value-of select=""$key""/>
        </key>
        <keyDelRef>
          <xsl:value-of select=""$keyDeliveryRef""/>
        </keyDelRef>
      </DEBUG>-->

      <xsl:variable name=""packingQty"">
        <xsl:value-of select=""sum(key($key, concat(generate-id(..), '|', s0:GID/s0:C213/C21302, '|', $keyDeliveryRef))/s0:GID/s0:C213/C21301)""/>
      </xsl:variable>

      <xsl:variable name=""C21302"">
        <xsl:value-of select=""s0:GID/s0:C213/C21302"" />
      </xsl:variable>


      <xsl:variable name=""packingType"">
        <xsl:value-of select=""ScriptNS0:DBValueExtract(string(ScriptNS0:DBLookup(0, $C21302, $connectionString, 'TM_Bosman_Package', 'Bosman')), 'KLG')"" />
      </xsl:variable>

      <xsl:call-template name=""GoodsDetail"">
        <xsl:with-param name=""ftl"" select=""$ftl""/>
        <xsl:with-param name=""packingQty"" select=""$packingQty""/>
        <xsl:with-param name=""packingType"" select=""$packingType""/>
        <xsl:with-param name=""key"" select=""$key""/>
        <xsl:with-param name=""keyDeliveryRef"" select=""$keyDeliveryRef""/>
      </xsl:call-template>

      <!--<DEBUG>
        <xsl:variable name=""cni"" select=""'1012022000334589'""/>
        <receiver>
          <xsl:value-of select=""$receiver""/>
        </receiver>
        <xpath>
        <xsl:choose>
          <xsl:when test=""$receiver = 'KLGEUEERSE01'"">
            <xsl:text>/ns0:EFACT_D96A_IFCSUM_BOSMAN/ns0:CNILoop1[ns0:CNI/ns0:C503_3/C50301='</xsl:text>
            <xsl:value-of select=""$cni""/>
            <xsl:text>']/ns0:GIDLoop1[ns0:GID/ns0:C213/C21302='</xsl:text>
            <xsl:value-of select=""$C21302""/>
            <xsl:text>']/ns0:DGSLoop1</xsl:text>
          </xsl:when>
          <xsl:when test=""$receiver = 'KLGEUVENLO01'"">
            <xsl:text>/ns0:EFACT_D96A_IFCSUM_BOSMAN/ns0:CNILoop1[ns0:CNI/ns0:C503_3/C50301='</xsl:text>
            <xsl:value-of select=""$cni""/>
            <xsl:text>']/ns0:GIDLoop1[ns0:GID/ns0:C213/C21302='</xsl:text>
            <xsl:value-of select=""$C21302""/>
            <xsl:text>'][ns0:PCILoop1/ns0:PCI/ns0:C210/C21001='</xsl:text>
            <xsl:value-of select=""$keyDeliveryRef""/>
            <xsl:text>']/ns0:DGSLoop1</xsl:text>
          </xsl:when>
        </xsl:choose>
        </xpath>
      </DEBUG>-->

      <xsl:choose>
        <xsl:when test=""$receiver = 'KLGEUEERSE01'"">
          <xsl:for-each select=""../s0:GIDLoop1[s0:GID/s0:C213/C21302/text()=$C21302]/s0:DGSLoop1"">
            <DangerousGood>
              <xsl:call-template name=""DangerousGood"">
                <xsl:with-param name=""packingQty"" select=""$packingQty""/>
                <xsl:with-param name=""packingType"" select=""$packingType""/>
              </xsl:call-template>
              <xsl:for-each select=""s0:FTX_11[FTX01 = 'AAD']"">
                <xsl:call-template name=""LocalizedDescription""/>
              </xsl:for-each>
            </DangerousGood>
          </xsl:for-each>
        </xsl:when>
        <xsl:when test=""$receiver = 'KLGEUVENLO01'"">
          <xsl:for-each select=""../s0:GIDLoop1[s0:GID/s0:C213/C21302=$C21302][s0:PCILoop1/s0:PCI/s0:C210/C21001=$keyDeliveryRef]/s0:DGSLoop1"">
            <DangerousGood>
              <xsl:call-template name=""DangerousGood"">
                <xsl:with-param name=""packingQty"" select=""$packingQty""/>
                <xsl:with-param name=""packingType"" select=""$packingType""/>
              </xsl:call-template>
              <xsl:for-each select=""s0:FTX_11[FTX01 = 'AAD']"">
                <xsl:call-template name=""LocalizedDescription""/>
              </xsl:for-each>
            </DangerousGood>
          </xsl:for-each>
        </xsl:when>
      </xsl:choose>

      <xsl:variable name=""C21001"">
        <xsl:value-of select=""s0:PCILoop1/s0:PCI/s0:C210/C21001""/>
      </xsl:variable>

      <!--Barcodes overnemen (SD-7882) NOG ALTIJD NIET LIVE / TERUGGEDRAAID-->
      <!--<xsl:for-each select=""//s0:PCILoop1[s0:PCI/s0:C210/C21001/text()=$C21001]/s0:GIN/*/C20801"">
        <Barcode>
          <Barcode>
            <xsl:value-of select=""text()""/>
          </Barcode>
        </Barcode>
      </xsl:for-each>-->

    </Good>

  </xsl:template>

  <xsl:template name=""GoodsDetail"">
    <xsl:param name=""ftl""/>
    <xsl:param name=""packingQty""/>
    <xsl:param name=""packingType""/>
    <xsl:param name=""key""/>
    <xsl:param name=""keyDeliveryRef""/>

    <PackingQty>
      <xsl:value-of select=""$packingQty""/>
    </PackingQty>
    <PackingType>
      <xsl:value-of select=""$packingType""/>
    </PackingType>
    <PackageQty>
      <xsl:value-of select=""sum(key($key, concat(generate-id(..), '|', s0:GID/s0:C213/C21302, '|', $keyDeliveryRef))/s0:GID/s0:C213_2/C21301)"" />
    </PackageQty>
    <PackageType>
      <xsl:value-of select=""ScriptNS0:DBValueExtract(string(ScriptNS0:DBLookup(0, s0:GID/s0:C213_2/C21302, $connectionString, 'TM_Bosman_Package', 'Bosman')), 'KLG')"" />
    </PackageType>
    <ProductDescription>
      <xsl:choose>
        <xsl:when test=""$receiver = 'KLGEUEERSE01'"">
          <xsl:value-of select=""s0:FTX_9[FTX01 = 'AAA']/s0:C108_9/C10801""/>
        </xsl:when>
        <xsl:when test=""$receiver = 'KLGEUVENLO01'"">
          <xsl:value-of select=""concat(s0:FTX_9[FTX01 = 'AAA']/s0:C108_9/C10801, ' | ', s0:PCILoop1/s0:PCI/s0:C210/C21001)""/>
        </xsl:when>
      </xsl:choose>
    </ProductDescription>
    <BrutoWeight>
      <xsl:value-of select=""format-number(sum(key($key, concat(generate-id(..), '|', s0:GID/s0:C213/C21302, '|', $keyDeliveryRef))/s0:MEALoop4/s0:MEA_5[MEA01 = 'WT']/s0:C174_5/C17402), '0.00')"" />
    </BrutoWeight>
    <LoadingMeter>
      <xsl:variable name=""loadingMeters"" select=""format-number(sum(key($key, concat(generate-id(..), '|', s0:GID/s0:C213/C21302, '|', $keyDeliveryRef))/s0:MEALoop4/s0:MEA_5[MEA01 = 'LMT']/s0:C174_5/C17402), '0.00')"" />
      <xsl:choose>
        <xsl:when test=""$ftl = 'true' and position() = 1"">13.6</xsl:when>
        <xsl:when test=""$ftl = 'true' and position() > 1"">0</xsl:when>
        <xsl:when test=""$loadingMeters > 13.6"">13.6</xsl:when>
        <xsl:otherwise>
          <xsl:value-of select=""$loadingMeters"" />
        </xsl:otherwise>
      </xsl:choose>
    </LoadingMeter>
    <Volume>
      <xsl:value-of select=""format-number(sum(key($key, concat(generate-id(..), '|', s0:GID/s0:C213/C21302, '|', $keyDeliveryRef ))/s0:MEALoop4/s0:MEA_5[MEA01 = 'VOL']/s0:C174_5/C17402), '0.00')"" />
    </Volume>
    <ContainerNumber>
      <xsl:value-of select=""./s0:CNT_2[/s0:C270_2/C27001 = '34']/s0:C270_2/C27002""></xsl:value-of>
    </ContainerNumber>
  </xsl:template>

  <xsl:template name=""DangerousGood"">
    <xsl:param name=""packingQty""/>
    <xsl:param name=""packingType""/>

    <xsl:variable name=""DGSpackingQty"">
      <xsl:value-of select=""s0:MEALoop7/s0:EQN_16/s0:C523_16/C52301""/>
    </xsl:variable>

    <xsl:variable name=""DGSpackingType"">
      <xsl:value-of select=""ScriptNS0:DBValueExtract(string(ScriptNS0:DBLookup(0, s0:FTX_11/s0:C108_11/C10801, $connectionString, 'TM_Bosman_Package', 'Bosman')), 'KLG')"" />
    </xsl:variable>

    <xsl:variable name=""nosTextGB"">
      <xsl:for-each select=""s0:FTX_11[FTX01 = 'NOS']"">
        <xsl:if test=""FTX05 = 'GB'"">
          <xsl:value-of select=""s0:C108_11/C10801"" />
        </xsl:if>
      </xsl:for-each>
    </xsl:variable>

    <UNNumber>
      <xsl:value-of select=""s0:DGS/s0:C234/C23401"" />
    </UNNumber>
    <Class>
      <xsl:value-of select=""s0:DGS/s0:C236/C23601"" />
    </Class>
    <SubClass1 />
    <SubClass2 />
    <SubClass3 />
    <Labels />
    <Qty>
      <!--<xsl:value-of select=""$packingQty""/>-->
      <xsl:value-of select=""$DGSpackingQty""/>
    </Qty>
    <Weight>
      <xsl:value-of select=""s0:MEALoop7/s0:MEA_8/s0:C174_8/C17402"" />
    </Weight>
    <PackageType>
      <!--<xsl:value-of select=""$packingType""/>-->
      <xsl:value-of select=""$DGSpackingType""/>
    </PackageType>
    <PackingGroup>
      <xsl:choose>
        <xsl:when test=""s0:DGS/DGS05 = ''"">0</xsl:when>
        <xsl:when test=""s0:DGS/DGS05 = '0'"">0</xsl:when>
        <xsl:when test=""s0:DGS/DGS05 = '1'"">I</xsl:when>
        <xsl:when test=""s0:DGS/DGS05 = '2'"">II</xsl:when>
        <xsl:when test=""s0:DGS/DGS05 = '3'"">III</xsl:when>
      </xsl:choose>
    </PackingGroup>
    <TransportCategory>
      <!--<xsl:value-of select=""name()"" />-->
      <xsl:value-of select=""s0:DGS/DGS12"" />
    </TransportCategory>
    <NOSText>
      <xsl:value-of select=""$nosTextGB""/>
    </NOSText>
    <TunnelRestrictionCode>
      <xsl:value-of select=""s0:FTX_11[FTX01 = 'AAC']/s0:C108_11/C10801"" />
    </TunnelRestrictionCode>

  </xsl:template>

  <xsl:template name=""LocalizedDescription"">
    <LocalizedDescription>
      <LanguageCode>
        <xsl:value-of select=""FTX05"" />
      </LanguageCode>
      <Description>
        <xsl:value-of select=""s0:C108_11/C10801"" />
      </Description>
    </LocalizedDescription>
  </xsl:template>

  <!-- end region -->

  <xsl:variable name=""removeDate1"" select=""KeyList:RemoveData($guid1)""/>
  <xsl:variable name=""removeDate2"" select=""KeyList:RemoveData($guid2)""/>
  <xsl:variable name=""dbClose"" select=""ScriptNS0:DBLookupShutdown()""/>

</xsl:stylesheet>";
        
        private const int _useXSLTransform = 0;
        
        private const string _strArgList = @"<ExtensionObjects>
  <ExtensionObject Namespace=""http://schemas.microsoft.com/BizTalk/2003/ScriptNS0"" 
                   AssemblyName=""Microsoft.BizTalk.BaseFunctoids, Version=3.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"" 
                   ClassName=""Microsoft.BizTalk.BaseFunctoids.FunctoidScripts"" />
  <ExtensionObject Namespace=""http://schemas.microsoft.com/BizTalk/2003/ScriptNS1"" 
                   AssemblyName=""Microsoft.BizTalk.CrossReferencing, Version=3.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"" 
                   ClassName=""Microsoft.BizTalk.CrossReferencing.CrossReferencing"" />

  <ExtensionObject Namespace=""TM.Shared.Components.Biztalk""
                   AssemblyName=""TM.Shared.Components, Version=3.0.37.0, Culture=neutral, PublicKeyToken=9cbf569b151cb1d4""
                   ClassName=""TM.Shared.Components.BiztalkFunctions"" />
  <ExtensionObject Namespace=""TM.Shared.Components.DateTime""
                   AssemblyName=""TM.Shared.Components, Version=3.0.37.0, Culture=neutral, PublicKeyToken=9cbf569b151cb1d4""
                   ClassName=""TM.Shared.Components.DateTimeFunctions"" />
  <ExtensionObject Namespace=""TM.Shared.Components.KeyList""
                   AssemblyName=""TM.Shared.Components, Version=3.0.37.0, Culture=neutral, PublicKeyToken=9cbf569b151cb1d4""
                   ClassName=""TM.Shared.Components.KeyListFunctions"" />
  <ExtensionObject Namespace=""TM.Shared.Components.SSO""
                   AssemblyName=""TM.Shared.Components, Version=3.0.37.0, Culture=neutral, PublicKeyToken=9cbf569b151cb1d4""
                   ClassName=""TM.Shared.Components.SSOFunctions"" />
  <ExtensionObject Namespace=""TM.Shared.Components.String""
                   AssemblyName=""TM.Shared.Components, Version=3.0.37.0, Culture=neutral, PublicKeyToken=9cbf569b151cb1d4""
                   ClassName=""TM.Shared.Components.StringFunctions"" />

  <ExtensionObject Namespace=""TM.Bosman.Components.MSsql""
                   AssemblyName=""TM.Bosman.Components, Version=3.0.0.0, Culture=neutral, PublicKeyToken=ef8f53020aeb0dca""
                   ClassName=""TM.Bosman.Components.MSsql"" />
  <ExtensionObject Namespace=""TM.Bosman.Components.Logging""
                   AssemblyName=""TM.Bosman.Components, Version=3.0.0.0, Culture=neutral, PublicKeyToken=ef8f53020aeb0dca""
                   ClassName=""TM.Bosman.Components.Logging"" />

</ExtensionObjects>";
        
        private const string _strSrcSchemasList0 = @"TM.Bosman.Schemas.EFACT_D96A_IFCSUM_BOSMAN";
        
        private const global::TM.Bosman.Schemas.EFACT_D96A_IFCSUM_BOSMAN _srcSchemaTypeReference0 = null;
        
        private const string _strTrgSchemasList0 = @"TM.Shared.Schemas.Order";
        
        private const global::TM.Shared.Schemas.Order _trgSchemaTypeReference0 = null;
        
        public override string XmlContent {
            get {
                return _strMap;
            }
        }
        
        public override int UseXSLTransform {
            get {
                return _useXSLTransform;
            }
        }
        
        public override string XsltArgumentListContent {
            get {
                return _strArgList;
            }
        }
        
        public override string[] SourceSchemas {
            get {
                string[] _SrcSchemas = new string [1];
                _SrcSchemas[0] = @"TM.Bosman.Schemas.EFACT_D96A_IFCSUM_BOSMAN";
                return _SrcSchemas;
            }
        }
        
        public override string[] TargetSchemas {
            get {
                string[] _TrgSchemas = new string [1];
                _TrgSchemas[0] = @"TM.Shared.Schemas.Order";
                return _TrgSchemas;
            }
        }
    }
}
