This documentation is archived and is not being maintained.

XslCompiledTransform.Load Method (MethodInfo, Byte[], Type[])

Loads a method from a style sheet compiled using the XSLTC.exe utility.

Namespace:  System.Xml.Xsl
Assembly:  System.Xml (in System.Xml.dll)

public void Load(
	MethodInfo executeMethod,
	byte[] queryData,
	Type[] earlyBoundTypes


Type: System.Reflection.MethodInfo

A MethodInfo object representing the compiler-generated execute method of the compiled style sheet.

Type: System.Byte[]

A byte array of serialized data structures in the staticData field of the compiled style sheet as generated by the CompileToType method.

Type: System.Type[]

An array of types stored in the compiler-generated ebTypes field of the compiled style sheet.

This method accepts a compiled style sheet in the form of a MethodInfo object, a byte array, and a type array. DynamicMethod objects may be used to allow compiled style sheet methods to be discarded when the XslCompiledTransform object is reclaimed.

The code example below uses the Load to load a compiled style sheet. The transformation reduces the value of the Price element by ten percent.

using System;
using System.IO;
using System.Reflection;
using System.Xml;
using System.Xml.Xsl;

class Example
    static void Main()
        // Load a stylesheet compiled using the XSLTC.EXE utility
        Type compiledStylesheet = Assembly.Load("Transform").GetType("Transform");

        // Extract private members from the compiled stylesheet
        BindingFlags bindingFlags = BindingFlags.NonPublic | BindingFlags.Static;
        MethodInfo executeMethod = compiledStylesheet.GetMethod("Execute", bindingFlags);
        object staticData = compiledStylesheet.GetField("staticData", bindingFlags).GetValue(null);
        object earlyBoundTypes = compiledStylesheet.GetField("ebTypes", bindingFlags).GetValue(null);

        // Load into XslCompiledTransform
        XslCompiledTransform xslt = new XslCompiledTransform();
        xslt.Load(executeMethod, (byte[])staticData, (Type[])earlyBoundTypes);

        // Run the transformation
        xslt.Transform(XmlReader.Create(new StringReader("<Root><Price>9.50</Price></Root>")), (XsltArgumentList)null, Console.Out);

The "Transform" assembly used in this example was built using the xsltc.exe utility. For detailed information on using this command line tool, see How to: Perform an XSLT Transformation by Using an Assembly.

The code example above uses the following transformation:

<xsl:stylesheet version="1.0" xmlns:xsl=""
  <msxsl:script language="C#" implements-prefix="user">
  public double modifyPrice(double price){
    return price;
  <xsl:template match="Root">
    <Root xmlns="">
      <Price><xsl:value-of select="user:modifyPrice(Price)"/></Price>

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5 SP1, 3.0 SP1, 2.0 SP1