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

document is not an element, is it?

From: MW <onlymails@gmx.net>
Date: Sun, 09 Mar 2003 18:04:24 +0100
Message-ID: <3E6B7418.8060107@gmx.net>
To: Jonathan Robie <jonathan.robie@datadirect-technologies.com>, public-qt-comments@w3.org

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".
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"))

I hope, I'm not absolutely wrong ...

with kind regards,
Michael
Received on Sunday, 9 March 2003 12:04:32 GMT

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