XslTransform.Load Method

Definition

Loads the XSLT style sheet, including style sheets referenced in xsl:include and xsl:import elements.

Overloads

Load(XPathNavigator, XmlResolver, Evidence)

Loads the XSLT style sheet contained in the XPathNavigator. This method allows you to limit the permissions of the style sheet by specifying evidence.

Load(IXPathNavigable, XmlResolver, Evidence)

Loads the XSLT style sheet contained in the IXPathNavigable. This method allows you to limit the permissions of the style sheet by specifying evidence.

Load(XPathNavigator, XmlResolver)
Obsolete.

Loads the XSLT style sheet contained in the XPathNavigator.

Load(IXPathNavigable, XmlResolver)
Obsolete.

Loads the XSLT style sheet contained in the IXPathNavigable.

Load(XmlReader, XmlResolver)
Obsolete.

Loads the XSLT style sheet contained in the XmlReader.

Load(XmlReader, XmlResolver, Evidence)

Loads the XSLT style sheet contained in the XmlReader. This method allows you to limit the permissions of the style sheet by specifying evidence.

Load(XPathNavigator)
Obsolete.

Loads the XSLT style sheet contained in the XPathNavigator.

Load(IXPathNavigable)
Obsolete.

Loads the XSLT style sheet contained in the IXPathNavigable.

Load(XmlReader)
Obsolete.

Loads the XSLT style sheet contained in the XmlReader.

Load(String)

Loads the XSLT style sheet specified by a URL.

Load(String, XmlResolver)

Loads the XSLT style sheet specified by a URL.

Remarks

Note

The XslTransform class is obsolete in the .NET Framework version 2.0. The XslCompiledTransform class is the new XSLT processor. For more information, see Using the XslCompiledTransform Class and Migrating From the XslTransform Class.

Load(XPathNavigator, XmlResolver, Evidence)

Loads the XSLT style sheet contained in the XPathNavigator. This method allows you to limit the permissions of the style sheet by specifying evidence.

public:
 void Load(System::Xml::XPath::XPathNavigator ^ stylesheet, System::Xml::XmlResolver ^ resolver, System::Security::Policy::Evidence ^ evidence);
public void Load (System.Xml.XPath.XPathNavigator stylesheet, System.Xml.XmlResolver resolver, System.Security.Policy.Evidence evidence);
member this.Load : System.Xml.XPath.XPathNavigator * System.Xml.XmlResolver * System.Security.Policy.Evidence -> unit
Public Sub Load (stylesheet As XPathNavigator, resolver As XmlResolver, evidence As Evidence)

Parameters

stylesheet
XPathNavigator

An XPathNavigator object containing the style sheet to load.

resolver
XmlResolver

The XmlResolver used to load any style sheets referenced in xsl:import and xsl:include elements. If this is null, external resources are not resolved.

The XmlResolver is not cached after the Load method completes.

evidence
Evidence

The Evidence set on the assembly generated for the script block in the XSLT style sheet.

If this is null, script blocks are not processed, the XSLT document() function is not supported, and privileged extension objects are disallowed.

The caller must have ControlEvidence permission in order to supply evidence for the script assembly. Semi-trusted callers can set this parameter to null.

Exceptions

The current node does not conform to a valid style sheet.

The referenced style sheet requires functionality that is not allowed by the evidence provided.

The caller tries to supply evidence and does not have ControlEvidence permission.

Examples

The following example performs an XSLT transformation using a style sheet from an outside source. Because the style sheet comes from an untrusted source, the resolver and evidence parameters are set to null.


public static void TransformFile (XPathNavigator xsltNav) {

 // Load the stylesheet.
 XslTransform xslt = new XslTransform();
 xslt.Load(xsltNav, null, null);

 // Transform the file.
 xslt.Transform("books.xml", "books.html", null);
}

public shared sub TransformFile (xsltNav as XPathNavigator) 
 
 ' Load the stylesheet.
 Dim xslt as XslTransform = new XslTransform()
 xslt.Load(xsltNav, nothing, nothing)

 ' Transform the file.
 xslt.Transform("books.xml", "books.html", nothing)
end sub

Remarks

Note

The XslTransform class is obsolete in the .NET Framework version 2.0. The XslCompiledTransform class is the new XSLT processor. For more information, see Using the XslCompiledTransform Class and Migrating From the XslTransform Class.

XslTransform supports the XSLT 1.0 syntax. The XSLT style sheet must include the namespace declaration xmlns:xsl= http://www.w3.org/1999/XSL/Transform.

The style sheet is loaded from the current position of the XPathNavigator. To use a portion of the loaded document as the style sheet, navigate to the node corresponding to the beginning of the style sheet. After the Load method returns, the XPathNavigator is positioned at the beginning of the style sheet (on the xsl:style sheet node).

There are different ways to provide evidence. The following table describes what type of evidence to provide for common user scenarios.

Scenario Type of evidence to provide
The XSLT style sheet is self-contained or comes from a code base that you trust. Use the evidence from your assembly.

XsltTransform xslt = new XslTransform(); 
xslt.Load(xslNav, resolver, this.GetType().Assembly.Evidence);
The XSLT style sheet comes from an outside source. The origin of the source is known, and there is a verifiable URL. Create evidence using the URL.

XsltTransform xslt = new XslTransform(); 
Evidence evidence = XmlSecureResolver.CreateEvidenceForUrl(style sheetURL); 
xslt.Load(xslNav,resolver,evidence);
The XSLT style sheet comes from an outside source. The origin of the source is not known. Set evidence to null. Script blocks are not processed, the XSLT document() function is not supported, and privileged extension objects are disallowed.

Additionally, you can also set the resolver parameter to null. This ensures that xsl:import and xsl:include elements are not processed.
The XSLT style sheet comes from an outside source. The origin of the source is not known, but you require script support. Request evidence from the caller. The API of the caller must provide a way to provide evidence, typically the Evidence class.

See also

Applies to

Product Introduced

Load(IXPathNavigable, XmlResolver, Evidence)

Loads the XSLT style sheet contained in the IXPathNavigable. This method allows you to limit the permissions of the style sheet by specifying evidence.

public:
 void Load(System::Xml::XPath::IXPathNavigable ^ stylesheet, System::Xml::XmlResolver ^ resolver, System::Security::Policy::Evidence ^ evidence);
public void Load (System.Xml.XPath.IXPathNavigable stylesheet, System.Xml.XmlResolver resolver, System.Security.Policy.Evidence evidence);
member this.Load : System.Xml.XPath.IXPathNavigable * System.Xml.XmlResolver * System.Security.Policy.Evidence -> unit
Public Sub Load (stylesheet As IXPathNavigable, resolver As XmlResolver, evidence As Evidence)

Parameters

stylesheet
IXPathNavigable

An object implementing the IXPathNavigable interface. In the .NET Framework, this can be either an XmlNode (typically an XmlDocument), or an XPathDocument containing the XSLT style sheet.

resolver
XmlResolver

The XmlResolver used to load any style sheets referenced in xsl:import and xsl:include elements. If this is null, external resources are not resolved.

The XmlResolver is not cached after the Load method completes.

evidence
Evidence

The Evidence set on the assembly generated for the script block in the XSLT style sheet.

If this is null, script blocks are not processed, the XSLT document() function is not supported, and privileged extension objects are disallowed.

The caller must have ControlEvidence permission in order to supply evidence for the script assembly. Semi-trusted callers can set this parameter to null.

Exceptions

The loaded resource is not a valid style sheet.

The referenced style sheet requires functionality that is not allowed by the evidence provided.

The caller tries to supply evidence and does not have ControlEvidence permission.

Remarks

Note

The XslTransform class is obsolete in the .NET Framework version 2.0. The XslCompiledTransform class is the new XSLT processor. For more information, see Using the XslCompiledTransform Class and Migrating From the XslTransform Class.

XslTransform supports the XSLT 1.0 syntax. The XSLT style sheet must include the namespace declaration xmlns:xsl= http://www.w3.org/1999/XSL/Transform.

There are different ways to provide evidence. The following table describes what type of evidence to provide for common user scenarios.

Scenario Type of evidence to provide
The XSLT style sheet is self-contained or comes from a code base that you trust. Use the evidence from your assembly.

XsltTransform xslt = new XslTransform(); 
xslt.Load(style sheet, resolver, this.GetType().Assembly.Evidence);
The XSLT style sheet comes from an outside source. The origin of the source is known, and there is a verifiable URL. Create evidence using the URL.

XsltTransform xslt = new XslTransform(); 
Evidence evidence = XmlSecureResolver.CreateEvidenceForUrl(style sheetURL); 
xslt.Load(style sheet,resolver,evidence);
The XSLT style sheet comes from an outside source. The origin of the source is not known. Set evidence to null. Script blocks are not processed, the XSLT document() function is not supported, and privileged extension objects are disallowed.

Additionally, you can also set the resolver parameter to null. This ensures that xsl:import and xsl:include elements are not processed.
The XSLT style sheet comes from an outside source. The origin of the source is not known, but you require script support. Request evidence from the caller. The API of the caller must provide a way to provide evidence, typically the Evidence class.

See also

Applies to

Product Introduced

Load(XPathNavigator, XmlResolver)

Caution

You should pass evidence to Load() method

Loads the XSLT style sheet contained in the XPathNavigator.

public:
 void Load(System::Xml::XPath::XPathNavigator ^ stylesheet, System::Xml::XmlResolver ^ resolver);
public void Load (System.Xml.XPath.XPathNavigator stylesheet, System.Xml.XmlResolver? resolver);
public void Load (System.Xml.XPath.XPathNavigator stylesheet, System.Xml.XmlResolver resolver);
[System.Obsolete("You should pass evidence to Load() method")]
public void Load (System.Xml.XPath.XPathNavigator stylesheet, System.Xml.XmlResolver resolver);
member this.Load : System.Xml.XPath.XPathNavigator * System.Xml.XmlResolver -> unit
[<System.Obsolete("You should pass evidence to Load() method")>]
member this.Load : System.Xml.XPath.XPathNavigator * System.Xml.XmlResolver -> unit
Public Sub Load (stylesheet As XPathNavigator, resolver As XmlResolver)

Parameters

stylesheet
XPathNavigator

An XPathNavigator object that contains the XSLT style sheet.

resolver
XmlResolver

The XmlResolver used to load any style sheets referenced in xsl:import and xsl:include elements. If this is null, external resources are not resolved.

The XmlResolver is not cached after the Load method completes.

Attributes

Exceptions

The current node does not conform to a valid style sheet.

The style sheet contains embedded scripts, and the caller does not have UnmanagedCode permission.

Remarks

Note

The XslTransform class is obsolete in the .NET Framework version 2.0. The XslCompiledTransform class is the new XSLT processor. For more information, see Using the XslCompiledTransform Class and Migrating From the XslTransform Class.

XslTransform supports the XSLT 1.0 syntax. The XSLT style sheet must include the namespace declaration xmlns:xsl= http://www.w3.org/1999/XSL/Transform.

The style sheet is loaded from the current position of the XPathNavigator. To use a portion of the loaded document as the style sheet, navigate to the node corresponding to the beginning of the style sheet. After the Load method returns, the XPathNavigator is positioned at the beginning of the style sheet (on the xsl:style sheet node).

If the style sheet contains embedded scripting, the script is compiled to an assembly. The assembly has full trust. The recommended practice is to provide evidence using the Load(XPathNavigator, XmlResolver, Evidence).

Note

If the caller does not have UnmanagedCode permission, the embedded script is not compiled and a SecurityException is thrown. See SecurityPermission and SecurityPermissionFlag.UnmanagedCode for more information.

See also

Applies to

Product Introduced

Load(IXPathNavigable, XmlResolver)

Caution

You should pass evidence to Load() method

Loads the XSLT style sheet contained in the IXPathNavigable.

public:
 void Load(System::Xml::XPath::IXPathNavigable ^ stylesheet, System::Xml::XmlResolver ^ resolver);
public void Load (System.Xml.XPath.IXPathNavigable stylesheet, System.Xml.XmlResolver? resolver);
public void Load (System.Xml.XPath.IXPathNavigable stylesheet, System.Xml.XmlResolver resolver);
[System.Obsolete("You should pass evidence to Load() method")]
public void Load (System.Xml.XPath.IXPathNavigable stylesheet, System.Xml.XmlResolver resolver);
member this.Load : System.Xml.XPath.IXPathNavigable * System.Xml.XmlResolver -> unit
[<System.Obsolete("You should pass evidence to Load() method")>]
member this.Load : System.Xml.XPath.IXPathNavigable * System.Xml.XmlResolver -> unit
Public Sub Load (stylesheet As IXPathNavigable, resolver As XmlResolver)

Parameters

stylesheet
IXPathNavigable

An object implementing the IXPathNavigable interface. In the .NET Framework, this can be either an XmlNode (typically an XmlDocument), or an XPathDocument containing the XSLT style sheet.

resolver
XmlResolver

The XmlResolver used to load any style sheets referenced in xsl:import and xsl:include elements. If this is null, external resources are not resolved.

The XmlResolver is not cached after the Load method completes.

Attributes

Exceptions

The loaded resource is not a valid style sheet.

The style sheet contains embedded scripts, and the caller does not have UnmanagedCode permission.

Remarks

Note

The XslTransform class is obsolete in the .NET Framework version 2.0. The XslCompiledTransform class is the new XSLT processor. For more information, see Using the XslCompiledTransform Class and Migrating From the XslTransform Class.

XslTransform supports the XSLT 1.0 syntax. The XSLT style sheet must include the namespace declaration xmlns:xsl= http://www.w3.org/1999/XSL/Transform.

If the style sheet contains embedded scripting, the script is compiled to an assembly. The assembly has full trust. The recommended practice is to provide evidence using the Load(IXPathNavigable, XmlResolver, Evidence) method.

Note

If the caller does not have UnmanagedCode permission, the embedded script is not compiled and a SecurityException is thrown. See SecurityPermission and SecurityPermissionFlag.UnmanagedCode for more information.

See also

Applies to

Product Introduced

Load(XmlReader, XmlResolver)

Caution

You should pass evidence to Load() method

Loads the XSLT style sheet contained in the XmlReader.

public:
 void Load(System::Xml::XmlReader ^ stylesheet, System::Xml::XmlResolver ^ resolver);
public void Load (System.Xml.XmlReader stylesheet, System.Xml.XmlResolver? resolver);
public void Load (System.Xml.XmlReader stylesheet, System.Xml.XmlResolver resolver);
[System.Obsolete("You should pass evidence to Load() method")]
public void Load (System.Xml.XmlReader stylesheet, System.Xml.XmlResolver resolver);
member this.Load : System.Xml.XmlReader * System.Xml.XmlResolver -> unit
[<System.Obsolete("You should pass evidence to Load() method")>]
member this.Load : System.Xml.XmlReader * System.Xml.XmlResolver -> unit
Public Sub Load (stylesheet As XmlReader, resolver As XmlResolver)

Parameters

stylesheet
XmlReader

An XmlReader object that contains the XSLT style sheet.

resolver
XmlResolver

The XmlResolver used to load any style sheets referenced in xsl:import and xsl:include elements. If this is null, external resources are not resolved.

The XmlResolver is not cached after the Load(XmlReader, XmlResolver) method completes.

Attributes

Exceptions

The current node does not conform to a valid style sheet.

The style sheet contains embedded scripts, and the caller does not have UnmanagedCode permission.

Remarks

Note

The XslTransform class is obsolete in the .NET Framework version 2.0. The XslCompiledTransform class is the new XSLT processor. For more information, see Using the XslCompiledTransform Class and Migrating From the XslTransform Class.

XslTransform supports the XSLT 1.0 syntax. The XSLT style sheet must include the namespace declaration xmlns:xsl= http://www.w3.org/1999/XSL/Transform.

This method loads the XSLT style sheet, including any style sheets referenced in xsl:include and xsl:import elements. 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 returns, 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).

If the style sheet contains entities, you should specify an XmlReader that can resolve entities (XmlReader.CanResolveEntity returns true). In this case, an XmlValidatingReader can be used.

If the style sheet contains embedded scripting, the script is compiled to an assembly. The assembly has full trust. The recommended practice is to provide evidence using the Load(XmlReader, XmlResolver, Evidence) method.

Note

If the caller does not have UnmanagedCode permission, the embedded script is not compiled and a SecurityException is thrown. See SecurityPermission and SecurityPermissionFlag.UnmanagedCode for more information.

See also

Applies to

Product Introduced

Load(XmlReader, XmlResolver, Evidence)

Loads the XSLT style sheet contained in the XmlReader. This method allows you to limit the permissions of the style sheet by specifying evidence.

public:
 void Load(System::Xml::XmlReader ^ stylesheet, System::Xml::XmlResolver ^ resolver, System::Security::Policy::Evidence ^ evidence);
public void Load (System.Xml.XmlReader stylesheet, System.Xml.XmlResolver resolver, System.Security.Policy.Evidence evidence);
member this.Load : System.Xml.XmlReader * System.Xml.XmlResolver * System.Security.Policy.Evidence -> unit
Public Sub Load (stylesheet As XmlReader, resolver As XmlResolver, evidence As Evidence)

Parameters

stylesheet
XmlReader

An XmlReader object containing the style sheet to load.

resolver
XmlResolver

The XmlResolver used to load any style sheets referenced in xsl:import and xsl:include elements. If this is null, external resources are not resolved.

The XmlResolver is not cached after the Load method completes.

evidence
Evidence

The Evidence set on the assembly generated for the script block in the XSLT style sheet.

If this is null, script blocks are not processed, the XSLT document() function is not supported, and privileged extension objects are disallowed.

The caller must have ControlEvidence permission in order to supply evidence for the script assembly. Semi-trusted callers can set this parameter to null.

Exceptions

The current node does not conform to a valid style sheet.

The referenced style sheet requires functionality that is not allowed by the evidence provided.

The caller tries to supply evidence and does not have ControlEvidence permission.

Examples

The following example performs an XSLT transformation where xsltReader is an XmlReader containing a style sheet and secureURL is a trusted URL that can be used to create Evidence. The XmlSecureResolver.CreateEvidenceForUrl method is used to create Evidence which is applied to the style sheet.

void TransformFile( XmlReader^ xsltReader, String^ secureURL )
{
   
   // Load the stylesheet using a default XmlUrlResolver and Evidence 
   // created using the trusted URL.
   XslTransform^ xslt = gcnew XslTransform;
   xslt->Load( xsltReader, gcnew XmlUrlResolver, XmlSecureResolver::CreateEvidenceForUrl( secureURL ) );
   
   // Transform the file.
   xslt->Transform("books.xml","books.html",gcnew XmlUrlResolver);
}


public static void TransformFile (XmlReader xsltReader, String secureURL) {

 // Load the stylesheet using a default XmlUrlResolver and Evidence
 // created using the trusted URL.
 XslTransform xslt = new XslTransform();
 xslt.Load(xsltReader, new XmlUrlResolver(), XmlSecureResolver.CreateEvidenceForUrl(secureURL));

 // Transform the file.
 xslt.Transform("books.xml", "books.html", new XmlUrlResolver());
}

public shared sub TransformFile (xsltReader as XmlReader, secureURL as String) 
 
 ' Load the stylesheet using a default XmlUrlResolver and Evidence 
 ' created using the trusted URL.
 Dim xslt as XslTransform = new XslTransform()
 xslt.Load(xsltReader, new XmlUrlResolver(), XmlSecureResolver.CreateEvidenceForUrl(secureURL))

 ' Transform the file.
 xslt.Transform("books.xml", "books.html", new XmlUrlResolver())
end sub

Remarks

Note

The XslTransform class is obsolete in the .NET Framework version 2.0. The XslCompiledTransform class is the new XSLT processor. For more information, see Using the XslCompiledTransform Class and Migrating From the XslTransform Class.

XslTransform supports the XSLT 1.0 syntax. The XSLT style sheet must include the namespace declaration xmlns:xsl= http://www.w3.org/1999/XSL/Transform.

This method loads the XSLT style sheet, including any style sheets referenced in xsl:include and xsl:import elements. 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 returns, 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).

If the style sheet contains entities, you should specify an XmlReader that can resolve entities (XmlReader.CanResolveEntity returns true). In this case, an XmlValidatingReader can be used.

There are different ways to provide evidence. The following table describes what type of evidence to provide for common user scenarios.

Scenario Type of evidence to provide
The XSLT style sheet is self-contained or comes from a code base that you trust. Use the evidence from your assembly.

XsltTransform xslt = new XslTransform(); 
xslt.Load(xslReader, resolver, this.GetType().Assembly.Evidence);
The XSLT style sheet comes from an outside source. The origin of the source is known, and there is a verifiable URL. Create evidence using the URL.

XsltTransform xslt = new XslTransform();
 Evidence evidence = XmlSecureResolver.CreateEvidenceForUrl(stylesheetURL); 
xslt.Load(xslReader,resolver,evidence);
The XSLT style sheet comes from an outside source. The origin of the source is not known. Set evidence to null. Script blocks are not processed, the XSLT document() function is not supported, and privileged extension objects are disallowed.

Additionally, you can also set the resolver parameter to null. This ensures that xsl:import and xsl:include elements are not processed.
The XSLT style sheet comes from an outside source. The origin of the source is not known, but you require script support. Request evidence from the caller. The API of the caller must provide a way to provide evidence, typically the Evidence class.

See also

Applies to

Product Introduced

Load(XPathNavigator)

Caution

You should pass evidence to Load() method

Loads the XSLT style sheet contained in the XPathNavigator.

public:
 void Load(System::Xml::XPath::XPathNavigator ^ stylesheet);
public void Load (System.Xml.XPath.XPathNavigator stylesheet);
[System.Obsolete("You should pass evidence to Load() method")]
public void Load (System.Xml.XPath.XPathNavigator stylesheet);
member this.Load : System.Xml.XPath.XPathNavigator -> unit
[<System.Obsolete("You should pass evidence to Load() method")>]
member this.Load : System.Xml.XPath.XPathNavigator -> unit
Public Sub Load (stylesheet As XPathNavigator)

Parameters

stylesheet
XPathNavigator

An XPathNavigator object that contains the XSLT style sheet.

Attributes

Exceptions

The current node does not conform to a valid style sheet.

The style sheet contains embedded scripts, and the caller does not have UnmanagedCode permission.

Remarks

Note

The XslTransform class is obsolete in the .NET Framework version 2.0. The XslCompiledTransform class is the new XSLT processor. For more information, see Using the XslCompiledTransform Class and Migrating From the XslTransform Class.

XslTransform supports the XSLT 1.0 syntax. The XSLT style sheet must include the namespace declaration xmlns:xsl= http://www.w3.org/1999/XSL/Transform.

This method loads the XSLT style sheet, including any style sheets referenced in xsl:include and xsl:import elements. External resources are resolved using an XmlUrlResolver with no user credentials. If the style sheet(s) are located on a network resource which requires authentication, use the overload that takes an XmlResolver as one of its arguments and specify an XmlResolver with the necessary credentials.

The style sheet is loaded from the current position of the XPathNavigator. To use just a portion of the loaded document as the style sheet, navigate to the node corresponding to the beginning of the style sheet. After the Load method returns, the XPathNavigator is positioned at the beginning of the style sheet (on the xsl:style sheet node).

If the style sheet contains embedded scripting, the script is compiled to an assembly. The assembly has full trust. The recommended practice is to provide evidence using the Load(XPathNavigator, XmlResolver, Evidence) method.

Note

If the caller does not have UnmanagedCode permission, the embedded script is not compiled and a SecurityException is thrown. See SecurityPermission and SecurityPermissionFlag.UnmanagedCode for more information.

Applies to

Product Introduced

Load(IXPathNavigable)

Caution

You should pass evidence to Load() method

Loads the XSLT style sheet contained in the IXPathNavigable.

public:
 void Load(System::Xml::XPath::IXPathNavigable ^ stylesheet);
public void Load (System.Xml.XPath.IXPathNavigable stylesheet);
[System.Obsolete("You should pass evidence to Load() method")]
public void Load (System.Xml.XPath.IXPathNavigable stylesheet);
member this.Load : System.Xml.XPath.IXPathNavigable -> unit
[<System.Obsolete("You should pass evidence to Load() method")>]
member this.Load : System.Xml.XPath.IXPathNavigable -> unit
Public Sub Load (stylesheet As IXPathNavigable)

Parameters

stylesheet
IXPathNavigable

An object implementing the IXPathNavigable interface. In the .NET Framework, this can be either an XmlNode (typically an XmlDocument), or an XPathDocument containing the XSLT style sheet.

Attributes

Exceptions

The loaded resource is not a valid style sheet.

The style sheet contains embedded scripts, and the caller does not have UnmanagedCode permission.

Remarks

Note

The XslTransform class is obsolete in the .NET Framework version 2.0. The XslCompiledTransform class is the new XSLT processor. For more information, see Using the XslCompiledTransform Class and Migrating From the XslTransform Class.

XslTransform supports the XSLT 1.0 syntax. The XSLT style sheet must include the namespace declaration xmlns:xsl= http://www.w3.org/1999/XSL/Transform.

This method loads the XSLT style sheet, including any style sheets referenced in xsl:include and xsl:import elements. External resources are resolved using an XmlUrlResolver with no user credentials. If the style sheet(s) are located on a network resource which requires authentication, use the overload that takes an XmlResolver as one of its arguments and specify an XmlResolver with the necessary credentials.

If the style sheet contains embedded scripting, the script is compiled to an assembly. The assembly has full trust. The recommended practice is to provide evidence using the Load(IXPathNavigable, XmlResolver, Evidence) method.

Note

If the caller does not have UnmanagedCode permission, the embedded script is not compiled and a SecurityException is thrown. See SecurityPermission and SecurityPermissionFlag.UnmanagedCode for more information.

Applies to

Product Introduced

Load(XmlReader)

Caution

You should pass evidence to Load() method

Loads the XSLT style sheet contained in the XmlReader.

public:
 void Load(System::Xml::XmlReader ^ stylesheet);
public void Load (System.Xml.XmlReader stylesheet);
[System.Obsolete("You should pass evidence to Load() method")]
public void Load (System.Xml.XmlReader stylesheet);
member this.Load : System.Xml.XmlReader -> unit
[<System.Obsolete("You should pass evidence to Load() method")>]
member this.Load : System.Xml.XmlReader -> unit
Public Sub Load (stylesheet As XmlReader)

Parameters

stylesheet
XmlReader

An XmlReader object that contains the XSLT style sheet.

Attributes

Exceptions

The current node does not conform to a valid style sheet.

The style sheet contains embedded scripts, and the caller does not have UnmanagedCode permission.

Examples

The following example transforms an XML file sorting all the books by title.

#using <System.Xml.dll>
#using <System.dll>

using namespace System;
using namespace System::IO;
using namespace System::Xml;
using namespace System::Xml::Xsl;
using namespace System::Xml::XPath;
int main()
{
   String^ filename = "books.xml";
   String^ stylesheet = "titles.xsl";
   
   // Create the reader to load the stylesheet. 
   // Move the reader to the xsl:stylesheet node.
   XmlTextReader^ reader = gcnew XmlTextReader( stylesheet );
   reader->Read();
   reader->Read();
   
   // Create the XslTransform object and load the stylesheet.
   XslTransform^ xslt = gcnew XslTransform;
   xslt->Load( reader );
   
   // Load the file to transform.
   XPathDocument^ doc = gcnew XPathDocument( filename );
   
   // Create an XmlTextWriter which outputs to the console.
   XmlTextWriter^ writer = gcnew XmlTextWriter( Console::Out );
   
   // Transform the file and send the output to the console.
   xslt->Transform(doc,nullptr,writer);
   writer->Close();
}

using System;
using System.IO;
using System.Xml;
using System.Xml.Xsl;
using System.Xml.XPath;

public class Sample
{
  private const String filename = "books.xml";
  private const String stylesheet = "titles.xsl";

  public static void Main()
  {
    //Create the reader to load the stylesheet.
    //Move the reader to the xsl:stylesheet node.
    XmlTextReader reader = new XmlTextReader(stylesheet);
    reader.Read();
    reader.Read();

    //Create the XslTransform object and load the stylesheet.
    XslTransform xslt = new XslTransform();
    xslt.Load(reader);

    //Load the file to transform.
    XPathDocument doc = new XPathDocument(filename);

    //Create an XmlTextWriter which outputs to the console.
    XmlTextWriter writer = new XmlTextWriter(Console.Out);

    //Transform the file and send the output to the console.
    xslt.Transform(doc, null, writer);
    writer.Close();
  }
}
Imports System.IO
Imports System.Xml
Imports System.Xml.Xsl
Imports System.Xml.XPath

public class Sample

  private const filename as String = "books.xml"
  private const stylesheet as String = "titles.xsl"

  public shared sub Main()

    'Create the reader to load the stylesheet. 
    'Move the reader to the xsl:stylesheet node.
    Dim reader as XmlTextReader = new XmlTextReader(stylesheet)
    reader.Read()
    reader.Read()

    'Create the XslTransform object and load the stylesheet.
    Dim xslt as XslTransform = new XslTransform()
    xslt.Load(reader)

    'Load the file to transform.
    Dim doc as XPathDocument = new XPathDocument(filename)
             
    'Create an XmlTextWriter which outputs to the console.
    Dim writer as XmlTextWriter = new XmlTextWriter(Console.Out)

    'Transform the file and send the output to the console.
    xslt.Transform(doc, nothing, writer)
    writer.Close()  

  end sub
end class

The example uses the following data files as input.

books.xml

<bookstore>
  <book genre="autobiography" publicationdate="1981" ISBN="1-861003-11-0">
    <title>The Autobiography of Benjamin Franklin</title>
    <author>
      <first-name>Benjamin</first-name>
      <last-name>Franklin</last-name>
    </author>
    <price>8.99</price>
  </book>
  <book genre="novel" publicationdate="1967" ISBN="0-201-63361-2">
    <title>The Confidence Man</title>
    <author>
      <first-name>Herman</first-name>
      <last-name>Melville</last-name>
    </author>
    <price>11.99</price>
  </book>
  <book genre="philosophy" publicationdate="1991" ISBN="1-861001-57-6">
    <title>The Gorgias</title>
    <author>
      <name>Plato</name>
    </author>
    <price>9.99</price>
  </book>
</bookstore>

titles.xsl

<!--Stylesheet to sort all books by title-->
<!--Created 2/13/2001-->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  <xsl:template match="bookstore">
      <books>
        <xsl:apply-templates select="book">
          <xsl:sort select="title"/>
        </xsl:apply-templates>
       </books>
   </xsl:template>
  <xsl:template match="book">
          <book><xsl:copy-of select="node()"/></book>
  </xsl:template>
</xsl:stylesheet>

Remarks

Note

The XslTransform class is obsolete in the .NET Framework version 2.0. The XslCompiledTransform class is the new XSLT processor. For more information, see Using the XslCompiledTransform Class and Migrating From the XslTransform Class.

XslTransform supports the XSLT 1.0 syntax. The XSLT style sheet must include the namespace declaration xmlns:xsl= http://www.w3.org/1999/XSL/Transform.

This method loads the XSLT style sheet, including any style sheets referenced in xsl:include and xsl:import elements. External resources are resolved using an XmlUrlResolver with no user credentials. If the style sheet(s) are located on a network resource which requires authentication, use the overload that takes an XmlResolver as one of its arguments and specify an XmlResolver with the necessary credentials.

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

If the style sheet contains entities, you should specify an XmlReader that can resolve entities (XmlReader.CanResolveEntity returns true). In this case, an XmlValidatingReader can be used.

If the style sheet contains embedded scripting, the script is compiled to an assembly. The assembly has full trust. The recommended practice is to provide evidence using the Load(XmlReader, XmlResolver, Evidence) method.

Note

If the caller does not have UnmanagedCode permission, the embedded script is not compiled and a SecurityException is thrown. See SecurityPermission and SecurityPermissionFlag.UnmanagedCode for more information.

Applies to

Product Introduced

Load(String)

Loads the XSLT style sheet specified by a URL.

public:
 void Load(System::String ^ url);
public void Load (string url);
member this.Load : string -> unit
Public Sub Load (url As String)

Parameters

url
String

The URL that specifies the XSLT style sheet to load.

Exceptions

The loaded resource is not a valid style sheet.

The style sheet contains embedded script, and the caller does not have UnmanagedCode permission.

Examples

The following example transforms an XML document into an HTML document. It displays the ISBN, title, and price for each book in a table.

#using <System.dll>
#using <System.Xml.dll>

using namespace System;
using namespace System::IO;
using namespace System::Xml;
using namespace System::Xml::Xsl;
using namespace System::Xml::XPath;

int main()
{
   String^ filename = "books.xml";
   String^ stylesheet = "output.xsl";

   //Load the stylesheet.
   XslTransform^ xslt = gcnew XslTransform;
   xslt->Load( stylesheet );

   //Load the file to transform.
   XPathDocument^ doc = gcnew XPathDocument( filename );

   //Create an XmlTextWriter which outputs to the console.
   XmlTextWriter^ writer = gcnew XmlTextWriter( Console::Out );

   //Transform the file and send the output to the console.
   xslt->Transform(doc,nullptr,writer,nullptr);
   writer->Close();
}
using System;
using System.IO;
using System.Xml;
using System.Xml.Xsl;
using System.Xml.XPath;

public class Sample
{
  private const String filename = "books.xml";
  private const String stylesheet = "output.xsl";

  public static void Main()
  {
    //Load the stylesheet.
    XslTransform xslt = new XslTransform();
    xslt.Load(stylesheet);

    //Load the file to transform.
    XPathDocument doc = new XPathDocument(filename);

    //Create an XmlTextWriter which outputs to the console.
    XmlTextWriter writer = new XmlTextWriter(Console.Out);

    //Transform the file and send the output to the console.
    xslt.Transform(doc, null, writer, null);
    writer.Close();
  }
}
Option Strict
Option Explicit

Imports System.IO
Imports System.Xml
Imports System.Xml.Xsl
Imports System.Xml.XPath

Public Class Sample
    Private Shared filename1 As String = "books.xml"
    Private Shared stylesheet1 As String = "output.xsl"
    
    
    Public Shared Sub Main()
        'Load the stylesheet.
        Dim xslt As New XslTransform()
        xslt.Load(stylesheet1)
        
        'Load the file to transform.
        Dim doc As New XPathDocument(filename1)
        
        'Create an XmlTextWriter which outputs to the console.
        Dim writer As New XmlTextWriter(Console.Out)
        
        'Transform the file and send the output to the console.
        xslt.Transform(doc, Nothing, writer, Nothing)
        writer.Close()
    End Sub
End Class

The sample uses the following two input files.

books.xml

<?xml version='1.0'?>
<!-- This file represents a fragment of a book store inventory database -->
<bookstore>
  <book genre="autobiography" publicationdate="1981" ISBN="1-861003-11-0">
    <title>The Autobiography of Benjamin Franklin</title>
    <author>
      <first-name>Benjamin</first-name>
      <last-name>Franklin</last-name>
    </author>
    <price>8.99</price>
  </book>
  <book genre="novel" publicationdate="1967" ISBN="0-201-63361-2">
    <title>The Confidence Man</title>
    <author>
      <first-name>Herman</first-name>
      <last-name>Melville</last-name>
    </author>
    <price>11.99</price>
  </book>
  <book genre="philosophy" publicationdate="1991" ISBN="1-861001-57-6">
    <title>The Gorgias</title>
    <author>
      <name>Plato</name>
    </author>
    <price>9.99</price>
  </book>
</bookstore>

output.xsl

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="bookstore">
  <HTML>
    <BODY>
      <TABLE BORDER="2">
        <TR>
          <TD>ISBN</TD>
          <TD>Title</TD>
          <TD>Price</TD>
        </TR>
        <xsl:apply-templates select="book"/>
      </TABLE>
    </BODY>
  </HTML>
</xsl:template>
<xsl:template match="book">
  <TR>
    <TD><xsl:value-of select="@ISBN"/></TD>
    <TD><xsl:value-of select="title"/></TD>
    <TD><xsl:value-of select="price"/></TD>
  </TR>
</xsl:template>
</xsl:stylesheet>

Remarks

Note

The XslTransform class is obsolete in the .NET Framework version 2.0. The XslCompiledTransform class is the new XSLT processor. For more information, see Using the XslCompiledTransform Class and Migrating From the XslTransform Class.

XslTransform supports the XSLT 1.0 syntax. The XSLT style sheet must include the namespace declaration xmlns:xsl="http://www.w3.org/1999/XSL/Transform".

This method loads the XSLT style sheet, including any style sheets referenced in xsl:include and xsl:import elements. External resources are resolved using an XmlUrlResolver with no user credentials. If the style sheet(s) are located on a network resource which requires authentication, use the overload that takes an XmlResolver as one of its arguments and specify an XmlResolver with the necessary credentials.

If the style sheet contains embedded scripting, the script is compiled to an assembly. The URI of the style sheet is used to create evidence, which is applied to the assembly.

Note

If the caller does not have UnmanagedCode permission, the embedded script is not compiled and a SecurityException is thrown. See SecurityPermission and SecurityPermissionFlag.UnmanagedCode for more information.

Applies to

Product Introduced

Load(String, XmlResolver)

Loads the XSLT style sheet specified by a URL.

public:
 void Load(System::String ^ url, System::Xml::XmlResolver ^ resolver);
public void Load (string url, System.Xml.XmlResolver? resolver);
public void Load (string url, System.Xml.XmlResolver resolver);
member this.Load : string * System.Xml.XmlResolver -> unit
Public Sub Load (url As String, resolver As XmlResolver)

Parameters

url
String

The URL that specifies the XSLT style sheet to load.

resolver
XmlResolver

The XmlResolver to use to load the style sheet and any style sheet(s) referenced in xsl:import and xsl:include elements.

If this is null, a default XmlUrlResolver with no user credentials is used to open the style sheet. The default XmlUrlResolver is not used to resolve any external resources in the style sheet, so xsl:import and xsl:include elements are not resolved.

The XmlResolver is not cached after the Load(String, XmlResolver) method completes.

Exceptions

The loaded resource is not a valid style sheet.

The style sheet contains embedded script, and the caller does not have UnmanagedCode permission.

Examples

The following example transforms an XML document into an HTML document. The example loads an XSLT style sheet which contains an xsl:include element referencing another style sheet. An XmlUrlResolver is passed to the Load method which sets the credentials necessary to access the network resource for the included style sheet.

using System;
using System.IO;
using System.Xml;
using System.Xml.XPath;
using System.Xml.Xsl;
using System.Net;

public class Sample
{
   private const String filename = "books.xml";
   private const String stylesheet = "sort.xsl";

   public static void Main()
   {
      //Create the XslTransform.
     XslTransform xslt = new XslTransform();

     //Create a resolver and set the credentials to use.
     XmlUrlResolver resolver = new XmlUrlResolver();
     resolver.Credentials = CredentialCache.DefaultCredentials;

     //Load the stylesheet.
     xslt.Load(stylesheet, resolver);

     //Load the XML data file.
     XPathDocument doc = new XPathDocument(filename);

     //Create the XmlTextWriter to output to the console.
     XmlTextWriter writer = new XmlTextWriter(Console.Out);

     //Transform the file.
     xslt.Transform(doc, null, writer, null);
     writer.Close();
  }
}
Imports System.IO
Imports System.Xml
Imports System.Xml.XPath
Imports System.Xml.Xsl
Imports System.Net

public class Sample

   private shared filename as String = "books.xml"
   private shared stylesheet as String = "sort.xsl"

   public shared sub Main()
   
     'Create the XslTransform.
     Dim xslt as XslTransform = new XslTransform()

     'Create a resolver and set the credentials to use.
     Dim resolver as XmlUrlResolver = new XmlUrlResolver()
     resolver.Credentials = CredentialCache.DefaultCredentials

     'Load the stylesheet.
     xslt.Load(stylesheet, resolver)

     'Load the XML data file.
     Dim doc as XPathDocument = new XPathDocument(filename)

     'Create the XmlTextWriter to output to the console.             
     Dim writer as XmlTextWriter = new XmlTextWriter(Console.Out)

     'Transform the file.
     xslt.Transform(doc, nothing, writer, nothing)
     writer.Close()

  end sub
end class

The example uses the following data files as input.

books.xml

<!-- This file represents a fragment of a book store inventory database -->
<bookstore>
  <book genre="autobiography" publicationdate="1981" ISBN="1-861003-11-0">
    <title>The Autobiography of Benjamin Franklin</title>
    <author>
      <first-name>Benjamin</first-name>
      <last-name>Franklin</last-name>
    </author>
    <price>8.99</price>
  </book>
  <book genre="novel" publicationdate="1967" ISBN="0-201-63361-2">
    <title>The Confidence Man</title>
    <author>
      <first-name>Herman</first-name>
      <last-name>Melville</last-name>
    </author>
    <price>11.99</price>
  </book>
  <book genre="philosophy" publicationdate="1991" ISBN="1-861001-57-6">
    <title>The Gorgias</title>
    <author>
      <name>Plato</name>
    </author>
    <price>9.99</price>
  </book>
</bookstore>

sort.xsl

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  <xsl:template match="bookstore"/>
  <xsl:include href="http://serverA/includefile.xsl"/>  
  <xsl:template match="book">
     <TR>
      <TD><xsl:value-of select="@ISBN"/></TD>
      <TD><xsl:value-of select="title"/></TD>
      <TD><xsl:value-of select="price"/></TD>
    </TR>
  </xsl:template>
</xsl:stylesheet>

includefile.xsl

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="bookstore">
  <HTML>
    <BODY>
    <TABLE BORDER="2">
      <TR>
        <TD>ISBN</TD>
        <TD>Title</TD>
        <TD>Price</TD>
      </TR>
    <xsl:apply-templates select="book">
      <xsl:sort select="@ISBN"/>
    </xsl:apply-templates>
    </TABLE>
    </BODY>
  </HTML>
</xsl:template>
</xsl:stylesheet>

Remarks

Note

The XslTransform class is obsolete in the .NET Framework version 2.0. The XslCompiledTransform class is the new XSLT processor. For more information, see Using the XslCompiledTransform Class and Migrating From the XslTransform Class.

XslTransform supports the XSLT 1.0 syntax. The XSLT style sheet must include the namespace declaration xmlns:xsl= http://www.w3.org/1999/XSL/Transform.

If the style sheet contains embedded scripting, the script is compiled to an assembly. The URI of the style sheet is used to create evidence, which is applied to the assembly.

Note

If the caller does not have UnmanagedCode permission, the embedded script is not compiled and a SecurityException is thrown. See SecurityPermission and SecurityPermissionFlag.UnmanagedCode for more information.

See also

Applies to

Product Introduced