|
Subject: RE: [xsl] Dynamic Menu Using XSL (Example) From: Michael Sell <msell@xxxxxxxxxxxxxxx> Date: Wed, 13 Dec 2006 17:37:25 +1100 |
function transformXML(xmlDocURL, xslDocURL, divID)
{
// declare the local variables
var xmlDoc, xslDoc, docProcessor, docCache, DocRequest, docFragment;
// try the following
try
{
// instantiate and load the xml document
xmlDoc = new ActiveXObject("MSXML2.DOMDocument");
xmlDoc.async = false;
xmlDoc.load(xmlDocURL);
// instantiate and load the xsl document
xslDoc = new ActiveXObject("MSXML2.FreeThreadedDOMDocument");
xslDoc.async = false;
xslDoc.load(xslDocURL);
// prepare the xsl document for transformation
docCache = new ActiveXObject("MSXML2.XSLTemplate");
docCache.stylesheet = xslDoc;
// instantiate the document processor and submit the xml document
docProcessor = docCache.createProcessor();
docProcessor.input = xmlDoc;
// add parameters to the xsl document
docProcessor.addParameter("book", getCookie("book"), "");
docProcessor.addParameter("category", getCookie("category"), "");
docProcessor.addParameter("keyword", getCookie("keyword"), "");
docProcessor.addParameter("sort", getCookie("sort"), "");
docProcessor.addParameter("status", getCookie("status"), "");
docProcessor.addParameter("topic", getCookie("topic"), "");
docProcessor.addParameter("view", getCookie("view"), "");
// process the documents into html and submit to the passed div box
docProcessor.transform();
// divID.innerHTML = docProcessor.output;
document.getElementById(divID).innerHTML = docProcessor.output;
}
// catch any errors from the above code
catch(e)
{
// try the following
try
{
// instantiate and load the xml document
docRequest = new XMLHttpRequest();
docRequest.open("GET", xmlDocURL, false);
docRequest.send(null);
xmlDoc = docRequest.responseXML;
// instantiate and load the xsl document
docRequest = new XMLHttpRequest();
docRequest.open("GET", xslDocURL, false);
docRequest.send(null);
xslDoc = docRequest.responseXML;
// instantiate the document processor and submit the xsl document
docProcessor = new XSLTProcessor();
docProcessor.importStylesheet(xslDoc);
// add parameters to the xsl document
docProcessor.setParameter(null, "book", getCookie("book"));
docProcessor.setParameter(null, "category", getCookie("category"));
docProcessor.setParameter(null, "keyword", getCookie("keyword"));
docProcessor.setParameter(null, "sort", getCookie("sort"));
docProcessor.setParameter(null, "status", getCookie("status"));
docProcessor.setParameter(null, "topic", getCookie("topic"));
docProcessor.setParameter(null, "view", getCookie("view"));
// clear the passed div if anything was in it
document.getElementById(divID).innerHTML = "";
// process the documents into html and submit to the passed div
docFragment = docProcessor.transformToFragment(xmlDoc, document);
document.getElementById(divID).appendChild(docFragment);
}
// catch any errors from the above code
catch(e)
{
// do nothing
}
}
}
----- Original Message ---- From: Michael Kay <mike@xxxxxxxxxxxx> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx Sent: Monday, December 11, 2006 3:47:42 PM Subject: RE: [xsl] Dynamic Menu Using XSL
So are you saying you want to invoke a client-side transformation that changes the page in response to user input? That's doable, but we need to understand your processing model. The main issue with client-side transformation is making it work cross-browser - again, that's doable, but one needs to understand the requirements so that you can use the right API.
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| RE: [xsl] XSL limitations?, Michael Kay | Thread | [xsl] XSL FO Table formatting, Dave Dran |
| RE: [xsl] XSL limitations?, Michael Kay | Date | [xsl] XSL FO Table formatting, Dave Dran |
| Month |