More Complex Patterns

Matches <note> elements that have <section> grandparents.
Matches <stockquote> elements that have a “symbol” attribute
Matches <stockquote> elements that have a “symbol” attribute with the value “XXXX
Matches <emphasis> or <strong> elements
Pattern Syntax
The XPath pattern syntax is described formally in the XPath specification. Here we’re going to look at the syntax in abstract, but less formal terms:
• An XPath pattern is a ‘location path’, a location path is absolute if it begins with a slash (“/”) and relative otherwise
• A relative location path consists of a series of steps, separated by slashes
• A step is an axis specifier, a node test, and a predicate
The formal syntax is made more complicated by the fact that it must describe both the abbreviated and unabbreviated syntaxes
Scroll to Top