<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                            xmlns:rdf ="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
                            xmlns:owl="http://www.w3.org/2002/07/owl#"
                            xmlns:xsd="http://www.w3.org/2000/10/XMLSchema#"
                            xmlns:ged="http://jay.askren.net/gedcom/rdf"
             version="1.1">
<xsl:output method="html" />
<xsl:template match="/rdf:RDF">
    <html>
        
        <xsl:variable name="firstIndividualId">
            <xsl:call-template name="getFirstIndividualId"/>
        </xsl:variable>
        
        <xsl:variable name="fatherId">
            <xsl:call-template name="getFatherId"> 
                <xsl:with-param name="id" select="$firstIndividualId"></xsl:with-param>
            </xsl:call-template>
        </xsl:variable>
        
        <xsl:variable name="fathersFatherId">
            <xsl:call-template name="getFatherId"> 
                <xsl:with-param name="id" select="$fatherId"></xsl:with-param>
            </xsl:call-template>
        </xsl:variable>
        
        <xsl:variable name="fathersFathersFatherId">
            <xsl:call-template name="getFatherId"> 
                <xsl:with-param name="id" select="$fathersFatherId"></xsl:with-param>
            </xsl:call-template>
        </xsl:variable>
        
        <xsl:variable name="fathersFathersMotherId">
            <xsl:call-template name="getMotherId"> 
                <xsl:with-param name="id" select="$fathersFatherId"></xsl:with-param>
            </xsl:call-template>
        </xsl:variable>
        
        <xsl:variable name="fathersMotherId">
            <xsl:call-template name="getMotherId"> 
                <xsl:with-param name="id" select="$fatherId"></xsl:with-param>
            </xsl:call-template>
        </xsl:variable>
        
        <xsl:variable name="fathersMothersFatherId">
            <xsl:call-template name="getFatherId"> 
                <xsl:with-param name="id" select="$fathersMotherId"></xsl:with-param>
            </xsl:call-template>
        </xsl:variable>
        
        <xsl:variable name="fathersMothersMotherId">
            <xsl:call-template name="getMotherId"> 
                <xsl:with-param name="id" select="$fathersMotherId"></xsl:with-param>
            </xsl:call-template>
        </xsl:variable>
        
        <xsl:variable name="motherId">
            <xsl:call-template name="getMotherId">
                <xsl:with-param name="id" select="$firstIndividualId"></xsl:with-param>
            </xsl:call-template>
        </xsl:variable>
        
        <xsl:variable name="mothersFatherId">
            <xsl:call-template name="getFatherId"> 
                <xsl:with-param name="id" select="$motherId"></xsl:with-param>
            </xsl:call-template>
        </xsl:variable>
        
        <xsl:variable name="mothersFathersFatherId">
            <xsl:call-template name="getFatherId"> 
                <xsl:with-param name="id" select="$mothersFatherId"></xsl:with-param>
            </xsl:call-template>
        </xsl:variable>
        
        <xsl:variable name="mothersFathersMothersId">
            <xsl:call-template name="getMotherId"> 
                <xsl:with-param name="id" select="$mothersFatherId"></xsl:with-param>
            </xsl:call-template>
        </xsl:variable>
        
        <xsl:variable name="mothersMotherId">
            <xsl:call-template name="getMotherId"> 
                <xsl:with-param name="id" select="$motherId"></xsl:with-param>
            </xsl:call-template>
        </xsl:variable>
        
        <xsl:variable name="mothersMothersFatherId">
            <xsl:call-template name="getFatherId"> 
                <xsl:with-param name="id" select="$mothersMotherId"></xsl:with-param>
            </xsl:call-template>
        </xsl:variable>
        
        <xsl:variable name="mothersMothersMotherId">
            <xsl:call-template name="getMotherId"> 
                <xsl:with-param name="id" select="$mothersMotherId"></xsl:with-param>
            </xsl:call-template>
        </xsl:variable>
        
        <head>
            <STYLE type="text/css">
                SUP {font-family:"Times New Roman"; font-size:11pt; line-height:11pt}
            </STYLE>
            <title>  Family Tree of <xsl:call-template name="getName"> 
                                                    <xsl:with-param name="id" select="$firstIndividualId"></xsl:with-param>
                                                </xsl:call-template>
            </title>
        </head>
        <body background="bg.gif" bgcolor="#E6E0DB">        
            <table  width="770" cellpadding="0" cellspacing="0" >
                <tr><td><H3># Individuals in Gedcom File = <xsl:value-of select="count(/rdf:RDF/Individual)" /></H3></td>
                        <td><H3># Families in Gedcom File = <xsl:value-of select="count(/rdf:RDF/Family)" /></H3></td></tr>
                        </table>
            <br/>
            
            <table  width="770" cellpadding="0" cellspacing="0" border="0" bg="bg.gif">
                <tr> <td><img src="bg.gif" width="70" height="11"/></td>
                        <td><img src="bg.gif" width="100" height="11"/></td>
                        <td><img src="bg.gif" width="100" height="11"/></td>
                        <td><img src="bg.gif" width="100" height="11"/></td>
                        <td><img src="bg.gif" width="100" height="11"/></td>
                        <td><img src="bg.gif" width="30" height="11"/></td>
                        <td><img src="bg.gif" width="200" height="11"/></td>
                        <td><img src="bg.gif" width="70" height="11"/></td></tr>

                <tr><td colspan="4"><img src="bg.gif" width="370" height="55"/></td>
                        <td><img src="ct2.gif" width="100" height="75"/></td>
                        <td><img src="ct1.gif" width="30" height="75"/></td>
                        <td width="200" height="55" bgcolor="#FFFFFF">
                                        <sup> 
                                            <xsl:call-template name="getName">
                                                <xsl:with-param name="id" select="$fathersFathersFatherId"></xsl:with-param>
                                            </xsl:call-template><br/>
                                            <xsl:call-template name="getBirth">
                                                <xsl:with-param name="id" select="$fathersFathersFatherId"></xsl:with-param>
                                            </xsl:call-template><br/>
                                            <xsl:call-template name="getDeath">
                                                <xsl:with-param name="id" select="$fathersFathersFatherId"></xsl:with-param>
                                            </xsl:call-template>
                                        </sup>
                         </td>
                        <td>
                                    <xsl:call-template name="hasParent"> 
                                        <xsl:with-param name="id" select="$fathersFathersFatherId"></xsl:with-param>
                                    </xsl:call-template>
                                </td></tr>

                <tr><td colspan="4"><img src="bg.gif" width="370" height="11"/></td>
                        <td><img src="ct3.gif" width="100" height="30"/></td>
                        <td><img src="bg.gif" width="30" height="11"/></td></tr>

                <tr><td colspan="2"><img src="bg.gif" width="170" height="55"/></td>
                        <td><img src="ct2.gif" width="100" height="75"/></td>
                        <td colspan="2" width="200" height="55" bgcolor="#FFFFFF">
                                        <sup> 
                                            <xsl:call-template name="getName">
                                                <xsl:with-param name="id" select="$fathersFatherId"></xsl:with-param>
                                            </xsl:call-template>
                                            <br/>
                                            <xsl:call-template name="getBirth">
                                                <xsl:with-param name="id" select="$fathersFatherId"></xsl:with-param>
                                            </xsl:call-template><br/>
                                            <xsl:call-template name="getDeath">
                                                <xsl:with-param name="id" select="$fathersFatherId"></xsl:with-param>
                                            </xsl:call-template>
                                        </sup>
                                        </td>
                        
                        <td><img src="ct1.gif" width="30" height="75"/></td>
                        <td width="200" height="55" bgcolor="#FFFFFF">
                                        <sup>
                                            <xsl:call-template name="getName">
                                                <xsl:with-param name="id" select="$fathersFathersMotherId"></xsl:with-param>
                                            </xsl:call-template>        
                                            <br/>
                                            <xsl:call-template name="getBirth">
                                                <xsl:with-param name="id" select="$fathersFathersMotherId"></xsl:with-param>
                                            </xsl:call-template><br/>
                                            <xsl:call-template name="getDeath">
                                                <xsl:with-param name="id" select="$fathersFathersMotherId"></xsl:with-param>
                                            </xsl:call-template>
                                        </sup>
                        </td>
                        <td>
                                    <xsl:call-template name="hasParent"> 
                                        <xsl:with-param name="id" select="$fathersFathersMotherId"></xsl:with-param>
                                    </xsl:call-template>
                                </td></tr>

                    <tr><td><img src="bg.gif" width="70" height="11"/></td>
                            <td><img src="bg.gif" width="100" height="11"/></td>
                            <td><img src="ct3.gif" width="100" height="30"/></td></tr>
                            
                    <tr><td><img src="bg.gif" width="70" height="55"/></td>
                            <td><img src="ct2.gif" width="100" height="75"/></td>
                            <td colspan="2" width="200" height="55" bgcolor="#FFFFFF">
                                <sup> 
                                        <xsl:call-template name="getName">
                                           <xsl:with-param name="id" select="$fatherId"></xsl:with-param>
                                        </xsl:call-template><br/>
                                        <xsl:call-template name="getBirth">
                                                <xsl:with-param name="id" select="$fatherId"></xsl:with-param>
                                            </xsl:call-template><br/>
                                            <xsl:call-template name="getDeath">
                                                <xsl:with-param name="id" select="$fatherId"></xsl:with-param>
                                            </xsl:call-template>
                                        
                                </sup>
                                </td>
                            <td><img src="ct2.gif" width="100" height="75"/></td>
                            <td><img src="ct1.gif" width="30" height="75"/></td>
                            <td width="200" height="55" bgcolor="#FFFFFF">
                                <sup> 
                                    <xsl:call-template name="getName">
                                                <xsl:with-param name="id" select="$fathersMothersFatherId"></xsl:with-param>
                                    </xsl:call-template> 
                                    <br/>
                                    <xsl:call-template name="getBirth">
                                                <xsl:with-param name="id" select="$fathersMothersFatherId"></xsl:with-param>
                                            </xsl:call-template><br/>
                                            <xsl:call-template name="getDeath">
                                                <xsl:with-param name="id" select="$fathersMothersFatherId"></xsl:with-param>
                                            </xsl:call-template>
                                </sup>
                            </td><td>
                                    <xsl:call-template name="hasParent"> 
                                        <xsl:with-param name="id" select="$fathersMothersFatherId"></xsl:with-param>
                                    </xsl:call-template>
                                </td>
                            </tr>

                    <tr><td><img src="bg.gif" width="70" height="11"/></td>
                            <td><img src="ct3.gif" width="100" height="30"/></td>
                            <td><img src="ct3.gif" width="100" height="30"/></td>
                            <td><img src="bg.gif" width="100" height="11"/></td>
                            <td><img src="ct3.gif" width="100" height="30"/></td></tr>

                    <tr><td><img src="bg.gif" width="70" height="55"/></td>
                            <td><img src="ct5.gif" width="100" height="75"/></td>
                            <td><img src="ct4.gif" width="100" height="75"/></td>
                            <td colspan="2" width="200" height="55" bgcolor="#FFFFFF">
                                <sup> 
                                    <xsl:call-template name="getName">
                                        <xsl:with-param name="id" select="$fathersMotherId"></xsl:with-param>
                                    </xsl:call-template>
                                    <br/>
                                <xsl:call-template name="getBirth">
                                                <xsl:with-param name="id" select="$fathersMotherId"></xsl:with-param>
                                            </xsl:call-template><br/>
                                            <xsl:call-template name="getDeath">
                                                <xsl:with-param name="id" select="$fathersMotherId"></xsl:with-param>
                                            </xsl:call-template>
                                </sup>
                                </td>
                             <td><img src="ct1.gif" width="30" height="75"/></td>
                             <td width="200" height="55" bgcolor="#FFFFFF">
                                 <sup> 
                                     <xsl:call-template name="getName">
                                                <xsl:with-param name="id" select="$fathersMothersMotherId"></xsl:with-param>
                                     </xsl:call-template> 
                                     <br/>
                                     <xsl:call-template name="getBirth">
                                                <xsl:with-param name="id" select="$fathersMothersMotherId"></xsl:with-param>
                                            </xsl:call-template><br/>
                                            <xsl:call-template name="getDeath">
                                                <xsl:with-param name="id" select="$fathersMothersMotherId"></xsl:with-param>
                                            </xsl:call-template>
                                 </sup>
                             </td><td>
                                    <xsl:call-template name="hasParent"> 
                                        <xsl:with-param name="id" select="$fathersMothersMotherId"></xsl:with-param>
                                    </xsl:call-template>
                                </td>
                    </tr>

                    <tr><td><img src="bg.gif" width="70" height="11"/></td>
                            <td><img src="ct3.gif" width="100" height="30"/></td></tr>

                    <tr><td>
                                    <xsl:call-template name="hasChild"> 
                                        <xsl:with-param name="id" select="$firstIndividualId"></xsl:with-param>
                                    </xsl:call-template>
                                </td>
                            <td colspan="2" width="200" height="55" bgcolor="#FFFFFF">
                                <sup>
                                    <xsl:call-template name="getName"> 
                                        <xsl:with-param name="id" select="$firstIndividualId"></xsl:with-param>
                                    </xsl:call-template>
                                    <br/>
                                    <xsl:call-template name="getBirth">
                                                <xsl:with-param name="id" select="$firstIndividualId"></xsl:with-param>
                                            </xsl:call-template><br/>
                                            <xsl:call-template name="getDeath">
                                                <xsl:with-param name="id" select="$firstIndividualId"></xsl:with-param>
                                            </xsl:call-template>
                                </sup>
                                </td>
                            <td><img src="bg.gif" width="100" height="55"/></td>
                            <td><img src="ct2.gif" width="100" height="75"/></td>
                            <td><img src="ct1.gif" width="30" height="75"/></td>
                            <td width="200" height="55" bgcolor="#FFFFFF">
                                <sup> 
                                    <xsl:call-template name="getName">
                                                <xsl:with-param name="id" select="$mothersFathersFatherId"></xsl:with-param>
                                    </xsl:call-template> 
                                    <br/>
                                    <xsl:call-template name="getBirth">
                                                <xsl:with-param name="id" select="$mothersFathersFatherId"></xsl:with-param>
                                            </xsl:call-template><br/>
                                            <xsl:call-template name="getDeath">
                                                <xsl:with-param name="id" select="$mothersFathersFatherId"></xsl:with-param>
                                            </xsl:call-template>
                                </sup>
                            </td><td>
                                    <xsl:call-template name="hasParent"> 
                                        <xsl:with-param name="id" select="$mothersFathersFatherId"></xsl:with-param>
                                    </xsl:call-template>
                               </td>
                    </tr>

                    <tr><td><img src="bg.gif" width="70" height="11"/></td>
                            <td><img src="ct3.gif" width="100" height="30"/></td>
                            <td><img src="bg.gif" width="100" height="11"/></td>
                            <td><img src="bg.gif" width="100" height="11"/></td>
                            <td><img src="ct3.gif" width="100" height="30"/></td></tr>

                    <tr><td><img src="bg.gif" width="70" height="55"/></td>
                            <td><img src="ct5.gif" width="100" height="75"/></td>
                            <td><img src="ct2.gif" width="100" height="75"/></td>
                            <td colspan="2" width="200" height="55" bgcolor="#FFFFFF">
                                <sup> 
                                    <xsl:call-template name="getName">
                                        <xsl:with-param name="id" select="$mothersFatherId"></xsl:with-param>
                                    </xsl:call-template>
                                    <br/>
                                    <xsl:call-template name="getBirth">
                                                <xsl:with-param name="id" select="$mothersFatherId"></xsl:with-param>
                                            </xsl:call-template><br/>
                                            <xsl:call-template name="getDeath">
                                                <xsl:with-param name="id" select="$mothersFatherId"></xsl:with-param>
                                            </xsl:call-template>
                                </sup>
                                </td>
                            <td><img src="ct1.gif" width="30" height="75"/></td>
                            <td width="200" height="55" bgcolor="#FFFFFF">
                                <sup> 
                                    <xsl:call-template name="getName">
                                        <xsl:with-param name="id" select="$mothersFathersMothersId"></xsl:with-param>
                                    </xsl:call-template>
                                    <br/>
                                    <xsl:call-template name="getBirth">
                                                <xsl:with-param name="id" select="$mothersFathersMothersId"></xsl:with-param>
                                            </xsl:call-template><br/>
                                            <xsl:call-template name="getDeath">
                                                <xsl:with-param name="id" select="$mothersFathersMothersId"></xsl:with-param>
                                            </xsl:call-template>
                                </sup>
                            </td><td>
                                    <xsl:call-template name="hasParent"> 
                                        <xsl:with-param name="id" select="$mothersFathersMothersId"></xsl:with-param>
                                    </xsl:call-template>
                                </td>
                    </tr>
                    
                    <tr><td><img src="bg.gif" width="70" height="11"/></td>
                            <td><img src="ct3.gif" width="100" height="30"/></td>
                            <td><img src="ct3.gif" width="100" height="30"/></td></tr>

                    <tr><td><img src="bg.gif" width="70" height="55"/></td>
                            <td><img src="ct4.gif" width="100" height="75"/></td>
                            <td colspan="2" width="200" height="55" bgcolor="#FFFFFF">
                                <sup> 
                                    <xsl:call-template name="getName">
                                        <xsl:with-param name="id" select="$motherId"></xsl:with-param>
                                    </xsl:call-template><br/>
                                    <xsl:call-template name="getBirth">
                                                <xsl:with-param name="id" select="$motherId"></xsl:with-param>
                                            </xsl:call-template><br/>
                                            <xsl:call-template name="getDeath">
                                                <xsl:with-param name="id" select="$motherId"></xsl:with-param>
                                            </xsl:call-template>
                                </sup>
                                </td>
                                <td><img src="ct2.gif" width="100" height="75"/></td>
                                <td><img src="ct1.gif" width="30" height="75"/></td>
                                <td width="200" height="55" bgcolor="#FFFFFF">
                                    <sup> 
                                        <xsl:call-template name="getName">
                                            <xsl:with-param name="id" select="$mothersMothersFatherId"></xsl:with-param>
                                        </xsl:call-template>
                                        <br/>
                                    <xsl:call-template name="getBirth">
                                                <xsl:with-param name="id" select="$mothersMothersFatherId"></xsl:with-param>
                                            </xsl:call-template><br/>
                                            <xsl:call-template name="getDeath">
                                                <xsl:with-param name="id" select="$mothersMothersFatherId"></xsl:with-param>
                                            </xsl:call-template></sup>
                                </td><td>
                                    <xsl:call-template name="hasParent"> 
                                        <xsl:with-param name="id" select="$mothersMothersFatherId"></xsl:with-param>
                                    </xsl:call-template>
                               </td>
                    </tr>
                    
                    <tr><td colspan="2"><img src="bg.gif" width="170" height="11"/></td>
                            <td><img src="ct3.gif" width="100" height="30"/></td>
                            <td><img src="bg.gif" width="100" height="11"/></td>
                            <td><img src="ct3.gif" width="100" height="30"/></td></tr>

                    <tr><td colspan="2"></td>
                            <td><img src="ct4.gif" width="100" height="75"/></td>
                            <td colspan="2" width="200" height="55" bgcolor="#FFFFFF">
                                <sup> 
                                    <xsl:call-template name="getName">
                                        <xsl:with-param name="id" select="$mothersMotherId"></xsl:with-param>
                                    </xsl:call-template>
                                <br/>
                                <xsl:call-template name="getBirth">
                                                <xsl:with-param name="id" select="$mothersMotherId"></xsl:with-param>
                                            </xsl:call-template><br/>
                                            <xsl:call-template name="getDeath">
                                                <xsl:with-param name="id" select="$mothersMotherId"></xsl:with-param>
                                            </xsl:call-template>
                                    </sup>
                                </td>
                                <td><img src="ct1.gif" width="30" height="75"/></td>
                                <td width="200" height="55" bgcolor="#FFFFFF">
                                    <sup> 
                                        <xsl:call-template name="getName">
                                            <xsl:with-param name="id" select="$mothersMothersMotherId"></xsl:with-param>
                                        </xsl:call-template>
                                        <br/>
                                        <xsl:call-template name="getBirth">
                                                <xsl:with-param name="id" select="$mothersMothersMotherId"></xsl:with-param>
                                            </xsl:call-template><br/>
                                            <xsl:call-template name="getDeath">
                                                <xsl:with-param name="id" select="$mothersMothersMotherId"></xsl:with-param>
                                            </xsl:call-template>
                                    </sup>
                                </td><td>
                                    <xsl:call-template name="hasParent"> 
                                        <xsl:with-param name="id" select="$mothersMothersMotherId"></xsl:with-param>
                                    </xsl:call-template>
                                </td>
                    </tr>
                    
</table>
            
            
         </body>
    </html>
    
</xsl:template>

<xsl:template name="getFirstIndividualId">
     <xsl:value-of select="/rdf:RDF/Individual/@rdf:ID"/>
</xsl:template> 

<xsl:template name="getFatherId">
    <xsl:param name="id"></xsl:param>
    
     <xsl:variable name="familyId">
            <xsl:for-each select="/rdf:RDF/Individual[@rdf:ID=$id]" >
                <xsl:value-of select="./childIn/Family/@rdf:resource" />
            </xsl:for-each>
     </xsl:variable>
     
     <xsl:for-each select="/rdf:RDF/Individual/spouseIn/Family[@rdf:resource=$familyId and ../../sex/xsd:string/@rdf:value='M']" >
            <xsl:value-of select="../../@rdf:ID" />
     </xsl:for-each>
     
</xsl:template>

<xsl:template name="getMotherId">
    <xsl:param name="id"></xsl:param>
         <xsl:variable name="familyId">
            <xsl:for-each select="/rdf:RDF/Individual[@rdf:ID=$id]" >
                <xsl:value-of select="./childIn/Family/@rdf:resource" />
            </xsl:for-each>
     </xsl:variable>
     
     <xsl:for-each select="/rdf:RDF/Individual/spouseIn/Family[@rdf:resource=$familyId and ../../sex/xsd:string/@rdf:value='F']" >
            <xsl:value-of select="../../@rdf:ID" />
     </xsl:for-each>
     
</xsl:template>

<xsl:template name="getName">
     <xsl:param name="id"></xsl:param>
     <xsl:for-each select="/rdf:RDF/Individual[@rdf:ID=$id]" >
             <xsl:value-of select="./name/xsd:string/@rdf:value" />
     </xsl:for-each>
</xsl:template>

<xsl:template name="getBirth">
     <xsl:param name="id"></xsl:param>
     <xsl:for-each select="/rdf:RDF/Individual[@rdf:ID=$id]" >
             b: <xsl:value-of select="./birth/date/xsd:date/@rdf:value" /> <br/> &#160;&#160;&#160; <xsl:value-of select="./birth/place/xsd:string/@rdf:value" />
     </xsl:for-each>
</xsl:template>

<xsl:template name="getDeath">
     <xsl:param name="id"></xsl:param>
     <xsl:for-each select="/rdf:RDF/Individual[@rdf:ID=$id]" >
             d: <xsl:value-of select="./death/date/xsd:date/@rdf:value" /> <br/> &#160;&#160;&#160; <xsl:value-of select="./death/place/xsd:string/@rdf:value" />
     </xsl:for-each>
</xsl:template>

<xsl:template name="hasParent">
     <xsl:param name="id"></xsl:param>
        <xsl:variable name="familyId">
            <xsl:for-each select="/rdf:RDF/Individual[@rdf:ID=$id]" >
                <xsl:value-of select="./childIn/Family/@rdf:resource" />
            </xsl:for-each>
     </xsl:variable>
     
     <xsl:variable name="parentCount">
         <xsl:value-of select="count(/rdf:RDF/Individual/spouseIn/Family[@rdf:resource=$familyId])"/>
     </xsl:variable>
     
     <xsl:if test="$parentCount &gt; 0" >
            <img src="car.gif" width="100" height="75"/>
     </xsl:if>
</xsl:template>

<xsl:template name="hasChild">
     <xsl:param name="id"></xsl:param>
     
      <xsl:variable name="familyId">
            <xsl:for-each select="/rdf:RDF/Individual[@rdf:ID=$id]" >
                <xsl:value-of select="./spouseIn/Family/@rdf:resource" />
            </xsl:for-each>
      </xsl:variable>
      
      <xsl:variable name="childCount">
         <xsl:value-of select="count(/rdf:RDF/Individual/childIn/Family[@rdf:resource=$familyId])"/>
      </xsl:variable>
      
     <xsl:if test="$childCount &gt; 0" >
            <img src="cal.gif" width="100" height="75"/>
     </xsl:if>
     
</xsl:template>


</xsl:stylesheet>
