I have 2 xml file and requirement is to merge both file into one by matching node. Below are the files.
First XML is (the original one):
<EF_Candidate_List>
<EF_Candidate>
<candidate_id>1</candidate_id>
<field_1>foo</field_1>
</EF_Candidate>
<EF_Candidate>
<candidate_id>2</candidate_id>
<field_1>bar</field_1>
</EF_Candidate>
</EF_Candidate_List>
Second XML need to merge based on node
<EF_Candidate_List>
<EF_Candidate>
<candidate_id>1</candidate_id>
<account_number>10</account_number>
<account_number>50</account_number>
<EF_Candidate>
<candidate_id>2</candidate_id>
<account_number>20</account_number>
</EF_Candidate>
</EF_Candidate_List>
Expecting xml result file.
<EF_Candidate_List>
<EF_Candidate>
<candidate_id>1</candidate_id>
<field_1>foo</field_1>
<column>10</column>
<column>50</column>
</EF_Candidate>
<EF_Candidate>
<candidate_id>2</candidate_id>
<field_1>bar</field_1>
<column>20</column>
</EF_Candidate>
</EF_Candidate_List>
I have created below xsl.
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:variable name="val" select="document('test2.xml')/EF_Candidate_List/EF_Candidate/account_number" />
<!-- identity transform -->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="EF_Candidate">
<xsl:copy>
<xsl:apply-templates/>
<column>
<xsl:value-of select="$val" />
</column>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
it result into below xml file.
<?xml version="1.0" encoding="UTF-8"?>
<EF_Candidate_List>
<EF_Candidate>
<candidate_id>1</candidate_id>
<field_1>foo</field_1>
<column>10</column>
</EF_Candidate>
<EF_Candidate>
<candidate_id>2</candidate_id>
<field_1>bar</field_1>
<column>10</column>
</EF_Candidate>
</EF_Candidate_List>
I'm fairly new to XSLT so please excuse the potentially novice question. Any guidance would be appreciated here. Thanks in advance.