<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:wdr="http://www.w3.org/2007/05/powder#" xmlns:wdrs="http://www.w3.org/2007/05/powder-s#" xmlns:owl="http://www.w3.org/2002/07/owl#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" exclude-result-prefixes="wdr">
	<xsl:output method="xml" indent="yes" encoding="UTF-8"/>

	<xsl:template match="/wdr:powder">
		<rdf:RDF>
			<xsl:apply-templates select="wdr:attribution"/>
			<xsl:apply-templates select="wdr:more"/>
			<xsl:apply-templates select="wdr:descriptorset" mode="predefined"/>
			<xsl:apply-templates select="wdr:ol/wdr:dr | wdr:dr"/>
		</rdf:RDF>
	</xsl:template>
	<!--

#################
#
# Attribution handling
#
#################-->

	<xsl:template match="wdr:attribution">
		<owl:Ontology rdf:about="">
			<wdrs:issuedby rdf:resource="{wdr:issuedby/@src}"/>
			<xsl:apply-templates select="wdr:issued"/>
			<xsl:apply-templates select="wdr:validfrom"/>
			<xsl:apply-templates select="wdr:validuntil"/>
			<xsl:apply-templates select="wdr:displaytext"/>
			<xsl:apply-templates select="wdr:displayicon"/>
			<xsl:apply-templates select="wdr:certifiedby"/>
			<xsl:apply-templates select="wdr:supportedby"/>
			<xsl:apply-templates select="wdr:seealso"/>
		</owl:Ontology>
		<xsl:apply-templates select="wdr:aboutregex"/>
	</xsl:template>

	<xsl:template match="wdr:more">
		<owl:Ontology rdf:about="">
			<rdfs:seeAlso rdf:resource="{@src}"/>
		</owl:Ontology>
	</xsl:template>

	<xsl:template match="wdr:issued">
		<wdrs:issued>
			<xsl:value-of select="."/>
		</wdrs:issued>
	</xsl:template>

	<xsl:template match="wdr:validfrom">
		<wdrs:validFrom>
			<xsl:value-of select="."/>
		</wdrs:validFrom>
	</xsl:template>

	<xsl:template match="wdr:validuntil">
		<wdrs:validUntil>
			<xsl:value-of select="."/>
		</wdrs:validUntil>
	</xsl:template>

	<xsl:template match="wdr:displaytext">
		<wdrs:text>
			<xsl:apply-templates select="@xml:lang"/>
			<xsl:value-of select="."/>
		</wdrs:text>
	</xsl:template>
	
	<xsl:template match="wdr:displayicon">
		<wdrs:logo rdf:resource="{@src}">
		</wdrs:logo>
	</xsl:template>

	<xsl:template match="wdr:aboutregex">
		<owl:Class rdf:nodeID="aboutset">
			<owl:equivalentClass>
				<owl:Class>
					<owl:intersectionOf rdf:parseType="Collection">
						<owl:Restriction>
							<owl:onProperty rdf:resource="http://www.w3.org/2007/05/powder-s#matchesregex"/>
<!--							<owl:hasValue rdf:datatype="http://www.w3.org/2001/XMLSchema#string">\:\/\/(([^\/\?\#]*)\@)?([^\:\/\?\#\@]+\.)?(<xsl:value-of select="."/>)(\:([0-9]+))?\/</owl:hasValue>-->
							<owl:hasValue rdf:datatype="http://www.w3.org/2001/XMLSchema#string"><xsl:value-of select="."/></owl:hasValue>
						</owl:Restriction>
					</owl:intersectionOf>
				</owl:Class>
			</owl:equivalentClass>
		</owl:Class>
	</xsl:template>

	<xsl:template match="wdr:certifiedby">
		<wdrs:certfiedby rdf:resource="{@src}"/>
	</xsl:template>

	<xsl:template match="wdr:supportedby">
		<wdrs:supportedby rdf:resource="{@src}"/>
	</xsl:template>

	<xsl:template match="wdr:label">
		<rdfs:label>
			<xsl:apply-templates select="@xml:lang"/>
			<xsl:value-of select="."/>
		</rdfs:label>
	</xsl:template>

	<xsl:template match="wdr:comment">
		<rdfs:comment>
			<xsl:apply-templates select="@xml:lang"/>
			<xsl:value-of select="."/>
		</rdfs:comment>
	</xsl:template>

	<xsl:template match="wdr:seealso">
		<rdfs:seeAlso rdf:resource="{@src}">
		</rdfs:seeAlso>
	</xsl:template>

	<xsl:template match="@xml:lang">
		<xsl:copy-of select="."/>
	</xsl:template>
	
<!--#########
#
# Predefined descriptorsets reference in the DR
#
##############
-->
	<xsl:template match="wdr:descriptorset" mode="predefined">
		<xsl:choose>
			<xsl:when test="@node | @xml:id">
				<xsl:variable name="id" select="@node | @xml:id"/>
				<xsl:variable name="attr-name">
					<xsl:choose>
						<xsl:when test="@node">rdf:nodeID</xsl:when>
						<xsl:when test="@xml:id">rdf:ID</xsl:when>
					</xsl:choose>
				</xsl:variable>
				<owl:Class>
					<xsl:attribute name="{$attr-name}"><xsl:value-of select="$id"/></xsl:attribute>
					<xsl:comment>xsl:template match=wdr:descriptorset mode=predefined</xsl:comment>
					<xsl:choose>
						<xsl:when test="/wdr:powder/wdr:attribution/wdr:aboutregex">
							<!-- make a subclass of aboutset if there is one -->
							<rdfs:subClassOf rdf:nodeID="aboutset"/>
						</xsl:when>
						<xsl:otherwise>
							<!-- otherwise we have an owl:Thing -->
							<rdfs:subClassOf rdf:resource="http://www.w3.org/2002/07/owl#Thing"/>
						</xsl:otherwise>
					</xsl:choose>
					<rdfs:subClassOf>
						<owl:Class>
							<owl:intersectionOf rdf:parseType="Collection">
								<xsl:apply-templates select="*[not(namespace-uri()='http://www.w3.org/2007/05/powder#') and not(@rdf:resource)]"/>
								<xsl:apply-templates select="*[not(namespace-uri()='http://www.w3.org/2007/05/powder#') and (@rdf:resource)]"/>
								<xsl:apply-templates select="wdr:sha1sum | wdr:certified | wdr:typeof"/>
							</owl:intersectionOf>
						</owl:Class>
					</rdfs:subClassOf>
					<xsl:apply-templates select="wdr:displaytext"/>
					<xsl:apply-templates select="wdr:displayicon"/>
					<xsl:apply-templates select="wdr:seealso"/>
					<xsl:apply-templates select="wdr:label"/>
					<xsl:apply-templates select="wdr:comment"/>
				</owl:Class>
			</xsl:when>
			<xsl:when test="@include">
				<owl:Class>
					<owl:equivalentClass rdf:nodeID="{@include}"/>
				</owl:Class>
			</xsl:when>
			<xsl:when test="@src">
				<owl:Class>
					<owl:equivalentClass rdf:resource="{@src}"/>
				</owl:Class>
			</xsl:when>
		</xsl:choose>
	</xsl:template>
<!-- #####################

  Basic handling of DRs 

######################## 
-->
	<xsl:template match="wdr:dr[not(parent::wdr:ol)]">
		<xsl:apply-templates select="wdr:iriset[not(ancestor::wdr:ol)]"/>
		<xsl:apply-templates select="wdr:descriptorset[not(ancestor::wdr:ol)]"/>
		<xsl:apply-templates select="wdr:tagset[not(ancestor::wdr:ol)]"/>
		<xsl:apply-templates select="wdr:iriset" mode="build-rdf-description"/>
	</xsl:template>
	
	<xsl:template match="wdr:dr[parent::wdr:ol]">
		<xsl:apply-templates select="wdr:iriset[ancestor::wdr:ol]"/>
		<xsl:apply-templates select="wdr:descriptorset[ancestor::wdr:ol]"/>
		<xsl:apply-templates select="wdr:tagset[ancestor::wdr:ol]"/>
		<xsl:apply-templates select="wdr:iriset" mode="build-rdf-description-ol"/>
	</xsl:template>

	<!--
###############
#
# IRISet handling
#
#################-->

	<!-- for DRs which are not part of an ordered list...-->
	<xsl:template match="wdr:iriset[not(ancestor::wdr:ol)]">
		<!-- the iriset ID increments from any previous iriset that the same or another dr, as long as that dr is not part of an ol (those are numbered differently to help create and reference exclusions)-->
		<xsl:variable name="id" select="count(ancestor::wdr:dr/preceding-sibling::wdr:dr/wdr:iriset | preceding-sibling::wdr:iriset) + 1"/>
		<owl:Class rdf:nodeID="iriset_{$id}">
			<xsl:comment>xsl:template match=wdr:iriset[not(ancestor::wdr:ol)]</xsl:comment>
			<xsl:choose>	<!-- implements rule that an empty IRI set is the empty set -->
				<xsl:when test="not(node())">
				<owl:equivalentClass rdf:resource="http://www.w3.org/2002/07/owl#Nothing" /> 
				</xsl:when>
				<xsl:when test="not(normalize-space(.))">
				<owl:equivalentClass rdf:resource="http://www.w3.org/2002/07/owl#Nothing" /> 
				</xsl:when>
				<xsl:otherwise>
			<owl:equivalentClass>
				<owl:Class>
					<owl:intersectionOf rdf:parseType="Collection">
						<xsl:apply-templates select="*"/>
					</owl:intersectionOf>
				</owl:Class>
			</owl:equivalentClass>
				</xsl:otherwise>
			</xsl:choose>
		</owl:Class>
	</xsl:template>

	<!-- and here for DRs that are part of an ordered list (and hence require an 'exclusion' class)-->
	<xsl:template match="wdr:iriset[ancestor::wdr:ol]">
		<xsl:variable name="ol" select="count(ancestor::wdr:ol/preceding-sibling::wdr:ol) + 1"/>
		<xsl:variable name="id" select="count(ancestor::wdr:dr/preceding-sibling::wdr:dr/wdr:iriset | preceding-sibling::wdr:iriset) + 1"/>
		<owl:Class rdf:nodeID="iriset_ol{$ol}_{$id}">
			<xsl:comment>xsl:template match=wdr:iriset[ancestor::wdr:ol]</xsl:comment>
			<xsl:choose>	<!-- implements rule that an empty IRI set is the empty set -->
				<xsl:when test="not(node())">
					<owl:equivalentClass rdf:resource="http://www.w3.org/2002/07/owl#Nothing" />
				</xsl:when>
				<xsl:when test="not(normalize-space(.))">
				<owl:equivalentClass rdf:resource="http://www.w3.org/2002/07/owl#Nothing" /> 
				</xsl:when>
			<xsl:otherwise>
			<owl:equivalentClass>
				<owl:Class>
					<owl:intersectionOf rdf:parseType="Collection">
						<xsl:apply-templates select="wdr:includeregex"/>
						<xsl:apply-templates select="wdr:excluderegex"/>
						<xsl:if test="$id &gt; 1">
							<!-- Refer to the exclusion for every other iriset in the ordered list-->
							<xsl:for-each select="ancestor::wdr:dr/preceding-sibling::wdr:dr/wdr:iriset | preceding-sibling::wdr:iriset">
								<xsl:variable name="iriset_not_id">
									<xsl:number value="position()"/>
								</xsl:variable>
								<!-- these must be unique within the document so include the document ordinality of the ordered list as part of the value-->
								<owl:Class rdf:nodeID="iriset_ol{$ol}_{$iriset_not_id}_not"/>
							</xsl:for-each>
						</xsl:if>
					</owl:intersectionOf>
				</owl:Class>
			</owl:equivalentClass></xsl:otherwise></xsl:choose>
		</owl:Class>
		<!-- Create an exclusion that will be referenced every other iriset in the ordered list. These must be unique within the document so include the document ordinality of the ordered list as part of the value-->
		<owl:Class rdf:nodeID="iriset_ol{$ol}_{$id}_not">
			<owl:equivalentClass>
				<owl:Class>
					<owl:unionOf rdf:parseType="Collection">
						<xsl:apply-templates select="wdr:includeregex" mode="not"/>
						<xsl:apply-templates select="wdr:excluderegex" mode="not"/>
					</owl:unionOf>
				</owl:Class>
			</owl:equivalentClass>
		</owl:Class>
	</xsl:template>

	<xsl:template match="wdr:includeregex">
		<owl:Restriction>
			<owl:onProperty rdf:resource="http://www.w3.org/2007/05/powder-s#matchesregex"/>
			<owl:hasValue rdf:datatype="http://www.w3.org/2001/XMLSchema#string">
				<xsl:value-of select="."/>
			</owl:hasValue>
		</owl:Restriction>
	</xsl:template>

	<xsl:template match="wdr:includeregex" mode="not">
		<owl:Restriction>
			<owl:onProperty rdf:resource="http://www.w3.org/2007/05/powder-s#notmatchesregex"/>
			<owl:hasValue rdf:datatype="http://www.w3.org/2001/XMLSchema#string">
				<xsl:value-of select="."/>
			</owl:hasValue>
		</owl:Restriction>
	</xsl:template>

	<xsl:template match="wdr:excluderegex">
		<owl:Restriction>
			<owl:onProperty rdf:resource="http://www.w3.org/2007/05/powder-s#notmatchesregex"/>
			<owl:hasValue rdf:datatype="http://www.w3.org/2001/XMLSchema#string">
				<xsl:value-of select="."/>
			</owl:hasValue>
		</owl:Restriction>
	</xsl:template>

	<xsl:template match="wdr:excluderegex" mode="not">
		<owl:Restriction>
			<owl:onProperty rdf:resource="http://www.w3.org/2007/05/powder-s#matchesregex"/>
			<owl:hasValue rdf:datatype="http://www.w3.org/2001/XMLSchema#string">
				<xsl:value-of select="."/>
			</owl:hasValue>
		</owl:Restriction>
	</xsl:template>
	<!--

 Finally create the subclass relationship between the iriset and the descriptorset(s) that describe it. This is handled differently for dr's in an ordered list and those without.

-->	
		<xsl:template match="wdr:iriset" mode="build-rdf-description">
		<xsl:variable name="iriset-id" select="count(preceding-sibling::wdr:iriset | ancestor::wdr:dr/preceding-sibling::wdr:dr/wdr:iriset) + 1"/>
		<owl:Class rdf:nodeID="iriset_{$iriset-id}">
			<xsl:comment>xsl:template match=wdr:iriset mode=build-rdf-description</xsl:comment>
			<xsl:for-each select="../wdr:descriptorset">
				<xsl:variable name="ds-id">
					<xsl:value-of select="count(ancestor::wdr:dr/preceding-sibling::wdr:dr/wdr:descriptorset) + position()"/>
				</xsl:variable>
				<!-- these must be unique and increment from the any other dr/descriptorsets which do not have parent ol's -->
				<rdfs:subClassOf rdf:nodeID="descriptorset_{$ds-id}"/>
				</xsl:for-each>
			<xsl:for-each select="../wdr:tagset">
				<xsl:variable name="ts-id">
					<xsl:value-of select="count(ancestor::wdr:dr/preceding-sibling::wdr:dr/wdr:tagset) + position()"/>
				</xsl:variable>
				<!-- these must be unique and increment from the any other dr/tagsets which do not have parent ol's -->
				<rdfs:subClassOf rdf:nodeID="tagset_{$ts-id}"/>
			</xsl:for-each>
		</owl:Class>
	</xsl:template>

	<xsl:template match="wdr:iriset" mode="build-rdf-description-ol">
		<xsl:variable name="iriset-id" select="count(preceding-sibling::wdr:iriset | ancestor::wdr:dr/preceding-sibling::wdr:dr/wdr:iriset) + 1"/>
		<xsl:variable name="ol" select="count(ancestor::wdr:ol/preceding-sibling::wdr:ol) + 1"/>
		<owl:Class rdf:nodeID="iriset_ol{$ol}_{$iriset-id}">
			<xsl:comment>xsl:template match=wdr:iriset mode=build-rdf-description-ol</xsl:comment>
			<xsl:for-each select="../wdr:descriptorset">
				<!-- the ds-id increments from all the previous descriptorsets in the same <ol> in the same or previous <dr>s-->
				<xsl:variable name="ds-id">
					<xsl:value-of select="count(ancestor::wdr:dr/preceding-sibling::wdr:dr/wdr:descriptorset) + position()"/>
				</xsl:variable>
				<rdfs:subClassOf rdf:nodeID="descriptorset_ol{$ol}_{$ds-id}"/>
			</xsl:for-each>
			<xsl:for-each select="../wdr:tagset">
				<!-- the ts-id increments from all the previous tagsets in the same <ol> in the same or previous <dr>s-->
				<xsl:variable name="ts-id">
					<xsl:value-of select="count(ancestor::wdr:dr/preceding-sibling::wdr:dr/wdr:tagset) + position()"/>
				</xsl:variable>
				<rdfs:subClassOf rdf:nodeID="tagset_ol{$ol}_{$ts-id}"/>
			</xsl:for-each>
		</owl:Class>
	</xsl:template>

	<!--
###############
#
# Descriptorset handling
#
#################-->

	<!-- For descriptorsets that are part of an ordered list-->
	<xsl:template match="wdr:descriptorset[ancestor::wdr:ol]">
		<xsl:variable name="id" select="count(preceding-sibling::wdr:descriptorset | ancestor::wdr:dr/preceding-sibling::wdr:dr/wdr:descriptorset) + 1"/>
		<xsl:variable name="ol" select="count(ancestor::wdr:ol/preceding-sibling::wdr:ol) + 1"/>
		<owl:Class rdf:nodeID="descriptorset_ol{$ol}_{$id}">
			<xsl:comment>xsl:template match=wdr:descriptorset[ancestor::wdr:ol]</xsl:comment>
			<xsl:choose>
				<xsl:when test="@include">
					<!-- just refer to the included class. Not much else to do -->
					<owl:equivalentClass rdf:nodeID="{@include}"/>
				</xsl:when>
				<xsl:when test="@src">
					<!-- just refer to the included class. Not much else to do -->
					<owl:equivalentClass rdf:resource="{@src}"/>
				</xsl:when>
			</xsl:choose>
			<xsl:choose>
				<xsl:when test="/wdr:powder/wdr:attribution/wdr:aboutregex">
					<!-- make a subclass of aboutset if there is one -->
					<rdfs:subClassOf rdf:nodeID="aboutset"/>
				</xsl:when>
				<xsl:otherwise>
					<!-- otherwise we have an owl:Thing -->
					<rdfs:subClassOf rdf:resource="http://www.w3.org/2002/07/owl#Thing"/>
				</xsl:otherwise>
			</xsl:choose>
			<xsl:choose>
				<xsl:when test="not(@include | @src)">
					<!-- unless we had an include, build this descriptorset -->
					<rdfs:subClassOf>
						<owl:Class>
							<owl:intersectionOf rdf:parseType="Collection">
								<xsl:apply-templates select="*[not(namespace-uri()='http://www.w3.org/2007/05/powder#') and not(@rdf:resource)]"/>
								<xsl:apply-templates select="*[not(namespace-uri()='http://www.w3.org/2007/05/powder#') and (@rdf:resource)]"/>
								<xsl:apply-templates select="wdr:sha1sum | wdr:certified | wdr:typeof"/>
							</owl:intersectionOf>
						</owl:Class>
					</rdfs:subClassOf>
					<xsl:apply-templates select="wdr:displaytext"/>
					<xsl:apply-templates select="wdr:displayicon"/>
					<xsl:apply-templates select="wdr:seealso"/>
					<xsl:apply-templates select="wdr:label"/>
					<xsl:apply-templates select="wdr:comment"/>
				</xsl:when>
			</xsl:choose>
		</owl:Class>
	</xsl:template>

	<!-- For descriptorsets that are not part of an ordered list-->
	<xsl:template match="wdr:descriptorset[not(ancestor::wdr:ol)]">
		<xsl:variable name="id" select="count(preceding-sibling::wdr:descriptorset | ancestor::wdr:dr/preceding-sibling::wdr:dr/wdr:descriptorset) + 1"/>
		<owl:Class rdf:nodeID="descriptorset_{$id}">
			<xsl:comment>xsl:template match=wdr:descriptorset[not(ancestor::wdr:ol)]</xsl:comment>
			<xsl:choose>
				<xsl:when test="@include">
					<!-- just refer to the included class. Not much else to do -->
					<owl:equivalentClass rdf:nodeID="{@include}"/>
				</xsl:when>
				<xsl:when test="@src">
					<!-- just refer to the included class. Not much else to do -->
					<owl:equivalentClass rdf:resource="{@src}"/>
				</xsl:when>
			</xsl:choose>
			<xsl:choose>
				<xsl:when test="/wdr:powder/wdr:attribution/wdr:aboutregex">
					<rdfs:subClassOf rdf:nodeID="aboutset"/>
				</xsl:when>
				<xsl:otherwise>
					<rdfs:subClassOf rdf:resource="http://www.w3.org/2002/07/owl#Thing"/>
				</xsl:otherwise>
			</xsl:choose>
			<xsl:choose>
				<xsl:when test="not(@include | @src)">
					<rdfs:subClassOf>
						<owl:Class>
							<owl:intersectionOf rdf:parseType="Collection">
								<xsl:apply-templates select="*[not(namespace-uri()='http://www.w3.org/2007/05/powder#') and not(@rdf:resource)]"/>
								<xsl:apply-templates select="*[not(namespace-uri()='http://www.w3.org/2007/05/powder#') and (@rdf:resource)]"/>
								<xsl:apply-templates select="wdr:sha1sum | wdr:certified | wdr:typeof"/>
							</owl:intersectionOf>
						</owl:Class>
					</rdfs:subClassOf>
				</xsl:when>
			</xsl:choose>
			<xsl:apply-templates select="wdr:displaytext"/>
			<xsl:apply-templates select="wdr:displayicon"/>
			<xsl:apply-templates select="wdr:seealso"/>
			<xsl:apply-templates select="wdr:label"/>
			<xsl:apply-templates select="wdr:comment"/>
		</owl:Class>
	</xsl:template>

	<xsl:template match="wdr:sha1sum">
		<owl:Restriction>
			<owl:onProperty rdf:resource="http://www.w3.org/2007/05/powder-s#sha1sum"/>
			<owl:hasValue>
				<xsl:value-of select="."/>
			</owl:hasValue>
		</owl:Restriction>
	</xsl:template>

	<xsl:template match="wdr:certified">
		<owl:Restriction>
			<owl:onProperty rdf:resource="http://www.w3.org/2007/05/powder-s#certified"/>
			<owl:hasValue>
				<xsl:value-of select="."/>
			</owl:hasValue>
		</owl:Restriction>
	</xsl:template>

	<xsl:template match="wdr:typeof">
		<owl:Class rdf:about="{@src}"/>
	</xsl:template>

	<!-- displaytext and displayicon use the same template matches as the attribution block earlier-->
	<!--
#######################
#
# Tagset handling
#
########################-->

	<xsl:template match="wdr:tagset[not(ancestor::wdr:ol)]">
		<xsl:variable name="tagset-id" select="count(ancestor::wdr:dr/preceding-sibling::wdr:dr/wdr:tagset) + 1"/>
		<owl:Class rdf:nodeID="tagset_{$tagset-id}">
			<xsl:apply-templates select="wdr:label"/>
			<xsl:apply-templates select="wdr:comment"/>
			<xsl:apply-templates select="wdr:seealso"/>
			<rdfs:subClassOf>
				<owl:Class>
					<owl:intersectionOf rdf:parseType="Collection">
						<xsl:apply-templates select="wdr:tag"/>
					</owl:intersectionOf>
				</owl:Class>
			</rdfs:subClassOf>
		</owl:Class>
	</xsl:template>

	<xsl:template match="wdr:tagset[ancestor::wdr:ol]">
		<xsl:variable name="ol" select="count(ancestor::wdr:ol/preceding-sibling::wdr:ol) + 1"/>
		<xsl:variable name="tagset-id" select="count(ancestor::wdr:dr/preceding-sibling::wdr:dr/wdr:tagset) + 1"/>
		<owl:Class rdf:nodeID="tagset_ol{$ol}_{$tagset-id}">
			<xsl:apply-templates select="wdr:label"/>
			<xsl:apply-templates select="wdr:comment"/>
			<xsl:apply-templates select="wdr:seealso"/>
			<rdfs:subClassOf>
				<owl:Class>
					<owl:intersectionOf rdf:parseType="Collection">
						<xsl:apply-templates select="wdr:tag"/>
					</owl:intersectionOf>
				</owl:Class>
			</rdfs:subClassOf>
		</owl:Class>
	</xsl:template>

	<xsl:template match="wdr:tag">
		<owl:Restriction>
			<owl:onProperty rdf:resource="http://www.w3.org/2007/05/powder-s#tag"/>
		<xsl:choose>
			<xsl:when test="@xml:lang">
				<owl:hasValue xml:lang="{@xml:lang}">
					<xsl:value-of select="."/>
				</owl:hasValue>
			</xsl:when>
			<xsl:otherwise>
				<owl:hasValue>
					<xsl:value-of select="."/>
				</owl:hasValue>
			</xsl:otherwise>
		</xsl:choose>
		</owl:Restriction>
	</xsl:template>


	<!--################
#
# Handler for elements outside POWDER namespace
#
###################   -->

	<xsl:template match="*[not(namespace-uri()='http://www.w3.org/2007/05/powder#') and not(@rdf:resource)]">
		<owl:Restriction>
			<owl:onProperty rdf:resource="{namespace-uri()}{local-name()}"/>
			<owl:hasValue>
				<xsl:value-of select="text()"/>
			</owl:hasValue>
		</owl:Restriction>
	</xsl:template>

	<xsl:template match="*[not(namespace-uri()='http://www.w3.org/2007/05/powder#') and (@rdf:resource)]">
		<owl:Restriction>
			<owl:onProperty rdf:resource="{namespace-uri()}{local-name()}"/>
			<owl:hasValue rdf:resource="{@rdf:resource}"/>
		</owl:Restriction>
	</xsl:template>
</xsl:stylesheet>
