note 78436 added to ref.xsl
| From: | pb at online-magazin dot at | Date: | Thu, 11 Oct 2007 22:13:57 +0000 |
| Subject: | note 78436 added to ref.xsl | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-131315@lists.php.net to get a copy of this message | ||
Calling the Saxon XSLT Processor is a very esay task to do!
You just need to do some simple task
1. Install the JavaBridge for PHP
2. Download the freeware (B) Saxon distribution from http://saxon.sourceforge.net/
3. Put the jar files in a directory whre you have access
4. Use this sample of code
// Directory where the jar files are located
define("SAXON_DIR", $_SERVER['DOCUMENT_ROOT']."/saxonb8.9.0/");
// include the jars
java_require(SAXON_DIR."saxon8.jar;".SAXON_DIR."saxon8-dom.jar");
$sXslFile = $_SERVER['DOCUMENT_ROOT']."/myfirst.xsl"; // The xsl file
$sXmlFile = $_SERVER['DOCUMENT_ROOT']."/myfirst.xml"; // The xml file
try
{
$oXslSource = new java("javax.xml.transform.stream.StreamSource",
"file://".$sXslFile);
$oXmlSource = new java("javax.xml.transform.stream.StreamSource",
"file://".$sXmlFile);
$oFeatureKeys = new JavaClass("net.sf.saxon.FeatureKeys");
// Create the Factory
$oTransformerFactory = new java("net.sf.saxon.TransformerFactoryImpl");
//Disable source document validation
$oTransformerFactory->setAttribute($oFeatureKeys->SCHEMA_VALIDATION, 4);
// Create a new Transformer
$oTransFormer = $oTransformerFactory->newTransformer($oXslSource);
// Create a StreamResult to store the output
$oResultStringWriter = new java("java.io.StringWriter");
$oResultStream = new java("javax.xml.transform.stream.StreamResult",
$oResultStringWriter);
// Transform
$oTransFormer->transform($oXmlSource, $oResultStream);
// Echo the output from the transformation
echo java_cast($oResultStringWriter->toString(), "string");
}
catch(JavaException $e){
echo java_cast($e->getCause()->toString(), "string");
exit;
}
5. Enjoy
This is working quite well.
----
Server IP: 81.223.48.75
Probable Submitter: 88.117.36.190
----
Manual Page -- http://www.php.net/manual/en/ref.xsl.php
Edit -- https://master.php.net/note/edit/78436
Del: integrated -- https://master.php.net/note/delete/78436/integrated
Del: useless -- https://master.php.net/note/delete/78436/useless
Del: bad code -- https://master.php.net/note/delete/78436/bad+code
Del: spam -- https://master.php.net/note/delete/78436/spam
Del: non-english -- https://master.php.net/note/delete/78436/non-english
Del: in docs -- https://master.php.net/note/delete/78436/in+docs
Del: other reasons-- https://master.php.net/note/delete/78436
Reject -- https://master.php.net/note/reject/78436
Search -- https://master.php.net/manage/user-notes.php