on 07-07-2009 10:04 AM
Hi
I am trying to concatenate an unknown number of records in the source message to just one field in the target message.
The structure in the source message is:
<simple>
<record>
<string>first string value</string>
</record>
<record>
<string>second string value</string>
</record>
<record>
<string>third string value</string>
</record>
<concatstring></concatstring>
</simple>
Where the number of records in the source message is unknown.
The target message should look like this:
<simple>
<concatstring>first string value second string value third string value</concatstring>
</simple>
I tried using UDF:
public String concat(String count,String streng,Container container){
int counter = Integer.parseInt(count);
String out = " ";
for(int i=0;i<(counter);i++){
out = out + streng;
}
return out;
}
But that only picks up the value of the field in the first record and repeats that the number of counts.
Can I avoid using a UDF? If not, what is the code?
Looking forward to the answer
Mikael
write a UDF of type Queue
set the context of string to simple
UDF should look like
String finalString = "";
int count = streng.length; // input string array count
for(int i=0;i<count;i++)
{
finalString = finalString + streng<i>;
}
result.addValue(finalString);
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello,
In case, number of records from source structure to combine is not know, will this UDF work?
IN my case, i have a node in source structure which have occurrence as 0:unbound, and i have to combine its value separated by comma into a single string node of target structure.
Can anyone provide me the way to do it?
Regards,
Neha
Hi,
TO achive this you need to remove the context for <string> source field and send whole queue as the input parameter to the UDF.
In UDF, concatenate all the queue value and return the resultant string.
Regards,
Shweta.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Mikael,
Try using this XSLT code.
<?xml version='1.0'?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<GetCustomerInformationResponse>
<GetCustomerInformationResult>
<xsl:text disable-output-escaping="yes"><![CDATA[<![CDATA[<?xml version="1.0" encoding="UTF-8"?>]]></xsl:text>
<xsl:copy-of select="*"/>
<xsl:text disable-output-escaping="yes"><![CDATA[]]]]></xsl:text>
<xsl:text disable-output-escaping="yes"><![CDATA[>]]></xsl:text>
</GetCustomerInformationResult>
</GetCustomerInformationResponse>
</xsl:template>
</xsl:stylesheet>
This will solve your problem.
Regards,
Sarvseh Desai
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Sarvesh,
Sorry could not help noticing a copy and paste..atleast clean up and remove the lines highlighted in BOLD.
<?xml version='1.0'?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<GetCustomerInformationResponse>
<GetCustomerInformationResult>
<xsl:text disable-output-escaping="yes"><![CDATA[<![CDATAhttp://<?xml version=\"1.0\" encoding=\"UTF-8\"?>]></xsl:text>
<xsl:copy-of select="*"/>
<xsl:text disable-output-escaping="yes"><!CDATA[]]]></xsl:text>
<xsl:text disable-output-escaping="yes"><![CDATA>]></xsl:text>
</GetCustomerInformationResult>
</GetCustomerInformationResponse>
</xsl:template>
</xsl:stylesheet> \
Regards
Ravi Raman
You need not pass the count to the UDF.
Change the context of string field to higher level then apply the udf(Execution type as context) as below:
public String concat(String a[],Container container){
String out = " ";
for(int i=0;i<a.length;i++){
out = out + a<i>;
}
return out;
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This message was moderated.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Chage the context of the String element from record node to simple node.
you can also use this UDF code... you UDF should be advanced UDF....
String out = "";
for(inti=0;i<streng.length;i++)
{
out = out + streng<i>
}
result.addValue(out);
~SaNv...
Edited by: Santhosh Kumar V on Jul 7, 2009 2:43 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 |
---|---|
84 | |
23 | |
11 | |
9 | |
8 | |
5 | |
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.