Sometimes it's useful to detect which XSLT engine your XSLT stylersheet is being executed by, e.g. to shortcut processing using an engine-specific extension function or to workaround a bug in particlular engine. Now that Microsoft alone ships 3 different XSLT engines - MSXML3/MSXML4/MSXML5/MSXML6, XslTransform and XslCompiledTransform, detecting XSLT engine from within XSLT stylesheet may be vital requirement. Here is how it can be done.
MSXML supports "ms:version" system property, which can be retrieved using standard XSLT system-property() function. The value returned is MSXML version - "3", "4", "5" and so on. XslTransform doesn't support "ms:version" property and returns empty string (just like any other non-Microsoft XSLT engine). But new XslCompiledTransform does support it and "returns a string representing the version of the assembly implementing XslCompiledTransform in the same format as returned by Assembly.ImageRuntimeVersion property ('v2.0.50727' for .NET Framework 2.0)."
This, along with standard 'xsl:vendor' property should give us enough information to differentiate between Microsoft XSLT engines. Here is a sample XSLT stylesheet that does the trick:
This XSLT stylesheet is being executed using
Leave a comment