<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    
    <xsl:output indent="yes" method="xml"/>
    <xsl:template match="gedCom">
        <graph directed="0">
  			<!-- nodes -->           
            <xsl:apply-templates select="INDI"/>
             <!-- edges -->
            <!--<xsl:apply-templates select="FAM/MARR"/>-->
	    <xsl:apply-templates select="FAM"/>
        </graph>
    </xsl:template>
    
    <!--ignore the submission record.  I don't need this information-->
    <xsl:template match="SUBM"/>
    
    <!--This is required by the DTD-->
    <xsl:template match="HEAD">
        <HeaderRec>
            <FileCreation Date=""/>
            <Submitter>
                <Link Ref="" Target=""/>
            </Submitter>
        </HeaderRec>
    </xsl:template>
    
    <xsl:template match="FAM">
    	<xsl:for-each select="CHIL">
    			
                <edge source="{normalize-space(text())}" target="{normalize-space(parent::node()/HUSB)}"></edge>
                <edge source="{normalize-space(text())}" target="{normalize-space(parent::node()/WIFE)}"></edge>
                
        </xsl:for-each>
        
            
            <!--Each family should of course only have one husband and one wife, 
                but I couldn't figure out how to use an if statement instead of for-each -->
            <!--<xsl:for-each select="HUSB">
                <HusbFath>
                    <Link Target="IndividualRec" Ref="{normalize-space(text())}"/>
                </HusbFath>
            </xsl:for-each>
            
            <xsl:for-each select="WIFE">
                <WifeMoth>
                    <Link Target="IndividualRec" Ref="{normalize-space(text())}" />
                </WifeMoth>
            </xsl:for-each>-->
            
            
        
    </xsl:template>
    
    <xsl:template match="INDI">
        <node id="{normalize-space(text())}" label="{normalize-space(NAME)}">
        </node>
    </xsl:template>
    
   
    
   <xsl:template match="MARR">
        <EventRec Id="M{normalize-space(parent::node()/text())}" Type="marriage" VitalType="marriage">
            <xsl:for-each select="parent::node()/HUSB">
                <Participant>
                    <Link Target="IndividualRec" Ref="{normalize-space(parent::node()/HUSB)}"  />
                    <Role>husband</Role>
                </Participant>
            </xsl:for-each>
            
            <xsl:for-each select="parent::node()/WIFE">
                <Participant>
                    <Link Target="IndividualRec" Ref="{normalize-space(parent::node()/WIFE)}"  />
                    <Role>wife</Role>
                </Participant>
            </xsl:for-each>
            
            <Date Calendar="Julian">
                <xsl:value-of select="normalize-space(DATE)"/>
            </Date>
            
            <Place>
                <PlaceName>
                    <xsl:value-of select="normalize-space(PLAC)"/>
                </PlaceName>
            </Place>
            
        </EventRec>
    </xsl:template>
    
    
    
</xsl:stylesheet>
