Published:
Warning: This blog entry was written two or more years ago. Therefore, it may contain broken links, out-dated or misleading content, or information that is just plain wrong. Please read on with caution.
Step 3: Insert Site Formatting
So far we have covered how to parse our xml sitemap using xsl. However we still want to make the sitemap's appearance consistent with out website.
To do this we could take our layout html and insert it inside our xsl:template tags but around our xsl for-each code like thus.
<xsl:stylesheet version="2.0" xmlns:html="http://www.w3.org/TR/REC-html40" xmlns:sitemap="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<html>
<head>
<title>My Sitemap</title>
</head>
<body>
<div id="wrapper">
<xsl:variable name="lower" select="'abcdefghijklmnopqrstuvwxyz'"/>
<xsl:variable name="upper" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'"/>
<table cellpadding="5">
<tr style="border-bottom:1px black solid;">
<th>URL</th>
<th>Priority</th>
<th>Change Frequency</th>
<th>LastChange</th>
</tr>
<xsl:for-each select="sitemap:urlset/sitemap:url">
--snip--
--snip--
</xsl:for-each>
</div>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
While this would work its not really a great solution. This approach basically means you have to maintain two identical templates for the same site.
Fortunately we can leverage the technique I outlined for building a dynamic sitemap the same way here to dynamically build our XSL file.
Reader Comments