XQuery
Priscilla Walmsley (pwalmsley@datypic.com)
ISBN: 0596006349
1st edition, , O'Reilly Media, Inc.
Chapter 3: Expressions: XQuery building blocks
Example | Value |
---|---|
doc("catalog.xml")/catalog/product[2]/name = 'Floppy Sun Hat'
|
true
|
doc("catalog.xml")/catalog/product[4]/number < 500
|
false
|
1 > 2
|
false
|
() = (1, 2)
|
false
|
(2, 5) > (1, 3)
|
true
|
(1, "a") = (2, "b")
| Type error |
Example | Value |
---|---|
3 gt 4
|
false
|
"abc" lt "def"
|
true
|
doc("catalog.xml")/catalog/product[4]/number lt 500
| Type error, if number is untyped or nonnumeric |
<a>3</a> gt <z>2</z>
|
true
|
<a>03</a> gt <z>2</z>
| false , since a and z are untyped and treated like strings |
(1, 2) eq (1, 2)
| Type error |
declare namespace functx = "http://www.functx.com"; declare function functx:between-inclusive ($value as xs:anyAtomicType, $minValue as xs:anyAtomicType, $maxValue as xs:anyAtomicType) as xs:boolean { $value >= $minValue and $value <= $maxValue }; (: Example call :) let $prod := doc("catalog.xml")//product[1] return functx:between-inclusive ($prod/number, 1, 500)
Example | Value |
---|---|
$n1 is $n2
|
false
|
$n1 is $n1
|
true
|
doc("catalog.xml")/catalog/product[1] is doc("catalog.xml")//product[number = 557]
|
true
|
doc("catalog.xml")/catalog/product[2]/@dept is doc("catalog.xml")/catalog/product[3]/@dept
|
false
|
for $prod in (doc("catalog.xml")/catalog/product) return if ($prod/@dept = 'ACC') then <accessoryNum>{data($prod/number)}</accessoryNum> else <otherNum>{data($prod/number)}</otherNum>
for $prod in (doc("catalog.xml")/catalog/product) return if ($prod/@dept = 'ACC') then (<accessoryNum>{data($prod/number)}</accessoryNum>, <accessoryName>{data($prod/name)}</accessoryName>) else <otherNum>{data($prod/number)}</otherNum>
for $prod in (doc("catalog.xml")/catalog/product) return if ($prod/@dept = 'ACC') then <accessory>{data($prod/number)}</accessory> else if ($prod/@dept = 'WMN') then <womens>{data($prod/number)}</womens> else if ($prod/@dept = 'MEN') then <mens>{data($prod/number)}</mens> else <other>{data($prod/number)}</other>
Example | Return value |
---|---|
not(true())
|
false
|
not($numItems > 0)
| false if $numItems > 0 |
not(doc("catalog.xml")/catalog/ product)
| false if there is at least one product child of catalog in catalog.xml |
not(())
|
true
|
not("")
|
true
|