SAXONICA

Saxon Documentation
Full Contents
About Saxon
Changes in this Release
Conditions of Use
Using XSLT 2.0
Using XQuery
Handling Source Documents
XML Schema Processing
XPath API for Java
Saxon on .NET
Extensibility
| Introduction
| Writing extension functions in Java
| Converting Arguments to Java Extension Functions
| Converting the Result of a Java Extension Function
» | Writing extension functions for .NET
| Converting Arguments to .NET Extension Functions
| Converting the Result of a .NET Extension Function
| Writing XSLT extension instructions
| Customizing Serialization
| Implementing a collating sequence
| Localizing numbers and dates
| Adding an output encoding
| Writing a URI Resolver for Input Files
| Writing a URI Resolver for Output Files
Saxon Extensions
Sample Saxon Applications
The Saxon SQL Extension
XSLT Elements
XPath 2.0 Expression Syntax
Function Library
Standards Conformance

# Calling .NET Instance-Level Methods

Instance-level methods (that is, non-static methods) are called by supplying an extra first argument of type .NET Object which is the object on which the method is to be invoked. A .NET Object is usually created by calling an extension function (e.g. a constructor) that returns an object; it may also be passed to the style sheet as the value of a global parameter. Matching of method names is done as for static methods. If there are several methods in the class that match the localname, the system again tries to find the one that is the best fit, according to the types of the supplied arguments.

For example, the following XSLT stylesheet prints the operating system name and version.

    <xsl:stylesheet version="2.0"
    				xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

    <xsl:template name="main">
      <out xmlns:env="clitype:System.Environment" xmlns:os="clitype:System.OperatingSystem">
        <xsl:variable name="os" select="env:OSVersion()"/>
          <v platform="{os:Platform($os)}" version="{os:Version($os)}"/>
      </out>
    </xsl:template>
    </xsl:stylesheet>

The equivalent in XQuery is:

    declare namespace env="clitype:System.Environment";
    declare namespace os="clitype:System.OperatingSystem";
    let $os := env:OSVersion() return
    <v platform="{os:Platform($os)}" version="{os:Version($os)}"/>

If any exceptions are thrown by the method, or if a matching method cannot be found, processing of the stylesheet will be abandoned. If the tracing option has been set (-TJ) on the command line, a full stack trace will be output. The exception will be wrapped in a `TransformerException` and passed to any user-specified `ErrorListener` object, so the `ErrorListener` can also produce extra diagnostics.

Next