Using XML, XSLT for Genealogy.

My experience about XSLT applied to Genealogy

I'm a beginner with XML and while I was learning XSLT transformations, I decided to test my new knowledge to handle genealogical datas. Here I propose to explain how to use XSLT transformation in order to extract informations from pedegrees. I tested this transformation with a subset of Napoleon's family. It may be useful for those who want to display their small genalogy

About XML and XSLT

XML is a simple, very flexible text format derived from SGML (ISO 8879). Originally designed to meet the challenges of large-scale electronic publishing. XML is also plays an increasingly important role in the exchange of a wide variety of data on the Web and elsewhere. [www.w3.org].

XSLT is used to transform an XML document into another XML document, or another type of document that is recognized by a browser, like HTML and XHTML. Normally XSLT does this by transforming each XML element into an (X)HTML element. XSLT can also add new elements into the output file, or remove elements. It can rearrange and sort elements, and test and make decisions about which elements to display, and a lot more. A common way to describe the transformation process is to say that XSLT transforms an XML source tree into an XML result tree. [www.w3schools.com]

The XML file

The XML file is available HERE. It is used to store the datas about families and individuals. With microsoft internet explorer, it will be automaticaly transformed into HTML else you'll need a tool, such as XT, to transform this XML with the XSLT file

Here is a sample

<?xml version='1.0' ?>
<?xml:stylesheet type="text/xsl" href="genealogy2xhtml.xsl" ?> <!-- link to the XSLT stylesheet, will transform the XML with internet explorer -->

<genea> <!-- root element is genea -->

<fam id='F1'>	<!-- open a family, give him an unique identifier in the pedegree -->
	<father id="CMB" />	<!-- declare the identifier of the father -->
	<mother id="MLR" />	<!-- declare the identifier of the mother -->
	<children id="N1" />	<!-- declare the identifiers of the children -->
	<children id="LB" />
	<text> </text>	<!-- you can include any information in HTML about this family in the text tag -->
</fam>	<!-- close the family -->

<fam id='F2'>
	<father id="N1" />
	<mother id="JB" />

</fam>

(...)

<indi id='CMB'>	<!-- open an individual, give him an unique identifier in the pedegree -->
	<name>Bonaparte</name>	<!-- name of the individual -->
	<surname>Charles-Marie</surname>	<!-- surname of the individual -->
	<born>1746</born>	<!-- born info -->
	<dead>1785</dead>	<!-- death info -->
	<photo  src="http://www.napoleon.org/fr/essentiels/genealogie/detail/image/2.jpg"/>	<!-- a link to a picture -->
		<!-- you can include any information in HTML about this individual in the text tag -->
	<text>Avocat au Conseil superieur de Corse qui le reconnait noble (1771), assesseur de la juridiction royale des provinces et ville d'Ajaccio, depute de la pieve d'Ajaccio aux Etats de Corse, depute de la noblesse de Corse aupres du roi (1779).</text>
</indi>	<!-- close the individual -->

<indi id='MLR'>
	<name>RAMOLINO</name>
	<surname>Maria Letizia</surname>
	<born>1750</born>
	<dead>1836</dead>
	<photo  src="http://www.napoleon.org/fr/essentiels/genealogie/detail/image/14.jpg"/>
	<text>Veuve a 35 ans, proclamee par decret du 23 mars 1805 &quot;Son Altesse imperiale  Madame, Mere de l'Empereur&quot;.</text>
</indi>


<indi id='N1'>
	<name>Bonaparte</name>
	<surname>Napoleon</surname>
	<born>1769</born>
	<dead>1821</dead>
	<photo src="http://www.napoleon.org/fr/essentiels/genealogie/detail/image/16.jpg"/>
	<text>General de division (1795), premier consul (1799), consul a vie (1802), mediateur de la Confederation suisse (1803), empereur hereditaire des Francais (1804), roi d'Italie (1805), protecteur de la Confederation du Rhin (1806), prince souverain de l'Ile d'Elbe (1814), abdique en faveur de son fils en 1814, seconde abdication en 1815, exil et mort a Sainte-Helene.<p align="center" style="background:gray">Le sacre de l empereur<br /> <img src="http://cartelfr.louvre.fr/pub/fr/image/23446_p0000818.001.jpg" /></p></text>
</indi>

</genea>	<!-- close the xml file -->

The XSLT file

The XSLT file is available HERE. It looks like this:

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

<xsl:key name="indilist" match="indi" use="./@id" />
<xsl:key name="famlist" match="fam" use="./@id" />

<xsl:template match="/">
<html>
<head><title>Genealogie</title></head>
<body style="font-family: times; ">
<xsl:apply-templates select="genea"/>
</body>
</html>
</xsl:template>

<xsl:template match="genea">
<h1>Genealogie</h1>

<h2>Familles</h2>
<div>
<xsl:apply-templates select="//fam" />
</div>
<h2>Individus</h2>
<div>
<xsl:apply-templates select="indi">
(...)

The Result

using internet explorer, the result is HERE else you'll need a tool, such as XT to transform this XML with the XSLT file

Generating a Tree with Graphiz

Tools such as graphiz can be used to generate 'graphs'.

Another XSLT file called genealogy2dot.xsl is then used to transform the XML file into an input for the graphiz program. The result was shown below: children are linked to their parent


Pierre Lindenbaum 2004 plindenbaumNOSPAM@yahoo.fr