<?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="text" />
<xsl:key name="indilist" match="indi" use="./@id" />

<xsl:template match="/">
digraph G {
<xsl:apply-templates />
}
</xsl:template>

<xsl:template match="fam">
<xsl:if test="father/@id and mother/@id">
<!-- <xsl:value-of select="father/@id" />-&gt;<xsl:value-of select="mother/@id" />; -->
</xsl:if>

<xsl:for-each select="children" >
<xsl:if test="../father/@id">
<xsl:value-of select="@id" />-&gt;<xsl:value-of select="../father/@id" />;
</xsl:if>
<xsl:if test="../mother/@id">
<xsl:value-of select="@id" />-&gt;<xsl:value-of select="../mother/@id" />;
</xsl:if>
</xsl:for-each>

</xsl:template>

<xsl:template match="indi">
<xsl:value-of select="@id" />[label=&quot;<xsl:call-template name="shortindiname">
		<xsl:with-param name="id" select="@id"/>
	</xsl:call-template> &quot;];
</xsl:template>


<xsl:template name="shortindiname">
	<xsl:param name="id" />
	<xsl:for-each select="key('indilist', $id)">
	<b>
	<xsl:call-template name="titleize">
		<xsl:with-param name="s" select="name"/>
	</xsl:call-template>	
	</b>
	<xsl:if test="surname">
		<xsl:text> </xsl:text>
		<xsl:call-template name="titleize">
			<xsl:with-param name="s" select="surname"/>
		</xsl:call-template>	
	</xsl:if>
	<xsl:if test="born or dead">\n(<xsl:if test="born"><xsl:value-of select="born" /></xsl:if>-<xsl:if test="dead"><xsl:value-of select="dead" /></xsl:if>)</xsl:if>
	</xsl:for-each>

</xsl:template>


<xsl:template name="titleize">
	<xsl:param name="s" />
	<xsl:call-template name="toupper">
		<xsl:with-param name="s" select="substring($s,1,1)"/>
	</xsl:call-template>	
	<xsl:call-template name="tolower">
		<xsl:with-param name="s" select="substring($s,2)"/>
	</xsl:call-template>	
</xsl:template>

<xsl:template name="toupper">
	<xsl:param name="s" />
	<xsl:value-of select="translate($s,'abcdefghijklmnopqrstuvwxyz','ABCDEFGHIJKLMNOPQRSTUVWXYZ')" />
</xsl:template>

<xsl:template name="tolower">
	<xsl:param name="s" />
	<xsl:value-of select="translate($s,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')" />
</xsl:template>



</xsl:stylesheet>

