Welcome   |   ASP.NET   |   Web Services   |   How Do I...?   |   Class Browser
  |   I want my samples in...   

How Do I...? Common Tasks QuickStart Tutorial

Go To...

How Do I...Use an Extension Object in an XSLT Style Sheet?

The XsltArgumentList class contains XSLT parameters and XSLT extension objects. When passed into the Execute method, these parameters and extension objects can be invoked from style sheets.

C# ExtensionObject.exe
View Source

[This sample can be found at M:\web\users\Sites\AspnetQuickStart\v2.0\QuickStart\howto\samples\Xml\ExtensionObject\
To build this sample, open the SDK command prompt and navigate to the above path. Build the sample using the build tool msbuild passing the solution file as the first parameter: msbuild mySample.sln. The compiled executable will be found in the sub directory \bin directory.]

XSLT extension objects are added to the XsltArgumentList using the AddExtensionObject method. A qualified name and namespace URI are associated with the extension object at that time.

		
//Create an XsltArgumentList
XsltArgumentList xslArg = new XsltArgumentList();

//Add an object to calculate the circumference of the circle.
Calculate obj = new Calculate();
xslArg.AddExtensionObject("urn:myObj", obj);
C#

The following code creates the XSLT processor and executes the transformation. By passing in the XsltArgumentList object to the Execute method, the extension object is now usable by the XSLT processor.

		
//Create XslCompiledTransform and compile stylesheet.
XslCompiledTransform processor = new XslCompiledTransform();
...
//Create an XmlWriter to output to the console.   
using (XmlWriter writer = XmlWriter.Create(Console.Out))
{
    //Transform the file.
    processor.Transform(filename, xslArg, writer);
}
C#

Summary

  1. The XsltArgumentList class extends XSLT functionality by allowing you to add extension objects and parameters.
  2. Use the AddExtensionObject method to add the extension object.
  3. Invoke the extension object in the style sheet.
  4. Pass the XsltArgumentList object to the Transform method.



Microsoft .NET Framework SDK QuickStart Tutorials Version 2.0
Copyright � 2005 Microsoft Corporation. All rights reserved.


Hosted by MaximumASP | Found a broken link? | Contact Us | Terms and conditions | Privacy Policy | Advertise with us
� 2000 - 2008  Mindcracker LLC. All Rights Reserved