Magazine |
| | Community |
| | Workshop |
| | Tools & Samples |
| | Training |
| | Site Info |
|
|
||||||||
|
Collections returned by XSL pattern-matching operations preserve document order, hierarchy, and identity, to the extent that these are defined. That is, a collection of elements is returned in document order without repeated elements. Because by definition attributes are unordered, there is no implicit order to the attribute collection.
The collection of all elements with a certain tag name is expressed using the tag name itself. This can be qualified by showing that the elements are selected from the current context by using a period and forward slash (./), but the current context is used by default and need not be noted explicitly.
Examples
Find all first-name elements. These examples are equivalent:
./first-name
first-name
Find all unqualified book elements:
book
The XSL pattern-matching notation makes it easy to find a specific node within a set of nodes. Simply enclose the index ordinal within square brackets. The ordinal is zero-based (the first element is number zero).
Examples
The following finds the first author element:
author[0]
The following finds the third author element that has a first name:
author[first-name][2]
Note that indexes are relative to the parent. In other words, consider the following data:
Find the first y from each x:
x/y[0]
Find the first y from the entire set of y elements within x elements:
(x/y)[0]
Find the first y from the first x:
x[0]/y[0]
The end method returns true for the last element in a collection. Note that end is relative to the parent node.
Examples
Find the last book:
book[end()]
Find the last author for each book:
book/author[end()]
Find the last author from the entire set of authors of books:
(book/author)[end()]
Parentheses can be used to group collection operators for clarity or where the normal precedence is inadequate to express an operation.
See Also
Does this content meet your programming needs? Write us!
© 1998 Microsoft Corporation. All rights reserved. Terms of use.