Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

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
)

Parameters

executeMethod
Type: System.Reflection.MethodInfo

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

queryData
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.

earlyBoundTypes
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);
    }
}
NoteNote:

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="http://www.w3.org/1999/XSL/Transform"
  xmlns:msxsl="urn:schemas-microsoft-com:xslt"
  xmlns:user="urn:my-scripts">
  <msxsl:script language="C#" implements-prefix="user">
    <![CDATA[
  public double modifyPrice(double price){
    price*=0.9;
    return price;
  }
  ]]>
  </msxsl:script>
  <xsl:template match="Root">
    <Root xmlns="">
      <Price><xsl:value-of select="user:modifyPrice(Price)"/></Price>
    </Root>
  </xsl:template>
</xsl:stylesheet>

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
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.