aceinthehole
aceinthehole

Reputation: 5222

BizTalk - mapping a source that has a Parent-Child relationship a flat destination

I have seen this question about a parent child relationship, but it is not exactly the same since I have nothing to tag with.

I have a source flat file that look like this

Location  Route       Prod   Company      Date      Amount
XXX       RT00008     UT     COMPANY1     20110926  3
XXX       RT00008     UT     COMPANY1     20110927  1
XXX       RT00008     UT     COMPANY1     20110928  1
XXX       RT00008     UT     COMPANY1     20110929  1
XXX       RT00008     UT     COMPANY1     20110930  1
XXX       RT00171     SPW    COMPANY2     20110928  1
XXX       RT00171     UT     COMPANY2     20110926  1
XXX       RT00171     UT     COMPANY2     20110927  1
XXX       RT00171     UT     COMPANY2     20110928  1

Here is the killer, for each unique combination of Route, Prod, and Company I need one record with the days of week filled in. For instance the previous example should map into 3 separate rows in the output.

Loc,   Route,  Pr,  Company, Sun, Mon, Tues,  Wed, Thur, Fri, Sat 
XXX, RT00008,  UT, COMPANY1,   0,   3,    1,    1,    1,   1,   1
XXX, RT00171, SPW, COMPANY2,   0,   0,    0,    1,    0,   0,   0
XXX, RT00171,  UT, COMPANY2,   0,   1,    1,    1,    0,   0,   0

Now my question is, is there a way to do this without XSLT? Can it be done by using functoid, in one or more series of maps? It seems like the table looping functoid is custom built for the opposite of this situation, can it be done in reverse? If it can only be done using XSLT I am still scratching my head on how to do it?

Thanks for any help!

Upvotes: 1

Views: 1244

Answers (1)

TJ Amas
TJ Amas

Reputation: 1301

I created two schema representations of your Flat files (not flat file schemas, but they will suffice for the illustration).

I started with a biztalk map thats would populate the first day with the appropriate value for a given combo of Company, Route and Prod. I went to xsl to allow it loop through a collection of identified combos to populate ALL days for the identified combo.

Its probably best that you load up the .btm supplied along with the schemas and xsl to see what I've done. I can explain anything thats unclear.

Its probably worth noting that you could tidy up the solution but I hope it gives you a pointer.

Two points to note: the "day" nodes are only created when a value exists for that day. You can change this in the xsl. And, I used a valid date time to test (e.g. 26-09-2011) so you'll have to parse your date when determining what DayOfWeek your date is.

The first Schema:

<?xml version="1.0" encoding="utf-16"?>
<xs:schema xmlns="http://BizTalk_Server_Project2.Schema1" xmlns:b="http://schemas.microsoft.com/BizTalk/2003" targetNamespace="http://BizTalk_Server_Project2.Schema1" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="Root">
    <xs:complexType>
      <xs:sequence>
        <xs:element minOccurs="1" maxOccurs="unbounded" name="Record">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="Location" type="xs:string" />
              <xs:element name="Route" type="xs:string" />
              <xs:element name="Prod" type="xs:string" />
              <xs:element name="Company" type="xs:string" />
              <xs:element name="Date" type="xs:string" />
              <xs:element name="Amount" type="xs:string" />
            </xs:sequence>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>

The second schema:

<?xml version="1.0" encoding="utf-16"?>
<xs:schema xmlns="http://BizTalk_Server_Project2.Schema2" xmlns:b="http://schemas.microsoft.com/BizTalk/2003" targetNamespace="http://BizTalk_Server_Project2.Schema2" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="Root">
    <xs:complexType>
      <xs:sequence>
        <xs:element minOccurs="1" maxOccurs="unbounded" name="Record">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="Loc" type="xs:string" />
              <xs:element name="Route" type="xs:string" />
              <xs:element name="Pr" type="xs:string" />
              <xs:element name="Company" type="xs:string" />
              <xs:element name="Sun" type="xs:string" />
              <xs:element name="Mon" type="xs:string" />
              <xs:element name="Tue" type="xs:string" />
              <xs:element name="Wed" type="xs:string" />
              <xs:element name="Thurs" type="xs:string" />
              <xs:element name="Friday" type="xs:string" />
              <xs:element name="Sat" type="xs:string" />
            </xs:sequence>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>

The BizTalk Map:

 <?xml version="1.0" encoding="utf-16"?>
    <mapsource Name="BizTalk Map" Version="2" BizTalkServerMapperTool_Version="3.0" XRange="100" YRange="420" OmitXmlDeclaration="Yes" TreatElementsAsRecords="No" OptimizeValueMapping="Yes" GenerateDefaultFixedNodes="Yes" PreserveSequenceOrder="No" IgnoreNamespacesForLinks="Yes" method="xml" CopyPIs="No" xmlVersion="1.0">
        <SrcTree RootNode_Name="Root">
            <Reference Location=".\Schema1.xsd" />
        </SrcTree>
        <TrgTree RootNode_Name="Root">
            <Reference Location=".\Schema2.xsd" />
        </TrgTree>
        <ScriptTypePrecedence>
            <CSharp Enabled="Yes" />
            <ExternalAssembly Enabled="Yes" />
            <VbNet Enabled="Yes" />
            <JScript Enabled="Yes" />
            <XsltCallTemplate Enabled="Yes" />
            <Xslt Enabled="Yes" />
        </ScriptTypePrecedence>
        <TreeValues>
            <TestValues />
            <ConstantValues />
        </TreeValues>
        <CustomXSLT XsltPath=".\Map1.xsl" ExtObjXmlPath=".\Map1_extxml.xml" />
        <Pages>
            <Page Name="Page 1">
                <Links>
                    <Link LinkID="22" LinkFrom="/*[local-name()='&lt;Schema&gt;']/*[local-name()='Root']/*[local-name()='Record']/*[local-name()='Date']" LinkTo="107" />
                    <Link LinkID="19" LinkFrom="/*[local-name()='&lt;Schema&gt;']/*[local-name()='Root']/*[local-name()='Record']/*[local-name()='Company']" LinkTo="106" />
                    <Link LinkID="16" LinkFrom="/*[local-name()='&lt;Schema&gt;']/*[local-name()='Root']/*[local-name()='Record']/*[local-name()='Prod']" LinkTo="105" />
                    <Link LinkID="14" LinkFrom="/*[local-name()='&lt;Schema&gt;']/*[local-name()='Root']/*[local-name()='Record']/*[local-name()='Route']" LinkTo="104" />
                    <Link LinkID="20" LinkFrom="106" LinkTo="/*[local-name()='&lt;Schema&gt;']/*[local-name()='Root']/*[local-name()='Record']/*[local-name()='Company']" />
                    <Link LinkID="15" LinkFrom="104" LinkTo="/*[local-name()='&lt;Schema&gt;']/*[local-name()='Root']/*[local-name()='Record']/*[local-name()='Route']" />
                    <Link LinkID="11" LinkFrom="103" LinkTo="/*[local-name()='&lt;Schema&gt;']/*[local-name()='Root']/*[local-name()='Record']/*[local-name()='Loc']" />
                    <Link LinkID="10" LinkFrom="/*[local-name()='&lt;Schema&gt;']/*[local-name()='Root']/*[local-name()='Record']/*[local-name()='Location']" LinkTo="103" />
                    <Link LinkID="18" LinkFrom="102" LinkTo="106" />
                    <Link LinkID="13" LinkFrom="102" LinkTo="105" />
                    <Link LinkID="12" LinkFrom="102" LinkTo="104" />
                    <Link LinkID="9" LinkFrom="102" LinkTo="103" />
                    <Link LinkID="1" LinkFrom="98" LinkTo="/*[local-name()='&lt;Schema&gt;']/*[local-name()='Root']" />
                    <Link LinkID="8" LinkFrom="101" LinkTo="102" />
                    <Link LinkID="6" LinkFrom="99" LinkTo="101" />
                    <Link LinkID="21" LinkFrom="/*[local-name()='&lt;Schema&gt;']/*[local-name()='Root']/*[local-name()='Record']/*[local-name()='Company']" LinkTo="100" />
                    <Link LinkID="3" LinkFrom="/*[local-name()='&lt;Schema&gt;']/*[local-name()='Root']/*[local-name()='Record']/*[local-name()='Route']" LinkTo="100" />
                    <Link LinkID="4" LinkFrom="/*[local-name()='&lt;Schema&gt;']/*[local-name()='Root']/*[local-name()='Record']/*[local-name()='Prod']" LinkTo="100" />
                    <Link LinkID="5" LinkFrom="100" LinkTo="99" />
                    <Link LinkID="24" LinkFrom="107" LinkTo="109" />
                    <Link LinkID="31" LinkFrom="109" LinkTo="117" />
                    <Link LinkID="38" LinkFrom="/*[local-name()='&lt;Schema&gt;']/*[local-name()='Root']/*[local-name()='Record']/*[local-name()='Amount']" LinkTo="117" />
                    <Link LinkID="30" LinkFrom="108" LinkTo="116" />
                    <Link LinkID="23" LinkFrom="107" LinkTo="108" />
                    <Link LinkID="37" LinkFrom="/*[local-name()='&lt;Schema&gt;']/*[local-name()='Root']/*[local-name()='Record']/*[local-name()='Amount']" LinkTo="116" />
                    <Link LinkID="33" LinkFrom="110" LinkTo="119" />
                    <Link LinkID="32" LinkFrom="112" LinkTo="118" />
                    <Link LinkID="34" LinkFrom="113" LinkTo="120" />
                    <Link LinkID="35" LinkFrom="114" LinkTo="121" />
                    <Link LinkID="36" LinkFrom="115" LinkTo="122" />
                    <Link LinkID="26" LinkFrom="107" LinkTo="110" />
                    <Link LinkID="25" LinkFrom="107" LinkTo="112" />
                    <Link LinkID="27" LinkFrom="107" LinkTo="113" />
                    <Link LinkID="28" LinkFrom="107" LinkTo="114" />
                    <Link LinkID="29" LinkFrom="107" LinkTo="115" />
                    <Link LinkID="39" LinkFrom="/*[local-name()='&lt;Schema&gt;']/*[local-name()='Root']/*[local-name()='Record']/*[local-name()='Amount']" LinkTo="118" />
                    <Link LinkID="40" LinkFrom="/*[local-name()='&lt;Schema&gt;']/*[local-name()='Root']/*[local-name()='Record']/*[local-name()='Amount']" LinkTo="119" />
                    <Link LinkID="41" LinkFrom="/*[local-name()='&lt;Schema&gt;']/*[local-name()='Root']/*[local-name()='Record']/*[local-name()='Amount']" LinkTo="120" />
                    <Link LinkID="42" LinkFrom="/*[local-name()='&lt;Schema&gt;']/*[local-name()='Root']/*[local-name()='Record']/*[local-name()='Amount']" LinkTo="121" />
                    <Link LinkID="43" LinkFrom="/*[local-name()='&lt;Schema&gt;']/*[local-name()='Root']/*[local-name()='Record']/*[local-name()='Amount']" LinkTo="122" />
                    <Link LinkID="17" LinkFrom="105" LinkTo="/*[local-name()='&lt;Schema&gt;']/*[local-name()='Root']/*[local-name()='Record']/*[local-name()='Pr']" />
                    <Link LinkID="44" LinkFrom="116" LinkTo="/*[local-name()='&lt;Schema&gt;']/*[local-name()='Root']/*[local-name()='Record']/*[local-name()='Sun']" />
                    <Link LinkID="45" LinkFrom="117" LinkTo="/*[local-name()='&lt;Schema&gt;']/*[local-name()='Root']/*[local-name()='Record']/*[local-name()='Mon']" />
                    <Link LinkID="46" LinkFrom="118" LinkTo="/*[local-name()='&lt;Schema&gt;']/*[local-name()='Root']/*[local-name()='Record']/*[local-name()='Tue']" />
                    <Link LinkID="47" LinkFrom="119" LinkTo="/*[local-name()='&lt;Schema&gt;']/*[local-name()='Root']/*[local-name()='Record']/*[local-name()='Wed']" />
                    <Link LinkID="48" LinkFrom="120" LinkTo="/*[local-name()='&lt;Schema&gt;']/*[local-name()='Root']/*[local-name()='Record']/*[local-name()='Thurs']" />
                    <Link LinkID="49" LinkFrom="121" LinkTo="/*[local-name()='&lt;Schema&gt;']/*[local-name()='Root']/*[local-name()='Record']/*[local-name()='Friday']" />
                    <Link LinkID="50" LinkFrom="122" LinkTo="/*[local-name()='&lt;Schema&gt;']/*[local-name()='Root']/*[local-name()='Record']/*[local-name()='Sat']" />
                </Links>
                <Functoids>
                    <Functoid FunctoidID="107" Functoid-FID="260" X-Cell="52" Y-Cell="194">
                        <Input-Parameters>
                            <Parameter Type="link" Value="22" linkIndex="0" Guid="7470c0bc-c75c-4ab5-99f2-250d7fe1e389" />
                        </Input-Parameters>
                        <ScripterCode>
                            <Script Language="CSharp">
                                <![CDATA[///*Uncomment the following code for a sample Inline C# function
    //that concatenates two inputs. Change the number of parameters of
    //this function to be equal to the number of inputs connected to this functoid.*/

    public string dow(string myDate)
    {
        return DateTime.Parse(myDate).DayOfWeek.ToString();
    }
    ]]>
                            </Script>
                        </ScripterCode>
                    </Functoid>
                    <Functoid FunctoidID="106" Functoid-FID="375" X-Cell="56" Y-Cell="193">
                        <Input-Parameters>
                            <Parameter Type="link" Value="18" linkIndex="0" Guid="87396644-e663-4615-9e42-67060259fb1a" />
                            <Parameter Type="link" Value="19" linkIndex="1" Guid="cc39c66f-59fd-427d-aefc-5c1195e6a72f" />
                        </Input-Parameters>
                    </Functoid>
                    <Functoid FunctoidID="105" Functoid-FID="375" X-Cell="56" Y-Cell="191">
                        <Input-Parameters>
                            <Parameter Type="link" Value="13" linkIndex="0" Guid="691fde94-db0b-4f53-b2ee-ff8f8f980027" />
                            <Parameter Type="link" Value="16" linkIndex="1" Guid="04844567-8d00-44cd-9b90-89e5009c4269" />
                        </Input-Parameters>
                    </Functoid>
                    <Functoid FunctoidID="104" Functoid-FID="375" X-Cell="56" Y-Cell="189">
                        <Input-Parameters>
                            <Parameter Type="link" Value="12" linkIndex="0" Guid="16e52083-f9c4-4563-980c-146f4621dab6" />
                            <Parameter Type="link" Value="14" linkIndex="1" Guid="58d9d487-43be-4e7a-a0b0-efbbae08d004" />
                        </Input-Parameters>
                    </Functoid>
                    <Functoid FunctoidID="103" Functoid-FID="375" X-Cell="56" Y-Cell="187">
                        <Input-Parameters>
                            <Parameter Type="link" Value="9" linkIndex="0" Guid="230f2ff4-b9aa-4903-893b-90bd3fe49540" />
                            <Parameter Type="link" Value="10" linkIndex="1" Guid="5cc1c29a-7398-4005-ace7-4cbc4c176960" />
                        </Input-Parameters>
                    </Functoid>
                    <Functoid FunctoidID="102" Functoid-FID="705" X-Cell="54" Y-Cell="186">
                        <Input-Parameters>
                            <Parameter Type="link" Value="8" linkIndex="0" Guid="b3777b48-0d39-499c-96c9-40ffdd0c8737" />
                        </Input-Parameters>
                    </Functoid>
                    <Functoid FunctoidID="98" Functoid-FID="260" X-Cell="52" Y-Cell="182">
                        <Input-Parameters />
                        <ScripterCode>
                            <Script Language="CSharp">
                                <![CDATA[// declare global variables for Voucher number assignment
    System.Collections.Generic.List<string> keyList = 
    new System.Collections.Generic.List<string>();

    public void init(){}
    ]]>
                            </Script>
                        </ScripterCode>
                    </Functoid>
                    <Functoid FunctoidID="101" Functoid-FID="315" X-Cell="54" Y-Cell="184">
                        <Input-Parameters>
                            <Parameter Type="link" Value="6" linkIndex="0" Guid="4a5c621f-9f4f-4b1f-a81b-6dce03aa402a" />
                            <Parameter Type="constant" Value="true" linkIndex="1" Guid="5aafc712-0e6c-44be-baf8-c3a7d8806eb5" />
                        </Input-Parameters>
                    </Functoid>
                    <Functoid FunctoidID="99" Functoid-FID="260" X-Cell="52" Y-Cell="184">
                        <Input-Parameters>
                            <Parameter Type="link" Value="5" linkIndex="0" Guid="bb64de45-0250-4d51-8ee3-4759d7812160" />
                        </Input-Parameters>
                        <ScripterCode>
                            <Script Language="CSharp">
                                <![CDATA[// Add invoice number to list if it doesn't already exist.
    // increment voucher number if new invoice

    public Boolean AddKeyToList(string key)
    {
       // if the Invoice number is not already in the List
       if (!keyList.Contains(key))
       {
          // Add to list
          keyList.Add(key);

          return true;
       }
       return false;

    }]]>
                            </Script>
                        </ScripterCode>
                    </Functoid>
                    <Functoid FunctoidID="100" Functoid-FID="107" X-Cell="44" Y-Cell="175">
                        <Input-Parameters>
                            <Parameter Type="link" Value="21" linkIndex="0" Guid="f630c6c2-b5c2-4c77-bf53-d25fdfb06b78" />
                            <Parameter Type="link" Value="3" linkIndex="1" Guid="f24d57bc-22d9-4390-bdf1-52ca16f9b45b" />
                            <Parameter Type="link" Value="4" linkIndex="2" Guid="87ee7e4f-374c-4343-aa68-0a5bf6fffac7" />
                        </Input-Parameters>
                    </Functoid>
                    <Functoid FunctoidID="117" Functoid-FID="375" X-Cell="56" Y-Cell="195">
                        <Input-Parameters>
                            <Parameter Type="link" Value="31" linkIndex="0" Guid="4e5e0ad8-543e-4a41-b702-74d2d8356030" />
                            <Parameter Type="link" Value="38" linkIndex="1" Guid="c94e83a7-1220-4797-ac03-751e089e9a07" />
                        </Input-Parameters>
                    </Functoid>
                    <Functoid FunctoidID="109" Functoid-FID="315" X-Cell="54" Y-Cell="195">
                        <Input-Parameters>
                            <Parameter Type="link" Value="24" linkIndex="0" Guid="c6998772-def3-4a8a-ae7d-0cdb947f95a4" />
                            <Parameter Type="constant" Value="Monday" linkIndex="1" Guid="64603dba-6df1-4b59-8968-62949ccc6759" />
                        </Input-Parameters>
                    </Functoid>
                    <Functoid FunctoidID="108" Functoid-FID="315" X-Cell="54" Y-Cell="194">
                        <Input-Parameters>
                            <Parameter Type="link" Value="23" linkIndex="0" Guid="d44d97ba-b3d3-48cd-a3c9-7ce4726d35df" />
                            <Parameter Type="constant" Value="Sunday" linkIndex="1" Guid="75cf8619-0493-4aac-9f76-1a020d7fac0f" />
                        </Input-Parameters>
                    </Functoid>
                    <Functoid FunctoidID="116" Functoid-FID="375" X-Cell="56" Y-Cell="194">
                        <Input-Parameters>
                            <Parameter Type="link" Value="30" linkIndex="0" Guid="c37bfe5c-9a5a-4b23-b300-16c942ba785b" />
                            <Parameter Type="link" Value="37" linkIndex="1" Guid="b02aab3d-6437-401c-9b06-bdf7c7d9c832" />
                        </Input-Parameters>
                    </Functoid>
                    <Functoid FunctoidID="110" Functoid-FID="315" X-Cell="54" Y-Cell="197">
                        <Input-Parameters>
                            <Parameter Type="link" Value="26" linkIndex="0" Guid="1cd88b45-1667-416e-aeef-78cc599f3cc7" />
                            <Parameter Type="constant" Value="Wednesday" linkIndex="1" Guid="773c8e04-45a2-4d1e-983f-0b53745c038f" />
                        </Input-Parameters>
                    </Functoid>
                    <Functoid FunctoidID="112" Functoid-FID="315" X-Cell="54" Y-Cell="196">
                        <Input-Parameters>
                            <Parameter Type="link" Value="25" linkIndex="0" Guid="599dfe5a-202b-49ee-a439-1276296501bd" />
                            <Parameter Type="constant" Value="Tuesday" linkIndex="1" Guid="bd4a7be3-b886-4cad-ab71-077b9cb507e0" />
                        </Input-Parameters>
                    </Functoid>
                    <Functoid FunctoidID="113" Functoid-FID="315" X-Cell="54" Y-Cell="198">
                        <Input-Parameters>
                            <Parameter Type="link" Value="27" linkIndex="0" Guid="61d375df-85ad-49ef-8161-5c7908e7a1f9" />
                            <Parameter Type="constant" Value="Thursday" linkIndex="1" Guid="efb2d4af-52e1-41c3-8886-e8acbcf6f788" />
                        </Input-Parameters>
                    </Functoid>
                    <Functoid FunctoidID="114" Functoid-FID="315" X-Cell="54" Y-Cell="199">
                        <Input-Parameters>
                            <Parameter Type="link" Value="28" linkIndex="0" Guid="84dc8167-ef26-41e2-8cbc-92bc09d9b513" />
                            <Parameter Type="constant" Value="Friday" linkIndex="1" Guid="bdea9f04-4e4d-458a-bc6c-5a7d063a9128" />
                        </Input-Parameters>
                    </Functoid>
                    <Functoid FunctoidID="115" Functoid-FID="315" X-Cell="54" Y-Cell="200">
                        <Input-Parameters>
                            <Parameter Type="link" Value="29" linkIndex="0" Guid="ad77c87e-b292-4b10-9932-7fc9f5981869" />
                            <Parameter Type="constant" Value="Saturday" linkIndex="1" Guid="d811f065-8eed-4445-9356-fe5327b2c634" />
                        </Input-Parameters>
                    </Functoid>
                    <Functoid FunctoidID="118" Functoid-FID="375" X-Cell="56" Y-Cell="196">
                        <Input-Parameters>
                            <Parameter Type="link" Value="32" linkIndex="0" Guid="32cd8143-b582-4d49-a048-84e54cd42bea" />
                            <Parameter Type="link" Value="39" linkIndex="1" Guid="95fffee4-6451-442d-9a60-19a297388aa5" />
                        </Input-Parameters>
                    </Functoid>
                    <Functoid FunctoidID="119" Functoid-FID="375" X-Cell="56" Y-Cell="197">
                        <Input-Parameters>
                            <Parameter Type="link" Value="33" linkIndex="0" Guid="d222802d-a84e-4cdd-8920-48623705506d" />
                            <Parameter Type="link" Value="40" linkIndex="1" Guid="9be3005a-d0e2-454d-b970-a350becadf5d" />
                        </Input-Parameters>
                    </Functoid>
                    <Functoid FunctoidID="120" Functoid-FID="375" X-Cell="56" Y-Cell="198">
                        <Input-Parameters>
                            <Parameter Type="link" Value="34" linkIndex="0" Guid="bfe3b4b6-c52a-4762-9c2c-b868d7f203fd" />
                            <Parameter Type="link" Value="41" linkIndex="1" Guid="f7eed5ef-5156-4d4b-8cc9-42a5c5773ec2" />
                        </Input-Parameters>
                    </Functoid>
                    <Functoid FunctoidID="121" Functoid-FID="375" X-Cell="56" Y-Cell="199">
                        <Input-Parameters>
                            <Parameter Type="link" Value="35" linkIndex="0" Guid="d2765ea5-a23c-43f5-834e-ec5e610f1114" />
                            <Parameter Type="link" Value="42" linkIndex="1" Guid="ccf811b9-31bc-4cb2-9d00-fa784c357575" />
                        </Input-Parameters>
                    </Functoid>
                    <Functoid FunctoidID="122" Functoid-FID="375" X-Cell="56" Y-Cell="200">
                        <Input-Parameters>
                            <Parameter Type="link" Value="36" linkIndex="0" Guid="63f4d89b-0487-434a-97a7-137b70376867" />
                            <Parameter Type="link" Value="43" linkIndex="1" Guid="2f302981-121d-4825-8251-6b9bd0123278" />
                        </Input-Parameters>
                    </Functoid>
                </Functoids>
            </Page>
        </Pages>
    </mapsource>

in the generated xsl, replace the <Root> element with:

<ns0:Root>
                <xsl:for-each select="Record">
                    <xsl:variable name="var:v1" select="userCSharp:StringConcat(string(Company/text()) , string(Route/text()) , string(Prod/text()))" />
                    <xsl:variable name="var:v6" select="string(Company/text())" />
                    <xsl:variable name="var:v7" select="string(Route/text())" />
                    <xsl:variable name="var:v8" select="string(Prod/text())" />
                    <xsl:variable name="var:v9" select="userCSharp:StringConcat($var:v6 , $var:v7 , $var:v8)" />
                    <xsl:variable name="var:v25" select="string(Date/text())" />

                    <!-- Only create a new record node in the destibation if the Keys are different! -->
                    <xsl:variable name="varCurrentCompany" select="string(Company/text())" />
                    <xsl:variable name="varPrevCompany" select="string(preceding-sibling::Record[1]/Company/text())" />
                    <xsl:variable name="varCurrentRoute" select="string(Route/text())" />
                    <xsl:variable name="varPrevRoute" select="string(preceding-sibling::Record[1]/Route/text())" />
                    <xsl:variable name="varCurrentProd" select="string(Prod/text())" />
                    <xsl:variable name="varPrevProd" select="string(preceding-sibling::Record[1]/Prod/text())" />

                    <!-- do this by checking if the current record is different to the previous record -->
                    <xsl:if test="($varCurrentCompany!=$varPrevCompany) or ($varCurrentRoute!=$varPrevRoute) or ($varCurrentProd!=$varPrevProd)">
                        <Record>
                            <xsl:variable name="var:v2" select="userCSharp:AddKeyToList(string($var:v1))" />
                            <xsl:variable name="var:v3" select="userCSharp:LogicalEq(string($var:v2) , &quot;true&quot;)" />
                            <xsl:variable name="var:v4" select="userCSharp:LogicalNot(string($var:v3))" />
                            <xsl:if test="string($var:v4)='true'">
                                <xsl:variable name="var:v5" select="Location/text()" />
                                <Loc>
                                    <xsl:value-of select="$var:v5" />
                                </Loc>
                            </xsl:if>
                            <xsl:variable name="var:v10" select="userCSharp:AddKeyToList(string($var:v9))" />
                            <xsl:variable name="var:v11" select="userCSharp:LogicalEq(string($var:v10) , &quot;true&quot;)" />
                            <xsl:variable name="var:v12" select="userCSharp:LogicalNot(string($var:v11))" />
                            <xsl:if test="string($var:v12)='true'">
                                <xsl:variable name="var:v13" select="Route/text()" />
                                <Route>
                                    <xsl:value-of select="$var:v13" />
                                </Route>
                            </xsl:if>
                            <xsl:variable name="var:v14" select="userCSharp:AddKeyToList(string($var:v9))" />
                            <xsl:variable name="var:v15" select="userCSharp:LogicalEq(string($var:v14) , &quot;true&quot;)" />
                            <xsl:variable name="var:v16" select="userCSharp:LogicalNot(string($var:v15))" />
                            <xsl:if test="string($var:v16)='true'">
                                <xsl:variable name="var:v17" select="Prod/text()" />
                                <Pr>
                                    <xsl:value-of select="$var:v17" />
                                </Pr>
                            </xsl:if>
                            <xsl:variable name="var:v18" select="userCSharp:AddKeyToList(string($var:v9))" />
                            <xsl:variable name="var:v19" select="userCSharp:LogicalEq(string($var:v18) , &quot;true&quot;)" />
                            <xsl:variable name="var:v20" select="userCSharp:LogicalNot(string($var:v19))" />
                            <xsl:if test="string($var:v20)='true'">
                                <xsl:variable name="var:v21" select="Company/text()" />
                                <Company>
                                    <xsl:value-of select="$var:v21" />
                                </Company>
                            </xsl:if>
                        </Record>
                    </xsl:if>
                    <xsl:variable name="var:v22" select="userCSharp:dow(string(Date/text()))" />
                    <xsl:variable name="var:v23" select="userCSharp:LogicalEq(string($var:v22) , &quot;Sunday&quot;)" />
                    <xsl:if test="string($var:v23)='true'">
                        <xsl:variable name="var:v24" select="Amount/text()" />
                        <Sun>
                            <xsl:value-of select="$var:v24" />
                        </Sun>
                    </xsl:if>
                    <xsl:variable name="var:v26" select="userCSharp:dow($var:v25)" />
                    <xsl:variable name="var:v27" select="userCSharp:LogicalEq(string($var:v26) , &quot;Monday&quot;)" />
                    <xsl:if test="string($var:v27)='true'">
                        <xsl:variable name="var:v28" select="Amount/text()" />
                        <Mon>
                            <xsl:value-of select="$var:v28" />
                        </Mon>
                    </xsl:if>
                    <xsl:variable name="var:v29" select="userCSharp:dow($var:v25)" />
                    <xsl:variable name="var:v30" select="userCSharp:LogicalEq(string($var:v29) , &quot;Tuesday&quot;)" />
                    <xsl:if test="string($var:v30)='true'">
                        <xsl:variable name="var:v31" select="Amount/text()" />
                        <Tue>
                            <xsl:value-of select="$var:v31" />
                        </Tue>
                    </xsl:if>
                    <xsl:variable name="var:v32" select="userCSharp:dow($var:v25)" />
                    <xsl:variable name="var:v33" select="userCSharp:LogicalEq(string($var:v32) , &quot;Wednesday&quot;)" />
                    <xsl:if test="string($var:v33)='true'">
                        <xsl:variable name="var:v34" select="Amount/text()" />
                        <Wed>
                            <xsl:value-of select="$var:v34" />
                        </Wed>
                    </xsl:if>
                    <xsl:variable name="var:v35" select="userCSharp:dow($var:v25)" />
                    <xsl:variable name="var:v36" select="userCSharp:LogicalEq(string($var:v35) , &quot;Thursday&quot;)" />
                    <xsl:if test="string($var:v36)='true'">
                        <xsl:variable name="var:v37" select="Amount/text()" />
                        <Thurs>
                            <xsl:value-of select="$var:v37" />
                        </Thurs>
                    </xsl:if>
                    <xsl:variable name="var:v38" select="userCSharp:dow($var:v25)" />
                    <xsl:variable name="var:v39" select="userCSharp:LogicalEq(string($var:v38) , &quot;Friday&quot;)" />
                    <xsl:if test="string($var:v39)='true'">
                        <xsl:variable name="var:v40" select="Amount/text()" />
                        <Friday>
                            <xsl:value-of select="$var:v40" />
                        </Friday>
                    </xsl:if>
                    <xsl:variable name="var:v41" select="userCSharp:dow($var:v25)" />
                    <xsl:variable name="var:v42" select="userCSharp:LogicalEq(string($var:v41) , &quot;Saturday&quot;)" />
                    <xsl:if test="string($var:v42)='true'">
                        <xsl:variable name="var:v43" select="Amount/text()" />
                        <Sat>
                            <xsl:value-of select="$var:v43" />
                        </Sat>
                    </xsl:if>
                </xsl:for-each>
                <xsl:variable name="var:v44" select="userCSharp:init()" />
                <xsl:value-of select="$var:v44" />
            </ns0:Root>

Upvotes: 2

Related Questions