<?xml version="1.0" encoding="UTF-8" ?>
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
 |                                                                           |
 | o:XML is published under the GNU General Public Licence                   |
 |   (see http://www.gnu.org/licenses/licenses.html#GPL).                    |
 |                                                                           |
 | A copy of the licence agreement (gpl.txt) must be part of any             |
 |   redistribution of any form.                                             |
 |                                                                           |
 | o:XML was created by Martin Klang <mars@pingdynasty.com>.                 |
 |                                                                           |
 | For more information please see:                                          |
 |   http://www.o-xml.org/                                                   |
 |                                                                           |
 +- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
<xsl:stylesheet version="1.0" xmlns:o="http://www.o-xml.org/lang/"
		xmlns:UML="org.omg.xmi.namespace.UML"
		xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="xml" indent="yes"/>

  <xsl:template match="/">
    <XMI xmi.version="1.2"
	 xmlns:UML="org.omg.xmi.namespace.UML">
      <XMI.header>
	<XMI.documentation>
	  <XMI.exporter>o:XML XMI Generator</XMI.exporter>
	  <XMI.exporterVersion>0.1</XMI.exporterVersion>
	</XMI.documentation>
      </XMI.header>
      <XMI.content>
	<UML:Model xmi.id="model-0" name="model 1" isSpecification="false"
		   isRoot="false" isLeaf="false" isAbstract="false">
	  <UML:Namespace.ownedElement>
	    <xsl:apply-templates/>
	  </UML:Namespace.ownedElement>
	</UML:Model>
      </XMI.content>
    </XMI>
  </xsl:template>
  
  <xsl:template match="o:module">
    <UML:Package name="{@name}"
		 isSpecification="false" isRoot="false"
		 isLeaf="false" isAbstract = 'false'>
      <xsl:apply-templates select="." mode="xmi.id"/>
          <UML:Namespace.ownedElement>
	    <xsl:apply-templates/>
      </UML:Namespace.ownedElement>
    </UML:Package>
  </xsl:template>

  <xsl:template match="o:type">
    <UML:Class name="{@name}"
	       isSpecification = 'false' isRoot = 'false' 
	       isLeaf = 'false' isAbstract = 'false'
	       isActive = 'false'>
      <xsl:apply-templates select="." mode="xmi.id"/>
      <xsl:apply-templates select="@access"/>
      <xsl:if test="o:parent">
	<UML:GeneralizableElement.generalization>
	  <xsl:apply-templates select="o:parent" mode="reference"/>
	</UML:GeneralizableElement.generalization>
      </xsl:if>
      <xsl:if test="o:variable">
	<UML:Classifier.feature>
	  <xsl:apply-templates select="o:variable"/>
	</UML:Classifier.feature>
      </xsl:if>
      <xsl:if test="o:function">
	<UML:Classifier.feature>
	  <xsl:apply-templates select="o:function"/>
	</UML:Classifier.feature>
      </xsl:if>
    </UML:Class>
    <xsl:apply-templates select="o:parent" mode="declare"/>
  </xsl:template>

  <xsl:template match="o:variable">
    <UML:Attribute name="{@name}"
		   isSpecification="false" ownerScope="instance"
		   changeability="changeable">
      <xsl:apply-templates select="." mode="xmi.id"/>
      <xsl:apply-templates select="@access"/>
      <xsl:apply-templates select="@type"/>
    </UML:Attribute>
  </xsl:template>

  <xsl:template match="o:variable/@type">
    <UML:StructuralFeature.type>
      <UML:Class>
	<xsl:apply-templates select="//o:type[@name = current()/@type]" mode="xmi.idref"/>
      </UML:Class>
    </UML:StructuralFeature.type>
  </xsl:template>

  <xsl:template match="o:function">
    <UML:Operation name="{@name}"
		   isSpecification = 'false' ownerScope = 'instance'
		   isQuery = 'false' concurrency = 'sequential' 
		   isRoot = 'false' isLeaf = 'false'
		   isAbstract = 'false'>
      <xsl:apply-templates select="." mode="xmi.id"/>
      <xsl:apply-templates select="@access"/>
      <UML:BehavioralFeature.parameter>
	<xsl:apply-templates select="@type"/>
	<xsl:apply-templates select="o:param"/>
      </UML:BehavioralFeature.parameter>
    </UML:Operation>
  </xsl:template>

  <xsl:template match="o:function/@type">
    <UML:Parameter xmi.id="return-{count(preceding::o:function)}" name="return"
		   isSpecification="false" kind="return">
      <UML:Parameter.type>
	<UML:Class>
	  <xsl:apply-templates select="//o:type[@name = current()]" mode="xmi.idref"/>
	</UML:Class>
      </UML:Parameter.type>
    </UML:Parameter>
  </xsl:template>

  <xsl:template match="o:param">
    <UML:Parameter name="{@name}"
		   isSpecification="false" kind="in">
      <xsl:apply-templates select="." mode="xmi.id"/>
      <UML:Parameter.type>
	<UML:Class>
	  <xsl:apply-templates select="//o:type[@name = current()/@type]" mode="xmi.idref"/>
	</UML:Class>
      </UML:Parameter.type>
    </UML:Parameter>
  </xsl:template>

  <xsl:template match="o:parent" mode="reference">
    <UML:Generalization>
      <xsl:apply-templates select="." mode="xmi.idref"/>
    </UML:Generalization>
  </xsl:template>

  <xsl:template match="o:parent" mode="declare">
    <UML:Generalization isSpecification="false">
      <xsl:apply-templates select="." mode="xmi.id"/>
      <UML:Generalization.child>
	<UML:Class>
	  <xsl:apply-templates select="parent::o:type" mode="xmi.idref"/>
	</UML:Class>
      </UML:Generalization.child>
      <UML:Generalization.parent>
	<UML:Class>
	  <xsl:apply-templates select="//o:type[@name = current()/@name]" mode="xmi.idref"/>
	</UML:Class>
      </UML:Generalization.parent>
    </UML:Generalization>
  </xsl:template>

  <xsl:template match="@access">
    <xsl:attribute name="visibility"><xsl:value-of select="."/></xsl:attribute>
  </xsl:template>

  <xsl:template match="o:*" mode="xmi.id">
    <xsl:attribute name="xmi.id">
      <xsl:apply-templates select="." mode="generate-xmi-id"/>
    </xsl:attribute>
  </xsl:template>

  <xsl:template match="o:*[@xmi.id]" mode="xmi.id">
    <xsl:attribute name="xmi.id"><xsl:value-of select="@xmi.id"/></xsl:attribute>
  </xsl:template>

  <xsl:template match="o:*" mode="xmi.idref">
    <xsl:attribute name="xmi.idref">
      <xsl:apply-templates select="." mode="generate-xmi-id"/>
    </xsl:attribute>
  </xsl:template>

  <xsl:template match="o:*[@xmi.id]" mode="xmi.idref">
    <xsl:attribute name="xmi.idref"><xsl:value-of select="@xmi.id"/></xsl:attribute>
 </xsl:template>

 <!-- templates to generate new id's for xmi.id and xmi.idref attributes -->
  <xsl:template match="o:module" mode="generate-xmi-id">package-<xsl:value-of select="@name"/></xsl:template>

  <xsl:template match="o:type" mode="generate-xmi-id">type-<xsl:value-of select="@name"/></xsl:template>

  <xsl:template match="o:variable" mode="generate-xmi-id">variable-<xsl:value-of select="count(preceding::o:variable)"/></xsl:template>

  <xsl:template match="o:function" mode="generate-xmi-id">function-<xsl:value-of select="count(preceding::o:function)"/></xsl:template>

  <xsl:template match="o:param" mode="generate-xmi-id">param-<xsl:value-of select="count(preceding::o:param)"/></xsl:template>

  <xsl:template match="o:parent" mode="generate-xmi-id">generalization-<xsl:value-of select="count(preceding::o:parent)"/></xsl:template>

  <xsl:template match="text()"/>

</xsl:stylesheet>
