"apply-templates" - The Child Transformation Call Element

This section describes the 'apply-templates' element, which is used in the content of a 'template' element. The evaluation of an 'apply-templates' element is to perform a child transformation on some selected elements in the source XML document.

"apply-templates": A child element used as part of the content of a "template" element. An "apply-templates" element serves as a child transformation call statement during the process when the transformation engine is evaluating the content of the parent template.

An "apply-templates" element is not declaration element. An "apply-templates" element is an action element. When "apply-templates" element is evaluated, or executed, some elements from source XML document will be selected and transformed. The transformation result become the evaluation result.

The syntax of the "apply-templates" element is shown in 2 examples below:

<xsl:apply-templates select="pattern"/>

<xsl:apply-templates/>

where "pattern" is a pattern used to match elements in the source XML document.

If "pattern" matches nothing, the evaluation result is empty.

If "pattern" matches multiple parts, all of the matched parts will be transformed. The evaluation result is the concatenation of transformation result texts of all matched elements.

If attribute "select" is not specified, the default selection pattern will be used. The default selection pattern will match all child elements of current context.

For example, the first template in following stylesheet is defined with an "apply-templates" element as part of the content mixed with literal texts.

 <xsl:template match="p">
  Text part 1.
  <xsl:apply-templates select="c"/>
  Text part 2.
 </xsl:template>
 <xsl:template match="c">
  Literal text for "c".
 </xsl:template>

The content evaluation logic will be:

To test the above stylesheet, I wrote this source XML document:

<p a="v">
 Some text with a <c>child element</c>.
</p>

If the first template of the above stylesheet is applied. the transformation engine will match the element "p" in the source XML document with the first template, and insert template's content into the result document:

  Text part 1.
  Literal text for "c".
  Text part 2.

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

 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

 XPath (XML Path) Language

 XSLT Elements as Programming Statements

 Control and Generate XML Element in the Result

 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