downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

XSLTProcessor::transformToUri> <XSLTProcessor::setProfiling
Last updated: Fri, 13 Nov 2009

view this page in

XSLTProcessor::transformToDoc

(PHP 5)

XSLTProcessor::transformToDocDOMDocument に変換する

説明

DOMDocument transformToDoc ( DOMNode $doc )

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

パラメータ

doc

変換されるノードを指定します。

返り値

結果の DOMDocument 。 エラーが発生した場合は 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!

参考



add a note add a note User Contributed Notes
XSLTProcessor::transformToDoc
franp at free dot fr
31-Aug-2006 12:16
In most cases if you expect XML (or XHTML) as output you better use transformToXML() directly. You gain better control over xsl:output attributes, notably omit-xml-declaration.

Instead of :
$proc = new XSLTProcessor();
$proc->importStylesheet($xsl);
$dom = $proc->transformToDoc($xml);
echo $dom->saveXML();

do use :
$proc = new XSLTProcessor();
$proc->importStylesheet($xsl);
$newXml = $proc->transformToXML($xml);
echo $newXml;

In the first case, <?xml version="1.0" encoding="utf-8"?> is added whatever you set the omit-xml-declaration while transformToXML() take the attribute into account.

 
show source | credits | sitemap | contact | advertising | mirror sites