I recently updated to FireFox .9, the latest and greatest web browser from Mozilla.org

I then installed Bookmarks Synchronizer, a Firefox extension that allows me to synchronize my bookmarks by uploading an XML file to my website every time they are updated.

I wanted to provide a nicely formatted page on my websites, so I found an XSL transform to convert the XML file to HTML on the fly. I then wrote a PHP script which takes an XML file and XSL transform and outputs the processed HTML or XML.
You can view the result of my handiwork here: http://rationalmind.net/bookmarks

(That URL actually loads http://rationalmind.net/?file=XSLT&xml=david/bookmarks.xml&xsl=david/bookmarks.xsl)

If you would like to try this yourself, the code is below:

(The pretty code was generated with the Enscript syntax-highlight plugin for WordPress.)

// Get Variables
$xml = $_GET['xml'];$xsl = $_GET['xsl'];$format = $_GET['format'];
// Check for variables
if (!$xml || !$xsl){
echo "Directions: xslt.php?&xml=david/bookmarks.xml&xsl=david/bookmarks.xsl
Optionally, add &format=xml";
die(); }
// What to do?
if ($format == xml) {
header('Content-type: text/xml', true);
} else {
echo "< ?xml version="1.0" encoding="iso-8859-1"?".">";
}
// Allocate a new X S L T processor
$xh = xslt_create();
// Process the document, returning the result into the $result variable
$result = xslt_process($xh, $xml, $xsl);
if ($result) {
   print $result;
}
else {
    print "Sorry, ".$xml." could not be transformed by ".$xsl." into";
    print "  the \$result variable the reason is that " . xslt_error($xh) .
    print " and the error code is " . xslt_errno($xh);
}
xslt_free($xh);
//</>

2 Responses to “Fun with XML”

If you haven’t already, you need to install the Web Developer extension. Seriously. I can’t believe how much stuff he’s packed into 85k.

The web developer extension is awesome, especially the live CSS edit and element outlining features. I also love Mozilla’s ability to view the source of selected elements.

Something to say?