- From: Jonathan Robie <jonathan.robie@datadirect-technologies.com>
- Date: Mon, 10 Mar 2003 10:57:41 -0500
- To: MW <onlymails@gmx.net>, public-qt-comments@w3.org
At 06:04 PM 3/9/2003 +0100, MW wrote: >Hi Jonathan! > >In the working draft "XQuery 1.0: An XML Query Language" in chapter "4.5 >Function Definitions" there is this example: >define function depth($e as element) as xs:integer >{ > {-- An empty element has depth 1 --} > {-- Otherwise, add 1 to max depth of children --} > if (empty($e/*)) then 1 > else max(for $c in $e/* return depth($c)) + 1 >} >depth(document("partlist.xml")) > >But this function does not run in GALAX. And I think it is obvious that >the function must not work, because the funktion-parameter is declared >as "element", but it is called with a parameter of type "document". I >think the declaration must be changed from "element" to "item". Right, that's a bug in the spec. >The next problem is the return value. The function only works properly if >I explicitly construct (or cast as) xs:integer before returning the result. >I've written a function which returns the correct result in GALAX: >define function depth($item as item) as xs:integer >{ > {-- An empty element has depth 1 --} > {-- Otherwise, add 1 to max depth of children --} > if (empty($item/*)) then xs:integer(1) > else xs:integer(max(for $sub in $item/* return depth($sub)) + 1) >} >depth(document("partlist.xml")) That's a bug in GALAX, I think. The literal 1 is an integer, and integers in XQuery are of type xs:integer. See section 3.1.1, Literals. Jonathan
Received on Monday, 10 March 2003 10:57:50 UTC