Using xsl:include with XMLTransform
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.