Xcerpt Tutorial - Chapter 3 (Multiple Queries/Joins)

This document is (c)2003 Sebastian Schaffert and the Xcerpt Team.
Please contact schaffer@informatik.uni-muenchen.de on any questions.

A Price Summary for Books

The query described in this example queries two XML resources, bib.xml and reviews.xml. Each of these resources is a sample book database from an imaginary online book store. The following query creates an aggregated summary of prices for each title sold by both book stores:
GOAL
  books-with-prices [
    all book-with-prices [
      title [ var T ],
      price-a [ var Pa ],
      price-b [ var Pb ]
    ]
  ]
FROM
  and {
    in { 
      resource {"file:bib.xml"},
      bib {{
        book {{
          title { var T  },
          price { var Pa }
        }}
      }}
    },
    in {
      resource {"file:reviews.xml"},
      reviews {{
        entry {{
          title { var T },
          price { var Pb }
        }}
      }}
    }
  }
END
      

As you can see in this example, several different query terms may be connected by wraping them in an and element (specifying that both queries have to succeed with these variables). The other available connection is or (denoting that at least one of the queries has to succeed).

Note that since variables in Xcerpt are like variables in logic, the and-connection together with the multiple occurences of the variable T represents the equivalent of an equi-join in relational databases, such that each combination of the variables T, Pa and Pb is always "valid" as expected.

Summary of Chapter 3

Go to Chapter 4 to see how several rules can be combined to form complex queries.

Sebastian Schaffert
Last modified: Wed Mar 12 11:46:07 CET 2003