I would like to use XSLT to merge two element nodes where their local names are different.
e.g. Merge file1.xml
<A>
<B>
<C>
<D>Value</D>
</C>
</B>
<G>
<C>
<H>Value</H>
</C>
</G>
</A>
with file2.xml
<A>
<E>
<C>
<F>Value</F>
</C>
</E>
</A>
to get output file3.xml
<A>
<B>
<C>
<D>Value</D>
<F>Value</F>
</C>
</B>
<G>
<C>
<H>Value</H>
<F>Value</F>
</C>
</G>
</A>
I basically want to treat E as a wildcard. Is this possible? If so, could you provide some XSLT that would work for this? I've been trying for a number of hours and can't seem to come up with a solution.
EDIT: asked for attempts... This XSLT:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes"/>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()" />
</xsl:copy>
</xsl:template>
<xsl:template match="A">
<xsl:copy>
<xsl:apply-templates select="*"/>
<xsl:apply-templates select="document('file1.xml')/A/node()" />
</xsl:copy>
</xsl:template>
<xsl:template match="C">
<xsl:copy>
<xsl:apply-templates select="*"/>
<xsl:apply-templates select="document('file1.xml')/A/./C/*" />
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
Gave this output:
<?xml version="1.0"?>
<A><E>
<C><F>Value</F></C>
</E>
<B>
<C><D>Value</D></C>
</B>
<G>
<C><H>Value</H></C>
</G>
</A>