on 09-12-2007 9:54 PM
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
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
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.
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,
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++;
}
}
}
}
}
}
}
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.
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,
User | Count |
---|---|
78 | |
10 | |
9 | |
7 | |
6 | |
6 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.