Prepare a (nested) table of contents for Book1, listing all the sections and their titles. Preserve the original attributes of each
element, if any. Solution in XQuery: declare function local:toc($book-or-section as element()) as element()* { for $section in $book-or-section/section return
{ $section/@* , $section/title , local:toc($section) }
}; { for $s in doc("book.xml")/book return local:toc($s) } Expected Result:
Introduction
Audience
Web Data and the Two Cultures
A Syntax For Data
Base Types
Representing Relational Databases
Representing Object Databases
Prepare a (flat) figure list for Book1, listing all the figures and their titles. Preserve the original attributes of each
element, if any. Solution in XQuery: { for $f in doc("book.xml")//figure return
{ $f/@* } { $f/title }
}
Expected Result:
Traditional client/server architecture
Graph representations of structures
Examples of Relations
How many sections are in Book1, and how many figures? Solution in XQuery: { count(doc("book.xml")//section) }, { count(doc("book.xml")//figure) } Expected Result: 7 3 How many top-level sections are in Book1? Solution in XQuery: { count(doc("book.xml")/book/section) } Expected Result: 2 Make a flat list of the section elements in Book1. In place of its original attributes, each section element should have two attributes, containing the title of the section and the number of figures immediately contained in the section. Solution in XQuery: { for $s in doc("book.xml")//section let $f := $s/figure return
} Expected Result:
Make a nested list of the section elements in Book1, preserving their original attributes and hierarchy. Inside each section element, include the title of the section and an element that includes the number of figures immediately contained in the section. Solution in XQuery: declare function local:section-summary($book-or-section as element()) as element()* { for $section in $book-or-section return
{ $section/@* } { $section/title } { count($section/figure) } { local:section-summary($section/section) }
}; { for $s in doc("book.xml")/book/section return local:section-summary($s) } Editorial note This solution was provided by Michael Wenger, a student at the University of Würzburg. Expected Result:
Introduction 0
Audience 0
Web Data and the Two Cultures 1
A Syntax For Data 1
Base Types 0
Representing Relational Databases 1
Representing Object Databases 0