"value-of" - Evaluating XPath String Expressions

This section describes the 'value-of' element, which is used in the content of a 'template' element. The 'value-of' element is an XSLT statement that evaluates an XPath expression into a string.

"value-of": A child element used as part of the content of a "template" element. An "value-of" element serves as an XPath string expression evaluation statement. The syntax of the "value-of" element is:

<xsl:value-of select="expression"/>

where "expression" is an XPath expression that produces a string.

When an expression of non-string datatype is used, its final value will be converted into a sting using these rules:

For example, the following template is defined with a "value-of" element:

<xsl:template match="p">
 <xsl:value-of select="3 * 3"/>;
 <xsl:value-of select="@a"/>;
 <xsl:value-of select="c"/>
</xsl:template>

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

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

If the above template is applied, the transformation engine will match the element "p" in the source XML document with the defined template. Then the transformation engine will evaluate 3 XPath expressions and generate this output:

 9;
 v;
 child element

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

 Java Implementation of XSLT

 XPath (XML Path) Language

XSLT Elements as Programming Statements

"value-of" - Evaluating XPath String Expressions

 Examples of Using "value-of" Elements

 "{expression}" - Shorthand of "value-of" Elements

 "variable" - Declaring Variables

 "for-each" - Looping through a Node Set

 Examples of Using "for-each" Elements

 "if" - The Conditional Element

 "choose" - The If...Else Element

 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