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.

另请参阅

适用于

产品 Introduced

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.

注解

如果启用了 XSLT document() 函数,则使用 XmlUrlResolver 不带用户凭据的进行解析。If 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.

另请参阅

适用于

产品 Introduced

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.

注解

如果启用了 XSLT document() 函数,则使用 XmlUrlResolver 不带用户凭据的进行解析。If 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.

另请参阅

适用于

产品 Introduced

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

注解

如果启用了 XSLT document() 函数,则使用 XmlUrlResolver 不带用户凭据的进行解析。If 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.

另请参阅

适用于

产品 Introduced

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.

另请参阅

适用于

产品 Introduced

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.

另请参阅

适用于

产品 Introduced

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.

另请参阅

适用于

产品 Introduced

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.

另请参阅

适用于

产品 Introduced

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.

另请参阅

适用于

产品 Introduced

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()

注解

如果启用了 XSLT document() 函数,则使用 XmlUrlResolver 不带用户凭据的进行解析。If 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.

另请参阅

适用于

产品 Introduced

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()

注解

如果启用了 XSLT document() 函数,则使用 XmlUrlResolver 不带用户凭据的进行解析。If 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.

另请参阅

适用于

产品 Introduced

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.

另请参阅

适用于

产品 Introduced

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

用于解析 XSLT document() 函数的 XmlResolverThe 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

另请参阅

适用于

产品 Introduced

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>

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.

另请参阅

适用于

产品 Introduced

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

用于解析 XSLT document() 函数的 XmlResolverThe XmlResolver used to resolve the XSLT document() function. 如果为 null,则不解析 document() 函数。If this is null, the document() function is not resolved.

适用于

产品 Introduced