none
Error while test ASN856: 'xsl:template' cannot be a child of the 'ns0:X12_00501_856' RRS feed

  • Question

  • Hello,

    Any help appreciated! I spent couple of hours looking at this XSLT and searching on Google but stillan't see the issue.

    This is my XSLT script that gives me an error -'xsl:template' cannot be a child of the 'ns0:X12_00501_856'

    <xsl:template name="BuildFullASN">                  
    <xsl:for-each select="//Shipment">
       <xsl:element name = "HLLoop1">            
      <xsl:call-template name="BuildHL">
        <xsl:with-param name ="HL02" select=" '' "/>
        <xsl:with-param name ="HL03" select=" 'S' "/>
      </xsl:call-template>
     <xsl:element name="ns0:DTM_2">
       <xsl:element name="DTM01">11</xsl:element>
       <xsl:element name="DTM02">
      <xsl:value-of select="//ShipmentDate"/>
       </xsl:element>
        </xsl:element>
     </xsl:element>

     <!--Create HL loop for each Order-->
      <xsl:element name = "HLLoop1">
       <xsl:call-template name="BuildHL">
        <xsl:with-param name ="HL02" select=" 'S' "/>
        <xsl:with-param name ="HL03" select=" 'O' "/>
      </xsl:call-template>
       <xsl:element name="ns0:PRF">
        <xsl:element name="PRF01">
        <xsl:value-of select="./PONumber"/>
       </xsl:element>
      </xsl:element>
      </xsl:element>
     
     <!--Create HL loop for each Item-->
      <xsl:for-each select="./Item">
          <xsl:element name = "ns0:HLLoop1">
             <xsl:call-template name="BuildHL">
        <xsl:with-param name ="HL02" select=" 'O' "/>
        <xsl:with-param name ="HL03" select=" 'I' "/>
       </xsl:call-template>
       <xsl:element name = "ns0:LIN">
        <xsl:element name = "LIN01">
         <xsl:value-of select="ItemLineNo"/>
        </xsl:element>
        <xsl:element name = "LIN02">VP</xsl:element>
        <xsl:element name = "LIN03">
         <xsl:value-of select="PartNumber"/>
        </xsl:element>
       </xsl:element>
       <xsl:element name = "ns0:SN1">
        <xsl:element name = "SN101">
         <xsl:value-of select="ItemLineNo"/>
        </xsl:element>
        <xsl:element name = "SN102">
           <xsl:value-of select="QuantityShipped"/>
        </xsl:element>
        <xsl:element name = "SN103">EA</xsl:element>
       </xsl:element>
      </xsl:element>
     </xsl:for-each>
    </xsl:for-each>
     
     <!--Build CTT Segment-->
     <xsl:element name = "ns0:CTT">
      <xsl:element name = "CTT101">
       <xsl:value-of select="userCSharp:GetHL01()"/>
      </xsl:element>
     </xsl:element> 
    </xsl:template>  
     
     <!--Build HL Segment-->
     <xsl:template name="BuildHL">
      <xsl:param name="HL02"/>
      <xsl:param name="HL03"/>
      
      <xsl:element name = "ns0:HL">
       <xsl:element name = "HL01">
        <xsl:value-of select="userCSharp:ReturnHL01($HL03)"/>
       </xsl:element>
       
       <xsl:if test="$HL02 != ''">
       <xsl:element name = "HL02">
        <xsl:value-of select="userCSharp:ReturnHL02($HL02)"/>
       </xsl:element>
       </xsl:if>
       <xsl:element name = "HL03">
        <xsl:value-of select="$HL03"/>
       </xsl:element>
      </xsl:element>
     </xsl:template> 


    akolons

    Sunday, July 26, 2015 7:18 PM

Answers

All replies

  • Can you provide some context?
    Monday, July 27, 2015 12:28 PM
  • Thank you John-305 for getting back to me. I'm new to EDI and this is just simplified example of 856 that I'm facing. The real thing contains more HLLoop layers and I hope that if I can manage this sample then I can work on my real source document.

    <Package>
    <Segment_BSN>
          <TransactionSetPurposeCode>00</TransactionSetPurposeCode>
          <ShipmentID>20090422051</ShipmentID>
          <BSNDate>20090422</BSNDate>
          <BSNTime>1704</BSNTime>
       </Segment_BSN>
     <Shipment>
      <ShipmentPurposeCode>00</ShipmentPurposeCode>
      <ShipmentID>123456789</ShipmentID>
      <ShipmentDate>20150726</ShipmentDate>
      <ShipmentTime>1232</ShipmentTime>
      <PONumber>ORD123456</PONumber>
      <PODate>20150720</PODate>
      <Item>
       <ItemLineNo>001</ItemLineNo>
       <PartNumber>0072356665</PartNumber>
       <QuantityShipped>100</QuantityShipped>
      </Item>
      <Item>
       <ItemLineNo>002</ItemLineNo>
       <PartNumber>0072322222</PartNumber>
       <QuantityShipped>200</QuantityShipped>
      </Item>
     </Shipment>
    </Package> 


    akolons

    Monday, July 27, 2015 12:49 PM
  • Actually, I means how are you executing this Xslt?  In a Scripting Functoid, Map replacement, some other means?
    Monday, July 27, 2015 3:47 PM
  • Sorry. It's Scripting functoid to HLLoop1.


    akolons

    Monday, July 27, 2015 4:48 PM
  • Sorry again, hit Submit button too fast.

    Here is thee Inline XSLT for HLLoop1:

    int HL01 = 0;
    int ShipHL = 0;
    int OrdHL = 0;
    int PackHL = 0;
    int ItemHL = 0;

    public string ReturnHL01(string LevelCode)
    {
      HL01 += 1;
      if (LevelCode == "S")
          ShipHL = HL01;
     if (LevelCode == "O") 
      OrdHL = HL01;
     if (LevelCode == "P") 
      PackHL = HL01;
     if (LevelCode == "I") 
      ItemHL = HL01;
     return HL01.ToString(); 
      
    }

    public string ReturnHL02(string LevelCode)
    {
    int retlevel = 0;
    if (LevelCode == "S")
        retlevel = ShipHL;
    if (LevelCode == "O")
        retlevel = OrdHL;
    if (LevelCode == "P")
      retlevel = PackHL;
    if (LevelCode == "I")
      retlevel = ItemHL; 
    return retlevel.ToString();  
    }

    public string GetHL01()
    {
       return HL01.ToString();
    }
    <xsl:template name="BuildFullASN">                  
    <xsl:for-each select="//Shipment">
       <xsl:element name = "HLLoop1">            
      <xsl:call-template name="BuildHL">
        <xsl:with-param name ="HL02" select=" '' "/>
        <xsl:with-param name ="HL03" select=" 'S' "/>
      </xsl:call-template>
     <xsl:element name="ns0:DTM_2">
       <xsl:element name="DTM01">11</xsl:element>
       <xsl:element name="DTM02">
      <xsl:value-of select="//ShipmentDate"/>
       </xsl:element>
        </xsl:element>
     </xsl:element>

     <!--Create HL loop for each Order-->
      <xsl:element name = "HLLoop1">
       <xsl:call-template name="BuildHL">
        <xsl:with-param name ="HL02" select=" 'S' "/>
        <xsl:with-param name ="HL03" select=" 'O' "/>
      </xsl:call-template>
       <xsl:element name="ns0:PRF">
        <xsl:element name="PRF01">
        <xsl:value-of select="./PONumber"/>
       </xsl:element>
      </xsl:element>
      </xsl:element>
     
     <!--Create HL loop for each Item-->
      <xsl:for-each select="./Item">
          <xsl:element name = "ns0:HLLoop1">
             <xsl:call-template name="BuildHL">
        <xsl:with-param name ="HL02" select=" 'O' "/>
        <xsl:with-param name ="HL03" select=" 'I' "/>
       </xsl:call-template>
       <xsl:element name = "ns0:LIN">
        <xsl:element name = "LIN01">
         <xsl:value-of select="ItemLineNo"/>
        </xsl:element>
        <xsl:element name = "LIN02">VP</xsl:element>
        <xsl:element name = "LIN03">
         <xsl:value-of select="PartNumber"/>
        </xsl:element>
       </xsl:element>
       <xsl:element name = "ns0:SN1">
        <xsl:element name = "SN101">
         <xsl:value-of select="ItemLineNo"/>
        </xsl:element>
        <xsl:element name = "SN102">
           <xsl:value-of select="QuantityShipped"/>
        </xsl:element>
        <xsl:element name = "SN103">EA</xsl:element>
        </xsl:element>
       </xsl:element>
      </xsl:for-each>
    </xsl:for-each>
     
     <!--Build CTT Segment-->
     <xsl:element name = "ns0:CTT">
      <xsl:element name = "CTT101">
       <xsl:value-of select="userCSharp:GetHL01()"/>
      </xsl:element>
     </xsl:element> 
    </xsl:template>  
     
     <!--Build HL Segment-->
     <xsl:template name="BuildHL">
      <xsl:param name="HL02"/>
      <xsl:param name="HL03"/>
      
      <xsl:element name = "ns0:HL">
       <xsl:element name = "HL01">
        <xsl:value-of select="userCSharp:ReturnHL01($HL03)"/>
       </xsl:element>
       
       <xsl:if test="$HL02 != ''">
       <xsl:element name = "HL02">
        <xsl:value-of select="userCSharp:ReturnHL02($HL02)"/>
       </xsl:element>
       </xsl:if>
       <xsl:element name = "HL03">
        <xsl:value-of select="$HL03"/>
       </xsl:element>
      </xsl:element>
     </xsl:template>

    And another Scripting functoid on the above it with Inline C#:

    int hl01 = 0;

    public int PutHL01()
    {
       return ++hl01;
    }

    public string PutHL02()
    {
      if (hl01 > 2) return "2";
      else if (hl01  == 1) return "";
    return "1";
    }

    public string HL03()
    {
      if (hl01 > 2) return "I";
    else if (hl01 == 1) return "S";
    return "O";
    }

    :


    akolons

    Monday, July 27, 2015 4:51 PM
  • Is the Scripting Template set to XSLT Template?
    Monday, July 27, 2015 8:24 PM
  • No, it was Inline XSLT. So I changed it to the Template and then found out some errors and after I fixed the errors I got the output I needed!! thank you very much for all your help Johns-305 [boatseller]!!

    akolons

    • Marked as answer by akolons2011 Monday, July 27, 2015 9:00 PM
    Monday, July 27, 2015 9:00 PM
  • Great.

    As for the Loops, you might want to create custom loops for the different entity types.

    You can follow the sample in this Wiki Article: http://social.technet.microsoft.com/wiki/contents/articles/27099.biztalk-edi-features-not-just-for-hipaa.aspx

    The method for creating Custom Fields can be used equally with Loops.

    Monday, July 27, 2015 9:10 PM