XML Tutorials - Herong's Tutorial Examples - v5.25, by Herong Yang
"output" - The Output Format Control Element
This section describes the 'output' element, which is an optional element inside the 'stylesheet' element in an XSLT stylesheet file to control the format of the transformation output.
"output": An optional first element inside the "stylesheet" element in an XSLT stylesheet file. An "output" element serves as the output format control statement. It actually sets system configuration values to the XSL processor to control the output format.
The syntax of the "output" element is shown in 3 examples below:
<xsl:output method="xml" version="1.0" encoding="UTF-8"/> <xsl:output method="html"/> <xsl:output method="text"/>
where "method" is an attribute used to set the XSL processor's output formatting method. It takes one of the following 3 commonly used values:
Let's try "xml" method first with hello_xml.xsl:
<?xml version="1.0"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="xml"/> <xsl:template match="p"></p>Hello world!<p> - From hello.xsl.</xsl:template> </xsl:stylesheet>
Here is the hello.xml we have used in previous sections:
<?xml version="1.0"?> <p>Hello world!</p>
Now run the XSLT transformation Java program described earlier:
herong> java XSLTransformer hello.xml output.xml hello_xml.xsl herong> more output.xml <?xml version="1.0" encoding="UTF-8"?> </p>Hello world!<p> - From hello.xsl.
Notice that the "xml" method converted ">" to ">".
For the next test, change method from "xml" to "text", hello_text.xsl:
<?xml version="1.0"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="text"/> <xsl:template match="p"></p>Hello world!<p> - From hello.xsl.</xsl:template> </xsl:stylesheet>
Run the XSLT transformation Java program again:
herong> java XSLTransformer hello.xml output.txt hello_text.xsl herong> more output.txt </p>Hello world!<p> - From hello.xsl.
Notice that the "text" method converted "<" to "<".
Table of Contents
Introduction of XML (eXtensible Markup Language)
DOM (Document Object Model) Programming Interface
SAX (Simple API for XML) Programming Interface
DTD (Document Type Definition) Introduction
Validating an XML Document against the Specified DTD Document Type
XSD (XML Schema Definition) Introduction
Validating XML Documents Against Specified XML Schemas
XSL (Extensible Stylesheet Language) Introduction
XSLT (XSL Transformations) Introduction
XSLT Elements as Programming Statements
►Control and Generate XML Element in the Result
►"output" - The Output Format Control Element
Generating Transformation Output in XML Format
"element" and "attribute" - Constructing Output Elements
"copy" - Copy Elements from Source to Result
PHP Extensions for XML Manipulation
Processing XML with Python Scripts
XML Tools Plugin for Notepad++
XML Plugin Packages for Atom Editor