Export (0) Print
Expand All
0 out of 3 rated this helpful - Rate this topic

Patterns

A pattern is a type of expression that returns a set of nodes based on a set of conditions for a node. Nodes that satisfy the conditions match the pattern. The syntax for patterns is a subset of the syntax for expressions. In particular, location paths that meet certain restrictions can be used as patterns. An expression that is also a pattern always evaluates to an object of type node-set. A node matches a pattern if the node is a member of the result of evaluating the pattern as an expression with respect to some possible context; the possible contexts are those whose context node is the node being matched or one of its ancestors.

The following table lists examples of patterns.

 

Pattern Matches

Para

any para element

*

any element

chapter|appendix

any chapter element and any appendix element

olist/item

any item element with an olist parent

appendix//para

any para element with an appendix ancestor element

/

the root node

text()

any text node

processing-instruction()

any processing instruction

node()

any node other than an attribute node and the root node

id("W11")

the element with unique ID W11

para[1]

any para element that is the first para child element of its parent

*[position()=1 and self::para]

any para element that is the first child element of its parent

para[last()=1]

any para element that is the only para child element of its parent

items/item[position()>1]

any item element that has an items parent and that is not the first item child of its parent

item[position() mod 2 = 1]

any item element that is an odd-numbered item child of its parent

div[@class="appendix"]//p

any p element with a div ancestor element that has a class attribute with value appendix

@class

any class attribute (not any element that has a class attribute)

@*

any attribute

See Also

Reference

Location Paths




Build Date:

2012-08-02
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.