<?php
/**
 * Transform a specified rss feed into html.
 * The XSL style sheet is specifed as the second parameter. If none is specified, the function will try to find a "rss.xsl" file in the current directory
 * @param   string    $rssFeed          The url of the rss feed to parse
 * @param   string    $xslStyleSheet    The place of the XSL style sheet either on the file system, or a url
 * @return  string    Return the HTML generated by the transformation of the XML
 */
function htmlize($rssFeed=null$xslStyleSheet="rss.xsl"){
  
$html="";
  if(
$rssFeed===null){
    return 
null;
  }
  if(!
file_exists($xslStyleSheet)){
    
$msg="The XSL style sheet $xslStyleSheet was not found in ".basedir(__FILE__);
    
error_log($msg);
    
//We don't show the error message by default, for security
    
die();
  }
  
//We get the stream content into a variable.
  
$rssContent=file_get_contents($rssFeed);
  
//We initialize the XSLT engine
  
$xsl = new XSLTProcessor();
  
//And create a DOM document element.
  
$doc = new DOMDocument();
  
//load the XSL style sheet into the DOM document
  
$doc->load($xslStyleSheet);
  
//And indicate the XSLT engine to use this DOM representation of my file.
  
$xsl->importStyleSheet($doc);
  
//We import the XML into the DOM parser
  
$doc->loadXML($rssContent);
  
//And we transform it via the XSL engine
  
$html=$xsl->transformToXML($doc);

  return 
$html;
}
?>