locked
Looping sub records in the map RRS feed

  • Question

  • Source Schema:

    <Items>

    <Item>

    </Item>

    <Item>

    </Item>

    </Items>

    Destination:

    <DetailRequest>

    <DetailsHeader> -- Appears only one time

    </DetailsHeader> -- Appears multiple times

    <DetailsLines>

    <DetailSummery> Appears only one time

    </DetailSummery>

    Now i need to map Item to Details lines and i have used looping functoid but its appearing only one time because no for each in the xsl .

    do i need to use inline xslt to achieve  ? 


    Monday, April 2, 2018 5:59 PM

Answers

  • Most likely, the source and/or target nodes in the Schemas are defined Max Occurs = 1 (default).

    Change the repeating elements to unbounded (*).

    Monday, April 2, 2018 6:33 PM
    Moderator

All replies

  • In order to provide the best advice and avoid duplicates, can you describe everything you have tried?

    This is a pretty common scenario.

    Monday, April 2, 2018 6:09 PM
    Moderator
  • I have kept looping functoid from Item record to <DetailsLines>  but in results its showing only one record because no for each in the xsl.

    Monday, April 2, 2018 6:13 PM
  • Most likely, the source and/or target nodes in the Schemas are defined Max Occurs = 1 (default).

    Change the repeating elements to unbounded (*).

    Monday, April 2, 2018 6:33 PM
    Moderator
  • Can you please provide the exact schemas both input and output as well as input xml and expteded output xml?

    If this answers your question please mark it accordingly. If this post is helpful, please vote as helpful.

    Monday, April 2, 2018 6:40 PM
  • 

    I need to place multiple invoice details order in the invoice details request node 

    invoice details order is unbound .

     
    Monday, April 2, 2018 7:03 PM
  • Most likely, the source and/or target nodes in the Schemas are defined Max Occurs = 1 (default).

    Change the repeating elements to unbounded (*).

    Is <Item> also unbounded?
    Monday, April 2, 2018 7:26 PM
    Moderator
  • Yes Item is unbound .
    Monday, April 2, 2018 7:27 PM
  •   <?xml version="1.0" encoding="UTF-16" ?> 
    - <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:var="http://schemas.microsoft.com/BizTalk/2003/var" exclude-result-prefixes="msxsl var s0 userCSharp ScriptNS0" version="1.0" xmlns:ns0="http://www.w3.org/XML/1998/namespace" xmlns:s0="http://OM.BizTalk.Invoicing.Schemas.Canonicals_V1" xmlns:userCSharp="http://schemas.microsoft.com/BizTalk/2003/userCSharp" xmlns:ScriptNS0="http://schemas.microsoft.com/BizTalk/2003/ScriptNS0">
      <xsl:output omit-xml-declaration="yes" method="xml" version="1.0" /> 
    - <xsl:template match="/">
      <xsl:apply-templates select="/s0:Invoice" /> 
      </xsl:template>
    - <xsl:template match="/s0:Invoice">
      <xsl:variable name="var:v1" select="userCSharp:StringConcat("1.0")" /> 
      <xsl:variable name="var:v12" select="userCSharp:MathAdd(string(EndRecord/EndRecordFields/TotalSales/text()) , string(EndRecord/EndRecordFields/TotalFreight/text()) , string(EndRecord/EndRecordFields/TotalTax/text()) , string(EndRecord/EndRecordFields/TotalExtraDeliveryFee/text()))" /> 
    - <cXML>
    - <xsl:attribute name="version">
      <xsl:value-of select="$var:v1" /> 
      </xsl:attribute>
      <xsl:variable name="var:v2" select="ScriptNS0:GetCurrentTimeStamp()" /> 
    - <xsl:attribute name="timestamp">
      <xsl:value-of select="$var:v2" /> 
      </xsl:attribute>
    - <Header>
    - <From>
    - <Credential>
      <xsl:variable name="var:v3" select="ScriptNS0:GetSetting("Coupa CXML Invoice Credential domain")" /> 
    - <xsl:attribute name="domain">
      <xsl:value-of select="$var:v3" /> 
      </xsl:attribute>
      <xsl:variable name="var:v4" select="ScriptNS0:GetSetting("Coupa CXML Invoice From Identity")" /> 
    - <Identity>
      <xsl:value-of select="$var:v4" /> 
      </Identity>
      </Credential>
      </From>
    - <To>
    - <Credential>
      <xsl:variable name="var:v5" select="ScriptNS0:GetSetting("Coupa CXML Invoice Credential domain")" /> 
    - <xsl:attribute name="domain">
      <xsl:value-of select="$var:v5" /> 
      </xsl:attribute>
      <xsl:variable name="var:v6" select="ScriptNS0:GetSetting("Coupa CXML Invoice To Identity")" /> 
    - <Identity>
      <xsl:value-of select="$var:v6" /> 
      </Identity>
      </Credential>
      </To>
    - <Sender>
    - <Credential>
      <xsl:variable name="var:v7" select="ScriptNS0:GetSetting("Coupa CXML Invoice Credential domain")" /> 
    - <xsl:attribute name="domain">
      <xsl:value-of select="$var:v7" /> 
      </xsl:attribute>
      <xsl:variable name="var:v8" select="ScriptNS0:GetSetting("Coupa CXML Invoice From Identity")" /> 
    - <Identity>
      <xsl:value-of select="$var:v8" /> 
      </Identity>
      <xsl:variable name="var:v9" select="ScriptNS0:GetSetting("Coupa CXML Invoice SharedSecret")" /> 
    - <SharedSecret>
      <xsl:value-of select="$var:v9" /> 
      </SharedSecret>
      </Credential>
      <xsl:variable name="var:v10" select="ScriptNS0:GetSetting("Coupa CXML Invoice User Agent")" /> 
    - <UserAgent>
      <xsl:value-of select="$var:v10" /> 
      </UserAgent>
      </Sender>
      </Header>
    - <Request>
      <xsl:variable name="var:v11" select="ScriptNS0:GetSetting("Coupa CXML Invoice Deployment Mode")" /> 
    - <xsl:attribute name="deploymentMode">
      <xsl:value-of select="$var:v11" /> 
      </xsl:attribute>
    - <InvoiceDetailRequest>
    - <InvoiceDetailRequestHeader>
    - <xsl:attribute name="invoiceID">
      <xsl:value-of select="Header/ExtInvoiceNumber/text()" /> 
      </xsl:attribute>
    - <xsl:attribute name="invoiceDate">
      <xsl:value-of select="Header/Dates/InvoiceDate/text()" /> 
      </xsl:attribute>
    - <InvoicePartner>
    - <Contact>
    - <xsl:attribute name="addressID">
      <xsl:value-of select="Address/Addres/ShipFromInfo/Address1/text()" /> 
      </xsl:attribute>
      </Contact>
      </InvoicePartner>
    - <InvoiceDetailPaymentTerm>
    - <xsl:attribute name="payInNumberOfDays">
      <xsl:value-of select="Header/TermsInfo/TermsDiscDueDate/text()" /> 
      </xsl:attribute>
    - <xsl:attribute name="percentageRate">
      <xsl:value-of select="Header/TermsInfo/TermsDiscPercent/text()" /> 
      </xsl:attribute>
      </InvoiceDetailPaymentTerm>
      </InvoiceDetailRequestHeader>
    - <InvoiceDetailOrder>
    - <InvoiceDetailOrderInfo>
    - <OrderReference>
    - <DocumentReference>
    - <xsl:attribute name="payloadID">
      <xsl:value-of select="Header/RefNumbers/CustomerOrderNumber/text()" /> 
      </xsl:attribute>
      </DocumentReference>
      </OrderReference>
      </InvoiceDetailOrderInfo>
    - <InvoiceDetailItem>
    - <xsl:attribute name="invoiceLineNumber">
      <xsl:value-of select="ItemDetails/Item/LineNumber/text()" /> 
      </xsl:attribute>
    - <xsl:attribute name="quantity">
      <xsl:value-of select="ItemDetails/Item/QtyShipNumber/text()" /> 
      </xsl:attribute>
    - <UnitOfMeasure>
      <xsl:value-of select="ItemDetails/Item/UniOfMeasure/text()" /> 
      </UnitOfMeasure>
    - <UnitPrice>
    - <Money>
    - <xsl:attribute name="currency">
      <xsl:value-of select="ItemDetails/Item/UnitPrice/text()" /> 
      </xsl:attribute>
      </Money>
      </UnitPrice>
    - <InvoiceDetailItemReference>
    - <xsl:attribute name="lineNumber">
      <xsl:value-of select="ItemDetails/Item/LineNumber/text()" /> 
      </xsl:attribute>
    - <Description>
    - <xsl:attribute name="ns0:lang">
      <xsl:value-of select="ItemDetails/Item/Description/text()" /> 
      </xsl:attribute>
      </Description>
      </InvoiceDetailItemReference>
    - <SubtotalAmount>
    - <Money>
    - <xsl:attribute name="currency">
      <xsl:value-of select="EndRecord/EndRecordFields/TotalSales/text()" /> 
      </xsl:attribute>
      </Money>
      </SubtotalAmount>
    - <Tax>
    - <TaxDetail>
    - <TaxAmount>
    - <Money>
    - <xsl:attribute name="currency">
      <xsl:value-of select="EndRecord/EndRecordFields/TotalTax/text()" /> 
      </xsl:attribute>
      </Money>
      </TaxAmount>
      </TaxDetail>
      </Tax>
      </InvoiceDetailItem>
      </InvoiceDetailOrder>
    - <InvoiceDetailSummary>
    - <Tax>
    - <Money>
    - <xsl:attribute name="currency">
      <xsl:value-of select="ItemDetails/Item/LineTaxAmount/text()" /> 
      </xsl:attribute>
      </Money>
      </Tax>
    - <ShippingAmount>
    - <Money>
    - <xsl:attribute name="currency">
      <xsl:value-of select="EndRecord/EndRecordFields/TotalFreight/text()" /> 
      </xsl:attribute>
      </Money>
      </ShippingAmount>
    - <NetAmount>
    - <Money>
    - <xsl:attribute name="currency">
      <xsl:value-of select="$var:v12" /> 
      </xsl:attribute>
      </Money>
      </NetAmount>
      </InvoiceDetailSummary>
      </InvoiceDetailRequest>
      </Request>
      </cXML>
      </xsl:template>
    - <msxsl:script language="C#" implements-prefix="userCSharp">
    - <![CDATA[ public string StringConcat(string param0)
    {
       return param0;
    }
    
    
    public string MathAdd(string param0, string param1, string param2, string param3)
    {
    	System.Collections.ArrayList listValues = new System.Collections.ArrayList();
    	listValues.Add(param0);
    	listValues.Add(param1);
    	listValues.Add(param2);
    	listValues.Add(param3);
    	double ret = 0;
    	foreach (string obj in listValues)
    	{
    	double d = 0;
    		if (IsNumeric(obj, ref d))
    		{
    			ret += d;
    		}
    		else
    		{
    			return "";
    		}
    	}
    	return ret.ToString(System.Globalization.CultureInfo.InvariantCulture);
    }
    
    
    public bool IsNumeric(string val)
    {
    	if (val == null)
    	{
    		return false;
    	}
    	double d = 0;
    	return Double.TryParse(val, System.Globalization.NumberStyles.AllowThousands | System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture, out d);
    }
    
    public bool IsNumeric(string val, ref double d)
    {
    	if (val == null)
    	{
    		return false;
    	}
    	return Double.TryParse(val, System.Globalization.NumberStyles.AllowThousands | System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture, out d);
    }
    
    
    
      ]]> 
      </msxsl:script>
      </xsl:stylesheet>

    Monday, April 2, 2018 7:28 PM
  • Sorry John source schema repeating node doesn't has unbound due to that for each doesn't appear in the xsl
    Monday, April 2, 2018 11:43 PM