Part of the EllisLab Network
   
 
XSLT as templating instead the normal view
Posted: 02 March 2008 12:11 PM   [ Ignore ]  
Summer Student
Total Posts:  4
Joined  03-02-2008

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:

<?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;
        
}
    }
}
?> 
Profile
 
 
Posted: 02 March 2008 08:33 PM   [ Ignore ]   [ # 1 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  593
Joined  02-04-2008

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.

$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.

Profile
 
 
Posted: 03 March 2008 03:24 AM   [ Ignore ]   [ # 2 ]  
Summer Student
Total Posts:  4
Joined  03-02-2008

It’s a PHP 4 code not PHP5
http://il2.php.net/xslt_create
“(PHP 4 >= 4.0.3)”

Profile
 
 
Posted: 03 March 2008 03:40 AM   [ Ignore ]   [ # 3 ]  
Summer Student
Total Posts:  4
Joined  03-02-2008

I got the following error:

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?

Profile
 
 
Posted: 03 March 2008 04:31 AM   [ Ignore ]   [ # 4 ]  
Sr. Research Associate
RankRankRankRankRank
Total Posts:  4785
Joined  07-14-2006

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?

Profile
 
 
Posted: 03 March 2008 09:26 AM   [ Ignore ]   [ # 5 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  593
Joined  02-04-2008

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.

Profile
 
 
   
 
 
‹‹ Parser Static Helper      Introducing...REST! ››