XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition (47 page)

BOOK: XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition
7.51Mb size Format: txt, pdf, ePub
ads

If the value of an attribute of a literal result element contains curly braces (
{
and
}
), then it is treated as an
attribute value template
(discussed further in the next section). The text between the curly braces is treated as an XPath expression, and is evaluated as a string; the attribute written to the result tree contains this string in place of the expression. For example, suppose we apply the following template to the
books.xml
file used earlier:


  

    

      

    


  


Because the
position()
function takes the values 1, 2, 3, and 4, as we move through the set of books, the output will take the following form:

Sayings of the Century


Sword of Honour


Moby Dick


The Lord of the Rings


It is also possible to generate attributes for a literal result element by two other mechanisms:

Attributes are added to the generated element node in a defined order: firstly, attributes incorporated using
xsl:use-attribute-sets
, then attributes present on the literal result element itself, and finally attributes added using

instructions. The significance of this sequence is that if two or more attributes with the same name are added, it is the last one that counts. It doesn't mean that they will necessarily appear in this order when the result tree is serialized.

Namespaces for a Literal Result Element

The namespace nodes of a literal result element are also copied to the result sequence of the sequence constructor. This is often the source of some confusion. The literal result element in the stylesheet will have a namespace node for every namespace declaration that is in scope: that is, every
xmlns
or
xmlns:*
attribute on the literal result element itself, or on any of its ancestor elements in the stylesheet. The only exception is that the attribute
xmlns = “”
does not act as a namespace declaration, rather it cancels any earlier declaration for the default namespace.

BOOK: XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition
7.51Mb size Format: txt, pdf, ePub
Read Book Download Book
ads

Other books

Starting Now by Debbie Macomber
Retribution (The Lone Riders MC Series Book 2) by Michelle Betham
Grim Tides (Marla Mason) by Pratt, T.A.
Foxmask by Juliet Marillier
After Victory: A Searching for Glory Novel (A Second Chance Love Story) by Hunter J. Keane
Darwin's Natural Selection by Allen, Katie
DEAD: Blood & Betrayal: Book 11 of the DEAD Series by TW Brown
Framed to Death (A Faith Hunter Scrap This Mystery Book 4) by Christina Freeburn
Crossing to Safety by Wallace Stegner
Mars by Ben Bova