Generating Transformation Output in XML Format

This section provides a tutorial example on how to generate transformation output in XML format. The first approach is to include output XML element as literal XML elements in the transformation template.

In most situations, XSLT stylesheet is used to transform one XML document into another XML document. This requires that the transformation output must be generated as XML elements.

There are three ways to generate XML elements in an XSLT transformation template:

Let's see an example of using literal XML elements in transformation template first.

Here is the source XML document, output_xml.xml:

<?xml version="1.0"?>
<user name="Herong">
 Administrator can delete users.
 Points are earned by posting messages.

Here is the transformation template with some literal XML elements:

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
<xsl:output method="xml"/>
<xsl:template match="user">
 <profile role="guest">
  Rank can be promoted.
  Name must be unique.

Run to perform the transformation, you should get:

<?xml version="1.0" encoding="UTF-8" ?>
<profile role="guest">
  Rank can be promoted.
  Name must be unique.

The output looks good. All 3 literal XML elements are included in the result XML document correctly.

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


 Full Version in PDF/EPUB