W3C home > Mailing lists > Public > public-qt-comments@w3.org > March 2003

Re: document is not an element, is it?

From: Jonathan Robie <jonathan.robie@datadirect-technologies.com>
Date: Mon, 10 Mar 2003 10:57:41 -0500
Message-Id: <5.2.0.9.0.20030310105500.01251e70@ncmail.datadirect-technologies.com>
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 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Tuesday, 27 March 2012 18:14:24 GMT