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 2.0. You can perform Extensible Stylesheet Language for Transformations (XSLT) transformations using the XslCompiledTransform class.

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

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