Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> Dynamiczne wyświetlanie xml'a
tmk
post 21.07.2005, 00:36:41
Post #1





Grupa: Zarejestrowani
Postów: 135
Pomógł: 0
Dołączył: 15.04.2004
Skąd: w-wa

Ostrzeżenie: (0%)
-----


Witam
otrzymuję iformacje w xml'u, chciałbym je prezentować na stroniew formie HTMLowej. Czy najlepiej to robić w php korzystając z parsujących funkcji wbudowanych czy może poprostu załączać css'a lub xslt?

a przy okazji, znacie jakieś porządne materiały dotyczące XSLT? i moze ogólnie prezentowania xmla w htmlowych znacznikach

z góry dzięki
Go to the top of the page
+Quote Post
bigZbig
post 27.07.2005, 14:31:09
Post #2





Grupa: Zarejestrowani
Postów: 740
Pomógł: 15
Dołączył: 23.08.2004
Skąd: Poznań

Ostrzeżenie: (0%)
-----


Mozesz dolaczyc css albo xsl wprost - nowoczesne przegladarki powinny sobie z tym poradzic bezposrednio, ale lepszym rozwiazaniem jest dokonanie przeksztalcen w php i przesylanie do klienta wyniku w formacie html. Mozesz do tego uzyc ponizszej clasy ktora zwraca w wyniku kod html.

  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(
  24. '/_xml' => $xml,
  25. '/_xsl' =>$xsl
  26. );
  27.  
  28. $html = $this->_xsltProcess ('arg:/_xml', 'arg:/_xsl', null, $arguments);
  29.  
  30. $this->_xsltFree();
  31. return $html; 
  32. }
  33.  
  34.  function _xsltProcess($xml_arg,$xsl_arg,$xslcontainer = null,$args = null,$params = null) {
  35. // Start with preparing the arguments
  36. $xml_arg = str_replace('arg:', '', $xml_arg);
  37. $xsl_arg = str_replace('arg:', '', $xsl_arg);
  38.  
  39. // Create instances of the DomDocument class
  40. $xml = new DomDocument;
  41. $xsl = new DomDocument;
  42.  
  43. // Load the xml document and the xsl template
  44. $xml->loadXML($args[$xml_arg]);
  45. $xsl->loadXML($args[$xsl_arg]);
  46.  
  47. // Load the xsl template
  48. $this->xsltproc->importStyleSheet($xsl);
  49.  
  50. // Set parameters when defined
  51. if ($params) {
  52. foreach ($params as $param => $value) {
  53. $xsltproc->setParameter(&#092;"\", $param, $value);
  54. }
  55. }
  56.  
  57. // Start the transformation
  58. $processed = $this->xsltproc->transformToXML($xml);
  59.  
  60. // Put the result in a file when specified
  61. if ($xslcontainer) {
  62. return @file_put_contents($xslcontainer, $processed);
  63. } else {
  64. return $processed;
  65. }
  66. }
  67.  
  68. function _xsltFree() {
  69. unset($this->xsltproc);
  70. }
  71. }
  72.  
  73. $parser = new bigXslt ();
  74. $html = $parser->createHtml (&#092;"file.xml\", \"file.xsl\");
  75. ?>


--------------------
bigZbig (Zbigniew Heintze) | blog.heintze.pl
Go to the top of the page
+Quote Post
enceladus
post 27.07.2005, 16:11:26
Post #3





Grupa: Zarejestrowani
Postów: 127
Pomógł: 0
Dołączył: 19.11.2003
Skąd: Poznań

Ostrzeżenie: (0%)
-----


Zgadzam się, że najlepiej przekształcić do HTML-a po stronie serwera, ale nie wiem czy php jest najwydajniejszym rozwiązaniem. Istnieją metody realizujące to na poziomie samego serwera WWW. Np przez:
Modxslt: http://www.mod-xslt2.com/
AxKit: http://www.axkit.org/
mod_publisher: http://apache.webthing.com/mod_publisher/
i wiele innych rozwiązań ....


--------------------
Enceladus
Warsztat: bez warsztatu
Aktua
Go to the top of the page
+Quote Post

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

 



RSS Wersja Lo-Fi Aktualny czas: 25.04.2024 - 11:45