XML
  Home arrow XML arrow Page 4 - XSL Transformation With PHP And Sablot...
Dev Shed Forums 
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Mobile Linux 
App Generation ROI 
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? 
XML

XSL Transformation With PHP And Sablotron
By: Harish Kamath, (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 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:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb 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 - Handling Things Better


    (Page 4 of 8 )

    Now, though the script you just saw is pretty primitive, it gets the job done. However, when you're working on a real project, you need to be more professional in your approach. So let's take this to the next level, with a slightly different version of the script above:

    <?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
    xslt_run($xslthandler, $xslfile,
    $xmlfile);




    // get and print the result
    echo xslt_fetch_result($xslthandler);




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




    ?>

    This is a slightly more structured approach. After defining the filenames for the XML and XSLT content, I've used the xslt_create() function to create a new instance of the XSLT processor and return a handle to it.

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

    This handle is used in all subsequent XSLT operations.

    Next, I've used the xslt_run() function to read and process the XML and XSLT files, and store the results of the processing in the default result buffer.

    // process the two files to get the desired output
    xslt_run($xslthandler, $xslfile,
    $xmlfile);

    Once the processing is complete and the output dumped into the default result buffer, I've used the xslt_fetch_result() function to fetch the contents of the buffer and print it to the browser.

    // get and print the result
    echo xslt_fetch_result($xslthandler);

    Finally, it's a good idea to clean things up by destroying the handle created during this process, so as to not occupy valuable memory.

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

    The xslt_free() function frees up the memory occupied by the XSLT processor.

    Using xslt_run() is often preferable to using xslt_process(), since the xslt_run() function is happy to accept file references to the XML and XSLT data as arguments (as opposed to xslt_process(), which only accepts string variables). Using xslt_run() can, therefore, often save you a few lines of code when performing server-side transformation with PHP.

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


     

       

    XML ARTICLES

    - 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...
    - SimpleXML
    - XForms Basics, Part 3
    - XForms Basics, Part 2
    - XForms Basics

     
    Application Delivery: Everything You Wanted to Know, but Didn`t Know You Needed to Ask
    A comprehensive guide to examining the topics of Wide-area Data Services and app....

     
    Best Practices: Safe and Secure Hardware Asset Recovery
    Companies increasingly must meet EPA and local requirements for the disposal of ....

     
    Managing SSL Security in Multi-Server Environments
    Read this white paper to learn how to simplify management of your organization's....

     
    Open Source Security Myths
    Open Source Software (OSS) is computer software whose source code is available t....

     
    Power and Cooling Capacity Management for Data Centers
    This paper describes the principles for achieving power and cooling capacity man....

     




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
    Stay green...Green IT