Important: |
---|
This is retired content. This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This content may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist. |
Constraints and branching can be applied to any collection by adding a filter clause, [ pattern], to the collection. The filter is analogous to the SQL WHERE clause. The filter contains a pattern within it called the filter pattern. The filter pattern evaluates to a Boolean value and is tested for each element in the collection. Any elements in the collection failing the filter pattern test are omitted from the result collection.
For convenience, if a collection is placed within the filter, a Boolean TRUE is generated if the collection contains any members and a FALSE is generated if the collection is empty. An expression such as "author/degree" implies a collection-to-Boolean conversion function that evaluates to TRUE if there exists an author with a child element degree.
Note that any number of filters can appear at a given level of an expression. Empty filters are not allowed.
Filters are always evaluated with respect to a context. In other
words, the expression
"book[author]"
means that for every book element that
is found, test whether it has an author child element. Likewise,
"book[author = 'Bob']"
means that for every book
element that is found, test whether it has an author child element
with the value "Bob". One can examine the value of the context as
well by using the period (.) character. For example,
"book[. = 'Trenton']"
means that for every book that is
found in the current context, test whether its value is
"Trenton".
If a filter compares values of elements and the filter is to be applied to more than one child element, you might want to use the anyand allkeywords. When these keywords are not specified, only the first matching child is used for the comparison.
This pattern looks for the first author child of each book element. If the value of the author child is "Bob", the corresponding book element will be returned.
Copy Code | |
---|---|
book[author="Bob"] |
Examples
Find all books that contain at least one excerpt element.
Copy Code | |
---|---|
book[excerpt] |
Find all titles of books that contain at least one excerpt element.
Copy Code | |
---|---|
book[excerpt]/title |
Find all authors of books where the book contains at least one excerpt and the author has at least one degree.
Copy Code | |
---|---|
book[excerpt]/author[degree] |
Find all books that have authors with at least one degree.
Copy Code | |
---|---|
book[author/degree] |
Find all books that have an excerpt and a title.
Copy Code | |
---|---|
book[excerpt][title] |