XslCompiledTransform.OutputSettings 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取一个 XmlWriterSettings 对象,该对象包含从样式表的 xsl:output
元素派生的输出信息。
public:
property System::Xml::XmlWriterSettings ^ OutputSettings { System::Xml::XmlWriterSettings ^ get(); };
public System.Xml.XmlWriterSettings? OutputSettings { get; }
public System.Xml.XmlWriterSettings OutputSettings { get; }
member this.OutputSettings : System.Xml.XmlWriterSettings
Public ReadOnly Property OutputSettings As XmlWriterSettings
属性值
一个只读 XmlWriterSettings 对象,其中包含从样式表 的 xsl:output
元素派生的输出信息。 此值可为 null
。
示例
以下示例演示如何使用该 OutputSettings 属性创建将 XmlWriter 文本写入控制台的对象。
using System;
using System.IO;
using System.Xml;
using System.Xml.Xsl;
using System.Xml.XPath;
public class Sample {
private const String filename = "books.xml";
private const String stylesheet = "outputConsole.xsl";
public static void Main() {
// Create the XslTransform object and load the style sheet.
XslCompiledTransform xslt = new XslCompiledTransform();
xslt.Load(stylesheet);
// Load the file to transform.
XPathDocument doc = new XPathDocument(filename);
// Create the writer.
XmlWriter writer = XmlWriter.Create(Console.Out, xslt.OutputSettings);
// Transform the file and send the output to the console.
xslt.Transform(doc, writer);
writer.Close();
}
}
Imports System.IO
Imports System.Xml
Imports System.Xml.Xsl
Imports System.Xml.XPath
Public Class Sample
Private Const filename As String = "books.xml"
Private Const stylesheet As String = "outputConsole.xsl"
Public Shared Sub Main()
' Create the XslTransform object and load the style sheet.
Dim xslt As New XslCompiledTransform()
xslt.Load(stylesheet)
' Load the file to transform.
Dim doc As New XPathDocument(filename)
' Create the writer.
Dim writer As XmlWriter = XmlWriter.Create(Console.Out, xslt.OutputSettings)
' Transform the file and send the output to the console.
xslt.Transform(doc, writer)
writer.Close()
End Sub
End Class
该示例使用 books.xml
文件和 outputConsole.xsl
文件作为输入。
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>
outputConsole.xsl
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="text" omit-xml-declaration="yes"/>
<xsl:template match="bookstore">
Sorted Book Titles:
<xsl:apply-templates select="book">
<xsl:sort select="title"/>
</xsl:apply-templates>
</xsl:template>
<xsl:template match="book">
Title: <xsl:value-of select="node()"/>
</xsl:template>
</xsl:stylesheet>
注解
在成功调用 Load 该方法后填充此属性。 它包含派生自 xsl:output
已编译样式表元素的信息。 可以将此 XmlWriterSettings 对象传递给 XmlWriter.Create 方法以创建 XmlWriter 要输出的对象。