Project | WXT | Basics | Download | Documentation | Samples

XPATH in short

XPATH was first initiated as a integral, and necessary, part of XSLT, but has been lifted out as a concept of its own that is usable in many connections. XPATH is a general mechanisme to identify items in a treestructured document.

The basic structure in an XPATH-expression is best considered as an analogy to a unix filepath. We always have to take into account what is called "the context node". In other words we must be aware of where we stand in the tree when we try to formulate an expression that brings us to another place. When you formulate XPATH-expressions in connection with WXT we allways use the root as context node. The task is allways to select a set of nodes somewhere down in the tree (down since trees in the computerworld for some reason allways has the root up). Below you will find some explained examples of expressions that probably is typical for the kind of selections we will use in connection with WXT. The examples are inspired by (X)HTML to support your asossiations, but are of course not limited to this XML-dialect.

//div All elements of type div in the document
//div/p All elements of type p which are children of div elements
//div/* All elements which are children of div elements
//*[@class='mlcode'] All elements which has an attribute with name class with value mlcode
//div/*[@class='mlcode'] All elements which are children of div-elements and has an attribute with name class with value mlcode
//script[@type='text/javascript'] All javascript nodes
//div[@class='clevel1'][position()=2] The second div-element with an attribute class with value clevel1
//h1 | //p All elements of type h1 or p
//div[contains(@class,'1')] All div elements which has an attribute class that contains the letter 1

You may find numerous examples and XSL-tutorials on the net. It may be usefull to experiment with a tool like XPath Explorer [23] .