Microsoft HomeproductssearchsupportshopWrite Us   Microsoft Home
Magazine
 |  Community
 |  Workshop
 |  Tools & Samples
 |  Training
 |  Site Info

Workshop  |  XML (Extensible Markup Language)

Collections


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

Indexing Into a Collection

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:


<x>
    <y/>
    <y/>
</x>
<x>
    <y/>
    <y/>
</x>

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]

Finding the Last Element in a Collection

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()]

Grouping

Parentheses can be used to group collection operators for clarity or where the normal precedence is inadequate to express an operation.

See Also

Sample Data, Examples


Does this content meet your programming needs? Write us!

Back to topBack to top

© 1998 Microsoft Corporation. All rights reserved. Terms of use.

 

Magazine Home
Ask Jane
DHTML Dude
Extreme XML
For Starters
More or Hess
Servin' It Up
Site Lights
Web Men Talking
Member Community Home
Benefits: Freebies & Discounts
Benefits: Promote Your Site
Benefits: Connect with Your Peers
Benefits at a Glance
Online Special-Interest Groups
Your Membership
SBN Stores
Join Now
Workshop Home
Essentials
Content & Component Delivery
Component Development
Data Access & Databases
Design
DHTML, HTML & CSS
Extensible Markup Language (XML)
Languages & Development Tools
Messaging & Collaboration
Networking, Protocols & Data Formats
Reusing Browser Technology
Security & Cryptography
Server Technologies
Streaming & Interactive Media
Web Content Management
Workshop Index
Tools & Samples Home
Tools
Samples, Headers, Libs
Images
Sounds
Style Sheets
Web Fonts
Training Home
SBN Live Seminars
SBN Live Chats
Courses
Peer Support
CD-ROM Training
Books & Training Kits
Certification
SBN Home
New to SBN?
What's New on SBN
Site Map
Site Search
Glossary
Write Us
About This Site