I have the sitemap of my website in an XML file in this format:
<?xml version="1.0" encoding="utf-8"?>
<urlset xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd" xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
<loc>http://www.mywebsite.com//index.html</loc>
<lastmod>2014-08-16</lastmod>
<priority>0.5</priority>
</url>
<url>
// ... etc.
How can I automatically create an HTML page from this XML file containing a well formatted nice-looking clickable sitemap for the visitors of my website? Ideally this should be a PHP script which outputs the desired HTML to the browser.
EDIT: I have created some code which you can look at in the accepted solution. How can this code be optimized?