Export (0) Print
Expand All

XslCompiledTransform.Load Method (XmlReader)

Compiles the style sheet contained in the XmlReader.

Namespace:  System.Xml.Xsl
Assembly:  System.Xml (in System.Xml.dll)

public void Load(
	XmlReader stylesheet
)

Parameters

stylesheet
Type: System.Xml.XmlReader

An XmlReader containing the style sheet.

ExceptionCondition
ArgumentNullException

The stylesheet value is null.

XsltException

The style sheet contains an error.

The XslCompiledTransform class supports the XSLT 1.0 syntax. The XSLT style sheet must use the http://www.w3.org/1999/XSL/Transform namespace.

The style sheet loads from the current node of the XmlReader through all its children. This enables you to use a portion of a document as the style sheet. After the Load method completes, the XmlReader is positioned on the next node after the end of the style sheet. If the end of the document is reached, the XmlReader is positioned at the end of file (EOF).

This method has the following behavior:

  • An XmlUrlResolver with no user credentials is used to process any xsl:import or xsl:include elements.

  • The document() function is disabled.

  • Embedded scripts are not supported.

You can use the Load(XmlReader, XsltSettings, XmlResolver) overload to specify an XmlResolver with the necessary authentication credentials, or to specify different XSLT settings.

The following example loads a style sheet contained in an XmlReader object.

// Create a reader that contains the style sheet.
XmlReader reader = XmlReader.Create("titles.xsl");
reader.ReadToDescendant("xsl:stylesheet");

// Load the style sheet.
XslCompiledTransform xslt = new XslCompiledTransform();
xslt.Load(reader);

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
Show:
© 2015 Microsoft