(PHP 5, PHP 7, PHP 8)
XSLTProcessor::transformToDoc — ドキュメント に変換する
XSLTProcessor::importStylesheet() メソッドで与えられたスタイルシートを適用し、 ソースノードをドキュメント (例: DOMDocument) に変換します。
document
変換される DOMDocument、SimpleXMLElement、または libxml と互換性があるオブジェクトを指定します。
returnClass
XSLTProcessor::transformToDoc() が返すオブジェクトのクラス名を指定する、オプションのパラメータです。ここで指定するクラスは、document
と同じものか、それを継承したクラスであるべきです。
結果の ドキュメント を返します。 エラーが発生した場合は false
を返します。
例1 DOMDocument への変換
<?php
// XML ソースをロードする
$xml = new DOMDocument;
$xml->load('collection.xml');
$xsl = new DOMDocument;
$xsl->load('collection.xsl');
// 変換の設定を行う
$proc = new XSLTProcessor;
$proc->importStyleSheet($xsl); // XSL ルールを適用する
echo trim($proc->transformToDoc($xml)->firstChild->wholeText);
?>
上の例の出力は以下となります。
Hey! Welcome to Nicolas Eliaszewicz's sweet CD collection!