Share via


Output Options on the XslCompiledTransform Class

This topic discusses the available XSLT output options. You can specify output options in the style sheet, or on the Transform method.

xsl:output Element

The xsl:output element specifies options for the output. The output type specified by the Transform method determines the behavior of the xsl:output options.

The following table describes the behavior for each of the attributes available on the xsl:output element when the output type is a stream or a TextWriter.

Attribute name

Behavior

method

Supported.

version

Ignored. The version is always 1.0 for XML and 4.0 for HTML.

encoding

Ignored when outputting to a TextWriter. The TextWriter.Encoding property is used instead.

omit-xml-declaration

Supported.

standalone

Supported.

doctype-public

Supported.

doctype-system

Supported.

cdata-section-elements

Supported.

indent

Supported.

media-type

Supported.

Sending Output to an XmlWriter

If your style sheet uses the xsl:output element and the output type is an XmlWriter object, you should use the XslCompiledTransform.OutputSettings property when you create the XmlWriter object. The XslCompiledTransform.OutputSettings property returns an XmlWriterSettings object that contains information derived from the xsl:output element of a compiled style sheet. This XmlWriterSettings object can be passed to the XmlWriter.Create method to create an XmlWriter object with the correct settings.

Output Types

The following list describes the output types available on the Transform command.

XmlWriter

The XmlWriter class writes out XML streams or files. You can specify the features to support on the XmlWriter object, including output options, by using the XmlWriterSettings class. The XmlWriter class is an integral part of the System.Xml framework. Use this output type to pipeline the output results into another XML process.

String

Use this output type to specify the URI of the output file.

Stream

A stream is an abstraction of a sequence of bytes, such as a file, an input/output device, an inter-process communication pipe, or a TCP/IP socket. The Stream class and its derived classes provide a generic view of these different types of input and output, isolating the programmer from the specific details of the operating system and the underlying devices.

Use this output type to send data to a FileStream, MemoryStream, or an output stream (Response.OutputStream).

TextWriter

The TextWriter writes sequential characters. It is implemented in the StringWriter and StreamWriter classes, which write characters to strings or streams, respectively. Use this output type when you want to output to a string.

Notes

  • When writing out empty tags, a space is written between the last character of the element name and the backslash, <myElement /> for example. This lets older browsers display the generated HTML pages correctly.

See Also

Other Resources

XSLT Transformations