Wednesday, November 30, 2022
Code Search
Code Bank
.NET Applications
XSD Schema Generator
.NET/XML Training


Using the XSLT document() function in .NET 1.1

Version 1.1 of the .NET platform sports a slightly different XslTransform object with more secure Load() and Transform() methods. Many of the overloaded versions of the Transform() method from version 1.0 of .NET are now considered to be obsolete. If you take a closer look at the Transform() method (in the documentation for version 1.1 of the framework) you’ll see that the new overloads expect you to pass an instance of an XmlResolver. An example of one of these overloads is shown below:

public void Transform(XPathNavigator, XsltArgumentList, TextWriter, XmlResolver);

This a little confusing for some because XmlResolver is an abstract class that cannot be created directly. However, a class named XmlUrlResolver derives from XmlResolver and can be instantiated using the familiar “new” keyword in VB.NET or C#. In cases where basic XSLT transformations (transformations that involve a single XML document) must be performed, a null (Nothing in VB.NET) can be passed for the XmlResolver parameter as shown below:

StringWriter sw = new StringWriter(); XslTransform xsl = new XslTransform(); xsl.Load(xslPath); //A null XmlResolver is passed for this basic transformation xsl.Transform(xmlDoc,null,sw,null); lblOutput.Text = sw.ToString();

Passing null for the XmlResolver parameter when more than one XML document is involved in the transformation presents a problem. If you need to use the document() function to transform multiple XML documents simultaneously, then passing a null will cause these external documents to be ignored. The demo code for this sample application demonstrates how to properly call the Transform() method of the XslTransform class when the document() function must be used to transform multiple XML documents.

Teaches XML, XSLT, XslTransform, XmlUrlResolver
Requirements .NET 1.1
Article: Click Here
Example: Click Here
View Source Code: Click Here
Download Code: Click Here


.NET, SharePoint and Silverlight Training Solutions
    Online, Onsite and Video Training on .NET and SharePoint technologies available through The Wahlin Group.

© 2007 Wahlin Consulting LLC
XML for ASP.NET Developers in bookstores