Article ID: 313997 - View products that this article applies to.
This article was previously published under Q313997
This article provides a roadmap to introduce the .NET Framework namespaces and classes that you can use to programmatically execute Extensible Stylesheets Language Transformation (XSLT) transformations in .NET applications. Roadmap articles provide links to useful information, including online documentation, Microsoft Knowledge Base articles, and Microsoft white papers, to help you learn about a Microsoft product or technology.
This article is not an XSLT tutorial. This article assumes that you are familiar with the World Wide Web Consortium (W3C) XSLT standard
(http://www.w3.org/TR/xslt)and have experience with writing XSLT style sheets to transform XML data.
From the developer perspective, XSLT is a programming language with a rich, XML-based syntax that implements elements that correspond to programming constructs and elements to address common transformation requirements.
XSLT style sheets frequently use XML Path Language (XPath) queries to locate nodes in the source XML document and to apply XSLT templates to transform these nodes. The efficiency of the XPath queries in an XSLT style sheet frequently influence and affect the performance of transformations that use it.
From a high-level stand point, an XSLT processor is a software component that applies a specified style sheet to a specified source XML document to execute an XSLT transformation and to generate the required output.
The final output that the XSLT transformations generate are typically result documents that present the original XML data in the specified target format.
(http://support.microsoft.com/kb/307322/EN-US/ )HOW TO: Apply an XSL Transformation to an XML Document by Using Visual C# .NET
300929W3C XSLT Recommendation
(http://support.microsoft.com/kb/300929/EN-US/ )HOW TO: Apply an XSL Transformation from an XML Document to an XML Document by Using Visual Basic .NET
The System.Xml.Xsl namespace also implements the following classes to support XSLT exception handling and advanced options that are related to the execution of XSLT transformations and XPath queries:
This method is useful when you must persist the output that the intermediate phases generate for additional processing that is not directly tied into the transformation process. For additional information about this topic and for a code sample that illustrates its usage, click the article number below to view the article in the Microsoft Knowledge Base:
(http://support.microsoft.com/kb/320847/EN-US/ )HOW TO: Pipeline XSLT Transformations in .NET Applications
In .NET applications, an XsltArgumentList object is used to supply values for XSLT parameters at execution time. The AddParam method is used to add a name-value pair that represents a parameter that is defined in the style sheet and its value to an XsltArgumentList object. The XsltArgumentList object is then supplied as a parameter when executing the Transform method of the XslTransform object that is used to execute the transformation.
The GetParam and the RemoveParam methods are used to access and to remove individual parameters that are added to an XsltArgumentList object. For additional information about how to execute parameterized XSLT transformation in .NET applications, click the article number below to view the article in the Microsoft Knowledge Base:
(http://support.microsoft.com/kb/321704/EN-US/ )HOW TO: Execute Parameterized XSL Transformations in .NET Applications
In the .NET Framework, custom inline functions and subroutines are coded in <msxsl:script> blocks in the XSLT style sheet. You can use a Microsoft Visual Studio .NET programming language such as Microsoft Visual Basic .NET or Microsoft Visual C# .NET to implement these routines.
One of the drawbacks that is associated with using inline script blocks is that they make the XSLT style sheets non-portable. The technology, the tags, and the semantics that are used to implement inline script blocks are vendor-specific extensions that the W3C XSLT specifications do not standardize.
You can only use an XSLT style sheet that defines and uses inline script blocks successfully in transformations that are executed by using an XSLT processor that can interpret the related semantics and integrate with the technology that has to execute the code.
In the .NET Framework, managed assemblies are generated and loaded implicitly to execute the code that is contained in inline <msxsl:script> script blocks. There is currently a known problem in the .NET Framework that prevents these assemblies from being correctly unloaded when the transformation process completes. This anomaly can lead to an increase in memory usage if the affected style sheet is repeatedly loaded to execute XSLT transformations. The unreleased memory is released only when the host process is recycled. For additional information about this problem in the .NET Framework, click the article number below to view the article in the Microsoft Knowledge Base:
316775To work around this problem in Microsoft ASP.NET applications, you can load the affected style sheets only one time during the life of the application, cache the affected style sheets (in the ASP.NET cache), and then reuse the cached versions for transformations after that.
(http://support.microsoft.com/kb/316775/EN-US/ )PRB: Cannot Unload Assemblies That You Create and Load by Using Script in XSLT
In Windows Forms and Console applications, you can use global XslTransform object instances to load the affected style sheets when the application starts and to execute later transformations. These workarounds do not apply when XSLT transformations have to be executed in stateless environments (for example, with middle-tier Enterprise Services components).
Microsoft recommends that you use XSLT extension objects to implement custom XPath extension functions to work around this problem.
You can create .NET Framework DLLs to implement and to use Extension objects when you execute transformations in .NET applications. The custom subroutines and functions are implemented in a DLL, and an object instance of the DLL component is provided as a run-time parameter by using an XsltArgumentList object when you execute the Transform method of an XslTransform object.
The AddExtensionObject method of the XsltArgumentList class is used to add an Extension object instance to an XsltArgumentList object. You can use the Get and the Remove methods of the Extension object to access and to remove an Extension object instance that is added to an XsltArgumentList object.
The W3C XSLT specification addresses the concept and the use of Extension elements and functions without any heed or reference to the base technology that you must use to implement them. You must define and use standards-based XML namespace prefixes in style sheets to reference functions and subroutines that are implemented in Extension objects. Vendors can select a technology that is best suited to their platform to address the implementation aspects of the Extension objects. For additional information about the concept and the use of XSLT Extension objects in the .NET Framework and for steps to create an end-to-end application that demonstrates how to use Extension objects when you execute XSLT transformations in .NET applications, click the article number below to view the article in the Microsoft Knowledge Base:
(http://support.microsoft.com/kb/321702/EN-US/ )HOW TO: Use Extension Objects When You Execute XSL Transformations in Visual Basic .NET Applications
(http://support.microsoft.com/kb/325689/EN-US/ )INFO: Performance of XSLT Transformations in the .NET Framework
Searching the Knowledge Base
Microsoft Product Support Services
For additional information%1, click the article number%2 below to view the article%2 in the Microsoft Knowledge Base:
(http://support.microsoft.com/kb/313651/EN-US/ )INFO: Roadmap for XML in the .NET Framework