Author: Steven Neiland

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.

Leveraging Coldfusion & Url Rewriting to Style XSL

As with building a sitemap dynamically, the first step in building a dynamic xsl file is to convert it from xsl to cfm. We simple rename it from sitemap.xsl to sitemapXsl.cfm .

At this point our sitemap xml file is still pointing to sitemap.xsl so we either change the pointer in the sitemap file, or as I prefer we create a rewrite rule that points traffic for sitemap.xsl to sitemapXsl.cfm as follows.

#Sitemap XSL rule
RewriteRule ^sitemap.xsl/?$ sitemapXsl.cfm [L,NC]

Set the Encoding and Load the CFML

Now that we have the xsl file converted to cfm we need to instruct our cfml engine to serve it as an xsl file. To do this we place the following three directives at the top of our sitemapXsl.cfm file.

<cfsetting enablecfoutputonly="true" showdebugoutput="false">
<cfprocessingdirective pageencoding="utf-8">
<cfcontent type="text/xsl">

Override Default Encoding

It is important to note that if you have set a doctype in your site template that this must be disabled or it will conflict with the xsl declaration. To do this I use a simple param as follows.

<cfsetting enablecfoutputonly="true" showdebugoutput="false">
<cfprocessingdirective pageencoding="utf-8">
<cfcontent type="text/xsl">
<!---Override site default doc type--->
<cfset doctypeOverride = true>
1 2 3 4 5 6 7

What Do You Think?

Reader Comments

Post a Comment

Comment Etiquette:

  • 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 or appear to be advertisments, will not be published.
  • Comments that appear to be created for the purpose of linkbuilding to commercial sites will be removed.

We are all adults here so play nice.


Archives Blog Listing

Tag Listing

Learn CF In A Week


Fork me on GitHub