(:=== XPath Demo ===:) (:*************************************************************** SIMPLE PATH EXPRESSION All book titles ****************************************************************:) doc("bookstore.xml")/Bookstore/Book/Title (:*************************************************************** ALTERNATIVES (UNION) All book or magazine titles ****************************************************************:) doc("bookstore.xml")/Bookstore/(Book|Magazine)/Title (:*************************************************************** WILDCARD All titles ****************************************************************:) doc("bookstore.xml")/Bookstore/*/Title (:*************************************************************** OPERATOR // (ALL DESCENDANTS) All titles ****************************************************************:) doc("bookstore.xml")//Title (:*************************************************************** COMBINING // AND WILDCARD All elements ****************************************************************:) doc("bookstore.xml")//* (:*************************************************************** SELECTING ATTRIBUTES All book ISBNs [[ Error, then fix with data() ]] ****************************************************************:) doc("bookstore.xml")/Bookstore/Book/@ISBN (:*************************************************************** PATH WITH CONDITION All books costing less than $90 ****************************************************************:) doc("bookstore.xml")/Bookstore/Book[@Price < 90] (:*************************************************************** CONDITION INSIDE PATH Titles of books costing less than $90 ****************************************************************:) doc("bookstore.xml")/Bookstore/Book[@Price < 90]/Title (:*************************************************************** EXISTENCE CONDITION Titles of books containing a remark ****************************************************************:) doc("bookstore.xml")/Bookstore/Book[Remark]/Title (:*************************************************************** COMPLEX CONDITION Titles of books costing less than $90 where "Ullman" is an author [[ Same query but "Jeffrey Ullman" is an author ]] [[ Original query but add "Widom" is not an author ]] ****************************************************************:) doc("bookstore.xml")/Bookstore/Book[@Price < 90 and Authors/Author/Last_Name = "Ullman"]/Title (:*************************************************************** Nth ELEMENT All second authors [[ also third ]] ****************************************************************:) doc("bookstore.xml")//Authors/Author[2] (:*************************************************************** CONTAINS() PREDICATE Titles of books with a remark containing "great" ****************************************************************:) doc("bookstore.xml")//Book[contains(Remark, "great")]/Title (:*************************************************************** "SELF-JOIN" All magazines where there's a book with the same title ****************************************************************:) doc("bookstore.xml")//Magazine[Title = doc("bookstore.xml")//Book/Title] (:*************************************************************** PARENT AXIS AND NAME() FUNCTION All elements whose parent tag is not "Bookstore" or "Book" ****************************************************************:) doc("bookstore.xml")/Bookstore//*[name(parent::*) != "Bookstore" and name(parent::*) != "Book"] (:*************************************************************** SIBLING AXIS All books and magazines with non-unique titles [[ Not quite right, then fix ]] ****************************************************************:) doc("bookstore.xml")/Bookstore/*[Title = following-sibling::*/Title] (:*************************************************************** FOR-ALL (KLUDGE) Books where every author's first name includes "J" ****************************************************************:) doc("bookstore.xml")//Book[ count(Authors/Author[contains(First_Name, "J")]) = count(Authors/Author/First_Name)] (:*************************************************************** COMPLEX CONDITION REVISITED Titles of books costing less than $90 where "Ullman" is an author but "Widom is not an author ****************************************************************:) doc("bookstore.xml")/Bookstore/Book[@Price < 90 and Authors/Author/Last_Name = "Ullman" and count(Authors/Author[Last_Name = "Widom"]) = 0]/Title