PHPプログラムに関する各種メモ書き

PHPでXMLのXSLT変換を行う。

XMLファイルからHTMLファイルを作成したい時、XSLTを使うと早い場合があります。

そのサンプル

<?php
$xml = new DomDocument();
$xml->load('test.xml');
$xsl = new DomDocument();
$xsl->load('sample01.xsl');
$processor = new xsltprocessor();
$processor->importStyleSheet($xsl);
echo $processor->transformToXML($xml);
?>

XSLT書式

http://vosegus.org/guideline/xslt.html

例:そのノードのテキストが hoge の場合のみ ZZZZZZZZZ を表示する

<xsl:if test="contains(./text() , 'hoge')">
ZZZZZZZZZ
</xsl:if>

襟:デフォルト値をセットする

<xsl:param name="contents">デフォルト値</xsl:param>

関連エントリー

No.741
04/08 10:00

edit

Xpath
XML