<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet 
        xmlns="http://www.w3.org/2005/10/wsdl-rdf/"
		xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
		xmlns:wsdl="http://www.w3.org/ns/wsdl/"  
  		xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
  		xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
 		xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
 	 	xmlns:sawsdl="http://www.w3.org/ns/sawsdl/" version="1.0">
 
<!-- Version 0.7 Mohamed Bennis, Fabien Gandon, INRIA, Sophia antipolis, Edelweiss research team -->
<!-- This transformation is available as freeware and under the non viral open-source licence CeCILL-C -->
<!-- see licence details at : http://www.cecill.info/licences/Licence_CeCILL-C_V1-en.html -->
 	 	
<xsl:output indent="yes" method="xml" media-type="application/rdf+xml" encoding="UTF-8" omit-xml-declaration="yes"/>
 
 <!-- target of the current definitions\description of service -->
<xsl:variable name='tnamespace' select="/wsdl:definitions/@targetNamespace | /wsdl:description/@targetNamespace" />

<!-- To construct IRI fragment for each wsdl component -->
   
<xsl:template name="construct_attribut">

	<!-- parameter "id" used to identify a reference of component in SAWSDL file  -->
	<xsl:param name="id" />
	<!-- parameter "id_value" used to identify a value of attribut of component in SAWSDL file -->
	<xsl:param name="id_value" />
	<!-- parameter used to identify how many part we have to reference component in SAWSDL file -->
	<xsl:param name="level" />
	
	<!-- a prefix namespace of the attribut value -->
 	<xsl:variable name="prefix_attribut_name" select="substring-before($id_value,':')" />
 	<!-- a value of the attribut wihout a prefix of namespace -->
	<xsl:variable name="attribut_name" select="substring-after($id_value,':')" />
	<!-- a value of the interface (portType in Wsdl1.1) associate to message name-->
	<xsl:variable name="attribut_name_part0" select="parent::*/parent::*/@name | parent::*/parent::*/@ref " />
	<!-- a value of the interfaceOperation (Operation in Wsdl1.1) associate to message name -->
	<xsl:variable name="attribut_name_part1" select="parent::*/@ref | parent::*/@name" />
	
	<xsl:choose>
					<!-- case where the value of attribut has a prefix  -->
			        <xsl:when test='contains($id_value,":")'>
			        	   
			        	   <!-- search a namespace used by attribut value or there parents -->    	 
			        	<xsl:for-each select="/wsdl:definitions/namespace::*">
		   		 	 								
							<xsl:choose>
							    <!-- case where we detect a prefix used by attribut value -->
								<xsl:when test="$prefix_attribut_name=name()">
									<xsl:choose>
									
										<xsl:when test="$id='service' or $id='typeDefinition'">
											<xsl:value-of select="concat($tnamespace,'xmlns(ns1=',. ,')wsdl.',$id,'(ns1:',$attribut_name,')')"/>
										</xsl:when>
										
										<xsl:when test='$id="interface"'>
											<xsl:value-of select="concat($tnamespace,'xmlns(ns1=',. ,')wsdl.',$id,'(ns1:',$attribut_name,')')"/>
										</xsl:when>
										
										<xsl:when test='$id="interfaceFault"'>
											<xsl:value-of select="concat($tnamespace,'xmlns(ns1=',. ,')wsdl.',$id,'(',$attribut_name,')')"/>
										</xsl:when>
										
										<xsl:when test="$id='interfaceOperation' or $id='endpoint'">
										                <!-- parent (interfaceOperation) don't contain a prefix  -->
														<xsl:if test="$level=1">
															<xsl:value-of select="concat($tnamespace,'xmlns(ns1=',. ,')wsdl.',$id,'(',$attribut_name_part1,'/ns1:',$attribut_name,')')"/>
														</xsl:if>
											
														<!-- parent contain ":" (a prefix)  -->
														<xsl:if test ="$level=2">
													
																<!-- case where there are a namespace in the first part of interface operation  -->
													     	    <xsl:variable name="value_part2"   select="concat(')xmlns(ns2=',. ,')wsdl.',$id,'(ns1:',substring-after($attribut_name_part1,':'),'/ns2:',$attribut_name,')')"></xsl:variable>
													         	<xsl:for-each select="/wsdl:definitions/namespace::*">
													         	    <xsl:choose>
																		<xsl:when test="substring-before($attribut_name_part1,':')=name()">
													         				<xsl:value-of select="concat($tnamespace,'xmlns(ns1=',. ,$value_part2)"/>
													         			</xsl:when>
													         		</xsl:choose>
												     			</xsl:for-each>
												     	 </xsl:if>
										    </xsl:when>
										
										
										<xsl:when test="$id='interfaceMessageReference' or $id='bindingMessageReference'">
								                <!--case where only a message (attribut value) use a prefix namespace -->
								                <xsl:if test="$level=1">
													<xsl:value-of select="concat($tnamespace,'xmlns(ns1=',. ,')wsdl.',$id,'(',$attribut_name_part0,'/',$attribut_name_part1,'/ns1:',$attribut_name,')')"/>
												</xsl:if>
									
												<!--case where a message (attribut value) and its direct parent (interfaceOperation) use prefix namespace -->
												<xsl:if test ="$level=2">
											
													    <!-- case where there are a namespace in the first part of interface operation  -->
											     	    <xsl:variable name="value_part_2"   select="concat(')xmlns(ns2=',. ,')wsdl.',$id,'(',$attribut_name_part0,'/ns1:',substring-after($attribut_name_part1,':'),'/ns2:',$attribut_name,')')"></xsl:variable>
											         	
											         	<xsl:for-each select="/wsdl:definitions/namespace::*">
											         	    <xsl:choose>
																<xsl:when test="substring-before($attribut_name_part1,':')=name()">
											         				<xsl:value-of select="concat($tnamespace,'xmlns(ns1=',. ,$value_part_2)"/>
											         			</xsl:when>
											         		</xsl:choose>
										     			</xsl:for-each>
										     		
										     	</xsl:if>
										     	<!--case where  a message (attribut value) and its parent (interface, portType) use prefix namespace -->
										       	<xsl:if test="$level=3">
													<xsl:variable name="value_part-2" select="concat(')xmlns(ns2=',. ,')wsdl.',$id,'(ns1:',substring-after($attribut_name_part0,':'),'/',$attribut_name_part1,'/ns2:',$attribut_name,')')"></xsl:variable>
											         	
											         	<xsl:for-each select="/wsdl:definitions/namespace::*">
											         	    <xsl:if test="substring-before($attribut_name_part0,':')=name()">
											         				<xsl:value-of select="concat($tnamespace,'xmlns(ns1=',. ,$value_part-2)"/>
											         		</xsl:if>
										     			</xsl:for-each>
										     	</xsl:if>
												
												<!--case where  a message (attribut value) and its both parents (interface and interfaceOperation) use prefix namespace -->
												<xsl:if test="$level=4">
													
													<xsl:variable name="value2" select="concat(')xmlns(ns3=',. ,')wsdl.',$id,'(ns1:',substring-after($attribut_name_part0,':'),'/ns2:',substring-after($attribut_name_part1,':'),'/ns3:',$attribut_name,')')"></xsl:variable>
											         	
											         	<xsl:for-each select="/wsdl:definitions/namespace::*">
											         	    <xsl:if test="substring-before($attribut_name_part1,':')=name()">
											         	        <xsl:variable name="value_part" select="concat(')xmlns(ns2=',. ,$value2)" />
											        			<xsl:for-each select="/wsdl:definitions/namespace::*">
											         	    		<xsl:if test="substring-before($attribut_name_part0,':')=name()">
											         	            	<xsl:value-of select="concat($tnamespace,'xmlns(ns1=',. ,$value_part)"/>
											         				</xsl:if>
										     					</xsl:for-each>
											         		</xsl:if>
										     			</xsl:for-each>
										     	</xsl:if>
										</xsl:when>
										
										<xsl:when test='$id="binding"'>
											<xsl:value-of select="concat($tnamespace,'xmlns(ns1=',. ,')wsdl.',$id,'(ns1:',$attribut_name,')')"></xsl:value-of>
										</xsl:when>
										
										<xsl:when test='$id="bindingOperation"'>
										                <!-- case where only a message (attribut value) use a prefix namespace -->
										       			<xsl:if test="$level=1">
															<xsl:value-of select="concat($tnamespace,'xmlns(ns1=',. ,')wsdl.',$id,'(',$attribut_name_part1,'/ns1:',$attribut_name,')')"/>
														</xsl:if>
											
														<!-- case where a message (attribut value) and its direct parent (interfaceOperation) use prefix namespace -->
														<xsl:if test ="$level=2">
																 <xsl:variable name="value_part2b"   select="concat(')xmlns(ns2=',. ,')wsdl.',$id,'(ns1:',substring-after($attribut_name_part1,':'),'/ns2:',$attribut_name,')')"></xsl:variable>
													         	<xsl:for-each select="/wsdl:definitions/namespace::*">
													         	    <xsl:choose>
																		<xsl:when test="substring-before($attribut_name_part1,':')=name()">
													         				<xsl:value-of select="concat($tnamespace,'xmlns(ns1=',. ,$value_part2b)"/>
													         			</xsl:when>
													         		</xsl:choose>
												     			</xsl:for-each>
												     	</xsl:if>
										</xsl:when>
									</xsl:choose>
								<!-- end of a case where we detect a prefix used by attribut value -->
								</xsl:when>
							 </xsl:choose>
						<!-- end of search a namespace used by attribut value or there parents --> 
						</xsl:for-each>
						
					<!-- end of a case where the value of attribut has a prefix  --> 
			        </xsl:when>
			        <!-- case where the value of attribut hasn't a prefix  --> 
					<xsl:otherwise>
			            <xsl:choose>
									<xsl:when test="$id='service' or $id='typeDefinition'">
										<xsl:value-of select="concat($tnamespace,'wsdl.',$id,'(',$id_value,')')"/>
									</xsl:when>
									
									<xsl:when test='$id="interface"'>
										<xsl:value-of select="concat($tnamespace,'wsdl.',$id,'(',$id_value,')')"/>
									</xsl:when>
									
									<xsl:when test='$id="interfaceFault"'>
										<xsl:value-of select="concat($tnamespace ,'wsdl.',$id,'(',parent::*/@name,'/',@name,')')"/>
									</xsl:when>
									
									<xsl:when test="$id='interfaceOperation' or $id='endpoint'">
										<!-- No attribut value uses a prefix namespace -->
										<xsl:if test="$level=1">
													<xsl:value-of select="concat($tnamespace,'wsdl.',$id,'(',$attribut_name_part1,'/',$id_value,')')"/>
										</xsl:if>
											
										<!-- case where a direct parent of attribut (interfaceOperation) contain a prefix namespace -->
										<xsl:if test ="$level=2">
											
								     	    <xsl:for-each select="/wsdl:definitions/namespace::*">
								         	    <xsl:choose>
													<xsl:when test="substring-before($attribut_name_part1,':')=name()">
														<xsl:variable name="value_part2i"   select="concat('xmlns(ns1=',. ,')wsdl.',$id,'(ns1:',substring-after($attribut_name_part1,':'),'/',$id_value,')')"></xsl:variable>
								         	       		<xsl:value-of select="concat($tnamespace,$value_part2i)"/>
								         			</xsl:when>
								         		</xsl:choose>
							     			</xsl:for-each>
											     		
										</xsl:if>
									</xsl:when>
					
									
									<xsl:when test="$id='interfaceMessageReference' or $id='bindingMessageReference'">
					                   	<!--case where no attribut value uses a prefix namespace -->
						               	<xsl:if test="$level=1">
						   
											<xsl:value-of select="concat($tnamespace ,'wsdl.',$id,'(',$attribut_name_part0,'/',$attribut_name_part1,'/',$id_value,')')"/>
									   	</xsl:if>
							
										<!-- case where only a direct parent (interfaceOperation) of a message (attribut value) use a prefix namespace -->
										<xsl:if test ="$level=2">
									
											<!-- case where there are a namespace in interface operation  -->
									     	  	<xsl:for-each select="/wsdl:definitions/namespace::*">
									         	    	<xsl:if test="substring-before($attribut_name_part1,':')=name()">
									         				<xsl:value-of select="concat($tnamespace,'xmlns(ns1=',. ,')wsdl.',$id,'(',$attribut_name_part0,'/ns1:',substring-after($attribut_name_part1,':'),'/',$id_value,')')"/>
									         			</xsl:if>
								     			</xsl:for-each>
								     		
								     	</xsl:if>
								     	<!--case where only a parent (interface) of a message (attribut value) use a prefix namespace -->
								     	
								     	<xsl:if test="$level=3">
								     	
												<xsl:for-each select="/wsdl:definitions/namespace::*">
									         	    <xsl:if test="substring-before($attribut_name_part0,':')=name()">
									         				<xsl:value-of select="concat($tnamespace,'xmlns(ns1=',. ,')wsdl.',$id,'(ns1:',substring-after($attribut_name_part0,':'),'/',$attribut_name_part1,'/',$id_value,')')"/>
									         		</xsl:if>
									         		
								     			</xsl:for-each>
								     	</xsl:if>
										<!-- case where a direct parent of message (interfaceOperation) and its parent (interface or portType) use prefix namespace -->										
										<xsl:if test="$level=4">
										
												<xsl:for-each select="/wsdl:definitions/namespace::*">
									         	    <xsl:if test="substring-before($attribut_name_part1,':')=name()">
									         	        <xsl:variable name="value_l4" select="concat(')xmlns(ns2=',.,')wsdl.',$id,'(ns1:',substring-after($attribut_name_part0,':'),'/ns2:',substring-after($attribut_name_part1,':'),'/',$id_value,')')" />
									        			<xsl:for-each select="/wsdl:definitions/namespace::*">
									         	    		<xsl:if test="substring-before($attribut_name_part0,':')=name()">
									         	            	<xsl:value-of select="concat($tnamespace,'xmlns(ns1=',. ,$value_l4)"/>
									         				</xsl:if>
								     					</xsl:for-each>
									         		</xsl:if>
								     			</xsl:for-each>
								     	</xsl:if>
								    </xsl:when>
										
									<xsl:when test='$id="binding"'>
										<xsl:value-of select="concat($tnamespace,'wsdl.',$id,'(',$id_value,')')"/>
									</xsl:when>
									
									<xsl:when test='$id="bindingOperation"'>
										
										<!--case where no attribut value uses a prefix namespace -->
					    				<xsl:if test="$level=1">
											<xsl:value-of select="concat($tnamespace,'wsdl.',$id,'(',$attribut_name_part1,'/',$id_value,')')"/>
										</xsl:if>
							
										<!-- case where only a direct parent (interfaceOperation) of a message (attribut value) use a prefix namespace -->
										<xsl:if test ="$level=2">
											<!-- case where there are a namespace in the first part of interface operation  -->
									     	<xsl:for-each select="/wsdl:definitions/namespace::*">
									         	    <xsl:choose>
														<xsl:when test="substring-before($attribut_name_part1,':')=name()">
															<xsl:variable name="value_part2bo"   select="concat('xmlns(ns1=',. ,')wsdl.',$id,'(ns1:',substring-after($attribut_name_part1,':'),'/',$id_value,')')"></xsl:variable>
									         	       		<xsl:value-of select="concat($tnamespace,$value_part2bo)"/>
									         			</xsl:when>
									         		</xsl:choose>
								     		</xsl:for-each>
								     	</xsl:if>
								     	
									</xsl:when>
								</xsl:choose>
			        <!-- end of a case where the value of attribut hasn't a prefix  -->	
			        </xsl:otherwise>
	</xsl:choose>
</xsl:template>

<!-- To transform a definitions of WSDL to rdf form in the output -->
<xsl:template match="wsdl:definitions | wsdl:description">
			
			<rdf:RDF xmlns="http://www.w3.org/2005/10/wsdl-rdf/" >
					<!-- target a namespace of service -->
					<xsl:variable name="service_namespace_prefix" select="'xmlns:serv'" />
					<xsl:attribute name= "{$service_namespace_prefix}" > 
  						<xsl:value-of select="$tnamespace"/>
					</xsl:attribute>
				
 					<Description rdf:about="">
						<xsl:apply-templates select="wsdl:service" />
						<xsl:apply-templates select="wsdl:portType | wsdl:interface"/>
						<xsl:apply-templates select="wsdl:binding"/>
					</Description>
			</rdf:RDF>
</xsl:template>

<!-- To transform a service declaration to rdf form in the output -->
<xsl:template match="wsdl:service" >
<service>
	<Service>
		<xsl:attribute name="rdf:about"  >
			   <xsl:call-template name="construct_attribut">
			    <xsl:with-param name="id">service</xsl:with-param>
			     <xsl:with-param name="id_value"><xsl:value-of select='@name'/></xsl:with-param>
			   </xsl:call-template>
		</xsl:attribute>
  		<xsl:for-each select="@interface" >
  				<xsl:element name='{name()}'>
  					<xsl:attribute name="rdf:resource">
	  					<xsl:call-template name="construct_attribut">
				   		 	<xsl:with-param name="id">interface</xsl:with-param>
				   		 	<xsl:with-param name="id_value"><xsl:value-of select='.'/></xsl:with-param>
				   		</xsl:call-template>
  						
  					</xsl:attribute>
  				</xsl:element>
   		</xsl:for-each>
   		
   		<!-- To transform endpoint/port of service to rdf form in the output -->
   		<endpoint>
  	 		<xsl:for-each select="wsdl:port | wsdl:endpoint" >
  				<Endpoint>
  					<xsl:attribute name="rdf:about">
  												<xsl:choose>
  					   	 							<xsl:when test="contains(parent::*/@name,':')">		 					
			 		 									<xsl:call-template name="construct_attribut">
						    								<xsl:with-param name="id">endpoint</xsl:with-param>
						     								<xsl:with-param name="id_value"><xsl:value-of select='@name'/></xsl:with-param>
						  						   			 <xsl:with-param name="level">2</xsl:with-param>
						  								</xsl:call-template>
						  							 </xsl:when>
						  							 <xsl:otherwise>
						  								<xsl:call-template name="construct_attribut">
						    								<xsl:with-param name="id">endpoint</xsl:with-param>
						     								<xsl:with-param name="id_value"><xsl:value-of select='@name'/></xsl:with-param>
						     								<xsl:with-param name="level">1</xsl:with-param>
						     							</xsl:call-template>
						  							</xsl:otherwise>
			 		 							</xsl:choose>
  					    
  					</xsl:attribute>
  					
   					<xsl:for-each select="@binding" >
  						<usesBinding>
  							<xsl:attribute name="rdf:resource">
  								<xsl:call-template name="construct_attribut">
			    					<xsl:with-param name="id">binding</xsl:with-param>
			     					<xsl:with-param name="id_value"><xsl:value-of select='.'/></xsl:with-param>
			  					 </xsl:call-template>
	   						</xsl:attribute>
    					</usesBinding>
    				</xsl:for-each>
  					<!-- To transform location of service to rdf form in the output -->
  					<xsl:for-each select="address |soap:address" >
  						<address>
  							<xsl:attribute name="rdf:resource">
    							<xsl:value-of select='@location'/>
    						</xsl:attribute>
    					</address>
   					</xsl:for-each>
  				</Endpoint>
  			</xsl:for-each>
  		</endpoint>
  </Service>
</service>
</xsl:template>

<!-- To transform a portype/interface declaration to rdf form in the output -->
<xsl:template match="wsdl:portType | wsdl:interface">
		<!-- target a Model Reference of semantic annotation service -->
		<xsl:variable name='sawsdl_mR_portType' select="@sawsdl:modelReference"></xsl:variable>
		<interface>
 			<Interface>
 				<xsl:attribute name="rdf:about">
 						<xsl:call-template name="construct_attribut">
				   		 	<xsl:with-param name="id">interface</xsl:with-param>
				   		 	<xsl:with-param name="id_value"><xsl:value-of select='@name'/></xsl:with-param>
				   		</xsl:call-template>
  				</xsl:attribute>
 		 		
				<!--To transform a extension of interface (from wsdl 2.0 specification) to rdf form in the output -->
 		 		<xsl:for-each select="@extends">
 		 		  <xsl:if test ="@extends">
 	 				<extends>
  						<xsl:attribute name="rdf:resource">
  							<xsl:call-template name="construct_attribut">
				   		 		<xsl:with-param name="id">interface</xsl:with-param>
				   		 		<xsl:with-param name="id_value"><xsl:value-of select='.'/></xsl:with-param>
				   			</xsl:call-template>
 		 				</xsl:attribute>
  					</extends>
  				  </xsl:if>
 				</xsl:for-each>
 				
 				<xsl:for-each select="@sawsdl:modelReference">
 		 			<xsl:element name='sawsdl:modelReference'>
 		 				<xsl:attribute name="rdf:resource">
 		 					<xsl:value-of select="$sawsdl_mR_portType"/>
 		 				</xsl:attribute>
 		 			</xsl:element>
 		 		</xsl:for-each>
 		 		
				<!-- To transform an operation service to rdf form in the output -->
 				 <interfaceOperation>
 					<xsl:for-each select="wsdl:operation" >
 					<xsl:variable name='sawsdl_mR_operation' select="@sawsdl:modelReference"/>
 						<InterfaceOperation>
  								<xsl:attribute name="rdf:about">
  											<xsl:choose>
			 		 								 <xsl:when test="contains(parent::*/@name,':')">		 					
			 		 									<xsl:call-template name="construct_attribut">
						    								<xsl:with-param name="id">interfaceOperation</xsl:with-param>
						     								<xsl:with-param name="id_value"><xsl:value-of select='@name'/></xsl:with-param>
						  						   			 <xsl:with-param name="level">2</xsl:with-param>
						  								</xsl:call-template>
						  							 </xsl:when>
						  							 <xsl:otherwise>
						  								<xsl:call-template name="construct_attribut">
						    								<xsl:with-param name="id">interfaceOperation</xsl:with-param>
						     								<xsl:with-param name="id_value"><xsl:value-of select='@name'/></xsl:with-param>
						     								<xsl:with-param name="level">1</xsl:with-param>
						     							</xsl:call-template>
						  							</xsl:otherwise>
			 		 							</xsl:choose>
  								</xsl:attribute>
  								
  								<!-- target a Model Reference of semantic annotation service -->
 		 						
 		 									<xsl:for-each select="@sawsdl:modelReference">
 		 										<xsl:element name='sawsdl:modelReference'>
 		 											<xsl:attribute name="rdf:resource">
 		 												<xsl:value-of select="$sawsdl_mR_operation"/>
 		 											</xsl:attribute>
 		 										</xsl:element>
 		 									</xsl:for-each>
 		 					
  								
 		 						<!-- To transform an input of operation service to rdf form in the output -->
 		 						<interfaceMessageReference>
    						 		<xsl:for-each select="wsdl:input">
    						 		<xsl:variable name='sawsdl_mR_input' select="@sawsdl:modelReference"/>
 		 							  <xsl:if test ="@message | @element | @name">
 										<InputMessage>
 											<xsl:attribute name="rdf:about">
 													<xsl:choose>
 													 
 													 <!-- case where both parents of attribut (interface,interfaceOperation) contain a prefix namespace -->
			 		 								 <xsl:when test="contains(parent::*/parent::*/@name,':') and contains(parent::*/@name,':') ">
			 		 								 		<xsl:call-template name="construct_attribut">
						    									<xsl:with-param name="id">interfaceMessageReference</xsl:with-param>
						     									<xsl:with-param name="id_value"><xsl:value-of select='@message | @element'/></xsl:with-param>
						  						   			 	<xsl:with-param name="level">4</xsl:with-param>
						  									</xsl:call-template>
						  							
			 		 								 </xsl:when>
			 		 								
			 		 								 <!-- case where a parent of attribut (interface) contains a prefix namespace -->
			 		 								 <xsl:when test="contains(parent::*/parent::*/@name,':') and not(contains(parent::*/@name,':')) ">		 					
			 		 										<xsl:call-template name="construct_attribut">
						    									<xsl:with-param name="id">interfaceMessageReference</xsl:with-param>
						     									<xsl:with-param name="id_value"><xsl:value-of select='@message | @element'/></xsl:with-param>
						  						   			 	<xsl:with-param name="level">3</xsl:with-param>
						  									</xsl:call-template>
						  							 </xsl:when>
						  							
						  							 <!-- case where a direct parent of attribut (interfaceOperation) contains a prefix namespace -->
						  							 <xsl:when test="not(contains(parent::*/parent::*/@name,':')) and contains(parent::*/@name,':') ">		 					
			 		 										<xsl:call-template name="construct_attribut">
						    									<xsl:with-param name="id">interfaceMessageReference</xsl:with-param>
						     									<xsl:with-param name="id_value"><xsl:value-of select='@message | @element'/></xsl:with-param>
						  						   			 	<xsl:with-param name="level">2</xsl:with-param>
						  									</xsl:call-template>
						  							 </xsl:when> 					
			 		 								
			 		 								 <!-- case where no parents of attribut (interface and interfaceOperation) contain a prefix namespace -->
						  							 <xsl:otherwise>
						  								<xsl:call-template name="construct_attribut">
						    								<xsl:with-param name="id">interfaceMessageReference</xsl:with-param>
						     								<xsl:with-param name="id_value"><xsl:value-of select='@message | @element'/></xsl:with-param>
						     								<xsl:with-param name="level">1</xsl:with-param>
						     							</xsl:call-template>
						  							</xsl:otherwise>
			 		 							</xsl:choose>
  													<!--xsl:value-of select="concat($tnamespace,'wsdl.interfaceMessageReference(',parent::*/parent::*/@name,'/',parent::*/@name,'/',@message | @element,')')"/-->
 		 									</xsl:attribute>
 		 									<!-- target a Model Reference of semantic annotation service -->
 		 									
 		 									<xsl:for-each select="@sawsdl:modelReference">
 		 										<xsl:element name='sawsdl:modelReference'>
 		 											<xsl:attribute name="rdf:resource">
 		 												<xsl:value-of select="$sawsdl_mR_input"/>
 		 											</xsl:attribute>
 		 										</xsl:element>
 		 									</xsl:for-each>
 		 									<!-- target a label of message (input message) -->
 		 									<xsl:if test ="@messageLabel | @name">
 		 									<xsl:variable name='message_label' select='@name | @messageLabel'/>
 		 									<xsl:for-each select="@name | @messageLabel">
 		 										<messageLabel>
 		 											<xsl:attribute name="rdf:resource">
 		 												<xsl:value-of select="$message_label"/>
  													</xsl:attribute>
 		 										</messageLabel>
 		 									</xsl:for-each>
 		 									</xsl:if>
 		 								</InputMessage>
 		 							  </xsl:if>
									</xsl:for-each>
									</interfaceMessageReference>
									<!-- To transform an output of operation service to rdf form in the output -->
									<interfaceMessageReference>
									<xsl:for-each select="wsdl:output">
									  <xsl:if test ="@message | @element | @name">
 										<OutputMessage>
 											<xsl:attribute name="rdf:about">
 												<xsl:choose>
 													
 													 <!-- case where both parents of attribut (interface and interfaceOperation) contain a prefix namespace -->
			 		 								 <xsl:when test="contains(parent::*/parent::*/@name,':') and contains(parent::*/@name,':') ">
			 		 								 		<xsl:call-template name="construct_attribut">
						    									<xsl:with-param name="id">interfaceMessageReference</xsl:with-param>
						     									<xsl:with-param name="id_value"><xsl:value-of select='@message | @element'/></xsl:with-param>
						  						   			 	<xsl:with-param name="level">4</xsl:with-param>
						  									</xsl:call-template>
						  							
			 		 								 </xsl:when>
			 		 								
			 		 								 <!-- case where no parents of attribut (interface and interfaceOperation) contain a prefix namespace -->
			 		 								 <xsl:when test="contains(parent::*/parent::*/@name,':') and not(contains(parent::*/@name,':')) ">		 					
			 		 										<xsl:call-template name="construct_attribut">
						    									<xsl:with-param name="id">interfaceMessageReference</xsl:with-param>
						     									<xsl:with-param name="id_value"><xsl:value-of select='@message | @element'/></xsl:with-param>
						  						   			 	<xsl:with-param name="level">3</xsl:with-param>
						  									</xsl:call-template>
						  							 </xsl:when>
						  							
						  							 <!-- case where a direct parent of attribut (interfaceOperation) contain a prefix namespace -->
						  							 
						  							 <xsl:when test="not(contains(parent::*/parent::*/@name,':')) and contains(parent::*/@name,':') ">		 					
			 		 										<xsl:call-template name="construct_attribut">
						    									<xsl:with-param name="id">interfaceMessageReference</xsl:with-param>
						     									<xsl:with-param name="id_value"><xsl:value-of select='@message | @element'/></xsl:with-param>
						  						   			 	<xsl:with-param name="level">2</xsl:with-param>
						  									</xsl:call-template>
						  							 </xsl:when> 					
			 		 							
			 		 								 <!-- case where no parents of attribut (interface and interfaceOperation) contain a prefix namespace -->
												 	 <xsl:otherwise>
						  								<xsl:call-template name="construct_attribut">
						    								<xsl:with-param name="id">interfaceMessageReference</xsl:with-param>
						     								<xsl:with-param name="id_value"><xsl:value-of select='@message | @element'/></xsl:with-param>
						     								<xsl:with-param name="level">1</xsl:with-param>
						     							</xsl:call-template>
						  							 </xsl:otherwise>
			 		 							</xsl:choose>
  											</xsl:attribute>
  											
 		 									<!-- target a Model Reference of semantic annotation service -->
 		 									<xsl:variable name='sawsdl_mR_output' select="@sawsdl:modelReference"/>
 		 									<xsl:for-each select="@sawsdl:modelReference">
 		 										<xsl:element name='sawsdl:modelReference'>
 		 											<xsl:attribute name="rdf:resource">
 		 												<xsl:value-of select="$sawsdl_mR_output"/>
 		 											</xsl:attribute>
 		 										</xsl:element>
 		 									</xsl:for-each>

 		 									<!-- target a label of message (output message) -->
 		 									<xsl:if test ="@messageLabel | @name">
	 		 									<xsl:variable name='message_label' select='@name | @messageLabel'/>
	 		 									<xsl:for-each select="@name | @messageLabel">
	 		 										<messageLabel>
	 		 											<xsl:attribute name="rdf:resource">
	 		 												<xsl:value-of select="$message_label"/>
	  													</xsl:attribute>
	 		 									    </messageLabel>
	 		 									</xsl:for-each>
	 		 								 </xsl:if>
										</OutputMessage>
									  </xsl:if>
									</xsl:for-each>
    						 	</interfaceMessageReference>
    						 	
    						 	<!-- To transform a pattern used in operation service to rdf form in the output -->
    						 	<xsl:if test="@pattern">
	    						 	<messageExchangePattern>
	    						 		<xsl:attribute name="rdf:resource">
	  										<xsl:value-of select='@pattern'/>
	 		 							</xsl:attribute>
	    						 	</messageExchangePattern>
    						 	</xsl:if>
    						 	
    						 	<!-- To transform a style used in operation service to rdf form in the output -->
    						 	<xsl:if test="@style">
	    						 	<operationStyles>
	    						 		<xsl:attribute name="rdf:resource">
	  										<xsl:value-of select='@style'/>
	 		 							</xsl:attribute>
	    						 	</operationStyles>
    						 	</xsl:if>
    					</InterfaceOperation>
    				</xsl:for-each>
  				 </interfaceOperation>
  				 
  				 <!-- To transform an fault portType/interface service to rdf form in the output -->
  				 <xsl:for-each select="wsdl:fault">
  				 <interfaceFault>
  				 		<xsl:attribute name="rdf:resource">
  				 		        <xsl:call-template name="construct_attribut">
				   		 				<xsl:with-param name="id">interfaceFault</xsl:with-param>
				   		 				<xsl:with-param name="id_value"><xsl:value-of select='@name'/></xsl:with-param>
				   				</xsl:call-template>
  								
 		 				</xsl:attribute>
 		 				
 		 				<!-- target a Model Reference of semantic annotation service -->
 		 				<xsl:variable name='sawsdl_mR_fault' select="@sawsdl:modelReference"/>
 		 				<xsl:for-each select="@sawsdl:modelReference">
 		 							<xsl:element name='sawsdl:modelReference'>
 		 								<xsl:attribute name="rdf:resource">
 		 									<xsl:value-of select="$sawsdl_mR_fault"/>
 		 								</xsl:attribute>
 		 							</xsl:element>
 		 				</xsl:for-each>
  				   </interfaceFault>
  				 </xsl:for-each>
  			</Interface>
  			</interface>
</xsl:template>

<!-- To transform a service binding to rdf form in the output -->
<xsl:template match="wsdl:binding">
         <binds>
	 		<Binding>
 				<xsl:attribute name="rdf:about">
 					<xsl:call-template name="construct_attribut">
			    			<xsl:with-param name="id">binding</xsl:with-param>
			     			<xsl:with-param name="id_value"><xsl:value-of select='@name'/></xsl:with-param>
			  		</xsl:call-template>
  				</xsl:attribute>
 		 		
 		 		<!-- To transform a type of binding to rdf form in the output -->
 		 		<xsl:if test="@type">
	 		 		<rdf:type>
	 		 			<xsl:attribute name="rdf:resource">
										<xsl:call-template name="construct_attribut">
	   										<xsl:with-param name="id">typeDefinition</xsl:with-param>
	    									<xsl:with-param name="id_value"><xsl:value-of select='@type'/></xsl:with-param>
		 								</xsl:call-template>
	  					</xsl:attribute>
	 		 		</rdf:type>
 		 		</xsl:if>
 		 		<!-- To transform an operation binding to rdf form in the output -->
 		 		<bindingOperation>
 		 			<xsl:for-each select="wsdl:operation">
 		 				<BindingOperation>
	 		 			
	 		 						 <xsl:attribute name="rdf:about">
			 		 						
			 		 						<xsl:choose>
			 		 								 <xsl:when test="contains(parent::*/@name,':')">		 					
			 		 									<xsl:call-template name="construct_attribut">
						    								<xsl:with-param name="id">bindingOperation</xsl:with-param>
						     								<xsl:with-param name="id_value"><xsl:value-of select='@name |@ref '/></xsl:with-param>
						  						   			 <xsl:with-param name="level">2</xsl:with-param>
						  								</xsl:call-template>
						  							 </xsl:when>
						  							 <xsl:otherwise>
						  								<xsl:call-template name="construct_attribut">
						    								<xsl:with-param name="id">bindingOperation</xsl:with-param>
						     								<xsl:with-param name="id_value"><xsl:value-of select='@name |@ref '/></xsl:with-param>
						     								<xsl:with-param name="level">1</xsl:with-param>
						     							</xsl:call-template>
						  							</xsl:otherwise>
			 		 						</xsl:choose>
			 		 				 </xsl:attribute>
		 		 	
 		 					<!-- target an operation name in binding message reference -->
 		 					<xsl:variable name='bmessage_reference' select="concat(parent::*/@name,'/',@name| @ref)"/>
 		 					
 		 						<!-- case of input wsdl message -->
 		 						<bindingMessageReference>
 		 						    
    						 		<xsl:for-each select="wsdl:input">
    						 		   <xsl:if test ="@message | @element | @name">
 										<InputMessage>
 												
 											<xsl:attribute name="rdf:about">
 											   <xsl:choose>
 												
 													 <!-- case where both parents of attribut (interface and interfaceOperation) contain a prefix namespace -->
						  							 <xsl:when test="contains(parent::*/parent::*/@name | parent::*/parent::*/@ref  ,':') and contains(parent::*/@name | parent::*/@ref,':') ">
			 		 								 		<xsl:call-template name="construct_attribut">
						    									<xsl:with-param name="id">bindingMessageReference</xsl:with-param>
						     									<xsl:with-param name="id_value"><xsl:value-of select='@name | @element | @message'/></xsl:with-param>
						  						   			 	<xsl:with-param name="level">4</xsl:with-param>
						  									</xsl:call-template>
						  		
			 		 								 </xsl:when>
			 		 						
			 		 								 <!-- case where a parent of attribut (interface ) contains a prefix namespace -->
						 							 <xsl:when test="contains(parent::*/parent::*/@name | parent::*/parent::*/@ref ,':') and not(contains(parent::*/@ref | parent::*/@name,':')) ">		 					
			 		 										<xsl:call-template name="construct_attribut">
						    									<xsl:with-param name="id">bindingMessageReference</xsl:with-param>
						     									<xsl:with-param name="id_value"><xsl:value-of select='@name | @element | @message'/></xsl:with-param>
						  						   			 	<xsl:with-param name="level">3</xsl:with-param>
						  									</xsl:call-template>
						  							 </xsl:when>
						  						
						  							  <!-- case where a parent of attribut (interfaceOperation) contains a prefix namespace -->
						  							 <xsl:when test="not(contains(parent::*/parent::*/@name | parent::*/parent::*/@ref,':')) and contains(parent::*/@name | parent::*/@ref,':') ">		 					
			 		 										<xsl:call-template name="construct_attribut">
						    									<xsl:with-param name="id">bindingMessageReference</xsl:with-param>
						     									<xsl:with-param name="id_value"><xsl:value-of select='@name | @element | @message'/></xsl:with-param>
						  						   			 	<xsl:with-param name="level">2</xsl:with-param>
						  									</xsl:call-template>
						  							 </xsl:when> 					
			 		 								
			 		 								 <!-- case where no parents of attribut (interface and interfaceOperation) contain a prefix namespace -->
						  							 <xsl:otherwise>
						  								<xsl:call-template name="construct_attribut">
						    								<xsl:with-param name="id">bindingMessageReference</xsl:with-param>
						     								<xsl:with-param name="id_value"><xsl:value-of select='@name | @element | @message'/></xsl:with-param>
						     								<xsl:with-param name="level">1</xsl:with-param>
						     							</xsl:call-template>
						  							</xsl:otherwise>
			 		 							</xsl:choose>
			 		 						  
 		 									</xsl:attribute>
 		 									
 		 									
 		 									<!-- target a label of message (input message) -->
 		 									<xsl:if test ="@messageLabel | @name">
	 		 									<xsl:variable name='message_label' select='@name | @messageLabel'/>
	 		 									<xsl:for-each select="@name | @messageLabel">
	 		 										<messageLabel>
	 		 											<xsl:attribute name="rdf:resource">
	 		 												<xsl:value-of select="$message_label"/>
	  													</xsl:attribute>
	 		 										</messageLabel>
	 		 									</xsl:for-each>
 		 									</xsl:if>
										</InputMessage>
									  </xsl:if>
									</xsl:for-each>
									</bindingMessageReference>
									
									<!-- case of output wsdl message -->
									<bindingMessageReference>
									<xsl:for-each select="wsdl:output">
									  <xsl:if test ="@message | @element | @name">
 										<OutputMessage>
 										  	<xsl:attribute name="rdf:about">
 												   
 												   <xsl:choose>
 													
 													 <!-- case where both parents of attribut (interface and interfaceOperation) contain a prefix namespace -->
						  							 <xsl:when test="contains(parent::*/parent::*/@name | parent::*/parent::*/@ref ,':') and contains(parent::*/@ref | parent::*/@name,':') ">
			 		 								 		<xsl:call-template name="construct_attribut">
						    									<xsl:with-param name="id">bindingMessageReference</xsl:with-param>
						     									<xsl:with-param name="id_value"><xsl:value-of select='@message | @element | @name'/></xsl:with-param>
						  						   			 	<xsl:with-param name="level">4</xsl:with-param>
						  									</xsl:call-template>
						  							
			 		 								 </xsl:when>
			 		 								 
			 		 								 <!-- case where a parent of attribut (interface) contains a prefix namespace -->
						  							 <xsl:when test="contains(parent::*/parent::*/@name | parent::*/parent::*/@ref ,':') and not(contains(parent::*/@ref | parent::*/@name ,':')) ">		 					
			 		 										<xsl:call-template name="construct_attribut">
						    									<xsl:with-param name="id">bindingMessageReference</xsl:with-param>
						     									<xsl:with-param name="id_value"><xsl:value-of select='@message | @element | @name'/></xsl:with-param>
						  						   			 	<xsl:with-param name="level">3</xsl:with-param>
						  									</xsl:call-template>
						  							 </xsl:when>
						  						
						  							 <!-- case where a parent of attribut (interfaceOperation) contains a prefix namespace -->
						  							 <xsl:when test="not(contains(parent::*/parent::*/@name | parent::*/parent::*/@ref ,':')) and contains(parent::*/@ref | parent::*/@name ,':') ">		 					
			 		 										<xsl:call-template name="construct_attribut">
						    									<xsl:with-param name="id">bindingMessageReference</xsl:with-param>
						     									<xsl:with-param name="id_value"><xsl:value-of select='@message | @element | @name'/></xsl:with-param>
						  						   			 	<xsl:with-param name="level">2</xsl:with-param>
						  									</xsl:call-template>
						  							 </xsl:when> 					
			 		 								
			 		 								  <!-- case where no parents of attribut (interface and interfaceOperation) contain a prefix namespace -->
						  							 <xsl:otherwise>
						  								<xsl:call-template name="construct_attribut">
						    								<xsl:with-param name="id">bindingMessageReference</xsl:with-param>
						     								<xsl:with-param name="id_value"><xsl:value-of select='@message | @element | @name'/></xsl:with-param>
						     								<xsl:with-param name="level">1</xsl:with-param>
						     							</xsl:call-template>
						  							</xsl:otherwise>
			 		 							</xsl:choose>
			 		 						  
  											   </xsl:attribute>
 		 									
 		 									
 		 									<!-- target a label of message (output message) -->
 		 									<xsl:if test ="@messageLabel | @name">
 		 										<xsl:variable name='message_label' select='@name | @messageLabel'/>
 		 										<xsl:for-each select="@name | @messageLabel">
 		 											<messageLabel>
 		 												<xsl:attribute name="rdf:resource">
 		 													<xsl:value-of select="$message_label"/>
  														</xsl:attribute>
 		 											</messageLabel>
 		 										</xsl:for-each>
 		 									</xsl:if>
 		 									
 		 								  </OutputMessage>
 		 								</xsl:if>
 		 								</xsl:for-each>
 		 							</bindingMessageReference>
 		 				 </BindingOperation>
 		 			</xsl:for-each>
 		 		</bindingOperation>
			</Binding>
		</binds>
</xsl:template>

</xsl:stylesheet>
