Welcome Guest, Not a member yet? Register   Sign In
XSLT as templating instead the normal view
#1

[eluser]nadavvin[/eluser]
Hello

I want to use XSLT as the templates since is a wide use standard.

I expanded the Loader class but from some readon is not load the XSLT file:
Code:
<?php

class MY_Loader extends CI_Loader {
    function xslt($path, $data, $return = false) {
        // Load the XML source
        $content = $this->_ci_load(array('_ci_path' => $path, '_ci_return' => true));
        if(!$content) {
            return false;
        }
        $xml = new DOMDocument;
        $xml->load($data);

        $xsl = new DOMDocument;
        $xsl->load($xslt);

        // Configure the transformer
        $proc = new XSLTProcessor;
        $proc->importStyleSheet($xsl); // attach the xsl rules


        $result = trim($proc->transformToDoc($xml)->firstChild->wholeText);
        if($return) {
            return $result;
        } else {
            echo $result;
        }
    }
}
?>
#2

[eluser]louis w[/eluser]
This might help you a little. This is an excerpt from a cms i did which used xslt as the views. This i not CI code, but can be adapted for your use:

$params['xml'] should be an xml string
$params['xsl'] should be the path to an xsl stylesheet

Hope this helps.

Code:
$xh = xslt_create();
xslt_set_encoding($xh,"ISO-8859-1");

// Take out the next two lines if you do not need a scheme handler
$sh_array = array('get_all' => 'XSLSchemeHandler');
xslt_set_scheme_handlers($xh,$sh_array);


$args = array(
    'xmldata'     => $params['xml']
    );

$result = xslt_process($xh, 'arg:/xmldata', $params['xsl'], NULL, $args);
xslt_free($xh);

PS: This is php5 only code. If you need php4 let me know, you would have to use sablotron instead of the built in transformer.
#3

[eluser]nadavvin[/eluser]
It's a PHP 4 code not PHP5
http://il2.php.net/xslt_create
"(PHP 4 >= 4.0.3)"
#4

[eluser]nadavvin[/eluser]
I got the following error:
Code:
An Error Was Encountered

Unable to load the requested file: main.xslt

I want to place the XSLT files where the view folder.

Where is search the file?

Why is it not search from the view folder if it base on the same code of the view loader code?
#5

[eluser]xwero[/eluser]
I can understand why you want to use XSLT for templating, it's very powerful and you don't have to add php code to the template but i wonder about the benchmarks. Is it faster or equal to php templating?
#6

[eluser]louis w[/eluser]
Your right, that was my php4 code, not the version for 5.

I believe that it searches off the include path for the file. You will need to put your view folder into the include path, or base it off a location already in there.




Theme © iAndrew 2016 - Forum software by © MyBB