XML + XSL in a Client Browser
-
Hi guys, Usually I use XSL to transform XML at the server-side with ASP.NET. I have recently found out that it is possible to specify a stylesheet at the top of an XML file. The web browser then uses the XSL document to render the XML file. I came across several websites which say that there is lack of browser support, but they were quite old. I have tested a simple scenario in IE7, IE8 BETA, Chrome, FF3, and Safari and it seems to work wonders. So I didn't know whether there were any more subtle issues, or compatibility problems. Are there any issues with this approach? Ideally I wanted to have the client browser do the transforms to ease the load at the server-side. Many thanks, Lea Hayes
-
Hi guys, Usually I use XSL to transform XML at the server-side with ASP.NET. I have recently found out that it is possible to specify a stylesheet at the top of an XML file. The web browser then uses the XSL document to render the XML file. I came across several websites which say that there is lack of browser support, but they were quite old. I have tested a simple scenario in IE7, IE8 BETA, Chrome, FF3, and Safari and it seems to work wonders. So I didn't know whether there were any more subtle issues, or compatibility problems. Are there any issues with this approach? Ideally I wanted to have the client browser do the transforms to ease the load at the server-side. Many thanks, Lea Hayes
lhayes00 wrote:
So I didn't know whether there were any more subtle issues, or compatibility problems.
There certainly can be, I imagine. This is awkward since I detest assumptions, however given the history of browser compatibility it's likely a safe one.
lhayes00 wrote:
Are there any issues with this approach?
Obviously, the more basic your XML-XSLT is the less likely any problems will surface. Conversely.... well I think you get the idea, yes?
led mike
-
Hi guys, Usually I use XSL to transform XML at the server-side with ASP.NET. I have recently found out that it is possible to specify a stylesheet at the top of an XML file. The web browser then uses the XSL document to render the XML file. I came across several websites which say that there is lack of browser support, but they were quite old. I have tested a simple scenario in IE7, IE8 BETA, Chrome, FF3, and Safari and it seems to work wonders. So I didn't know whether there were any more subtle issues, or compatibility problems. Are there any issues with this approach? Ideally I wanted to have the client browser do the transforms to ease the load at the server-side. Many thanks, Lea Hayes
I'm not sure which browsers other than IE support embedded XSLT documents, meaning they automatically do the transformation. However you can do the transformation using javascript and write out the result using the .innerHTML property. This is especially useful when creating Ajax style interfaces. The code looks something like this:
var xmlDoc = new ActiveXObject("Msxml2.DOMDocument");
xmlDoc.async = false;
xmlDoc.load("doc.xml")var xslDoc = new ActiveXObject("Msxml2.DOMDocument");
xslDoc.async = false;
xslDoc.load(Server.MapPath("doc.xsl"));myDiv.innerHTML = xmlDoc.transformNode(xslDoc);
For cross-browser support you will need to modify the line of code where you create the Xml document because different browsers handle it differently.
-
I'm not sure which browsers other than IE support embedded XSLT documents, meaning they automatically do the transformation. However you can do the transformation using javascript and write out the result using the .innerHTML property. This is especially useful when creating Ajax style interfaces. The code looks something like this:
var xmlDoc = new ActiveXObject("Msxml2.DOMDocument");
xmlDoc.async = false;
xmlDoc.load("doc.xml")var xslDoc = new ActiveXObject("Msxml2.DOMDocument");
xslDoc.async = false;
xslDoc.load(Server.MapPath("doc.xsl"));myDiv.innerHTML = xmlDoc.transformNode(xslDoc);
For cross-browser support you will need to modify the line of code where you create the Xml document because different browsers handle it differently.