Styling a Sitemap Using XSL and Coldfusion - page 7

Author: Steven Neiland
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.

Include CFML template

For the sake of simplicity here I have split my site template into two files pagetop.cfm and pagebottom.cfm. This is not the only or best way of doing it, it just best illustrates the technique.

Note: Notice that as with the dynamic sitemap example there is no space between the cfoutput tag and the first xsl tag.

<cfsetting enablecfoutputonly="true" showdebugoutput="false">
<cfprocessingdirective pageencoding="utf-8">
<cfcontent type="text/xsl">
<!---Override site default doc type--->
<cfset doctypeOverride = true>
<cfoutput><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="/">
<cfinclude template="pagetop.cfm">

<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>

<cfinclude template="pagebottom.cfm">
</xsl:template>

</xsl:stylesheet></cfoutput>
</cfcontent>

Step 4: Test and Debug Encoding

At this stage you should be able to visit your sitemap and see a list of hyperlinks inside your standard site template. However it is more likely that you will see an error.

The reason you are likely to see an error is because xsl requires certain characters to be encoded in a particular way. For example the "&" symbol should be encoded as "&amp;". My advice would be to comment out your entire template layout then slowly add back elements and tackle each encoding issue as you go.

Final Word

If you have managed to read this far then congrats. I hope I did not bore you too much. I know this has been a long one but I felt it was worth the extra effort to explain how xsl works.

1 2 3 4 5 6 7

Reader Comments

  • Please keep comments on-topic.
  • Please do not post unrelated questions or large chunks of code.
  • Please do not engage in flaming/abusive behaviour.
  • Comments that contain advertisments or appear to be created for the purpose of link building, will not be published.

Archives Blog Listing