Various strategies are possible:
(a) you can define a template rule that matches either of these element names (match="A|B")
(b) you can define two different template rules for the two different element names (it doesn't matter if one of the rules is unused)
(c) you can define two separate stylesheets for the two document types, with the common code that they share included into both using xsl:import.
Option (c) is probably the one that gives you most flexibility in the future.
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer's Reference