<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
                xmlns="http://www.w3.org/1999/xhtml"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                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:foaf="http://xmlns.com/foaf/0.1/"
                exclude-result-prefixes="rdf rdfs dc foaf"
                >

    <xsl:template match="/">
        <xsl:apply-templates select="rdf:RDF/foaf:Person"/>
        <xsl:apply-templates select="rdfs:*"/>
    </xsl:template>

    <xsl:template match="/rdf:RDF/foaf:Person">
        <html>
            <head>
                <title>HTML rendering of <xsl:value-of select="foaf:name"/>'s foaf metadata</title>
                <link rel="stylesheet" href="foaf.css" type="text/css" />
            </head>
            <body>
                <p><a href="/"><img src="http://www.w3.org/RDF/icons/rdf_powered_button.48" alt="Friend of a Friend" border="0"/></a></p>
                <h1>FOAF Metadata from <xsl:value-of select="foaf:name"/></h1>
                <p>This is a visual presentation of <abbr title="Friend of a Friend">FOAF</abbr> metadata via XSLT. See source for its XML serialization.</p>
                <p>To make your own <a href="http://xmlns.com/foaf/0.1/">Foaf</a> file use the <a href="http://www.ldodds.com/foaf/foaf-a-matic.html">Foaf-a-matic</a></p>
                <table border="1" cellpadding="5" cellspacing="0">
                    <caption>FOAF Elements described here</caption>
                    <col class="term" />
                    <col class="desc" span="2" />
                    <thead>
                        <tr><th>Property</th><th colspan="2">Value</th></tr>
                    </thead>
                    <tbody>
                        <xsl:apply-templates select="foaf:*"/>
                    </tbody>
                </table>
                <p><img src="http://www.w3.org/RDF/icons/rdf_metadata_button.32" alt="RDF Metadata"/> Note: This metadata was transformed from XML via XSLT.</p>
                <hr />
            </body>
        </html>
    </xsl:template>

    <xsl:template match="foaf:*[@rdf:resource]">
        <xsl:message>first: <xsl:value-of select="local-name()"/></xsl:message>

        <tr>
            <td><xsl:value-of select="local-name()"/></td>
            <td colspan="2"><a href="{.}"><xsl:value-of select="."/></a></td>
        </tr>

        <xsl:apply-templates/>
    </xsl:template>

    <xsl:template match="foaf:*">
        <xsl:message>second: <xsl:value-of select="local-name()"/></xsl:message>

        <tr>
            <td><xsl:value-of select="local-name()"/></td>
            <td colspan="2"><xsl:value-of select="."/></td>
        </tr>

        <xsl:apply-templates/>
    </xsl:template>

    <xsl:template match="foaf:*[@dc:title]">
        <xsl:message>third: <xsl:value-of select="local-name()"/></xsl:message>

        <tr>
            <td><xsl:value-of select="local-name()"/></td>
            <xsl:choose>
                <xsl:when test="starts-with(@rdf:resource,'urn:isbn')">
                    <td><a><xsl:attribute name="href">http://www.amazon.com/exec/obidos/ASIN/<xsl:value-of select="translate(substring(@rdf:resource,10),'-','')"/></xsl:attribute><xsl:value-of select="./@rdf:resource"/></a></td>
                </xsl:when>
                <xsl:otherwise>
                    <td><a href="{./@rdf:resource}"><xsl:value-of select="./@rdf:resource"/></a></td>
                </xsl:otherwise>
            </xsl:choose>
            <td><xsl:value-of select="./@dc:title"/></td>
        </tr>

        <xsl:apply-templates/>
    </xsl:template>

	<!-- do nothing by default -->

	<xsl:template match="*">
		<!-- <xsl:message>default: <xsl:value-of select="local-name()"/></xsl:message> -->
	</xsl:template>
</xsl:stylesheet>
