Warning: include(/var/www/syscpwebs/web15/html/stats/php-stats.redir.php) [function.include]: failed to open stream: No such file or directory in /home/garetjax/webapps/garetjax_old/docs/tpl/xslt/doc.php on line 42

Warning: include() [function.include]: Failed opening '/var/www/syscpwebs/web15/html/stats/php-stats.redir.php' for inclusion (include_path='.:/usr/local/lib/php') in /home/garetjax/webapps/garetjax_old/docs/tpl/xslt/doc.php on line 42

Documentazione Template.php

In questa pagina cercherò di spiegare il funzionamento della classe Template, basata su XSLT.

Più che una guida vera e propria, questa pagina, sarà una raccolta di esempi che verranno aggiunti a mano a mano qualora lo si riterrà necessario.

Indice

  1. Quick start
  2. Business logic
  3. Presentation logic

Quick start

Directory structure

web/ index.php lib/ Template.php views/ index.xsl

index.php

<?php

require 'library/Template.php';

$view = new Template();

// Assegno bar alla variabile foo
$view->assign('foo''bar');

// Sintassi alternativa
$view->title 'Example';

if (!isset(
$_GET['debug'])) {
    
// Visualizzo il risultato
    
echo $view->render('views/index.xsl');
} else {
    
// Oppure visualizzo l'albero xml (debug)
    
echo $view->render();
}

index.xsl

<?xml version="1.0" encoding="utf-8"?>
<xsl:transform version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<!-- Formattazione output -->
<xsl:output
    method="xml"
    omit-xml-declaration="yes"
    encoding="utf-8"
    doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"
    doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
    indent="yes"
    media-type="text/html"/>

<!-- Punto d'entrata -->
<xsl:template name="general" match="/">
    <html xml:lang="it" lang="it">
        <head>
            <title><xsl:value-of select="title"/></title>
        </head>
        
        <body>
            <!-- Richiamo la variabile -->
            <p><xsl:value-of select="foo"/></p>
        </body>
    </html>
</xsl:template>

</xsl:transform>

Risultato

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="it" lang="it">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Example</title>
  </head>
  <body>
    <p>bar</p>
  </body>
</html>

Business logic

File d'esempio