﻿<?xml version="1.0" encoding="utf-8" ?> 
<Template Title = "XSL Transformer">
	<import-xml src = "Templates/TemplateTools.xml" id = "TemplateTools" />
	<div>XML</div>
	<textarea style = "height:100px;width:95%;font: normal 8pt courier;" wrap="off" rid="oXmlSource">
	</textarea>
	<div>XSL</div>
	<textarea style = "height:100px;width:95%;font: normal 8pt courier;" wrap="off" rid="oXslSource">
	</textarea>
	<div>
	<input type = "button" value = "Test" onclick = "${this}.Test()" />
	<input type = "button" value = "Transform" onclick = "${this}.Transform()" />
	</div>
	<textarea style = "height:100px;width:95%;font: normal 8pt courier;" wrap="off" rid="oResults">
	</textarea>
	<embedded-script><![CDATA[
		embedded_init : function(){
			this.GetElementByRID("oXmlSource").value = "<?xml version=\"1.0\" encoding=\"utf-8\" ?> \n<Root />";
			this.GetElementByRID("oXslSource").value = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n"
				+ "<xsl:stylesheet version=\"2.0\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\" >\n"
				+ "<xsl:output omit-xml-declaration = \"yes\" />\n"
				+ "<xsl:template match=\"/Root\">\n"
				+ "Root!\n"
				+ "</xsl:template>\n"
				+ "</xsl:stylesheet>\n"
			;
		},
		Test : function(){
			var oX = org.cote.js.xml.parseXmlDocument(this.TrimSafe(this.GetElementByRID("oXmlSource").value));
			var oXS = org.cote.js.xml.parseXmlDocument(this.TrimSafe(this.GetElementByRID("oXslSource").value));
			this.GetElementByRID("oResults").value = 
				"XML : " + (oX != null && oX.documentElement != null ? true :false) + "\n"
				+ "XSL : " + (oXS != null && oXS.documentElement != null ? true : false)
			;
		},
		Transform : function(){
			var oX = org.cote.js.xml.parseXmlDocument(this.TrimSafe(this.GetElementByRID("oXmlSource").value).replace(/\t/gi,"    "));
			var oXS = org.cote.js.xml.parseXmlDocument(this.TrimSafe(this.GetElementByRID("oXslSource").value.replace(/\t/gi,"    ")));
			var oR = org.cote.js.xml.transformNode(oX, oXS, 0, 0, 0, 0, 1);
			var s = "";
			this.GetElementByRID("oResults").value = oR;
		}
	]]></embedded-script>
</Template>
