ankursaxena
October 24th, 2003, 11:23 AM
Hi I have an XML file with many sets of tables each with an id by a unique name. Now I was wondering is there a way to use this XML file like a database and display the correct table. eg In my main HTML file i will have links like
Patek
Lange
Rolex
etc. By clicking the correct link it should open a new page and display the table correcsponding to the id here..
how should i do this without a server side script or anything..i am currently putting and testing something on my comcast website and they dont allow me to run any server side scripts. please help..that would be great.
thanx a ton.
Ankur
khp
October 25th, 2003, 12:34 AM
You should be able to do much of what you want, using xslt and javascripts, running on the client side.
The main drawback with a clientside approach is that it requires that the browser supports xslt and javascript/vbscript.
The simplest way to preform an xslt transformation on an xml file is to stick a processing instruction like this in the header of the xml file
<?xml-stylesheet href="template.xsl" type="text/xsl"?>
And then load the xml file directly into the browser, this approach is supported by netscape7(mozilla1.0) and later, and IE6.
And of course this has the slight drawback, that you can only define one view of the xml file this way. Which according to your posting isn't quite what you want.
To let us apply any number of different xslt stylesheets to an xml file, we need to do some scripting, on the clientside, this limits us to javascript and vbscript. I have no clue how to do this in vbscript. But here's how it's done in javascript
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript">
//<![CDATA[
var xmlfile = "template.xml";
var xslfile = "template.xsl";
var xmldone = 0;
function onload_ ()
{
xml = document.implementation.createDocument("","",null);
xsl = document.implementation.createDocument("","",null);
xml.onload = xml_loaded;
xsl.onload = xml_loaded;
xml.load(xmlfile);
xsl.load(xslfile);
}
function xml_loaded ()
{
xmldone++;
if (xmldone > 1)
{
var xmltransformed = document.implementation.createDocument("","",null);
xsltProcessor = new XSLTProcessor();
xsltProcessor.transformDocument( xml, xsl, xmltransformed, null);
document.getElementById("output").appendChild(xmltransformed.documentElement);
}
}
//]]>
</script>
<title>XSLT Transformation</title>
</head>
<body id="body" onLoad="onload_()">
<div id="output">
</div>
</body>
</html>
This javascripted html page will load the xmlfile and xslt file define by the variables at the top of the code, apply the stylesheet to the xml page and display the results. This works in Netscape7(mozilla1.0) and later. I'am not sure about IE6, but I suspect that it won't work.
To lean more about xml/xslt and get more details on IE support for xslt you might want to visit www.w3schools.com