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 比 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

XmlResolver 用來解析樣式表 URI 和 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[]

CompileToType(XmlReader, XsltSettings, XmlResolver, Boolean, TypeBuilder, String) 方法產生的已編譯樣式表中,staticData 欄位中序列化資料結構的位元組陣列。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.

另請參閱

適用於