q11.cd 2.99 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98

type Bib = <bib>[Book*]
type Book = <book year=String>[Title  (Author+ | Editor+ ) Publisher Price ]
type Author = <author>[Last  First ]
type Editor = <editor>[Last  First  Affiliation ]
type Title  = <title>[PCDATA ]
type Last  = <last>[PCDATA]
type First  = <first>[PCDATA]
type Affiliation = <affiliation>[PCDATA]
type Publisher  = <publisher>[PCDATA]
type Price  = <price>[PCDATA];;

let doc : Bib = <bib>[
             <book year="1994">[
                  <title>['TCP/IP Illustrated']
                  <author>[<last>['Stevens']
                  <first>['W.']]
                  <publisher>['Addison-Wesley']
                  <price>['65.95']
             ]
             <book year="1992">[
                  <title>['Advanced Programming in the Unix environment']
                  <author>[<last>['Stevens'] <first>['W.']]
                  <publisher>['Addison-Wesley']
                  <price>['65.95']
             ]
             <book year="2000">[ 
                  <title>['Data on the Web']
                  <author>[<last>['Abiteboul'] <first>['Serge']]
                  <author>[<last>['Buneman'] <first>['Peter']]
                  <author>[<last>['Suciu'] <first>['Dan']]
                  <publisher>['Morgan Kaufmann Publishers']
                  <price>['39.95']
            ]
            <book year="1999">[
                  <title>['The Economics of Technology and Content for Digital TV']
                  <editor>[
                      <last>['Gerbarg'] <first>['Darcy']
                      <affiliation>['CITI']
                  ]
                  <publisher>['Kluwer Academic Publishers']
                  <price>['129.95']
             ]];;
	     
	     
	     
(*
--------------------------------Q11------------------------------------------
For each book with an author, return the book with its title and authors. 
For each book with an editor, return a reference with the book title and the editor`s affiliation.
-------------------------------------------------------------------------------
<bib>
{
        for $b in doc("http://bstore1.example.com/bib.xml")//book[author]
        return
            <book>
                { $b/title }
                { $b/author }
            </book>
}
{
        for $b in doc("http://bstore1.example.com/bib.xml")//book[editor]
        return
          <reference>
            { $b/title }
            {$b/editor/affiliation}
          </reference>
}
</bib>  

*)

<bib>((
select <book>(([b]/Title) @ ([b]/Author))
from b in [doc]/<book ..>[_ Author;_])
@
(select <reference>(([b]/Title) @ ([b]/Editor/Affiliation))
from b in [doc]/<book ..>[_ Editor;_]     
));;


<bib>((
select <book>([t] @ la)
from <bib>[b::Book+] in [doc],
     <book ..>[t&Title la::Author+ ;_] in b
)@(
select <reference>[t aff]
from <bib>[b::Book+] in [doc],
     <book ..>[t&Title _* <editor>[_* aff&Affiliation] ;_] in b));;



<bib>
select <(tag)>([t] @ [a1] @a2)
from <book ..>[t&Title ((tag:=`book)&a1&Author a2::Author* | (tag:=`reference)&a1&Editor a2::Editor*) _*] in [doc]/Book;;