<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"  xmlns:UML="omg.org/UML/1.4">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" omit-xml-declaration="no" />
<xsl:template match="/">
	<xsl:element name="UMLProfile">
		<xsl:attribute name="profiletype" >uml2</xsl:attribute>
		<xsl:element name="Documentation">
			<xsl:attribute name="id" >profile</xsl:attribute>
			<xsl:attribute name="name">org.andromda.profile-3.2-SNAPSHOT</xsl:attribute>
			<xsl:attribute name="version" >1.0</xsl:attribute>
			<xsl:attribute name="notes" >AndroMDA Profile</xsl:attribute>
		</xsl:element>
		<xsl:element name="Content">
			<xsl:element name="Stereotypes">
				<xsl:apply-templates select="/XMI/XMI.content/UML:Model/UML:Namespace.ownedElement/UML:Package/UML:Namespace.ownedElement"/>
			</xsl:element>
		</xsl:element>
	</xsl:element>
</xsl:template>
<xsl:template match="/XMI/XMI.content/UML:Model/UML:Namespace.ownedElement/UML:Package/UML:Namespace.ownedElement">
	<xsl:for-each select="UML:Stereotype">
		<xsl:element name="Stereotype">
			<xsl:attribute name="name"><xsl:value-of select="@name"/></xsl:attribute>
			<xsl:attribute name="notes"><xsl:value-of select="UML:ModelElement.comment/UML:Comment/@name"/>	</xsl:attribute>
			<xsl:variable name="id" select="@xmi.id"/>
			<xsl:call-template name="generalizes">
				<xsl:with-param name="id" select="..//UML:Generalization[@child=$id]/@parent"/>
			</xsl:call-template>
			<xsl:element name="AppliesTo">
				<xsl:element name="Apply">
					<xsl:attribute name="type"><xsl:value-of select="UML:Stereotype.baseClass"/></xsl:attribute>
				</xsl:element>
			</xsl:element>
		</xsl:element>
	</xsl:for-each>
</xsl:template>
<xsl:template name="generalizes">
	<xsl:param name="id"/>
	<xsl:if test="string-length(normalize-space($id))>0">
		<xsl:attribute name="generalizes">
			<xsl:value-of select="//UML:Stereotype[@xmi.id=$id]/@name"/>
		</xsl:attribute>
	</xsl:if>
</xsl:template>
</xsl:stylesheet>
