Index: /DCWoRMS/branches/coolemall/src/test/DEBBTranslator/xml/PLMXMLTranslator.xsl
===================================================================
--- /DCWoRMS/branches/coolemall/src/test/DEBBTranslator/xml/PLMXMLTranslator.xsl	(revision 946)
+++ /DCWoRMS/branches/coolemall/src/test/DEBBTranslator/xml/PLMXMLTranslator.xsl	(revision 949)
@@ -17,4 +17,7 @@
 	<xsl:param name="resourceUnitClasses" select="resourceUnitClasses" />
 
+	<!-- Information from which level the translator should start moving information to templates -->
+	<xsl:variable name="templateStartLevel" select="'Node'" />
+
 	<!-- Specification of the output document -->
 	<xsl:output method="xml" version="1.0" encoding="UTF-8"
@@ -31,5 +34,6 @@
 	<xsl:template match="/">
 		<xsl:element name="environment">
-			<xsl:attribute name="xsi:noNamespaceSchemaLocation">DCWormsResSchema.xsd</xsl:attribute>
+			<xsl:attribute name="xsi:noNamespaceSchemaLocation">../DCWormsResSchema.xsd</xsl:attribute>
+			
 			<xsl:element name="resources">
 				<!-- Iterate the document, create hierarchy and "links" to templates -->
@@ -40,8 +44,10 @@
 			</xsl:element>
 			
-			<xsl:element name="templates">
-				<!-- Iterate the document and createTemplates -->
-				<xsl:apply-templates select="//plm:InstanceGraph" mode="createTemplates"/>
-			</xsl:element>
+			<xsl:if test="fun:containsTemplates()">
+				<xsl:element name="templates">
+					<!-- Iterate the document and createTemplates -->
+					<xsl:apply-templates select="//plm:InstanceGraph" mode="createTemplates"/>
+				</xsl:element>			
+			</xsl:if>
 			
 		</xsl:element>
@@ -55,5 +61,5 @@
 
 	<xsl:template match="plm:InstanceGraph" mode="createTemplates">
-		<xsl:apply-templates select="plm:ProductRevisionView" mode="createTemplates"/>
+		<xsl:apply-templates select="//plm:ProductRevisionView[plm:UserData/plm:UserValue/@title='DEBBLevel' and plm:UserData/plm:UserValue/@value=$templateStartLevel]" mode="createTemplates"/>
 	</xsl:template>
 
@@ -68,4 +74,9 @@
 				<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]" />-->
+				<xsl:apply-templates select="//plm:ProductRevisionView[@id=$productInstanceId]" mode="createHierarchy"/>
 
 				<!-- Add hostnames, labels, locations, sequences, etc. -->
@@ -109,12 +120,5 @@
 						</xsl:element>
 					</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:if>				
 			</xsl:element>
 		</xsl:if>
@@ -134,17 +138,26 @@
 			select="plm:UserData/plm:UserValue[@title='DEBBComponentId']/@value" />
 	
-		<xsl:element name="templateId">
+		<xsl:attribute name="class">
 			<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:attribute>
+		
+		<xsl:choose>
+			<xsl:when test="$debbLevel = $templateStartLevel">
+				<!-- Change into template. The rest of the hierarchy will be in template. -->
+				<xsl:element name="templateId">
+					<xsl:value-of select="$debbLevel"/>
+					<xsl:text>-</xsl:text>
+					<xsl:value-of select="$debbComponentId"/>
+				</xsl:element>		
+			</xsl:when>
+			<xsl:otherwise>
+				<!-- 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:otherwise>
+		</xsl:choose>
 	</xsl:template>
 	
@@ -341,4 +354,8 @@
 		
 	
+	<xsl:function name="fun:containsTemplates">
+		<xsl:variable name="productRevisionViews" select="$rootDoc//plm:ProductRevisionView[UserData/UserValue/@DEBBLevel=$templateStartLevel]"/>
+		<xsl:value-of select="count($productRevisionViews) > 0"/>
+	</xsl:function>	
 	
 </xsl:stylesheet>
