Do method chaining with PHP is easy. But I need something like this,
$xml = $dom->transformToThis('file1.xsl')->transformToThis('file2.xsl')->saveXML();
or
$books = $dom->
transformToThis('file1.xsl')->
transformToThis('file2.xsl')->
getElementsByTagName('book');
It is possible with PHP's DOMDocument or DOMNode?
class DOMxx extends DOMDocument {
public function __construct() {
parent::__construct("1.0", "UTF-8");
}
function trasformToThis($xslfile) {
$xsldom = new DOMDocument('1.0', 'UTF-8');
$xsldom->load($xslfile);
$xproc = new XSLTProcessor();
$xproc->importStylesheet($xsldom);
$this = $xproc->transformToDoc($this); // ERROR!
return $this;
}
} // class
The $this = X
is a invalid construct in PHP, and I not understand the workaround explained here. I can use something like $this->loadXML( $xproc->transformToDoc($this)->saveXML() );
but it is a big overload, and the question is about how to do the correct thing.
Another (wrong) way to try to implement,
function trasformToThis($xslfile) {
... same ...
return $xproc->transformToDoc($this); // lost trasformToThis() method
}
so, in this case the question is "How to cast to DOMxx?".