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

This section describes the shorthand version of 'value-of' element, {expression}, should be used to include expressions in attribute values in literal XML elements.

As you can see from the example in the previous section, "value-of" elements can be used to evaluate XPath expressions to produce strings to build result document.

Here is another exampple:

<xsl:template match="update">
 <update><date><xsl:value-of select="@date"/></date></update>
</xsl:template>

In this template, I am trying to copy the "update" element from the source to the result. All the child nodes and attributes of "update" are ignored, except the "date" attribute, which is transformed into a child element with the same name. The value of "date" is inserted into the output as "date" element's content.

But if you try to keep the "date" attribute as an attribute with the "value-of" element in output:

<xsl:template match="update">
 <update date="<xsl:value-of select="@date"/>"/>
</xsl:template>

You will get into syntax errors, because XML tags are not allowed in attribute value strings of literal XML elements.

To avoid syntax problems, when a "value-of" statement is used as part of the value string of an XML attribute, it must be replaced by the shorthand version of "{expression}". So the following statement:

 <e_name a_name="{expression}"/>

is logically equivalent to:

 <e_name a_name="<xsl:value-of select="pattern"/>"/>

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