<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
    xmlns:h="http://www.w3.org/1999/xhtml"
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns:vote="http://rdf.opiumfield.com/vote/"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
    xmlns:foaf="http://xmlns.com/foaf/0.1/"
    xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
    >
    <xsl:param name="base">
        <xsl:choose>
            <xsl:when test="//h:base[@href]">
                <xsl:value-of select="//h:base/@href"/>
            </xsl:when>
            <xsl:otherwise />
        </xsl:choose>
    </xsl:param>
    <xsl:output method="xml" indent="yes" />
    <xsl:template match="text()" />
    <xsl:template match="h:html">
        <rdf:RDF>
            <xsl:apply-templates select="//h:a[@href][@rev]" />
        </rdf:RDF>
    </xsl:template>
    <xsl:template match="h:a[contains(concat(' ', @rev, ' '), ' vote-for ')]">
        <vote:VoteLink>
            <rdfs:label><xsl:value-of select="normalize-space(text())" /></rdfs:label>
            <vote:voteResource rdf:resource="{@href}" />
            <vote:voted rdf:resource="http://rdf.opiumfield.com/vote/voteFor" />
            <vote:voteBy>
                <foaf:Agent>
                    <foaf:made rdf:resource="{$base}" />
                </foaf:Agent>
            </vote:voteBy>
        </vote:VoteLink>
    </xsl:template>
    <xsl:template match="h:a[contains(concat(' ', @rev, ' '), ' vote-against ')]">
        <vote:VoteLink>
            <rdfs:label><xsl:value-of select="normalize-space(text())" /></rdfs:label>
            <vote:voteResource rdf:resource="{@href}" />
            <vote:voted rdf:resource="http://rdf.opiumfield.com/vote/voteAgainst" />
            <vote:voteBy>
                <foaf:Agent>
                    <foaf:made rdf:resource="{$base}" />
                </foaf:Agent>
            </vote:voteBy>
        </vote:VoteLink>
    </xsl:template>
    <xsl:template match="h:a[contains(concat(' ', @rev, ' '), ' vote-abstain ')]">
        <vote:VoteLink>
            <rdfs:label><xsl:value-of select="normalize-space(text())" /></rdfs:label>
            <vote:voteResource rdf:resource="{@href}" />
            <vote:voted rdf:resource="http://rdf.opiumfield.com/vote/voteAbstain" />
            <vote:voteBy>
                <foaf:Agent>
                    <foaf:made rdf:resource="{$base}" />
                </foaf:Agent>
            </vote:voteBy>
        </vote:VoteLink>
    </xsl:template>
</xsl:stylesheet>
