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

Michael Kay mhk at mhk.me.uk
Tue Jul 20 10:30:56 PDT 2004


Atomic values and nodes carry a type label, and it is the type label of the
supplied value that is tested against the required type, not the actual
value that is passed. The type label of "5" is xs:integer, which is not a
subtype of xs:positiveInteger, so the test fails.

It's not that different from Java, where you aren't allowed to pass a long
to a function that expects an int, even if the long is within the allowed
range for an int.

I do agree that the result is rather surprising, but it is correct.

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
> 



More information about the talk mailing list