Home arrow XML arrow Page 6 - XSL Transformation With PHP And Sablotron

Mistakes Happen - XML

So you've got your XML, and you've also got an XSLT stylesheet to format it. But how do you put the two of them together? Fear not - you can use PHP's Sablotron extension to perform XSLT transformation of XML data on the server. This article tells you how.

TABLE OF CONTENTS:
  1. XSL Transformation With PHP And Sablotron
  2. Getting Down To Business
  3. Start It Up
  4. Handling Things Better
  5. An Evening At The Moulin Rouge
  6. Mistakes Happen
  7. Publish Or Die!
  8. Endzone
By: Harish Kamath, (c) Melonfire
Rating: starstarstarstarstar / 6
November 30, 2001

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement
Like any good API, PHP's Sablotron extension comes with an excellent error-handling mechanism. I'll modify one of the examples above to illustrate:

<?php




// the files
$xmlfile = "person.xml";
$xslfile = "person.xsl";




// create the XSLT processor
$xslthandler = xslt_create() or die("Houston, we
have a problem. No XSLT
handler available. Mission aborted.");




// process the two files to get the desired output
if(xslt_run($xslthandler,
$xslfile, $xmlfile))
{
// get and print the result
echo xslt_fetch_result($xslthandler);
}
else
{
//
error
echo "Something bad just happened.n";
echo "Error code: " . xslt_errno($xslthandler)
. "n";
echo "Error string: " . xslt_error($xslthandler) . "n";
exit;
}




// free the resources occupied by the handlers
xslt_free($xslthandler);




?>

Much of the code here has been culled from the previous examples. The difference: this script includes a primitive error-handling mechanism, which checks whether or not the processing was successful, and returns an error code and message if not.

Both the xslt_errno() and xslt_error() functions accept a handle for the XSLT processor, and return the last error code and message generated by the processor. At least that's the theory - in my experiments with PHP 4.0.6, these functions failed to work as advertised.

 
 
>>> More XML Articles          >>> More By Harish Kamath, (c) Melonfire
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

XML ARTICLES

- Google Docs and Xpath Data Functions
- Flex Array Collection Sort and Filtering
- The Flex Tree Control
- Flex List Controls
- Working with Flex and Datagrids
- How to Set Up Podcasting and Vodcasting
- Creating an RSS Reader Application
- Building an RSS File
- An Introduction to XUL Part 6
- An Introduction to XUL Part 5
- An Introduction to XUL Part 4
- An Introduction to XUL Part 3
- An Introduction to XUL Part 2
- An Introduction to XUL Part 1
- XML Matters: Practical XML Data Design and M...

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: