XQuery
Priscilla Walmsley (pwalmsley@datypic.com)
ISBN: 0596006349
1st edition, , O'Reilly Media, Inc.
Chapter 14: Static typing
typeswitch ($myProduct) case element(*,prod:HatType) return xs:string($myProduct/size) case element(*,prod:ShirtType) return xs:string(concat($myProduct/size/@system, ": ", $myProduct/size)) case element(*,prod:UmbrellaType) return "none" default return "n/a"
typeswitch ($myProduct) case $h as element(*,prod:HatType) return xs:string($h/size) case $s as element(*,prod:ShirtType) return xs:string(concat($s/size/@system, ": ", $s/size)) case element(*,prod:UmbrellaType) return "none" default return "n/a"
if ($myProduct instance of element(*,prod:HatType)) then xs:string($myProduct/size) else if ($myProduct instance of element(*,prod:ShirtType)) then xs:string(concat($myProduct/size/@system, ": ", $myProduct/size)) else if ($myProduct instance of element(*,prod:UmbrellaType)) then "none" else "n/a"
if ($myProduct instance of element(*,prod:HatType)) then <p>The size is: {data($myProduct/size)}</p> else ()
if ($myProduct instance of element(*,prod:HatType)) then <p>The size is: {data(($myProduct treat as element(*,prod:HatType))/size)}</p> else ()
for $prod as element(*,ProductType) in doc("catalog.xml")/catalog/* order by $prod/name return $prod/name
every $number as element(*,xs:integer) in doc("catalog.xml")//number satisfies ($number > 0)