XSL import another XSL on Client-Side.
-
I try XSL Transfrom on client-side using javascript. My XSL file has a import tag in itself, but it couln't find the another XSL file. I have to excute this transform on Client-Side for some reason. How can I put the import href content Here goes my test code. this page written with .NET Javascript code on the webpage. function Transform() { var xsl = new ActiveXObject("MSXML.DOMDocument"); var xml = new ActiveXObject("MSXML.DOMDocument"); xsl.async = false; xsl.load(dataXmlPath); xsl.async = false; xsl.load(styleXslPath); var data = xml.transformNode(xsl); } number.xml (XML Data file)----------------------- <?xml version='1.0'?> <data> <circle> <radius>12</radius> </circle> <circle> <radius>37.5</radius> </circle> </data> calc.xsl (XSL Style file)------------------------ <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:include href="calc2.xsl"/> </xsl:stylesheet> calc2.xsl (XSL import file)------------------------ <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="data"> <circles> <xsl:for-each select="circle"> <circle> <xsl:copy-of select="node()"/> <circumference> <xsl:value-of select="radius"/> </circumference> </circle> </xsl:for-each> </circles> </xsl:template> </xsl:stylesheet>
-
I try XSL Transfrom on client-side using javascript. My XSL file has a import tag in itself, but it couln't find the another XSL file. I have to excute this transform on Client-Side for some reason. How can I put the import href content Here goes my test code. this page written with .NET Javascript code on the webpage. function Transform() { var xsl = new ActiveXObject("MSXML.DOMDocument"); var xml = new ActiveXObject("MSXML.DOMDocument"); xsl.async = false; xsl.load(dataXmlPath); xsl.async = false; xsl.load(styleXslPath); var data = xml.transformNode(xsl); } number.xml (XML Data file)----------------------- <?xml version='1.0'?> <data> <circle> <radius>12</radius> </circle> <circle> <radius>37.5</radius> </circle> </data> calc.xsl (XSL Style file)------------------------ <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:include href="calc2.xsl"/> </xsl:stylesheet> calc2.xsl (XSL import file)------------------------ <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="data"> <circles> <xsl:for-each select="circle"> <circle> <xsl:copy-of select="node()"/> <circumference> <xsl:value-of select="radius"/> </circumference> </circle> </xsl:for-each> </circles> </xsl:template> </xsl:stylesheet>
<script> function Transform() { var xsl = new ActiveXObject("MSXML.DOMDocument"); var xml = new ActiveXObject("MSXML.DOMDocument"); xml.async = false; xml.load("number.xml"); xsl.async = false; xsl.load("calc.xsl"); return xml.transformNode(xsl); } alert(Transform()); </script>
-
<script> function Transform() { var xsl = new ActiveXObject("MSXML.DOMDocument"); var xml = new ActiveXObject("MSXML.DOMDocument"); xml.async = false; xml.load("number.xml"); xsl.async = false; xsl.load("calc.xsl"); return xml.transformNode(xsl); } alert(Transform()); </script>
yes. it works. thank you. actually i tested with below script function in order to get a XML Object. function loadXMLDoc(filepath) { if (window.XMLHttpRequest) { xhttp=new XMLHttpRequest(); } else { xhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xhttp.open("GET",filepath,false); xhttp.send(""); return xhttp.responseXML; } I thought it's the same but it wasn't.. var xsl = new ActiveXObject("MSXML.DOMDocument"); xsl.async = false; xsl.load("calc.xsl"); this works fine.
-
yes. it works. thank you. actually i tested with below script function in order to get a XML Object. function loadXMLDoc(filepath) { if (window.XMLHttpRequest) { xhttp=new XMLHttpRequest(); } else { xhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xhttp.open("GET",filepath,false); xhttp.send(""); return xhttp.responseXML; } I thought it's the same but it wasn't.. var xsl = new ActiveXObject("MSXML.DOMDocument"); xsl.async = false; xsl.load("calc.xsl"); this works fine.
I'm glad I could help.