4 Replies Latest reply: Jul 20, 2012 1:39 PM by Eddie Irvine RSS

Add tags to payload before message mapping

Eddie Irvine
Currently Being Moderated

Hi,

 

I've the following problem:

I get the following XML payload:

 

<?xml version="1.0" encoding="UTF-8"?>
<ns0:MT_Pricing xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
xmlns:tns="urn:pricing" xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" 
xmlns:enc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:ns0="urn:pricing">
   <scales>
      <scale>500.00</scale>
      <rate>2.13</rate>
   </scales>
   <scales>
      <scale>1000.00</scale>
      <rate>1.93</rate>
   </scales>
   <amount>2.33</amount>
   <currency>CNY</currency>
   <per>1  </per>
   <uom>KG</uom>
</ns0:MT_Pricing>

 

 

I've the requirement to add the following tags to the XML payload BEFORE performing the message mapping:

 

 <scales>
    <scale>0.00</scale>
    <rate>2.33</rate>
 </scales>

 

 

That means that I've to fill the value of <amount> to <rate>.

How can I do that?

Is it best to use XSLT mapping for that purpose?

 

You're help is much appreciated

  • Re: Add tags to payload before message mapping
    Stefan Grube
    Currently Being Moderated

    You can use graphical mapping tool also. Define a message mapping, where source and target structure is the same, so you can add this mapping as first step to your operation mapping.

     

    Of course you can also use XSLT or Java mapping, but I think it is more convinient to use graphical mapping tool.

    • Re: Add tags to payload before message mapping
      Eddie Irvine
      Currently Being Moderated

      Stefan Grube wrote:

       

      You can use graphical mapping tool also. Define a message mapping, where source and target structure is the same, so you can add this mapping as first step to your operation mapping.

      Hi Stefan,

       

      I'm just trying to do that, but I'm a little bit lost.

      I don't know how to map the <scales> to <scales> and the <amount> to <rate> simultaneously...

       

      For the given example my output should be like that:

       

      <?xml version="1.0" encoding="UTF-8"?>  
      <ns0:MT_Pricing xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   
      xmlns:xsd="http://www.w3.org/2001/XMLSchema"   
      xmlns:tns="urn:pricing" xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"   
      xmlns:enc="http://schemas.xmlsoap.org/soap/encoding/"  
      xmlns:ns0="urn:pricing">  
         <scales>  
            <scale>0.00</scale>  
            <rate>2.33</rate>  
         </scales> 
       <scales>  
            <scale>500.00</scale>  
            <rate>2.13</rate>  
         </scales>  
         <scales>  
            <scale>1000.00</scale>  
            <rate>1.93</rate>  
         </scales>  
         <amount>2.33</amount>  
         <currency>CNY</currency>  
         <per>1  </per>  
         <uom>KG</uom>  
      </ns0:MT_Pricing>  

       

      It would be very kind if you could help me on that!

      • Re: Add tags to payload before message mapping
        Stefan Grube
        Currently Being Moderated

        right-click on node scales, choose "duplicate subtree" from menu. Now you have two entries for scales in target structure. Assign scales to first, amount to second.

        • Re: Add tags to payload before message mapping
          Eddie Irvine
          Currently Being Moderated

          Thanks, Stefan.

           

          As I don't like graphical message mapping (and I also was not able to create it correctly ), I succeeded to map the payload via XSLT mapping:

           

          <?xml version='1.0' encoding='utf-8'?>
          <xsl:stylesheet version="1.0"
          xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
              <xsl:output method="xml" encoding="UTF-8"/>
              <xsl:template match="/">
                  <MT_Pricing>
                      <xsl:if test="MT_Pricing/scales">
                          <scales>
                              <scale>0.00</scale>
                              <rate>
                                  <xsl:value-of select="MT_Pricing/amount" />
                              </rate>
                          </scales>
                      </xsl:if>
                      <xsl:copy-of select="MT_Pricing/scales" />
                      <xsl:copy-of select="MT_Pricing/amount" />
                      <xsl:copy-of select="MT_Pricing/currency" />
                      <xsl:copy-of select="MT_Pricing/per" />
                      <xsl:copy-of select="MT_Pricing/uom" />
                  </MT_Pricing>
              </xsl:template>
          </xsl:stylesheet>

           

           

          But nevertheless thanks for your help.

Actions