Project

Profile

Help

XsltTransformer and threadsafety

Added by Jihad Haddad over 10 years ago

Hi

I just began using Saxon to test to see how it will apply to our product. We have an ASP.Net website and part of the HTML we emit should be produced through an XSL transformation. I found out that the Saxon XsltTransformer class can be used to perform XSL transformations, but the documentation also states that it is not thread safe. Does that mean that I cannot use the same XsltTransformer object simultaneously to perform and XSL tranformation, or can I assume that lack of thread safety only applies to loading and compiling the XSL file, as is the case with .Net own XSLT transformer XslCompiledTransform (see http://msdn.microsoft.com/en-us/library/system.xml.xsl.xslcompiledtransform(v=vs.110).aspx under Thread Safety)

The thing is that our XSL file is 1.5 Mb large, and it requires a lot of resources to load and compile it.

Thank you in advance Jihad


Replies (1)

RE: XsltTransformer and threadsafety - Added by Michael Kay over 10 years ago

The result of compiling a stylesheet is an XsltExecutable. The XsltExecutable can be used as often as you like in as many threads as you like; it is effectively immutable once created. By contrast, the XsltTransformer holds the input, output, and intermediate state of a running transformation, which means it must not be used to run more than one transformation at a time.

So the answer is, compile your stylesheet to an XsltExecutable, and then use that simultaneously in as many threads as you like. To use it, use the Load() method to create an XsltTransformer, supply the parameters and other per-transformation details to the XsltTransformer, and then call XsltTransformer.Run().

    (1-1/1)

    Please register to reply