[xquery-talk] XQuery treatment of xs:positiveInteger?

David Sewell dsewell at virginia.edu
Tue Jul 20 10:42:17 PDT 2004


Thanks to Peter, Till, and Michael for the explanation! So a fix to that
sample code would entail (at least)

  my:simple-add( 2 cast as xs:positiveInteger, 3 cast as xs:positiveInteger)

Cumbersome, but at least I understand now what would be required to use
a derived integer data type in a function to constrain input values.
Looks like it's easier to use xs:integer with an explicit check on
values instead.

David

> Michael Kay
>
> > -----Original Message-----
> > From: talk-bounces at xquery.com
> > [mailto:talk-bounces at xquery.com] On Behalf Of David Sewell
> > Sent: 20 July 2004 04:31
> > To: talk at xquery.com
> > Subject: [xquery-talk] XQuery treatment of xs:positiveInteger?
> >
> > Given the following XQuery code:
> >
> >   declare namespace my = "uri:foo";
> >
> >   declare function my:simple-add($x as xs:positiveInteger,
> >                                  $y as xs:positiveInteger) as
> > xs:positiveInteger
> >       { $x + $y };
> >
> >   my:simple-add(2, 3)
> >
> > Shouldn't this happily produce '5' for output, as it would if the data
> > types were all xs:integer?
> >
> > I get complaints about argument type when I run this on three
> > different
> > XQuery processors. For example, Saxon 8:
> >
> > "Required type of first argument of my:simple-add()
> >   is xs:positiveInteger; supplied value has type xs:integer"
> >
> > How can '2' not be interpreted as xs:positiveInteger?  (Adding a "+"
> > before the arguments doesn't make a difference.)
> >
> > Am I missing something totally obvious about use of derived
> > data types,
> > or is this a parser bug?
> >
> > David
> >
> > --
> > David Sewell, Editorial and Technical Manager
> > Electronic Imprint, The University of Virginia Press
> > PO Box 400318, Charlottesville, VA 22904-4318 USA
> > Courier: 310 Old Ivy Way, Suite 302, Charlottesville VA 22903
> > Email: dsewell at virginia.edu   Tel: +1 434 924 9973
> >
> > _______________________________________________
> > talk at xquery.com
> > http://xquery.com/mailman/listinfo/talk
> >
>
>

-- 
David Sewell, Editorial and Technical Manager
Electronic Imprint, The University of Virginia Press
PO Box 400318, Charlottesville, VA 22904-4318 USA
Courier: 310 Old Ivy Way, Suite 302, Charlottesville VA 22903
Email: dsewell at virginia.edu   Tel: +1 434 924 9973
Web: http://www.ei.virginia.edu/


More information about the talk mailing list