Mono Class Library: System.Xml.Xsl.XsltArgumentList Overview | Members

System.Xml.Xsl.XsltArgumentList.AddExtensionObject Method

Associates an extension object with a namespace to provide added functionality to XPath expressions in the System.Xml.Xsl.XslTransform.

public void AddExtensionObject (string namespaceUri, object extension)

Parameters

namespaceUri
The URI of the namespace to associate with the extension object.
extension
The extension object.

Remarks

The static and instance methods of extension are made available to XSLT stylesheets via XPath function calls.

The arguments and return type of extension methods can be the basic numeric types, strings, System.Xml.XPath.XPathNavigator objects, and System.Xml.XPath.XPathNodeIterator objects. Using XPathNavigators and XPathNodeIterators allows the extension method to receive and pass back node sets.

Only one extension object may be associated with any namespace, and the http://www.w3.org/1999/XSL/Transform namespace may not be used.

The following example makes a string length function available to an XSLT stylesheet.

C# Example

class MyExtObject {
	public int GetStringLength(string s) {
		return s.Length;
	}
}

(...elsewhere...)

XsltArgumentList args = new XsltArgumentList();
args.AddExtensionObject("http://www.mydomain.com/mynamespace", new MyExtObject());
XmlReader result = stylesheet.Transform(doc, args);
  

The stylesheet accesses this function by declaring the namespace and then using XPath:

XML Example

<template match="mynode" xmlns:ext="http://www.mydomain.com/mynamespace">
   <xsl:value-of select="ext:GetStringLength('MyString')"/>
</template>

Requirements

Namespace: System.Xml.Xsl
Assembly: System.Xml (in System.Xml.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0