XQuery
Priscilla Walmsley (pwalmsley@datypic.com)
ISBN: 1491915103
2nd edition, , O'Reilly Media, Inc.
Chapter 10: Namespaces and XQuery
Please note that the book contains many inline examples and informal tables that are not provided here.
<cat:catalog xmlns:cat="http://datypic.com/cat" xmlns:prod="http://datypic.com/prod"> <cat:number>1446</cat:number> <prod:product> <prod:number>563</prod:number> <prod:name prod:language="en">Floppy Sun Hat</prod:name> </prod:product> </cat:catalog>
<foo:catalog xmlns:foo="http://datypic.com/cat" xmlns:bar="http://datypic.com/prod"> <foo:number>1446</foo:number> <bar:product> <bar:number>563</bar:number> <bar:name bar:language="en">Floppy Sun Hat</bar:name> </bar:product> </foo:catalog>
<product xmlns="http://datypic.com/prod" xmlns:app="http://datypic.com/app" app:id="P123" dept="ACC"> ... </product>
<catalog xmlns="http://datypic.com/cat"> <number>1446</number> <prod:product xmlns:prod="http://datypic.com/prod"> <prod:number>563</prod:number> <prod:name language="en">Floppy Sun Hat</prod:name> </prod:product> </catalog>
<catalog xmlns="http://datypic.com/cat"> <number>1446</number> <product xmlns="http://datypic.com/prod"> <number>563</number> <name language="en">Floppy Sun Hat</name> </product> </catalog>
declare namespace rep = "http://datypic.com/report"; declare namespace prod = "http://datypic.com/prod"; <rep:report> { doc("cat_ns.xml")//prod:product } </rep:report>
<rep:report xmlns:rep="http://datypic.com/report"> <prod:product xmlns="http://datypic.com/cat" xmlns:prod="http://datypic.com/prod"> <prod:number>563</prod:number> <prod:name language="en">Floppy Sun Hat</prod:name> </prod:product> </rep:report>
declare default element namespace "http://datypic.com/cat"; declare namespace rep = "http://datypic.com/report"; declare namespace prod = "http://datypic.com/prod"; <rep:report> { doc("cat_ns.xml")/catalog/prod:product } </rep:report>
declare namespace rep = "http://datypic.com/report"; declare namespace cat = "http://datypic.com/cat"; declare namespace prod2 = "http://datypic.com/prod"; <rep:report> { doc("cat_ns.xml")/cat:catalog/prod2:product } </rep:report>
<rep:report xmlns="http://datypic.com/cat" xmlns:prod="http://datypic.com/prod" xmlns:rep="http://datypic.com/report"> { doc("cat_ns.xml")/catalog/prod:product } </rep:report>
<rep:report xmlns:rep="http://datypic.com/report" xmlns:prod="http://datypic.com/prod" xmlns="http://datypic.com/cat"> <prod:product> <prod:number>563</prod:number> <prod:name language="en">Floppy Sun Hat</prod:name> </prod:product> </rep:report>
xquery version "3.0"; declare namespace rep="http://datypic.com/report"; declare default element namespace "http://datypic.com/prod"; declare namespace cat="http://datypic.com/cat"; element rep:report { namespace {""} {"http://datypic.com/cat"}, namespace prod {"http://datypic.com/prod"}, doc("cat_ns.xml")/cat:catalog/product }
<report xmlns="http://datypic.com/report"> <firstChild/> {doc("prod_ns.xml")/*} </report>
<report xmlns="http://datypic.com/report"> <firstChild/> <prod:product xmlns:prod="http://datypic.com/prod"> <prod:number>563</prod:number> <prod:name language="en">Floppy Sun Hat</prod:name> </prod:product> </report>
<prod:product xmlns:prod="http://datypic.com/prod"> <prod:number>563</prod:number> <prod:name language="en">Floppy Sun Hat</prod:name> </prod:product>
<report xmlns="http://datypic.com/report" xmlns:cat="http://datypic.com/cat" xmlns:prod="http://datypic.com/prod"> { for $prod in doc("prod_ns.xml")/prod:product return <lineItem> {$prod/prod:number} {$prod/prod:name} </lineItem> } </report>
<report xmlns:prod="http://datypic.com/prod" xmlns:cat="http://datypic.com/cat" xmlns="http://datypic.com/report"> <lineItem> <prod:number>563</prod:number> <prod:name language="en">Floppy Sun Hat</prod:name> </lineItem> </report>
declare default element namespace "http://datypic.com/report"; declare namespace cat = "http://datypic.com/cat"; declare namespace prod = "http://datypic.com/prod"; <report> { for $prod in doc("prod_ns.xml")/prod:product return <lineItem> {$prod/prod:number} {$prod/prod:name} </lineItem> } </report>
<report xmlns="http://datypic.com/report"> <lineItem> <prod:number xmlns:prod="http://datypic.com/prod"> 563</prod:number> <prod:name xmlns:prod="http://datypic.com/prod" language="en">Floppy Sun Hat</prod:name> </lineItem> </report>
declare namespace cat = "http://datypic.com/cat"; <report xmlns="http://datypic.com/report" xmlns:prod="http://datypic.com/prod"> { for $prod in doc("prod_ns.xml")/prod:product return <lineItem> {$prod/prod:number} {$prod/prod:name} </lineItem> } </report>
<report xmlns:prod="http://datypic.com/prod" xmlns="http://datypic.com/report"> <lineItem> <prod:number>563</prod:number> <prod:name language="en">Floppy Sun Hat</prod:name> </lineItem> </report>
<cat:catalog xmlns:cat="http://datypic.com/cat" xmlns:prod="http://datypic.com/prod" xmlns:ord="http://datypic.com/ord"> <prod:product> <prod:number>563</prod:number> <prod:name language="en">Floppy Sun Hat</prod:name> </prod:product> </cat:catalog>
declare copy-namespaces no-preserve, inherit; <report xmlns="http://datypic.com/report" xmlns:cat="http://datypic.com/cat" xmlns:prodnew="http://datypic.com/prod"> { doc("cat_ns2.xml")//prodnew:product } </report>
<report xmlns="http://datypic.com/report" xmlns:cat="http://datypic.com/cat" xmlns:prodnew="http://datypic.com/prod"> <prod:product xmlns:prod="http://datypic.com/prod"> <prod:number>563</prod:number> <prod:name language="en">Floppy Sun Hat</prod:name> </prod:product> </report>
declare copy-namespaces preserve, no-inherit; <report xmlns="http://datypic.com/report" xmlns:cat="http://datypic.com/cat" xmlns:prodnew="http://datypic.com/prod"> { doc("cat_ns2.xml")//prodnew:product } </report>
<report xmlns="http://datypic.com/report" xmlns:cat="http://datypic.com/cat" xmlns:prodnew="http://datypic.com/prod"> <prod:product xmlns:prod="http://datypic.com/prod" xmlns:ord="http://datypic.com/ord" xmlns="" xmlns:prodnew=""> <prod:number>563</prod:number> <prod:name language="en">Floppy Sun Hat</prod:name> </prod:product> </report>
xquery version "3.0"; declare namespace rep = "http://datypic.com/report"; <rep:report> { doc("cat_ns.xml")//Q{http://datypic.com/prod}product } </rep:report>