Please email course staff at cs145@cs.stanford.edu for further assistance with your OTC account. To have your password reset, just send your account login (the cs145_user one) with your request. You should never send a password, and staff should never ask for it. (Keep the last line in mind; it is often true of good security systems in the real world.)
For students who were around after the 28 Apr 2003 problem session, here is a corrected explanation of multiple predicates in brackets:
[3]
is equivalent to [position() = 3]
,
an ordinary condition.
position()
is not counted relative to foo, but
to the results of the expression so far. For example, if position() occurs
in condition b, it counts across the result of (foo[a]).
As a result,
/Bookstore/Book[3]
means "from the sequence of
Book elements
that are children of the document element Bookstore, return the third one."
(Return the third Book in the Bookstore.)
/Bookstore/Book[3][@Price=70]
means "from the sequence of
Book elements
that are children of the document element Bookstore, return the third one
if additionally, it has an attribute Price with value 70."
(Return the third Book in the Bookstore if its Price is 70.)
/Bookstore/Book[@Price=70][3]
means "from the sequence of
Book elements
that are children of the document element Bookstore, and which additionally
have an attribute Price with value 70, return the third one."
(Return the third Book in the Bookstore that has a Price of 70.)
(This interpretation is drawn loosely from the normative examples in the XPath 1.0 Recommendation and the XPath 2.0 draft, not the language grammar or specification text.)
return
clause?for $i in 1 return <one> $i </one>
returns
<one> $i </one>
, andfor $i in 1 return <one> { $i } </one>
returns
<one> 1 </one>
.
for $i in 1 return input()//Title
evaluates the XPath
expression, returning all elements named Title from the XQuery
expression's input.
[condition a][condition b]
=
Any point where a condition in brackets is permitted, multiple conditions,
each in brackets, are permitted one after another.
Where multiple conditions appear, all of them apply.
parent::
and self::
mean
in XPath (and XQuery)?parent::
means to consider the node one step toward the root
of the tree, rather than the default of considering all children nodes.
self::
means to consider the same node, rather than the
default of considering all the children nodes.
So, for example, where Element
or child::Element
means to select any child elements named Element
,
parent::Element
means to select any element named
Element
one step "up" (toward the root of the tree),
and self::Element
means to select any node itself,
if it is named Element
. The designation before
the double colon is called the axis, as mentioned in class.
node()
test in XPath (and XQuery)?
The function node()
selects (matches) any node.
For example, where self::Element
selects
a node itself only if it is named Element
,
self::node()
selects itself as long as it is a node.