XML
  Home arrow XML arrow Page 7 - XSL Transformation With PHP And Sablotron
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
Google.com  
XML

XSL Transformation With PHP And Sablotron
By: Harish Kamath, (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 6
    2001-11-30


    Table of Contents:
  • XSL Transformation With PHP And Sablotron
  • Getting Down To Business
  • Start It Up
  • Handling Things Better
  • An Evening At The Moulin Rouge
  • Mistakes Happen
  • Publish Or Die!
  • Endzone

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    XSL Transformation With PHP And Sablotron - Publish Or Die!
    ( Page 7 of 8 )

    Now that you've seen the different techniques available to process XSLT stylesheets, here's a simple example which demonstrates a real-life use of this technology - a simple XML to HTML publishing system.

    Let's assume that you have a collection of data, all neatly tagged and marked up in XML. Now, you need to use this information in different places. Some of it may need to be converted into HTML, for use on a Web site; other bits of it may need to be converted into WML, for wireless transfer, or imported into a database, or transformed into PDF documents, or...

    With PHP's XSLT engine, accomplishing all this becomes a snap. All you need are separate stylesheets, each one taking care of a particular type of conversion. Feed these stylesheets to a PHP script which knows how to handle them, and Bob's your uncle.

    As an example, consider the following script, which accepts XML and XSLT input and saves the results of this transformation as an HTML document:

    <?php




    // the fodder for the Sablotron XSLT processor
    $xmlfile = "person.xml";
    $xslfile
    = "person.xsl";
    $htmlfile = "/www/person.html";




    // create the XSLT processor
    $xslthandler = xslt_create() or die("Can't create
    XSLT handle!");




    // process the two files to get the desired output
    if(xslt_run($xslthandler,
    $xslfile, $xmlfile))
    {
    // get result buffer
    $result = xslt_fetch_result($xslthandler);




    // publish the result to a static HTML file
    $htmlfp = fopen($htmlfile,"w+");
    fputs($htmlfp,$result);
    fclose($htmlfp);




    echo "File $htmlfile successfully created!";
    }
    else
    {
    // error handler
    echo
    "An error occurred:n";
    echo "Error number: " . xslt_errno($xslthandler) . "n";
    echo
    "Error string: " . xslt_error($xslthandler) . "n";
    exit;
    }




    // clean up
    xslt_free($xslthandler);
    ?>

    Granted, it's pretty simple - but isn't that a good thing?

    In a similar manner, you could write scripts to convert your XML data into other formats, insert it into a database or exchange it with other servers.

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

       

    XML ARTICLES

    - 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...
    - Practical XML Data Design and Manipulation f...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 2 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek