1 XQuery Informationssysteme, 14.06.2007 Vortragender: Michael Schmidt.

Slides:



Advertisements
Ähnliche Präsentationen
Anzahl der ausgefüllten und eingesandten Fragebögen: 211
Advertisements

Vorlesung: 1 Betriebliche Informationssysteme 2003 Prof. Dr. G. Hellberg Studiengang Informatik FHDW Vorlesung: Betriebliche Informationssysteme Teil3.
Einführung in die Informatik: Programmierung und Software-Entwicklung
LS 2 / Informatik Datenstrukturen, Algorithmen und Programmierung 2 (DAP2)
LS 2 / Informatik Datenstrukturen, Algorithmen und Programmierung 2 (DAP2)
Erkennen Sie die Kirchenkreise Heiteres Ratespiel Kirchen aus der Region.
Telefonnummer.
CPCP Institute of Clinical Pharmacology AGAH Annual Meeting, 29. Februar 2004, Berlin, Praktischer Umgang mit den Genehmigungsanträgen gemäß 12. AMG Novelle.
Modelle und Methoden der Linearen und Nichtlinearen Optimierung (Ausgewählte Methoden und Fallstudien) U N I V E R S I T Ä T H A M B U R G November 2011.
Modelle und Methoden der Linearen und Nichtlinearen Optimierung (Ausgewählte Methoden und Fallstudien) U N I V E R S I T Ä T H A M B U R G November 2011.
Workshop zur Medienarbeit der katholischen Kirche Aspekte des Religionsmonitors Berlin, 02. April 2008.
1 JIM-Studie 2010 Jugend, Information, (Multi-)Media Landesanstalt für Kommunikation Baden-Württemberg (LFK) Landeszentrale für Medien und Kommunikation.
= = = = 47 = 47 = 48 = =
Rechneraufbau & Rechnerstrukturen, Folie 2.1 © W. Oberschelp, G. Vossen W. Oberschelp G. Vossen Kapitel 2.
Internet facts 2008-II Graphiken zu dem Berichtsband AGOF e.V. September 2008.
Vorlesung: 1 Betriebliche Informationssysteme 2003 Prof. Dr. G. Hellberg Studiengang Informatik FHDW Vorlesung: Betriebliche Informationssysteme Teil2.
Differentielles Paar UIN rds gm UIN
Maxwell-Boltzmann Ausgewählte Themen des analogen Schaltungsentwurfs
Prof. Dr. Bernhard Wasmayr
Studienverlauf im Ausländerstudium
Schieferdeckarten Dach.ppt
LS 2 / Informatik Datenstrukturen, Algorithmen und Programmierung 2 (DAP2)
Datenstrukturen, Algorithmen und Programmierung 2 (DAP2)
Prof. Dr. Bernhard Wasmayr VWL 2. Semester
AWA 2007 Natur und Umwelt Natürlich Leben
Rechneraufbau & Rechnerstrukturen, Folie 12.1 © W. Oberschelp, G. Vossen W. Oberschelp G. Vossen Kapitel 12.
20:00.
Die Geschichte von Rudi
„Küsse deine Freunde“ – FlexKom-App teilen
Zusatzfolien zu B-Bäumen
Kopfrechnen Logisch 4 Seite 52 Start. 1 Wie viel fehlt bis zu 1 h? 43 min.
In der Schule.
Eine Einführung in die CD-ROM
GBI Genios Wiso wiso bietet Ihnen das umfassendste Angebot deutsch- und englischsprachiger Literatur für die Wirtschafts- und Sozialwissenschaften. Wir.
Dokumentation der Umfrage
für Weihnachten oder als Tischdekoration für das ganze Jahr
1 Ein kurzer Sprung in die tiefe Vergangenheit der Erde.
Wir üben die Malsätzchen
Syntaxanalyse Bottom-Up und LR(0)
Datenbanktechnologie Daniel Ebner SS Mai Ulrike Lohner.
NEU! 1 2. Wo kommt diese Art von Rezeptor im Körper vor?
Aufgabensammlung Thermodynamik Frank-Michael Barth ISBN: © 2014 Oldenbourg Wissenschaftsverlag GmbH Abbildungsübersicht / List of Figures.
PROCAM Score Alter (Jahre)
Ertragsteuern, 5. Auflage Christiana Djanani, Gernot Brähler, Christian Lösel, Andreas Krenzin © UVK Verlagsgesellschaft mbH, Konstanz und München 2012.
Geometrische Aufgaben
Kennst du dich aus mit Nadelbäumen?
Symmetrische Blockchiffren DES – der Data Encryption Standard
Retuschen.ppt Die folgende Schau zeigt die Möglichkeiten, mit PhotoDraw Digitalbilder zu retuschieren. Vergleichen Sie jeweils zwei Bildpaare durch fleissiges.
1 (C)2006, Hermann Knoll, HTW Chur, FHO Quadratische Reste Definitionen: Quadratischer Rest Quadratwurzel Anwendungen.
Großer Altersunterschied bei Paaren fällt nicht auf!
Zahlentheorie und Zahlenspiele Hartmut Menzer, Ingo Althöfer ISBN: © 2014 Oldenbourg Wissenschaftsverlag GmbH Abbildungsübersicht / List.
MINDREADER Ein magisch - interaktives Erlebnis mit ENZO PAOLO
1 (C)2006, Hermann Knoll, HTW Chur, FHO Quadratische Reste Definitionen: Quadratischer Rest Quadratwurzel Anwendungen.
Schutzvermerk nach DIN 34 beachten 20/05/14 Seite 1 Grundlagen XSoft Lösung :Logische Grundschaltung IEC-Grundlagen und logische Verknüpfungen.
Folie Beispiel für eine Einzelauswertung der Gemeindedaten (fiktive Daten)
1 Arbeitsgemeinschaft Biologische Psychiatrie Verordnungsgewohnheiten von Psychopharmaka Statuserhebung 2005 W.Günther G.Laux T.Messer N.Müller M.Schmauss.
1 Mathematical Programming Nichtlineare Programmierung.
Imperfekt Wie sagt man das mit Imperfekt
Ertragsteuern, 5. Auflage Christiana Djanani, Gernot Brähler, Christian Lösel, Andreas Krenzin © UVK Verlagsgesellschaft mbH, Konstanz und München 2012.
Unternehmensbewertung Thomas Hering ISBN: © 2014 Oldenbourg Wissenschaftsverlag GmbH Abbildungsübersicht / List of Figures Tabellenübersicht.
Folie Einzelauswertung der Gemeindedaten
Numbers Greetings and Good-byes All about Me Verbs and Pronouns
1.6.3 Test auf Verlustfreiheit (Verbundtreue) (4|10)
J-Team: Gymnasium Ulricianum Aurich und MTV Aurich Ein Projekt im Rahmen von UlricianumBewegt.de Euro haben wir schon…  8000 mal habt ihr bereits.
Datum:17. Dezember 2014 Thema:IFRS Update zum Jahresende – die Neuerungen im Überblick Referent:Eberhard Grötzner, EMA ® Anlass:12. Arbeitskreis Internationale.
1 10 pt 15 pt 20 pt 25 pt 5 pt 10 pt 15 pt 20 pt 25 pt 5 pt 10 pt 15 pt 20 pt 25 pt 5 pt 10 pt 15 pt 20 pt 25 pt 5 pt 10 pt 15 pt 20 pt 25 pt 5 pt Wie.
Einführung in die Volkswirtschaftslehre, Mikroökonomie und Wettbewerbspolitik Lothar Wildmann ISBN: © 2014 Oldenbourg Wissenschaftsverlag.
Sehen, Hören, Schmecken: wenn uns unsere Sinne täuschen
1 Medienpädagogischer Forschungsverbund Südwest KIM-Studie 2014 Landesanstalt für Kommunikation Baden-Württemberg (LFK) Landeszentrale für Medien und Kommunikation.
Monatsbericht Ausgleichsenergiemarkt Gas – Oktober
 Präsentation transkript:

1 XQuery Informationssysteme, Vortragender: Michael Schmidt

2 XPath (Wiederholung) Anfragesprache auf XML XPath-Expressions selektieren Knoten des Eingabe-Dokuments bib book title author /bib//title

3 XPath (Wiederholung) Path Steps: axis::nodetest Axen: child, descendant, ancestor, following, following-sibling,... Node-tests: Tag, *, node(), text() Absolute Pfade: /step/step/… Relative Pfade: step/step/...

4 XQuery SQL für XML W3C Recommendation Funktionale Programmiersprache, Turing-vollständig XQueries enthalten XPath Ausdrücke Ergebnis einer XQuery: wohlgeformte XML- Dokumente (XPath: Menge von Knoten) Keine Datenmanipulationssprache (z.B. keine Updates)

5 Node-Construction und Konstanten { " Hello World " } XQuery Hello World Ergebnis " Hello World " XQuery "Hello World" Ergebnis

6 Dokument-Zugriff { doc( " bookstore.xml " )/bib/book[price>30] } T1 A1 50 T2 A2 20 T3 A3 bookstore.xml T1 A1 50 Ergebnis XQuery

7 Sequenz { ( doc( " bookstore.xml " )/bib/article/title, doc( " bookstore.xml " )/bib/book/title ) } T3 T1 T2 T1 A1 50 T2 A2 20 T3 A3 bookstore.xml Ergebnis XQuery Ordnung bleibt erhalten!

8 FR-Expression { for $book in doc( " bookstore.xml " )//book return $book/title } T1 A1 50 T2 A2 20 T3 A3 bookstore.xml T1 T2 Ergebnis XQuery

9 FWR-Expressions { for $book in doc( " bookstore.xml " )//book where $book/price>30 return { $book/title/text() } T1 A1 50 T2 A2 20 T3 A3 bookstore.xml T1 Ergebnis Konstruktion von Knoten, die im Dokument nicht vorkommen XQuery

10 FLWR-Expressions T1 A1 50 T2 A2 20 T3 A3 bookstore.xml { for $book in doc("bookstore.xml")//book let $booktitle := { $book/title/text() } where ($book/price>30) return $booktitle } T1 Ergebnis XQuery

11 FLWOR-Expressions { for $book in doc( " bookstore.xml " )//book let $booktitle := $book/title where ($book/price>10) order by $booktitle/text() descending return { $booktitle/text() } } T1 A1 50 T2 A2 20 T3 A3 bookstore.xml T2 T1 Ergebnis XQuery

12 Where-Expressions Konnektive and, or, fn:not T1 A1 50 T2 A2 20 T3 A3 bookstore.xml { for $book in doc( " bookstore.xml " )//book where ($book/price>10 and fn:not($book/author/text()= " A1 " )) return $book/title } T2 Ergebnis XQuery

13 Some-Expressions bookstore.xml { for $book in doc( " bookstore.xml " )//book where (some $a in $book/author satisfies $a/text()= " A2 " ) return $book/title } Ergebnis XQuery T1 A1 A2 T2 A3 A4 T1

14 For vs let-Expressions { for $x in (1 to 5) return {$x} } { let $x:=(1 to 5) return {$x} } XQuery 1 XQuery 2 Ergebnis Iteration keine Iteration Ergebnis

15 If-then-else Expressions { for $book in doc("bookstore.xml")//book return if (fn:exists($book/price)) then { $book/title } else { $book/title } } XQuery bookstore.xml T1 A1 T2 A2 30 T1 T2 Ergebnis

16 Vordefinierte Funktionen Zahlreiche built-in Functions: Boolean: fn:exists(), fn:empty() … String Manipulation: fn:concat(), fn:uppercase() … String Tests: fn:contains(), fn:starts-with() … Sequenzen: fn:exactly-one(), fn:distinct-values() … Mathematisch: fn:floor(), fn:round(), fn:abs() … …

17 Vordefinierte Funktionen { for $book in doc( " bookstore.xml " )//book where (fn:exists($book/price) and fn:contains($book/author, " A " )) return $book/title } XQuery T1 A1 50 T2 A2 20 T3 A3 bookstore.xml T1 T2 Ergebnis

18 XQuery Joins Vergleich unterschiedlicher Teile des Eingabe- Dokuments Auch Joins zwischen verschiedenen Dokumenten möglich Im Gegensatz zu SQL-Joins, oftmals nicht leicht zu erkennen, da keine eigene Syntax (kein JOIN-Keyword) Optimierung der Auswertung von Joins durch herkömmliche und XML-spezifische Methoden

19 XQuery Joins { for $bib in doc( " bookstore.xml " )/bib return for $book in $bib/book return for $article in $bib/article where $book/author=$article/author return { $book/title, $article/title} } XQuery bib book titleauthor T1A1 book titleauthor T2A2 article titleauthor T3A3 article titleauthor T4A1 $book $article T1 T4 Ergebnis

20 XQuery Joins { for $a in doc(" for $b in doc(" where $a/isbn = $b/isbn return { $b/title } { $a/price/text() } { $b/price/text() } } XQuery Join über zwei Dokumente

21 Aggregatfunktionen fn:min(), fn:max(), fn:count(), fn:sum(), fn:avg() { for $book in doc( " bookstore.xml " )//book return { ($book/title, { fn:count($book/author) } ) } XQuery bookstore.xml T1 A1 A2 T2 A3 T1 2 T2 1 Ergebnis

22 Aggregatfunktionen { for $o in fn:distinct-values(doc("adressen.xml")//ort) let $ort:=doc("adressen.xml")//ort[self::node()=$o] where fn:count($ort)>=2 order by $o return {($ort[1]/name,$ort[1]/plz)} {count($ort)} } Beispiel: Gegeben Adressdatenbank, berechne Orte und Zahl der Adressen für Orte mit mind. 2 Adressen adressen.xml SB S1 SB S2 … Ergebnis SB66121, NK66538, …

23 Datentransformation XML: Generalisierung von HTML XQuery ermöglicht Anfragen auf XML- Dokumente und direkte Ausgabe von HTML XML und XQuery in Web-Szenarien gut geeignet

24 Datentransformation T1 A1 50 T2 A2 20 T3 A3 bookstore.xml Angebot Buchliste { for $book in doc("bookstore.xml")//book return {$book/title/text()} {$book/author/text()} } XQuery

25 Datentransformation Angebot Buchliste T1 A1 T2 A2 Ergebnis

26 Vielfalt an Konstrukten FLWOR – Expressions Aggregationen Typkonversionen (nicht besprochen) Gleichheit von Knoten (Benutzerdefinierte) Funktionen Sehr komplex, effiziente Auswertung von XQuery noch immer ein aktives Forschungsgebiet

27 XQ – ein XQuery Fragment query ::= Ɛ | query | query query | var | var/axis::v | for var in var/axis::v return query | if cond then query else query cond ::= var = var | var = | true | some var in var/axis::v satisfies cond | cond and cond | cond or cond | not cond Syntax Composition-free XQ

28 Composition-free XQuery book bib book { let $x := { for $book in /bib/book return { $book } } for $b in $x/booklist/b return $b/* } XQuery

29 Composition-free XQuery book bib book booklist book b b $x $book { let $x := { for $book in /bib/book return { $book } } for $b in $x/booklist/b return $b/* } neu konstruiert XQuery

30 Composition-free XQuery book bib book booklist book b b $x book books book $book $b { let $x := { for $book in /bib/book return { $book } } for $b in $x/booklist/b return $b/* } XQuery

31 Composition-free XQuery in der Praxis: viele XQuery Anfragen mit Komposition können in äquivalente XQ-Anfragen umgeschrieben werden { let $x := { for $book in /bib/book return { $book } } for $b in $x/booklist/b return $b/* } { for $book in /bib/book return $book } XQuery XQ query

32 Eigenschaft von XQ niedrigere Komplexität in der Auswertung Variablen binden immer an einen Knoten im Eingabebaum { for $x in //x return for $y in $x//y return $y } x x yy $x r Ergebnis XQ expression

33 Eigenschaft von XQ niedrigere Komplexität in der Auswertung Variablen binden immer an einen Knoten im Eingabebaum x x yy $x $y r Ergebnis { for $x in //x return for $y in $x//y return $y } XQ expression

34 Eigenschaft von XQ niedrigere Komplexität in der Auswertung Variablen binden immer an einen Knoten im Eingabebaum x x yy $x $y r Ergebnis { for $x in //x return for $y in $x//y return $y } XQ expression

35 Eigenschaft von XQ niedrigere Komplexität in der Auswertung Variablen binden immer an einen Knoten im Eingabebaum x x yy $x r Ergebnis { for $x in //x return for $y in $x//y return $y } XQ expression

36 Eigenschaft von XQ niedrigere Komplexität in der Auswertung Variablen binden immer an einen Knoten im Eingabebaum x x yy $y r $x Ergebnis { for $x in //x return for $y in $x//y return $y } XQ expression

37 Eigenschaft von XQ niedrigere Komplexität in der Auswertung Variablen binden immer an einen Knoten im Eingabebaum x x yy r $x $y Ergebnis { for $x in //x return for $y in $x//y return $y } XQ expression

38 XQ formale Semantik k: Anzahl gebundener Variablen e: derzeitiges environment (Variablenbindung) false als leere Liste Ergebnis: Liste von Knoten

39 XQ formale Semantik

40 XQ formale Semantik

41 XQ Evaluierung [[ { $x 2 $x 1 } ]] 2 (, ) = [ [[$x 2 $x 1 ]] 2 (, ) ] = [ [[$x 2 ]] 2 (, ) [[$x 1 ]] 2 (, ) ] = [ ]

42 XQ Evaluierung { for $book in //book return if (some $author in $book/author satisfies $author/text()=A1) then $book else () } bookstore.xml T1 A1 T2 A2 XQuery

43 XQ Evaluierung [[ { for $book in //book return if (some $author in $book/author satisfies $author/text()=A1) then $book else ()} ]] 0 ()

44 XQ Evaluierung [[ { for $book in //book return if (some $author in $book/author satisfies $author/text()=A1) then $book else ()} ]] 0 () [[for $book in //book return if (some $author in $book/author satisfies $author/text()=A1) then $book else ()]] 0 ()

45 XQ Evaluierung [[ { for $book in //book return if (some $author in $book/author satisfies $author/text()=A1) then $book else ()} ]] 0 () [[for $book in //book return if (some $author in $book/author satisfies $author/text()=A1) then $book else ()]] 0 () l=[[//book]] 0 () = [ A1 T1, A2 T2 ]

46 XQ Evaluierung [[ { for $book in //book return if (some $author in $book/author satisfies $author/text()=A1) then $book else ()} ]] 0 () [[for $book in //book return if (some $author in $book/author satisfies $author/text()=A1) then $book else ()]] 0 () l=[[//book]] 0 () = [ A1 T1, A2 T2 ] [[if (some …)]] 1 (l 1 ) + [[if (some …)]] 1 (l 2 )

47 XQ Evaluierung [[if (some $author in $book/author satisfies $author/text()=A1) then $book else ()]] 1 ( A1 T1 ) [[ { for $book in //book return if (some $author in $book/author satisfies $author/text()=A1) then $book else ()} ]] 0 () [[for $book in //book return if (some $author in $book/author satisfies $author/text()=A1) then $book else ()]] 0 () l=[[//book]] 0 () = [ A1 T1, A2 T2 ] [[if (some …)]] 1 (l 1 ) + [[if (some …)]] 1 (l 2 )

48 XQ Evaluierung [[for $author in $book/author return $author/text()=A1]] 1 ( A1 T1 ) [[if (some $author in $book/author satisfies $author/text()=A1) then $book else ()]] 1 ( A1 T1 ) [[ { for $book in //book return if (some $author in $book/author satisfies $author/text()=A1) then $book else ()} ]] 0 () [[for $book in //book return if (some $author in $book/author satisfies $author/text()=A1) then $book else ()]] 0 () l=[[//book]] 0 () = [ A1 T1, A2 T2 ] [[if (some …)]] 1 (l 1 ) + [[if (some …)]] 1 (l 2 )

49 XQ Evaluierung l =[[$book/author]] 1 ( A1 T1 ) = [ A1 ] [[for $author in $book/author return $author/text()=A1]] 1 ( A1 T1 ) [[ { for $book in //book return if (some $author in $book/author satisfies $author/text()=A1) then $book else ()} ]] 0 () [[for $book in //book return if (some $author in $book/author satisfies $author/text()=A1) then $book else ()]] 0 () l=[[//book]] 0 () = [ A1 T1, A2 T2 ] [[if (some …)]] 1 (l 2 ) + [[if (some …)]] 1 (l 1 ) [[if (some $author in $book/author satisfies $author/text()=A1) then $book else ()]] 1 ( A1 T1 ) [[$author/text()=A1]] 2 ( …, A1 )

50 XQ Evaluierung [[$author/text()=A1]] 2 ( …, A1 ) [ ] l =[[$book/author]] 1 ( A1 T1 ) = [ A1 ] [[for $author in $book/author return $author/text()=A1]] 1 ( A1 T1 ) [[if (some $author in $book/author satisfies $author/text()=A1) then $book else ()]] 1 ( A1 T1 ) [[ { for $book in //book return if (some $author in $book/author satisfies $author/text()=A1) then $book else ()} ]] 0 () [[for $book in //book return if (some $author in $book/author satisfies $author/text()=A1) then $book else ()]] 0 () l=[[//book]] 0 () = [ A1 T1, A2 T2 ] [[if (some …)]] 1 (l 1 ) + [[if (some …)]] 1 (l 2 ) [[$author/text()]] 2 (…) [A1] [[A1]] 2 (…) [A1]

51 XQ Evaluierung [[$author/text()=A1]] 2 ( …, A1 ) [ ] l =[[$book/author]] 1 ( A1 T1 ) = [ A1 ] [[for $author in $book/author return $author/text()=A1]] 1 ( A1 T1 ) [ ] [[if (some $author in $book/author satisfies $author/text()=A1) then $book else ()]] 1 ( A1 T1 ) [[ { for $book in //book return if (some $author in $book/author satisfies $author/text()=A1) then $book else ()} ]] 0 () [[for $book in //book return if (some $author in $book/author satisfies $author/text()=A1) then $book else ()]] 0 () l=[[//book]] 0 () = [ A1 T1, A2 T2 ] [[if (some …)]] 1 (l 1 ) + [[if (some …)]] 1 (l 2 )

52 XQ Evaluierung [[$book]] 1 ( A1 T1 ) [ A1 T1 ] [[$author/text()=A1]] 2 ( …, A1 ) [ ] l =[[$book/author]] 1 ( A1 T1 ) = [ A1 ] [[for $author in $book/author return $author/text()=A1]] 1 ( A1 T1 ) [ ] [[if (some $author in $book/author satisfies $author/text()=A1) then $book else ()]] 1 ( A1 T1 ) [ A1 T1 ] [[ { for $book in //book return if (some $author in $book/author satisfies $author/text()=A1) then $book else ()} ]] 0 () [[for $book in //book return if (some $author in $book/author satisfies $author/text()=A1) then $book else ()]] 0 () l=[[//book]] 0 () = [ A1 T1, A2 T2 ] [[if (some …)]] 1 (l 1 ) + [[if (some …)]] 1 (l 2 ) [ A1 T1 ] +

53 XQ Evaluierung [[ { for $book in //book return if (some $author in $book/author satisfies $author/text()=A1) then $book else ()} ]] 0 () [[for $book in //book return if (some $author in $book/author satisfies $author/text()=A1) then $book else ()]] 0 () l=[[//book]] 0 () = [ A1 T1, A2 T2 ] [[if (some …)]] 1 (l 1 ) + [[if (some …)]] 1 (l 2 ) [ A1 T1 ] + [[if (some $author in $book/author satisfies $author/text()=A1) then $book else ()]] 1 ( A2 T2 )

54 XQ Evaluierung [[ { for $book in //book return if (some $author in $book/author satisfies $author/text()=A1) then $book else ()} ]] 0 () [[for $book in //book return if (some $author in $book/author satisfies $author/text()=A1) then $book else ()]] 0 () l=[[//book]] 0 ()= [ A1 T1, A2 T2 ] [[if (some …)]] 1 (l 0 ) + [[if (some …)]] 1 (l 1 ) [ A1 T1 ] + [[if (some $author in $book/author satisfies $author/text()=A1) then $book else ()]] 1 ( A2 T2 ) [[for $author in $book/author return $author/text()=A1]] 1 ( A2 T2 )

55 XQ Evaluierung [[ { for $book in //book return if (some $author in $book/author satisfies $author/text()=A1) then $book else ()} ]] 0 () [[for $book in //book return if (some $author in $book/author satisfies $author/text()=A1) then $book else ()]] 0 () l=[[//book]] 0 ()= [ A1 T1, A2 T2 ] [[if (some …)]] 1 (l 1 ) + [[if (some …)]] 1 (l 2 ) [ A1 T1 ] + [[if (some $author in $book/author satisfies $author/text()=A1) then $book else ()]] 1 ( A2 T2 ) [[for $author in $book/author return $author/text()=A1]] 1 ( A2 T2 ) l =[[$book/author]] 1 ( A2 T2 ) = [ A2 ] [[$author/text()=A1]] 2 ( …, A2 )

56 XQ Evaluierung [[ { for $book in //book return if (some $author in $book/author satisfies $author/text()=A1) then $book else ()} ]] 0 () [[for $book in //book return if (some $author in $book/author satisfies $author/text()=A1) then $book else ()]] 0 () l=[[//book]] 0 () = [ A1 T1, A2 T2 ] [[if (some …)]] 1 (l 1 ) + [[if (some …)]] 1 (l 2 ) [ A1 T1 ] + [[if (some $author in $book/author satisfies $author/text()=A1) then $book else ()]] 1 ( A2 T2 ) [[for $author in $book/author return $author/text()=A1]] 1 ( A2 T2 ) l =[[$book/author]] 1 ( A2 T2 ) = [ A2 ] [[$author/text()=A1]] 2 ( …, A2 ) [] [[$author/text()]] 2 (…) [A2] [[A1]] 2 (…) [A1]

57 XQ Evaluierung [[ { for $book in //book return if (some $author in $book/author satisfies $author/text()=A1) then $book else ()} ]] 0 () [[for $book in //book return if (some $author in $book/author satisfies $author/text()=A1) then $book else ()]] 0 () l=[[//book]] 0 () = [ A1 T1, A2 T2 ] [[if (some …)]] 1 (l 1 ) + [[if (some …)]] 1 (l 2 ) [ A1 T1 ] + [[if (some $author in $book/author satisfies $author/text()=A1) then $book else ()]] 1 ( A2 T2 ) [[for $author in $book/author return $author/text()=A1]] 1 ( A2 T2 ) [] l =[[$book/author]] 1 ( A2 T2 ) = [ A2 ] [[$author/text()=A1]] 2 ( …, A2 ) []

58 XQ Evaluierung [[ { for $book in //book return if (some $author in $book/author satisfies $author/text()=A1) then $book else ()} ]] 0 () [[for $book in //book return if (some $author in $book/author satisfies $author/text()=A1) then $book else ()]] 0 () l=[[//book]] 0 () = [ A1 T1, A2 T2 ] [[if (some …)]] 1 (l 1 ) + [[if (some …)]] 1 (l 2 ) [ A1 T1 ] + [[if (some $author in $book/author satisfies $author/text()=A1) then $book else ()]] 1 ( A2 T2 ) [] [[for $author in $book/author return $author/text()=A1]] 1 ( A2 T2 ) [] l =[[$book/author]] 1 ( A2 T2 ) = [ A2 ] [[$author/text()=A1]] 2 ( …, A2 ) [] [[()]] 1 ( A2 T2 ) [] []

59 XQ Evaluierung [[ { for $book in //book return if (some $author in $book/author satisfies $author/text()=A1) then $book else ()} ]] 0 () [[for $book in //book return if (some $author in $book/author satisfies $author/text()=A1) then $book else ()]] 0 () [ A1 T1 ] l=[[//book]] 0 () = [ A1 T1, A2 T2 ] [[if (some …)]] 1 (l 1 ) + [[if (some …)]] 1 (l 2 ) [ A1 T1 ] + [] [[if (some $author in $book/author satisfies $author/text()=A1) then $book else ()]] 1 ( A2 T2 ) [] [[for $author in $book/author return $author/text()=A1]] 1 ( A2 T2 ) [] l =[[$book/author]] 1 ( A2 T2 ) = [ A2 ] [[$author/text()=A1]] 2 ( …, A2 ) [] [[()]] 1 ( A2 T2 ) []

60 XQ Evaluierung [[ { for $book in //book return if (some $author in $book/author satisfies $author/text()=A1) then $book else ()} ]] 0 () [ A1 T1 ] [[for $book in //book return if (some $author in $book/author satisfies $author/text()=A1) then $book else ()]] 0 () [ A1 T1 ] l=[[//book]] 0 () = [ A1 T1, A2 T2 ] [[if (some …)]] 1 (l 1 ) + [[if (some …)]] 1 (l 2 ) [ A1 T1 ] + [] [[if (some $author in $book/author satisfies $author/text()=A1) then $book else ()]] 1 ( A2 T2 ) [] [[for $author in $book/author return $author/text()=A1]] 1 ( A2 T2 ) [] l =[[$book/author]] 1 ( A2 T2 ) = [ A2 ] [[$author/text()=A1]] 2 ( …, A2 ) [] [[()]] 1 ( A2 T2 ) []

61 XQ: 2 Arten von Gleichheit Deep Equality Vergleiche Bäume als Werte z.B.: n1 deep-equal n2 n2 deep-equal n7 n3 = deep-equal n10 n4 = deep-equal n11 n4 deep-equal n10 Atomic Equality Vergleiche Blätter als Werte z.B.: n4 = atomic n11 n4 atomic n9 n1: people n2: person n4: Karln6: Auer n7: person n5: lnn3: fn n9: Auern11: Karl n10: fnn8: ln

62 XQuery – Komplexere Beispiele { for $b in doc("doc.xml")//book where fn:count($b/author) > 0 return { $b/title } { for $a in $b/author[position()<=2] return $a } { if (fn:count($b/author) > 2) then else () } } Für jedes Buch mit mindestens einem Autor, gib den Titel und die ersten beiden Autoren aus und ein leeres et-al-Element wenn das Buch weitere Autoren besitzt XQuery

63 XQuery – Komplexere Beispiele Finde den minimalen Preis für jedes Buch und gib ihn in der Form eines minprice-Elements mit dem Titel des Buchs als title-Attribut aus. { let $doc := doc("doc.xml") for $t in fn:distinct-values($doc//book/title) let $p := $doc//book[title = $t]/price return { fn:min($p) } } XQuery

64 XQuery – Komplexere Beispiele Gib alle Paare von Büchern aus, die unterschiedliche Titel aber die selben Autoren (möglicherweise in unterschiedlicher Reihenfolge) haben. { for $book1 in doc("doc.xml")//book, $book2 in doc("doc.xml")//book let $aut1:=for $a in $book1/author order by $a/last, $a/first return $a let $aut2 := for $a in $book2/author order by $a/last, $a/first return $a where $book1 << $book2 and not($book1/title = $book2/title) and fn:deep-equal($aut1, $aut2) return { $book1/title } { $book2/title } } XQuery Annahme: Autoren haben die Form FIRSTNAME LASTNAME <<: vor

65 Literatur und Links Buch XQuery from the Experts, Addison Wesley (Kapitel 1) (Howard Katz, Don Chamberlin, Denise Draper, Mary Fernandez, Michael Kay, Jonathan Robie, Michael Rys, Jerome Simeon, Jim Tivy, Philip Wadler) XQuery Tutorial: W3C XQuery: W3C XQuery Functions: Galax XQuery Engine (installiert in CIP-Pools):