document is not an element, is it?

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 UTC