cancel
Showing results for 
Search instead for 
Did you mean: 

UDF for conactinating all the source fields in to a single target field

Former Member
0 Kudos

Hello Experts,

I have a scenario where I need have the following source and target structure.

Source :-

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

<ns0:XATADriverUpdates_Req_Out xmlns:ns0="http://sysco.com/pi/test">

<Record>

<PayrollRequest>

<StartDate/>

<EndDate/>

<UserDefinedOrganizationID/>

<UserDefinedDriverID/>

<IncludeSubOrgs/>

</PayrollRequest>

</Record>

</ns0:XATADriverUpdates_Req_Out>

Target :-

I have a single field called " PARMS "

The mapping I need is as below :-

Whatever fields are there in the source side should come in the PARMS field in the target side.

PARMS = <Record>

<PayrollRequest>

<StartDate/>

<EndDate/>

<UserDefinedOrganizationID/>

<UserDefinedDriverID/>

<IncludeSubOrgs/>

</PayrollRequest>

</Record>

for e.g :- if the source is like

<Record>

<PayrollRequest>

<StartDate>1</StartDate>

<EndDate>2</EndDate>

<UserDefinedOrganizationID>3</UserDefinedOrganizationID>

<UserDefinedDriverID>4</UserDefinedDriverID>

<IncludeSubOrgs>4</IncludeSubOrgs>

</PayrollRequest>

</Record>

then my target field should be

PARMS = <Record>

<PayrollRequest>

<StartDate>1</StartDate>

<EndDate>2</EndDate>

<UserDefinedOrganizationID>3</UserDefinedOrganizationID>

<UserDefinedDriverID>4</UserDefinedDriverID>

<IncludeSubOrgs>4</IncludeSubOrgs>

</PayrollRequest>

</Record>

I think we need to write a UDF for this.

Can you please help me out with UDF code.

Need your responses asap.

Thanks in adavnce,

Sunil

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi Sunil,

Open notepad and put this code:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ns0="urn:cidx:names:specification:ces:schema:all:5:0">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="@*|node()">
		<xsl:copy>
			<xsl:apply-templates select="@*|node()"/>
		</xsl:copy>
	</xsl:template>
 <xsl:template match="/">
<PARMS >
 <xsl:copy>
			<xsl:text disable-output-escaping="yes"> <![CDATA[<![CDATA[
			
			]]
			>
		


]]>

Save it as .xsl file and zip it and import it in imported archives and use it directly in interface mapping. Here we are not doing graphical mapping.

Regards,

---Satish

Former Member
0 Kudos

Hi Satish,

Thanks for your quick response.

I will try this one and let you know.

If I need the vice versa in the response section,what would be my code for XSLT mapping.

I mean this time is Source is a single field " GetPayrollResult " and there are various target fields to which we need to split the single source field.

Thanks,

Sunil

Former Member
0 Kudos

Hi Sunil,

If you are getting the field in PARMS for example then you use this code:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output omit-xml-declaration="yes" /> 
<xsl:template match="@*|node()">
<xsl:copy>
  <xsl:apply-templates select="@*|node()" /> 
  </xsl:copy>
  </xsl:template>
<xsl:template match="/">
  <xsl:value-of select="//PARMS" disable-output-escaping="yes" /> 
  </xsl:template>
  </xsl:stylesheet>

Now if you want to do any mapping with the structure inside PARMS then use two maps. First xsl mapping to split the single field into multiple fields and then graphical mapping for multiple fields to target message type.

Regards,

---Satish

Former Member
0 Kudos

Hi Satish,

I have a source field named "GetPayrollResult".

I need to split the single source field to the below mentioned structure.

<Record>

<TimeRecord>

<StartDate/>

<EndDate/>

<UserDefinedOrganizationID/>

<UserDefinedDriverID/>

<IncludeSubOrgs/>

</TimeRecord>

</Record>

The most important note is that there is no field separator in the "GetPayrollResult" string to identify the various fields.

Thanks,

Sunil

Edited by: SUNIL DALAL on Mar 18, 2010 10:41 PM

Former Member
0 Kudos

Hi Satish,

Can you please let me know how we can test our mapping.

Thanks,

Sunil

Former Member
0 Kudos

Hi Sunil,

You can test in altova xml spy.

Regards,

---Satish

Former Member
0 Kudos

Hi Srini,

I have tried with the code that you have provided , but the target field is empty although the test is successfull.

And please let me know how to test the XSL mapping in altova, as I am new to it.

Thanks,

Sunil

Former Member
0 Kudos

Hi Sunil,

You can write an xsl mapping for this. Search in sdn for CDATA and that would do the trick for you. You can see this thread also:

Regards,

---Satish

Former Member
0 Kudos

Hi sunil

Do you want to put XML content into a field PARMS?

Edited by: Luis Ortiz on Mar 18, 2010 11:24 AM

Former Member
0 Kudos

Hi Luis,

Yes you are right. I need to put XML content into a field PARMS.

Thanks for ur understanding.

Sunil

Former Member
0 Kudos

Hi Sunil

It difficult to get it with UDF .

You should use XSL mapping to get XML or create a module to get the XML.

Or try this. (sound crazy but depends is a hard )

constant "<Record> <PayrollRequest><StartDate>"

StartDate----


concat

constant "</StartDate> <EndDate>"

..........................

continuos until complete all nodes.

Edited by: Luis Ortiz on Mar 18, 2010 11:52 AM

Edited by: Luis Ortiz on Mar 18, 2010 11:56 AM