none
adding an element with an attribute to destination schema that doesn't exist on source schema RRS feed

  • Question

  • I have source schema which looks something like below:

    source schema
    ------------------
     name                    //attribute
     address1                //attribute
     address2                //attribute
     city                       //attribute

    I need to map it to a destination schema which looks like below:

    destination schema
    --------------------
    employee                  //record (repeating element)
      fieldname                //attribute
      type                       //attribute

    After mapping, the xml would look like below: 

    <employee fieldname= 'name' type='string'>
    <employee fieldname= 'address1' type ='string'>
    <employee fieldname= 'address2' type ='string'>
    <employee fieldname= 'city' type ='string'>

    (fieldname exists in source schema, but 'type'  doesn't. basing on the fieldname, I add it on the destination schema using ValueMapping functoid )And I am able to do it successfully, but my question is, I need to add a field called 'salary' of type 'double' to the destination schema similar to the other values

    <employee fieldname= 'salary' type ='double'>

    But salary doesn't exist in 'source' schema,  and it needs to be there in destination schema associated with the attribute 'type='dcouble''   How can I accomplish this? Appreciate any help. thanks!!

    Monday, December 29, 2014 8:39 PM

Answers

  • Hi Anne,

    For your requirement, all you need is Table Looping functiod and Table Extractor functiod.

    In this example, I am not using the value mapping functiod (you can also use it, but I prefer to make this sample easier for you to understand) so using a “string” as constant.

    When you mean by you want

    <employee fieldname= 'name' type='string'>

    <employee fieldname= 'address1' type ='string'>

    <employee fieldname= 'address2' type ='string'> <employee fieldname= 'city' type ='string'>

    I assume you’re looking for something like this

    <employee fieldname= 'ValueOfName' type='string'>

    <employee fieldname= 'ValueOfAddress1' type ='string'>

    <employee fieldname= 'ValueOfAddress2' type ='string'>

    <employee fieldname= 'ValueOfCity' type ='string'>

    Or if you just need field names not the value of the fields, you can still do what you want with the way you do now but using Table Looping functiod and Table Extractor functiod.

    Let me explain this.

    1. Use Table Looping functiod with following parameters:
      1. 5 = You need 5 records in output i.e. name, address1,address2,city and salary.
      2. 2 = you need 2 columns. i.e. fieldname and type.
      3. Link from 'name' in source schema. Here I have just linked the 'name' from source schema, so this will have VALUE-of-Name element/attribute. Or if you can want just the field name, you can use the way you’re using to get the field name.
      4. Repeat the above step for all the rest of the fields. I have linked address1, address2 and city.
      5. 7<sup>th</sup> parameter is “string” as constant, which I will be passing to “type” attribute in destination. Again you can use value mapping functiod as you do. If you use value mapping functiod, then rest of the parameter shall be value mapping functiod.
      6. Then I add last two paraters “salary” and “double” as constants, which I will be using to add the new record. Below image show the parameters for Table looping functiond:
    2. Now select the “Configure Table Looping grid” property and map as shown. Give a closer look to the way how this grid has been mapped. Last record in the grid shows the additional record which you want to add with “salary” and “double”
    3. Now add “Table Extractor functiod”, set its first parameter to “Table looping” and second parameter as “1”
    4. Now another “Table Extractor functiod”, set its first parameter to “Table looping” and second parameter as “2”. Below image show the Table Txtrator functiods parameters:
    5. Now link the Table Looping functiod to “employee” record in destination schema.

    Use the above you will get the output as you wanted. Following is the output, note: as mentioned in the fieldName attribute I have the value of the source fields/attributes since I have used the direct link from soruce in Table Looping functiod parameters, you can use the link which is producing the value for you now for fieldname:

      <employee fieldName="name_0" type="string"></employee>
      <employee fieldName="address1_1" type="string"></employee>
      <employee fieldName="address2_2" type="string"></employee>
      <employee fieldName="city_3" type="string"></employee>
      <employee fieldName="salary" type="double"></employee>


     

     



    If this answers your question please mark it accordingly. If this post is helpful, please vote as helpful by clicking the upward arrow mark next to my reply.


    • Edited by M.R.Ashwin Prabhu Tuesday, December 30, 2014 1:18 PM
    • Marked as answer by Angie Xu Monday, January 5, 2015 2:39 AM
    Tuesday, December 30, 2014 1:16 PM
  • Following the map image for your reference:



    Following is the Table Looping functiod's grid configuration view;



    If this answers your question please mark it accordingly. If this post is helpful, please vote as helpful by clicking the upward arrow mark next to my reply.


    • Edited by M.R.Ashwin Prabhu Tuesday, December 30, 2014 1:21 PM
    • Marked as answer by Angie Xu Monday, January 5, 2015 2:39 AM
    Tuesday, December 30, 2014 1:18 PM

All replies

  • Understand it this way, Destination is in no way dependent on soource schema. Source schema only helps provide values and sometimes similar strcuture to help create destination easily.

    You can use string concatenate functoid without any source and map it to destination filedname node and put whatever value inside string concat (in your case 'Salary').

    Try and let knw.

    Thanks

    Tuesday, December 30, 2014 1:33 AM
  • Hi Annee,

    Just add the salary node with data type double in your destination schema which is in your case employee schema . Reopen the map ,you will be able to see salary node populated .

    You can set any default value for salary  in schema node or you can set its value in Map as per your requirement .

    Thanks

    Abhishek

    Tuesday, December 30, 2014 5:01 AM
  • User wants to add value as "Salary" to existing attribute "fieldname", not to create a new node in the destination schema.

    Hi Annee,

    You can use scripting functoid. The scripting functoid of "Inline XSLT" type. You can refer to my code and build your own based on your output XML Structure.  

    <xsl:for-each select="//Orders/Order">
    <xsl:element name="Order">
    <xsl:element name="Ordernumber"><xsl:value-of select="Ordernumber" /></xsl:element>
    <xsl:element name="OrderAmount"><xsl:value-of select="Amount" /></xsl:element>
    </xsl:element>
    </xsl:for-each>
    
    <xsl:element name="Order">
        <xsl:element name="Ordernumber">400</xsl:element>
        <xsl:element name="OrderAmount">40</xsl:element>
    </xsl:element>

    Basically, the for-each creates line in the output according to the input and the xsl:element after the for-each creates the new node.

    Your existing mapping requires no change. 

    Regards,

    Rachit




    Tuesday, December 30, 2014 5:44 AM
    Moderator
  • If you want to create new node The easiest way to do that would be with an Inline XSLT Scripting Functoid.

    In your case, the XSLT would be just static XML content containing the hard coded EntityMemberAttribute.

    Map the dynamic one as usual, then connect the Scripting Functoid also to EntityMemberAttribute and you should get both.

    Its being well described in below blog

    http://vijaymodi.wordpress.com/2008/06/02/biztalk-create-multiple-nodes-in-destination-schema-using-xslt-in-map-file/

    Thanks

    Abhishek

    Tuesday, December 30, 2014 6:03 AM
  • Hi Anne,

    For your requirement, all you need is Table Looping functiod and Table Extractor functiod.

    In this example, I am not using the value mapping functiod (you can also use it, but I prefer to make this sample easier for you to understand) so using a “string” as constant.

    When you mean by you want

    <employee fieldname= 'name' type='string'>

    <employee fieldname= 'address1' type ='string'>

    <employee fieldname= 'address2' type ='string'> <employee fieldname= 'city' type ='string'>

    I assume you’re looking for something like this

    <employee fieldname= 'ValueOfName' type='string'>

    <employee fieldname= 'ValueOfAddress1' type ='string'>

    <employee fieldname= 'ValueOfAddress2' type ='string'>

    <employee fieldname= 'ValueOfCity' type ='string'>

    Or if you just need field names not the value of the fields, you can still do what you want with the way you do now but using Table Looping functiod and Table Extractor functiod.

    Let me explain this.

    1. Use Table Looping functiod with following parameters:
      1. 5 = You need 5 records in output i.e. name, address1,address2,city and salary.
      2. 2 = you need 2 columns. i.e. fieldname and type.
      3. Link from 'name' in source schema. Here I have just linked the 'name' from source schema, so this will have VALUE-of-Name element/attribute. Or if you can want just the field name, you can use the way you’re using to get the field name.
      4. Repeat the above step for all the rest of the fields. I have linked address1, address2 and city.
      5. 7<sup>th</sup> parameter is “string” as constant, which I will be passing to “type” attribute in destination. Again you can use value mapping functiod as you do. If you use value mapping functiod, then rest of the parameter shall be value mapping functiod.
      6. Then I add last two paraters “salary” and “double” as constants, which I will be using to add the new record. Below image show the parameters for Table looping functiond:
    2. Now select the “Configure Table Looping grid” property and map as shown. Give a closer look to the way how this grid has been mapped. Last record in the grid shows the additional record which you want to add with “salary” and “double”
    3. Now add “Table Extractor functiod”, set its first parameter to “Table looping” and second parameter as “1”
    4. Now another “Table Extractor functiod”, set its first parameter to “Table looping” and second parameter as “2”. Below image show the Table Txtrator functiods parameters:
    5. Now link the Table Looping functiod to “employee” record in destination schema.

    Use the above you will get the output as you wanted. Following is the output, note: as mentioned in the fieldName attribute I have the value of the source fields/attributes since I have used the direct link from soruce in Table Looping functiod parameters, you can use the link which is producing the value for you now for fieldname:

      <employee fieldName="name_0" type="string"></employee>
      <employee fieldName="address1_1" type="string"></employee>
      <employee fieldName="address2_2" type="string"></employee>
      <employee fieldName="city_3" type="string"></employee>
      <employee fieldName="salary" type="double"></employee>


     

     



    If this answers your question please mark it accordingly. If this post is helpful, please vote as helpful by clicking the upward arrow mark next to my reply.


    • Edited by M.R.Ashwin Prabhu Tuesday, December 30, 2014 1:18 PM
    • Marked as answer by Angie Xu Monday, January 5, 2015 2:39 AM
    Tuesday, December 30, 2014 1:16 PM
  • Following the map image for your reference:



    Following is the Table Looping functiod's grid configuration view;



    If this answers your question please mark it accordingly. If this post is helpful, please vote as helpful by clicking the upward arrow mark next to my reply.


    • Edited by M.R.Ashwin Prabhu Tuesday, December 30, 2014 1:21 PM
    • Marked as answer by Angie Xu Monday, January 5, 2015 2:39 AM
    Tuesday, December 30, 2014 1:18 PM
  • thank u all for the resposnes!

    And thanks a lot Ashwin for the detailed explanation including the screenshots.

    Monday, January 5, 2015 5:32 PM
  • Thanks again Ashwin for the solution with clear explanation.

    I have one question though: As u pointed, I am expecting the output in following format:

    <employee fieldName="name" type="string">Annee</employee>

    Ur solution gives the output in following format:

      <employee fieldName="Annee" type="string"/>


    So I used a constant string for the column1 and managed to get the following output:

    <employee fieldName="name" type="string"/>


    But using the same table looping functoid, how do I map the name value of the attribute to the field so I get the desired output as: <employee fieldName="name" type="string">Annee</employee>

    Appreciate your help! Thanks!!

    Wednesday, January 7, 2015 8:31 PM