One approach could be to navigate over DocumentA, but passing in a parameter set to the equivalent node in Document B.
To start with, match the document node of A, and start the matching off with the document node from B
<xsl:template match="/">
<xsl:apply-templates>
<xsl:with-param name="parentB" select="document('DocB.xml')"/>
</xsl:apply-templates>
</xsl:template>
Then, you would have a template matching any element (in A) with the current (parent) node in B as the parameter
<xsl:template match="*">
<xsl:param name="parentB"/>
To find the equivalent 'child' node in B, you would first find the current position of the A node (should there be more than one child of the same name), and then check if such a child exists under the parent B node
<xsl:variable name="posA">
<xsl:number />
</xsl:variable>
<xsl:variable name="nodeB" select="$parentB/*[local-name() = local-name(current())][number($posA)]"/>
Then, it is just a case of determining whether to copy the A or B node. To copy the B node, the B node would have to exist, and not have any child elements (it might have child text nodes though, which would be copied
<xsl:when test="$nodeB and not($nodeB/*)">
<xsl:copy-of select="$nodeB/node()"/>
</xsl:when>
Otherwise, continue processing the A node (passing in the current B node as a parameter).
Try this XSLT
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/">
<xsl:apply-templates>
<xsl:with-param name="parentB" select="document('DocB.xml')"/>
</xsl:apply-templates>
</xsl:template>
<xsl:template match="*">
<xsl:param name="parentB"/>
<xsl:variable name="posA">
<xsl:number />
</xsl:variable>
<xsl:variable name="nodeB" select="$parentB/*[local-name() = local-name(current())][number($posA)]"/>
<xsl:copy>
<xsl:choose>
<xsl:when test="$nodeB and not($nodeB/*)">
<xsl:copy-of select="$nodeB/node()"/>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="@*|node()">
<xsl:with-param name="parentB" select="$nodeB"/>
</xsl:apply-templates>
</xsl:otherwise>
</xsl:choose>
</xsl:copy>
</xsl:template>
<xsl:template match="@*|node()[not(self::*)]">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>