Эта таблица стилей:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:key name="kElementByAncestors" match="*"
use="concat(name(../..),'+',name(..))"/>
<xsl:key name="kAttributeByAncestors" match="@*"
use="concat(name(../..),'+',name(..))"/>
<xsl:param name="pSource2" select="'source2.xml'"/>
<xsl:variable name="vSource2" select="document($pSource2,/)"/>
<xsl:template match="*">
<xsl:variable name="vKey" select="concat(name(..),'+',name())"/>
<xsl:variable name="vCurrent" select="."/>
<xsl:copy>
<xsl:for-each select="$vSource2">
<xsl:variable name="vNames">
<xsl:text>|</xsl:text>
<xsl:for-each select="$vCurrent/*">
<xsl:value-of select="concat(name(),'|')"/>
</xsl:for-each>
</xsl:variable>
<xsl:copy-of select="key('kAttributeByAncestors',$vKey)"/>
<xsl:copy-of select="$vCurrent/@*"/>
<xsl:copy-of
select="key('kElementByAncestors',
$vKey)[not(contains($vNames,
concat('|',
name(),
'|')))]"/>
</xsl:for-each>
<xsl:apply-templates select="node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
С этим входом:
<Customer>
<Lname>Smith</Lname>
<Data>Data</Data>
</Customer>
И "source2.xml":
<Customer test="test">
<Fname>John</Fname>
<Lname>Smith</Lname>
</Customer>
Выход:
<Customer test="test">
<Fname>John</Fname>
<Lname>Smith</Lname>
<Data>Data</Data>
</Customer>