Resolving External XSLT Style Sheets and Documents

There are several times during a transformation when you may need to resolve external resources.

Note

The XslTransform class is obsolete in the .NET Framework version 2.0. You can perform Extensible Stylesheet Language for Transformations (XSLT) transformations using the XslCompiledTransform class. See Using the XslCompiledTransform Class and Migrating From the XslTransform Class for more information.

There are several times during a transformation when you may need to resolve external resources:

  • During the Load to locate an external style sheet.

  • During Load to resolve any <xsl:include> or <xsl:import> elements found in the style sheet.

  • During Transform to resolve any document() functions.

Using the XmlResolver Class

If authentication is required to access a network resource, use the Load methods that have an XmlResolver parameter to pass the XmlResolver object, which has the necessary credential properties set.

If you have a custom XmlResolver that you want to use, or if you need to specify different credentials, the following table lists the task required, depending on when the external resource needs resolution.

What process requires resolution

Task required

During Load to locate the style sheet.

Specify the overloaded Load method that takes, as a parameter, an XmlResolver if the style sheet is on a resource that requires credentials.

During Load to resolve <xsl:include> or <xsl:import>.

Specify the overloaded Load method that takes, as a parameter, an XmlResolver. The XmlResolver is used to load the style sheets referenced by the import or include statements. If you pass in null, the external resources are not resolved.

During a transformation to resolve any document() functions.

Specify the XmlResolver during the transformation by using the Transform method that takes an XmlResolver argument.

The document() function retrieves other XML resources from a style sheet, in addition to the initial XML data provided by the input stream. Since this function allows the inclusion of XML data that can be located elsewhere, an XmlResolver with a null value supplied to the Transform method prevents the document() function from executing. If you want to use the document() function, use the Transform method that takes an XmlResolver as a parameter, in addition to having the appropriate permission set.

For more information on the Load method and its use of the XmlResolver, see XslTransform.Load(String, XmlResolver). For more information on the XmlResolver class, see Resolving Resources Using the XmlResolver and XmlResolver Class.

When the Transform method is called, permissions are calculated against the evidence provided at load time, and that permission set is assigned to the entire transformation process. If the document() function attempts to initiate an action that requires permissions not found in the set, an exception is thrown.

See Also

Concepts

XSLT Transformations with the XslTransform Class

XslTransform Class Implements the XSLT Processor

Outputs from an XslTransform

XSLT Transformations Over Different Stores

XsltArgumentList for Style Sheet Parameters and Extension Objects

XSLT Stylesheet Scripting Using <msxsl:script>

Support for the msxsl:node-set() Function

XPathNavigator in Transformations

XPathNodeIterator in Transformations

XPathDocument Input to XslTransform

XmlDataDocument Input to XslTransform

XmlDocument Input to XslTransform