PHP
  Home arrow PHP arrow Page 8 - Plugging RDF Content Into Your Web Site With PHP
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? 
PHP

Plugging RDF Content Into Your Web Site With PHP
By: icarus, (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 19
    2002-02-27


    Table of Contents:
  • Plugging RDF Content Into Your Web Site With PHP
  • Have Content, Will Syndicate
  • Switching Channels
  • Fresh Meat
  • Capture The Flag
  • Nesting Time
  • Back To Class
  • Adding A Little Style
  • Homework

  • 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


    Plugging RDF Content Into Your Web Site With PHP - Adding A Little Style
    ( Page 8 of 9 )

    In case you don't like the thought of iterating through all those PHP arrays and marking them up with HTML, you also have the option to format and display the data using an XSLT stylesheet. PHP 4.1 comes with support for the Sablotron XSLT processor via a new XSLT API, which can be used to combine an XSLT stylesheet with an XML (or, in this case, RDF) document to easily transform XML markup into browser-readable HTML.

    I'm not going to get into the details of this - take a look at the PHP manual, or at the links at the end of the article, for detailed information - but I will demonstrate what I mean with a simple example. First, here's the stylesheet:

    <?xml version="1.0"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:rss="http://purl.org/rss/1.0/" xmlns:dc="http://purl.org/dc/elements/1.1/" version="1.0"> <!-- main page --> <xsl:template match="/rdf:RDF"> <html> <head> <basefont face="Arial" size="2"/> </head> <body> <xsl:apply-templates select="rss:channel" /> <ul> <xsl:apply-templates select="rss:item" /> </ul> </body> </html> </xsl:template> <!-- channel --> <xsl:template match="rss:channel"> <b> <a> <xsl:attribute name="href"><xsl:value-of select="rss:link" /></xsl:attribute> <xsl:value-of select="rss:title" /> </a> </b> </xsl:template> <!-- item --> <xsl:template match="rss:item"> <li /> <a> <xsl:attribute name="href"><xsl:value-of select="rss:link" /></xsl:attribute> <xsl:value-of select="rss:title" /> </a> <br /> <xsl:value-of select="rss:description" /> </xsl:template> </xsl:stylesheet>
    And here's the PHP script that combines the stylesheet above with the Freshmeat RDF document described previously to generate an HTML page:

    <?php // XML file // this needs to be a local file $xml = "fm-releases.rdf"; // XSLT file $xslt = "fm.xsl"; // create a new XSLT processor $xp = xslt_create(); // transform the XML file as per the XSLT stylesheet // return the result to $result $result = xslt_process($xp, $xml, $xslt); if ($result) { // print it echo $result; } // clean up xslt_free($xp); ?>
    Fairly simple and self-explanatory again, I think. The two documents are merged to produce the following composite output:



    This is an alternative, and perhaps simpler (though not all that optimal), method of turning RDF data browser-readable HTML. Note, however, that you will need to have an external program running (probably via cron) to update your local copy of the RDF file on a regular basis, since the PHP XSLT processor may have trouble accessing a remote file.

     
     
    >>> More PHP Articles          >>> More By icarus, (c) Melonfire
     

       

    PHP ARTICLES

    - Using Directory Iterators to Build Loader Ap...
    - Using the spl_autoload() Functions to Build ...
    - Working Out of the Object Context to Build L...
    - Using the _autoload() Magic Function to Buil...
    - The Destruct Magic Function in PHP 5
    - The Autoload Magic Function in PHP 5
    - Developing a Recursive Loading Class for Loa...
    - The Sleep and Wakeup Magic Functions in PHP 5
    - Using the Clone Magic Function in PHP 5
    - Including Files Recursively with Loader Appl...
    - The Call Magic Function in PHP 5
    - Designing a Captcha System with PHP and MySQL
    - Using Static Methods to Build Loader Apps in...
    - The Isset and Unset Magic Functions in PHP 5
    - Advanced PHP Form Input Validation to Check ...





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