﻿<?xml version="1.0" encoding="UTF-8" ?>

<xsl:stylesheet version="1.0"
	xmlns="http://www.w3.org/1999/xhtml"
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
	xmlns:foaf="http://xmlns.com/foaf/0.1/"
	xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
	xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:rss="http://purl.org/rss/1.0/"
	exclude-result-prefixes="foaf rdf rdfs dc">
 
<xsl:template match="/">
	<html xml:lang="ja" lang="ja">
	<head>
		<title>FOAF meta-data of
			<xsl:value-of select="rdf:RDF/foaf:Person/foaf:name"/>
		</title>
		<link rel="stylesheet" href="foaf.css" type="text/css" />
	</head>
	<body>
		<h1>FOAF meta-data of
			<xsl:value-of select="rdf:RDF/foaf:Person/foaf:name"/>
		</h1>
		<xsl:apply-templates select="rdf:RDF/foaf:Person"/>
		<address>This is a visual presentation of FOAF metadata via XSLT. See source for its XML serialization.</address>
	</body>
	</html>
</xsl:template>

<xsl:template match="foaf:Person">
	<table cellspacing="3">
		<tbody>
			<xsl:apply-templates select="foaf:name"/>
			<xsl:apply-templates select="foaf:nick"/>
			<xsl:apply-templates select="foaf:gender"/>
			<xsl:apply-templates select="foaf:mbox"/>
			<xsl:apply-templates select="foaf:skypeChatID"/>
			<xsl:apply-templates select="foaf:homepage"/>
			<xsl:apply-templates select="foaf:weblog"/>
			<tr>
				<td valign="top" class="property">
					<p>Interest</p>
				</td>
				<td valign="top" class="value">
					<ul>
						<xsl:apply-templates select="foaf:interest"/>
					</ul>
				</td>
			</tr>
			<tr>
				<td valign="top" class="property">
					<p>Friends</p>
				</td>
				<td valign="top" class="value">
					<ul>
						<xsl:apply-templates select="foaf:knows"/>
					</ul>
				</td>
			</tr>
		</tbody>
	</table>
</xsl:template>

<xsl:template match="foaf:name">
	<tr>
		<td valign="top" class="property">
			<p>Name</p>
		</td>
		<td valign="top" class="value">
			<p>
				<xsl:value-of select="."/>
			</p>
		</td>
	</tr>
</xsl:template>

<xsl:template match="foaf:nick">
	<tr>
		<td valign="top" class="property">
			<p>My Nick</p>
		</td>
		<td valign="top" class="value">
			<p>
				<xsl:value-of select="."/>
			</p>
		</td>
	</tr>
</xsl:template>

<xsl:template match="foaf:gender">
	<tr>
		<td valign="top" class="property">
			<p>Gender</p>
		</td>
		<td valign="top" class="value">
			<p>
				<xsl:choose>
					<xsl:when test=".='male'">Male</xsl:when>
					<xsl:when test=".='female'">Female</xsl:when>
					<xsl:otherwise>Unknown</xsl:otherwise>
				</xsl:choose>
			</p>
		</td>
	</tr>
</xsl:template>

<xsl:template match="foaf:mbox">
	<tr>
		<td valign="top" class="property">
			<p>Mail</p>
		</td>
		<td valign="top" class="value">
			<p>
				<xsl:value-of select="@rdf:resource"/>
				<xsl:apply-templates select="foaf:mbox_sha1sum"/>
			</p>
		</td>
	</tr>
</xsl:template>

<xsl:template match="foaf:mbox_sha1sum">
	(<xsl:value-of select="."/>)
</xsl:template>

<xsl:template match="foaf:homepage">
	<tr>
		<td valign="top" class="property">
			<p>Web Site</p>
		</td>
		<td valign="top" class="value">
			<p>
				<a>
					<xsl:attribute name="href">
						<xsl:value-of select="@rdf:resource"/>
					</xsl:attribute>
					<xsl:value-of select="@dc:title"/>
				</a>
			</p>
		</td>
	</tr>
</xsl:template>

<xsl:template match="foaf:weblog">
	<tr>
		<td valign="top" class="property">
			<p>Weblog</p>
		</td>
		<td valign="top" class="value">
			<p>
				<a>
					<xsl:attribute name="href">
						<xsl:value-of select="@rdf:resource"/>
					</xsl:attribute>
					<xsl:value-of select="@dc:title"/>
				</a>
			</p>
			<ul>
				<xsl:for-each select="document('index.rdf')/rdf:RDF/rss:item">
					<li>
						<a>
							<xsl:attribute name="href">
								<xsl:value-of select="rss:link"/>
							</xsl:attribute>
							<xsl:value-of select="rss:title"/>
						</a>
					</li>
				</xsl:for-each>
			</ul>
		</td>
	</tr>
</xsl:template>
<xsl:template match="foaf:skypeChatID">
	<tr>
		<td valign="top" class="property">
			<p>Skype</p>
		</td>
		<td valign="top" class="value">
			<p>
				<xsl:value-of select="."/>
			</p>
		</td>
	</tr>
</xsl:template>

<xsl:template match="foaf:interest">
	<li>
		<a>
			<xsl:attribute name="href">
				<xsl:value-of select="@rdf:resource"/>
			</xsl:attribute>
			<xsl:value-of select="@dc:title"/>
		</a>
	</li>
</xsl:template>

<xsl:template match="foaf:knows">
	<li>
		<a>
			<xsl:attribute name="href">
				<xsl:value-of select="foaf:Person/rdfs:seeAlso/@rdf:resource"/>
			</xsl:attribute>
			<xsl:value-of select="foaf:Person/foaf:nick"/>
		</a>
	</li>
</xsl:template>

</xsl:stylesheet>
