Index: /DCWoRMS/branches/coolemall/src/test/DEBBTranslator/xml/PLMXMLTranslator.xsl
===================================================================
--- /DCWoRMS/branches/coolemall/src/test/DEBBTranslator/xml/PLMXMLTranslator.xsl	(revision 941)
+++ /DCWoRMS/branches/coolemall/src/test/DEBBTranslator/xml/PLMXMLTranslator.xsl	(revision 946)
@@ -1,6 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<xsl:stylesheet version="1.0"
+<xsl:stylesheet version="2.0"
 	xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:plm="http://www.plmxml.org/Schemas/PLMXMLSchema"
-	xmlns:cim="http://www.coolemall.eu/DEBBComponent" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+	xmlns:cim="http://www.coolemall.eu/DEBBComponent" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+	xmlns:fun="http://whatever">
 
 	<!-- Importing xslt for translating debb components -->
@@ -32,17 +33,30 @@
 			<xsl:attribute name="xsi:noNamespaceSchemaLocation">DCWormsResSchema.xsd</xsl:attribute>
 			<xsl:element name="resources">
-				<xsl:apply-templates select="//plm:InstanceGraph" />
+				<!-- Iterate the document, create hierarchy and "links" to templates -->
+				<xsl:apply-templates select="//plm:InstanceGraph" mode="createHierarchy"/>
+								
+				<!-- Create main scheduler -->
 				<xsl:element name="scheduler"></xsl:element>
 			</xsl:element>
+			
+			<xsl:element name="templates">
+				<!-- Iterate the document and createTemplates -->
+				<xsl:apply-templates select="//plm:InstanceGraph" mode="createTemplates"/>
+			</xsl:element>
+			
 		</xsl:element>
 	</xsl:template>
 
-	<xsl:template match="plm:InstanceGraph">
+	<xsl:template match="plm:InstanceGraph" mode="createHierarchy">
 		<!-- Finding root DEBB -->
 		<xsl:variable name="rootRef" select="@rootRefs" />
-		<xsl:apply-templates select="plm:ProductInstance[@id=$rootRef]" />
-	</xsl:template>
-
-	<xsl:template match="plm:ProductInstance">
+		<xsl:apply-templates select="plm:ProductInstance[@id=$rootRef]" mode="createHierarchy"/>
+	</xsl:template>
+
+	<xsl:template match="plm:InstanceGraph" mode="createTemplates">
+		<xsl:apply-templates select="plm:ProductRevisionView" mode="createTemplates"/>
+	</xsl:template>
+
+	<xsl:template match="plm:ProductInstance" mode="createHierarchy">
 		<xsl:variable name="partRef" select="@partRef" />
 		<!-- Get rid of # at the beginning -->
@@ -54,7 +68,4 @@
 				<xsl:attribute name="name"><xsl:value-of select="@name" /></xsl:attribute>
 
-				<!-- Find corresponding ProductRevisionView and let it translate itself -->
-				<xsl:apply-templates
-					select="//plm:ProductRevisionView[@id=$productInstanceId]" />
 
 				<!-- Add hostnames, labels, locations, sequences, etc. -->
@@ -99,12 +110,21 @@
 					</xsl:element>
 				</xsl:if>
+				
+				<!-- Find corresponding ProductRevisionView and let it translate itself -->
+<!--				<xsl:apply-templates-->
+<!--					select="//plm:ProductRevisionView[@id=$productInstanceId]" />-->
+				<xsl:apply-templates select="//plm:ProductRevisionView[@id=$productInstanceId]" mode="createHierarchy"/>
+				
+				
 			</xsl:element>
 		</xsl:if>
 	</xsl:template>
-
-	<xsl:template match="plm:ProductRevisionView">
+	
+	
+	<xsl:template match="plm:ProductRevisionView" mode="createHierarchy">
+
 		<!-- instanceRefs contain space separated ids of nested DEBBs -->
 		<xsl:variable name="tokenizedText" select="tokenize(@instanceRefs, ' ')" />
-
+	
 		<!-- DEBBLevel -->
 		<xsl:variable name="debbLevel"
@@ -113,5 +133,132 @@
 		<xsl:variable name="debbComponentId"
 			select="plm:UserData/plm:UserValue[@title='DEBBComponentId']/@value" />
-		<!-- DEBBComponentFile -->
+	
+		<xsl:element name="templateId">
+			<xsl:value-of select="$debbLevel"/>
+			<xsl:text>-</xsl:text>
+			<xsl:value-of select="$debbComponentId"/>
+		</xsl:element>
+
+		<!-- Iterate children and ask them to translate themselves -->
+		<xsl:for-each select="1 to count($tokenizedText)">
+			<xsl:variable name="index" select="." />
+			<xsl:apply-templates
+				select="$rootDoc//plm:ProductInstance[@id=$tokenizedText[$index]]" mode="createHierarchy"/>
+		</xsl:for-each>
+		
+	</xsl:template>
+	
+	<xsl:template match="plm:ProductRevisionView" mode="createTemplates">
+	
+		<xsl:variable name="debbLevel"
+			select="plm:UserData/plm:UserValue[@title='DEBBLevel']/@value" />
+			
+		<xsl:variable name="debbComponentId"
+			select="plm:UserData/plm:UserValue[@title='DEBBComponentId']/@value" />
+
+		<xsl:variable name="debbComponentFile"
+			select="plm:UserData/plm:UserValue[@title='DEBBComponentFile']/@value" />
+	
+		<xsl:if test="$debbLevel">
+			<xsl:element name="computingResourceTemplate">
+				<xsl:attribute name="name">
+					<xsl:value-of select="$debbLevel"/>
+					<xsl:text>-</xsl:text>
+					<xsl:value-of select="$debbComponentId"/>
+				</xsl:attribute>
+				<xsl:attribute name="class">
+					<xsl:value-of select="$debbLevel"/>
+				</xsl:attribute>
+				
+				<!-- Read information from DEBBComponent file -->
+		
+				<xsl:choose>
+					 <!-- DEBB Components file is defined  -->
+					<xsl:when test="$debbComponentFile != ''">
+						<xsl:comment>
+							DEBB Component file is <xsl:value-of select="$debbComponentFile" />
+						</xsl:comment>
+						<xsl:variable name="nestedDoc" select="document($debbComponentFile)" />
+					
+<!--						<xsl:value-of select="fun:translateDEBBComponent($nestedDoc, $debbComponentFile)"/>-->
+
+						<xsl:apply-templates select="$nestedDoc//*[ComponentId=$debbComponentId]">
+							<xsl:with-param name="computingResourceClasses">
+								<xsl:value-of select="$computingResourceClasses" />
+							</xsl:with-param>
+							<xsl:with-param name="resourceUnitClasses">
+								<xsl:value-of select="$resourceUnitClasses" />
+							</xsl:with-param>
+						</xsl:apply-templates>
+					
+					</xsl:when>
+					 <!-- DEBB Components file is not defined. Use default one.  -->
+					<xsl:otherwise>
+						<xsl:comment>
+							DEBB Component file is <xsl:value-of select="$defaultDEBBComponentsFileName" />
+						</xsl:comment>
+						<xsl:variable name="nestedDoc"
+							select="document($defaultDEBBComponentsFileName)" />
+		
+<!--							<xsl:value-of select="fun:translateDEBBComponent($nestedDoc, $debbComponentFile)"/>-->
+							
+						<xsl:apply-templates select="$nestedDoc//*[ComponentId=$debbComponentId]">
+							<xsl:with-param name="computingResourceClasses">
+								<xsl:value-of select="$computingResourceClasses" />
+							</xsl:with-param>
+							<xsl:with-param name="resourceUnitClasses">
+								<xsl:value-of select="$resourceUnitClasses" />
+							</xsl:with-param>
+						</xsl:apply-templates>
+		
+					</xsl:otherwise>
+				</xsl:choose>			
+			</xsl:element>
+		</xsl:if>
+	</xsl:template>
+	
+	<xsl:function name="fun:translateDEBBComponent">
+		<xsl:param name="nestedDoc"/>
+		<xsl:param name="debbComponentId"/>
+	
+		<xsl:text>BEGIN</xsl:text>
+		debbComponentId=<xsl:value-of select="$debbComponentId"/>
+		<xsl:comment>
+			<xsl:text>translateDEBBComponent(</xsl:text>
+			<xsl:value-of select="$nestedDoc/ComponentId"/>
+			<xsl:text>, </xsl:text>
+			<xsl:value-of select="$debbComponentId"/>
+			<xsl:text>)</xsl:text>
+		</xsl:comment>
+		
+		<!-- Does not work :((( -->
+		<xsl:apply-templates select="$nestedDoc//*[ComponentId=$debbComponentId]">
+			<xsl:with-param name="computingResourceClasses">
+				<xsl:value-of select="$computingResourceClasses" />
+			</xsl:with-param>
+			<xsl:with-param name="resourceUnitClasses">
+				<xsl:value-of select="$resourceUnitClasses" />
+			</xsl:with-param>
+		</xsl:apply-templates>
+
+		<xsl:text>END</xsl:text>
+	
+	
+	</xsl:function>
+	
+	<!--
+	
+	<xsl:template match="plm:ProductRevisionView" mode="createTemplates">
+		
+		 instanceRefs contain space separated ids of nested DEBBs 
+		<xsl:variable name="tokenizedText" select="tokenize(@instanceRefs, ' ')" />
+		
+		 DEBBLevel 
+		<xsl:variable name="debbLevel"
+			select="plm:UserData/plm:UserValue[@title='DEBBLevel']/@value" />
+		 DEBBComponentId 
+		<xsl:variable name="debbComponentId"
+			select="plm:UserData/plm:UserValue[@title='DEBBComponentId']/@value" />
+		 DEBBComponentFile 
 		<xsl:variable name="debbComponentFile"
 			select="plm:UserData/plm:UserValue[@title='DEBBComponentFile']/@value" />
@@ -127,7 +274,9 @@
 		</xsl:if>
 
-		<!-- Add DEBB information from DEBB Components file -->
+		
+		 Add DEBB information from DEBB Components file 
+		<xsl:attribute name="test">choose</xsl:attribute>
 		<xsl:choose>
-			<!-- DEBB Components file is defined -->
+			 DEBB Components file is defined 
 			<xsl:when test="$debbComponentFile != ''">
 				<xsl:comment>
@@ -137,13 +286,5 @@
 				<xsl:variable name="nestedDoc" select="document($debbComponentFile)" />
 				<xsl:apply-templates select="$nestedDoc//*[ComponentId=$debbComponentId]" />
-			</xsl:when>
-			<!-- DEBB Components file is not defined. Use default one. -->
-			<xsl:otherwise>
-				<xsl:comment>
-					DEBB Component file is
-					<xsl:value-of select="$defaultDEBBComponentsFileName" />
-				</xsl:comment>
-				<xsl:variable name="nestedDoc"
-					select="document($defaultDEBBComponentsFileName)" />
+
 				<xsl:apply-templates select="$nestedDoc//*[ComponentId=$debbComponentId]">
 					<xsl:with-param name="computingResourceClasses">
@@ -154,8 +295,40 @@
 					</xsl:with-param>
 				</xsl:apply-templates>
+			
+				<xsl:call-template name="translateDEBBComponent">
+					<xsl:with-param name="nestedDoc"><xsl:value-of select="$nestedDoc"/></xsl:with-param>
+					<xsl:with-param name="debbComponentId"><xsl:value-of select="$debbComponentId"/></xsl:with-param>
+				</xsl:call-template>
+			</xsl:when>
+			 DEBB Components file is not defined. Use default one. 
+			<xsl:otherwise>
+				<xsl:comment>
+					DEBB Component file is
+					<xsl:value-of select="$defaultDEBBComponentsFileName" />
+				</xsl:comment>
+				<xsl:variable name="nestedDoc"
+					select="document($defaultDEBBComponentsFileName)" />
+
+
+				<xsl:call-template name="translateDEBBComponent">
+					<xsl:with-param name="nestedDoc"><xsl:value-of select="$nestedDoc"/></xsl:with-param>
+					<xsl:with-param name="debbComponentId"><xsl:value-of select="$debbComponentId"/></xsl:with-param>
+				</xsl:call-template>
+					
+				<xsl:apply-templates select="$nestedDoc//*[ComponentId=$debbComponentId]">
+					<xsl:with-param name="computingResourceClasses">
+						<xsl:value-of select="$computingResourceClasses" />
+					</xsl:with-param>
+					<xsl:with-param name="resourceUnitClasses">
+						<xsl:value-of select="$resourceUnitClasses" />
+					</xsl:with-param>
+				</xsl:apply-templates>
+					
 			</xsl:otherwise>
 		</xsl:choose>
-
-		<!-- Iterate children and ask them to translate themselves -->
+		
+		
+
+		 Iterate children and ask them to translate themselves 
 		<xsl:for-each select="1 to count($tokenizedText)">
 			<xsl:variable name="index" select="." />
@@ -164,4 +337,9 @@
 		</xsl:for-each>
 	</xsl:template>
+	
+	-->
+		
+	
+	
 </xsl:stylesheet>
 
