Magazine |
| | Community |
| | Workshop |
| | Tools & Samples |
| | Training |
| | Site Info |
|
|
||||||||
|
Finds the nearest ancestor matching the pattern. It returns either a single element result or null.
Syntax
ancestor(pattern)
Parameters
- pattern
- Pattern to be matched.
Remarks
The ancestor method can start a filter, but can't appear to the right of a '/' or '//' in a pattern.
This method always returns a single element result or null. If used in expressions, null evaluates to false.
This method is restricted to operating on single nodes or on collections that can be cast to a single node. (A collection can be cast to a node if at most it can have one element in it. For example, author[1] can be cast to a node, whereas book/author[1] cannot.)
Examples
Find the nearest book ancestor of the current element:
ancestor(book)
Find the nearest ancestor author element that is contained in a book element:
ancestor(book/author)
Does this content meet your programming needs? Write us!
© 1998 Microsoft Corporation. All rights reserved. Terms of use.