<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:output method="html" encoding="ISO-8859-1" indent="yes"/>
	<xsl:key name="imageLookup" match="/familyTree/images/image" use="@id"/>
	<xsl:param name="SearchName">PETER</xsl:param>
	<xsl:param name="IncludePartner">0</xsl:param>
	<xsl:template match="/">
		<table class="border">
			<tr>
				<th colspan="3">Leibbrandts</th>
			</tr>
			<tr>
				<th>Name</th><th>Links</th><th>Notes</th>
			</tr>
			<xsl:for-each select="//person[contains(translate(concat(name, ' ', nickname),'abcdefghijklmnopqrstuvwxyz','ABCDEFGHIJKLMNOPQRSTUVWXYZ'), $SearchName)]">
				<xsl:sort select="name"/>
				<xsl:call-template name="personRow"/>
			</xsl:for-each>
			<xsl:if test="$IncludePartner=1">
			<tr>
				<th colspan="3">Partners (non-Leibbrandts)</th>
			</tr>
			<tr>
				<th>Name</th><th>Links</th><th>Notes</th>
			</tr>	
				<xsl:for-each select=" //partner[contains(translate(concat(name, ' ', surname, ' ', nickname),'abcdefghijklmnopqrstuvwxyz','ABCDEFGHIJKLMNOPQRSTUVWXYZ'), $SearchName)]">
					<xsl:sort select="name"/>
					<xsl:call-template name="personRow"/>
				</xsl:for-each>
			</xsl:if>
		</table>
	</xsl:template>
	<xsl:template name="personRow">
		<tr>
			<td class="border">
				<span class="NameID"><xsl:value-of select="name"/><xsl:if test="nickname!='' "> "<xsl:value-of select="nickname"/>"</xsl:if><xsl:if test="surname!='' "> (<xsl:value-of select="surname"/>)</xsl:if></span>
			</td>
			<td class="border">
				<a>
					<xsl:attribute name="href">Ancestors.asp?id=<xsl:value-of select="ancestor-or-self::*[name()='person']/@id"/></xsl:attribute>
					<img alt="Ancestors" title="Ancestors" src="Images/FamilyCrestXS.png" border="0"/>
				</a>
				<xsl:if test="partner/children">
					<a>
						<xsl:attribute name="href">Descendants.asp?id=<xsl:value-of select="ancestor-or-self::*[name()='person']/@id"/></xsl:attribute>
						<img alt="Descendants" title="Descendants" src="Images/ArrowRight.png" border="0"/>
					</a>
				</xsl:if>
			</td>
			<td class="border">
				<span class="notes">
					<xsl:if test="@id">[<xsl:value-of select="@id"/>] </xsl:if>
					<xsl:apply-templates select="born | died | married | divorced"/>
					<xsl:if test="notes">
						<br/>
						<xsl:value-of select="notes"/>
					</xsl:if>
				</span>
				<xsl:if test="images">
					<xsl:for-each select="images/image">
					<xsl:choose>
						<xsl:when test="starts-with(@idRef, 'Flag')">
						</xsl:when>
						<xsl:otherwise>
							<xsl:variable name="img" select="key('imageLookup', @idRef)"/>
							<xsl:text> </xsl:text>
							<a href="ImageDetail.asp?id={@idRef}">
								<img src="Images/{$img/@id}.t{@position}.{$img/@format}" height="96" width="80" alt="{name}"/>
							</a>
						</xsl:otherwise>
					</xsl:choose>
					</xsl:for-each>
					<br/>
				</xsl:if>
			</td>
		</tr>
	</xsl:template>
	<xsl:template match="born | died | married | divorced">
		<xsl:if test="position()!=1">, </xsl:if>
		<xsl:value-of select="name()"/>:<xsl:if test="@approx">&#x00B1;</xsl:if><xsl:value-of select="."/>
		<xsl:if test="@place"> at <xsl:value-of select="@place"/></xsl:if>
	</xsl:template>

</xsl:stylesheet>

