"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">&lt;/p>Hello world!&lt;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"?>
&lt;/p&gt;Hello world!&lt;p&gt;
  - From hello.xsl.

Notice that the "xml" method converted ">" to "&gt;".

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">&lt;/p>Hello world!&lt;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 "&lt;" to "<".

Table of Contents

 About This Book

 Introduction of XML (eXtensible Markup Language)

 XML File Syntax

 XML File Browsers

 XML-JSON Document Conversion

 DOM (Document Object Model) Programming Interface

 SAX (Simple API for XML) Programming Interface

 DTD (Document Type Definition) Introduction

 Syntaxes of DTD Statements

 Validating an XML Document against the Specified DTD Document Type

 XSD (XML Schema Definition) Introduction

 Syntaxes of XSD Statements

 Validating XML Documents Against Specified XML Schemas

 XSL (Extensible Stylesheet Language) Introduction

 Java Implementation of XSLT

 XSLT (XSL Transformations) Introduction

 XPath (XML Path) Language

 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

 Copying Attributes and Texts

 PHP Extensions for XML Manipulation

 Processing XML with Python Scripts

 XML Notepad - XML Editor

 XML Tools Plugin for Notepad++

 XML Plugin Packages for Atom Editor

 XML 1.1 Changes and Parsing Examples

 Archived Tutorials

 References

 Full Version in PDF/EPUB