Detecting version of Microsoft XSLT engine from within XSLT

| No Comments | 1 TrackBack

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:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ms="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="ms"> <xsl:template match="/"> <p> This XSLT stylesheet is being executed using <xsl:choose> <xsl:when test="system-property('xsl:vendor') = 'Microsoft'"> <xsl:text>Microsoft </xsl:text> <xsl:variable name="ms-version" select="system-property('ms:version')"/> <xsl:choose> <xsl:when test="$ms-version = ''">XslTransform</xsl:when> <xsl:when test="starts-with($ms-version, 'v')">XslCompiledTransform</xsl:when> <xsl:otherwise> MSXML <xsl:value-of select="$ms-version" /> </xsl:otherwise> </xsl:choose> </xsl:when> <xsl:otherwise> Unrecognized XSLT engine from '<xsl:value-of select="system-property('xsl:vendor')" />' </xsl:otherwise> </xsl:choose> </p> </xsl:template> </xsl:stylesheet>

Through a solid Microsoft Exchange server in-house or paying for Exchange email outsourcing you'll have access to a Microsoft Exchange server that lets you access email and shared calendars worldwide through Exchange 2007 hosting software.

Related Blog Posts

1 TrackBack

TrackBack URL: http://www.tkachenko.com/cgi-bin/mt-tb.cgi/562

Leave a comment