<?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/"
  xmlns:admin="http://webns.net/mvcb/"
  xmlns:cc="http://web.resource.org/cc/"
  xmlns:mm="http://musicbrainz.org/mm/mm-2.1#"
  exclude-result-prefixes="foaf rdf rdfs dc"
  xml:lang="ja">
 
<xsl:template match="/">
  <html xmlns="http://www.w3.org/1999/xhtml" lang="ja" xml:lang="ja">
  <head>
    <title>FOAF meta-data of
      <xsl:value-of select="rdf:RDF/foaf:Person/foaf:name"/>
    </title>
    <link rel="stylesheet" href="./styles/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:msnChatID"/>
      <xsl:apply-templates select="foaf:homepage"/>
      <xsl:apply-templates select="foaf:weblog"/>
      <tr>
        <td valign="top" class="property">
          <p>興味あること</p>
        </td>
        <td valign="top" class="value">
          <ul>
            <xsl:apply-templates select="foaf:interest"/>
          </ul>
        </td>
      </tr>
      <tr>
        <td valign="top" class="property">
          <p>友達</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>名前</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>ニック・ネーム</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>性別</p>
    </td>
    <td valign="top" class="value">
      <p>
        <xsl:choose>
          <xsl:when test=".='male'">男</xsl:when>
          <xsl:when test=".='female'">女</xsl:when>
          <xsl:otherwise>不明</xsl:otherwise>
        </xsl:choose>
      </p>
    </td>
  </tr>
</xsl:template>

<xsl:template match="foaf:mbox">
  <tr>
    <td valign="top" class="property">
      <p>メール・アドレス</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="./@rdf:resource"/>
        </a>
        <!-- xsl:apply-templates select="../foaf:mbox_sha1sum"/ -->
      </p>
    </td>
  </tr>
</xsl:template>

<xsl:template match="foaf:homepage">
  <tr>
    <td valign="top" class="property">
      <p>ホーム・ページ</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>ウェブログ</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('../blog/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:msnChatID">
  <tr>
    <td valign="top" class="property">
      <p>MSN Messenger</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:template match="foaf:mbox_sha1sum">
  (<xsl:value-of select="."/>)
</xsl:template>

</xsl:stylesheet>
