将PHP XSLT处理器升级到XSLT 2.0 [英] Upgrade PHP XSLT processor to XSLT 2.0

查看:102
本文介绍了将PHP XSLT处理器升级到XSLT 2.0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以/容易地升级PHP的库以使用XSLT 2.0?

Is it possible/easy to upgrade PHP's library to use XSLT 2.0?

当前设置:

xsl
XSL     enabled
libxslt Version     1.1.24
libxslt compiled against libxml Version     2.6.32
EXSLT   enabled
libexslt Version    1.1.24 

推荐答案

Saxon-C 项目为其XSLT 2.0实现提供了PHP API.

The Saxon-C project provides a PHP API for its XSLT 2.0 implementation.

这是基本的安装过程:

请在您的计算机上安装以下软件包以构建Saxon/C PHP扩展:make,php-devel,(php5-dev/php55-dev/php55w-devel),apache2或httpd,gcc-c ++或g ++, gcj(或仅链接jni.h文件)

Please have the following packages on your machine to build the Saxon/C PHP extension: make, php-devel, (php5-dev/php55-dev/php55w-devel), apache2 or httpd, gcc-c++ or g++, gcj (or just link the jni.h file)

运行命令:

phpize
./configure --enable-saxon
make
sudo make install

更新php.ini文件(如果使用Ubuntu,通常在'/etc/php5/apache2/'位置)以包含php扩展名.在动态扩展"部分中插入以下内容:extension = saxon.so

Update the php.ini file (if using Ubuntu it is usually in the location '/etc/php5/apache2/') to contain the php extension. Insert the following in the Dynamic Extensions section: extension=saxon.so

运行命令:

sudo service apache2 restart

示例代码:

<?php 
/* simple example to show transforming to string */
 function exampleSimple1($proc, $xmlfile, $xslFile){
    $proc->setSourceFile($xmlfile);
    $proc->setStylesheetFile($xslFile);

    $result = $proc->transformToString();               
if($result != null) {               
echo '<b/>exampleSimple1:</b/><br/>';       
echo 'Output:'.$result;
} else {
    echo "Result is null";
}
$proc->clearParameters();
$proc->clearProperties();            
}


$foo_xml = "xml/foo.xml";
$foo_xsl = "xsl/foo.xsl";

$proc = new SaxonProcessor();

//On Windows we recommend setting the cwd using the overloaded constructor 
//because there remains an issue with building Saxon/C with PHP when using the function VCWD_GETCWD. i.e. $proc = new SaxonProcessor('C://www/html//trax//');

$version = $proc->version();
echo 'Saxon Processor version: '.$version;
echo '<br/>';        
exampleSimple1($proc, $foo_xml, $foo_xsl);
?>

libxslt2和libexslt库仅限于XSLT 1.0,XPath 1.0和EXSLT支持,用于为PHP提供默认的XSLT处理器. XML_XSLT2Processor 项目旨在提供升级路径.

The libxslt2 and libexslt libraries, which are limited to XSLT 1.0, XPath 1.0, and EXSLT support, are used to provide the default XSLT processor for PHP. The XML_XSLT2Processor project is intended to provide an upgrade path.

这是基本的安装过程:

请遵循要使用的处理器站点上提供的说明,以获取有关如何安装XSLT处理器的说明.基本上,您将需要在某个目录中提取处理器二进制文件.

Follow the instructions provided on the site of the processor you want to use for instructions on how to install that XSLT processor. Basically, you'll be required to extract the processor binary in some directory.

一旦设置了处理器,就可以下载XML_XSLT2Processor. 使用PEAR安装程序

Once you have the processor set up, you can download XML_XSLT2Processor. Using the PEAR installer

如果尚未安装PEAR安装程序,请查看PEAR站点上的安装说明(基本上,在Windows上,启动PHP文件夹中的go-pear.bat文件,在典型情况下,单击"Enter"一直),然后安装PEAR安装程序,也就是"PEAR软件包管理器".

If you don't already have the PEAR installer, check the installation instructions on the PEAR site (basically, on Windows, you start the go-pear.bat file in PHP's folder, and in the typical case click "Enter" all the way), and install the PEAR installer a.k.a. the "PEAR package manager".

拥有PEAR安装程序后,只需键入以下内容即可从中安装XML_XSLT2Processor 梨安装路径/to/the/tgz/arhive 但是请当然替换路径.例如,如果版本0.5.3与PHP文件夹位于同一文件夹中,则可以使用以下命令进行安装 梨安装XML_XSLT2Processor_v0_5_3.tgz

Once you have the PEAR installer, you can install XML_XSLT2Processor from it, by simply typing pear install path/to/the/tgz/arhive but replace the path of course. For example, if version 0.5.3 was in the same folder as the PHP folder, you can install it with the command pear install XML_XSLT2Processor_v0_5_3.tgz

手动安装

如果您没有(访问)PEAR安装程序,仍然可以通过将归档文件的内容提取到任何目录中来安装XML_XSLT2Processor.但是,建议此目录位于include_path中的路径中,您可以在php.ini中指定该路径.为了更紧密地模拟PEAR安装程序,您还可以将"XSLT2Processor-verion"目录重命名为"XML".

If you don't have (access to) the PEAR installer, you can still install XML_XSLT2Processor by extracting the contents of the archive in any directory. However, it is recommended that this directory is among the paths in your include_path, which you can specify in php.ini. To more closely emulate the PEAR installer, you may also rename the "XSLT2Processor-verion" directory to "XML".

用法

完成上述所有操作后,您可以创建一个新的PHP文件,并在其中包含XML_XSLT2Processor.如果您使用过PEAR安装程序,则应从"XML"文件夹中获得"XSLT2Processor.php",因此:

Once all of the above is done, you can create a new PHP file and include XML_XSLT2Processor in it. If you've used the PEAR installer, "XSLT2Processor.php" should be available from the "XML" folder, thus:

<?php 
include "XML/XSLT2Processor.php";
//The rest of the code
?>

您将需要使用该类的PHP文件中的包含行,该行应该在使用该类中的任何函数之前发生.文档的其余部分将向您展示如何构造XML_XSLT2Processor类,并解释每个函数的原型并提供一些示例.

You'll need the include line in the PHP file that will be using the class and it should occur before you use any of the functions in that class. The rest of the documentation will show you how to construct the XML_XSLT2Processor class, as well as explain each function's prototype and give some examples.

请注意,如果您在使用PHP XSL扩展之前就已经使用过它,那么您唯一真正需要知道的就是XML_XSLT2Processor :: __ construct()函数.其余部分与之兼容,尽管只有此处提供了一些新功能.请注意,由于类的体系结构(不是PECL扩展以及全部...),registerPHPFunctions()和setProfiling()函数不可用.

Note that if you've worked with the PHP XSL extension before using this one, the only thing you really must know is the XML_XSLT2Processor::__construct() function. The rest is compatible with it, though there are some new features available only here. Be aware that the registerPHPFunctions() and setProfiling() functions are not available due to the architecture of the class (not being a PECL extension and all...).

参考

XSLT2Processor项目新闻

Saxon-C产品信息

Saxon-C PHP API

这篇关于将PHP XSLT处理器升级到XSLT 2.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆