Posted by: jaimalchohan on: August 3, 2009
I’ve decided to kick this blog off again, after much time off, and for my first post … I’ll introduce my Cached, Compiled, XSL Web Control.
Ever used the XSL control? It looks something like this:
<asp:Xml ID="xml1" DocumentSource="/MyData.xml" TransformSource="/MyStyle.xsl" />
I was working on a XML content driven project recently where I had to do many XML transforms on a page, and the above simly did not cut it, for the following reasons:
Mainly it was the lack of caching that annoyed me
My solution? come up with my own XsltControl
I started off with a basic XsltControl, wrapped a WebControl around it and added caching CompiledTransforms. Extra support was added for adding paramaters via markup.
So, now, you I can write
<custom:XsltControl ID="MyTransform" runat="server">
<custom:Argument Name="markup" Value="This text came from a paramater added via markup" />
<custom:Argument Name="resource" meta:resourcekey="Resource" />
</custom:XsltControl>
The control also allows you to set the path of a xsl include directory which it will cache and add cache dependencies to the Xsl for, so when the Xsl changes, or an includes file changes the cached version is invalidated and the new version picked up on the next transform.
XsltControl
Visual Studio 2008 Solution. [you'll have to rename the file to .zip]