XslCompiledTransform.Load 方法

定义

编译样式表。Compiles the style sheet.

重载

Load(IXPathNavigable, XsltSettings, XmlResolver)

编译 IXPathNavigable 中包含的 XSLT 样式表。Compiles the XSLT style sheet contained in the IXPathNavigable. XmlResolver 可以解析任何 XSLT importinclude 元素,而 XSLT 设置决定了样式表的权限。The XmlResolver resolves any XSLT import or include elements and the XSLT settings determine the permissions for the style sheet.

Load(String, XsltSettings, XmlResolver)

加载和编译 URI 指定的 XSLT 样式表。Loads and compiles the XSLT style sheet specified by the URI. XmlResolver 可以解析任何 XSLT importinclude 元素,而 XSLT 设置决定了样式表的权限。The XmlResolver resolves any XSLT import or include elements and the XSLT settings determine the permissions for the style sheet.

Load(MethodInfo, Byte[], Type[])

从使用 XSLTC.exe 实用程序编译的样式表中加载一个方法。Loads a method from a style sheet compiled using the XSLTC.exe utility.

Load(XmlReader, XsltSettings, XmlResolver)

编译 XmlReader 中包含的 XSLT 样式表。Compiles the XSLT style sheet contained in the XmlReader. XmlResolver 可以解析任何 XSLT importinclude 元素,而 XSLT 设置决定了样式表的权限。The XmlResolver resolves any XSLT import or include elements and the XSLT settings determine the permissions for the style sheet.

Load(XmlReader)

编译 XmlReader 中包含的样式表。Compiles the style sheet contained in the XmlReader.

Load(Type)

加载使用 XSLT 编译器 (xsltc.exe) 创建的已编译样式表。Loads the compiled style sheet that was created using the XSLT Compiler (xsltc.exe).

Load(String)

加载和编译位于指定 URI 的样式表。Loads and compiles the style sheet located at the specified URI.

Load(IXPathNavigable)

编译 IXPathNavigable 对象中包含的样式表。Compiles the style sheet contained in the IXPathNavigable object.

注解

尽管 XslCompiledTransform 类的总体性能优于 XslTransform 类,但在首次对转换调用时,Load 类的 XslCompiledTransform 方法可能比 Load 类的 XslTransform 方法慢。Although the overall performance of the XslCompiledTransform class is better than the XslTransform class, the Load method of the XslCompiledTransform class might perform more slowly than the Load method of the XslTransform class the first time it is called on a transformation. 这是因为必须先编译 XSLT 文件,才能加载该文件。This is because the XSLT file must be compiled before it is loaded. 有关详细信息,请参阅以下博客文章:XslCompiledTransform Slower than XslTransform?(XslCompiledTransform 比 XslTransform 慢?)For more information, see the following blog post: XslCompiledTransform Slower than XslTransform?

备注

以调试模式编译的 XSLT 与以发布模式编译的 XSLT 之间有一些差别。There are differences between XSLT compiled in Debug mode and XSLT compiled in Release mode. 在有些情况下,以调试模式编译的样式表在 Load 期间不会引发错误,但以后在 Transform 期间会失败。In some situations, style sheets compiled in Debug mode will not throw errors during Load, but will later fail during Transform. 以发布模式编译的同一个样式表在 Load 期间就会失败。The same style sheet compiled in Release mode will fail during Load. 例如,当某个表达式需要节点集,而分配给该表达式的变量不是节点集类型的时,就会出现这种情况。An example of such behavior is when a variable that is not of a node-set type is assigned to an expression where a node-set is required.

Load(IXPathNavigable, XsltSettings, XmlResolver)

编译 IXPathNavigable 中包含的 XSLT 样式表。Compiles the XSLT style sheet contained in the IXPathNavigable. XmlResolver 可以解析任何 XSLT importinclude 元素,而 XSLT 设置决定了样式表的权限。The XmlResolver resolves any XSLT import or include elements and the XSLT settings determine the permissions for the style sheet.

public:
 void Load(System::Xml::XPath::IXPathNavigable ^ stylesheet, System::Xml::Xsl::XsltSettings ^ settings, System::Xml::XmlResolver ^ stylesheetResolver);
public void Load (System.Xml.XPath.IXPathNavigable stylesheet, System.Xml.Xsl.XsltSettings? settings, System.Xml.XmlResolver? stylesheetResolver);
public void Load (System.Xml.XPath.IXPathNavigable stylesheet, System.Xml.Xsl.XsltSettings settings, System.Xml.XmlResolver stylesheetResolver);
member this.Load : System.Xml.XPath.IXPathNavigable * System.Xml.Xsl.XsltSettings * System.Xml.XmlResolver -> unit
Public Sub Load (stylesheet As IXPathNavigable, settings As XsltSettings, stylesheetResolver As XmlResolver)

参数

stylesheet
IXPathNavigable

一个实现 IXPathNavigable 接口的对象。An object implementing the IXPathNavigable interface. 在 Microsoft .NET Framework 中,这可以是 XmlNode(一般为 XmlDocument),或者是包含该样式表的 XPathDocumentIn the Microsoft .NET Framework, this can be either an XmlNode (typically an XmlDocument), or an XPathDocument containing the style sheet.

settings
XsltSettings

应用于样式表的 XsltSettingsThe XsltSettings to apply to the style sheet. 如果是 null,则应用 Default 设置。If this is null, the Default setting is applied.

stylesheetResolver
XmlResolver

XmlResolver,用于解析 XSLT importinclude 元素中引用的所有样式表。The XmlResolver used to resolve any style sheets referenced in XSLT import and include elements. 如果这为 null,则不解析外部资源。If this is null, external resources are not resolved.

例外

stylesheet 值为 nullThe stylesheet value is null.

样式表中有错。The style sheet contains an error.

示例

下面的示例加载样式表。The following example loads a style sheet. XmlSecureResolver对象包含访问 import include 在样式表中找到的任何或元素所需的凭据。The XmlSecureResolver object contains the credentials necessary to access any import or include elements found in the style sheet.

// Create a resolver and specify the necessary credentials.
XmlUrlResolver resolver = new XmlUrlResolver();
System.Net.NetworkCredential myCred;
myCred  = new System.Net.NetworkCredential(UserName,SecurelyStoredPassword,Domain);
resolver.Credentials = myCred;

// Load the style sheet.
XslCompiledTransform xslt = new XslCompiledTransform();
xslt.Load(new XPathDocument("http://serverName/data/xsl/sort.xsl"), XsltSettings.Default, resolver);
' Create a resolver and specify the necessary credentials.
Dim resolver As New XmlUrlResolver()
Dim myCred As System.Net.NetworkCredential
myCred = New System.Net.NetworkCredential(UserName, SecurelyStoredPassword, Domain)
resolver.Credentials = myCred
        
' Load the style sheet.
Dim xslt As New XslCompiledTransform()
xslt.Load(New XPathDocument("http://serverName/data/xsl/sort.xsl"), XsltSettings.Default, resolver)

注解

XslCompiledTransform类支持 XSLT 1.0 语法。The XslCompiledTransform class supports the XSLT 1.0 syntax. XSLT 样式表必须使用 http://www.w3.org/1999/XSL/Transform 命名空间。The XSLT style sheet must use the http://www.w3.org/1999/XSL/Transform namespace.

适用于

Load(String, XsltSettings, XmlResolver)

加载和编译 URI 指定的 XSLT 样式表。Loads and compiles the XSLT style sheet specified by the URI. XmlResolver 可以解析任何 XSLT importinclude 元素,而 XSLT 设置决定了样式表的权限。The XmlResolver resolves any XSLT import or include elements and the XSLT settings determine the permissions for the style sheet.

public:
 void Load(System::String ^ stylesheetUri, System::Xml::Xsl::XsltSettings ^ settings, System::Xml::XmlResolver ^ stylesheetResolver);
public void Load (string stylesheetUri, System.Xml.Xsl.XsltSettings? settings, System.Xml.XmlResolver? stylesheetResolver);
public void Load (string stylesheetUri, System.Xml.Xsl.XsltSettings settings, System.Xml.XmlResolver stylesheetResolver);
member this.Load : string * System.Xml.Xsl.XsltSettings * System.Xml.XmlResolver -> unit
Public Sub Load (stylesheetUri As String, settings As XsltSettings, stylesheetResolver As XmlResolver)

参数

stylesheetUri
String

样式表的 URI。The URI of the style sheet.

settings
XsltSettings

应用于样式表的 XsltSettingsThe XsltSettings to apply to the style sheet. 如果是 null,则应用 Default 设置。If this is null, the Default setting is applied.

stylesheetResolver
XmlResolver

用于解析样式表 URI 的 XmlResolver 以及在 XSLT importinclude 元素中引用的任何样式表。The XmlResolver used to resolve the style sheet URI and any style sheets referenced in XSLT import and include elements.

例外

stylesheetUristylesheetResolver 值为 nullThe stylesheetUri or stylesheetResolver value is null.

样式表中有错。The style sheet contains an error.

无法找到该样式表。The style sheet cannot be found.

stylesheetUri 值包含无法找到的文件名或目录。The stylesheetUri value includes a filename or directory that cannot be found.

无法解析 stylesheetUri 值。The stylesheetUri value cannot be resolved.

- 或 --or- 处理该请求时出错。An error occurred while processing the request.

stylesheetUri 不是有效的 URI。stylesheetUri is not a valid URI.

加载样式表时出现分析错误。There was a parsing error loading the style sheet.

示例

下面的示例加载存储在网络资源上的样式表。The following example loads a style sheet that is stored on a network resource. XmlSecureResolver 对象指定访问该样式表所需的凭据。An XmlSecureResolver object specifies the credentials necessary to access the style sheet.

// Create the XslCompiledTransform object.
XslCompiledTransform xslt = new XslCompiledTransform();

// Create a resolver and set the credentials to use.
XmlSecureResolver resolver = new XmlSecureResolver(new XmlUrlResolver(), "http://serverName/data/");
resolver.Credentials = CredentialCache.DefaultCredentials;

// Load the style sheet.
xslt.Load("http://serverName/data/xsl/sort.xsl", null, resolver);
' Create the XslCompiledTransform object.
Dim xslt As New XslCompiledTransform()
        
' Create a resolver and set the credentials to use.
Dim resolver As New XmlSecureResolver(New XmlUrlResolver(), "http://serverName/data/")
resolver.Credentials = CredentialCache.DefaultCredentials
        
' Load the style sheet.
xslt.Load("http://serverName/data/xsl/sort.xsl", Nothing, resolver)

注解

XslCompiledTransform类支持 XSLT 1.0 语法。The XslCompiledTransform class supports the XSLT 1.0 syntax. XSLT 样式表必须使用 http://www.w3.org/1999/XSL/Transform 命名空间。The XSLT style sheet must use the http://www.w3.org/1999/XSL/Transform namespace.

使用 XmlReader 带有默认设置的来加载样式表。An XmlReader with default settings is used to load the style sheet. 在上禁用 DTD 处理 XmlReaderDTD processing is disabled on the XmlReader. 如果需要 DTD 处理,请创建一个 XmlReader 启用了此功能的,并将其传递给 Load 方法。If you require DTD processing, create an XmlReader with this feature enabled, and pass it to the Load method.

适用于

Load(MethodInfo, Byte[], Type[])

从使用 XSLTC.exe 实用程序编译的样式表中加载一个方法。Loads a method from a style sheet compiled using the XSLTC.exe utility.

public:
 void Load(System::Reflection::MethodInfo ^ executeMethod, cli::array <System::Byte> ^ queryData, cli::array <Type ^> ^ earlyBoundTypes);
public void Load (System.Reflection.MethodInfo executeMethod, byte[] queryData, Type[]? earlyBoundTypes);
public void Load (System.Reflection.MethodInfo executeMethod, byte[] queryData, Type[] earlyBoundTypes);
member this.Load : System.Reflection.MethodInfo * byte[] * Type[] -> unit
Public Sub Load (executeMethod As MethodInfo, queryData As Byte(), earlyBoundTypes As Type())

参数

executeMethod
MethodInfo

一个 MethodInfo 对象,表示已编译样式表中由编译器生成的 execute 方法。A MethodInfo object representing the compiler-generated execute method of the compiled style sheet.

queryData
Byte[]

已编译样式表的 staticData 字段中的一个序列化数据结构字节数组,该已编译样式表由 CompileToType(XmlReader, XsltSettings, XmlResolver, Boolean, TypeBuilder, String) 方法生成。A byte array of serialized data structures in the staticData field of the compiled style sheet as generated by the CompileToType(XmlReader, XsltSettings, XmlResolver, Boolean, TypeBuilder, String) method.

earlyBoundTypes
Type[]

一个类型数组,该数组存储在已编译样式表中由编译器生成的 ebTypes 字段中。An array of types stored in the compiler-generated ebTypes field of the compiled style sheet.

示例

下面的代码示例使用 Load 加载已编译的样式表。The code example below uses the Load to load a compiled style sheet. 转换可将元素的值减少 Price 10%。The transformation reduces the value of the Price element by ten percent.

using System;
using System.IO;
using System.Reflection;
using System.Xml;
using System.Xml.Xsl;

class Example
{
    static void Main()
    {
        // Load a stylesheet compiled using the XSLTC.EXE utility
        Type compiledStylesheet = Assembly.Load("Transform").GetType("Transform");

        // Extract private members from the compiled stylesheet
        BindingFlags bindingFlags = BindingFlags.NonPublic | BindingFlags.Static;
        MethodInfo executeMethod = compiledStylesheet.GetMethod("Execute", bindingFlags);
        object staticData = compiledStylesheet.GetField("staticData", bindingFlags).GetValue(null);
        object earlyBoundTypes = compiledStylesheet.GetField("ebTypes", bindingFlags).GetValue(null);

        // Load into XslCompiledTransform
        XslCompiledTransform xslt = new XslCompiledTransform();
        xslt.Load(executeMethod, (byte[])staticData, (Type[])earlyBoundTypes);

        // Run the transformation
        xslt.Transform(XmlReader.Create(new StringReader("<Root><Price>9.50</Price></Root>")), (XsltArgumentList)null, Console.Out);
    }
}
Imports System.IO
Imports System.Reflection
Imports System.Xml
Imports System.Xml.Xsl

Module Module1

    Sub Main()
        ' Load a stylesheet compiled using the XSLTC.EXE utility
        Dim compiledStylesheet As Type = [Assembly].Load("Transform").GetType("Transform")

        ' Extract private members from the compiled stylesheet
        Dim bindingFlags As BindingFlags = bindingFlags.NonPublic Or bindingFlags.Static
        Dim executeMethod As MethodInfo = compiledStylesheet.GetMethod("Execute", bindingFlags)
        Dim staticData As Object = compiledStylesheet.GetField("staticData", bindingFlags).GetValue(Nothing)
        Dim earlyBoundTypes As Object = compiledStylesheet.GetField("ebTypes", bindingFlags).GetValue(Nothing)

        ' Load into XslCompiledTransform
        Dim xslt As New XslCompiledTransform()
        xslt.Load(executeMethod, CType(staticData, Byte()), CType(earlyBoundTypes, Type()))

        ' Run the transformation
        xslt.Transform(XmlReader.Create(New StringReader("<Root><Price>9.50</Price></Root>")), CType(Nothing, XsltArgumentList), Console.Out)
    End Sub
End Module

备注

本示例中使用的 "转换" 程序集是使用 xsltc.exe 实用工具生成的。The "Transform" assembly used in this example was built using the xsltc.exe utility. 有关使用此命令行工具的详细信息,请参阅 如何:使用程序集执行 XSLT 转换For detailed information on using this command line tool, see How to: Perform an XSLT Transformation by Using an Assembly.

前面的代码示例使用以下转换:The previous code example uses the following transformation:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:msxsl="urn:schemas-microsoft-com:xslt"
  xmlns:user="urn:my-scripts">
  <msxsl:script language="C#" implements-prefix="user">
    <![CDATA[
  public double modifyPrice(double price){
    price*=0.9;
    return price;
  }
  ]]>
  </msxsl:script>
  <xsl:template match="Root">
    <Root xmlns="">
      <Price><xsl:value-of select="user:modifyPrice(Price)"/></Price>
    </Root>
  </xsl:template>
</xsl:stylesheet>

注解

此方法接受一个已编译的样式表,其形式为 MethodInfo 对象、字节数组和类型数组。This method accepts a compiled style sheet in the form of a MethodInfo object, a byte array, and a type array. DynamicMethod 对象可用于允许在回收对象时放弃编译的样式表方法 XslCompiledTransformDynamicMethod objects may be used to allow compiled style sheet methods to be discarded when the XslCompiledTransform object is reclaimed.

适用于

Load(XmlReader, XsltSettings, XmlResolver)

编译 XmlReader 中包含的 XSLT 样式表。Compiles the XSLT style sheet contained in the XmlReader. XmlResolver 可以解析任何 XSLT importinclude 元素,而 XSLT 设置决定了样式表的权限。The XmlResolver resolves any XSLT import or include elements and the XSLT settings determine the permissions for the style sheet.

public:
 void Load(System::Xml::XmlReader ^ stylesheet, System::Xml::Xsl::XsltSettings ^ settings, System::Xml::XmlResolver ^ stylesheetResolver);
public void Load (System.Xml.XmlReader stylesheet, System.Xml.Xsl.XsltSettings? settings, System.Xml.XmlResolver? stylesheetResolver);
public void Load (System.Xml.XmlReader stylesheet, System.Xml.Xsl.XsltSettings settings, System.Xml.XmlResolver stylesheetResolver);
member this.Load : System.Xml.XmlReader * System.Xml.Xsl.XsltSettings * System.Xml.XmlResolver -> unit
Public Sub Load (stylesheet As XmlReader, settings As XsltSettings, stylesheetResolver As XmlResolver)

参数

stylesheet
XmlReader

包含该样式表的 XmlReaderThe XmlReader containing the style sheet.

settings
XsltSettings

应用于样式表的 XsltSettingsThe XsltSettings to apply to the style sheet. 如果是 null,则应用 Default 设置。If this is null, the Default setting is applied.

stylesheetResolver
XmlResolver

XmlResolver,用于解析 XSLT importinclude 元素中引用的所有样式表。The XmlResolver used to resolve any style sheets referenced in XSLT import and include elements. 如果这为 null,则不解析外部资源。If this is null, external resources are not resolved.

例外

stylesheet 值为 nullThe stylesheet value is null.

样式表中有错。The style sheet contains an error.

示例

下面的示例加载一个样式表并启用对 XSLT 脚本的支持。The following example loads a style sheet and enables support for XSLT scripting.

// Create the XslCompiledTransform object.
XslCompiledTransform xslt = new XslCompiledTransform();

// Create a resolver and set the credentials to use.
XmlSecureResolver resolver = new XmlSecureResolver(new XmlUrlResolver(), "http://serverName/data/");
resolver.Credentials = CredentialCache.DefaultCredentials;

XmlReader reader = XmlReader.Create("http://serverName/data/xsl/sort.xsl");

// Create the XsltSettings object with script enabled.
XsltSettings settings = new XsltSettings(false,true);

// Load the style sheet.
xslt.Load(reader, settings, resolver);
' Create the XslCompiledTransform object.
Dim xslt As New XslCompiledTransform()
        
' Create a resolver and set the credentials to use.
Dim resolver As New XmlSecureResolver(New XmlUrlResolver(), "http://serverName/data/")
resolver.Credentials = CredentialCache.DefaultCredentials
        
Dim reader As XmlReader = XmlReader.Create("http://serverName/data/xsl/sort.xsl")
        
' Create the XsltSettings object with script enabled.
Dim settings As New XsltSettings(False, True)
        
' Load the style sheet.
xslt.Load(reader, settings, resolver)

注解

XslCompiledTransform类支持 XSLT 1.0 语法。The XslCompiledTransform class supports the XSLT 1.0 syntax. XSLT 样式表必须使用 http://www.w3.org/1999/XSL/Transform 命名空间。The XSLT style sheet must use the http://www.w3.org/1999/XSL/Transform namespace.

样式表从的当前节点加载 XmlReader 到其所有子级。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. Load 方法完成后,将 XmlReader 定位到样式表末尾后的下一个节点。After the Load method completes, the XmlReader is positioned on the next node after the end of the style sheet. 如果已到达文档结尾,XmlReader 将位于文件结尾 (EOF)。If the end of the document is reached, the XmlReader is positioned at the end of file (EOF).

适用于

Load(XmlReader)

编译 XmlReader 中包含的样式表。Compiles the style sheet contained in the XmlReader.

public:
 void Load(System::Xml::XmlReader ^ stylesheet);
public void Load (System.Xml.XmlReader stylesheet);
member this.Load : System.Xml.XmlReader -> unit
Public Sub Load (stylesheet As XmlReader)

参数

stylesheet
XmlReader

包含此样式表的 XmlReaderAn XmlReader containing the style sheet.

例外

stylesheet 值为 nullThe stylesheet value is null.

样式表中有错。The style sheet contains an error.

示例

下面的示例加载对象中包含的样式表 XmlReaderThe 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);
' Create a reader that contains the style sheet.
Dim reader As XmlReader = XmlReader.Create("titles.xsl")
reader.ReadToDescendant("xsl:stylesheet")
        
' Load the style sheet.
Dim xslt As New XslCompiledTransform()
xslt.Load(reader)

注解

XslCompiledTransform类支持 XSLT 1.0 语法。The XslCompiledTransform class supports the XSLT 1.0 syntax. XSLT 样式表必须使用 http://www.w3.org/1999/XSL/Transform 命名空间。The XSLT style sheet must use the http://www.w3.org/1999/XSL/Transform namespace.

样式表从的当前节点加载 XmlReader 到其所有子级。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. Load 方法完成后,将 XmlReader 定位到样式表末尾后的下一个节点。After the Load method completes, the XmlReader is positioned on the next node after the end of the style sheet. 如果已到达文档结尾,XmlReader 将位于文件结尾 (EOF)。If the end of the document is reached, the XmlReader is positioned at the end of file (EOF).

此方法具有以下行为:This method has the following behavior:

  • 使用 XmlUrlResolver 没有用户凭据的进行处理任何 xsl:importxsl:include 元素。An XmlUrlResolver with no user credentials is used to process any xsl:import or xsl:include elements.

  • document()已禁用该函数。The document() function is disabled.

  • 不支持嵌入的脚本。Embedded scripts are not supported.

可以使用 Load(XmlReader, XsltSettings, XmlResolver) 重载来指定 XmlResolver 具有必要身份验证凭据的,或指定不同的 XSLT 设置。You can use the Load(XmlReader, XsltSettings, XmlResolver) overload to specify an XmlResolver with the necessary authentication credentials, or to specify different XSLT settings.

适用于

Load(Type)

加载使用 XSLT 编译器 (xsltc.exe) 创建的已编译样式表。Loads the compiled style sheet that was created using the XSLT Compiler (xsltc.exe).

public:
 void Load(Type ^ compiledStylesheet);
public void Load (Type compiledStylesheet);
member this.Load : Type -> unit
Public Sub Load (compiledStylesheet As Type)

参数

compiledStylesheet
Type

包含已编译样式表的类的名称。The name of the class that contains the compiled style sheet.

该名称通常是样式表的名称。This is usually the name of the style sheet. 除非另外指定,否则,xsltc.exe 工具将样式表名称用作类和程序集的名称。Unless otherwise specified, the xsltc.exe tool uses the name of the style sheet for the class and assembly names.

示例

下面的示例演示如何从 XSLT 程序集加载已编译的样式表。The following example shows how to load a compiled style sheet from an XSLT assembly. 该示例假设使用 xsltc.exe 工具创建一个名为 bookOrders.dll 的程序集,该类具有名为 bookOrders 的类。The example assumes that the xsltc.exe tool was used to create an assembly named bookOrders.dll with a class named bookOrders.

备注

在编译代码时,必须引用 XSLT 程序集。You have to reference the XSLT assembly when compiling the code. 例如,csc /r:system.dll;system.xml.dll;bookOrders.dll myCode.csFor example, csc /r:system.dll;system.xml.dll;bookOrders.dll myCode.cs.

// Load the type of the class.  
XslCompiledTransform xslt = new XslCompiledTransform();  
xslt.Load(typeof(bookOrders));  

注解

xsltc.exe 工具用于编译样式表和生成样式表中的程序集。The xsltc.exe tool is used to compile style sheets and generate assemblies from the style sheets. Load方法从程序集加载已编译的样式表。The Load method loads the compiled style sheet from the assembly.

备注

还必须在应用程序中包含 XSLT 程序集作为引用。You must also include the XSLT assembly as a reference in your application.

适用于

Load(String)

加载和编译位于指定 URI 的样式表。Loads and compiles the style sheet located at the specified URI.

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

参数

stylesheetUri
String

样式表的 URI。The URI of the style sheet.

例外

stylesheetUri 值为 nullThe stylesheetUri value is null.

样式表中有错。The style sheet contains an error.

无法找到该样式表。The style sheet cannot be found.

stylesheetUri 值包含无法找到的文件名或目录。The stylesheetUri value includes a filename or directory that cannot be found.

无法解析 stylesheetUri 值。The stylesheetUri value cannot be resolved.

- 或 --or- 处理该请求时出错。An error occurred while processing the request.

stylesheetUri 不是有效的 URI。stylesheetUri is not a valid URI.

加载样式表时出现分析错误。There was a parsing error loading the style sheet.

示例

下面的示例执行转换并输出到文件。The following example executes a transform and outputs to a file.

// Load the style sheet.
XslCompiledTransform xslt = new XslCompiledTransform();
xslt.Load("output.xsl");

// Execute the transform and output the results to a file.
xslt.Transform("books.xml", "books.html");
' Load the style sheet.
Dim xslt As New XslCompiledTransform()
xslt.Load("output.xsl")
        
' Execute the transform and output the results to a file.
xslt.Transform("books.xml", "books.html")

注解

XslCompiledTransform类支持 XSLT 1.0 语法。The XslCompiledTransform class supports the XSLT 1.0 syntax. XSLT 样式表必须使用 http://www.w3.org/1999/XSL/Transform 命名空间。The XSLT style sheet must use the http://www.w3.org/1999/XSL/Transform namespace.

此方法具有以下行为:This method has the following behavior:

  • 使用 XmlUrlResolver 不带用户凭据的来解析样式表 URI,并处理任何 xsl:importxsl:include 元素。An XmlUrlResolver with no user credentials is used to resolve the style sheet URI, and process any xsl:import or xsl:include elements.

  • 使用 XmlReader 带有默认设置的来加载样式表。An XmlReader with default settings is used to load the style sheet. 在上禁用 DTD 处理 XmlReaderDTD processing is disabled on the XmlReader. 如果需要 DTD 处理,请创建一个 XmlReader 启用了此功能的,并将其传递给 Load 方法。If you require DTD processing, create an XmlReader with this feature enabled, and pass it to the Load method.

  • document()已禁用该函数。The document() function is disabled.

  • 不支持嵌入的脚本。Embedded scripts are not supported.

可以使用 Load(String, XsltSettings, XmlResolver) 重载来指定 XmlResolver 具有必要身份验证凭据的,或指定不同的 XSLT 设置。You can use the Load(String, XsltSettings, XmlResolver) overload to specify an XmlResolver with the necessary authentication credentials, or to specify different XSLT settings.

适用于

Load(IXPathNavigable)

编译 IXPathNavigable 对象中包含的样式表。Compiles the style sheet contained in the IXPathNavigable object.

public:
 void Load(System::Xml::XPath::IXPathNavigable ^ stylesheet);
public void Load (System.Xml.XPath.IXPathNavigable stylesheet);
member this.Load : System.Xml.XPath.IXPathNavigable -> unit
Public Sub Load (stylesheet As IXPathNavigable)

参数

stylesheet
IXPathNavigable

一个实现 IXPathNavigable 接口的对象。An object implementing the IXPathNavigable interface. 在 Microsoft .NET Framework 中,这可以是 XmlNode(一般为 XmlDocument),或者是包含该样式表的 XPathDocumentIn the Microsoft .NET Framework, this can be either an XmlNode (typically an XmlDocument), or an XPathDocument containing the style sheet.

例外

stylesheet 值为 nullThe stylesheet value is null.

样式表中有错。The style sheet contains an error.

示例

下面的示例加载对象中包含的样式表 XPathDocumentThe following example loads a style sheet contained in an XPathDocument object.

XslCompiledTransform xslt = new XslCompiledTransform();
xslt.Load(new XPathDocument("http://serverName/data/xsl/sort.xsl"));
Dim xslt As New XslCompiledTransform()
xslt.Load(New XPathDocument("http://serverName/data/xsl/sort.xsl"))

注解

XslCompiledTransform类支持 XSLT 1.0 语法。The XslCompiledTransform class supports the XSLT 1.0 syntax. XSLT 样式表必须使用 http://www.w3.org/1999/XSL/Transform 命名空间。The XSLT style sheet must use the http://www.w3.org/1999/XSL/Transform namespace.

此方法具有以下行为:This method has the following behavior:

  • 使用 XmlUrlResolver 没有用户凭据的进行处理任何 xsl:importxsl:include 元素。An XmlUrlResolver with no user credentials is used to process any xsl:import or xsl:include elements.

  • document()已禁用该函数。The document() function is disabled.

  • 不支持嵌入的脚本。Embedded scripts are not supported.

可以使用 Load 重载来指定 XmlResolver 具有必要身份验证凭据的,或指定不同的 XSLT 设置。You can use the Load overload to specify an XmlResolver with the necessary authentication credentials, or to specify different XSLT settings.

适用于