Datasheet
It is transformed with the XSLT transformation format.xsl and the result is sent to the browser:
$xsltSource = new DOMDocument();
$xsltProc = new XSLTProcessor();
$xsltSource->load(‘format.xsl’);
$xsltProc->importStyleSheet($xsltSource);
header(“Cache-Control: max-age=60”);
header(“Content-type: text/html”);
print $xsltProc->transformToXML($document);
To manipulate XSLT client side in a consistent way between different browsers, you need a JavaScript
API such as Sarissa. The principle is the same, except that you can load the transformation at load time
and keep the
XSLTProcessor object to reuse it several times. You can load the transformation asyn-
chronously like any other XML resource. The request is initiated by the following instruction in
controller.js:
YAHOO.util.Connect.asyncRequest(‘GET’, “format.xsl”, this.xsltCallback);
And the result is kept to be used when needed:
BuzzWatchController.prototype.handleXSLTSuccess = function(o) {
if(o.responseText !== undefined){
this.xsltDom = o.responseXML;
}
}
XSLT processors are created and initialized with the XSLT transformation by the following statements:
var processor = new XSLTProcessor();
processor.importStylesheet(this.xsltDom);
The different callbacks that receive XML to update a panel can then be replaced by a generic one that
uses such a XSLT processor in
panel.js:
BuzzWatchPanel.prototype.handleSuccess = function(o) {
if(o.responseText !== undefined){
this.isEmpty = false;
this.setTimeout(getMaxAge(o));
var processor = YAHOO.buzzWatch.controller.getXSLTProcessor();
var result = processor.transformToDocument(o.responseXML);
YAHOO.buzzWatch.controller.returnXSLTProcessor(processor);
var o = document.getElementById(this.name);
var n = document.importNode(result.documentElement, true);
o.parentNode.replaceChild(n, o);
this.panelConfig = this.panel.cfg.getConfig();
this.panel.init(this.name, this.panelConfig);
this.panel.render();
}
}
32
Chapter 1
04_087889 ch01.qxp 5/2/07 12:56 PM Page 32