PHP
  Home arrow PHP arrow Page 8 - Plugging RDF Content Into Your Web Sit...
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 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Moblin 
JMSL Numerical Library 
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: 4 stars4 stars4 stars4 stars4 stars / 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:
      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


    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

    - Validating Web Forms with the Code Igniter P...
    - Output Buffering
    - Paginating Database Records with the Code Ig...
    - HTTP Headers in Web Development
    - Project Management: Administration
    - Building a Database-Driven Application with ...
    - User Authentication for a Project Management...
    - Introduction to the CodeIgniter PHP Framework
    - Adding Users for a Project Management Applic...
    - Migrating Class Code for a MIME Email to PHP...
    - Login and Logout Authentication for a Projec...
    - Composing Messages in HTML for MIME Email wi...
    - Project Management: Authentication
    - A Better Way to Determine MIME Types for MIM...
    - Project Management Overview





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway