Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [XML][PHP]Przetwarzanie xml w php5
Forum PHP.pl > Forum > Przedszkole
maraska
Witam. Zmieniłem wersję php z 4 na 5 i w jednym starociu mam przetwarzanie xml'a
(to nie moje i kompletnie się na tym nie znam)
W każdym razie wywala błąd parsowania bo php5 nie ma obsługi xslt_create

Wygląda to tak:
  1. function GetHtml($xsl_path , $xml , $params = array(), $encoding="UTF-8")
  2. {
  3.  
  4. // PRZETWARZANIE XML'A ////////////////////
  5. $arg = array("/_xml" => $xml);
  6. ob_start();
  7. $xh = xslt_create(); //////////////////TU JEST BŁĄD PARSOWANIA
  8. xslt_set_encoding($xh,$encoding);
  9. eval("?>".xslt_process($xh, "arg:/_xml", $xsl_path, NULL, $arg, $params)."<?php ");
  10. $result = ob_get_contents();
  11. xslt_free($xh);
  12. ob_end_clean();
  13.  
  14. //echo $xml;
  15.  
  16. if ($result) {
  17. $result = str_replace("<br/>","<br>",$result);
  18. $result = str_replace("<br />","<br>",$result);
  19. $result = str_replace('alt="" />','alt="" >',$result);
  20. return $result;
  21. }
  22.  
  23. else
  24. { /*
  25. echo "There was an error that occurred in the XSL transformation...\n";
  26. echo "\tError number: " .$xsl_path." ". xslt_errno($xh) . "\n";
  27. echo "\tError string: " . xslt_error($xh) . "\n"; */
  28. return -1;
  29. }
  30.  
  31. }


Znalazłem takie rozwiązanie problemu

  1. This is more usefull, no files needed, it just takes XML and XSL strings as input parameters and returns transformed XML
  2.  
  3. <?php
  4. /**
  5. * @param $xml
  6. * @param $xsl
  7. * @return string xml
  8. */
  9. function transform($xml, $xsl) {
  10. $xslt = new XSLTProcessor();
  11. $xslt->importStylesheet(new SimpleXMLElement($xsl));
  12. return $xslt->transformToXml(new SimpleXMLElement($xml));
  13. }
  14. ?>


ale nie wiem jak połączyć jedno z drugim.

Uprzejmie proszę o pomoc

Nikt nie pomoże sad.gif
nospor
No a jakim masz problem z funkcja ktora sam tu wkleiles? Przyjmuje ona jako parametry xml, ktory chcesz zamienic oraz xslt, ktore mowi jak zamienic i w rezultacie daje ci wynik po zamianie. W czym problem?
maraska
Problem jest w moim zerowym ogarnianiem tematu.
Nie poradzę sobie bez przykładu połączenia tego w całość.
Dlatego proszę o pomoc

Jak jest ktoś dla kogo to Zero Problem bo wszystko jasne, to proszę pokaż jak to połączyć
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.