XSLTProcessor::transformToDoc

ドキュメント に変換する

説明

public DOMDocumentfalse XSLTProcessor::transformToDoc(object $document, stringnull $returnClass = null)

XSLTProcessor::importStylesheet メソッドで与えられたスタイルシートを適用し、 ソースノードをドキュメント (例: DOMDocument) に変換します。

パラメータ

document

変換される DOMDocumentSimpleXMLElement、または 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!

参考

  • XSLTProcessor::transformToUri
  • XSLTProcessor::transformToXml