2

I'm working on a project that involves XSLT. And would like to use a C# script in my XSLT. Just like in the following link. XSLT 1.0 Get Current DateTime

Although I ran into this KB article http://support.microsoft.com/kb/316775 saying that this causes memory leaks when loading the stylesheet multiple times.

The KB article doesn't say which .NET versions are affected. Can anyone advise whether this is fixed in .NET 2.0 or higher ?

My target environment have .NET 2.0 and 3.5, although the code that does the XSLT transform is compiled to .NET 2.0.

Note: I don't have control over the code that run the transformation. I can only write the XSLT

Community
  • 1
  • 1
Madushan
  • 6,977
  • 31
  • 79

1 Answers1

2

This isn't a bug -- in the first place.

More importantly, this is absolutely avoidable.

The solution is: not to have inline scripts but to use an extension objects that contains the wanted extension functions.

More information how to write extension functions as part of an extension object -- for XslCompiledTransform can be found here:

http://msdn.microsoft.com/en-us/library/tf741884

and a full code example here:

http://msdn.microsoft.com/en-us/library/system.xml.xsl.xsltargumentlist.addextensionobject

Dimitre Novatchev
  • 240,661
  • 26
  • 293
  • 431
  • 1
    Hi Dimitre, Thanks for the response... I have already considered the approach you mentioned. But I want my C# code to be changeable without re-compiling. (Also, I don't have control over the code that run the transformation. I'm just writing the XSLT) I've also considered using EXSLT library, but it seems like .NET built in classes doesn't support it. – Madushan Jun 13 '12 at 05:19
  • @MadushanSiriwardena: If you don't have control, you must cooperate with the people whose code initiates the transformation -- they obviously know about your transformation. What exactly you want to achieve with the inline extension -- maybe it's achievable in pure XSLT 1.0? – Dimitre Novatchev Jun 13 '12 at 12:07
  • Sorry, I mean we're using a third party general purpose tool to run the XSLT as a part of the bigger system. So it's unlikely that I can ask the developers of the tool to change it. I'm trying to get system date into the result of the transformation. – Madushan Jun 13 '12 at 22:23
  • One way of getting the current date (or any external value) is to pass it as an external parameter to the transformation. Again, this requires coordination with the people, who initiate the transformation. Anyway, even the most elementary tool should support passing of external parameters. – Dimitre Novatchev Jun 13 '12 at 22:44