php - How to use/convert xml string as parameter in xsl transformation -


my code builds xml output mysql dataset. need transform html. saved in php variable , tried use in transformtoxml( $xml ) parameter raises expects object here. how convert xml output object used parameter here. here code:

<?php  // using resultset build xml dom can whatever !     header("content-type: text/xml");    $conn = new mysqli("localhost", "babar", "k4541616", "spec", 3306);    // 1 non-recursive db call message tree !    $result = $conn->query("call message_hier(1)");    //--$result = $conn->query("call message_hier_all()");    $xml = new domdocument;    $xpath = new domxpath($xml);    $msgs = $xml->createelement("messages");    $xml->appendchild($msgs);    // loop , build dom    while($row = $result->fetch_assoc()){      $msg = $xml->createelement("message");      foreach($row $col => $val) $msg->setattribute($col, $val);      if(is_null($row["parent_msg_id"])){      $msgs->appendchild($msg);    }    else{      $qry = sprintf("//*[@msg_id = '%d']", $row["parent_msg_id"]);      $parent = $xpath->query($qry)->item(0);      if(!is_null($parent)) $parent->appendchild($msg);     }     }    $result->close();    $conn->close();    $save = $xml->savexml();//-> here save mxl in php var    //echo $save;     $xslt = new xsltprocessor();    $xsl = new domdocument();    $xsl->load( 'msg.xsl');    $xslt->importstylesheet( $xsl );    header('content-type: application/xml');    print $xslt->transformtoxml($save); //->error: expects object here, string given.    ?> 

you need turn xml string object via domdocument::loadxml() before can use it.


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -