CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Nov 2004
    Posts
    3

    Question Data mapping (xml-to-xml) using with Mapforce

    I am using MapForce data mapping tool.

    i have below XML data as Source which is having duplicate elements like code, name:

    <?xml version="1.0" encoding="UTF-8"?>

    <CustomerDetails xmlns="http://www.tdxgroup.com/namespace"

    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

    xsi:schemaLocation="http://www.tdxgroup.com/namespace:\TDX\mapforce\example2\Customer1.xsd">



    <Customer>

    <Code>C001</Code>

    <Name>Cust1</Name>

    <Phone>88888888</Phone>

    </Customer>



    <Customer>

    <Code>C001</Code>

    <Name>Cus1</Name>

    <Phone>77777777</Phone>

    </Customer>



    <Customer>

    <Code>C001</Code>

    <Name>Cust1</Name>

    <Phone>66666666</Phone>

    </Customer>



    <Customer>

    <Code>C002</Code>

    <Name>Cust2</Name>

    <Phone>55555555</Phone>

    </Customer>


    <Customer>

    <Code>C003</Code>

    <Name>Cust3</Name>
    <Phone>55555555</Phone>
    </Customer>

    </CustomerDetails>

    This dupication need to be remove from source to target xml as given below Target xml data:

    <CustomerDetails xmlns="http://tdxgroup.com/namespace"

    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

    xsi:schemaLocation="http://tdxgroup.com/namespace:\TDX\mapforce\example2\Customer2.xsd">



    <Customer>

    <Code>C001</Code>

    <Name>Cust1</Name>

    <Phones>
    <Phone>88888888</Phone>

    <Phone>77777777</Phone>

    <Phone>66666666</Phone>

    </Phones>

    </Customer>

    <Customer>
    <Code>C002</Code>

    <Name>Cust2</Name>
    <Phones>
    <Phone>11111111</Phone>
    </Phones>

    </Customer>

    </CustomerDetails>

    Is this possible through MapForce tool, if yes then please provide solution on this problem.

    For your reference please find the attachment.


    Thanks in adavance.



    Regards

    AK
    Attached Files Attached Files

  2. #2
    Join Date
    May 2003
    Location
    Denmark
    Posts
    1,315

    Re: Data mapping (xml-to-xml) using with Mapforce

    This seems very simmilar to your other post http://www.codeguru.com/forum/showthread.php?t=319622

    No need to post the same question twice.
    The biggest problem encountered while trying to design a system that was completely foolproof,
    was, that people tended to underestimate the ingenuity of complete fools.
    Douglas Adams

  3. #3
    Join Date
    Oct 2004
    Posts
    107

    Re: Data mapping (xml-to-xml) using with Mapforce

    ? No, this is a different question altogether. You'd have to solve this one to use the answer to the next one...

    I don't believe this is achievable with mapforce (not simply anyways.) I recommend using the Muenchian grouping method. http://www.jenitennison.com/xslt/gro...muenchian.html
    ...
    <xsl:key name="customer-by-code" match="Customer" use="Code" />
    ..
    <xsl:for-each select="Customer[count(. | key('customer-by-code', Code)[1]) = 1]">
    <xsl:copy-of select="Code"/>
    <xsl:copy-of select="Name"/>
    <Phones>
    <xsl:for-each select="key('customer-by-code', Code)">
    <xsl:copy-of select="Phone"/>

  4. #4
    Join Date
    Nov 2004
    Posts
    3

    Unhappy Re: Data mapping (xml-to-xml) using with Mapforce

    Hi khp,

    This is different query but all together, i am desperately looking help for this.

    jkmyoung : Thanks for your quick reponse.

    you are right you understood what i need, i didn't understand your code could you kindly explain with more details with any example.

    I want to get this only using with mapforce.

    If somebody knows solution about this, please post as early as possible.

    Thanks in advance

    Regards
    Ashok

  5. #5
    Join Date
    Oct 2004
    Posts
    107

    Re: Data mapping (xml-to-xml) using with Mapforce

    I would have suggested posting on the Altova forums, but I see you've already done that... There are 2 major problems here:
    1. Finding the unique names (or Codes).
    2. Finding the Person elements with this name.

    I can't see a way to do this without using a custom xslt library function. Tools - Options - Libraries - Add - (xslt file)

    Put this in the xslt file you're adding.
    <xsl:template name="firstPerson">
    <!-- returns true if this is the first person with this name -->
    <xsl:param name="Person"/>
    <xsl:for-each select="$Person">
    <xsl:choose>
    <xsl:when test="not(preceding-sibling::Person[Name=$Person/Name])">true</xsl:when>
    <xsl:otherwise>false</xsl:otherwise>
    </xsl:choose>
    </xsl:for-each>
    </xsl:template>

    Use this as a filter condition, as to whether you want a new result person or not.
    Can't think of how to do the 2nd part in mapforce... Really, using a custom XSLT sheet for this one transformation is the way to go, but then you'd have to learn xslt. Maybe someone else has a better idea.
    Last edited by jkmyoung; November 29th, 2004 at 06:50 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured