<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:UML="omg.org/UML1.3">
<xsl:output indent="yes"/>

	<xsl:template match="/">
	
		<nta>
		<!--Declaracion de las variables globales, en este caso van a ser canales, canales de multisincronizacion, relojes, enteros y booleanos-->
			<declaration>
			
				<xsl:text>chan </xsl:text>
				<canales>
				<xsl:call-template name="variable_canal"/>
				</canales>
				
				<xsl:text>multi_chan </xsl:text>
				<canales_multi>
				<xsl:call-template name="variable_canal_multi"/>
				</canales_multi>
				
				<xsl:text>int [0,1] </xsl:text>
				<boolean>
		    	<xsl:call-template name="variable_boolean"/>
				</boolean>
				
				<xsl:text>int </xsl:text>
				<integer>
				<xsl:call-template name="variable_int"/>
				</integer>
				
				<xsl:text>clock </xsl:text>
				<reloj>
				<xsl:call-template name="variable_reloj"/>
				</reloj>
							
			</declaration>
			
			<!--Templates que componen el automata para actores y lifelines-->
			<xsl:for-each select="XMI/XMI.content/Foundation.Core.Namespace.ownedElement/Behavioral_Elements.Use_Cases.Actor">
			
				<xsl:call-template name="automata_templates">
					<xsl:with-param name="name"><xsl:value-of select="translate(Foundation.Core.ModelElement.name,' .','__')"/></xsl:with-param>
					<xsl:with-param name="identifier"><xsl:value-of select="@xmi.id"/></xsl:with-param>
				</xsl:call-template>
				
			</xsl:for-each>
			
			<xsl:for-each select="XMI/XMI.content/Foundation.Core.Namespace.ownedElement/Behavioral_Elements.Collaborations.ClassifierRole">
				
				<xsl:call-template name="automata_templates">
					<xsl:with-param name="name"><xsl:value-of select="translate(Foundation.Core.ModelElement.name,' .','__')"/></xsl:with-param>
					<xsl:with-param name="identifier"><xsl:value-of select="@xmi.id"/></xsl:with-param>
				</xsl:call-template>
				
			</xsl:for-each>
			
		<instantiation/>
		  <!--Faltan los correspondientes a los par y a los canales de multisincronización, finaliza con ,-->
		  <system>
		  
			<xsl:text>system </xsl:text>
				<xsl:for-each select="XMI/XMI.content/Foundation.Core.Namespace.ownedElement/Behavioral_Elements.Use_Cases.Actor">
				
					<xsl:value-of select="translate(Foundation.Core.ModelElement.name,' .','__')"/>
					<xsl:text>RoleType</xsl:text>
					<xsl:text>, </xsl:text>			
								
				</xsl:for-each>
			
				<xsl:for-each select="XMI/XMI.content/Foundation.Core.Namespace.ownedElement/Behavioral_Elements.Collaborations.ClassifierRole">
			
					<xsl:value-of select="translate(Foundation.Core.ModelElement.name,' .','__')"/>
					<xsl:text>RoleType</xsl:text>
					<xsl:text>, </xsl:text>				
								
				</xsl:for-each>
			  
		  </system>				
			
		</nta>		
		
	</xsl:template>
	
	<!--PLANTILLA DE LOS TEMPLATES QUE COMPONEN EL AUTÓMATA PARA CADA ACTOR Y LIFELINE-->
	<xsl:template name="automata_templates">
		
		<xsl:param name="name"/>
		<xsl:param name="identifier"/>
		
		<template>
		
		<name>
			<!--Identificador-->
			<xsl:attribute name="id">
				<xsl:value-of select="$identifier"/>
			</xsl:attribute>
				
			<xsl:value-of select="$name"/><xsl:text>RoleType</xsl:text>			
		</name>
						
		<!--A partir de aqui se deben ordenar los objetos que tengan relación con el template y se deben guardar los datos de interés para cada uno-->
		
		<!--Consulta de los mensajes-->
	
		<xsl:for-each select="//XMI/XMI.content/Foundation.Core.Namespace.ownedElement/Behavioral_Elements.Collaborations.Collaborations/Behavioral_Elements.Collaborations.Collaboration.interaction/Behavioral_Elements.Collaborations.Message">
			
			<xsl:variable name="nombre" select="translate(Foundation.Core.ModelElement.name,' .:','___')"/>
			<xsl:variable name="identificador" select="@xmi.id"/>			
			<xsl:variable name="origen" select="Behavioral_Elements.Collaborations.Message.sender/Behavioral_Elements.Collaborations.ClassifierRole/@xmi.idref"/>			
			<xsl:variable name="destino" select="Behavioral_Elements.Collaborations.Message.receiver/Behavioral_Elements.Collaborations.ClassifierRole/@xmi.idref"/>
						
			<!--Sólo nos interesan los mensajes que tengan como origen o destino el rol actual-->
			
			<xsl:if test="($identifier = $origen) or ($identifier = $destino)">
			
			<interaction>
			
				<!--Identificador-->
				<xsl:attribute name="id">
					<xsl:value-of select="$identificador"/>
				</xsl:attribute>
				
				<!--Identificador del frame padre en caso de existir-->							
				<xsl:attribute name="parent">
					<xsl:value-of select="Behavioral_Elements.Collaborations.Message.frame/Foundation.Extension_Mechanisms.Stereotype/@xmi.idref"/>
				</xsl:attribute>				
				
				<!--Nombre-->
				<xsl:attribute name="name">
				   <xsl:if test="contains(Foundation.Core.ModelElement.name,'_')">
					<xsl:value-of select="translate(substring-after(Foundation.Core.ModelElement.name,'_'),' .:','___')"/>
                   </xsl:if>
				   <xsl:if test="not(contains(Foundation.Core.ModelElement.name,'_'))">
				     <xsl:value-of select="translate(Foundation.Core.ModelElement.name,' .:','___')"/>
				   </xsl:if>
				</xsl:attribute>				
				
				<!--Rol, si es origen o destino del mensaje-->
				<xsl:attribute name="role">
				   <xsl:if test="$identifier = $origen">
					<xsl:value-of select="'source'"/>
                   </xsl:if>
				   <xsl:if test="$identifier = $destino">
				     <xsl:value-of select="'target'"/>
				   </xsl:if>
				</xsl:attribute>
				
				<!--Origen del mensaje-->
				<xsl:attribute name="source">
				   <xsl:value-of select="$origen"/>                   
				</xsl:attribute>
				
				<!--Destino del mensaje-->
				<xsl:attribute name="target">
				   <xsl:value-of select="$destino"/>                   
				</xsl:attribute>
				
				<!--Si está dentro de un frame de tipo par se deja marcado en que parte está-->
				<xsl:for-each select="//XMI/XMI.content/Foundation.Core.Namespace.ownedElement/Foundation.Extension_Mechanisms.TaggedValue/Foundation.Extension_Mechanisms.TaggedValue.tag[.='parOrder']">
				
					<xsl:if test="../Foundation.Extension_Mechanisms.TaggedValue.modelElement/Foundation.Core.ModelElement[@xmi.idref=$identificador]">
						<xsl:attribute name="parseq">
							<xsl:value-of select="../Foundation.Extension_Mechanisms.TaggedValue.value"/>
						</xsl:attribute>
					</xsl:if>					
					
				</xsl:for-each>
				
				<!--Si está dentro de un frame de tipo alt se deja marcado en que parte está-->
				<xsl:for-each select="//XMI/XMI.content/Foundation.Core.Namespace.ownedElement/Foundation.Extension_Mechanisms.TaggedValue/Foundation.Extension_Mechanisms.TaggedValue.tag[.='altOrder']">
				
					<xsl:if test="../Foundation.Extension_Mechanisms.TaggedValue.modelElement/Foundation.Core.ModelElement[@xmi.idref=$identificador]">
						<xsl:attribute name="altseq">
							<xsl:value-of select="../Foundation.Extension_Mechanisms.TaggedValue.value"/>
						</xsl:attribute>
					</xsl:if>
					
				</xsl:for-each>
				
				<!--Si está dentro de un frame de tipo alt_else se deja marcado en cual de las dos partes está-->
				<xsl:for-each select="//XMI/XMI.content/Foundation.Core.Namespace.ownedElement/Foundation.Extension_Mechanisms.TaggedValue/Foundation.Extension_Mechanisms.TaggedValue.tag[.='altelseOrder']">
				
					<xsl:if test="../Foundation.Extension_Mechanisms.TaggedValue.modelElement/Foundation.Core.ModelElement[@xmi.idref=$identificador]">
						<xsl:attribute name="altelseseq">
							<xsl:value-of select="../Foundation.Extension_Mechanisms.TaggedValue.value"/>
						</xsl:attribute>
					</xsl:if>
					
				</xsl:for-each>
				
				<!--Orden del elemento en el diagrama-->
				<orden>													
					<xsl:for-each select="//XMI/XMI.content/Foundation.Core.Namespace.ownedElement/Foundation.Extension_Mechanisms.TaggedValue/Foundation.Extension_Mechanisms.TaggedValue.tag[.='sequenceNumber']">									

						<xsl:if test="../Foundation.Extension_Mechanisms.TaggedValue.modelElement/Foundation.Core.ModelElement[@xmi.idref=$identificador]">
							<xsl:value-of select="../Foundation.Extension_Mechanisms.TaggedValue.value"/>
						</xsl:if>
						
					</xsl:for-each>
				</orden>
								
			</interaction>
			</xsl:if>
			
		</xsl:for-each>
		
		<!--Consulta de los frames-->
		
		<xsl:for-each select="//XMI/XMI.content/Foundation.Core.Namespace.ownedElement/Foundation.Extension_Mechanisms.Stereotype">
		
			<xsl:variable name="nombre" select="Foundation.Core.ModelElement.name"/>
			<xsl:variable name="identificador" select="@xmi.id"/>			
			
			<frames>
			
				<!--Identificador-->
				<xsl:attribute name="id">
					<xsl:value-of select="$identificador"/>
				</xsl:attribute>
				
				<!--Identificador del frame padre en caso de existir-->							
				<xsl:attribute name="parent">
					<xsl:value-of select="Foundation.Extension_Mechanisms.Stereotype.frame/Foundation.Extension_Mechanisms.Stereotype/@xmi.idref"/>
				</xsl:attribute>
				
				<!--Nombre-->			
				<xsl:attribute name="name">				   
					<xsl:if test="starts-with($nombre,'alt_else')">						
						<xsl:value-of select="concat('if',substring-after($nombre,'alt_else'))"/>						
					</xsl:if>
					<xsl:if test="not(starts-with($nombre,'alt_else'))">						
						<xsl:value-of select="$nombre"/>
					</xsl:if>
					                   
				</xsl:attribute>
												
				<!--Si está dentro de un frame de tipo par se deja marcado en que parte está-->
				<xsl:for-each select="//XMI/XMI.content/Foundation.Core.Namespace.ownedElement/Foundation.Extension_Mechanisms.TaggedValue/Foundation.Extension_Mechanisms.TaggedValue.tag[.='parOrder']">
				
					<xsl:if test="../Foundation.Extension_Mechanisms.TaggedValue.modelElement/Foundation.Core.ModelElement[@xmi.idref=$identificador]">
						<xsl:attribute name="parseq">
							<xsl:value-of select="../Foundation.Extension_Mechanisms.TaggedValue.value"/>
						</xsl:attribute>
					</xsl:if>
					
				</xsl:for-each>
				
				<!--Si está dentro de un frame de tipo alt se deja marcado en que parte está-->
				<xsl:for-each select="//XMI/XMI.content/Foundation.Core.Namespace.ownedElement/Foundation.Extension_Mechanisms.TaggedValue/Foundation.Extension_Mechanisms.TaggedValue.tag[.='altOrder']">
				
					<xsl:if test="../Foundation.Extension_Mechanisms.TaggedValue.modelElement/Foundation.Core.ModelElement[@xmi.idref=$identificador]">
						<xsl:attribute name="altseq">
							<xsl:value-of select="../Foundation.Extension_Mechanisms.TaggedValue.value"/>
						</xsl:attribute>
					</xsl:if>					
					
				</xsl:for-each>
				
				<!--Si está dentro de un frame de tipo alt_else se deja marcado en que parte está-->
				<xsl:for-each select="//XMI/XMI.content/Foundation.Core.Namespace.ownedElement/Foundation.Extension_Mechanisms.TaggedValue/Foundation.Extension_Mechanisms.TaggedValue.tag[.='altelseOrder']">
				
					<xsl:if test="../Foundation.Extension_Mechanisms.TaggedValue.modelElement/Foundation.Core.ModelElement[@xmi.idref=$identificador]">
						<xsl:attribute name="altelseseq">
							<xsl:value-of select="../Foundation.Extension_Mechanisms.TaggedValue.value"/>
						</xsl:attribute>
					</xsl:if>					
					
				</xsl:for-each>
				
				<!--Dejar marcada la guarda si tiene el frame-->
				<xsl:for-each select="//XMI/XMI.content/Foundation.Core.Namespace.ownedElement/Foundation.Extension_Mechanisms.TaggedValue/Foundation.Extension_Mechanisms.TaggedValue.tag[.='Guard']">
				
					<xsl:if test="../Foundation.Extension_Mechanisms.TaggedValue.modelElement/Foundation.Core.ModelElement[@xmi.idref=$identificador]">
						<xsl:attribute name="guard">
							<xsl:value-of select="../Foundation.Extension_Mechanisms.TaggedValue.value"/>
						</xsl:attribute>
					</xsl:if>					
					
				</xsl:for-each>
				
				<!--Dejar marcado el repeat si tiene el frame-->
				<xsl:for-each select="//XMI/XMI.content/Foundation.Core.Namespace.ownedElement/Foundation.Extension_Mechanisms.TaggedValue/Foundation.Extension_Mechanisms.TaggedValue.tag[.='Repeat']">
					
					<xsl:if test="../Foundation.Extension_Mechanisms.TaggedValue.modelElement/Foundation.Core.ModelElement[@xmi.idref=$identificador]">
						<xsl:attribute name="repeat">
							<xsl:value-of select="../Foundation.Extension_Mechanisms.TaggedValue.value"/>
						</xsl:attribute>
					</xsl:if>					
					
				</xsl:for-each>
				
				<!--Dejar marcada la guarda invertida si tiene el frame-->
				<xsl:for-each select="//XMI/XMI.content/Foundation.Core.Namespace.ownedElement/Foundation.Extension_Mechanisms.TaggedValue/Foundation.Extension_Mechanisms.TaggedValue.tag[.='Guard_invert']">
				
					<xsl:if test="../Foundation.Extension_Mechanisms.TaggedValue.modelElement/Foundation.Core.ModelElement[@xmi.idref=$identificador]">
						<xsl:attribute name="guard_invert">
							<xsl:value-of select="../Foundation.Extension_Mechanisms.TaggedValue.value"/>
						</xsl:attribute>
					</xsl:if>					
					
				</xsl:for-each>
				
				<!--Dejar marcado el repeat invertido si tiene el frame-->
				<xsl:for-each select="//XMI/XMI.content/Foundation.Core.Namespace.ownedElement/Foundation.Extension_Mechanisms.TaggedValue/Foundation.Extension_Mechanisms.TaggedValue.tag[.='Repeat_invert']">
					
					<xsl:if test="../Foundation.Extension_Mechanisms.TaggedValue.modelElement/Foundation.Core.ModelElement[@xmi.idref=$identificador]">
						<xsl:attribute name="repeat_invert">
							<xsl:value-of select="../Foundation.Extension_Mechanisms.TaggedValue.value"/>
						</xsl:attribute>
					</xsl:if>					
					
				</xsl:for-each>
				
				<!--Dejar indicado el número de elementos que contiene el frame-->
				<xsl:for-each select="//XMI/XMI.content/Foundation.Core.Namespace.ownedElement/Foundation.Extension_Mechanisms.TaggedValue/Foundation.Extension_Mechanisms.TaggedValue.tag[.='elements']">
				
					<xsl:if test="../Foundation.Extension_Mechanisms.TaggedValue.modelElement/Foundation.Core.ModelElement[@xmi.idref=$identificador]">
						<xsl:attribute name="elements">
							<xsl:value-of select="../Foundation.Extension_Mechanisms.TaggedValue.value"/>
						</xsl:attribute>
					</xsl:if>					
					
				</xsl:for-each>	
				
				<!--Dejar indicado si el frame es bloqueante-->
				<xsl:for-each select="//XMI/XMI.content/Foundation.Core.Namespace.ownedElement/Foundation.Extension_Mechanisms.TaggedValue/Foundation.Extension_Mechanisms.TaggedValue.tag[.='block']">
				
					<xsl:if test="../Foundation.Extension_Mechanisms.TaggedValue.modelElement/Foundation.Core.ModelElement[@xmi.idref=$identificador]">
						<xsl:attribute name="block">
							<xsl:value-of select="../Foundation.Extension_Mechanisms.TaggedValue.value"/>
						</xsl:attribute>
					</xsl:if>					
					
				</xsl:for-each>				
								
				
				<!--Orden del frame en el diagrama-->				
				<orden>
					<xsl:for-each select="//XMI/XMI.content/Foundation.Core.Namespace.ownedElement/Foundation.Extension_Mechanisms.TaggedValue/Foundation.Extension_Mechanisms.TaggedValue.tag[.='sequenceNumber']">									

						<xsl:if test="../Foundation.Extension_Mechanisms.TaggedValue.modelElement/Foundation.Core.ModelElement[@xmi.idref=$identificador]">							
							<xsl:value-of select="../Foundation.Extension_Mechanisms.TaggedValue.value"/>
						</xsl:if>
						
					</xsl:for-each>
				</orden>
								
			</frames>
			
			<!--Añadir marcas que indiquen el final de un frame en el orden correspondiente-->
			<frames_end>
			
				<xsl:attribute name="name">				   
					<xsl:if test="starts-with($nombre,'alt_else')">						
						<xsl:value-of select="concat('if',substring-after($nombre,'alt_else'))"/>						
					</xsl:if>
					<xsl:if test="not(starts-with($nombre,'alt_else'))">						
						<xsl:value-of select="$nombre"/>
					</xsl:if>
					                   
				</xsl:attribute>
				
				<!--Identificador-->
				<xsl:attribute name="id">
					<xsl:value-of select="$identificador"/>
				</xsl:attribute>
								
				<!--Dejar indicado el número de elementos que contiene el frame-->
				<xsl:for-each select="//XMI/XMI.content/Foundation.Core.Namespace.ownedElement/Foundation.Extension_Mechanisms.TaggedValue/Foundation.Extension_Mechanisms.TaggedValue.tag[.='elements']">
				
					<xsl:if test="../Foundation.Extension_Mechanisms.TaggedValue.modelElement/Foundation.Core.ModelElement[@xmi.idref=$identificador]">
						
							<xsl:variable name="elementos" select="../Foundation.Extension_Mechanisms.TaggedValue.value"/>							
							
							<!--Orden del final del frame en el diagrama-->
							<orden>
								<xsl:for-each select="//XMI/XMI.content/Foundation.Core.Namespace.ownedElement/Foundation.Extension_Mechanisms.TaggedValue/Foundation.Extension_Mechanisms.TaggedValue.tag[.='sequenceNumber']">									
			
									<xsl:if test="../Foundation.Extension_Mechanisms.TaggedValue.modelElement/Foundation.Core.ModelElement[@xmi.idref=$identificador]">							
										<xsl:value-of select="(../Foundation.Extension_Mechanisms.TaggedValue.value) + $elementos + 1"/>
									</xsl:if>
									
								</xsl:for-each>
							</orden>
						
					</xsl:if>					
					
				</xsl:for-each>	
				
				
												
			</frames_end>
												
		</xsl:for-each>
					
	
	</template>

</xsl:template>
	
<!--PLANTILLA PARA LAS VARIABLES DE TIPO CANAL-->
<xsl:template name="variable_canal">	
		
	<!--Posteriormente se deben eliminar los canales con origen igual al destino y aquellos que se repitan en orden inverso.
		Estos canales se utilizan para los "send" y "recv"-->
	<xsl:for-each select="XMI/XMI.content/Foundation.Core.Namespace.ownedElement/Behavioral_Elements.Collaborations.Collaborations/Behavioral_Elements.Collaborations.Collaboration.interaction/Behavioral_Elements.Collaborations.Message">
	
		<xsl:variable name="id_sour" select="Behavioral_Elements.Collaborations.Message.sender/Behavioral_Elements.Collaborations.ClassifierRole/@xmi.idref"/>
		
		<xsl:variable name="id_dest" select="Behavioral_Elements.Collaborations.Message.receiver/Behavioral_Elements.Collaborations.ClassifierRole/@xmi.idref"/>
		
		<chan>
				<!--Se debe tener en cuenta que pueden ser un actor o un rol-->
				
				<xsl:if test="/XMI/XMI.content/Foundation.Core.Namespace.ownedElement/Behavioral_Elements.Use_Cases.Actor[@xmi.id = $id_sour]">
				
					<xsl:value-of select="translate(/XMI/XMI.content/Foundation.Core.Namespace.ownedElement/Behavioral_Elements.Use_Cases.Actor[@xmi.id = $id_sour]/Foundation.Core.ModelElement.name,' .:','___')"/>
					
				</xsl:if>
				
				<xsl:if test="/XMI/XMI.content/Foundation.Core.Namespace.ownedElement/Behavioral_Elements.Collaborations.ClassifierRole[@xmi.id = $id_sour]">
				
					<xsl:value-of select="translate(/XMI/XMI.content/Foundation.Core.Namespace.ownedElement/Behavioral_Elements.Collaborations.ClassifierRole[@xmi.id = $id_sour]/Foundation.Core.ModelElement.name,' .:','___')"/>
					
				</xsl:if>
				
				<xsl:text>.</xsl:text>
				
				<xsl:if test="/XMI/XMI.content/Foundation.Core.Namespace.ownedElement/Behavioral_Elements.Use_Cases.Actor[@xmi.id = $id_dest]">
				
					<xsl:value-of select="translate(/XMI/XMI.content/Foundation.Core.Namespace.ownedElement/Behavioral_Elements.Use_Cases.Actor[@xmi.id = $id_dest]/Foundation.Core.ModelElement.name,' .:','___')"/>
				
				</xsl:if>
				
				<xsl:if test="/XMI/XMI.content/Foundation.Core.Namespace.ownedElement/Behavioral_Elements.Collaborations.ClassifierRole[@xmi.id = $id_dest]">
				
					<xsl:value-of select="translate(/XMI/XMI.content/Foundation.Core.Namespace.ownedElement/Behavioral_Elements.Collaborations.ClassifierRole[@xmi.id = $id_dest]/Foundation.Core.ModelElement.name,' .:','___')"/>
					
				</xsl:if>
					
		</chan>					
													
	</xsl:for-each>		
	
	<!-- También hay que definir un canal por cada frame par y cada objeto-->
	
	<xsl:for-each select="XMI/XMI.content/Foundation.Core.Namespace.ownedElement/Behavioral_Elements.Use_Cases.Actor/Foundation.Core.ModelElement.name">
	
		<xsl:variable name="objeto" select="."/>
		
		<xsl:for-each select="//XMI/XMI.content/Foundation.Core.Namespace.ownedElement/Foundation.Extension_Mechanisms.TaggedValue/Foundation.Extension_Mechanisms.TaggedValue.tag[.='parOrder' and ../Foundation.Extension_Mechanisms.TaggedValue.value='1']">
		
			<chan>
			
				<xsl:text>par_</xsl:text><xsl:value-of select="$objeto"/><xsl:value-of select="count(preceding::*/Foundation.Extension_Mechanisms.TaggedValue.tag[.='parOrder' and ../Foundation.Extension_Mechanisms.TaggedValue.value='1']) + 1"/>
				
			</chan>			
									
		</xsl:for-each>
		
	</xsl:for-each>		
	
	<xsl:for-each select="XMI/XMI.content/Foundation.Core.Namespace.ownedElement/Behavioral_Elements.Collaborations.ClassifierRole/Foundation.Core.ModelElement.name">
		
		<xsl:variable name="objeto" select="."/>
						  
		<xsl:for-each select="//XMI/XMI.content/Foundation.Core.Namespace.ownedElement/Foundation.Extension_Mechanisms.TaggedValue/Foundation.Extension_Mechanisms.TaggedValue.tag[.='parOrder' and ../Foundation.Extension_Mechanisms.TaggedValue.value='1']">
		
			<chan>
			
				<xsl:text>par_</xsl:text><xsl:value-of select="$objeto"/><xsl:value-of select="count(preceding::*/Foundation.Extension_Mechanisms.TaggedValue.tag[.='parOrder' and ../Foundation.Extension_Mechanisms.TaggedValue.value='1']) + 1"/>
				
			</chan>			
									
		</xsl:for-each>
					
		
	</xsl:for-each>				
									
	</xsl:template>
	
	<!--PLANTILLA PARA LAS VARIABLES DE TIPO CANAL DE MULTISINCRONIZACION-->
	<xsl:template name="variable_canal_multi">
		<!--Hay que definir dos canales multi por cada frame if o alt y tres canales multi por cada frame loop-->		
		<xsl:for-each select="XMI/XMI.content/Foundation.Core.Namespace.ownedElement/Foundation.Extension_Mechanisms.TaggedValue/Foundation.Extension_Mechanisms.TaggedValue.tag[.='altelseOrder' and ../Foundation.Extension_Mechanisms.TaggedValue.value='1']">
			
			<chan_multi>
			
				<xsl:text>if</xsl:text><xsl:value-of select="count(preceding::*/Foundation.Extension_Mechanisms.TaggedValue.tag[.='altelseOrder' and ../Foundation.Extension_Mechanisms.TaggedValue.value='1']) + 1"/><xsl:text>_1</xsl:text>
				
			</chan_multi>
			<chan_multi>
			
				<xsl:text>if</xsl:text><xsl:value-of select="count(preceding::*/Foundation.Extension_Mechanisms.TaggedValue.tag[.='altelseOrder' and ../Foundation.Extension_Mechanisms.TaggedValue.value='1']) + 1"/><xsl:text>_2</xsl:text>
			
			</chan_multi>
										
		</xsl:for-each>
		
		<xsl:for-each select="XMI/XMI.content/Foundation.Core.Namespace.ownedElement/Foundation.Extension_Mechanisms.TaggedValue/Foundation.Extension_Mechanisms.TaggedValue.tag[.='altOrder' and ../Foundation.Extension_Mechanisms.TaggedValue.value='1']">
				
			<chan_multi>
			
				<xsl:text>alt</xsl:text><xsl:value-of select="count(preceding::*/Foundation.Extension_Mechanisms.TaggedValue.tag[.='altOrder' and ../Foundation.Extension_Mechanisms.TaggedValue.value='1']) + 1"/><xsl:text>_1</xsl:text>
				
			</chan_multi>
			<chan_multi>
			
				<xsl:text>alt</xsl:text><xsl:value-of select="count(preceding::*/Foundation.Extension_Mechanisms.TaggedValue.tag[.='altOrder' and ../Foundation.Extension_Mechanisms.TaggedValue.value='1']) + 1"/><xsl:text>_2</xsl:text>
			
			</chan_multi>
										
		</xsl:for-each>
		
		<xsl:for-each select="XMI/XMI.content/Foundation.Core.Namespace.ownedElement/Foundation.Extension_Mechanisms.TaggedValue/Foundation.Extension_Mechanisms.TaggedValue.tag[.='Repeat']">
				
			<chan_multi>
			
				<xsl:text>loop</xsl:text><xsl:value-of select="count(preceding::*/Foundation.Extension_Mechanisms.TaggedValue.tag[.='Repeat' and ../Foundation.Extension_Mechanisms.TaggedValue.value='1']) + 1"/><xsl:text>_1</xsl:text>
				
			</chan_multi>
			<chan_multi>
			
				<xsl:text>loop</xsl:text><xsl:value-of select="count(preceding::*/Foundation.Extension_Mechanisms.TaggedValue.tag[.='Repeat' and ../Foundation.Extension_Mechanisms.TaggedValue.value='1']) + 1"/><xsl:text>_2</xsl:text>
				
			</chan_multi>
			<chan_multi>
			
				<xsl:text>loop</xsl:text><xsl:value-of select="count(preceding::*/Foundation.Extension_Mechanisms.TaggedValue.tag[.='Repeat' and ../Foundation.Extension_Mechanisms.TaggedValue.value='1']) + 1"/><xsl:text>_3</xsl:text>
							
			</chan_multi>
										
		</xsl:for-each>
	</xsl:template>
	
	<!--PLANTILLA PARA LAS VARIABLES BOOLEANAS-->
	<xsl:template name="variable_boolean">
	
		<xsl:for-each select="XMI/XMI.content/Foundation.Core.Namespace.ownedElement/Foundation.Extension_Mechanisms.TaggedValue[Foundation.Extension_Mechanisms.TaggedValue.tag='Variable']">
		
			<!--Ver si se trata de una variable booleana-->
			<xsl:if test="substring-after(Foundation.Extension_Mechanisms.TaggedValue.value,' ')='Boolean'">
			
			    <bool>
				<xsl:value-of select="substring-before(Foundation.Extension_Mechanisms.TaggedValue.value,'=')"/>
				</bool>
				
			</xsl:if>
													
		</xsl:for-each>
		
	</xsl:template>	
	
		
	<!--PLANTILLA PARA LAS VARIABLES GLOBALES INT INTERCAMBIADAS EN LOS EXCHANGE-->
	<xsl:template name="variable_int">

		<xsl:for-each select="XMI/XMI.content/Foundation.Core.Namespace.ownedElement/Foundation.Extension_Mechanisms.TaggedValue[Foundation.Extension_Mechanisms.TaggedValue.tag='Variable']">
		
			<!--Ver si se trata de una variable booleana-->
			<xsl:if test="substring-after(Foundation.Extension_Mechanisms.TaggedValue.value,' ')='Integer'">
			
			    <int>
				<xsl:value-of select="substring-before(Foundation.Extension_Mechanisms.TaggedValue.value,'=')"/>
				</int>
				
			</xsl:if>
													
		</xsl:for-each>
			
	</xsl:template>	
			
	<!--PLANTILLA PARA LAS VARIABLES DE TIPO RELOJ GLOBALES-->
	<xsl:template name="variable_reloj">
		
		<xsl:for-each select="XMI/XMI.content/Foundation.Core.Namespace.ownedElement/Foundation.Extension_Mechanisms.TaggedValue[Foundation.Extension_Mechanisms.TaggedValue.tag='Variable']">
		
			<!--Ver si se trata de una variable reloj-->
			<xsl:if test="substring-after(Foundation.Extension_Mechanisms.TaggedValue.value,' ')='Clock'">
			
			    <clock>
				<xsl:value-of select="substring-before(Foundation.Extension_Mechanisms.TaggedValue.value,' ')"/>
				</clock>
				
			</xsl:if>
													
		</xsl:for-each>
		
	</xsl:template>
			
</xsl:stylesheet>