cancel
Showing results for 
Search instead for 
Did you mean: 

Mapping problem

Former Member
0 Kudos

Hi all.

I've made a mapping and basicly the mapping works as follow. I get a sourcestructure in and everytime there will be a P01 in the target structure. But when there comes a P05 in the source there should be an extra P01 with that P05 inside in the target structure. So if the P01 that comes in have an P05 inside the structure then there should be 2 P01's created in the target structure. 1 without the P05 and 1 with the P05. The mappings are also sorted by the radNo.

Source message:

<?xml version="1.0" encoding="UTF-8"?>
 
<ns0:rtptest xmlns:ns0="http://">
   <messNo>123</messNo>
   <P01>
      <radNo>1</radNo>
      <P05>
         <P05data>11</P05data>
      </P05>
      <PXX>
         <PXXdata>111</PXXdata>
      </PXX>
   </P01>
   <P01>
      <radNo>3</radNo>
      <P05>
         <P05data>33</P05data>
      </P05>
      <PXX>
         <PXXdata>333</PXXdata>
      </PXX>
   </P01>
   <P01>
      <radNo>2</radNo>
      <PXX>
         <PXXdata>222</PXXdata>
      </PXX>
   </P01>
</ns0:rtptest>

The result looks like this:

<?xml version="1.0" encoding="UTF-8"?>
 
<ns0:rtptest xmlns:ns0"http://">
   <messNo>123</messNo>
   <P01>
   <radNo>1</radNo>
      <PXX>
      <PXXdata>111</PXXdata>
      </PXX>
   </P01>
   <P01>
   <radNo>2</radNo>
      <PXX>
      <PXXdata>222</PXXdata>
      </PXX>
   </P01>
   <P01>
   <radNo>3</radNo>
      <PXX>
      <PXXdata>333</PXXdata>
      </PXX>
   </P01>
   <P01>
   <radNo>1</radNo>
      <P05>
      <P05data>11</P05data>
      </P05>
   </P01>
   <P01>
   <radNo>3</radNo>
      <P05>
      <P05data>33</P05data>
      </P05>
   </P01>
</ns0:rtptest>

As you see the P01's with the P05's inside comes after the first P01's that have no P05's inside them. I would like tho get them like follows:

<?xml version="1.0" encoding="UTF-8"?>
 
<ns0:rtptest xmlns:ns0"http://">
   <messNo>123</messNo>
   <P01>
   <radNo>1</radNo>
      <PXX>
      <PXXdata>111</PXXdata>
      </PXX>
   </P01>
   <P01>
   <radNo>1</radNo>
      <P05>
      <P05data>11</P05data>
      </P05>
   </P01>
   <P01>
   <radNo>2</radNo>
      <PXX>
      <PXXdata>222</PXXdata>
      </PXX>
   </P01>
   <P01>
   <radNo>3</radNo>
      <PXX>
      <PXXdata>333</PXXdata>
      </PXX>
   </P01>
   <P01>
   <radNo>3</radNo>
      <P05>
      <P05data>33</P05data>
      </P05>
   </P01>
</ns0:rtptest>

I've done the mapping by making 2 P01's in the target structure and creating the second one when there are any data inside the P05 in the source structure. Now the question are. Can i sort everything by radNo or do I need to make major changes to the mappings? I migth need to use XSLT-mappings?

Would be great if somebody could give me some clues on if this is possible and if it is how to make it happen.

BR Andreas

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

I put together a quick XSLT to achieve the same, just modify it as per your requirement.

<xsl:transform version="1.0"

xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ns0="http://">

<xsl:output encoding="UTF-8" indent="yes" method="xml" version="1.0"/>

<xsl:template match="ns0:rtptest">

<ns0:rtptest>

<xsl:for-each select="P01[count(PXX)>0]">

<P01>

<radNo><xsl:value-of select="radNo"/></radNo>

<PXX>

<PXXdata>

<xsl:value-of select="PXX/PXXdata"/>

</PXXdata>

</PXX>

</P01>

</xsl:for-each>

<xsl:for-each select="P01[count(P05)>0]">

<P01>

<radNo><xsl:value-of select="radNo"/></radNo>

<P05>

<P05data>

<xsl:value-of select="P05/P05data"/>

</P05data>

</P05>

</P01>

</xsl:for-each>

</ns0:rtptest>

</xsl:template>

</xsl:transform>

Former Member
0 Kudos

That produced the same result that I already have.

I wanted this result:

<?xml version="1.0" encoding="UTF-8"?>
 
<ns0:rtptest xmlns:ns0"http://">
   <messNo>123</messNo>
   <P01>
   <radNo>1</radNo>
      <PXX>
      <PXXdata>111</PXXdata>
      </PXX>
   </P01>
   <P01>
   <radNo>1</radNo>
      <P05>
      <P05data>11</P05data>
      </P05>
   </P01>
   <P01>
   <radNo>2</radNo>
      <PXX>
      <PXXdata>222</PXXdata>
      </PXX>
   </P01>
   <P01>
   <radNo>3</radNo>
      <PXX>
      <PXXdata>333</PXXdata>
      </PXX>
   </P01>
   <P01>
   <radNo>3</radNo>
      <P05>
      <P05data>33</P05data>
      </P05>
   </P01>
</ns0:rtptest>

Former Member
0 Kudos

In order to achieve that you will need 2 XSLT, call the XSLT one after the other in the Interface Mapping.

First XSLT

<xsl:transform version="1.0"

xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ns0="http://">

<xsl:output encoding="UTF-8" indent="yes" method="xml" version="1.0"/>

<xsl:template match="ns0:rtptest">

<ns0:rtptest>

<messNo><xsl:value-of select="messNo"/></messNo>

<xsl:for-each select="P01[count(PXX)>0]">

<P01>

<radNo><xsl:value-of select="radNo"/></radNo>

<PXX>

<PXXdata>

<xsl:value-of select="PXX/PXXdata"/>

</PXXdata>

</PXX>

</P01>

</xsl:for-each>

<xsl:for-each select="P01[count(P05)>0]">

<P01>

<radNo><xsl:value-of select="radNo"/></radNo>

<P05>

<P05data>

<xsl:value-of select="P05/P05data"/>

</P05data>

</P05>

</P01>

</xsl:for-each>

</ns0:rtptest>

</xsl:template>

</xsl:transform>

Second XSLT

<xsl:transform version="1.0"

xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ns0="http://">

<xsl:output encoding="UTF-8" indent="yes" method="xml" version="1.0"/>

<xsl:template match="ns0:rtptest">

<ns0:rtptest>

<xsl:for-each select="P01">

<xsl:sort select="radNo"/>

<xsl:copy-of select="."/>

</xsl:for-each>

</ns0:rtptest>

</xsl:template>

</xsl:transform>

BR

Sameer

former_member194786
Active Contributor
0 Kudos

Hi Kalle,

I assume from your requirment that your source structure wil look like:

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

<ns0:rtptest xmlns:ns0="http://">

<messNo>123</messNo>

<P01> .... <0...unbounded>

<radNo> </radNo>

<PXX> <1...onbounded>

<PXXdata></P05data>

</PXX>

Now if my field PXX is P05 you need to create another P01 in the target structure. You can try the following logic for this:

(exists-> P05) Or (exists->P01)->createIf->P01

I think this should help you get the desired output.

Try it and let us know.

Regards,

Sanjeev.

Former Member
0 Kudos

PXX are not equal to P05.

PXX represent P02, P03, P04....

Everything except P05.

Not sure if I understand your solution.

In the targetstructure I have 2 P01's. One get created every time and the other get created when there are a P05 present in the source P01.

former_member194786
Active Contributor
0 Kudos

I just meant that use the condition as suggested:

(exists-> P05) Or (exists->P01)->createIf->P01

This will create a P01 on the target side for both P01's and also the P05's occuring.

I guess your P01 are created based upon the P01 occuding in the source structure and also for each P05 occuring. So this condition will create a P01 for each of them.

Hope its clearer now.

Former Member
0 Kudos

Hi,

With XSLT Mqpping this knd of sequecning will be bit easy.

You can go for either XSLT Mapping or even try for sorting the whole P01 structure based on <radNo>

OR

Make one Advanced UDF and try to re-shuffle the Result-list of all fields. But this will be more complicated than going for Sorting or may be for XSLT mapping.

Thanks

Swarup