XML Tutorials - Herong's Tutorial Examples - Version 5.05, by Dr. Herong Yang
"{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
Introduction of XML (eXtensible Markup Language)
DOM (Document Object Model) Programming Interface
SAX (Simple API for XML) Programming Interface
DTD (Document Type Definition) Introduction
Validating an XML Document against the Specified DTD Document Type
XSD (XML Schema Definition) Introduction
Validating XML Documents Against Specified XML Schemas
XSL (Extensible Stylesheet Language) Introduction
XSLT (XSL Transformations) Introduction
►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 Tools Plugin for Notepad++