XML Element Transformation Chains

This section provides a tutorial example on how an XSL processor uses a transformation chain to perform a transformation inside another transformation.

When the XSL processor is transforming an element with a template, which contains an "apply-templates" statement, the XSL processor will hold the transformation of the current element, and starts the transformation requested by the "apply-templates" statement. If the template used in the second transformation also contains another "apply-templates" statement, the XSL processor will hold the second transformation, and starts a third transformation. This processing pattern is forming a transformation chain, very much like the nested methods execution chain formed when running a Java program.

Let's use the following XML file, tree.xml, to explore how XSL processor is performing a transformation inside another transformation:

<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="tree.xsl"?>
<p>
 Text p1.
 <c1>
  Text c11.
  <g11>Text g11.</g11>
  Text c12.
  <g12>Text g12.</g12>
  Text c13.
 </c1>
 Text p2.
 <c2>
  Text c21.
  <g21>Text g21.</g21>
  Text c22.
  <g22>Text g22.</g22>
  Text c23.
 </c2>
 Text p3.
 <c3>
  Text c31.
  <g21>Text g31.</g21>
  Text c32.
  <g22>Text g32.</g22>
  Text c33.
 </c3>
 Text p4.
 <c3>
  Text c41.
 </c3>
 Text p5.
</p>

Let's test transform this XML document with the default template with this stylesheet, tree.xsl:

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
   xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
</xsl:stylesheet>

Now open tree.xml with Internet Explorer, you should get:

Text p1. Text c11. Text g11. Text c12. Text g12. Text c13. Text p2. 
Text c21. Text g21. Text c22. Text g22. Text c23. Text p3. Text c31. 
Text g31. Text c32. Text g32. Text c33. Text p4. Text c41. Text p5. 

Note that:

I have tried the "Save As" function in IE, but it offers only two file types to save: .xml and .xsl. So there is no way for me to save it as transformed text format. But don't worry, we will find another XSL processor that will allow us to save the transformation output as a text file.

Last update: 2014.

Table of Contents

 About This Book

 Introduction of XML (eXtensible Markup Language)

 XML File Syntax

 XML File Browsers

 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

XSLT (XSL Transformations) Introduction

 What Is XSLT (XSL Transformations)?

 "stylesheet" - The Stylesheet Declaration Element

 "template" - The Template Declaration Element

 Including Literal XML Elements in Templates

 "apply-templates" - The Child Transformation Call Element

 How the Transformation Process Gets Started?

 Default Transformation Template

XML Element Transformation Chains

 XML Element Transformation Chains - Complex Example

 Java Implementation of XSLT

 XPath (XML Path) Language

 XSLT Elements as Programming Statements

 Control and Generate XML Element in the Result

 XML Notepad - XML Editor

 XML Tools Plugin for Notepad++

 XML 1.1 Changes and Parsing Examples

 Outdated Tutorials

 References

 PDF Printing Version