phpDocumentor VFront
VFront_XML
[ class tree: VFront ] [ index: VFront ] [ all elements ]

Source for file xslparser.php

Documentation is available at xslparser.php

  1. <?php
  2. /**
  3.  * Questo parser viene utilizzato qualora si imposti la variabile
  4.  * di trasformazione XSLT lato server come true nelle variabili globali.
  5.  * 
  6.  * @desc Parser XSLT lato server
  7.  * @package VFront
  8.  * @subpackage VFront_XML
  9.  * @author M.Marcello Verona
  10.  * @copyright 2007 M.Marcello Verona
  11.  * @version 0.90
  12.  * @license http://www.gnu.org/licenses/gpl.html GNU Public License
  13.  */
  14.  
  15. if (PHP_VERSION >= 5{
  16.  
  17.     /**
  18.      * Emula la vecchia funzione di parser XSLT
  19.      *
  20.      * @return XsltProcessor 
  21.      */
  22.     function xslt_create({
  23.         return new XsltProcessor();
  24.     }
  25.  
  26.     /**
  27.      * Funzione che processa XML e XSL
  28.      *
  29.      * @desc Parser XSLT
  30.      * @param resource $xsltproc 
  31.      * @param unknown_type $xml_arg 
  32.      * @param unknown_type $xsl_arg 
  33.      * @param unknown_type $xslcontainer 
  34.      * @param unknown_type $args 
  35.      * @param unknown_type $params 
  36.      * @return unknown 
  37.      */
  38.     function xslt_process($xsltproc,
  39.                           $xml_arg,
  40.                           $xsl_arg,
  41.                           $xslcontainer null,
  42.                           $args null,
  43.                           $params null{
  44.         // Start with preparing the arguments
  45.         $xml_arg str_replace('arg:'''$xml_arg);
  46.         $xsl_arg str_replace('arg:'''$xsl_arg);
  47.  
  48.         // Create instances of the DomDocument class
  49.         $xml new DomDocument;
  50.         $xsl new DomDocument;
  51.  
  52.         // Load the xml document and the xsl template
  53.         $xml->loadXML($args[$xml_arg]);
  54.         $xsl->loadXML($args[$xsl_arg]);
  55.  
  56.         // Load the xsl template
  57.         $xsltproc->importStyleSheet($xsl);
  58.  
  59.         // Set parameters when defined
  60.         if ($params{
  61.             foreach ($params as $param => $value{
  62.                 $xsltproc->setParameter(""$param$value);
  63.             }
  64.         }
  65.  
  66.         // Start the transformation
  67.         $processed $xsltproc->transformToXML($xml);
  68.  
  69.         // Put the result in a file when specified
  70.         if ($xslcontainer{
  71.             return @file_put_contents($xslcontainer$processed);
  72.         else {
  73.             return $processed;
  74.         }
  75.  
  76.     }
  77.  
  78.     /**
  79.      * Libera le risorse utilizzate dal parser
  80.      *
  81.      * @param resource $xsltproc 
  82.      */
  83.     function xslt_free($xsltproc{
  84.         unset($xsltproc);
  85.     }
  86. }
  87.  
  88.  
  89. /**
  90.  * Funzione di parser XSLT.
  91.  * Richiede l'apertura di file remoti (allor_fopen_url = TRUE )
  92.  * 
  93.  *
  94.  * @param string $file_xml URL del file XML
  95.  * @param string $file_xsl URL del file XSL
  96.  * @return string HTML output
  97.  */
  98. function xslparser($file_xml,$file_xsl){
  99.  
  100.     $arguments array(
  101.         '/_xml' => file_get_contents($file_xml),
  102.         '/_xsl' => file_get_contents($file_xsl)
  103.     );
  104.     
  105.     $xsltproc xslt_create();
  106.     $html xslt_process(
  107.         $xsltproc,
  108.         'arg:/_xml',
  109.         'arg:/_xsl',
  110.         null,
  111.         $arguments
  112.     );
  113.  
  114.     xslt_free($xsltproc);
  115.     
  116.     return $html;
  117.  
  118. }
  119.  
  120.  
  121.  
  122.  
  123.  
  124. ?>

Documentation generated on Sat, 22 Sep 2007 11:51:59 +0200 by phpDocumentor 1.4.0a2