XslTransform.Load 方法

定義

載入 XSLT 樣式表,包括 xsl:includexsl:import 項目中參考的樣式表。

多載

Load(XPathNavigator, XmlResolver, Evidence)

載入 XPathNavigator 中包含的 XSLT 樣式表。 這個方法可讓您指定辨識項,限制樣式表的使用權限。

Load(IXPathNavigable, XmlResolver, Evidence)

載入 IXPathNavigable 中包含的 XSLT 樣式表。 這個方法可讓您指定辨識項,限制樣式表的使用權限。

Load(XPathNavigator, XmlResolver)
已淘汰.

載入 XPathNavigator 中包含的 XSLT 樣式表。

Load(IXPathNavigable, XmlResolver)
已淘汰.

載入 IXPathNavigable 中包含的 XSLT 樣式表。

Load(XmlReader, XmlResolver)
已淘汰.

載入 XmlReader 中包含的 XSLT 樣式表。

Load(XmlReader, XmlResolver, Evidence)

載入 XmlReader 中包含的 XSLT 樣式表。 這個方法可讓您指定辨識項,限制樣式表的使用權限。

Load(XPathNavigator)
已淘汰.

載入 XPathNavigator 中包含的 XSLT 樣式表。

Load(IXPathNavigable)
已淘汰.

載入 IXPathNavigable 中包含的 XSLT 樣式表。

Load(XmlReader)
已淘汰.

載入 XmlReader 中包含的 XSLT 樣式表。

Load(String)

載入 URL 指定的 XSLT 樣式表。

Load(String, XmlResolver)

載入 URL 指定的 XSLT 樣式表。

備註

注意

類別 XslTransform 在 .NET Framework 2.0 版中已過時。 類別 XslCompiledTransform 是新的 XSLT 處理器。 如需詳細資訊,請參閱 使用 XslCompiledTransform 類別從 XslTransform 類別移轉。

Load(XPathNavigator, XmlResolver, Evidence)

載入 XPathNavigator 中包含的 XSLT 樣式表。 這個方法可讓您指定辨識項,限制樣式表的使用權限。

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)

參數

stylesheet
XPathNavigator

XPathNavigator 物件,包含要載入的樣式表。

resolver
XmlResolver

XmlResolver,用來載入 和 專案中 xsl:include 參考 xsl:import 的任何樣式表單。 如果這個值是 null,就不會對外部資源進行解析。

XmlResolverLoad 方法完成後不會加以快取。

evidence
Evidence

Evidence,設定在 XSLT 樣式表中針對指令碼區塊所產生的組件上。

如果這是 null ,則不會處理腳本區塊,不支援 XSLT document() 函式,而且不允許特殊許可權擴充物件。

為了提供指令碼組件的辨識項,呼叫端必須擁有 ControlEvidence 使用權限。 非完全信任呼叫端可以設定這個參數為 null

例外狀況

目前的節點不符合有效的樣式表。

參考的樣式表需要功能,而提供的辨識項不允許此功能。

呼叫端嘗試提供辨識項,但沒有 ControlEvidence 使用權限。

範例

下列範例會使用來自外部來源的樣式表單來執行 XSLT 轉換。 因為樣式表單來自不受信任的來源, resolver 所以 和 evidence 參數會設定為 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

備註

注意

類別 XslTransform 在 .NET Framework 2.0 版中已過時。 類別 XslCompiledTransform 是新的 XSLT 處理器。 如需詳細資訊,請參閱 使用 XslCompiledTransform 類別從 XslTransform 類別移轉。

XslTransform 支援 XSLT 1.0 語法。 XSLT 樣式表單必須包含命名空間宣告 xmlns:xsl= http://www.w3.org/1999/XSL/Transform

樣式表單會從 的 XPathNavigator 目前位置載入。 若要使用載入檔的一部分做為樣式表單,請流覽至對應至樣式表單開頭的節點。 方法 Load 傳回之後,會 XPathNavigator 位於節點) 上樣式表單的開頭 (xsl:style sheet

提供辨識項的方式有不同。 下表描述要針對常見使用者案例提供何種類型的辨識項。

狀況 要提供之辨識項的類型
XSLT 樣式表單是獨立的,或來自您信任的程式碼基底。 使用元件中的辨識項。

XsltTransform xslt = new XslTransform(); 
xslt.Load(xslNav, resolver, this.GetType().Assembly.Evidence);
XSLT 樣式表來自外部來源。 來源的來源是已知的,而且有可驗證的 URL。 使用 URL 建立辨識項。

XsltTransform xslt = new XslTransform(); 
Evidence evidence = XmlSecureResolver.CreateEvidenceForUrl(style sheetURL); 
xslt.Load(xslNav,resolver,evidence);
XSLT 樣式表來自外部來源。 來源的源頭未知。 將辨識項設為 null。 不會處理指令碼區塊、不支援 XSLT document() 函式,且不允許已授權的擴充物件。

此外,您也可以將 resolver 參數設定為 null 。 這可確保 xsl:import 不會處理 和 xsl:include 專案。
XSLT 樣式表來自外部來源。 來源的源頭未知,但是您需要指令碼支援。 自呼叫端要求識別項。 呼叫端的 API 必須提供提供辨識項的方法,通常是 Evidence 類別。

另請參閱

適用於

Load(IXPathNavigable, XmlResolver, Evidence)

載入 IXPathNavigable 中包含的 XSLT 樣式表。 這個方法可讓您指定辨識項,限制樣式表的使用權限。

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)

參數

stylesheet
IXPathNavigable

實作 IXPathNavigable 介面的物件。 在 .NET Framework 中,這可以是 XmlNode (一般為 XmlDocument) 或包含 XSLT 樣式表的 XPathDocument

resolver
XmlResolver

XmlResolver,用來載入 和 專案中 xsl:include 參考 xsl:import 的任何樣式表單。 如果這個值是 null,就不會對外部資源進行解析。

XmlResolverLoad 方法完成後不會加以快取。

evidence
Evidence

Evidence,設定在 XSLT 樣式表中針對指令碼區塊所產生的組件上。

如果這是 null ,則不會處理腳本區塊,不支援 XSLT document() 函式,而且不允許特殊許可權擴充物件。

為了提供指令碼組件的辨識項,呼叫端必須擁有 ControlEvidence 使用權限。 非完全信任呼叫端可以設定這個參數為 null

例外狀況

載入的資源不是有效的樣式表。

參考的樣式表需要功能,而提供的辨識項不允許此功能。

呼叫端嘗試提供辨識項,但沒有 ControlEvidence 使用權限。

備註

注意

在 .NET Framework 2.0 版中,XslTransform 類別已過時。 類別 XslCompiledTransform 是新的 XSLT 處理器。 如需詳細資訊,請參閱 使用 XslCompiledTransform 類別從 XslTransform 類別移轉。

XslTransform 支援 XSLT 1.0 語法。 XSLT 樣式表單必須包含命名空間宣告 xmlns:xsl= http://www.w3.org/1999/XSL/Transform

提供辨識項的方式有不同。 下表描述要針對常見使用者案例提供何種類型的辨識項。

狀況 要提供之辨識項的類型
XSLT 樣式表單是獨立的,或來自您信任的程式碼基底。 使用元件中的辨識項。

XsltTransform xslt = new XslTransform(); 
xslt.Load(style sheet, resolver, this.GetType().Assembly.Evidence);
XSLT 樣式表來自外部來源。 來源的來源已知,而且有可驗證的 URL。 使用 URL 建立辨識項。

XsltTransform xslt = new XslTransform(); 
Evidence evidence = XmlSecureResolver.CreateEvidenceForUrl(style sheetURL); 
xslt.Load(style sheet,resolver,evidence);
XSLT 樣式表來自外部來源。 來源的源頭未知。 將辨識項設為 null。 不會處理指令碼區塊、不支援 XSLT document() 函式,且不允許已授權的擴充物件。

此外,您也可以將 resolver 參數設定為 null 。 這可確保 xsl:import 不會處理 和 xsl:include 專案。
XSLT 樣式表來自外部來源。 來源的源頭未知,但是您需要指令碼支援。 自呼叫端要求識別項。 呼叫端的 API 必須提供提供辨識項的方式,通常是 類別 Evidence

另請參閱

適用於

Load(XPathNavigator, XmlResolver)

Source:
XslTransform.cs
Source:
XslTransform.cs
Source:
XslTransform.cs

警告

You should pass evidence to Load() method

載入 XPathNavigator 中包含的 XSLT 樣式表。

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)

參數

stylesheet
XPathNavigator

XPathNavigator 物件,包含 XSLT 樣式表。

resolver
XmlResolver

XmlResolver,用來載入 和 元素 xsl:include 中所 xsl:import 參考的任何樣式表單。 如果這個值是 null,就不會對外部資源進行解析。

XmlResolverLoad 方法完成後不會加以快取。

屬性

例外狀況

目前的節點不符合有效的樣式表。

樣式表包含內嵌指令碼,但呼叫端沒有 UnmanagedCode 使用權限。

備註

注意

類別 XslTransform 在 .NET Framework 2.0 版中已過時。 類別 XslCompiledTransform 是新的 XSLT 處理器。 如需詳細資訊,請參閱 使用 XslCompiledTransform 類別從 XslTransform 類別移轉。

XslTransform 支援 XSLT 1.0 語法。 XSLT 樣式表單必須包含命名空間宣告 xmlns:xsl= http://www.w3.org/1999/XSL/Transform

樣式表單會從 的目前位置 XPathNavigator 載入。 若要使用已載入檔的一部分做為樣式表單,請流覽至對應至樣式表單開頭的節點。 方法 Load 傳回之後,位於 XPathNavigator) 節點上的樣式表單 xsl:style sheet 開頭 (。

如果樣式表單包含內嵌腳本,腳本會編譯為元件。 元件具有完全信任。 建議的做法是使用 Load(XPathNavigator, XmlResolver, Evidence) 提供辨識項。

注意

如果呼叫端沒有 UnmanagedCode 許可權,則不會編譯內嵌腳本並 SecurityException 擲回 。 如需詳細資訊,請參閱 SecurityPermissionSecurityPermissionFlag.UnmanagedCode

另請參閱

適用於

Load(IXPathNavigable, XmlResolver)

Source:
XslTransform.cs
Source:
XslTransform.cs
Source:
XslTransform.cs

警告

You should pass evidence to Load() method

載入 IXPathNavigable 中包含的 XSLT 樣式表。

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)

參數

stylesheet
IXPathNavigable

實作 IXPathNavigable 介面的物件。 在 .NET Framework 中,這可以是 XmlNode (一般為 XmlDocument) 或包含 XSLT 樣式表的 XPathDocument

resolver
XmlResolver

XmlResolver,用來載入 和 元素 xsl:include 中所 xsl:import 參考的任何樣式表單。 如果這個值是 null,就不會對外部資源進行解析。

XmlResolverLoad 方法完成後不會加以快取。

屬性

例外狀況

載入的資源不是有效的樣式表。

樣式表包含內嵌指令碼,但呼叫端沒有 UnmanagedCode 使用權限。

備註

注意

類別 XslTransform 在 .NET Framework 2.0 版中已過時。 類別 XslCompiledTransform 是新的 XSLT 處理器。 如需詳細資訊,請參閱 使用 XslCompiledTransform 類別從 XslTransform 類別移轉。

XslTransform 支援 XSLT 1.0 語法。 XSLT 樣式表單必須包含命名空間宣告 xmlns:xsl= http://www.w3.org/1999/XSL/Transform

如果樣式表單包含內嵌腳本,腳本會編譯為元件。 元件具有完全信任。 建議的做法是使用 Load(IXPathNavigable, XmlResolver, Evidence) 方法提供辨識項。

注意

如果呼叫端沒有 UnmanagedCode 許可權,則不會編譯內嵌腳本並 SecurityException 擲回 。 如需詳細資訊,請參閱 SecurityPermissionSecurityPermissionFlag.UnmanagedCode

另請參閱

適用於

Load(XmlReader, XmlResolver)

Source:
XslTransform.cs
Source:
XslTransform.cs
Source:
XslTransform.cs

警告

You should pass evidence to Load() method

載入 XmlReader 中包含的 XSLT 樣式表。

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)

參數

stylesheet
XmlReader

XmlReader 物件,包含 XSLT 樣式表。

resolver
XmlResolver

XmlResolver,用來載入 和 元素 xsl:include 中所 xsl:import 參考的任何樣式表單。 如果這個值是 null,就不會對外部資源進行解析。

XmlResolverLoad(XmlReader, XmlResolver) 方法完成後不會加以快取。

屬性

例外狀況

目前的節點不符合有效的樣式表。

樣式表包含內嵌指令碼,但呼叫端沒有 UnmanagedCode 使用權限。

備註

注意

類別 XslTransform 在 .NET Framework 2.0 版中已過時。 類別 XslCompiledTransform 是新的 XSLT 處理器。 如需詳細資訊,請參閱 使用 XslCompiledTransform 類別從 XslTransform 類別移轉。

XslTransform 支援 XSLT 1.0 語法。 XSLT 樣式表單必須包含命名空間宣告 xmlns:xsl= http://www.w3.org/1999/XSL/Transform

這個方法會載入 XSLT 樣式表單,包括 和 元素 xsl:import 中所 xsl:include 參考的任何樣式表單。 樣式表單會從 的目前節點載入到其所有子系 XmlReader 。 這可讓您使用檔的一部分做為樣式表單。

方法 Load 傳回之後,位於 XmlReader 樣式表單結尾之後的下一個節點上。 如果到達文件結尾,則 XmlReader 會定位於檔案結尾 (EOF)。

如果樣式表單包含實體,您應該指定 XmlReader 可以解析實體的 , (XmlReader.CanResolveEntity 傳回 true) 。 在此情況下, XmlValidatingReader 可以使用 。

如果樣式表單包含內嵌腳本,腳本會編譯為元件。 元件具有完全信任。 建議的做法是使用 Load(XmlReader, XmlResolver, Evidence) 方法提供辨識項。

注意

如果呼叫端沒有 UnmanagedCode 許可權,則不會編譯內嵌腳本並 SecurityException 擲回 。 如需詳細資訊,請參閱 SecurityPermissionSecurityPermissionFlag.UnmanagedCode

另請參閱

適用於

Load(XmlReader, XmlResolver, Evidence)

載入 XmlReader 中包含的 XSLT 樣式表。 這個方法可讓您指定辨識項,限制樣式表的使用權限。

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)

參數

stylesheet
XmlReader

XmlReader 物件,包含要載入的樣式表。

resolver
XmlResolver

XmlResolver,用來載入 和 元素 xsl:include 中所 xsl:import 參考的任何樣式表單。 如果這個值是 null,就不會對外部資源進行解析。

XmlResolverLoad 方法完成後不會加以快取。

evidence
Evidence

Evidence,設定在 XSLT 樣式表中針對指令碼區塊所產生的組件上。

如果這是 null ,則不會處理腳本區塊,則不支援 XSLT document() 函式,而且不允許特殊許可權的擴充物件。

為了提供指令碼組件的辨識項,呼叫端必須擁有 ControlEvidence 使用權限。 非完全信任呼叫端可以設定這個參數為 null

例外狀況

目前的節點不符合有效的樣式表。

參考的樣式表需要功能,而提供的辨識項不允許此功能。

呼叫端嘗試提供辨識項,但沒有 ControlEvidence 使用權限。

範例

下列範例會執行 XSLT 轉換,其中 xsltReaderXmlReader 包含樣式表單的 ,而且 secureURL 是可用來建立 Evidence 的信任 URL。 方法 XmlSecureResolver.CreateEvidenceForUrl 可用來建立 Evidence 套用至樣式表單的 。

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

備註

注意

類別 XslTransform 在 .NET Framework 2.0 版中已過時。 類別 XslCompiledTransform 是新的 XSLT 處理器。 如需詳細資訊,請參閱 使用 XslCompiledTransform 類別從 XslTransform 類別移轉。

XslTransform 支援 XSLT 1.0 語法。 XSLT 樣式表單必須包含命名空間宣告 xmlns:xsl= http://www.w3.org/1999/XSL/Transform

這個方法會載入 XSLT 樣式表單,包括 和 元素 xsl:import 中所 xsl:include 參考的任何樣式表單。 樣式表單會從 的目前節點 XmlReader 載入到其所有子系。 這可讓您使用檔的一部分做為樣式表單。

方法 Load 傳回之後,會 XmlReader 位於樣式表單結尾之後的下一個節點上。 如果到達文件結尾,則 XmlReader 會定位於檔案結尾 (EOF)。

如果樣式表單包含實體,您應該指定 XmlReader 可以解析實體的 , (XmlReader.CanResolveEntitytrue 回) 。 在此情況下, XmlValidatingReader 可以使用 。

提供辨識項的方式有不同。 下表描述要針對常見使用者案例提供何種類型的辨識項。

狀況 要提供之辨識項的類型
XSLT 樣式表單是獨立的,或來自您信任的程式碼基底。 使用元件中的辨識項。

XsltTransform xslt = new XslTransform(); &#13;&#10;xslt.Load(xslReader, resolver, this.GetType().Assembly.Evidence);
XSLT 樣式表來自外部來源。 來源的來源是已知的,而且有可驗證的 URL。 使用 URL 建立辨識項。

XsltTransform xslt = new XslTransform();&#13;&#10; Evidence evidence = XmlSecureResolver.CreateEvidenceForUrl(stylesheetURL); &#13;&#10;xslt.Load(xslReader,resolver,evidence);
XSLT 樣式表來自外部來源。 來源的源頭未知。 將辨識項設為 null。 不會處理指令碼區塊、不支援 XSLT document() 函式,且不允許已授權的擴充物件。

此外,您也可以將 resolver 參數設定為 null 。 這可確保 xsl:import 不會處理 和 xsl:include 專案。
XSLT 樣式表來自外部來源。 來源的源頭未知,但是您需要指令碼支援。 自呼叫端要求識別項。 呼叫端的 API 必須提供提供辨識項的方法,通常是 Evidence 類別。

另請參閱

適用於

Load(XPathNavigator)

Source:
XslTransform.cs
Source:
XslTransform.cs
Source:
XslTransform.cs

警告

You should pass evidence to Load() method

載入 XPathNavigator 中包含的 XSLT 樣式表。

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)

參數

stylesheet
XPathNavigator

XPathNavigator 物件,包含 XSLT 樣式表。

屬性

例外狀況

目前的節點不符合有效的樣式表。

樣式表包含內嵌指令碼,但呼叫端沒有 UnmanagedCode 使用權限。

備註

注意

類別 XslTransform 在 .NET Framework 2.0 版中已過時。 類別 XslCompiledTransform 是新的 XSLT 處理器。 如需詳細資訊,請參閱 使用 XslCompiledTransform 類別從 XslTransform 類別移轉。

XslTransform 支援 XSLT 1.0 語法。 XSLT 樣式表單必須包含命名空間宣告 xmlns:xsl= http://www.w3.org/1999/XSL/Transform

這個方法會載入 XSLT 樣式表單,包括 和 元素 xsl:import 中所 xsl:include 參考的任何樣式表單。 外部資源是使用 XmlUrlResolver 沒有使用者認證的 來解析。 如果樣式表單 () 位於需要驗證的網路資源上,請使用採用 XmlResolver 作為其中一個引數的多載,並使用必要的認證來指定 XmlResolver

樣式表單會從 的 XPathNavigator 目前位置載入。 若要只使用載入檔的一部分做為樣式表單,請流覽至對應至樣式表單開頭的節點。 方法 Load 傳回之後,會 XPathNavigator 位於節點) 上樣式表單的開頭 (xsl:style sheet

如果樣式表單包含內嵌腳本,腳本就會編譯成元件。 元件具有完全信任。 建議的做法是使用 Load(XPathNavigator, XmlResolver, Evidence) 方法提供辨識項。

注意

如果呼叫端沒有 UnmanagedCode 許可權,則不會編譯內嵌腳本,而且 SecurityException 會擲回 。 如需詳細資訊,請參閱 SecurityPermissionSecurityPermissionFlag.UnmanagedCode

適用於

Load(IXPathNavigable)

Source:
XslTransform.cs
Source:
XslTransform.cs
Source:
XslTransform.cs

警告

You should pass evidence to Load() method

載入 IXPathNavigable 中包含的 XSLT 樣式表。

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)

參數

stylesheet
IXPathNavigable

實作 IXPathNavigable 介面的物件。 在 .NET Framework 中,這可以是 XmlNode (一般為 XmlDocument) 或包含 XSLT 樣式表的 XPathDocument

屬性

例外狀況

載入的資源不是有效的樣式表。

樣式表包含內嵌指令碼,但呼叫端沒有 UnmanagedCode 使用權限。

備註

注意

類別 XslTransform 在 .NET Framework 2.0 版中已過時。 類別 XslCompiledTransform 是新的 XSLT 處理器。 如需詳細資訊,請參閱 使用 XslCompiledTransform 類別從 XslTransform 類別移轉。

XslTransform 支援 XSLT 1.0 語法。 XSLT 樣式表單必須包含命名空間宣告 xmlns:xsl= http://www.w3.org/1999/XSL/Transform

這個方法會載入 XSLT 樣式表單,包括 和 元素 xsl:import 中所 xsl:include 參考的任何樣式表單。 外部資源是使用 XmlUrlResolver 沒有使用者認證的 來解析。 如果樣式表單 () 位於需要驗證的網路資源上,請使用採用 XmlResolver 作為其中一個引數的多載,並使用必要的認證來指定 XmlResolver

如果樣式表單包含內嵌腳本,腳本就會編譯成元件。 元件具有完全信任。 建議的做法是使用 Load(IXPathNavigable, XmlResolver, Evidence) 方法提供辨識項。

注意

如果呼叫端沒有 UnmanagedCode 許可權,則不會編譯內嵌腳本,而且 SecurityException 會擲回 。 如需詳細資訊,請參閱 SecurityPermissionSecurityPermissionFlag.UnmanagedCode

適用於

Load(XmlReader)

Source:
XslTransform.cs
Source:
XslTransform.cs
Source:
XslTransform.cs

警告

You should pass evidence to Load() method

載入 XmlReader 中包含的 XSLT 樣式表。

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)

參數

stylesheet
XmlReader

XmlReader 物件,包含 XSLT 樣式表。

屬性

例外狀況

目前的節點不符合有效的樣式表。

樣式表包含內嵌指令碼,但呼叫端沒有 UnmanagedCode 使用權限。

範例

下列範例會轉換依標題排序所有書籍的 XML 檔案。

#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

此範例會使用下列資料檔案做為輸入。

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>

備註

注意

類別 XslTransform 在 .NET Framework 2.0 版中已過時。 類別 XslCompiledTransform 是新的 XSLT 處理器。 如需詳細資訊,請參閱 使用 XslCompiledTransform 類別從 XslTransform 類別移轉。

XslTransform 支援 XSLT 1.0 語法。 XSLT 樣式表單必須包含命名空間宣告 xmlns:xsl= http://www.w3.org/1999/XSL/Transform

這個方法會載入 XSLT 樣式表單,包括 和 元素 xsl:import 中所 xsl:include 參考的任何樣式表單。 外部資源是使用 XmlUrlResolver 沒有使用者認證的 來解析。 如果樣式表單 () 位於需要驗證的網路資源上,請使用採用 XmlResolver 作為其中一個引數的多載,並使用必要的認證來指定 XmlResolver

樣式表單會從 的目前節點 XmlReader 載入到其所有子系。 這可讓您使用檔的一部分做為樣式表單。 方法 Load 傳回之後,會 XmlReader 位於樣式表單結尾之後的下一個節點上。 如果到達文件結尾,則 XmlReader 會定位於檔案結尾 (EOF)。

如果樣式表單包含實體,您應該指定 XmlReader 可以解析實體的 , (XmlReader.CanResolveEntitytrue 回) 。 在此情況下, XmlValidatingReader 可以使用 。

如果樣式表單包含內嵌腳本,腳本就會編譯成元件。 元件具有完全信任。 建議的做法是使用 Load(XmlReader, XmlResolver, Evidence) 方法提供辨識項。

注意

如果呼叫端沒有 UnmanagedCode 許可權,則不會編譯內嵌腳本,而且 SecurityException 會擲回 。 如需詳細資訊,請參閱 SecurityPermissionSecurityPermissionFlag.UnmanagedCode

適用於

Load(String)

Source:
XslTransform.cs
Source:
XslTransform.cs
Source:
XslTransform.cs

載入 URL 指定的 XSLT 樣式表。

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

參數

url
String

URL,指定要載入的 XSLT 樣式表。

例外狀況

載入的資源不是有效的樣式表。

樣式表包含內嵌指令碼,但呼叫端沒有 UnmanagedCode 使用權限。

範例

下列範例會將 XML 檔轉換成 HTML 檔案。 它會顯示資料表中每張書籍的 ISBN、標題和價格。

#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

範例會使用下列兩個輸入檔案。

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>

備註

注意

類別 XslTransform 在 .NET Framework 2.0 版中已過時。 類別 XslCompiledTransform 是新的 XSLT 處理器。 如需詳細資訊,請參閱 使用 XslCompiledTransform 類別從 XslTransform 類別移轉。

XslTransform 支援 XSLT 1.0 語法。 XSLT 樣式表單必須包含命名空間宣告 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"

這個方法會載入 XSLT 樣式表單,包括 和 元素 xsl:import 中所 xsl:include 參考的任何樣式表單。 外部資源是使用 XmlUrlResolver 沒有使用者認證的 來解析。 如果樣式表單 () 位於需要驗證的網路資源上,請使用採用 XmlResolver 作為其中一個引數的多載,並使用必要的認證來指定 XmlResolver

如果樣式表單包含內嵌腳本,腳本會編譯為元件。 樣式表單的 URI 是用來建立套用至元件的辨識項。

注意

如果呼叫端沒有 UnmanagedCode 許可權,則不會編譯內嵌腳本並 SecurityException 擲回 。 如需詳細資訊,請參閱 SecurityPermissionSecurityPermissionFlag.UnmanagedCode

適用於

Load(String, XmlResolver)

Source:
XslTransform.cs
Source:
XslTransform.cs
Source:
XslTransform.cs

載入 URL 指定的 XSLT 樣式表。

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)

參數

url
String

URL,指定要載入的 XSLT 樣式表。

resolver
XmlResolver

XmlResolver,用來載入樣式表單和任何樣式表單, (和 元素 xsl:include 中所 xsl:import 參考的) 。

如果值為 null,則會使用不具有使用者認證的預設 XmlUrlResolver,開啟樣式表。 預設值 XmlUrlResolver 不會用來解析樣式表單中的任何外部資源,因此 xsl:import 不會解析元素 xsl:include

XmlResolverLoad(String, XmlResolver) 方法完成後不會加以快取。

例外狀況

載入的資源不是有效的樣式表。

樣式表包含內嵌指令碼,但呼叫端沒有 UnmanagedCode 使用權限。

範例

下列範例會將 XML 檔轉換成 HTML 檔案。 此範例會載入 XSLT 樣式表單,其中包含參考另一個 xsl:include 樣式表單的專案。 XmlUrlResolver會傳遞至 方法, Load 以設定存取包含樣式表單之網路資源所需的認證。

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

此範例會使用下列資料檔案作為輸入。

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>

備註

注意

類別 XslTransform 在 .NET Framework 2.0 版中已過時。 類別 XslCompiledTransform 是新的 XSLT 處理器。 如需詳細資訊,請參閱 使用 XslCompiledTransform 類別從 XslTransform 類別移轉。

XslTransform 支援 XSLT 1.0 語法。 XSLT 樣式表單必須包含命名空間宣告 xmlns:xsl= http://www.w3.org/1999/XSL/Transform

如果樣式表單包含內嵌腳本,腳本會編譯為元件。 樣式表單的 URI 是用來建立套用至元件的辨識項。

注意

如果呼叫端沒有 UnmanagedCode 許可權,則不會編譯內嵌腳本並 SecurityException 擲回 。 如需詳細資訊,請參閱 SecurityPermissionSecurityPermissionFlag.UnmanagedCode

另請參閱

適用於