<xsl:transform
    version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    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#"
    >

<!-- $Id: grokVioletUML.xsl,v 1.5 2005/09/30 19:41:19 connolly Exp $ -->

<xsl:output method="xml" indent="yes" />

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

<xsl:template
    match='void[@method="addNode"]/
  object[@class="com.horstmann.violet.ClassNode"]'>

  <xsl:variable name="n" select='normalize-space(void[@property="name"]/
				 void[@property="text"]/string)' />
  <xsl:variable name="id" select='@id' />
  <xsl:variable name="id1" select='translate($n, " ", "_")' />

  <s:Class rdf:ID="{$id}">
    <s:label><xsl:value-of select='$n' /></s:label>

    <xsl:for-each select='../../void[@method="connect"
		  and object[2]/@idref = $id
		  ]'>

      <xsl:variable name="ref" select='object[3]/@idref' />
      <xsl:variable name="refobj" select='../void/object[@id=$ref]' />

      <xsl:for-each select='object[1]
			    [@class="com.horstmann.violet.NoteEdge"]'>
	<s:comment>
	  <xsl:value-of select='$refobj/void[@property="text"]
				/void[@property="text"]/string' />
	</s:comment>
      </xsl:for-each>

      <xsl:for-each select='object[1]
	[@class="com.horstmann.violet.ClassRelationshipEdge"]'>

	  <xsl:variable name="label"
			select='void[@property="middleLabel"]/string' />
	  <xsl:variable name="startLabel"
			select='void[@property="startLabel"]/string' />
	  <xsl:variable name="endLabel"
			select='void[@property="endLabel"]/string' />

	  <xsl:if test="$label">
	    <s:subClassOf>
	      <owl:Restriction>
		<owl:onProperty rdf:resource="#{$label}" />
		<owl:allValuesFrom rdf:resource="#{$ref}" />
	      </owl:Restriction>
	    </s:subClassOf>

	    <xsl:if test='$startLabel = "1"'>
	      <s:subClassOf>
		<owl:Restriction>
		  <owl:onProperty rdf:resource="#{$label}" />
		  <owl:someValuesFrom rdf:resource="#{$ref}" />
		</owl:Restriction>
	      </s:subClassOf>
	    </xsl:if>

	    <xsl:if test='$endLabel = "1"'>
	      <s:subClassOf>
		<owl:Restriction>
		  <owl:onProperty rdf:resource="#{$label}" />
		  <owl:maxCardinality
		      rdf:datatype="http://www.w3.org/2001/XMLSchema#integer"
		      >1</owl:maxCardinality>
		</owl:Restriction>
	      </s:subClassOf>
	    </xsl:if>



	  </xsl:if>
      </xsl:for-each>

    </xsl:for-each>
  </s:Class>
</xsl:template>


<!-- don't pass text thru -->
<xsl:template match="text()"></xsl:template>

</xsl:transform>