4.2 Location Paths

The basic syntax of XPath is the location path. A location path consists of one or more items that identify nodes in a tree using the XPath data model and syntax. For example, looking back at nodes.xml, the following simple location path identifies the sole element node in that document:

amount

This is actually XPath's abbreviated syntax form, which you've seen a lot of already (you'll learn more about XPath's unabbreviated syntax a little later). This path assumes that the node will be found along the child axis (discussed in Section 4.6, later in this chapter).

Now, I'll add another location step to the location path:

amount/@vendor

Location steps are separated by a slash (/). This location path has two steps. The first step identifies the amount element, and the second step identifies the vendor attribute. This path assumes that the node will be found along the child axis followed by the attribute axis.

Another location path might be:

/amount/@xml:lang

Notice that this location path is preceded by a slash. The slash at the beginning of the location path indicates the root or document node, so this path tells the processor that the amount element must be the document element because it is the element child of the root node. The next step locates the xml:lang attribute that is associated with amount. Now here is another one:

/comment(  )

This path will locate a comment that is a child of the root or document node. comment( ) is a node test. A node test checks whether a node matches a particular kind of node such as comment( ), text( ), processing-instruction( ), or node( ) for any node.

Now, I'll go into more detail about location paths by describing XPath expressions.



Learning XSLT
Learning XSLT
ISBN: 0596003277
EAN: 2147483647
Year: 2003
Pages: 164

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net