Given two valid XML files:
file1.xml
<input>
<T>
<T1>AA</T1>
<T2>1</T2>
</T>
<T>
<T1>BB</T1>
<T2>1</T2>
</T>
<T>
<T1>AC</T1>
<T2>1</T2>
</T>
</input>
file2.xml
<input>
<T>
<T1>BB</T1>
<T2>2</T2>
</T>
<T>
<T1>AB</T1>
<T2>3</T2>
</T>
</input>
when the following stylesheet is applied to file1.xml:
XSLT 1.0
<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:variable name="file2" select="document('file2.xml')" />
<xsl:variable name="localT1s" select="/input/T/T1" />
<xsl:template match="/input">
<result>
<xsl:apply-templates select="T"/>
<xsl:apply-templates select="$file2/input/T[not(T1=$localT1s)]"/>
</result>
</xsl:template>
<xsl:template match="T">
<xsl:copy>
<xsl:copy-of select="T1"/>
<T2>
<xsl:choose>
<xsl:when test="$file2/input/T[T1=current()/T1]">
<xsl:value-of select="$file2/input/T[T1=current()/T1]/T2"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="T2"/>
</xsl:otherwise>
</xsl:choose>
</T2>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
the result will be:
<?xml version="1.0" encoding="UTF-8"?>
<result>
<T>
<T1>AA</T1>
<T2>1</T2>
</T>
<T>
<T1>BB</T1>
<T2>2</T2>
</T>
<T>
<T1>AC</T1>
<T2>1</T2>
</T>
<T>
<T1>AB</T1>
<T2>3</T2>
</T>
</result>
Edit
In response to your amended question:
It's not quite clear what do you know about the names of the <T#>
elements in the input files. If (as I assumed) nothing, then this gets rather complex:
XSLT 1.0
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:exsl="http://exslt.org/common"
extension-element-prefixes="exsl">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:variable name="file2" select="document('file2.xml')" />
<xsl:template match="/TT">
<xsl:variable name="localT1s" select="T/T1" />
<xsl:copy>
<xsl:apply-templates select="T"/>
<xsl:apply-templates select="$file2/TT/T[not(T1=$localT1s)]" mode="import"/>
</xsl:copy>
</xsl:template>
<xsl:template match="T">
<xsl:variable name="elemNames">
<xsl:for-each select="*">
<name><xsl:value-of select="name()"/></name>
</xsl:for-each>
</xsl:variable>
<xsl:copy>
<xsl:apply-templates select="*"/>
<xsl:apply-templates select="$file2/TT/T[T1=current()/T1]/*[not(name()=exsl:node-set($elemNames)/name)]" mode="import"/>
</xsl:copy>
</xsl:template>
<xsl:template match="T/*">
<xsl:variable name="T1" select="../T1" />
<xsl:variable name="Tx" select="name()" />
<xsl:copy>
<xsl:choose>
<xsl:when test="$file2/TT/T[T1=$T1]/*[name()=$Tx]">
<xsl:value-of select="$file2/TT/T[T1=$T1]/*[name()=$Tx]"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="."/>
</xsl:otherwise>
</xsl:choose>
</xsl:copy>
</xsl:template>
<xsl:template match="*" mode="import">
<xsl:copy-of select="."/>
</xsl:template>
</xsl:stylesheet>
I tested the above with these two files:
file1.xml
<TT>
<T>
<T1>A</T1>
<T2>a2</T2>
</T>
<T>
<T1>B</T1>
<T2>b2</T2>
<T3>b3</T3>
</T>
</TT>
file2.xml
<TT>
<T>
<T1>A</T1>
<T2>A2</T2>
<T3>A3</T3>
</T>
<T>
<T1>B</T1>
<T3>B3</T3>
</T>
<T>
<T1>C</T1>
<T2>C2</T2>
</T>
</TT>
and received this result:
<?xml version="1.0" encoding="UTF-8"?>
<TT>
<T>
<T1>A</T1>
<T2>A2</T2>
<T3>A3</T3>
</T>
<T>
<T1>B</T1>
<T2>b2</T2>
<T3>B3</T3>
</T>
<T>
<T1>C</T1>
<T2>C2</T2>
</T>
</TT>