Preface |
|
xvii | |
1 Introduction to XQuery |
|
1 | (14) |
|
|
1 | (3) |
|
|
2 | (1) |
|
|
2 | (1) |
|
|
3 | (1) |
|
|
4 | (1) |
|
|
5 | (2) |
|
|
7 | (1) |
|
Adding XML Elements and Attributes |
|
|
8 | (3) |
|
|
9 | (2) |
|
|
11 | (1) |
|
|
11 | (1) |
|
|
12 | (1) |
|
Aggregating and Grouping Values |
|
|
12 | (3) |
2 XQuery Foundations |
|
15 | (16) |
|
The Design and History of the XQuery Language |
|
|
15 | (1) |
|
|
16 | (2) |
|
|
16 | (1) |
|
|
16 | (1) |
|
|
17 | (1) |
|
|
17 | (1) |
|
|
18 | (3) |
|
|
18 | (1) |
|
|
19 | (1) |
|
|
20 | (1) |
|
|
20 | (1) |
|
|
21 | (1) |
|
|
21 | (7) |
|
|
22 | (4) |
|
|
26 | (1) |
|
|
27 | (1) |
|
|
28 | (1) |
|
|
28 | (3) |
3 Expressions: XQuery Building Blocks |
|
31 | (16) |
|
Categories of Expressions |
|
|
31 | (1) |
|
|
32 | (1) |
|
|
33 | (1) |
|
|
33 | (1) |
|
|
34 | (1) |
|
|
34 | (1) |
|
|
35 | (1) |
|
Precedence and Parentheses |
|
|
35 | (2) |
|
|
37 | (4) |
|
|
37 | (1) |
|
|
38 | (2) |
|
|
40 | (1) |
|
Conditional (if-then-else) Expressions |
|
|
41 | (2) |
|
Conditional Expressions and Effective Boolean Value |
|
|
42 | (1) |
|
Nesting Conditional Expressions |
|
|
43 | (1) |
|
|
43 | (2) |
|
Logical (and/or) Expressions |
|
|
45 | (2) |
|
Precedence of Logical Expressions |
|
|
45 | (1) |
|
|
46 | (1) |
4 Navigating XML by Using Paths |
|
47 | (18) |
|
|
47 | (7) |
|
Path Expressions and Context |
|
|
48 | (1) |
|
|
49 | (1) |
|
|
49 | (1) |
|
|
50 | (3) |
|
|
53 | (1) |
|
Other Expressions as Steps |
|
|
53 | (1) |
|
|
54 | (6) |
|
Comparisons in Predicates |
|
|
55 | (1) |
|
Using Positions in Predicates |
|
|
56 | (3) |
|
Using Multiple Predicates |
|
|
59 | (1) |
|
|
59 | (1) |
|
|
60 | (2) |
|
Working with the Context Node |
|
|
61 | (1) |
|
|
61 | (1) |
|
|
62 | (1) |
|
|
63 | (2) |
5 Adding Elements and Attributes to Results |
|
65 | (18) |
|
Including Elements and Attributes from the Input Document |
|
|
65 | (1) |
|
Direct Element Constructors |
|
|
66 | (11) |
|
Containing Literal Characters |
|
|
67 | (1) |
|
Containing Other Element Constructors |
|
|
68 | (1) |
|
Containing Enclosed Expressions |
|
|
68 | (3) |
|
Specifying Attributes Directly |
|
|
71 | (1) |
|
Declaring Namespaces in Direct Constructors |
|
|
72 | (1) |
|
Use Case: Modifying an Element from the Input Document |
|
|
73 | (1) |
|
Direct Element Constructors and Whitespace |
|
|
74 | (3) |
|
|
77 | (6) |
|
Computed Element Constructors |
|
|
77 | (3) |
|
Computed Attribute Constructors |
|
|
80 | (1) |
|
Use Case: Turning Content to Markup |
|
|
80 | (3) |
6 Selecting and Joining Using FLWORs |
|
83 | (16) |
|
Selecting with Path Expressions |
|
|
83 | (1) |
|
|
83 | (8) |
|
|
85 | (3) |
|
|
88 | (1) |
|
|
89 | (1) |
|
|
90 | (1) |
|
|
91 | (1) |
|
|
91 | (2) |
|
Binding Multiple Variables |
|
|
93 | (1) |
|
Selecting Distinct Values |
|
|
93 | (2) |
|
|
95 | (4) |
|
|
96 | (1) |
|
|
96 | (2) |
|
|
98 | (1) |
7 Sorting and Grouping |
|
99 | (20) |
|
|
99 | (9) |
|
|
99 | (4) |
|
|
103 | (1) |
|
|
103 | (2) |
|
Document Order Comparisons |
|
|
105 | (1) |
|
|
106 | (1) |
|
Indicating That Order Is Not Significant |
|
|
106 | (2) |
|
|
108 | (4) |
|
Grouping Using the group by Clause |
|
|
109 | (3) |
|
|
112 | (7) |
|
Ignoring "Missing" Values |
|
|
114 | (1) |
|
Counting "Missing" Values |
|
|
115 | (1) |
|
Aggregating on Multiple Values |
|
|
116 | (1) |
|
Constraining and Sorting on Aggregated Values |
|
|
116 | (3) |
8 Functions |
|
119 | (14) |
|
Built-in Versus User-Defined Functions |
|
|
119 | (1) |
|
|
119 | (5) |
|
|
120 | (1) |
|
|
121 | (1) |
|
|
121 | (2) |
|
|
123 | (1) |
|
Calling Functions with the Arrow Operator |
|
|
124 | (1) |
|
|
124 | (9) |
|
Why Define Your Own Functions? |
|
|
124 | (1) |
|
|
125 | (1) |
|
|
126 | (1) |
|
|
127 | (1) |
|
|
127 | (3) |
|
|
130 | (1) |
|
|
130 | (3) |
9 Advanced Queries |
|
133 | (24) |
|
Working with Positions and Sequence Numbers |
|
|
133 | (5) |
|
Adding Sequence Numbers to Results |
|
|
133 | (2) |
|
|
135 | (2) |
|
Testing for the Last Item |
|
|
137 | (1) |
|
|
138 | (6) |
|
Using start and end Conditions |
|
|
140 | (1) |
|
Windows Based on Position |
|
|
141 | (1) |
|
Windows Based on Previous or Next Items |
|
|
142 | (1) |
|
|
143 | (1) |
|
Copying Input Elements with Modifications |
|
|
144 | (6) |
|
Adding Attributes to an Element |
|
|
145 | (1) |
|
Removing Attributes from an Element |
|
|
146 | (1) |
|
Removing Attributes from All Descendants |
|
|
147 | (1) |
|
|
147 | (1) |
|
|
148 | (2) |
|
|
150 | (2) |
|
|
150 | (1) |
|
|
151 | (1) |
|
|
151 | (1) |
|
|
151 | (1) |
|
Using Intermediate XML Documents |
|
|
152 | (5) |
|
|
152 | (1) |
|
|
153 | (4) |
10 Namespaces and XQuery |
|
157 | (22) |
|
|
157 | (4) |
|
|
157 | (1) |
|
|
158 | (1) |
|
Default Namespace Declarations |
|
|
159 | (1) |
|
Namespaces and Attributes |
|
|
159 | (1) |
|
Namespace Declarations and Scope |
|
|
160 | (1) |
|
|
161 | (1) |
|
Namespace Declarations in Queries |
|
|
162 | (8) |
|
|
162 | (1) |
|
Prolog Namespace Declarations |
|
|
163 | (3) |
|
Namespace Declarations in Direct Element Constructors |
|
|
166 | (1) |
|
Namespace Declarations in Computed Constructors |
|
|
167 | (1) |
|
The Impact and Scope of Namespace Declarations |
|
|
168 | (2) |
|
Controlling Namespace Declarations in Your Results |
|
|
170 | (7) |
|
In-Scope Versus Statically Known Namespaces |
|
|
171 | (3) |
|
Controlling the Copying of Namespace Declarations |
|
|
174 | (3) |
|
|
177 | (2) |
11 A Closer Look at Types |
|
179 | (22) |
|
|
179 | (2) |
|
Advantages of a Strong Type System |
|
|
179 | (1) |
|
Do You Need to Care About Types? |
|
|
180 | (1) |
|
|
181 | (2) |
|
|
181 | (2) |
|
|
183 | (1) |
|
|
183 | (1) |
|
Types, Nodes, and Atomic Values |
|
|
183 | (1) |
|
|
183 | (1) |
|
|
184 | (1) |
|
|
184 | (1) |
|
The Static Analysis Phase |
|
|
184 | (1) |
|
The Dynamic Evaluation Phase |
|
|
185 | (1) |
|
Automatic Type Conversions |
|
|
185 | (5) |
|
|
185 | (1) |
|
|
186 | (1) |
|
Casting of Untyped Values |
|
|
186 | (1) |
|
|
186 | (1) |
|
|
187 | (2) |
|
Function Conversion Rules |
|
|
189 | (1) |
|
|
190 | (5) |
|
|
191 | (1) |
|
|
192 | (1) |
|
Simple Type Names as Sequence Types |
|
|
193 | (1) |
|
Element and Attribute Tests |
|
|
193 | (1) |
|
|
194 | (1) |
|
The instance of Expression |
|
|
194 | (1) |
|
|
195 | (6) |
|
|
195 | (1) |
|
|
196 | (1) |
|
|
197 | (1) |
|
|
198 | (3) |
12 Prologs, Modules, and Variables |
|
201 | (12) |
|
Structure of a Query: Prolog and Body |
|
|
201 | (3) |
|
|
202 | (1) |
|
|
203 | (1) |
|
Assembling Queries from Multiple Modules |
|
|
204 | (4) |
|
|
204 | (1) |
|
Importing a Library Module |
|
|
205 | (2) |
|
Loading a Library Module Dynamically |
|
|
207 | (1) |
|
|
208 | (3) |
|
Variable Declaration Syntax |
|
|
208 | (1) |
|
|
209 | (1) |
|
|
209 | (1) |
|
|
210 | (1) |
|
|
210 | (1) |
|
Private Functions and Variables |
|
|
211 | (1) |
|
Declaring External Functions |
|
|
211 | (2) |
13 Inputs and Outputs |
|
213 | (14) |
|
Types of Input and Output Documents |
|
|
213 | (1) |
|
Accessing Input Documents |
|
|
214 | (3) |
|
Accessing a Single Document with a Function |
|
|
214 | (1) |
|
|
215 | (1) |
|
Setting the Context Outside the Query |
|
|
216 | (1) |
|
|
216 | (1) |
|
Setting the Context in the Prolog |
|
|
217 | (1) |
|
|
217 | (10) |
|
|
218 | (2) |
|
|
220 | (4) |
|
Specifying Serialization Parameters by Using Option Declarations |
|
|
224 | (1) |
|
Specifying Serialization Parameters by Using a Separate XML Document |
|
|
225 | (1) |
|
|
226 | (1) |
|
|
226 | (1) |
14 Using Schemas with XQuery |
|
227 | (18) |
|
|
227 | (1) |
|
Why Use Schemas with Queries? |
|
|
228 | (2) |
|
W3C XML Schema: A Brief Overview |
|
|
230 | (3) |
|
Element and Attribute Declarations |
|
|
230 | (1) |
|
|
231 | (1) |
|
Namespaces and XML Schema |
|
|
232 | (1) |
|
In-Scope Schema Definitions |
|
|
233 | (3) |
|
Where Do In-Scope Schema Definitions Come From? |
|
|
233 | (1) |
|
|
234 | (2) |
|
Schema Validation and Type Assignment |
|
|
236 | (5) |
|
|
236 | (2) |
|
|
238 | (1) |
|
Assigning Type Annotations to Nodes |
|
|
238 | (1) |
|
|
239 | (1) |
|
Types and Newly Constructed Elements and Attributes |
|
|
240 | (1) |
|
Sequence Types and Schemas |
|
|
241 | (4) |
15 Static Typing |
|
245 | (10) |
|
|
245 | (3) |
|
Obvious Static Type Errors |
|
|
246 | (1) |
|
Static Typing and Schemas |
|
|
246 | (1) |
|
|
247 | (1) |
|
Static Typing Expressions and Constructs |
|
|
247 | (1) |
|
The Typeswitch Expression |
|
|
248 | (2) |
|
|
250 | (1) |
|
|
251 | (2) |
|
Type Declarations in FLWORs |
|
|
251 | (1) |
|
Type Declarations in Quantified Expressions |
|
|
252 | (1) |
|
Type Declarations in Global Variable Declarations |
|
|
253 | (1) |
|
The zero-or-one, one-or-more, and exactly-one Functions |
|
|
253 | (2) |
16 Writing Better Queries |
|
255 | (14) |
|
|
255 | (1) |
|
|
256 | (3) |
|
|
256 | (1) |
|
|
257 | (1) |
|
Using Comments for Documentation |
|
|
257 | (2) |
|
|
259 | (1) |
|
|
259 | (3) |
|
|
259 | (1) |
|
|
260 | (2) |
|
|
262 | (3) |
|
|
262 | (1) |
|
The error and trace Functions |
|
|
263 | (1) |
|
|
263 | (2) |
|
|
265 | (4) |
|
Avoid Reevaluating the Same or Similar Expressions |
|
|
266 | (1) |
|
Avoid Unnecessary Sorting |
|
|
266 | (1) |
|
Avoid Expensive Path Expressions |
|
|
267 | (1) |
|
Use Predicates Instead of where Clauses |
|
|
268 | (1) |
17 Working with Numbers |
|
269 | (14) |
|
|
269 | (1) |
|
|
269 | (1) |
|
|
269 | (1) |
|
The xs:float and xs:double Types |
|
|
270 | (1) |
|
|
270 | (1) |
|
Constructing Numeric Values |
|
|
270 | (2) |
|
|
271 | (1) |
|
|
271 | (1) |
|
|
272 | (1) |
|
|
273 | (4) |
|
Arithmetic Operations on Multiple Values |
|
|
274 | (1) |
|
Arithmetic Operations and Types |
|
|
274 | (1) |
|
Precedence of Arithmetic Operators |
|
|
274 | (1) |
|
Addition, Subtraction, and Multiplication |
|
|
275 | (1) |
|
|
275 | (1) |
|
|
276 | (1) |
|
|
277 | (2) |
|
|
279 | (4) |
|
|
279 | (1) |
|
Formatting Decimal Numbers |
|
|
280 | (1) |
|
The Decimal Format Declaration |
|
|
280 | (3) |
18 Working with Strings |
|
283 | (16) |
|
|
283 | (1) |
|
|
283 | (1) |
|
|
284 | (1) |
|
The xs:string Constructor and the string Function |
|
|
284 | (1) |
|
|
284 | (3) |
|
|
285 | (1) |
|
Determining Whether a String Contains Another String |
|
|
285 | (1) |
|
Matching a String to a Pattern |
|
|
286 | (1) |
|
|
287 | (1) |
|
Finding the Length of a String |
|
|
288 | (1) |
|
Concatenating and Splitting Strings |
|
|
289 | (2) |
|
|
289 | (1) |
|
|
290 | (1) |
|
Converting Between Codepoints and Strings |
|
|
291 | (1) |
|
|
291 | (3) |
|
Converting Between Uppercase and Lowercase |
|
|
291 | (1) |
|
Replacing Individual Characters in Strings |
|
|
292 | (1) |
|
Replacing Substrings That Match a Pattern |
|
|
292 | (2) |
|
|
294 | (1) |
|
|
294 | (1) |
|
Internationalization Considerations |
|
|
295 | (4) |
|
|
295 | (2) |
|
|
297 | (1) |
|
Determining the Language of an Element |
|
|
297 | (2) |
19 Regular Expressions |
|
299 | (16) |
|
The Structure of a Regular Expression |
|
|
299 | (2) |
|
|
299 | (1) |
|
|
299 | (1) |
|
Parenthesized Sub-Expressions and Branches |
|
|
300 | (1) |
|
Representing Individual Characters |
|
|
301 | (2) |
|
Representing Any Character |
|
|
303 | (1) |
|
Representing Groups of Characters |
|
|
303 | (3) |
|
|
304 | (1) |
|
|
304 | (1) |
|
|
305 | (1) |
|
Character Class Expressions |
|
|
306 | (2) |
|
Single Characters and Ranges |
|
|
306 | (1) |
|
|
307 | (1) |
|
Negative Character Class Expressions |
|
|
307 | (1) |
|
Escaping Rules for Character Class Expressions |
|
|
308 | (1) |
|
|
308 | (1) |
|
|
309 | (1) |
|
|
310 | (1) |
|
|
311 | (1) |
|
Using Sub-Expressions with Replacement Variables |
|
|
312 | (3) |
20 Working with Dates, Times, and Durations |
|
315 | (14) |
|
|
315 | (4) |
|
Constructing and Casting Dates and Times |
|
|
316 | (1) |
|
|
317 | (1) |
|
Comparing Dates and Times |
|
|
318 | (1) |
|
|
319 | (2) |
|
The xs:yearMonthDuration and xs:dayTimeDuration Types |
|
|
320 | (1) |
|
|
320 | (1) |
|
Extracting Components of Dates, Times, and Durations |
|
|
321 | (1) |
|
Formatting Dates and Times |
|
|
322 | (1) |
|
Using Arithmetic Operators on Dates, Times, and Durations |
|
|
323 | (4) |
|
Subtracting Dates and Times |
|
|
323 | (1) |
|
Adding and Subtracting Durations from Dates and Times |
|
|
324 | (1) |
|
Adding and Subtracting Two Durations |
|
|
325 | (1) |
|
Multiplying and Dividing Durations by Numbers |
|
|
326 | (1) |
|
Dividing Durations by Durations |
|
|
326 | (1) |
|
|
327 | (2) |
21 Working with Qualified Names, URIs, and IDs |
|
329 | (14) |
|
Working with Qualified Names |
|
|
329 | (5) |
|
|
330 | (2) |
|
Constructing Qualified Names |
|
|
332 | (1) |
|
Other Name-Related Functions |
|
|
333 | (1) |
|
|
334 | (5) |
|
|
334 | (2) |
|
|
336 | (2) |
|
|
338 | (1) |
|
|
339 | (4) |
|
|
340 | (1) |
|
Constructing ID Attributes |
|
|
341 | (1) |
|
Generating Unique ID Values |
|
|
341 | (2) |
22 Working with Other XML Constructs |
|
343 | (16) |
|
|
343 | (3) |
|
XML Comments and the Data Model |
|
|
343 | (1) |
|
|
344 | (1) |
|
Comments and Sequence Types |
|
|
344 | (1) |
|
|
345 | (1) |
|
|
346 | (3) |
|
Processing Instructions and the Data Model |
|
|
346 | (1) |
|
Querying Processing Instructions |
|
|
347 | (1) |
|
Processing Instructions and Sequence Types |
|
|
347 | (1) |
|
Constructing Processing Instructions |
|
|
348 | (1) |
|
|
349 | (2) |
|
Document Nodes and the Data Model |
|
|
349 | (1) |
|
Document Nodes and Sequence Types |
|
|
350 | (1) |
|
Constructing Document Nodes |
|
|
350 | (1) |
|
|
351 | (4) |
|
Text Nodes and the Data Model |
|
|
351 | (1) |
|
|
352 | (1) |
|
Text Nodes and Sequence Types |
|
|
353 | (1) |
|
Why Work with Text Nodes? |
|
|
353 | (2) |
|
|
355 | (1) |
|
XML Entity and Character References |
|
|
355 | (2) |
|
|
357 | (2) |
23 Function Items and Higher-Order Functions |
|
359 | (10) |
|
Why Higher-Order Functions? |
|
|
359 | (1) |
|
Constructing Functions and Calling Them Dynamically |
|
|
360 | (4) |
|
Named Function References |
|
|
360 | (1) |
|
Using function- lookup to Obtain a Function |
|
|
361 | (1) |
|
Inline Function Expressions |
|
|
361 | (1) |
|
Partial Function Application |
|
|
362 | (1) |
|
The Arrow Operator and Dynamic Function Calls |
|
|
363 | (1) |
|
|
363 | (1) |
|
Functions and Sequence Types |
|
|
364 | (1) |
|
|
364 | (5) |
|
Built-In Higher-Order Functions |
|
|
365 | (1) |
|
Writing Your Own Higher-Order Functions |
|
|
366 | (3) |
24 Maps, Arrays, and JSON |
|
369 | (22) |
|
|
369 | (9) |
|
|
369 | (2) |
|
|
371 | (4) |
|
|
375 | (1) |
|
|
375 | (1) |
|
Iterating over Entries in a Map |
|
|
376 | (1) |
|
|
376 | (2) |
|
|
378 | (7) |
|
|
378 | (1) |
|
|
379 | (1) |
|
|
380 | (1) |
|
|
380 | (2) |
|
|
382 | (1) |
|
|
383 | (1) |
|
Arrays and Sequence Types |
|
|
384 | (1) |
|
|
385 | (6) |
|
|
385 | (1) |
|
|
386 | (1) |
|
Converting Between JSON and XML |
|
|
387 | (4) |
25 Implementation-Specific Features |
|
391 | (8) |
|
|
391 | (1) |
|
|
392 | (2) |
|
New Features in XQuery 3.0 |
|
|
392 | (1) |
|
New Features in XQuery 3.1 |
|
|
393 | (1) |
|
Setting the Query Context |
|
|
394 | (1) |
|
|
395 | (1) |
|
|
396 | (1) |
|
|
397 | (2) |
26 XQuery for SQL Users |
|
399 | (14) |
|
Relational Versus XML Data Models |
|
|
399 | (2) |
|
Comparing SQL Syntax with XQuery Syntax |
|
|
401 | (7) |
|
|
401 | (1) |
|
|
402 | (2) |
|
|
404 | (1) |
|
Selecting Distinct Values |
|
|
405 | (1) |
|
Working with Multiple Tables and Subqueries |
|
|
406 | (2) |
|
|
408 | (1) |
|
|
408 | (3) |
|
Combining Structured and Semi-Structured Data |
|
|
409 | (1) |
|
|
409 | (2) |
|
|
411 | (2) |
27 XQuery for XSLT Users |
|
413 | (12) |
|
|
413 | (1) |
|
|
413 | (7) |
|
|
414 | (1) |
|
|
414 | (1) |
|
|
415 | (5) |
|
Using XQuery and XSLT Together |
|
|
420 | (1) |
|
XQuery Backward Compatibility with XPath 1.0 |
|
|
421 | (4) |
|
|
421 | (1) |
|
|
422 | (1) |
|
|
422 | (1) |
|
Function Conversion Rules |
|
|
423 | (1) |
|
Arithmetic and Comparison Expressions |
|
|
423 | (1) |
|
|
424 | (1) |
28 Additional XQuery-Related Standards |
|
425 | (10) |
|
|
425 | (1) |
|
|
426 | (2) |
|
|
428 | (2) |
|
|
430 | (2) |
|
XQuery API for Java (XQJ) |
|
|
432 | (3) |
A Built-in Function Reference |
|
435 | (200) |
B Built-in Types |
|
635 | (32) |
C Error Summary |
|
667 | (38) |
Index |
|
705 | |