I was doing a bunch of stuff with XML and XSL Transformations in ColdFusion the other day and I got really tired of the fact that I had to create an intermediary XSLT variable before I could call the XmlTransform() method. To deal with this, I whipped up a quick little ColdFusion custom tag, xslt.cfm. This tag simply takes, as an attribute, an XML document (or string), and applies the XSL transformation defined within the tag contents to the given XML document. Here's how it works inside:
Launch code in new window » Download code as text file »
Notice that in the Start execution mode of the tag, all we do is define the XML attribute. Then, in the End execution mode of the tag we simply replace the generated content with the result of the XmlTranform() method using the passed in the XML document and the existing generated content value.
To use the tag, you could do something like this:
Launch code in new window » Download code as text file »
Here I am modelling the navigation of an HTML page and then using the CF_XSLT ColdFusion custom tag to render it in place. This might seem like a really small piece of functionality, but it ended up making my life easier.
Download Code Snippet ZIP File
Comments (0) | Post Comment | Ask Ben | Permalink | Print Page
There are no comments posted for this web log entry.