Index: main/trunk/greenstone3/web/interfaces/default/js/debug_scripts.js
===================================================================
--- main/trunk/greenstone3/web/interfaces/default/js/debug_scripts.js	(revision 27154)
+++ main/trunk/greenstone3/web/interfaces/default/js/debug_scripts.js	(revision 27163)
@@ -549,4 +549,7 @@
 			_vEditor.selectRootElement();
 
+			_vEditor.setFileLocation(location);
+			_vEditor.setFileName(fileName);
+
 			if(!_isVisualEditor)
 			{
@@ -604,4 +607,34 @@
 			_greenbug.changeCurrentTemplate(location, fileName, nodename, namespace, name, match);
 		});
+	}
+	
+	//Turns a filename into it's location (i.e. interface/site/collection) and name
+	this.fileNameToLocationAndName = function(filepath)
+	{
+		var location;
+		var fileName;
+		//Use the filepath to work out where this file is from
+		if(filepath.search(/[\/\\]interfaces[\/\\]/) != -1)
+		{
+			location = "interface";
+			fileName = filepath.replace(/.*[\/\\]transform[\/\\]/, "");
+		}
+		else if(filepath.search(/[\/\\]sites[\/\\].*[\/\\]collect[\/\\].*[\/\\]etc[\/\\]/) != -1)
+		{
+			location = "collectionConfig";
+			fileName = filepath.replace(/.*[\/\\]sites[\/\\].*[\/\\]collect[\/\\].*[\/\\]etc[\/\\]/, "");
+		}
+		else if(filepath.search(/[\/\\]sites[\/\\].*[\/\\]collect[\/\\].*[\/\\]transform[\/\\]/) != -1)
+		{
+			location = "collection";
+			fileName = filepath.replace(/.*[\/\\]sites[\/\\].*[\/\\]collect[\/\\].*[\/\\]transform[\/\\]/, "");
+		}
+		else if(filepath.search(/[\/\\]sites[\/\\].*[\/\\]transform[\/\\]/) != -1)
+		{
+			location = "site";
+			fileName = filepath.replace(/.*[\/\\]sites[\/\\].*[\/\\]transform[\/\\]/, "");
+		}
+		
+		return {location:location, filename:fileName};
 	}
 
@@ -668,27 +701,5 @@
 					var match = $(this).attr("match");
 
-					var location;
-					var fileName;
-					//Use the filepath to work out where this file is from
-					if(filepath.search(/[\/\\]interfaces[\/\\]/) != -1)
-					{
-						location = "interface";
-						fileName = filepath.replace(/.*[\/\\]transform[\/\\]/, "");
-					}
-					else if(filepath.search(/[\/\\]sites[\/\\].*[\/\\]collect[\/\\].*[\/\\]etc[\/\\]/) != -1)
-					{
-						location = "collectionConfig";
-						fileName = filepath.replace(/.*[\/\\]sites[\/\\].*[\/\\]collect[\/\\].*[\/\\]etc[\/\\]/, "");
-					}
-					else if(filepath.search(/[\/\\]sites[\/\\].*[\/\\]collect[\/\\].*[\/\\]transform[\/\\]/) != -1)
-					{
-						location = "collection";
-						fileName = filepath.replace(/.*[\/\\]sites[\/\\].*[\/\\]collect[\/\\].*[\/\\]transform[\/\\]/, "");
-					}
-					else if(filepath.search(/[\/\\]sites[\/\\].*[\/\\]transform[\/\\]/) != -1)
-					{
-						location = "site";
-						fileName = filepath.replace(/.*[\/\\]sites[\/\\].*[\/\\]transform[\/\\]/, "");
-					}
+					var file = _greenbug.fileNameToLocationAndName(filepath);
 
 					var infoContainer = $("<option>");
@@ -696,5 +707,5 @@
 					_elements.push(infoContainer);
 
-					addChangeEventToInfoContainer(infoContainer, fileName, location, nodename, namespace, name, match);
+					addChangeEventToInfoContainer(infoContainer, file.filename, file.location, nodename, namespace, name, match);
 
 					if(name && name.length > 0)
Index: main/trunk/greenstone3/web/interfaces/default/js/visual-xml-editor.js
===================================================================
--- main/trunk/greenstone3/web/interfaces/default/js/visual-xml-editor.js	(revision 27154)
+++ main/trunk/greenstone3/web/interfaces/default/js/visual-xml-editor.js	(revision 27163)
@@ -8,4 +8,8 @@
 	var _thisEditor = this;
 	var _greenbug;
+	
+	//Store this file's location and name
+	var _fileLocation;
+	var _fileName;
 
 	//Stores what id we are up to (used to compare VEElements)
@@ -97,4 +101,14 @@
 		}
 	};
+
+	this.setFileLocation = function(fileLocation)
+	{
+		_fileLocation = fileLocation;
+	}
+	
+	this.setFileName = function(fileName)
+	{
+		_fileName = fileName;
+	}
 
 	//Get a connection to the DebugWidget
@@ -1213,5 +1227,4 @@
 				addButton.button();
 
-				/*
 				if(_xmlNode.tagName == "xsl:call-template" && _xmlNode.getAttribute("name").length > 0)
 				{
@@ -1225,58 +1238,24 @@
 					visitTemplateOption.click(function()
 					{
-						var template = "";
-						template += '<xsl:template match="/">';
-						template +=   '<calledTemplate>';
-						var params = $(_xmlNode).children("xsl\\:with-param");
-						if(!params.length)
-						{
-							template += '<xsl:call-template name="' + _xmlNode.getAttribute("name") + '"/>';
-						}
-						else
-						{
-							template += '<xsl:call-template name="' + _xmlNode.getAttribute("name") + '">';
-							for(var i = 0; i < params.length; i++)
-							{
-								var param = params.eq(i);
-								template += "<xsl:with-param";
-								for(var j = 0; j < param[0].attributes.length; j++)
-								{
-									var attr = param[0].attributes[j];
-									template += " " + attr.name + "=\"" + attr.value + "\"";
-								}
-								template += "/>";
-							}
-							template += '</xsl:call-template>';
-						}
-						template +=   '</calledTemplate>';
-						template += '</xsl:template>';
-						template = template.replace(" ", "%20");
-						
-						var url = document.URL;
-						if(url.indexOf("?") == url.length - 1)
-						{
-							url += "ilt=" + template;
-						}
-						else if(url.indexOf("?") != -1)
-						{
-							url += "&ilt=" + template;
-						}
-						else
-						{
-							url += "?ilt=" + template;
-						}
-						
+						var url = gs.xsltParams.library_name + "?a=g&rt=r&s=ResolveCallTemplate&s1.interfaceName=" + gs.xsltParams.interface_name + "&s1.siteName=" + gs.xsltParams.site_name + "&s1.collectionName=" + gs.cgiParams.c + "&s1.fileName=" + _fileName + "&s1.templateName=" + _xmlNode.getAttribute("name");
 						$.ajax(url)
 						.success(function(response)
 						{
-							var xml = $.parseXML(response);
-							var debug = $(xml).find("calledTemplate debug");
-
-							_greenbug.changeCurrentTemplate(debug[0].getAttribute("filename"), "template", "xsl", debug[0].getAttribute("name"), null);
-							$(".gbTemplateContainer").css("border", "1px dashed #AAAAAA");
+							var startIndex = response.indexOf("<requestedTemplate>") + ("<requestedTemplate>").length;
+							var endIndex = response.indexOf("</requestedTemplate>");
+							
+							if(endIndex != -1)
+							{
+								var templateFileName = response.substring(startIndex, endIndex);
+								var file = _greenbug.fileNameToLocationAndName(templateFileName);
+								_greenbug.changeCurrentTemplate(file.location, file.filename, "template", "xsl", _xmlNode.getAttribute("name"), null);
+							}
+							else
+							{
+								_greenbug.changeCurrentTemplate("interface", "gslib.xsl", "template", "xsl", _xmlNode.getAttribute("name"), null);
+							}
 						});
 					});
 				}
-				*/
 			}
 
