CLIX. XSL functions


The XSL extension implements the XSL standard, performing XSLT transformations using the libxslt library


This extension uses libxslt which can be found at libxslt version 1.0.18 or greater is required.


PHP 5 includes the XSL extension by default and can be enabled by adding the argument --with-xsl[=DIR] to your configure line. DIR is the libxslt installation directory.






Many examples in this reference require both an XML and an XSL file. We will use collection.xml and collection.xsl that contains the following:

例子 1. collection.xml

  <title>Fight for your mind</title>
  <artist>Ben Harper</artist>
  <title>Electric Ladyland</title>
  <artist>Jimi Hendrix</artist>

例子 2. collection.xsl

<xsl:stylesheet version="1.0" xmlns:xsl="">
 <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:template match="cd">
  <h1><xsl:value-of select="title"/></h1>
  <h2>by <xsl:value-of select="artist"/> - <xsl:value-of select="year"/></h2>
  <hr />


以下常量由本扩展模块定义,因此只有在本扩展模块被编译到 PHP 中,或者在运行时被动态加载后才有效。

XSL_CLONE_AUTO (integer)



XSLTProcessor->__construct() -- Creates a new XSLTProcessor object
XSLTProcessor->getParameter() -- Get value of a parameter
XSLTProcessor->hasExsltSupport() -- Determine if PHP has EXSLT support
XSLTProcessor->importStylesheet() -- Import stylesheet
XSLTProcessor->registerPHPFunctions() -- Enables the ability to use PHP functions as XSLT functions
XSLTProcessor->removeParameter() -- Remove parameter
XSLTProcessor->setParameter() -- Set value for a parameter
XSLTProcessor->transformToDoc() -- Transform to a DOMDocument
XSLTProcessor->transformToURI() -- Transform to URI
XSLTProcessor->transformToXML() -- Transform to XML

add a note add a note User Contributed Notes
adrian at foeder dot de
14-Sep-2006 05:45
If you want to use the document()-function inside your XSL stylesheet, please note that you have to use an absolute path there.
Important for windows users: the absolute path *has* to be with forward slashes, so subsitute windows-path-backslashes to forward slashes before you transform the document.

This will NOT work:
<xsl:copy-of select="document('test.xml')" />

This will also NOT work:
<xsl:copy-of select="document('c:\temp\test.xml')" />

But this WILL work:
<xsl:copy-of select="document('c:/temp/test.xml')" />
28-Apr-2006 09:26
Enable libxslt library, PHP 5, under windows:

To Enable:
In your php.ini
1. Uncomment ;extension=php_xsl.dll
2. Change extension_dir to
     extension_dir = "./ext"

To Confirm:
1. In a test.php page:
<?php phpinfo() ?>
2. Run test.php
3. Search for "libxslt Version". It should return a version number in a XSL headed table.

Further info Google
"Configuring and Testing PHP Servers for XSL Support"
Fabrice Bonny
30-Mar-2006 05:34
In response to how to use entities from DTD (internal or external) in XSLT. It works if you do this way:

$xsl = new DOMDocument;
$xsl->resolveExternals = TRUE;
$xsl->substituteEntities = TRUE;

Hope this helps! ;-)
basslines at gmail dot com
30-Mar-2006 02:07
As far as I can tell, the most recent stable versions of LibXML/LibXSLT/LibEXSLT do NOT support xPath 2.0 / XSLT 2.0 transformations. The only support for XSLT 2.0 that I've found is in Java's SAXON processor (
18-Mar-2006 01:14
In response to appletalk at gmail dot com
As many of you may have noticed, DOM parser gives errors if the '&nbsp;' entity is present. The E_WARN message looks like:
Warning: DOMDocument::load() [function.load]: Entity 'nbsp' not defined in ...
There're many ways to solve this:
b) Defining &nbsp;
At the top of the document, after the <?xml?> definition, add:
   <!DOCTYPE xsl:stylesheet [
   <!ENTITY nbsp "&#160;" >
Just wanted to let people know that option b does NOT work. I'm not sure why this isn't implemented correctly, but it isn't, so don't waste your time. It's unfortunate the DOMXSL transform is so much less capable than the old xslt function.
olivier dot sow at alias dot france
05-Aug-2005 09:27
if you have 'XML parser error 4: not well-formed (invalid token)' error without but your are sure to do no error at all, try this:
$Str = '';

$xp = xslt_create() or trigger_error('Could not create XSLT process.', E_USER_ERROR);

xslt_set_encoding($xp, 'ISO-8859-1');

// read the files into memory
$xsl_string = join('', file($XSLFile));
$xml_string = join('', file($XMLFile));

// set the argument buffer
$arg_buffer = array('/xml' => $xml_string, '/xsl' => $xsl_string);

// process the two files to get the desired output
if (($Str = xslt_process($xp, 'arg:/xml', 'arg:/xsl', NULL, $arg_buffer, $xsl_params))){

//Saves transformation result into '$ResultFile'
$fp = fopen($ResultFile,"w+");


found here:
venkatesh at lammersmedical dot com
01-Mar-2005 10:17
Here is function to read from the XSL sheet which is saved as a text file.

function ReadExcelSheet($filename){
             for ($i=0; $i<count($ar); $i++) {
                       if((substr($ar[$i],0,1)!= "\t")){
appletalk at gmail dot com
05-Feb-2005 02:32
As many of you may have noticed, DOM parser gives errors if the '&nbsp;' entity is present. The E_WARN message looks like:

Warning: DOMDocument::load() [function.load]: Entity 'nbsp' not defined in ...

There're many ways to solve this:
a) The hard way
<xsl:text disable-output-escaping="yes"> &amp;nbsp;</xsl:text>

b) Defining &nbsp;
At the top of the document, after the <?xml?> definition, add:
   <!DOCTYPE xsl:stylesheet [
   <!ENTITY nbsp "&#160;" >

c) External Doctype
Just in case you want need other HTML entities, you can call an external doctype with the proper definitions


Of course, you can download the file and place it in your server.
kekoajs at yahoo dot com
23-Dec-2004 06:07
Wow, I spent the better part of a day looking for how one could pass an entire test expression to an XSL stylesheet.  It seems that the XSLT 1.0 specification doesn't support it but PHP 5 (and maybe 4s) inclusion of  EXSLT allows one to do exactly that...

simply add these lines...


to the <xsl:stylesheet> element and when using an expression stored in a <xsl:param> element write

<xsl:if test="dyn:evaluate($param-name)">

and viola!  you can now use expressions generated externally in your stylesheet!

EXSLT adds many useful functions that can be integrated into your XSL in a similar fashion.  You can go to to learn more...
rd at jerntorget dot se
24-Sep-2004 06:58
If you get the following warning message:

xsltApplyOneTemplate: _if_ was not compiled in (if can for example be apply-template or some other method), i've found that the problem seems to be an &nbsp; directly before the <xsl:if> or what ever is causing the problem.

One way to get thru the problem is to use span tags around &nbsp;  like : <span>&nbsp;</span>
jw at jwscripts dot com
06-Sep-2004 05:23
The following code is a wrapper to support calls to some of the old xslt_* functions:


if (PHP_VERSION >= 5) {
// Emulate the old xslt library functions
function xslt_create() {
       return new

$xslcontainer = null,
$args = null,
$params = null) {
// Start with preparing the arguments
$xml_arg = str_replace('arg:', '', $xml_arg);
$xsl_arg = str_replace('arg:', '', $xsl_arg);

// Create instances of the DomDocument class
$xml = new DomDocument;
$xsl = new DomDocument;

// Load the xml document and the xsl template

// Load the xsl template

// Set parameters when defined
if ($params) {
           foreach (
$params as $param => $value) {
$xsltproc->setParameter("", $param, $value);

// Start the transformation
$processed = $xsltproc->transformToXML($xml);

// Put the result in a file when specified
if ($xslcontainer) {
           return @
file_put_contents($xslcontainer, $processed);
       } else {


xslt_free($xsltproc) {

$arguments = array(
'/_xml' => file_get_contents("newxslt.xml"),
'/_xsl' => file_get_contents("newxslt.xslt")

$xsltproc = xslt_create();
$html = xslt_process(


24-Jun-2004 10:43
If you're want to use XML from a variable e.g. $xmldata but the XSLT-StyleSheet from a file, you can do it also the following way:

= new xsltProcessor;