obj STRING is pr QID . sort String . subsort Id < String . op _ _ : String String -> String [ assoc ] . endo obj QUERY is pr INT . sort Query . op price > _ : Int -> Query . endo ***> DTD for Book Store 1 obj BOOKSTORE1-DTD is pr QID . pr INT . pr STRING . sorts Document Book BookList Title Author Price . subsort Book < BookList . op nil : -> BookList . op _ _ : BookList BookList -> BookList [ assoc idr: nil ]. op _ : BookList -> Document . op _ _ _ : Title Author Price -> Book . op _ : String -> Title . op _ _ : Id Id -> Author . op _ : Int -> Price . endo ***> XML for Book Store 1 obj BOOKSTORE1-XML is pr BOOKSTORE1-DTD . op doc1 : -> Document . eq doc1 = 'Inside 'XML 'Steven 'Holzner 39 'Professional 'XML 'Databases 'Kevin 'Williams 53 'Learning 'XML 'Erik 'Ray 41 . endo ***> query obj QUERY-BOOKSTORE1 is pr BOOKSTORE1-XML . pr QUERY . op query : Document Query -> BookList . op query : BookList Query -> BookList . var BL : BookList . vars N N1 N2 : Int . var T : Title . var A : Author . var P : Price . eq query( BL , price > N) = query(BL, price > N) . cq query( T A N1 BL , price > N2) = query(BL, price > N2) if N1 <= N2 . cq query( T A N1 BL , price > N2) = T A N1 query(BL, price > N2) if N1 > N2 . cq query( T A N1 , price > N2) = nil if N1 <= N2 . cq query( T A N1 , price > N2) = T A N1 if N1 > N2 . endo red query(doc1, price > 40) . ***> DTD for Book Store 2 obj BOOKSTORE2-DTD is pr QID . pr INT . pr STRING . sorts Document Book BookList Title Author Price FirstName LastName . subsort Book < BookList . op nil : -> BookList . op _ _ : BookList BookList -> BookList [ assoc idr: nil ]. op _ : BookList -> Document . op _ _ _ : Title Author Price -> Book . op _ : String -> Title . op _ _ : FirstName LastName -> Author . op _ : Id -> FirstName . op _ : Id -> LastName . op _ : Int -> Price . endo ***> XML for Book Store 2 obj BOOKSTORE2-XML is pr BOOKSTORE2-DTD . op doc2 : -> Document . eq doc2 = 'Java 'and 'XML 'Brett 'McLaughlin 350 'Professional 'XML 'Databases 'Kevin 'Williams 530 'XML 'by 'Example 'Benoit 'Marchal 190 . endo ***> Query for Book Store2 obj QUERY-BOOKSTORE2 is pr BOOKSTORE2-XML . pr QUERY . op query : Document Query -> BookList . op query : BookList Query -> BookList . var BL : BookList . vars N N1 N2 : Int . var T : Title . var A : Author . var P : Price . eq query( BL , price > N) = query(BL, price > N) . cq query( T A N1 BL , price > N2) = query(BL, price > N2) if N1 <= N2 . cq query( T A N1 BL , price > N2) = T A N1 query(BL, price > N2) if N1 > N2 . cq query( T A N1 , price > N2) = nil if N1 <= N2 . cq query( T A N1 , price > N2) = T A N1 if N1 > N2 . endo red query(doc2, price > 320) . ***> combined bookstore obj MY-BOOKSTORE-DTD is pr QID . pr INT . pr STRING . sorts Document Book BookList Title Author Price FirstName LastName . subsort Book < BookList . op nil : -> BookList . op _ _ : BookList BookList -> BookList [ assoc idr: nil ]. op _ : BookList -> Document . op _ _ _ : Title Author Price -> Book . op _ : String -> Title . op _ _ : FirstName LastName -> Author . op _ : Id -> FirstName . op _ : Id -> LastName . op _ : Int -> Price . endo obj QUERY-MY-BOOKSTORE is pr MY-BOOKSTORE-DTD . pr QUERY-BOOKSTORE1 . pr QUERY-BOOKSTORE2 . op doc : -> Document.MY-BOOKSTORE-DTD . op query : Document.MY-BOOKSTORE-DTD Query -> BookList.MY-BOOKSTORE-DTD . op f1 : BookList.BOOKSTORE1-DTD -> BookList.MY-BOOKSTORE-DTD . op f2 : BookList.BOOKSTORE2-DTD -> BookList.MY-BOOKSTORE-DTD . op q : Query -> Query . var Q : Query . var N : NzInt . var S : String . vars I1 I2 : Id . eq query(doc, Q) = f1(query(doc1, Q)) f2(query(doc2, q(Q))) . eq q(price > N) = price > (N * 8) . eq f1( S I1 I2 N ) = S I1 I2 N . eq f2( S I1 I2 N ) = S I1 I2 (N quo 8) . endo red query(doc, price > 50) .