I have been trying to write the XSLT to merge two different XMLs and produce a different XML output using the XSLT code using XSLT v2.0.
Below are my requirements.
Input XML1 is like this:
<?xml version="1.0" encoding="UTF-8"?>
<externalIdFields xmlns="urn:partner.soap.sforce.com/">
<object name="Account">
<ExternalID>
<name>ExtAccountID__c</name>
<type>string</type>
</ExternalID>
</object>
<object name="User"/>
<object name="Contact">
<ExternalID>
<name>ExtContactID__c</name>
<type>string</type>
</ExternalID>
</object>
<object name="Opportunity">
<ExternalID>
<name>ExtOpportunityID__c</name>
<type>decimal</type>
</ExternalID>
<ExternalID>
<name>UniqueAnotherOppID__c</name>
<type>boolean</type>
</ExternalID>
</object>
and XML2 is like this:
<?xml version="1.0" encoding="UTF-8"?>
<relationshipNames>
<object name="Account">
<reletionshipName>Parent</reletionshipName>
</object>
<object name="User">
<reletionshipName>Owner</reletionshipName>
</object>
<object name="Contact">
<reletionshipName>LookUpContact__r</reletionshipName>
</object>
<object name="Opportunity">
<reletionshipName>LookUpOpportunity__r</reletionshipName>
</object>
<object name="Opportunity">
<reletionshipName>AnotherRelationship__r</reletionshipName>
</object>
</relationshipNames>
The first XML contains all the external ids for each and second XML contains all the relationship names for each object.
The output XML should be
<?xml version="1.0" encoding="UTF-8"?>
<result xmlns:con = "http://www.approuter.com/schemas/cdk/config/">
<con:field name = "Parent.ExtAccountID__c" label = "Parent.ExtAccountID__c">
<con:type>string</con:type>
</con:field>
<con:field name = "LookUpContact__r.ExtContactID__c" label="LookUpContact__r.ExtContactID__c">
<con:type>string</con:type>
</con:field>
<con:field name = "LookUpOpportunity__r.ExtOpportunityID__c" label = "LookUpOpportunity__r.ExtOpportunityID__c">
<con:type>decimal</con:type>
</con:field>
<con:field name = "LookUpOpportunity__r.UniqueAnotherOppID__c." label = "LookUpOpportunity__r.UniqueAnotherOppID__c">
<con:type>boolean</con:type>
</con:field>
<con:field name = "AnotherRelationship__r.ExtOpportunityID__c." label = "AnotherRelationship__r.ExtOpportunityID__c">
<con:type>boolean</con:type>
</con:field>
<con:field name = "AnotherRelationship__r.UniqueAnotherOppID__c." label = "AnotherRelationship__r.UniqueAnotherOppID__c">
<con:type>boolean</con:type>
</con:field>
</result>
The merge is simple. For each externalId for each object, create a con:field tag and here the value for name and label should be corresponding relationshipName for that object and externalId field name. It will be relationshiName.externalIdFieldName. The relationshipName for an object should be associated to externalIds of only that object.
How can we achieve this? I saw an XSLT to merge two XMLs. But I did not understand the "@* | node()" part of different examples. Here I did not find examples which parses two completely different XMLs.
Appreciate your help.