on 06-04-2008 12:47 PM
Hi all.
Have the following situation.
The source message can look something like this.
<?xml version="1.0" encoding="UTF-8"?>
<ns0:sourcerecord xmlns:ns0="http:">
<s_record>
<ponum>1</ponum>
<polinenum>1</polinenum>
</s_record>
<s_record>
<ponum>2</ponum>
<polinenum>1</polinenum>
</s_record>
<s_record>
<ponum>1</ponum>
<polinenum>4</polinenum>
</s_record>
<s_record>
<ponum>1</ponum>
<polinenum>3</polinenum>
</s_record>
<s_record>
<ponum>2</ponum>
<polinenum>3</polinenum>
</s_record>
<s_record>
<ponum>2</ponum>
<polinenum>2</polinenum>
</s_record>
</ns0:sourcerecord>
And i want the following result at the target.
<?xml version="1.0" encoding="UTF-8"?>
<ns0:targetrecord xmlns:ns0="http:">
<t_record>
<ponum>1</ponum>
<linerec>
<polinenum>1</polinenum>
<linerec>
</linerec>
<polinenum>3</polinenum>
<linerec>
</linerec>
<polinenum>4</polinenum>
</linerec>
</t_record>
<t_record>
<ponum>2</ponum>
<linerec>
<polinenum>1</polinenum>
<linerec>
</linerec>
<polinenum>2</polinenum>
<linerec>
</linerec>
<polinenum>3</polinenum>
</linerec>
</t_record>
</ns0:targetrecord>
As you see the fields coming in a node with the same ponum should be collected in ansubnode to for the ponum and sorted. The sort are no problem but the big poblem I have are to get all the rigth fields in the same node.
I hope somebody can help me.
BR
Andreas
Andreas,
Please see the below snapshot and let me know if it helps!
http://www.flickr.com/photos/23855877@N07/2551290946/sizes/o/
http://www.flickr.com/photos/23855877@N07/2551290948/sizes/o/
http://www.flickr.com/photos/23855877@N07/2551290950/sizes/o/
http://www.flickr.com/photos/23855877@N07/2551290952/sizes/o/
Results-http://www.flickr.com/photos/23855877@N07/2551290954/sizes/o/
Thanks,
raj.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Andreas,
here you are tring to group the records by ponum, so you nedd to use the below udf in your graphical mapping.
Give the name of the udf as "groupingByPonum" with the cache type queue and two agguments ponum,polinenum:
public groupingByPonum(String[] ponum,String[] polinenum,ResultList result,Container container) {
int i,j=0,k=0,i1,j1;
Vector V[]=new Vector[ponum.length];
String[] pos= new String[ponum.length]; String t=new String();
for(i=0;i<ponum.length;i++) {
for(j=0;j<k;j++) {
if(pos[j].equals(ponum<i>)) break;
}
if(j==k) {
pos[k]=new String(ponum<i>); k++;
V[j]=new Vector();
}
V[j].addElement(polinenum<i>);
}
Vector temp=new Vector();
for(i=0;i<=j;i++) {
for(i1=1;i1<V<i>.size();i1++) {
for(j1=0;j1<i1;j1++) {
if(Integer.parseInt(V<i>.elementAt(j1).toString())>Integer.parseInt(V<i>.elementAt(i1).toString())) {
t=(String)V<i>.elementAt(i1); V<i>.removeElementAt(i1); V<i>.insertElementAt(V<i>.elementAt(j1), i1); V<i>.removeElementAt(j1); V<i>.insertElementAt(t, j1);
}
}
}
}
for(i=1;i<=j;i++) {
for(k=0;k<i;k++) {
if(Integer.parseInt(pos[k])>Integer.parseInt(pos<i>)) {
temp=V<i>; V<i>=V[k]; V[k]=temp;
}
}
}
for(i=0;i<=j;i++)
for(k=0;k<V<i>.size();k++)
result.addValue(V<i>.elementAt(k));
}
Now do this graphical mapping:
ponum>removeContexts>sort>splitByValue\[value changed\]>collapseContexts-->t_record
ponum>removeContexts>sort>splitByValue\[value changed\]>collapseContexts>splitByValue\[each value\]>ponum
ponum>removeContexts>sort>splitByValue\[value changed\]>linerec
ponum>removeContexts>groupingByPonum>splitByValue\[each value\]>polinenum
polinenum |
(in the udf give two inputs
1: ponum-->removeContexts
2: polinenum-->removeContexts)
that's all......
you can use this udf for any kind of grouping operation in message mapping.
--Sankar Choudhury
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
if you want you can try this XSLT mapping:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml"/>
<xsl:key name="po" match="s_record" use="ponum"/>
<xsl:template match="/">
<ns0:targetrecord xmlns:ns0="http://test.it">
<xsl:for-each select="//s_record[generate-id(.)=generate-id(key('po',ponum))]">
<xsl:sort select="ponum" order="ascending"/>
<t_records>
<ponum>
<xsl:value-of select="ponum"/>
</ponum>
<xsl:for-each select="key('po',ponum)">
<xsl:sort select="polinenum"/>
<linerec>
<polineum>
<xsl:value-of select="polinenum"/>
</polineum>
</linerec>
</xsl:for-each>
</t_records>
</xsl:for-each>
</ns0:targetrecord>
</xsl:template>
</xsl:stylesheet>
Copy it in a file with ex. xslt and import it in mapping.
Be careful to put a valid namespace in the source xml.I used for istance xmlns:ns0="http://test.it", otherwise you cannot test it.
Regards,
Emiliano
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ok, with the UDF I mentioned above instead it should be mapped as:
ponum -> ponum
ponum, ponum, polinenum -> doMap -> linerec
(change the context of the second "ponum" and "polinenum" to "sourcerecord" - right-click->context->...)
ponum, ponum, polinenum -> doMap -> splitByValue -> polinenum
(change the context of the second "ponum" and "polinenum" to "sourcerecord" - right-click->context->...)
Regards,
Yaghya
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
hi
check with standard function FORMAT BY EXAMPLE
check the below blog which illustrates the above function
/people/stefan.grube/blog/2005/12/29/new-functions-in-the-graphical-mapping-tool-xi-30-sp13
regards
chandrakanth
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Create a User Defined function "doMap" with type "context" that takes three parameters a, b, and c.
String currPonum = a[0];
for (int i=0; i< b.length; i++){
if (b<i> == currPonum)
result.addValue(c<i>);
}
Now map as follows:
ponum -> ponum
ponum, ponum, polinenum -> doMap -> polinenum
(change the context of the second "ponum" and "polinenum" to "sourcerecord" - right-click->context->...)
Regards,
Yaghya
Edited by: Yaghya Nana on Jun 4, 2008 2:04 PM
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
81 | |
10 | |
10 | |
9 | |
7 | |
6 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.