<xsl:transform
  version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:l="http://www.w3.org/2007/01/lbl22/label"
  xmlns:lt="http://www.w3.org/2007/01/lbl22/label#"
  xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
  xmlns:s="http://www.w3.org/2000/01/rdf-schema#"
  xmlns:owl="http://www.w3.org/2002/07/owl#"

  >

<xsl:output method="xml" indent="yes" />
<!-- $Id: label2rdf.xsl,v 1.3 2007/01/22 21:21:28 connolly Exp $ -->

<xsl:template match="/">
  <rdf:RDF>
    <xsl:apply-templates />
  </rdf:RDF>
</xsl:template>

<xsl:template match="l:label">
  <rdf:Description>
    <xsl:apply-templates select="l:scope" />
      <s:subClassOf>
	<xsl:apply-templates select="l:audience" />
      </s:subClassOf>
  </rdf:Description>
</xsl:template>

<xsl:template match="l:scope">
  <xsl:choose>
    <xsl:when test="l:except">

      <!-- A except B is intersection(A, complementOf(B)) -->
      <owl:intersectionOf rdf:parseType="Collection">
	<rdf:Description>
	  <xsl:apply-templates select="*" />
	</rdf:Description>
	<rdf:Description>
	  <owl:complementOf rdf:parseType="Resource">
	    <xsl:apply-templates select="l:except/*" />
	  </owl:complementOf>
	</rdf:Description>
      </owl:intersectionOf>
    </xsl:when>

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

<xsl:template match="l:domain">
  <owl:onProperty
      rdf:resource="http://www.w3.org/2007/01/lbl22/label#inDomain"/>
  <owl:hasValue><xsl:value-of select="." /></owl:hasValue>
</xsl:template>

<xsl:template match="l:domainPath">
  <owl:onProperty
      rdf:resource="http://www.w3.org/2007/01/lbl22/label#inPath"/>
  <owl:hasValue><xsl:value-of select="." /></owl:hasValue>
</xsl:template>

<xsl:template match="l:audience">
  <xsl:variable name="t" select='*[1]'/>
  <xsl:variable name="ns" select='namespace-uri($t)'/>
  <xsl:variable name="n" select='concat($ns, local-name($t))'/>

  <rdf:Description>
    <lt:suitableForAll rdf:resource="{$n}" />
  </rdf:Description>
</xsl:template>


<xsl:template match="*">
  <xsl:message>
    oops! no template for <xsl:value-of select="name()"/> element in <xsl:value-of select="name(..)"/>
  </xsl:message>
</xsl:template>

</xsl:transform>
