<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" indent="yes"/>

<!-- Main Template! -->
<xsl:template match="/">
<Gen-it>&#xa0;
	<Classes>
		<xsl:apply-templates select="//Foundation.Core.Class[@xmi.id]"  mode="class">
			<xsl:sort select="Foundation.Core.ModelElement.name"/>
		</xsl:apply-templates>&#xa0;
	</Classes>&#xa0;
</Gen-it>
</xsl:template>

<!-- Format a Class. -->
<xsl:template match="Foundation.Core.Class" mode="class">
	<xsl:variable name="xmi_id" select="@xmi.id" />
	<xsl:variable name="classname" select="Foundation.Core.ModelElement.name"/>&#xa0;
	<Class>&#xa0;
		<Class.name><xsl:value-of select="$classname"/></Class.name>&#xa0;
		<Class.stereotype><xsl:apply-templates select="./Foundation.Core.ModelElement.stereotype/Foundation.Extension_Mechanisms.Stereotype[@xmi.idref]"  mode="stereotype">
			</xsl:apply-templates></Class.stereotype>&#xa0;
		<Class.documentation><xsl:apply-templates select="./Foundation.Core.ModelElement.taggedValue/Foundation.Extension_Mechanisms.TaggedValue[Foundation.Extension_Mechanisms.TaggedValue.tag = 'documentation']"  mode="tag">
				</xsl:apply-templates></Class.documentation>
		<xsl:apply-templates select="./Foundation.Core.Classifier.feature/Foundation.Core.Attribute[@xmi.id]"  mode="attribute">
			</xsl:apply-templates>&#xa0;
		</Class>
</xsl:template>

<!-- Output a Class Name from a reference. -->
<xsl:template match="Foundation.Core.Class" mode="classref">
	<xsl:variable name="xmi_idref" select="@xmi.idref" />
	<xsl:value-of select="//Foundation.Core.Class[@xmi.id=$xmi_idref]/Foundation.Core.ModelElement.name"/>
</xsl:template>

<!-- Format an Attribute. -->
<xsl:template match="Foundation.Core.Attribute" mode="attribute">
	<xsl:variable name="element_name" select="Foundation.Core.ModelElement.name"/>
	<xsl:variable name="xmi_id" select="@xmi.id" />&#xa0;
		<Attribute>&#xa0;
			<Attribute.name><xsl:value-of select="$element_name"/></Attribute.name>&#xa0;
			<Attribute.datatype><xsl:apply-templates select="./Foundation.Core.StructuralFeature.type/Foundation.Core.DataType[@xmi.idref]"  mode="datatype">
				</xsl:apply-templates></Attribute.datatype>&#xa0;
			<Attribute.stereotype><xsl:apply-templates select="./Foundation.Core.ModelElement.stereotype/Foundation.Extension_Mechanisms.Stereotype[@xmi.idref]"  mode="stereotype">
				</xsl:apply-templates></Attribute.stereotype>&#xa0;
			<Attribute.documentation><xsl:apply-templates select="./Foundation.Core.ModelElement.taggedValue/Foundation.Extension_Mechanisms.TaggedValue[Foundation.Extension_Mechanisms.TaggedValue.tag = 'documentation']"  mode="tag">
				</xsl:apply-templates></Attribute.documentation>
			<xsl:apply-templates select="../../Foundation.Core.Classifier.associationEnd/Foundation.Core.AssociationEnd"  mode="referencing">
				<xsl:with-param name="attribute" select="$element_name"/>
				<xsl:with-param name="class" select="../../Foundation.Core.ModelElement.name"/>
				</xsl:apply-templates>&#xa0;
		</Attribute>
</xsl:template>
<xsl:template match="*" mode="referencing">
	<xsl:param name="attribute" select="'unknown'"/>
	<xsl:param name="class" select="'unknown class'"/>
	<xsl:variable name="xmi_idref" select="@xmi.idref"/>
	<xsl:apply-templates select="//Foundation.Core.AssociationEnd[@xmi.id=$xmi_idref]"  mode="ReferencedClass">
		<xsl:with-param name="attribute" select="$attribute"/>
		<xsl:with-param name="class" select="$class"/>
	</xsl:apply-templates>	
</xsl:template>

<xsl:template match="Foundation.Core.AssociationEnd" mode="ReferencedClass">
	<xsl:param name="attribute" select="'unknown'"/>
	<xsl:variable name="element_name" select="../../Foundation.Core.ModelElement.name"/>
	<xsl:variable name="xmi_id" select="@xmi.id" />
	<xsl:if test="$attribute=$element_name">&#xa0;
			<Reference>&#xa0;
				<Reference.name><xsl:value-of select="$element_name"/></Reference.name>&#xa0;
				<Reference.documentation><xsl:apply-templates select="../../Foundation.Core.ModelElement.taggedValue/Foundation.Extension_Mechanisms.TaggedValue[Foundation.Extension_Mechanisms.TaggedValue.tag = 'documentation']"  mode="tag">
					</xsl:apply-templates></Reference.documentation>
				<xsl:apply-templates select="../Foundation.Core.AssociationEnd[@xmi.id!=$xmi_id]"  mode="Othertest">
				</xsl:apply-templates>&#xa0;
			</Reference>
	</xsl:if>
</xsl:template>
<xsl:template match="Foundation.Core.AssociationEnd" mode="Othertest">
	<xsl:variable name="element_name" select="../../Foundation.Core.ModelElement.name"/>
	<xsl:variable name="xmi_id" select="@xmi.id" />&#xa0;
				<Reference.class>
				<xsl:apply-templates select="./Foundation.Core.AssociationEnd.type/Foundation.Core.Class"  mode="classref">
				</xsl:apply-templates>
				</Reference.class>&#xa0;
				<Reference.mulitplicity><xsl:value-of select="./Foundation.Core.AssociationEnd.multiplicity"/></Reference.mulitplicity>&#xa0;
				<Reference.optional><xsl:if test="substring(./Foundation.Core.AssociationEnd.multiplicity,1,1)='0'">True</xsl:if>
				<xsl:if test="substring(./Foundation.Core.AssociationEnd.multiplicity,1,1)!='0'">False</xsl:if>
				</Reference.optional>&#xa0;
				<Reference.attribute>
					<xsl:apply-templates select="./Foundation.Core.AssociationEnd.type/Foundation.Core.Class"  mode="PKClass">
					</xsl:apply-templates>
				</Reference.attribute>
</xsl:template>
<xsl:template match="Foundation.Core.Class" mode="PKClass">
	<xsl:variable name="xmi_idref" select="@xmi.idref" />
	<xsl:apply-templates select="//Foundation.Core.Class[@xmi.id=$xmi_idref]/Foundation.Core.Classifier.feature/Foundation.Core.Attribute"  mode="PK">
	</xsl:apply-templates>
</xsl:template>
<xsl:template match="Foundation.Core.Attribute" mode="PK">
	<xsl:variable name="attributename" select="Foundation.Core.ModelElement.name" />
	<xsl:apply-templates select="Foundation.Core.ModelElement.stereotype/Foundation.Extension_Mechanisms.Stereotype"  mode="PKStereotype">
		<xsl:with-param name="attributename" select="$attributename"/>
	</xsl:apply-templates>
</xsl:template>

<xsl:template match="Foundation.Extension_Mechanisms.Stereotype" mode="PKStereotype">
	<xsl:param name="attributename" select="unknown"/>
	<xsl:variable name="xmi_idref" select="@xmi.idref" />
	<xsl:apply-templates select="//Foundation.Extension_Mechanisms.Stereotype[@xmi.id=$xmi_idref]"  mode="PKStereotype2">
		<xsl:with-param name="attributename" select="$attributename"/>
	</xsl:apply-templates>
</xsl:template>

<xsl:template match="Foundation.Extension_Mechanisms.Stereotype" mode="PKStereotype2">
	<xsl:param name="attributename" select="unknown"/>
	<xsl:if test="Foundation.Core.ModelElement.name='PK'">
		<xsl:value-of select="$attributename"/>
	</xsl:if>
</xsl:template>


<!-- Output the value of a tag -->
<xsl:template match="Foundation.Extension_Mechanisms.TaggedValue" mode="tag">
	<xsl:value-of select="./Foundation.Extension_Mechanisms.TaggedValue.value"/>
</xsl:template>

<!-- Format a Attribute's Datatype. -->
<xsl:template match="Foundation.Core.DataType" mode="datatype">
	<xsl:variable name="xmi_idref" select="@xmi.idref" />
	<xsl:value-of select="//Foundation.Core.DataType[@xmi.id=$xmi_idref]/Foundation.Core.ModelElement.name"/>
</xsl:template>

<!-- Output the referenced stereotype -->
<xsl:template match="//Foundation.Extension_Mechanisms.Stereotype" mode="stereotype">
	<xsl:variable name="xmi_idref" select="@xmi.idref" />
	<xsl:value-of select="//Foundation.Extension_Mechanisms.Stereotype[@xmi.id=$xmi_idref]/Foundation.Core.ModelElement.name"/>
</xsl:template>

<!-- Output the referenced Datatypes -->
<xsl:template match="//Foundation.Core.DataType" mode="test">
	<xsl:variable name="xmi_idref" select="@xmi.idref" />
	<xsl:value-of select="//Foundation.Extension_Mechanisms.Stereotype[@xmi.id=$xmi_idref]/Foundation.Core.ModelElement.name"/>
</xsl:template>

</xsl:stylesheet>
                
