<?xml version="1.0" encoding="utf-8"?>

<xsl:stylesheet
  version="1.0"
  xmlns="http://www.w3.org/1999/xhtml"
  xmlns:xhtml="http://www.w3.org/1999/xhtml"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:familyweb="http://www.croftsoft.com/library/tutorials/familyweb">

<xsl:output
  method="html"
  indent="no" />

<xsl:variable name="root"     select="/familyweb:familyweb"/>
<xsl:variable name="template" select="document('familyweb.html')"/>

<xsl:template match="/">
  <xsl:apply-templates select="$template/node()"/>
</xsl:template>

<xsl:template match="xhtml:title">
  <xsl:choose>
    <xsl:when test="$root/familyweb:name/node()">
      <xsl:copy>
        <xsl:value-of
          select="$root/familyweb:name/node()"/>
      </xsl:copy>
    </xsl:when>
    <xsl:otherwise>
      <xsl:copy>
        <xsl:value-of select="current()" />
      </xsl:copy>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>

<xsl:template match="familyweb:content">

<center>
  <h1>
	  <xsl:choose>
	    <xsl:when test="$root/familyweb:name/node()">
	      <xsl:apply-templates select="$root/familyweb:name/node()"/>
	    </xsl:when>
	    <xsl:otherwise>
	      <xsl:apply-templates select="node()"/>
	    </xsl:otherwise>
	  </xsl:choose>
  </h1>
</center>

<hr />

<h2>
  Parents
</h2>
  
<xsl:apply-templates select="$root/familyweb:parent" />
<xsl:apply-templates select="$root/familyweb:father" />
<xsl:apply-templates select="$root/familyweb:mother" />
  
<h2>
  Children
</h2>
  
<xsl:apply-templates select="$root/familyweb:child" />
<xsl:apply-templates select="$root/familyweb:son" />
<xsl:apply-templates select="$root/familyweb:daughter" />
  
<h2>
  Other Relations
</h2>
  
<xsl:apply-templates select="$root/familyweb:sibling" />
<xsl:apply-templates select="$root/familyweb:brother" />
<xsl:apply-templates select="$root/familyweb:sister" />
<xsl:apply-templates select="$root/familyweb:spouse" />
<xsl:apply-templates select="$root/familyweb:husband" />
<xsl:apply-templates select="$root/familyweb:wife" />
  
<h2>
  Basic Data
</h2>

<xsl:apply-templates select="$root/familyweb:name" />
<xsl:apply-templates select="$root/familyweb:nickname" />
<xsl:apply-templates select="$root/familyweb:gender" />
<xsl:apply-templates select="$root/familyweb:birth_date" />
<xsl:apply-templates select="$root/familyweb:birth_place" />
<xsl:apply-templates select="$root/familyweb:marriage_date" />
<xsl:apply-templates select="$root/familyweb:marriage_place" />
<xsl:apply-templates select="$root/familyweb:death_date" />
<xsl:apply-templates select="$root/familyweb:death_place" />
<xsl:apply-templates select="$root/familyweb:burial_place" />

<xsl:apply-templates select="$root/familyweb:history" />
<xsl:apply-templates select="$root/familyweb:source" />
<xsl:apply-templates select="$root/familyweb:notes" />

<hr />

<center>
<a target="_blank"
  href="http://www.croftsoft.com/library/tutorials/familyweb/">
  Family Web</a>
</center>

</xsl:template>

<xsl:template match="familyweb:parent">
<b>
  Parent:
</b>
<xsl:if test="familyweb:url">
<a>
  <xsl:attribute name="href">
    <xsl:value-of select="familyweb:url" />
  </xsl:attribute>
  <xsl:value-of select="familyweb:name" />
</a>
</xsl:if>
<xsl:if test="not(familyweb:url)">
  <xsl:value-of select="familyweb:name" />
</xsl:if>
<br />
</xsl:template>

<xsl:template match="familyweb:father">
<b>
  Father:
</b>
<xsl:if test="familyweb:url">
<a>
  <xsl:attribute name="href">
    <xsl:value-of select="familyweb:url" />
  </xsl:attribute>
  <xsl:value-of select="familyweb:name" />
</a>
</xsl:if>
<xsl:if test="not(familyweb:url)">
  <xsl:value-of select="familyweb:name" />
</xsl:if>
<br />
</xsl:template>

<xsl:template match="familyweb:mother">
<b>
  Mother:
</b>
<xsl:if test="familyweb:url">
<a>
  <xsl:attribute name="href">
    <xsl:value-of select="familyweb:url" />
  </xsl:attribute>
  <xsl:value-of select="familyweb:name" />
</a>
</xsl:if>
<xsl:if test="not(familyweb:url)">
  <xsl:value-of select="familyweb:name" />
</xsl:if>
<br />
</xsl:template>

<xsl:template match="familyweb:child">
<b>
  Child:
</b>
<xsl:if test="familyweb:url">
<a>
  <xsl:attribute name="href">
    <xsl:value-of select="familyweb:url" />
  </xsl:attribute>
  <xsl:value-of select="familyweb:name" />
</a>
</xsl:if>
<xsl:if test="not(familyweb:url)">
  <xsl:value-of select="familyweb:name" />
</xsl:if>
<br />
</xsl:template>

<xsl:template match="familyweb:son">
<b>
  Son:
</b>
<xsl:if test="familyweb:url">
<a>
  <xsl:attribute name="href">
    <xsl:value-of select="familyweb:url" />
  </xsl:attribute>
  <xsl:value-of select="familyweb:name" />
</a>
</xsl:if>
<xsl:if test="not(familyweb:url)">
  <xsl:value-of select="familyweb:name" />
</xsl:if>
<br />
</xsl:template>

<xsl:template match="familyweb:daughter">
<b>
  Daughter:
</b>
<xsl:if test="familyweb:url">
<a>
  <xsl:attribute name="href">
    <xsl:value-of select="familyweb:url" />
  </xsl:attribute>
  <xsl:value-of select="familyweb:name" />
</a>
</xsl:if>
<xsl:if test="not(familyweb:url)">
  <xsl:value-of select="familyweb:name" />
</xsl:if>
<br />
</xsl:template>

<xsl:template match="familyweb:spouse">
<b>
  Spouse:
</b>
<xsl:if test="familyweb:url">
<a>
  <xsl:attribute name="href">
    <xsl:value-of select="familyweb:url" />
  </xsl:attribute>
  <xsl:value-of select="familyweb:name" />
</a>
</xsl:if>
<xsl:if test="not(familyweb:url)">
  <xsl:value-of select="familyweb:name" />
</xsl:if>
<br />
</xsl:template>

<xsl:template match="familyweb:husband">
<b>
  Husband:
</b>
<xsl:if test="familyweb:url">
<a>
  <xsl:attribute name="href">
    <xsl:value-of select="familyweb:url" />
  </xsl:attribute>
  <xsl:value-of select="familyweb:name" />
</a>
</xsl:if>
<xsl:if test="not(familyweb:url)">
  <xsl:value-of select="familyweb:name" />
</xsl:if>
<br />
</xsl:template>

<xsl:template match="familyweb:wife">
<b>
  Wife:
</b>
<xsl:if test="familyweb:url">
<a>
  <xsl:attribute name="href">
    <xsl:value-of select="familyweb:url" />
  </xsl:attribute>
  <xsl:value-of select="familyweb:name" />
</a>
</xsl:if>
<xsl:if test="not(familyweb:url)">
  <xsl:value-of select="familyweb:name" />
</xsl:if>
<br />
</xsl:template>

<xsl:template match="familyweb:sibling">
<b>
  Sibling:
</b>
<xsl:if test="familyweb:url">
<a>
  <xsl:attribute name="href">
    <xsl:value-of select="familyweb:url" />
  </xsl:attribute>
  <xsl:value-of select="familyweb:name" />
</a>
</xsl:if>
<xsl:if test="not(familyweb:url)">
  <xsl:value-of select="familyweb:name" />
</xsl:if>
<br />
</xsl:template>

<xsl:template match="familyweb:brother">
<b>
  Brother:
</b>
<xsl:if test="familyweb:url">
<a>
  <xsl:attribute name="href">
    <xsl:value-of select="familyweb:url" />
  </xsl:attribute>
  <xsl:value-of select="familyweb:name" />
</a>
</xsl:if>
<xsl:if test="not(familyweb:url)">
  <xsl:value-of select="familyweb:name" />
</xsl:if>
<br />
</xsl:template>

<xsl:template match="familyweb:sister">
<b>
  Sister:
</b>
<xsl:if test="familyweb:url">
<a>
  <xsl:attribute name="href">
    <xsl:value-of select="familyweb:url" />
  </xsl:attribute>
  <xsl:value-of select="familyweb:name" />
</a>
</xsl:if>
<xsl:if test="not(familyweb:url)">
  <xsl:value-of select="familyweb:name" />
</xsl:if>
<br />
</xsl:template>

<xsl:template match="familyweb:name">
<b>
  Name:
</b>
<xsl:value-of select="." />
<br />
</xsl:template>

<xsl:template match="familyweb:nickname">
<b>
  Nickname:
</b>
<xsl:value-of select="." />
<br />
</xsl:template>

<xsl:template match="familyweb:gender">
<b>
  Gender:
</b>
<xsl:value-of select="." />
<br />
</xsl:template>

<xsl:template match="familyweb:birth_date">
<b>
  Birth Date:
</b>
<xsl:value-of select="." />
<br />
</xsl:template>

<xsl:template match="familyweb:birth_date">
<b>
  Birth Date:
</b>
<xsl:value-of select="." />
<br />
</xsl:template>

<xsl:template match="familyweb:birth_place">
<b>
  Birth Place:
</b>
<xsl:value-of select="." />
<br />
</xsl:template>

<xsl:template match="familyweb:marriage_date">
<b>
  Marriage Date:
</b>
<xsl:value-of select="." />
<br />
</xsl:template>

<xsl:template match="familyweb:marriage_place">
<b>
  Marriage Place:
</b>
<xsl:value-of select="." />
<br />
</xsl:template>

<xsl:template match="familyweb:death_date">
<b>
  Death Date:
</b>
<xsl:value-of select="." />
<br />
</xsl:template>

<xsl:template match="familyweb:death_place">
<b>
  Death Place:
</b>
<xsl:value-of select="." />
<br />
</xsl:template>

<xsl:template match="familyweb:burial_place">
<b>
  Burial Place:
</b>
<xsl:value-of select="." />
<br />
</xsl:template>

<xsl:template match="familyweb:source">
<a name="source" />
<h2>
  Source
</h2>
<xsl:apply-templates select="@*|node()" />
</xsl:template>

<xsl:template match="familyweb:history">
<h2>
  History
</h2>
<xsl:apply-templates select="@*|node()" />
</xsl:template>

<xsl:template match="familyweb:notes">
<h2>
  Notes
</h2>
<xsl:apply-templates select="@*|node()" />
</xsl:template>

<xsl:template match="@*|node()">
  <xsl:copy>
    <xsl:apply-templates select="@*|node()" />
  </xsl:copy>
</xsl:template>

</xsl:stylesheet>