xml for testing
<gedcom>
<indi id="@I001">
<famc>@F002@</famc>
</indi>
<fam id="@F002">
<husb>@I005@</husb>
<wife>@I007@</wife>
</fam>
</gedcom> xsl
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes" method="xml"/>
<xsl:template match="/">
<root>
<xsl:apply-templates select="gedcom"/>
</root>
</xsl:template>
<xsl:template match="gedcom">
<xsl:apply-templates select="indi"/>
</xsl:template>
<xsl:template match="indi">
<xsl:apply-templates select="famc"/>
</xsl:template>
<xsl:template match="famc">
<famc>
<where>
<xsl:value-of select="."/>
</where>
<!-- delete last sign @ and select the node 2 level back in same level as
node fam indi
-->
<xsl:variable name="data" select="substring(.,1,string-length(.)-1)"/>
<xsl:apply-templates select="../../fam[@id=$data]"/>
</famc>
</xsl:template>
<xsl:template match="fam">
<datainfam>
<xsl:apply-templates/>
</datainfam>
</xsl:template>
<xsl:template match="husb|wife">
<data>
<xsl:value-of select="concat(local-name(.),' ',.)"/>
</data>
</xsl:template>
</xsl:stylesheet> result
<?xml version='1.0' ?>
<root>
<famc>
<where>@F002@</where>
<datainfam>
<data>husb @I005@</data>
<data>wife @I007@</data>
</datainfam>
</famc>
</root>