<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:h="http://www.w3.org/1999/xhtml"
  xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
  xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
  xmlns:wn="http://xmlns.com/wordnet/1.6/"
  exclude-result-prefixes="h">

 <xsl:comment>Author: Masahide Kanzaki; Original: 2002-09-19; Revised: 2002-09-23</xsl:comment>
 <xsl:output indent="yes"/>

 <xsl:template match="/">
  <rdf:RDF>
   <xsl:apply-templates select=".//h:table"/>
  </rdf:RDF>
 </xsl:template>

 <xsl:template match="h:table">
  <xsl:apply-templates select=".//h:tr[h:td]">
   <xsl:with-param name="class" select="@class"/>
   <xsl:with-param name="th" select=".//h:th"/>
  </xsl:apply-templates>
 </xsl:template>

 <xsl:template match="h:tr">
  <xsl:param name="class"/>
  <xsl:param name="th"/>
  <xsl:choose>
   <xsl:when test="$class">
    <xsl:element name="wn:{$class}">
     <xsl:for-each select=".//h:td">
      <xsl:call-template name="prop_elt">
       <xsl:with-param name="th" select="$th"/>
       <xsl:with-param name="pos" select="position()"/>
      </xsl:call-template>
     </xsl:for-each>
    </xsl:element>
   </xsl:when>
   <xsl:otherwise>
    <rdf:Description>
     <xsl:for-each select=".//h:td">
      <xsl:call-template name="prop_elt">
       <xsl:with-param name="th" select="$th"/>
       <xsl:with-param name="pos" select="position()"/>
      </xsl:call-template>
     </xsl:for-each>
    </rdf:Description>
   </xsl:otherwise>
  </xsl:choose>
 </xsl:template>

 <xsl:template name="prop_elt">
  <xsl:param name="th"/>
  <xsl:param name="pos"/>
  <xsl:variable name="v1"> ABCDEFGHIJKLMNOPQRSTUVWXYZ</xsl:variable>
  <xsl:variable name="v2">_abcdefghijklmnopqrstuvwxyz</xsl:variable>
  <xsl:element name="wn:{translate($th[$pos],$v1,$v2)}">
   <xsl:choose>
    <xsl:when test=".//h:a[@href]">
     <xsl:attribute name="rdf:resource">
      <xsl:value-of select=".//h:a/@href"/>
     </xsl:attribute>
     <xsl:attribute name="rdfs:label">
      <xsl:value-of select="."/>
     </xsl:attribute>
    </xsl:when>
    <xsl:otherwise>
     <xsl:value-of select="."/>
    </xsl:otherwise>
   </xsl:choose>
  </xsl:element>
 </xsl:template>

</xsl:stylesheet>
