1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
|
fXSL
============
The classes contained within this repository extend the standard XSLTProcessor to use exceptions at
all occasions of errors instead of PHP warnings, notices or semi completed transformations.
They also add various custom methods and shortcuts for convinience and to allow a nicer API to implement callbacks
to the PHP stack.
Requirements
------------
PHP: 5.3.3 (5.3.0-5.3.2 had serious issues with spl stacked autoloaders)
Extensions: dom, xsl, libxml
Installation
------------
fXSL can be installed using the PEAR Installer, the backbone of the PHP Extension and Application Repository that provides a distribution system for PHP packages.
Depending on your OS distribution and/or your PHP environment, you may need to install PEAR or update your existing PEAR installation before you can proceed with the instructions in this chapter.
``sudo pear upgrade PEAR`` usually suffices to upgrade an existing PEAR installation. The PEAR Manual explains how to perform a fresh installation of PEAR.
The following two commands are all that is required to install fDOMDocument using the PEAR Installer:
sudo pear channel-discover pear.netpirates.net
sudo pear install TheSeer/fXSL
After the installation you can find the source files inside your local PEAR directory; the path is usually either
``/usr/share/pear/TheSeer/fXSL`` (Fedora/Redhat) or ``/usr/lib/php/TheSeer/fXSL`` (Debian/Ubuntu).
Usage
-----
Simply require/include the autoload.php supplied and you can start using fXSL as a
drop in replacement for the standard XSLTProcessor.
Usage Samples
-------------
PHP Code:
<?php
use TheSeer\fXSL\fXSLCallback;
use TheSeer\fXSL\fXSLTProcessor;
require 'TheSeer/fXSL/autoload.php';
function demo() {
return 'Demo reply';
}
class foo {
public function bar($a, $b) {
$x = new \DOMDocument();
$x->loadXML('<?xml version="1.0" ?><root />');
$p = $x->createTextNode($a . ' -> ' . $b);
$x->documentElement->appendChild($p);
return $x->documentElement;
}
}
$tpl = new DOMDocument();
$tpl->load('test.xsl');
$dom = new DOMDocument();
$xsl = new fXSLTProcessor($tpl);
$xsl->registerPHPFunctions('demo');
$test = new fXSLCallback('test:only','test');
$test->setObject(new foo());
$xsl->registerCallback($test);
$result = $xsl->transformToXml($dom);
$tpl->formatOutput = true;
echo "Template:\n" . $tpl->saveXML();
echo "\n\nOutput:\n".$result;
?>
The 'test.xsl' XSL Stylesheet used:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" exclude-result-prefixes="php foo"
xmlns:foo="test:uri"
extension-element-prefixes="php func" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:php="http://php.net/xsl">
<xsl:output method="xml" indent="yes" encoding="utf-8" />
<xsl:template match="/">
<root>
<!-- classic php function callback -->
<demo><xsl:value-of select="php:function('demo')" /></demo>
<!-- fXSL registered callback method -->
<test><xsl:copy-of select="test:bar('hello','world')" /></test>
</root>
</xsl:template>
</xsl:stylesheet>
Changelog
---------
#####Release 1.1.0
* Added loadStylesheetFromFile and loadStylesheetFromXML methods
* Clear xml errors on construct
* Changed protected properties and methods to private
#####Release 1.0.4
* PHP 5.4 compatibilty: set a default security preference so writing files is allowed
#####Release 1.0.3
* Changed error detecting code to catch more problems
#####Release 1.0.2
* Extended Exception code to better show actual errors
#####Release 1.0.1
* Added support for black- and whitelisting of methods
* Generate nicer xsl code
* Various Bugfixes
#####Release 1.0.0
* Initial release
|