Rip's Domain

Using xsl:include with XMLTransform

Posted in ColdFusion by rip747 on May 16, 2007

Download the files by right click here. You will need to rename the jpg file to zip and unzip them. Sorry about this, but WordPress doesn’t allow uploading of zip files and this is the only workaround I know of.

XMLTransform has a big limitation in that you cannot use xsl:include with an xslt template. What this all means is that you can’t break down an xslt template into smaller groups and then include them in a parent template. This is like taking a loooooong ColdFusion template and breaking it up into smaller template by including the smaller templates with cfinclude.

Now I’ve been searching around with Google and have seem some very creative ways of working around this limitation. Some people loop through the directory and then read each template into memory using cffile and some use Java to handle everything.

Well here is my little work around that works great and the best part is IT’S SIMPLE. Before you do anything, download the files so you can follow along and run the example.

We’re going to use 5 files:

index.cfm – our template that call and transform our XML and XSLT
empty.xml – just an empty XML file for testing
master.xsl – this is the master template that will include the 2 child template
child1.xsl – child template to include
child2.xsl – child template to include

OK – So this is how simple this is. The secret is in the master template’s xsl:include tags. If you notice in the tag’s href attributes I’m calling both child templates but preceeding them with $fullpath$. Bascially what this is, is a string that I can look up and replace with CF. The string I’m going to replace it with is the variables.fullpath from the index.cfm

That’s pretty much it, I told you it was simple. And it works beautifully. Now you can pull apart your XSLT files instead of having one big one.

Remember to download the files (link at top of article) so that you can try it out for yourself. Be sure to give each one a look over.


2 Responses

Subscribe to comments with RSS.

  1. SueB said, on July 19, 2007 at 2:08 pm

    the link to download files opens up an image instead. I would very much like to see what you did.

  2. rip747 said, on July 19, 2007 at 2:18 pm

    If you actually read the first paragraph, it will tell you that you have to rename the file from .jpg to .zip since WordPress doesn’t let you upload ZIP file.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: