XQuery
Priscilla Walmsley (pwalmsley@datypic.com)
ISBN: 1491915103
2nd edition, , O'Reilly Media, Inc.
Chapter 2: XQuery Foundations
Please note that the book contains many inline examples and informal tables that are not provided here.
xquery version "3.1"; declare namespace html = "http://www.w3.org/1999/xhtml"; declare variable $orderTitle := "Order Report"; <h1>{$orderTitle}</h1>, for $item in doc("order.xml")//item order by $item/@num return <p>{data($item/@num)}</p>
<h1>Order Report</h1> <p>443</p> <p>557</p> <p>557</p> <p>563</p> <p>784</p> <p>784</p>
<catalog xmlns="http://datypic.com/cat"> <product dept="MEN" xmlns="http://datypic.com/prod"> <number>784</number> <name language="en">Cotton Dress Shirt</name> <colorChoices>white gray</colorChoices> <desc>Our <i>favorite</i> shirt!</desc> </product> </catalog>
<prod:product xmlns:prod="http://datypic.com/prod"> <prod:number>563</prod:number> <prod:name language="en">Floppy Sun Hat</prod:name> </prod:product>
declare namespace prod = "http://datypic.com/prod"; for $prod in doc("prod_ns.xml")/prod:product return $prod/prod:name
<prod:name xmlns:prod="http://datypic.com/prod" language="en">Floppy Sun Hat</prod:name>