Visualizzazione dei risultati da 1 a 2 su 2
  1. #1

    XslProcessor + dom->load()

    Allora, la classe:
    Codice PHP:
    class taskManager {

        private 
    $dom;
        private 
    $xmlHandler;
        private 
    $xslHandler;
        private 
    $output;

        public function 
    __construct() {
            
    $this->dom = new DOMDocument();
            
    $section = (!isset($_GET['x'])) ? 'index' trim($_GET['x']);
            if (
    $this->__loadXmlDoc($section) && $this->__loadXslDoc($section)) {
                
    $processor = new XsltProcessor();
                
    $processor->importStylesheet($this->xslHandler);
                
    $this->output $processor->transformToDoc($this->xmlHandler);
                } else {
                
    //i file che vuoi caricare non esistono!!!
                
    throw new Exception('Error - You are trying to process the wrong section for your site!!!');
            }
        }

        private function 
    __loadXmlDoc($section) {
            
    $file DIR_PATH '/content/' $section '.xml';
            if (
    $this->xmlHandler $this->dom->load($file)) {
                return 
    TRUE;
            }
            return 
    FALSE;
        }

        private function 
    __loadXslDoc($section) {
            
    $file DIR_PATH '/structure/' $section '.xsl';
            if (
    $this->xslHandler $this->dom->load($file)) {
                return 
    TRUE;
            }
            return 
    FALSE;
        }

        public function 
    __showXML() {
            return 
    $this->output->saveXML();
        }

    Classe molto semplice e di facile comprensione, spero.. Prendi tramite GET il nome della sezione da caricare e in teoria, carica l'xml e l'xsl correto della sezione per poi ritornarle a browser..
    L'unico problema è che:

    Codice PHP:
    $this->xmlHandler $this->dom->load($file
    mi restituisce, come giusto, TRUE (1 booleano) cosa che però non va bene con
    Codice PHP:
    $processor->importStylesheet($this->xslHandler); 
    perche questo metodo vuole un'oggetto in input e non un valore booleano..

    Come risolvo questo problema?? Ho provato con:

    Codice PHP:
    $this->xmlHandler &= $this->dom->load($file
    ma non ho avuto molta fortuna.. anzi l'errore scompare ma se ne creano altri tipo "Error - You are trying to process the wrong section for your site!!!" come se non trovasse/caricasse nessun file..

    Se qualcuno ha qualche spunto ben venga...
    Questa volta, più che un voto.. è favoreggiamento.

  2. #2
    Problema risolto, ho eseguito una chiamata statica al metodo load() della classe DOMDocument()... In questo modo mi carica i fogli come DOMDocument e non come valore booleano e cosi il processore Xslt esegue la trasformazione..

    Se vi interessa la classe basta chiedere.. peccato non mi legga Xsl 2.0
    Questa volta, più che un voto.. è favoreggiamento.

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.