Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> konwersja XML -> HTML poprzez XSL
morrison
post
Post #1





Grupa: Zarejestrowani
Postów: 117
Pomógł: 0
Dołączył: 24.05.2004
Skąd: krakow

Ostrzeżenie: (10%)
X----


jesli macie jakies doswiadczenie w tym temacie to bede wdzieczny za podpowiedzi. Zabieram sie za kolejny modul aplikacji i jeszcze nie do konca zapoznalem sie z tym, dlatego juz teraz chcialbym spytac o ewentualne sugestie. Mam okreslone pliki XML, ktore musza zostac zamienione w html. Jesli macie jakies ciekawe rozwiazania lub koncepcje to chetnie poznam.

Ponadto musze poruszyc temat edycji plikow xsl z poziomu aplikacji i mozliwosc modyfikowania tych plikow poprzez np przyciski, list rozwijane. Poza tym przy edytowaniu plikow xml musze udostepnic userowi mozliwosc sortowania wyswietlanych danych np wedlug zawartosci znacznika: <name>ktos</name>. Jak proponujecie to zrobic?

pozdr (IMG:http://forum.php.pl/style_emoticons/default/winksmiley.jpg)
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
morrison
post
Post #2





Grupa: Zarejestrowani
Postów: 117
Pomógł: 0
Dołączył: 24.05.2004
Skąd: krakow

Ostrzeżenie: (10%)
X----


Mam taki kod, ktory ma wykonac konwersję:
  1. <?php
  2. class bigXslt {
  3.  
  4.   var $xsltproc;
  5.  
  6.   function bigXslt () {
  7.     if (PHP_VERSION >= 5) {
  8.       $this->xsltproc = new XsltProcessor();
  9.     } else {
  10.       $this->xsltproc = xslt_create();
  11.     }
  12.   }
  13.  
  14.   function createHtml ($xml, $xsl) {
  15.   
  16.     $xml = (is_file($xml)) ? file_get_contents($xml) : $xml;
  17.     $xsl = (is_file($xsl)) ? file_get_contents($xsl) : $xsl;
  18.  
  19.     if ( (empty($xml) || !is_string($xml)) || (empty($xsl) || !is_string($xsl)) ) {
  20.       return false;
  21.     }
  22.   
  23.     $arguments = array('/_xml' => $xml,'/_xsl' =>$xsl);
  24.  
  25.     $html = $this->_xsltProcess ('arg:/_xml', 'arg:/_xsl', null, $arguments);
  26.  
  27.     $this->_xsltFree();
  28.     return $html;
  29.   }
  30.  
  31.    function _xsltProcess($xml_arg,$xsl_arg,$xslcontainer = null,$args = null,$params = null) {
  32.     // Start with preparing the arguments
  33.     $xml_arg = str_replace('arg:', '', $xml_arg);
  34.     $xsl_arg = str_replace('arg:', '', $xsl_arg);
  35.  
  36.     // Create instances of the DomDocument class
  37.     $xml = new DomDocument;
  38.     $xsl = new DomDocument;
  39.  
  40.     // Load the xml document and the xsl template
  41.     $xml->loadXML($args[$xml_arg]);
  42.     $xsl->loadXML($args[$xsl_arg]);
  43.  
  44.     // Load the xsl template
  45.     $this->xsltproc->importStyleSheet($xsl);
  46.  
  47.     // Set parameters when defined
  48.     if ($params) {
  49.       foreach ($params as $param => $value) {
  50.         $xsltproc->setParameter("", $param, $value);
  51.       }
  52.     }
  53.  
  54.     // Start the transformation
  55.     $processed = $this->xsltproc->transformToXML($xml);
  56.  
  57.     // Put the result in a file when specified
  58.     if ($xslcontainer) {
  59.       return @file_put_contents($xslcontainer, $processed);
  60.     } else {
  61.       return $processed;
  62.     }
  63.   }
  64.  
  65.   function _xsltFree() {
  66.     unset($this->xsltproc);
  67.   }
  68. }
  69.  
  70. $parser = new bigXslt ();
  71. $html = $parser->createHtml ("file.xml", "file.xsl");
  72.  
  73. echo $html;
  74. ?>


Jednakze wyrzuca bledy:
Kod
Warning: DOMDocument::loadXML() [function.loadXML]: XML declaration allowed only at the start of the document in Entity, line: 2 in /home/pawel/public_html/konw.php on line 41

Warning: Invalid or inclomplete context in /home/pawel/public_html/konw.php on line 55

W czym jest problem?

Ten post edytował morrison 12.11.2005, 10:31:03
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 27.12.2025 - 08:50