logo PHP XML Classes
A collection of classes and resources to process XML using PHP

Description: This is an abstraction class for the XSLT extension. This version works with the new XSLT extension from PHP 1.1, the class allows to transform XML documents using XSLT stylesheets passing the xml/xslt as a file or as a PHP string.

Xslt (class_xslt.php)
PHP XML Classes
Xslt (class_xslt.php)

Description: This class is an abstraction class for an XSLT processor, it let's you setup the XML to be processed and the XSLT stylesheet to use from a file or a PHP string. This implementation uses the Sablotron XSLT processor and was updated to work with the new PHP 4.1.x xslt extension.

NEWS:
  • 07-04-2002 Documentation updated and package rebuilt.
  • 05-15-2002 Updated to work under PHP 4.2.x
This class code as well as the documentation are hosted at SourceForge please visit our SourceForge page for releases, documentation, bug-tracking, support forums and mailing lists.

Resources Requirements
  • PHP 4.0.5+
  • XSLT extension

Features To-dos
  • Can receive the XML source as a string or a file (http://) works too.
  • Can receive the XSLT stylesheet as a string or a file (http://) works too.
  • Option to cache transformations for incresed speed.

Contact: Luis Argerich

Detailed description and usage:
Using the class:
include_once("class_xslt.php");
$xslt=new Xslt();
$xslt->setXml("applications.xml"); // or setXmlString($xml) if the xml is in a php string
$xslt->setXsl("tr1.xsl");          // or steXslString($xsl) if the xsl is in a php string
if($xslt->transform()) {
   $ret=$xslt->getOutput();
   echo $ret;
} else {
   print("Error:".$xslt->getError());
}

Documentation

Classes

class_xslt

Extends: None
Description: Class to handle XSLT transformations, the XML documents and the XSLT stylesheet can be passed as files or PHP strings.

Method Summary
 void Xslt()
          Constructor
 void destroy()
          Destructor
 string getOutput()
          Returns the result of the XSLT transformation
 void setXmlString(string $xml)
          Sets the XML to be transformed from a string
 void setXml(string $uri)
          Sets the XML to be transformed from a URI
 void setXslString(string $xsl)
          Sets the XSLT stylesheet to be used from a string
 void setXsl(string $uri)
          Sets the XSLT stylesheet to be used from a URI
 boolean transform(string $uri)
          Performs an XSLT transformation
 string getError(string $uri)
          Returns the error message if a transformation fails
 

Method Detail

Xslt

void Xslt(string $uri)
Constructor (no parameters)
 
Parameters:
Returns:
Nothing
Throws:
None

destroy

void destroy(string $uri)
Object destructor should be called to free resources allocated for the Sablotron processor.
 
Parameters:
Returns:
Nothing
Throws:
None

getOutput

string getOutput(string $uri)
This returns the result of the last XSLT transformation
 
Parameters:
Returns:
Transformation result's
Throws:
None

setXmlString

void setXmlString(string $xml)
This method sets the XML that is going to be transformed from a PHP string.
 
Parameters:
$xml -
Returns:
Nothing
Throws:
None

setXml

void setXml(string $uri)
This method sets the XML to be transformed from a URI, it can be a file in the local file system or a http:// form URI pointing to an XML file.
 
Parameters:
$uri - It can be a file, example "foo.xml" or a remote file, example: "http://foo.com/foo.xml"
Returns:
Nothing
Throws:
None

setXslString

void setXslString(string $xsl)
This method sets the XSLT stylesheet to be used from a PHP string.
 
Parameters:
$xsl - The XSLT stylesheet as a PHP string
Returns:
Nothing
Throws:
None

setXsl

void setXsl(string $uri)
This method sets the XSLT stylesheet to be used from a URI, it can be a file in the local file system or a http:// form URI pointing to the location of an XSLT file.
 
Parameters:
$uri - Use "foo.xslt" to point to a XSLT file in the local file system or "http://foo.com/foo.xsl" for a remote XSLT stylesheet.
Returns:
Nothing
Throws:
None

transform

boolean transform(string $uri)
Once an XML and an XSLT are set this method performs the XSLT transformation, the result can be obtained using the getOutput method.
 
Parameters:
Returns:
true/false indicating if the transformation was succesful
Throws:
None

getError

string getError(string $uri)
This method returns the error message when the transform() method returns false
 
Parameters:
Returns:
Error description
Throws:
None


Contribute!: If you want to contribute a class to this project or help with new versions of existing classes please let me know it by emaill Hosted at:
SourceForge.net Logo
Contact & credits
Luis Argerich
Rogerio

OSI Certified Open Source Software
OSI
RSS FEED XHTML