not sure I got all your ules 100% but something like
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output encoding="US-ASCII" indent="yes"/>
<xsl:variable name="f2" select="doc('sub2.xml')"/>
<xsl:key name="a" match="subdiv" use="@fips"/>
<xsl:template match="subdiv">
<xsl:variable name="a" select="key('a',@fips,$f2)"/>
<xsl:copy>
<xsl:copy-of select="@*"/>
<basename>
<name>
<xsl:value-of select="($a[(_at_)nt='N']/@short-name,basename/name1)[1]"/>
</name>
<xsl:apply-templates select="$a[(_at_)nt='N']/(@bgn-name,@bgn-name-nd)"/>
</basename>
<other-names>
<xsl:for-each-group
select="basename/*,$a[(_at_)nt='V']/(@bgn-name,@bgn-name-nd)[not((_dot_)=$a[(_at_)nt='N']/@*)]"
group-by=".">
<xsl:apply-templates select="."/>
</xsl:for-each-group>
</other-names>
</xsl:copy>
</xsl:template>
<xsl:template match="subdiv[(_at_)nt='N']/@bgn-name">
<long-form><xsl:value-of select="."/></long-form>
</xsl:template>
<xsl:template match="subdiv[(_at_)nt='N']/@bgn-name-nd">
<long-form-nd><xsl:value-of select="."/></long-form-nd>
</xsl:template>
<xsl:template match="subdiv[(_at_)nt='V']/@*">
<bgn-variant><xsl:value-of select="."/></bgn-variant>
</xsl:template>
<xsl:template match="basename[1]/*">
<alt-name><xsl:value-of select="."/></alt-name>
</xsl:template>
<xsl:template match="basename[2]/*">
<iso-name><xsl:value-of select="."/></iso-name>
</xsl:template>
</xsl:stylesheet>
where the main input (sub1.xml) is your first file and sub2.xml is your
second
$ saxon8 sub1.xml sub.xsl
<?xml version="1.0" encoding="US-ASCII"?>
<subdiv fips="AF13">
<basename>
<name>Kàbol</name>
<long-form>Velàyat-e Kàbol</long-form>
<long-form-nd>Velayat-e Kabol</long-form-nd>
</basename>
<other-names>
<alt-name>Kabul</alt-name>
<alt-name>Kaboul</alt-name>
<alt-name>Kàbul</alt-name>
<alt-name>Kabol</alt-name>
<iso-name>Kàbol</iso-name>
<bgn-variant>Velàyat-e Kàbul</bgn-variant>
<bgn-variant>Velayat-e Kabul</bgn-variant>
<bgn-variant>Kabul Province</bgn-variant>
</other-names>
</subdiv>
________________________________________________________________________
The Numerical Algorithms Group Ltd is a company registered in England
and Wales with company number 1249803. The registered office is:
Wilkinson House, Jordan Hill Road, Oxford OX2 8DR, United Kingdom.
This e-mail has been scanned for all viruses by Star. The service is
powered by MessageLabs.
________________________________________________________________________
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--