RE: [F&O] CER-07 exactly-one et al

The problem with these functions is that they loose the static type (it
becomes item()). If I have a instance of type xs:integer* that I want to
apply exactly-one() to, you need to treat it as xs:integer. Since you
would have to write a function/treat as expression for any single type
you may come across, it is easier to have a built-in function.

Best regards
Michael

> -----Original Message-----
> From: public-qt-comments-request@w3.org [mailto:public-qt-comments-
> request@w3.org] On Behalf Of Michael Brundage
> Sent: Tuesday, February 17, 2004 11:01 AM
> To: Mary Holstege; XQuery Public Comments
> Subject: Re: [F&O] CER-07 exactly-one et al
> 
> 
> Those functions type-check their arguments but don't change the static
> type
> of the expression.
> 
> I think you want:
> 
> define function exactly-one ( $items as item()* ) as item() {
>    $items treat as item()
> }
> 
> define function one-or-more ( $items as item()* ) as item()? {
>    $items treat as item()?
> }
> 
> define function zero-or-more ( $items as item()* ) as item()* {
>    $items treat as item()*
> }
> 
> which should take any sequence of items, change their cardinality
> statically, and error dynamically if the cardinality change is not
valid.
> 
> 
> Cheers,
> 
> Michael Brundage
> xquery@comcast.net
> 
> Writing as
> Author, XQuery: The XML Query Language (Addison-Wesley, 2004)
> Co-author, Professional XML Databases (Wrox Press, 2000)
> 
> not as
> Technical Lead
> Common Query Runtime/XML Query Processing
> WebData XML Team
> Microsoft
> 
> 
> On 2/17/04 10:16 AM, "Mary Holstege" <mary@cerisent.com> wrote:
> >> How can a user write a function that statically reduces the type
and
> >> raises an error if the dynamic cardinality is too big?
> >> Best regards
> >> Michael
> >
> > Perhaps I'm missing something, but I don't see why these don't do
the
> > trick.
> > The rules for sequence type matching allow you to report this either
> > statically
> > or dynamically:
> >
> >
> > define function exactly-one ( $items as item() ) as item()*
> > {
> >  $items
> > }
> >
> > define function one-or-more ( $items as item()+ ) as item()*
> > {
> >  $items
> > }
> >
> > define function zero-or-more ( $items as item()* ) as item()*
> > {
> >  $items
> > }
> >
> > //Mary
> >

Received on Tuesday, 17 February 2004 16:57:08 UTC