21 March 2007

Geni, Graphiz, Dot & Family Tree.

Geni is a genealogy-related social networking website launched in beta mode in January 2007. Since yesterday, the family tree can now be exported as a gedcom-xml file (alpha version).

The following xslt stylesheet transforms the gedcom file into a Graphiz/DOT input which can be used to generate the family tree.

Family Tree



<?xml version='1.0' ?>
<xsl:stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform' version='1.0'>
<xsl:output method='text' omit-xml-declaration="yes" />

<xsl:template match="GEDCOM">
digraph &quot;G&quot; {
<xsl:apply-templates select="FamilyRec"/>
<xsl:apply-templates select="IndividualRec"/>
}
</xsl:template>

<xsl:template match="IndividualRec">
<xsl:value-of select="@Id"/>[ shape=box, label=&quot;<xsl:value-of select="IndivName/GivenName"/><xsl:text> </xsl:text><xsl:value-of select="IndivName/SurName"/> <xsl:if test="DeathStatus=&apos;dead;&apos;">(d)</xsl:if>&quot;

<xsl:choose>
<xsl:when test="Gender=&apos;M&apos;">
,color=blue
</xsl:when>
<xsl:when test="Gender=&apos;F&apos;">
,color=pink
</xsl:when>
<xsl:otherwise>
,color=black
</xsl:otherwise>
</xsl:choose>


];
</xsl:template>

<xsl:template match="FamilyRec">
<xsl:variable name="famId"><xsl:value-of select="@Id"/></xsl:variable>

<xsl:value-of select="$famId"/>[shape=point];

<xsl:if test="HusbFath">
<xsl:value-of select="HusbFath/Link/@Ref"/>-&gt;<xsl:value-of select="$famId"/>;
</xsl:if>

<xsl:if test="WifeMoth">
<xsl:value-of select="WifeMoth/Link/@Ref"/>-&gt;<xsl:value-of select="$famId"/>;
</xsl:if>

<xsl:for-each select="Child">
<xsl:value-of select="$famId"/>-&gt;<xsl:value-of select="Link/@Ref"/>;
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>



Pierre