0
My codeはmysqlデータセットからxml出力を作成します。それから私はそれをHTMLに変換する必要があります。私はPHP変数に保存し、パラメータとしてtransformToXML($ XML)で使用しようとしましたが、ここでオブジェクトが必要です。このxml出力をここでパラメータとして使用するオブジェクトに変換するにはどうすればよいですか。あなたはそれを使用することができます前に、DOMDocument::loadXML()
経由でオブジェクトに戻ってあなたのXML文字列をオンにする必要がありますxsl変換でパラメータとしてXML文字列を使用/変換する方法
<?php
// i am using the resultset to build an XML DOM but you can do whatever you like with it !
header("Content-type: text/xml");
$conn = new mysqli("localhost", "babar", "k4541616", "spec", 3306);
// one non-recursive db call to get the 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 and build the DOM
while($row = $result->fetch_assoc()){
$msg = $xml->createElement("message");
foreach($row as $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 i 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 an object here, string given.
?>
どうすれば使用できますか? – XCeptable
もしあなたが好きなのであれば、 'save()'メソッドを呼び出すことができます。リンクを参照してください。 –
実際にどこで使うべきか尋ねたいですか?最後の行で結果を印刷することを意味するならば、 "print $ xslt-> transformToDoc($ save)"と同じ結果を使用します。または、以前にxmlをdomdocに変換するために使用すると言いますか? – XCeptable