Php/docs/xsltprocessor.transformtoxml

提供:Dev Guides
< Php
移動先:案内検索

XSLTProcessor::transformToXml

(PHP 5, PHP 7)

XSLTProcessor::transformToXmlXML に変換する


説明

public XSLTProcessor::transformToXml ( object $document ) : string|false|null

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


パラメータ

document
変換対象となる、DOMDocument オブジェクトあるいは SimpleXMLElement オブジェクトを指定します。


返り値

変換結果の文字列。エラーが発生した場合は false


例1 文字列への変換

<?php// XML ソースをロードする$xml = new DOMDocument;$xml->load('collection.xml');$xsl = new DOMDocument;$xsl->load('collection.xsl');// 変換の設定を行う$proc = new XSLTProcessor;$proc->importStyleSheet($xsl); // XSL ルールを適用するecho $proc->transformToXML($xml);?>

上の例の出力は以下となります。


Hey! Welcome to Nicolas Eliaszewicz's sweet CD collection!

<h1>Fight for your mind</h1><h2>by Ben Harper - 1995</h2><hr>
<h1>Electric Ladyland</h1><h2>by Jimi Hendrix - 1997</h2><hr>

参考