locked
Mapping question - get values from a specific node RRS feed

  • Question

  • Hi all,

    My source message contains multiple Address nodes:

    <Source xmlns="namespace_source">
      <Address> 
        <Type>Business</Type>
        <Street>Bakerstreet</Street>
        <City>Springfield</City>
      </Address>
      <Address>
        <Type>Home</Type>
        <Street>7th Avenue</Street>
        <City>Paloozaville</City>
      </Address>
    </Target>

    This needs to be mapped to my target message:

    <Target xmlns="namespace_target"> <BusinessStreet>Bakerstreet</BusinessStreet> <BusinessCity>Springfield</BusinessCity> <HomeStreet>7th Avenue</Homestreet> <HomeCity>Paloozaville</HomeCity> </Target>

    For the fields BusinessStreet and BusinessCity I would have to select the Address node from the source message wherein the Type field is set to Business.

    For the next two fields I need the other Address node having Type set to Home.

    How do I accomplish this?

    Thanks, Nils

    Thursday, April 19, 2012 10:14 AM

Answers

  • Try to use the Value Mapping Flattening functoid. See one example here


    Please mark the post answered your question as answer, and mark other helpful posts as helpful, it'll help other users who are visiting your thread for the similar problem, Regards -Rohit Sharma (http://rohitt-sharma.blogspot.com/)

    • Proposed as answer by Shailesh Kawade Thursday, April 19, 2012 10:57 AM
    • Marked as answer by Nils Gruson Friday, April 20, 2012 7:56 AM
    Thursday, April 19, 2012 10:30 AM
    Moderator
  • Hi all,

    My source message contains multiple Address nodes:

    <Source xmlns="namespace_source">
      <Address> 
        <Type>Business</Type>
        <Street>Bakerstreet</Street>
        <City>Springfield</City>
      </Address>
      <Address>
        <Type>Home</Type>
        <Street>7th Avenue</Street>
        <City>Paloozaville</City>
      </Address>
    </Target>

    This needs to be mapped to my target message:

    <Target xmlns="namespace_target"> <BusinessStreet>Bakerstreet</BusinessStreet> <BusinessCity>Springfield</BusinessCity> <HomeStreet>7th Avenue</Homestreet> <HomeCity>Paloozaville</HomeCity> </Target>

    For the fields BusinessStreet and BusinessCity I would have to select the Address node from the source message wherein the Type field is set to Business.

    For the next two fields I need the other Address node having Type set to Home.

    How do I accomplish this?

    Thanks, Nils

    Hi Nils,

     You can achieve this using the Equals,and value mapping Functoid.

    That is if the Address - > Type is Business, then map BusinessStreet and BusinessCity.

    For the next fields it is just simple as above..


    Don't forget to mark the post as answer or vote as helpful if it does, Regards - Rajasekhar.R

    • Proposed as answer by Shailesh Kawade Thursday, April 19, 2012 10:57 AM
    • Marked as answer by Nils Gruson Friday, April 20, 2012 7:55 AM
    Thursday, April 19, 2012 10:35 AM
  • Try the map as below. Have the looping functoid connected to each of the 4 elements on the target schema. This ensures that you loop for each Address on the source schema. It works but the loop on Address ends up happenning 4 times, instead of once. 

    If you don't like that you can always use a custom xslt. Validate the map below, copy the XSL into notepad and modify it so there's only one foreach loop on the Address, save it and reference it in the map's Custom XSLT path property.

    • Proposed as answer by Anil K Narayan Thursday, April 19, 2012 5:49 PM
    • Marked as answer by Nils Gruson Friday, April 20, 2012 7:56 AM
    Thursday, April 19, 2012 4:29 PM

All replies

  • Try to use the Value Mapping Flattening functoid. See one example here


    Please mark the post answered your question as answer, and mark other helpful posts as helpful, it'll help other users who are visiting your thread for the similar problem, Regards -Rohit Sharma (http://rohitt-sharma.blogspot.com/)

    • Proposed as answer by Shailesh Kawade Thursday, April 19, 2012 10:57 AM
    • Marked as answer by Nils Gruson Friday, April 20, 2012 7:56 AM
    Thursday, April 19, 2012 10:30 AM
    Moderator
  • Hi all,

    My source message contains multiple Address nodes:

    <Source xmlns="namespace_source">
      <Address> 
        <Type>Business</Type>
        <Street>Bakerstreet</Street>
        <City>Springfield</City>
      </Address>
      <Address>
        <Type>Home</Type>
        <Street>7th Avenue</Street>
        <City>Paloozaville</City>
      </Address>
    </Target>

    This needs to be mapped to my target message:

    <Target xmlns="namespace_target"> <BusinessStreet>Bakerstreet</BusinessStreet> <BusinessCity>Springfield</BusinessCity> <HomeStreet>7th Avenue</Homestreet> <HomeCity>Paloozaville</HomeCity> </Target>

    For the fields BusinessStreet and BusinessCity I would have to select the Address node from the source message wherein the Type field is set to Business.

    For the next two fields I need the other Address node having Type set to Home.

    How do I accomplish this?

    Thanks, Nils

    Hi Nils,

     You can achieve this using the Equals,and value mapping Functoid.

    That is if the Address - > Type is Business, then map BusinessStreet and BusinessCity.

    For the next fields it is just simple as above..


    Don't forget to mark the post as answer or vote as helpful if it does, Regards - Rajasekhar.R

    • Proposed as answer by Shailesh Kawade Thursday, April 19, 2012 10:57 AM
    • Marked as answer by Nils Gruson Friday, April 20, 2012 7:55 AM
    Thursday, April 19, 2012 10:35 AM
  • I think the problem lies in the fact that my source message con contain 2 address nodes (business and home) whereas the target message should only contain the root node with the aforementioned fields. If I use the Equal functoid in combination with the Value functoid, only the fields of the last Address node get mapped. The mapper sees two Address nodes in the source message. When processing the second Address node, it checks the Type field which is Home. The fields HomeStreet and HomeCity are filled with the correct values. Because the Type field of the current Address node doesn't match the check for 'Type equals Business' the fields BusinessStreet and BusinessCity are not mapped.

    I think I need something like this:

    - Get the Address node for Business

    - Use that node for mapping the fields BusinessStreet and BusinessCity

    - Get the Address node for Home

    - Use that node for mapping the fields HomeStreet and HomeCity

    Any pointers?

    Thanks, Nils

    Thursday, April 19, 2012 1:07 PM
  • Try the map as below. Have the looping functoid connected to each of the 4 elements on the target schema. This ensures that you loop for each Address on the source schema. It works but the loop on Address ends up happenning 4 times, instead of once. 

    If you don't like that you can always use a custom xslt. Validate the map below, copy the XSL into notepad and modify it so there's only one foreach loop on the Address, save it and reference it in the map's Custom XSLT path property.

    • Proposed as answer by Anil K Narayan Thursday, April 19, 2012 5:49 PM
    • Marked as answer by Nils Gruson Friday, April 20, 2012 7:56 AM
    Thursday, April 19, 2012 4:29 PM
  • Of course my example here was a simplification of a more complex mapping. Anyhow, inspecting the generated xsl did a lot. It turned out that my map wasn't functioning correctly due to the direct link from another node which led to a for-each loop on another element in the structure. Therefore, the second Address node was ignored.

    I corrected the mapping and now it's working with Equal and Value Mapping functoids.

    Thanks.

    Friday, April 20, 2012 8:02 AM