<?xml version="1.0" ?>
<!--
	Extracts RDF data from JavaScript License Web Labels document.
	Copyright © 2018, 2022  Paulina Laura Emilia <vilene -at- posteo -dot- net>

	This program is free software: you can redistribute it and/or modify
	it under the terms of the GNU Affero General Public License as
	published by the Free Software Foundation, either version 3 of the
	License, or (at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU Affero General Public License for more details.

	You should have received a copy of the GNU Affero General Public License
	along with this program.  If not, see <https://www.gnu.org/licenses/>.
-->
<xsl:stylesheet version="1.0"
	xmlns:dcterms="http://purl.org/dc/terms/"
	xmlns:h="http://www.w3.org/1999/xhtml"
	xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
	exclude-result-prefixes="h"
>
	<xsl:output method="xml" version="1.0" encoding="utf-8" indent="yes" />

	<xsl:template match="/">
		<rdf:RDF>
			<xsl:apply-templates select="//h:table[@id = 'jslicense-labels1']//h:tr[
				count(h:td) = 3 and count(h:td[1]/h:a) = 1]" />
		</rdf:RDF>
	</xsl:template>

	<xsl:template match="h:table[@id = 'jslicense-labels1']//h:tr">
		<rdf:Description>
			<xsl:attribute name="rdf:about">
				<xsl:value-of select="h:td[1]/h:a/@href" />
			</xsl:attribute>

			<xsl:apply-templates select="h:td[2]/h:a" mode="license" />
			<xsl:apply-templates select="h:td[3]/h:a" mode="source" />
		</rdf:Description>
	</xsl:template>

	<xsl:template match="h:a" mode="license">
		<dcterms:license rdf:resource="{@href}" />
	</xsl:template>

	<xsl:template match="h:a" mode="source">
		<dcterms:source rdf:resource="{@href}" />
	</xsl:template>
</xsl:stylesheet>
