XQuery
Priscilla Walmsley (pwalmsley@datypic.com)
ISBN: 1491915103
2nd edition, , O'Reilly Media, Inc.
Chapter 12: Prologs, Modules, and Variables
Please note that the book contains many inline examples and informal tables that are not provided here.
xquery version "3.0"; declare default element namespace "http://datypic.com/cat"; declare boundary-space preserve; declare namespace ord = "http://datypic.com/ord"; import schema namespace prod="http://datypic.com/prod" at "prod.xsd"; declare function local:getProdNums ($catalog as element()) as xs:integer* {for $prod in $catalog/product return xs:integer($prod/number)};
<h1>Order Report</h1>, for $item in doc("order.xml")//item order by $item/@num return $item
module namespace strings = "http://datypic.com/strings"; declare variable $strings:maxStringLength := 32; declare function strings:trim($arg as xs:string?) as xs:string? { replace(replace($arg,'^\s+',''),'\s+$','') };
module namespace strings = "http://datypic.com/strings"; declare function strings:trim($arg as xs:string?) as xs:string? { if (strings:get-norm-length($arg) < $strings:trim-length) then substring($arg, 1, $strings:trim-length) else $arg }; declare %private function strings:get-norm-length ($arg as xs:string?) as xs:integer { string-length(normalize-space($arg)) }; declare %private variable $strings:trim-length := 32;