2010-12-15 6 views
8

私はXMLは、XSLTを使用してHTMLネストされたリストのようにしてファイルを印刷したいと思ってるし、私の知る限りでは、コードがしかし、私は意味推測このエラーPHP 5でXSLT関数を有効にするにはどうすればよいですか?

Fatal error: Call to undefined function xslt_create()

を得ている、正しいですxslt関数は有効になっていません。 PHP内でこれらの機能を有効にするにはどうすればよいですか?私は(Javascriptライブラリのように)インクルードする必要のあるPHPファイルがありますか、それとももっと複雑なものですか?私はMediaTempleでホストされています。事前に

 <?php 

    // Allocate a new XSLT processor 
    $xh = xslt_create(); 

    // Process the document, returning the result into the $result variable 
    $result = xslt_process($xh, 'armstrong.xml', 'familyToNestedList.xsl'); 
    if ($result) { 
     print "SUCCESS, sample.xml was transformed by sample.xsl into the \$result"; 
     print " variable, the \$result variable has the following contents\n<br>\n"; 
     print "<pre>\n"; 
     print $result; 
     print "</pre>\n"; 
    } 
    else { 
     print "Sorry, sample.xml could not be transformed by sample.xsl into"; 
     print " the \$result variable the reason is that " . xslt_error($xh) . 
     print " and the error code is " . xslt_errno($xh); 
    } 

    xslt_free($xh); 

    ?> 

ありがとう:

はここで私が使用しているPHPコードです!

+0

http://www.php.net/manual/en/xslt.installation.php – DampeS8N

答えて

7

あなたはそれをサポートするためにcompile PHPを持っていて、すべての必要な依存関係を持っている必要があります。 PHP Manual for XSLTの対応する章を参照してください。

On Unix, run configure with the --enable-xslt --with-xslt-sablot options. The Sablotron library should be installed somewhere your compiler can find it. Make sure you have the same libraries linked to the Sablotron library as those, which are linked with PHP. The configuration options: --with-expat-dir=DIR --with-iconv-dir=DIR are there to help you specify them. When asking for support, always mention these directives, and whether there are other versions of those libraries installed on your system somewhere. Naturally, provide all the version numbers.

recommended extension for using XSL transformations with PHP5 is XSLInstallationから

This extension requires the libxml PHP extension. This means that passing in --enable-libxml is also required, although this is implicitly accomplished because libxml is enabled by default. This extension uses Sablotron and expat, which can both be found at » http://freshmeat.net/projects/sablotron/ . Binaries are provided as well as source. Enable by using the --with-xslt option with PHP 4.

Requirementsから

。あなたがする必要があるすべては二つの文書を変換である場合は、あなたの例ではショーとして、PHPのマニュアルからこの例を考えてみます。

$xml = new DOMDocument; 
$xml->load('collection.xml'); 

$xsl = new DOMDocument; 
$xsl->load('collection.xsl'); 

// Configure the transformer 
$proc = new XSLTProcessor; 
$proc->importStyleSheet($xsl); // attach the xsl rules 

echo $proc->transformToXML($xml); 

あなたは/場合を保つことができるようにtransformToXML方法は、変換された文書またはFALSEを返します。それ以外はあなたのコードから。いずれにしても、コードをアップグレードするのは簡単です。

+0

だから... OPはPHPを再コンパイルする必要がありますか? – sholsinger

+0

@sholsingerはい、上記のようなPHPが既に設定されていて、php.iniで拡張機能が無効になっている場合を除きます。しかし、XSLTはPHP5以降のPECLなので、そうは考えにくいでしょう。 – Gordon

+0

私のホストはMediaTempleであることを覚えておいてください。 –

16

Linuxのディストリビューションによっては、php5-xslモジュールをインストールし、php.iniファイルに "extension = php_xsl.so"という行を追加してapache2サーバを再起動することができます。

これは私のためにUbuntu 11.10で動作しました。コマンドラインに "sudo apt-get install php5-xsl"と入力して、php5-xmlをインストールすることができます。

+0

素晴らしい、ありがとう、私のために働いた! – neildaemond

+0

ubuntuで働いています。14. php.iniに何も追加する必要はありませんでした。 – grimurd

+0

Debian 8.0((jessie)64-bitで動くようになったので、php.iniに何も追加する必要はありませんでした。 –

2

さて、非常に簡単ですが、php.netでより明示的に説明することができます。

私は、ubuntuベースとphp-fpmを使用する1つのドッカーコンテナを使用しています。私のコンテキストでこの拡張機能をインストールするには

の手順は以下の通りであった:Linuxのリポジトリ上の

まず検索XSL拡張 のapt-キャッシュ検索XSL

私はPHP5-XSLを見つけてしまったので、それだけでインストールされました 自分だけ vimの/etc/php5/mods-available/xsl.ini

行い、起こらない場合は、セットアップの設定はすでに、追加されたインストールプロセスというのphp5-XSL

をインストールapt-getを

このコンテンツを挿入します。 extension = xsl。そう

(明らかにパスがPHPの設定の設定に応じているが、私の例では、デフォルトの設定です)

あなたはFPM PHPと行って再起動!

関連する問題