Otóż napisałem sobie system templaków pod xsl xml i php, klasa generuje dokument xml i konwertuje go do html-a za pomoca arkusza styli xsl, ogólnie jeżeli smarty ma wyłączone cachowanie to jest nawet do 20x szybsza, ale kiedy smarty ma włączone cachowanie to po dwóch przeładowaniach wygrywa o około 2 razy. I ja mam pytanko, jak zrobić jakiś fajny system cachowania dla takiej klasy- nie proszę o rozwiązanie ale o wskazóki co i jak, bo nigdy czegoś takiego nie robiłem:
KLASA:
<?php class etpl{ private $xml; public $xml_version; public $xml_encoding; private $xsl; public $xsl_path; private function is_array_asc($array){ return true; } return false; } public function __construct($xsl=false,$xml_version=false,$xml_encoding=false){ $xml_version?$this->xml_version=$xml_version:$this->xml_version="1.0"; $xml_encoding?$this->xml_encoding=$xml_encoding:$this->xml_encoding="UTF-8"; //create DOMDocument $this->xml = new DOMDocument($this->xml_version,$this->xml_encoding); $this->xml->appendChild($this->xml->createElement('root')); } public function setTemplate($xsl){ } private function array_to_xml($key,$value){ if($this->is_array_asc($value)){ $data .= "<".$key.">"; foreach($value as $k => $v){ $data.=$this->array_to_xml($k,$v); } else{ $data.="<$k>".$v."</$k>"; } } $data .= "</".$key.">"; }else{ foreach($value as $v){ $data .= "<".$key.">"; $data.=$this->array_to_xml($k,$v); } else{ $data.="<value>".$v."</value>"; } $data .= "</".$key.">"; } } return $data; } /* settig values */ public function set($key,$value){ $documentfragment = $this->xml->createDocumentFragment(); $documentfragment->appendXML($this->array_to_xml($key,$value)); $this->xml->documentElement->appendChild($documentfragment); }else{ $this->xml->documentElement->appendChild($this->xml->createElement($key,$value)); } } public function applyTemplate(){ $xml = $this->xml; $xsl = new DomDocument; $proc = new xsltprocessor; $proc->importStyleSheet($xsl); } } ?>
Wykorzystanie plik php:
<?php $tpl = new etpl("tpl.xsl"); $tpl->set("loop",$data); $tpl->set("title","tytuł"); $tpl->applyTemplate(); ?>
Wykorzystanie plik xsl:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output method="html"/> <xsl:template match="/"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title> <xsl:value-of select="//title" /> </title> </head> <body> <xsl:for-each select="//loop"> <xsl:value-of select="value" />data<br/> </xsl:for-each> </body> </html> </xsl:template> </xsl:stylesheet>