XSL エクステンションは、XSL の標準規格を実装したもので、 libxslt ライブラリを用いて » XSLT 変換 を行います。
このテクステンションは » http://xmlsoft.org/XSLT/ にある libxslt を使用します。 libxslt バージョン 1.1.0 以降が必要です。
PHP 5には、デフォルトでXSLエクステンションが含まれており、 configureに引数--with-xsl[=DIR] を追加することにより有効にすることができます。 DIR は libxslt をインストールしたディレクトリです。
XSLTProcessor::__construct - 新規 XSLTProcessor オブジェクトを生成する
XSLTProcessor::getParameter - パラメータの値を取得する
XSLTProcessor::hasExsltSupport - PHP が EXSLT をサポートしているかどうかを判定する
XSLTProcessor::importStylesheet - スタイルシートを取り込む
XSLTProcessor::registerPHPFunctions - XSLT 関数として PHP 関数を使用できるようにする
XSLTProcessor::removeParameter - パラメータを取り除く
XSLTProcessor::setParameter - パラメータの値を設定する
XSLTProcessor::transformToDoc - DOMDocument に変換する
XSLTProcessor::transformToURI - URI に変換する
XSLTProcessor::transformToXML - XML に変換する
このリファレンスにある多くの例は、XML ファイルと XSL ファイルの両方を必要とします。 例では、以下の内容を含む collection.xml と collection.xsl を使用します。
Example#1 collection.xml
<collection> <cd> <title>Fight for your mind</title> <artist>Ben Harper</artist> <year>1995</year> </cd> <cd> <title>Electric Ladyland</title> <artist>Jimi Hendrix</artist> <year>1997</year> </cd> </collection>
Example#2 collection.xsl
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:param name="owner" select="'Nicolas Eliaszewicz'"/> <xsl:output method="html" encoding="iso-8859-1" indent="no"/> <xsl:template match="collection"> Hey! Welcome to <xsl:value-of select="$owner"/>'s sweet CD collection! <xsl:apply-templates/> </xsl:template> <xsl:template match="cd"> <h1><xsl:value-of select="title"/></h1> <h2>by <xsl:value-of select="artist"/> - <xsl:value-of select="year"/></h2> <hr /> </xsl:template> </xsl:stylesheet>
以下の定数が定義されています。 この関数の拡張モジュールが PHP 組み込みでコンパイルされているか、 実行時に動的にロードされている場合のみ使用可能です。