I have been trying to write an XSLT with 2.0 version to convert CSV data (which is again embedded in XML element) to XML.
The following is my sample CSV data
<csv>
"Id","Success","Created","Error"
"001P000000aXgRAIA0","true","true",""
"","false","false","REQUIRED_FIELD_MISSING:Required fields are missing: [Name, Man1__c, man2__c]:Name Man1__c man2__c --"
</csv>
Here the first row is header fields and for the above data my output XML should be like
<results xmlns = "http://www.force.com/2009/06/asyncapi/dataload">
<result>
<id>001D000000ISUr3IAH</id>
<success>true</success>
<created>true</created>
</result>
<result>
<errors>
<fields>Name</fields>
<fields>Man1__c</fields>
<fields>man2__c</fields>
<message>Required fields are missing: [Name, Man1__c, man2__c]</message>
<statusCode>REQUIRED_FIELD_MISSING</statusCode>
</errors>
<success>false</success>
<created>false</created>
</result>
</results>
and my conversion should have the following logic to perform transformation.
As you can see in the first record (not header row, actually second row in the csv data) the success value is true, hence the result will be populated as is, with id, success and created information.
For the second row, the success is false, hence there will be no id element in the result but errors should be populated. To populate the errors, the error field from CSV data should be parsed and first token of : (colon), should be put into statusCode element and last token of : (colon) should be put into fields (by parsing it with space separated) and rest middle string should be put into message field of errors.
I have searched sample XSLT here and could not get how to start with. Could you please help me start with sample XSLT so that I can develop in achieving this ?