XslCompiledTransform.Transform 方法

定義

執行 XSLT 轉換。Executes the XSLT transformation.

多載

Transform(XmlReader, XsltArgumentList, TextWriter)

使用 XmlReader 物件所指定的輸入文件執行轉換,並將結果輸出至 TextWriterExecutes the transform using the input document specified by the XmlReader object and outputs the results to a TextWriter. XsltArgumentList 會提供額外的執行階段引數。The XsltArgumentList provides additional run-time arguments.

Transform(IXPathNavigable, XsltArgumentList, XmlWriter)

使用 IXPathNavigable 物件所指定的輸入文件執行轉換,並將結果輸出至 XmlWriterExecutes the transform using the input document specified by the IXPathNavigable object and outputs the results to an XmlWriter. XsltArgumentList 會提供額外的執行階段引數。The XsltArgumentList provides additional run-time arguments.

Transform(IXPathNavigable, XsltArgumentList, TextWriter)

使用 IXPathNavigable 物件所指定的輸入文件執行轉換,並將結果輸出至 TextWriterExecutes the transform using the input document specified by the IXPathNavigable object and outputs the results to an TextWriter. XsltArgumentList 會提供額外的執行階段引數。The XsltArgumentList provides additional run-time arguments.

Transform(IXPathNavigable, XsltArgumentList, Stream)

使用 IXPathNavigable 物件所指定的輸入文件執行轉換,並將結果輸出至資料流。Executes the transform using the input document specified by the IXPathNavigable object and outputs the results to a stream. XsltArgumentList 會提供額外的執行階段引數。The XsltArgumentList provides additional runtime arguments.

Transform(XmlReader, XsltArgumentList, XmlWriter)

使用 XmlReader 物件所指定的輸入文件執行轉換,並將結果輸出至 XmlWriterExecutes the transform using the input document specified by the XmlReader object and outputs the results to an XmlWriter. XsltArgumentList 會提供額外的執行階段引數。The XsltArgumentList provides additional run-time arguments.

Transform(XmlReader, XsltArgumentList, Stream)

使用 XmlReader 物件所指定的輸入文件執行轉換,並將結果輸出至資料流。Executes the transform using the input document specified by the XmlReader object and outputs the results to a stream. XsltArgumentList 會提供額外的執行階段引數。The XsltArgumentList provides additional run-time arguments.

Transform(String, String)

使用 URI 所指定的輸入文件執行轉換,並將結果輸出至檔案。Executes the transform using the input document specified by the URI and outputs the results to a file.

Transform(String, XsltArgumentList, TextWriter)

使用 URI 所指定的輸入文件執行轉換,並將結果輸出至 TextWriterExecutes the transform using the input document specified by the URI and outputs the results to a TextWriter.

Transform(String, XsltArgumentList, Stream)

使用 URI 所指定的輸入文件執行轉換,並將結果輸出至資料流。Executes the transform using the input document specified by the URI and outputs the results to stream. XsltArgumentList 會提供額外的執行階段引數。The XsltArgumentList provides additional run-time arguments.

Transform(IXPathNavigable, XmlWriter)

使用 IXPathNavigable 物件所指定的輸入文件執行轉換,並將結果輸出至 XmlWriterExecutes the transform using the input document specified by the IXPathNavigable object and outputs the results to an XmlWriter.

Transform(XmlReader, XmlWriter)

使用 XmlReader 物件所指定的輸入文件執行轉換,並將結果輸出至 XmlWriterExecutes the transform using the input document specified by the XmlReader object and outputs the results to an XmlWriter.

Transform(String, XmlWriter)

使用 URI 所指定的輸入文件執行轉換,並將結果輸出至 XmlWriterExecutes the transform using the input document specified by the URI and outputs the results to an XmlWriter.

Transform(XmlReader, XsltArgumentList, XmlWriter, XmlResolver)

使用 XmlReader 物件所指定的輸入文件執行轉換,並將結果輸出至 XmlWriterExecutes the transform using the input document specified by the XmlReader object and outputs the results to an XmlWriter. XsltArgumentList 會提供額外的執行階段引數,且 XmlResolver 會解析 XSLT document() 函式。The XsltArgumentList provides additional run-time arguments and the XmlResolver resolves the XSLT document() function.

Transform(String, XsltArgumentList, XmlWriter)

使用 URI 所指定的輸入文件執行轉換,並將結果輸出至 XmlWriterExecutes the transform using the input document specified by the URI and outputs the results to an XmlWriter. XsltArgumentList 會提供額外的執行階段引數。The XsltArgumentList provides additional run-time arguments.

Transform(IXPathNavigable, XsltArgumentList, XmlWriter, XmlResolver)

使用 IXPathNavigable 物件所指定的輸入文件執行轉換,並將結果輸出至 XmlWriterExecutes the transform by using the input document that is specified by the IXPathNavigable object and outputs the results to an XmlWriter. XsltArgumentList 會提供額外的執行階段引數,且 XmlResolver 會解析 XSLT document() 函式。The XsltArgumentList provides additional run-time arguments and the XmlResolver resolves the XSLT document() function.

備註

注意

在偵錯模式中編譯的 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.

Transform(XmlReader, XsltArgumentList, TextWriter)

使用 XmlReader 物件所指定的輸入文件執行轉換,並將結果輸出至 TextWriterExecutes the transform using the input document specified by the XmlReader object and outputs the results to a TextWriter. XsltArgumentList 會提供額外的執行階段引數。The XsltArgumentList provides additional run-time arguments.

public:
 void Transform(System::Xml::XmlReader ^ input, System::Xml::Xsl::XsltArgumentList ^ arguments, System::IO::TextWriter ^ results);
public void Transform (System.Xml.XmlReader input, System.Xml.Xsl.XsltArgumentList? arguments, System.IO.TextWriter results);
public void Transform (System.Xml.XmlReader input, System.Xml.Xsl.XsltArgumentList arguments, System.IO.TextWriter results);
member this.Transform : System.Xml.XmlReader * System.Xml.Xsl.XsltArgumentList * System.IO.TextWriter -> unit
Public Sub Transform (input As XmlReader, arguments As XsltArgumentList, results As TextWriter)

參數

input
XmlReader

包含輸入文件的 XmlReaderAn XmlReader containing the input document.

arguments
XsltArgumentList

XsltArgumentList,包含用來當做轉換輸入之符合命名空間的引數。An XsltArgumentList containing the namespace-qualified arguments used as input to the transform. 這個值可以是 nullThis value can be null.

results
TextWriter

您要輸出的目標 TextWriterThe TextWriter to which you want to output.

例外狀況

inputresults 的值為 nullThe input or results value is null.

執行 XSLT 轉換時發生錯誤。There was an error executing the XSLT transform.

備註

如果樣式表單包含 XSLT 函式 document() ,則會使用 XmlUrlResolver 沒有使用者認證的來解決。If the style sheet includes an XSLT document() function, it is resolved using an XmlUrlResolver with no user credentials. 如果外部資源位於需要驗證的網路資源上,請使用接受 XmlResolver 作為其引數的多載,並使用必要的認證來 XmlResolver 指定。If the external resource is located on a network resource that requires authentication, use the overload that takes an XmlResolver as one of its arguments and specify an XmlResolver with the necessary credentials.

另請參閱

適用於

Transform(IXPathNavigable, XsltArgumentList, XmlWriter)

使用 IXPathNavigable 物件所指定的輸入文件執行轉換,並將結果輸出至 XmlWriterExecutes the transform using the input document specified by the IXPathNavigable object and outputs the results to an XmlWriter. XsltArgumentList 會提供額外的執行階段引數。The XsltArgumentList provides additional run-time arguments.

public:
 void Transform(System::Xml::XPath::IXPathNavigable ^ input, System::Xml::Xsl::XsltArgumentList ^ arguments, System::Xml::XmlWriter ^ results);
public void Transform (System.Xml.XPath.IXPathNavigable input, System.Xml.Xsl.XsltArgumentList? arguments, System.Xml.XmlWriter results);
public void Transform (System.Xml.XPath.IXPathNavigable input, System.Xml.Xsl.XsltArgumentList arguments, System.Xml.XmlWriter results);
member this.Transform : System.Xml.XPath.IXPathNavigable * System.Xml.Xsl.XsltArgumentList * System.Xml.XmlWriter -> unit
Public Sub Transform (input As IXPathNavigable, arguments As XsltArgumentList, results As XmlWriter)

參數

input
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 data to be transformed.

arguments
XsltArgumentList

XsltArgumentList,包含用來當做轉換輸入之符合命名空間的引數。An XsltArgumentList containing the namespace-qualified arguments used as input to the transform. 這個值可以是 nullThis value can be null.

results
XmlWriter

您要輸出的目標 XmlWriterThe XmlWriter to which you want to output.

如果樣式表包含 xsl:output 元素,您應該使用從 OutputSettings 屬性傳回的 XmlWriterSettings物件建立 XmlWriterIf the style sheet contains an xsl:output element, you should create the XmlWriter using the XmlWriterSettings object returned from the OutputSettings property. 如此可確保 XmlWriter 具有正確的輸出設定。This ensures that the XmlWriter has the correct output settings.

例外狀況

inputresults 的值為 nullThe input or results value is null.

執行 XSLT 轉換時發生錯誤。There was an error executing the XSLT transform.

備註

如果 document() 已啟用 XSLT 函式,則會使用沒有使用者認證的來解決此函數 XmlUrlResolverIf the XSLT document() function is enabled, it is resolved using an XmlUrlResolver with no user credentials. 如果外部資源位於需要驗證的網路資源上,請使用接受 XmlResolver 作為其引數的多載,並使用必要的認證來 XmlResolver 指定。If the external resource is located on a network resource that requires authentication, use the overload that takes an XmlResolver as one of its arguments and specify an XmlResolver with the necessary credentials.

這個方法不支援 xsl:strip-space 元素。This method does not support the xsl:strip-space element. 如果編譯的樣式表單包含 xsl:strip-space 元素,您必須使用 Transform 接受 XmlReader 做為輸入引數的多載。If your compiled style sheet included the xsl:strip-space element, you must use the Transform overload which takes an XmlReader as the input argument.

IXPathNavigable 介面是在 XmlNodeXPathDocument 類別中實作的。The IXPathNavigable interface is implemented in the XmlNode and XPathDocument classes. 這些類別代表 XML 資料的記憶體中快取。These classes represent an in-memory cache of XML data.

  • XmlNode 類別是以 W3C 文件物件模型 (DOM) 為基礎,並包含編輯功能。The XmlNode class is based on the W3C Document Object Model (DOM) and includes editing capabilities.

  • XPathDocument 類別是以 XPath 資料模型為基礎的唯讀資料存放區。The XPathDocument class is a read-only data store based on the XPath data model. XPathDocument 是建議用於 XSLT 處理的類別。XPathDocument is the recommended class for XSLT processing. XmlNode 類別相比,它可提供更高的效能。It provides faster performance when compared to the XmlNode class.

轉換是指套用到整個文件。Transformations apply to the document as a whole. 換言之,如果您要傳入的節點不是文件的根節點,則不會阻止轉換程序取得已載入文件中的所有節點。In other words, if you pass in a node other than the document root node, this does not prevent the transformation process from accessing all nodes in the loaded document. 若要轉換節點片段,您必須建立只包含節點片段的物件,並將該物件傳遞至 Transform 方法。To transform a node fragment, you must create an object containing just the node fragment, and pass that object to the Transform method. 如需詳細資訊,請參閱如何:轉換節點片段For more information, see How to: Transform a Node Fragment.

另請參閱

適用於

Transform(IXPathNavigable, XsltArgumentList, TextWriter)

使用 IXPathNavigable 物件所指定的輸入文件執行轉換,並將結果輸出至 TextWriterExecutes the transform using the input document specified by the IXPathNavigable object and outputs the results to an TextWriter. XsltArgumentList 會提供額外的執行階段引數。The XsltArgumentList provides additional run-time arguments.

public:
 void Transform(System::Xml::XPath::IXPathNavigable ^ input, System::Xml::Xsl::XsltArgumentList ^ arguments, System::IO::TextWriter ^ results);
public void Transform (System.Xml.XPath.IXPathNavigable input, System.Xml.Xsl.XsltArgumentList? arguments, System.IO.TextWriter results);
public void Transform (System.Xml.XPath.IXPathNavigable input, System.Xml.Xsl.XsltArgumentList arguments, System.IO.TextWriter results);
member this.Transform : System.Xml.XPath.IXPathNavigable * System.Xml.Xsl.XsltArgumentList * System.IO.TextWriter -> unit
Public Sub Transform (input As IXPathNavigable, arguments As XsltArgumentList, results As TextWriter)

參數

input
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 data to be transformed.

arguments
XsltArgumentList

XsltArgumentList,包含用來當做轉換輸入之符合命名空間的引數。An XsltArgumentList containing the namespace-qualified arguments used as input to the transform. 這個值可以是 nullThis value can be null.

results
TextWriter

您要輸出的目標 TextWriterThe TextWriter to which you want to output.

例外狀況

inputresults 的值為 nullThe input or results value is null.

執行 XSLT 轉換時發生錯誤。There was an error executing the XSLT transform.

備註

如果 document() 已啟用 XSLT 函式,則會使用沒有使用者認證的來解決此函數 XmlUrlResolverIf the XSLT document() function is enabled, it is resolved using an XmlUrlResolver with no user credentials. 如果外部資源位於需要驗證的網路資源上,請使用接受 XmlResolver 作為其引數的多載,並使用必要的認證來 XmlResolver 指定。If the external resource is located on a network resource that requires authentication, use the overload that takes an XmlResolver as one of its arguments and specify an XmlResolver with the necessary credentials.

這個方法不支援 xsl:strip-space 元素。This method does not support the xsl:strip-space element. 如果編譯的樣式表單包含 xsl:strip-space 元素,您必須使用 Transform 接受 XmlReader 做為輸入引數的多載。If your compiled style sheet included the xsl:strip-space element, you must use the Transform overload which takes an XmlReader as the input argument.

IXPathNavigable 介面是在 XmlNodeXPathDocument 類別中實作的。The IXPathNavigable interface is implemented in the XmlNode and XPathDocument classes. 這些類別代表 XML 資料的記憶體中快取。These classes represent an in-memory cache of XML data.

  • XmlNode 類別是以 W3C 文件物件模型 (DOM) 為基礎,並包含編輯功能。The XmlNode class is based on the W3C Document Object Model (DOM) and includes editing capabilities.

  • XPathDocument 類別是以 XPath 資料模型為基礎的唯讀資料存放區。The XPathDocument class is a read-only data store based on the XPath data model. XPathDocument 是建議用於 XSLT 處理的類別。XPathDocument is the recommended class for XSLT processing. XmlNode 類別相比,它可提供更高的效能。It provides faster performance when compared to the XmlNode class.

轉換是指套用到整個文件。Transformations apply to the document as a whole. 換言之,如果您要傳入的節點不是文件的根節點,則不會阻止轉換程序取得已載入文件中的所有節點。In other words, if you pass in a node other than the document root node, this does not prevent the transformation process from accessing all nodes in the loaded document. 若要轉換節點片段,您必須建立只包含節點片段的物件,並將該物件傳遞至 Transform 方法。To transform a node fragment, you must create an object containing just the node fragment, and pass that object to the Transform method. 如需詳細資訊,請參閱如何:轉換節點片段For more information, see How to: Transform a Node Fragment.

另請參閱

適用於

Transform(IXPathNavigable, XsltArgumentList, Stream)

使用 IXPathNavigable 物件所指定的輸入文件執行轉換,並將結果輸出至資料流。Executes the transform using the input document specified by the IXPathNavigable object and outputs the results to a stream. XsltArgumentList 會提供額外的執行階段引數。The XsltArgumentList provides additional runtime arguments.

public:
 void Transform(System::Xml::XPath::IXPathNavigable ^ input, System::Xml::Xsl::XsltArgumentList ^ arguments, System::IO::Stream ^ results);
public void Transform (System.Xml.XPath.IXPathNavigable input, System.Xml.Xsl.XsltArgumentList? arguments, System.IO.Stream results);
public void Transform (System.Xml.XPath.IXPathNavigable input, System.Xml.Xsl.XsltArgumentList arguments, System.IO.Stream results);
member this.Transform : System.Xml.XPath.IXPathNavigable * System.Xml.Xsl.XsltArgumentList * System.IO.Stream -> unit
Public Sub Transform (input As IXPathNavigable, arguments As XsltArgumentList, results As Stream)

參數

input
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 data to be transformed.

arguments
XsltArgumentList

XsltArgumentList,包含用來當做轉換輸入之符合命名空間的引數。An XsltArgumentList containing the namespace-qualified arguments used as input to the transform. 這個值可以是 nullThis value can be null.

results
Stream

要輸出至的資料流。The stream to which you want to output.

例外狀況

inputresults 的值為 nullThe input or results value is null.

執行 XSLT 轉換時發生錯誤。There was an error executing the XSLT transform.

範例

下列範例會執行 XSLT 轉換並輸出至 FileStreamThe following example executes an XSLT transformation and outputs to a FileStream.

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

// Create the FileStream.
using (FileStream fs = new FileStream(@"c:\data\output.xml", FileMode.Create))
{
   // Execute the transformation.
   xslt.Transform(new XPathDocument("books.xml"), null, fs);
}
' Load the style sheet.
Dim xslt As New XslCompiledTransform()
xslt.Load("output.xsl")
        
' Create the FileStream.
Using fs As New FileStream("c:\data\output.xml", FileMode.Create)
   ' Execute the transformation.
    xslt.Transform(New XPathDocument("books.xml"), Nothing, fs)
End Using

備註

如果 document() 已啟用 XSLT 函式,則會使用沒有使用者認證的來解決此函數 XmlUrlResolverIf the XSLT document() function is enabled, it is resolved using an XmlUrlResolver with no user credentials. 如果外部資源位於需要驗證的網路資源上,請使用接受 XmlResolver 作為其引數的多載,並使用必要的認證來 XmlResolver 指定。If the external resource is located on a network resource that requires authentication, use the overload that takes an XmlResolver as one of its arguments and specify an XmlResolver with the necessary credentials.

這個方法不支援 xsl:strip-space 元素。This method does not support the xsl:strip-space element. 如果編譯的樣式表單包含 xsl:strip-space 元素,您必須使用 Transform 接受 XmlReader 做為輸入引數的多載。If your compiled style sheet included the xsl:strip-space element, you must use the Transform overload which takes an XmlReader as the input argument.

IXPathNavigable 介面是在 XmlNodeXPathDocument 類別中實作的。The IXPathNavigable interface is implemented in the XmlNode and XPathDocument classes. 這些類別代表 XML 資料的記憶體中快取。These classes represent an in-memory cache of XML data.

  • XmlNode 類別是以 W3C 文件物件模型 (DOM) 為基礎,並包含編輯功能。The XmlNode class is based on the W3C Document Object Model (DOM) and includes editing capabilities.

  • XPathDocument 類別是以 XPath 資料模型為基礎的唯讀資料存放區。The XPathDocument class is a read-only data store based on the XPath data model. XPathDocument 是建議用於 XSLT 處理的類別。XPathDocument is the recommended class for XSLT processing. XmlNode 類別相比,它可提供更高的效能。It provides faster performance when compared to the XmlNode class.

轉換是指套用到整個文件。Transformations apply to the document as a whole. 換言之,如果您要傳入的節點不是文件的根節點,則不會阻止轉換程序取得已載入文件中的所有節點。In other words, if you pass in a node other than the document root node, this does not prevent the transformation process from accessing all nodes in the loaded document. 若要轉換節點片段,您必須建立只包含節點片段的物件,並將該物件傳遞至 Transform 方法。To transform a node fragment, you must create an object containing just the node fragment, and pass that object to the Transform method. 如需詳細資訊,請參閱如何:轉換節點片段For more information, see How to: Transform a Node Fragment.

另請參閱

適用於

Transform(XmlReader, XsltArgumentList, XmlWriter)

使用 XmlReader 物件所指定的輸入文件執行轉換,並將結果輸出至 XmlWriterExecutes the transform using the input document specified by the XmlReader object and outputs the results to an XmlWriter. XsltArgumentList 會提供額外的執行階段引數。The XsltArgumentList provides additional run-time arguments.

public:
 void Transform(System::Xml::XmlReader ^ input, System::Xml::Xsl::XsltArgumentList ^ arguments, System::Xml::XmlWriter ^ results);
public void Transform (System.Xml.XmlReader input, System.Xml.Xsl.XsltArgumentList? arguments, System.Xml.XmlWriter results);
public void Transform (System.Xml.XmlReader input, System.Xml.Xsl.XsltArgumentList arguments, System.Xml.XmlWriter results);
member this.Transform : System.Xml.XmlReader * System.Xml.Xsl.XsltArgumentList * System.Xml.XmlWriter -> unit
Public Sub Transform (input As XmlReader, arguments As XsltArgumentList, results As XmlWriter)

參數

input
XmlReader

包含輸入文件的 XmlReaderAn XmlReader containing the input document.

arguments
XsltArgumentList

XsltArgumentList,包含用來當做轉換輸入之符合命名空間的引數。An XsltArgumentList containing the namespace-qualified arguments used as input to the transform. 這個值可以是 nullThis value can be null.

results
XmlWriter

您要輸出的目標 XmlWriterThe XmlWriter to which you want to output.

如果樣式表包含 xsl:output 元素,您應該使用從 OutputSettings 屬性傳回的 XmlWriterSettings物件建立 XmlWriterIf the style sheet contains an xsl:output element, you should create the XmlWriter using the XmlWriterSettings object returned from the OutputSettings property. 如此可確保 XmlWriter 具有正確的輸出設定。This ensures that the XmlWriter has the correct output settings.

例外狀況

inputresults 的值為 nullThe input or results value is null.

執行 XSLT 轉換時發生錯誤。There was an error executing the XSLT transform.

備註

如果樣式表單包含 XSLT 函式 document() ,則會使用 XmlUrlResolver 沒有使用者認證的來解決。If the style sheet includes an XSLT document() function, it is resolved using an XmlUrlResolver with no user credentials. 如果外部資源位於需要驗證的網路資源上,請使用接受 XmlResolver 作為其引數的多載,並使用必要的認證來 XmlResolver 指定。If the external resource is located on a network resource that requires authentication, use the overload that takes an XmlResolver as one of its arguments and specify an XmlResolver with the necessary credentials.

另請參閱

適用於

Transform(XmlReader, XsltArgumentList, Stream)

使用 XmlReader 物件所指定的輸入文件執行轉換,並將結果輸出至資料流。Executes the transform using the input document specified by the XmlReader object and outputs the results to a stream. XsltArgumentList 會提供額外的執行階段引數。The XsltArgumentList provides additional run-time arguments.

public:
 void Transform(System::Xml::XmlReader ^ input, System::Xml::Xsl::XsltArgumentList ^ arguments, System::IO::Stream ^ results);
public void Transform (System.Xml.XmlReader input, System.Xml.Xsl.XsltArgumentList? arguments, System.IO.Stream results);
public void Transform (System.Xml.XmlReader input, System.Xml.Xsl.XsltArgumentList arguments, System.IO.Stream results);
member this.Transform : System.Xml.XmlReader * System.Xml.Xsl.XsltArgumentList * System.IO.Stream -> unit
Public Sub Transform (input As XmlReader, arguments As XsltArgumentList, results As Stream)

參數

input
XmlReader

包含輸入文件的 XmlReaderAn XmlReader containing the input document.

arguments
XsltArgumentList

XsltArgumentList,包含用來當做轉換輸入之符合命名空間的引數。An XsltArgumentList containing the namespace-qualified arguments used as input to the transform. 這個值可以是 nullThis value can be null.

results
Stream

要輸出至的資料流。The stream to which you want to output.

例外狀況

inputresults 的值為 nullThe input or results value is null.

執行 XSLT 轉換時發生錯誤。There was an error executing the XSLT transform.

備註

如果樣式表單包含 XSLT 函式 document() ,則會使用 XmlUrlResolver 沒有使用者認證的來解決。If the style sheet includes an XSLT document() function, it is resolved using an XmlUrlResolver with no user credentials. 如果外部資源位於需要驗證的網路資源上,請使用接受 XmlResolver 作為其引數的多載,並使用必要的認證來 XmlResolver 指定。If the external resource is located on a network resource that requires authentication, use the overload that takes an XmlResolver as one of its arguments and specify an XmlResolver with the necessary credentials.

另請參閱

適用於

Transform(String, String)

使用 URI 所指定的輸入文件執行轉換,並將結果輸出至檔案。Executes the transform using the input document specified by the URI and outputs the results to a file.

public:
 void Transform(System::String ^ inputUri, System::String ^ resultsFile);
public void Transform (string inputUri, string resultsFile);
member this.Transform : string * string -> unit
Public Sub Transform (inputUri As String, resultsFile As String)

參數

inputUri
String

輸入文件的 URI。The URI of the input document.

resultsFile
String

輸出檔案的 URI。The URI of the output file.

例外狀況

inputUriresultsFile 的值為 nullThe inputUri or resultsFile value is null.

執行 XSLT 轉換時發生錯誤。There was an error executing the XSLT transform.

找不到輸入文件。The input document cannot be found.

inputUriresultsFile 值包含找不到的檔案名稱或目錄。The inputUri or resultsFile value includes a filename or directory cannot be found.

無法解析 inputUriresultsFile 值。The inputUri or resultsFile value cannot be resolved.

-或--or- 處理要求時發生錯誤An error occurred while processing the request

inputUriresultsFile 不是有效的 URI。inputUri or resultsFile is not a valid URI.

載入輸入文件時,發生剖析錯誤。There was a parsing error loading the input document.

範例

下列範例會執行轉換並輸出至檔案。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")

此範例會使用下列兩個輸入檔案: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>

備註

這個方法會使用 XmlUrlResolver 沒有使用者認證的預設值來解析輸入和輸出檔案。This method uses a default XmlUrlResolver with no user credentials to resolve the input and output documents. 如果這些資源中有任何一個位於需要驗證的網路資源上,請使用會採用 XmlResolver 作為其引數的多載,並使用 XmlResolver 必要的認證來指定。If any of these resources are located on a network resource that requires authentication, use the overload that takes an XmlResolver as one of its arguments and specify an XmlResolver with the necessary credentials.

XmlReader具有預設設定的會用來載入輸入檔。An XmlReader with default settings is used to load the input document. 上的 DTD 處理已停用 XmlReaderDTD processing is disabled on the XmlReader. 如果您需要 DTD 處理,請建立並 XmlReader 啟用這項功能,並將它傳遞給 Transform 方法。If you require DTD processing, create an XmlReader with this feature enabled, and pass it to the Transform method.

另請參閱

適用於

Transform(String, XsltArgumentList, TextWriter)

使用 URI 所指定的輸入文件執行轉換,並將結果輸出至 TextWriterExecutes the transform using the input document specified by the URI and outputs the results to a TextWriter.

public:
 void Transform(System::String ^ inputUri, System::Xml::Xsl::XsltArgumentList ^ arguments, System::IO::TextWriter ^ results);
public void Transform (string inputUri, System.Xml.Xsl.XsltArgumentList? arguments, System.IO.TextWriter results);
public void Transform (string inputUri, System.Xml.Xsl.XsltArgumentList arguments, System.IO.TextWriter results);
member this.Transform : string * System.Xml.Xsl.XsltArgumentList * System.IO.TextWriter -> unit
Public Sub Transform (inputUri As String, arguments As XsltArgumentList, results As TextWriter)

參數

inputUri
String

輸入文件的 URI。The URI of the input document.

arguments
XsltArgumentList

XsltArgumentList,包含用來當做轉換輸入之符合命名空間的引數。An XsltArgumentList containing the namespace-qualified arguments used as input to the transform. 這個值可以是 nullThis value can be null.

results
TextWriter

您要輸出的目標 TextWriterThe TextWriter to which you want to output.

例外狀況

inputUriresults 的值為 nullThe inputUri or results value is null.

執行 XSLT 轉換時發生錯誤。There was an error executing the XSLT transform.

找不到 inputUri 值所包含的檔案名稱或目錄。The inputUri value includes a filename or directory cannot be found.

無法保留 inputUri 值。The inputUri value cannot be resolved.

-或--or- 處理要求時發生錯誤An error occurred while processing the request

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

載入輸入文件時,發生剖析錯誤。There was a parsing error loading the input document.

範例

下列範例會執行 XSLT 轉換並輸出字串。The following example executes an XSLT transformation and outputs a string.

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

// Transform the file and output an HTML string.
string HTMLoutput;
StringWriter writer = new StringWriter();
xslt.Transform("books.xml", null, writer);
HTMLoutput = writer.ToString();
writer.Close();
' Load the style sheet.
Dim xslt As New XslCompiledTransform()
xslt.Load("HTML_out.xsl")
        
' Transform the file and output an HTML string.
Dim HTMLoutput As String
Dim writer As New StringWriter()
xslt.Transform("books.xml", Nothing, writer)
HTMLoutput = writer.ToString()
writer.Close()

備註

這個方法會使用 XmlUrlResolver 沒有使用者認證的預設值來解析輸入檔,以及在 document() 樣式表單中找到的任何 XSLT 函式實例。This method uses a default XmlUrlResolver with no user credentials to resolve the input document and any instances of the XSLT document() function found in the style sheet. 如果這些資源中有任何一個位於需要驗證的網路資源上,請使用會採用 XmlResolver 作為其引數的多載,並使用 XmlResolver 必要的認證來指定。If any of these resources are located on a network resource that requires authentication, use the overload that takes an XmlResolver as one of its arguments and specify an XmlResolver with the necessary credentials.

XmlReader具有預設設定的會用來載入輸入檔。An XmlReader with default settings is used to load the input document. 上的 DTD 處理已停用 XmlReaderDTD processing is disabled on the XmlReader. 如果您需要 DTD 處理,請建立並 XmlReader 啟用這項功能,並將它傳遞給 Transform 方法。If you require DTD processing, create an XmlReader with this feature enabled, and pass it to the Transform method.

另請參閱

適用於

Transform(String, XsltArgumentList, Stream)

使用 URI 所指定的輸入文件執行轉換,並將結果輸出至資料流。Executes the transform using the input document specified by the URI and outputs the results to stream. XsltArgumentList 會提供額外的執行階段引數。The XsltArgumentList provides additional run-time arguments.

public:
 void Transform(System::String ^ inputUri, System::Xml::Xsl::XsltArgumentList ^ arguments, System::IO::Stream ^ results);
public void Transform (string inputUri, System.Xml.Xsl.XsltArgumentList? arguments, System.IO.Stream results);
public void Transform (string inputUri, System.Xml.Xsl.XsltArgumentList arguments, System.IO.Stream results);
member this.Transform : string * System.Xml.Xsl.XsltArgumentList * System.IO.Stream -> unit
Public Sub Transform (inputUri As String, arguments As XsltArgumentList, results As Stream)

參數

inputUri
String

輸入文件的 URI。The URI of the input document.

arguments
XsltArgumentList

XsltArgumentList,包含用來當做轉換輸入之符合命名空間的引數。An XsltArgumentList containing the namespace-qualified arguments used as input to the transform. 這個值可以是 nullThis value can be null.

results
Stream

要輸出至的資料流。The stream to which you want to output.

例外狀況

inputUriresults 的值為 nullThe inputUri or results value is null.

執行 XSLT 轉換時發生錯誤。There was an error executing the XSLT transform.

找不到 inputUri 值所包含的檔案名稱或目錄。The inputUri value includes a filename or directory cannot be found.

無法保留 inputUri 值。The inputUri value cannot be resolved.

-或--or- 處理要求時發生錯誤An error occurred while processing the request

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

載入輸入文件時,發生剖析錯誤。There was a parsing error loading the input document.

備註

這個方法會使用 XmlUrlResolver 沒有使用者認證的預設值來解析輸入檔,以及在 document() 樣式表單中找到的任何 XSLT 函式實例。This method uses a default XmlUrlResolver with no user credentials to resolve the input document and any instances of the XSLT document() function found in the style sheet. 如果這些資源中有任何一個位於需要驗證的網路資源上,請使用會採用 XmlResolver 作為其引數的多載,並使用 XmlResolver 必要的認證來指定。If any of these resources are located on a network resource that requires authentication, use the overload that takes an XmlResolver as one of its arguments and specify an XmlResolver with the necessary credentials.

XmlReader具有預設設定的會用來載入輸入檔。An XmlReader with default settings is used to load the input document. 上的 DTD 處理已停用 XmlReaderDTD processing is disabled on the XmlReader. 如果您需要 DTD 處理,請建立並 XmlReader 啟用這項功能,並將它傳遞給 Transform 方法。If you require DTD processing, create an XmlReader with this feature enabled, and pass it to the Transform method.

另請參閱

適用於

Transform(IXPathNavigable, XmlWriter)

使用 IXPathNavigable 物件所指定的輸入文件執行轉換,並將結果輸出至 XmlWriterExecutes the transform using the input document specified by the IXPathNavigable object and outputs the results to an XmlWriter.

public:
 void Transform(System::Xml::XPath::IXPathNavigable ^ input, System::Xml::XmlWriter ^ results);
public void Transform (System.Xml.XPath.IXPathNavigable input, System.Xml.XmlWriter results);
member this.Transform : System.Xml.XPath.IXPathNavigable * System.Xml.XmlWriter -> unit
Public Sub Transform (input As IXPathNavigable, results As XmlWriter)

參數

input
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 data to be transformed.

results
XmlWriter

您要輸出的目標 XmlWriterThe XmlWriter to which you want to output.

如果樣式表包含 xsl:output 元素,您應該使用從 OutputSettings 屬性傳回的 XmlWriterSettings物件建立 XmlWriterIf the style sheet contains an xsl:output element, you should create the XmlWriter using the XmlWriterSettings object returned from the OutputSettings property. 如此可確保 XmlWriter 具有正確的輸出設定。This ensures that the XmlWriter has the correct output settings.

例外狀況

inputresults 的值為 nullThe input or results value is null.

執行 XSLT 轉換時發生錯誤。There was an error executing the XSLT transform.

範例

下列範例會執行 XSLT 轉換並輸出至 XmlWriter 物件。The following example executes an XSLT transformation and outputs to an XmlWriter object.

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

// Create the writer.
XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = true;
settings.IndentChars = "\t";
XmlWriter writer = XmlWriter.Create("output.xml", settings);

// Execute the transformation.
xslt.Transform(new XPathDocument("books.xml"), writer);
writer.Close();
' Load the style sheet.
Dim xslt As New XslCompiledTransform()
xslt.Load("output.xsl")
        
' Create the writer.
Dim settings As New XmlWriterSettings()
settings.Indent = True
settings.IndentChars = vbTab
Dim writer As XmlWriter = XmlWriter.Create("output.xml", settings)
        
' Execute the transformation.
xslt.Transform(New XPathDocument("books.xml"), writer)
writer.Close()

備註

如果 document() 已啟用 XSLT 函式,則會使用沒有使用者認證的來解決此函數 XmlUrlResolverIf the XSLT document() function is enabled, it is resolved using an XmlUrlResolver with no user credentials. 如果外部資源位於需要驗證的網路資源上,請使用接受 XmlResolver 作為其引數的多載,並使用必要的認證來 XmlResolver 指定。If the external resource is located on a network resource that requires authentication, use the overload that takes an XmlResolver as one of its arguments and specify an XmlResolver with the necessary credentials.

這個方法不支援 xsl:strip-space 元素。This method does not support the xsl:strip-space element. 如果編譯的樣式表單包含 xsl:strip-space 元素,您必須使用 Transform 接受 XmlReader 做為輸入引數的多載。If your compiled style sheet included the xsl:strip-space element, you must use the Transform overload which takes an XmlReader as the input argument.

IXPathNavigable 介面是在 XmlNodeXPathDocument 類別中實作的。The IXPathNavigable interface is implemented in the XmlNode and XPathDocument classes. 這些類別代表 XML 資料的記憶體中快取。These classes represent an in-memory cache of XML data.

  • XmlNode 類別是以 W3C 文件物件模型 (DOM) 為基礎,並包含編輯功能。The XmlNode class is based on the W3C Document Object Model (DOM) and includes editing capabilities.

  • XPathDocument 類別是以 XPath 資料模型為基礎的唯讀資料存放區。The XPathDocument class is a read-only data store based on the XPath data model. XPathDocument 是建議用於 XSLT 處理的類別。XPathDocument is the recommended class for XSLT processing. XmlNode 類別相比,它可提供更高的效能。It provides faster performance when compared to the XmlNode class.

轉換是指套用到整個文件。Transformations apply to the document as a whole. 換言之,如果您要傳入的節點不是文件的根節點,則不會阻止轉換程序取得已載入文件中的所有節點。In other words, if you pass in a node other than the document root node, this does not prevent the transformation process from accessing all nodes in the loaded document. 若要轉換節點片段,您必須建立只包含節點片段的物件,並將該物件傳遞至 Transform 方法。To transform a node fragment, you must create an object containing just the node fragment, and pass that object to the Transform method. 如需詳細資訊,請參閱如何:轉換節點片段For more information, see How to: Transform a Node Fragment.

另請參閱

適用於

Transform(XmlReader, XmlWriter)

使用 XmlReader 物件所指定的輸入文件執行轉換,並將結果輸出至 XmlWriterExecutes the transform using the input document specified by the XmlReader object and outputs the results to an XmlWriter.

public:
 void Transform(System::Xml::XmlReader ^ input, System::Xml::XmlWriter ^ results);
public void Transform (System.Xml.XmlReader input, System.Xml.XmlWriter results);
member this.Transform : System.Xml.XmlReader * System.Xml.XmlWriter -> unit
Public Sub Transform (input As XmlReader, results As XmlWriter)

參數

input
XmlReader

包含輸入文件的 XmlReaderThe XmlReader containing the input document.

results
XmlWriter

您要輸出的目標 XmlWriterThe XmlWriter to which you want to output.

如果樣式表包含 xsl:output 元素,您應該使用從 OutputSettings 屬性傳回的 XmlWriterSettings物件建立 XmlWriterIf the style sheet contains an xsl:output element, you should create the XmlWriter using the XmlWriterSettings object returned from the OutputSettings property. 如此可確保 XmlWriter 具有正確的輸出設定。This ensures that the XmlWriter has the correct output settings.

例外狀況

inputresults 的值為 nullThe input or results value is null.

執行 XSLT 轉換時發生錯誤。There was an error executing the XSLT transform.

範例

下列範例會轉換 books.xml 檔案中的第一本書。The following example transforms the first book in the books.xml file.

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

// Create the writer.
XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = true;
settings.IndentChars = "\t";
XmlWriter writer = XmlWriter.Create("output.xml", settings);

XmlReader reader = XmlReader.Create("books.xml");
reader.MoveToContent();

// Execute the transformation.
xslt.Transform(reader, writer);
writer.Close();
reader.Close();
' Load the style sheet.
Dim xslt As New XslCompiledTransform()
xslt.Load("output.xsl")
        
' Create the writer.
Dim settings As New XmlWriterSettings()
settings.Indent = True
settings.IndentChars = vbTab
Dim writer As XmlWriter = XmlWriter.Create("output.xml", settings)
        
Dim reader As XmlReader = XmlReader.Create("books.xml")
reader.MoveToContent()
        
' Execute the transformation.
xslt.Transform(reader, writer)
writer.Close()
reader.Close()

備註

如果 document() 已啟用 XSLT 函式,則會使用沒有使用者認證的來解決此函數 XmlUrlResolverIf the XSLT document() function is enabled, it is resolved using an XmlUrlResolver with no user credentials. 如果外部資源位於需要驗證的網路資源上,請使用接受 XmlResolver 作為其引數的多載,並使用必要的認證來 XmlResolver 指定。If the external resource is located on a network resource that requires authentication, use the overload that takes an XmlResolver as one of its arguments and specify an XmlResolver with the necessary credentials.

另請參閱

適用於

Transform(String, XmlWriter)

使用 URI 所指定的輸入文件執行轉換,並將結果輸出至 XmlWriterExecutes the transform using the input document specified by the URI and outputs the results to an XmlWriter.

public:
 void Transform(System::String ^ inputUri, System::Xml::XmlWriter ^ results);
public void Transform (string inputUri, System.Xml.XmlWriter results);
member this.Transform : string * System.Xml.XmlWriter -> unit
Public Sub Transform (inputUri As String, results As XmlWriter)

參數

inputUri
String

輸入文件的 URI。The URI of the input document.

results
XmlWriter

您要輸出的目標 XmlWriterThe XmlWriter to which you want to output.

如果樣式表包含 xsl:output 元素,您應該使用從 OutputSettings 屬性傳回的 XmlWriterSettings物件建立 XmlWriterIf the style sheet contains an xsl:output element, you should create the XmlWriter using the XmlWriterSettings object returned from the OutputSettings property. 如此可確保 XmlWriter 具有正確的輸出設定。This ensures that the XmlWriter has the correct output settings.

例外狀況

inputUriresults 的值為 nullThe inputUri or results value is null.

執行 XSLT 轉換時發生錯誤。There was an error executing the XSLT transform.

找不到 inputUri 值所包含的檔案名稱或目錄。The inputUri value includes a filename or directory cannot be found.

無法保留 inputUri 值。The inputUri value cannot be resolved.

-或--or- 處理這個要求時發生錯誤。An error occurred while processing the request.

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

載入輸入文件時,發生剖析錯誤。There was a parsing error loading the input document.

範例

下列範例會執行 XSLT 轉換並輸出至 XmlWriter 物件。The following example executes an XSLT transformation and outputs to an XmlWriter object.

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

// Create the writer.
XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = true;
settings.IndentChars = "\t";
XmlWriter writer = XmlWriter.Create("output.xml", settings);

// Execute the transformation.
xslt.Transform("books.xml", writer);
writer.Close();
' Load the style sheet.
Dim xslt As New XslCompiledTransform()
xslt.Load("output.xsl")
        
' Create the writer.
Dim settings As New XmlWriterSettings()
settings.Indent = True
settings.IndentChars = vbTab
Dim writer As XmlWriter = XmlWriter.Create("output.xml", settings)
        
' Execute the transformation.
xslt.Transform("books.xml", writer)
writer.Close()

備註

這個方法會使用 XmlUrlResolver 沒有使用者認證的預設值來解析輸入檔,以及在 document() 樣式表單中找到的任何 XSLT 函式實例。This method uses a default XmlUrlResolver with no user credentials to resolve the input document and any instances of the XSLT document() function found in the style sheet. 如果這些資源中有任何一個位於需要驗證的網路資源上,請使用會採用 XmlResolver 作為其引數的多載,並使用 XmlResolver 必要的認證來指定。If any of these resources are located on a network resource that requires authentication, use the overload that takes an XmlResolver as one of its arguments and specify an XmlResolver with the necessary credentials.

XmlReader具有預設設定的會用來載入輸入檔。An XmlReader with default settings is used to load the input document. 上的 DTD 處理已停用 XmlReaderDTD processing is disabled on the XmlReader. 如果您需要 DTD 處理,請建立並 XmlReader 啟用這項功能,並將它傳遞給 Transform 方法。If you require DTD processing, create an XmlReader with this feature enabled, and pass it to the Transform method.

這個方法不支援 xsl:strip-space 元素。This method does not support the xsl:strip-space element. 如果編譯的樣式表單包含 xsl:strip-space 元素,您必須使用 Transform 接受 XmlReader 做為輸入引數的多載。If your compiled style sheet included the xsl:strip-space element, you must use the Transform overload which takes an XmlReader as the input argument.

另請參閱

適用於

Transform(XmlReader, XsltArgumentList, XmlWriter, XmlResolver)

使用 XmlReader 物件所指定的輸入文件執行轉換,並將結果輸出至 XmlWriterExecutes the transform using the input document specified by the XmlReader object and outputs the results to an XmlWriter. XsltArgumentList 會提供額外的執行階段引數,且 XmlResolver 會解析 XSLT document() 函式。The XsltArgumentList provides additional run-time arguments and the XmlResolver resolves the XSLT document() function.

public:
 void Transform(System::Xml::XmlReader ^ input, System::Xml::Xsl::XsltArgumentList ^ arguments, System::Xml::XmlWriter ^ results, System::Xml::XmlResolver ^ documentResolver);
public void Transform (System.Xml.XmlReader input, System.Xml.Xsl.XsltArgumentList? arguments, System.Xml.XmlWriter results, System.Xml.XmlResolver? documentResolver);
public void Transform (System.Xml.XmlReader input, System.Xml.Xsl.XsltArgumentList arguments, System.Xml.XmlWriter results, System.Xml.XmlResolver documentResolver);
member this.Transform : System.Xml.XmlReader * System.Xml.Xsl.XsltArgumentList * System.Xml.XmlWriter * System.Xml.XmlResolver -> unit
Public Sub Transform (input As XmlReader, arguments As XsltArgumentList, results As XmlWriter, documentResolver As XmlResolver)

參數

input
XmlReader

包含輸入文件的 XmlReaderAn XmlReader containing the input document.

arguments
XsltArgumentList

XsltArgumentList,包含用來當做轉換輸入之符合命名空間的引數。An XsltArgumentList containing the namespace-qualified arguments used as input to the transform. 這個值可以是 nullThis value can be null.

results
XmlWriter

您要輸出的目標 XmlWriterThe XmlWriter to which you want to output.

如果樣式表包含 xsl:output 元素,您應該使用從 OutputSettings 屬性傳回的 XmlWriterSettings物件建立 XmlWriterIf the style sheet contains an xsl:output element, you should create the XmlWriter using the XmlWriterSettings object returned from the OutputSettings property. 如此可確保 XmlWriter 具有正確的輸出設定。This ensures that the XmlWriter has the correct output settings.

documentResolver
XmlResolver

XmlResolver 用來解析 XSLT document() 函式。The XmlResolver used to resolve the XSLT document() function. 如果值為 null,則不會解析 document() 函式。If this is null, the document() function is not resolved.

例外狀況

inputresults 的值為 nullThe input or results value is null.

執行 XSLT 轉換時發生錯誤。There was an error executing the XSLT transform.

範例

下列範例會使用 XmlSecureResolver 來解析 XSLT document() 函數。The following example uses an XmlSecureResolver to resolve the XSLT document() function.

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

XsltSettings settings = new XsltSettings();
settings.EnableDocumentFunction = true;

// Load the style sheet.
XslCompiledTransform xslt = new XslCompiledTransform();
xslt.Load("http://serverName/data/xsl/sort.xsl", settings, resolver);

// Transform the file.
using (XmlReader reader = XmlReader.Create("books.xml"))
{
   using (XmlWriter writer = XmlWriter.Create("output.xml"))
   {
      xslt.Transform(reader, null, writer, resolver);
   }
}
' Create a resolver and specify the necessary credentials.
Dim resolver As New XmlSecureResolver(New XmlUrlResolver(), "http://serverName/data/")
Dim myCred As System.Net.NetworkCredential
myCred = New System.Net.NetworkCredential(UserName, SecurelyStoredPassword, Domain)
resolver.Credentials = myCred
        
Dim settings As New XsltSettings()
settings.EnableDocumentFunction = True
        
' Load the style sheet.
Dim xslt As New XslCompiledTransform()
xslt.Load("http://serverName/data/xsl/sort.xsl", settings, resolver)
        
' Transform the file.
        Using reader As XmlReader = XmlReader.Create("books.xml")

            Using writer As XmlWriter = XmlWriter.Create("output.xml")
                xslt.Transform(reader, Nothing, writer, resolver)
            End Using

        End Using

另請參閱

適用於

Transform(String, XsltArgumentList, XmlWriter)

使用 URI 所指定的輸入文件執行轉換,並將結果輸出至 XmlWriterExecutes the transform using the input document specified by the URI and outputs the results to an XmlWriter. XsltArgumentList 會提供額外的執行階段引數。The XsltArgumentList provides additional run-time arguments.

public:
 void Transform(System::String ^ inputUri, System::Xml::Xsl::XsltArgumentList ^ arguments, System::Xml::XmlWriter ^ results);
public void Transform (string inputUri, System.Xml.Xsl.XsltArgumentList? arguments, System.Xml.XmlWriter results);
public void Transform (string inputUri, System.Xml.Xsl.XsltArgumentList arguments, System.Xml.XmlWriter results);
member this.Transform : string * System.Xml.Xsl.XsltArgumentList * System.Xml.XmlWriter -> unit
Public Sub Transform (inputUri As String, arguments As XsltArgumentList, results As XmlWriter)

參數

inputUri
String

輸入文件的 URI。The URI of the input document.

arguments
XsltArgumentList

XsltArgumentList,包含用來當做轉換輸入之符合命名空間的引數。An XsltArgumentList containing the namespace-qualified arguments used as input to the transform. 這個值可以是 nullThis value can be null.

results
XmlWriter

您要輸出的目標 XmlWriterThe XmlWriter to which you want to output.

如果樣式表包含 xsl:output 元素,您應該使用從 OutputSettings 屬性傳回的 XmlWriterSettings物件建立 XmlWriterIf the style sheet contains an xsl:output element, you should create the XmlWriter using the XmlWriterSettings object returned from the OutputSettings property. 如此可確保 XmlWriter 具有正確的輸出設定。This ensures that the XmlWriter has the correct output settings.

例外狀況

inputUriresults 的值為 nullThe inputUri or results value is null.

執行 XSLT 轉換時發生錯誤。There was an error executing the XSLT transform.

找不到 inputtUri 值所包含的檔案名稱或目錄。The inputtUri value includes a filename or directory cannot be found.

無法保留 inputUri 值。The inputUri value cannot be resolved.

-或--or- 處理這個要求時發生錯誤。An error occurred while processing the request.

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

載入輸入文件時,發生剖析錯誤。There was a parsing error loading the input document.

範例

下列範例會使用 XsltArgumentList 物件來建立代表目前日期和時間的參數。The following example uses an XsltArgumentList object to create a parameter representing the current date and time.

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

public class Sample
{

    public static void Main()
    {

        // Create the XslCompiledTransform and load the stylesheet.
        XslCompiledTransform xslt = new XslCompiledTransform();
        xslt.Load("order.xsl");

        // Create the XsltArgumentList.
        XsltArgumentList xslArg = new XsltArgumentList();

        // Create a parameter which represents the current date and time.
        DateTime d = DateTime.Now;
        xslArg.AddParam("date", "", d.ToString());

        // Transform the file.
        using (XmlWriter w = XmlWriter.Create("output.xml"))
        {
            xslt.Transform("order.xml", xslArg, w);
        }
    }
}
Imports System.IO
Imports System.Xml
Imports System.Xml.Xsl

Public Class Sample

    Public Shared Sub Main()

        ' Create the XslCompiledTransform and load the stylesheet.
        Dim xslt As New XslCompiledTransform()
        xslt.Load("order.xsl")

        ' Create the XsltArgumentList.
        Dim xslArg As New XsltArgumentList()

        ' Create a parameter which represents the current date and time.
        Dim d As DateTime = DateTime.Now
        xslArg.AddParam("date", "", d.ToString())

        Using w As XmlWriter = XmlWriter.Create("output.xml")
            ' Transform the file.
            xslt.Transform("order.xml", xslArg, w)
        End Using

    End Sub
End Class

此範例會使用下列兩個資料檔案做為輸入。The example uses the following two data files as input.

order.xmlorder.xml

<!--Represents a customer order-->
<order>
  <book ISBN='10-861003-324'>
    <title>The Handmaid's Tale</title>
    <price>19.95</price>
  </book>
  <cd ISBN='2-3631-4'>
    <title>Americana</title>
    <price>16.95</price>
  </cd>
</order>

順序 .xslorder.xsl

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:param name="date"/>
  <xsl:template match="/">
    <order>
      <date><xsl:value-of select="$date"/></date>
      <total><xsl:value-of select="sum(//price)"/></total>
    </order>
  </xsl:template>
</xsl:stylesheet>

備註

這個方法會使用 XmlUrlResolver 沒有使用者認證的預設值來解析輸入檔,以及在 document() 樣式表單中找到的任何 XSLT 函式實例。This method uses a default XmlUrlResolver with no user credentials to resolve the input document and any instances of the XSLT document() function found in the style sheet. 如果這些資源中有任何一個位於需要驗證的網路資源上,請使用會採用 XmlResolver 作為其引數的多載,並使用 XmlResolver 必要的認證來指定。If any of these resources are located on a network resource that requires authentication, use the overload that takes an XmlResolver as one of its arguments and specify an XmlResolver with the necessary credentials.

XmlReader具有預設設定的會用來載入輸入檔。An XmlReader with default settings is used to load the input document. 上的 DTD 處理已停用 XmlReaderDTD processing is disabled on the XmlReader. 如果您需要 DTD 處理,請建立並 XmlReader 啟用這項功能,並將它傳遞給 Transform 方法。If you require DTD processing, create an XmlReader with this feature enabled, and pass it to the Transform method.

另請參閱

適用於

Transform(IXPathNavigable, XsltArgumentList, XmlWriter, XmlResolver)

使用 IXPathNavigable 物件所指定的輸入文件執行轉換,並將結果輸出至 XmlWriterExecutes the transform by using the input document that is specified by the IXPathNavigable object and outputs the results to an XmlWriter. XsltArgumentList 會提供額外的執行階段引數,且 XmlResolver 會解析 XSLT document() 函式。The XsltArgumentList provides additional run-time arguments and the XmlResolver resolves the XSLT document() function.

public:
 void Transform(System::Xml::XPath::IXPathNavigable ^ input, System::Xml::Xsl::XsltArgumentList ^ arguments, System::Xml::XmlWriter ^ results, System::Xml::XmlResolver ^ documentResolver);
public void Transform (System.Xml.XPath.IXPathNavigable input, System.Xml.Xsl.XsltArgumentList? arguments, System.Xml.XmlWriter results, System.Xml.XmlResolver? documentResolver);
public void Transform (System.Xml.XPath.IXPathNavigable input, System.Xml.Xsl.XsltArgumentList arguments, System.Xml.XmlWriter results, System.Xml.XmlResolver documentResolver);
member this.Transform : System.Xml.XPath.IXPathNavigable * System.Xml.Xsl.XsltArgumentList * System.Xml.XmlWriter * System.Xml.XmlResolver -> unit
Public Sub Transform (input As IXPathNavigable, arguments As XsltArgumentList, results As XmlWriter, documentResolver As XmlResolver)

參數

input
IXPathNavigable

IXPathNavigable 物件指定要轉換的文件。The document to transform that is specified by the IXPathNavigable object.

arguments
XsltArgumentList

做為 XsltArgumentList 的引數清單。Argument list as XsltArgumentList.

results
XmlWriter

您要輸出的目標 XmlWriterThe XmlWriter to which you want to output.

如果樣式表包含 xsl:output 項目,您應該使用從 OutputSettings 屬性傳回的 XmlWriterSettings 物件建立 XmlWriterIf the style sheet contains an xsl:output element, you should create the XmlWriter by using the XmlWriterSettings object that is returned from the OutputSettings property. 如此可確保 XmlWriter 具有正確的輸出設定。This ensures that the XmlWriter has the correct output settings.

documentResolver
XmlResolver

XmlResolver,用於解析 XSLT document() 函式。The XmlResolver used to resolve the XSLT document() function. 如果值為 null,則不會解析 document() 函式。If this is null, the document() function is not resolved.

適用於