cancel
Showing results for 
Search instead for 
Did you mean: 

Mapping Issue

Former Member
0 Kudos

Hi,

I want to Map following structures:

Source:

Header

offers

item

prices

item

price1

price2

price3

item

price4

price5

price6

item

prices

item

price7

price8

price9

item

price10

price11

Target:

Result

Offer

price1

price2

price3

Offer

price7

price8

price9

Please Help.

Thanks in advance.

Beena

Accepted Solutions (0)

Answers (1)

Answers (1)

justin_santhanam
Active Contributor
0 Kudos

Beena,

Whats the issue in that? You can map directly right? On seeing your example it seems pretty straight forward!! Can u please provide some more insight about the problem.

Thanks for understanding.

raj.

Former Member
0 Kudos

Raj,

There are 3 repeating nodes in source structure.

offers, prices, price.

Target Structure should create 1 node for each offer node.

All the 'price' nodes under first 'prices' node i.e. price1, price2, price3 should be the children of offer node in target structure.

price4, price5, price6 should be skipped.

It is possible that there are no prices node under offers node in source structure.

i.e.

offers

item

prices

item

prices

item

price1

price2

Please help.

Thanks,

Beena.

justin_santhanam
Active Contributor
0 Kudos

Beena,

Really sorry. The structure is still confusing , can u please give the proper structure with occurrences. Target is fine. But source I couldn't able to figure out. So please give the source structure with occurrence.

Thanks.

raj.

Former Member
0 Kudos

Hi Beena,

Agree with Raj. Could you please provide one example with XML Tag ?

Thanks

Shubhankar

Former Member
0 Kudos

Hi,

And you expected to understand all this looking at your post!!!!!

Former Member
0 Kudos

Raj,

Source Structure:

Offers (0..1)

item (0...unbounded)

prices (0..1)

item (0...unbounded)

price (0..unbounded)

Target Structure:

Offer (0..unbounded)

price (0..unbounded)

I need to map all 'price' nodes under first item of 'prices' node in source structure to offer/price of target structure.

Offers/item/prices/item(0)/price --> offer/price

There might be no items under 'prices' node.

Thanks,

Beena.

Former Member
0 Kudos

Sorry,

I lost all formatting of source structure while posting.

Thanks,

Beena.

Former Member
0 Kudos

Hello Beena,

Check the source structure if I got that correct.

<b>Source Structure</b>

<?xml version="1.0" encoding="UTF-8"?>
<offers>
	<item>
		<prices>
			<item>
				<price>price1</price>
				<price>price2</price>
				<price>price3</price>
			</item>
			<item>
				<price>price4</price>
				<price>price5</price>
				<price>price6</price>
			</item>
		</prices>
		<prices>
			<item>
				<price>price7</price>
				<price>price8</price>
				<price>price9</price>
			</item>
			<item>
				<price>price10</price>
				<price>pric11</price>
				<price>price12</price>
			</item>
		</prices>
		<prices>
		</prices>
	</item>
</offers>

<b>Then the Mapping.</b>

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:output indent="yes" media-type="XML" encoding="UTF-8"/>

	<xsl:template match="/">
		<xsl:element name="Result">
			<xsl:for-each select="offers/item/prices">
				<xsl:element name="Offer">
					<xsl:for-each select="item[1]/price">
						<xsl:element name="price">
							<xsl:value-of select="."/>
						</xsl:element>
					</xsl:for-each>
				</xsl:element>
			</xsl:for-each>
		</xsl:element>
	</xsl:template>
</xsl:stylesheet>

<b>Last the target</b>.

<?xml version='1.0' encoding='UTF-8' ?>
<Result>
  <Offer>
    <price>price1</price>
    <price>price2</price>
    <price>price3</price>
  </Offer>
  <Offer>
    <price>price7</price>
    <price>price8</price>
    <price>price9</price>
  </Offer>
  <Offer/>
</Result>

In the source if there are not items under prices then an empty tag is created if this is not what you expect change the code accordingly.

Regards,

Former Member
0 Kudos

Hi,

could you copy paste ur source xml and give us a sample of the target xml u expect for that source...

Former Member
0 Kudos

Hi Beena,

I have written one UDF

prices===>Offer

price

====>MyCopyByValue ===>Prices

item

It is working that is for sure and I have test. Second time I am writing my UDF and so it may not be good programming.

Please give me the points.

Thanks

Shubhankar


public void MyCopyByValue(String[] a,String[] b,ResultList result,Container container){
int p=0;
int cnt1=0;
int cnt2=0;

while(!a[p].equals(result.CC))
{result.addValue(a[p]);
 p++;
 }
for (int i=0; i<b.length; i++)
{int cnt3=0;
   if(b<i>.equals(result.CC))
   {
      cnt1++;
      cnt2=i +1 -cnt1;
      //result.addValue(""+cnt2);
       for (int q=0; q<a.length;q++)
      {
         if(a[q].equals(result.CC))
         {
          cnt3++;
          if(cnt2 == cnt3){
            q++;
          result.addContextChange();
            while(!a[q].equals(result.CC))
         {result.addValue(a[q]);
            q++;
}
}
}
}
}
}
}

Former Member
0 Kudos

Thanks SriHari,

That solves the problem.

But I dont want to use XSLT mapping here and achieve this through message mapping only.

The structure I have given is part of one big structure and it is easier to use message mapping here as I am mapping RFC Response.

Thanks,

Beena.

Former Member
0 Kudos

Thanks Shubhankar,

Could you please tell me what is a and b?

Thanks,

Beena.

Former Member
0 Kudos

Hello,

I have written one UDF (type queue) for this.

Offers/item/prices/item/price with context changed to Offers/item/prices = a

apply mapwith default to this with value 'SUPPRESS' (in case there are no items under prices)

Offers/item/prices/item/price = b

int i = 0;

int j = 0;

boolean flag = false;

while (i < a.length)

{

if (a<i>.equals(b[j]) && flag == false)

{ result.addValue(a<i>); i+; j+; continue;}

if (a<i>.equals("SUPPRESS"))

{ result.addValue(ResultList.SUPPRESS);result.addValue(ResultList.CC); i+=2; continue;}

if (flag == false && b[j].equals(ResultList.CC) && !a<i>.equals(ResultList.CC))

{flag = true; j++;continue;}

if (flag == true && !b[j].equals(ResultList.CC) && !a<i>.equals(ResultList.CC))

{i+; j+;continue;}

if (flag == true && b[j].equals(ResultList.CC) && a<i>.equals(ResultList.CC))

{flag = false; result.addValue(a<i>); i+; j+;continue;}

Please let me know if there are any better ways of doing this?

Thanks,

Beena.

Former Member
0 Kudos

Hi Beena,

a is price and b is item.

But UDF can be optimised. is it now working?

Thanks

Shubhankar

Former Member
0 Kudos

Hello Beena,

Looking at the structure below...

Offers (0..1)

item (0...unbounded)

prices (0..1)

item (0...unbounded)

price (0..unbounded)

why dont you change the occurences for item under prices from (0...unbounded) to (0..1) which means at any point of time you will have only one item that is all we want and its a direct map, if I am not wrong.

Offers (0..1)

item (0...unbounded)

prices (0..1)

<b>item (0...1)</b>

price (0..unbounded)

Regards,

Former Member
0 Kudos

Hello SriHari,

That's good suggestion.

but the given structure is RFC Response and prices is a table.

Also price is a complex structure with 5 elements under it.

i.e.

<price>

<AvgPrice>

<Date> .....

</price>

Thanks,

Beena.