RE: document is not an element, is it?

At 05:35 PM 3/10/2003 -0500, Todd A. Mancini wrote:
> >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.
>
>Just to keep everything clear, and I cannot speak for GALAX, but isn't
>'node*' the return type of the document() function, not the 'document'
>type?  The 'document' type results from computed document constructors,
>not calls to the document() function.

But the document node is also the root of every document, presumably also 
of PARTLIST.XML.

>Furthermore, would it not be a static type error to rewrite the function
>so that the argument type is 'item' rather than 'element', as was
>suggested?  'node*' is not a subtype of 'item' (but 'item*' would be
>valid, as would, of course, 'node*', which is what I would recommend for
>the argument type).

I wasn't thinking of the static type - I agree that node* is best.

Jonathan 

Received on Monday, 10 March 2003 17:48:23 UTC