Giter VIP home page Giter VIP logo

fxsl's Introduction

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.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

fxsl's People

Contributors

covex-nn avatar lapistano avatar theseer avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.