Now that XslCompiledTransform in .NET 2.0 supports exsl:object-type() extension function I think a little intro is needed as this is really new function for Microsoft-oriented XSLT developers.
exsl:object-type() function brings a bit of reflection functionality into XSLT allowing dynamic type identification at runtime. That is using exsl:object-type() one can determine type of an object, e.g. a type of passed parameter value. In XSLT 1.0 type system that means 'string', 'number', 'boolean', 'node-set', 'RTF' or 'external':
For a sample of defensive programming using exsl:object-type() function consider the following dummy stylesheet:
XslTransformException --------------------- To use a result tree fragment in a path expression, first convert it to a node-set using the msxsl:node-set() function.Well, as usual with automatic error messages - at least unclear. Now with object type check you should get this:
XslTransformException --------------------- util42 template expects parameter $nodes to be a nodeset, not 'RTF'!Definitely more meaningful and safe. And of course it's now up to template author whether to terminate transformation or to recover.
Pretty useful fiunction. And when it comes to QA - that's a godsend. As a matter of interest, AFAIK exsl:object-type() function was implemented to help Microsoft XML Team with XslCompiledTransform testing in the first place.
Leave a comment