OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

 


 

   RE: [xml-dev] XPath 1.5? (was RE: [xml-dev] typing and markup)

[ Lists Home | Date Index | Thread Index ]

At 12:52 PM -0700 5/7/02, Jonathan Robie wrote:


>One use case is the Use Case R, which is currently too complex 
>precisely because it lacks a schema, which forces us to use casts to 
>get some things to come out right. Here are some examples:
>
>1.4.4.2 Q2 - as is:
>
><result>
>   {
>     for $i in document("items.xml")//item_tuple
>     let $b := document("bids.xml")//bid_tuple[itemno = $i/itemno]
>     where contains($i/description, "Bicycle")
>     return
>         <item_tuple>
>             { $i/itemno }
>             { $i/description }
>             <high_bid>{ max(for $z in $b/bid return decimal($z)) }</high_bid>
>         </item_tuple>
>     sortby(itemno)
>   }
></result>
>
>Without the cast, max() would sort according to the string value, 
>not the decimal value.

I would propose more simply that max() and similar functions always 
treat their arguments as numbers. I personally have never heard of a 
max() function that operates on strings anyway. Even if you tried to 
define it as the last in sort-order or some such, it really depends 
on the sort order, so you need an additional argument, not that this 
is a natural thing to do in the first place.

I suppose you might have a more logical max on date and time types, 
but again it's not common. I propose instead a latest() and 
earliest() which would always treat their arguments as dates. This 
seems much more natural to me than either of the solutions you 
propose.

Similarly, the avg() function should convert all nodes passed to it 
to numbers, as if by the XPath 1.0 number() function.

>You can pick through the whole Use Case R and see many examples like 
>this. Every single cast is superfluous in these use cases, present 
>only because there is no schema.
>

I skimmed them. Nothing jumped out at me that couldn't be handled by 
my proposal, but maybe I missed something. In brief, I suggest if you 
pass something to a function that expects a number, it's converted to 
a number. If you pass something to a function that expects a date, 
it's converted to a date. No muss, no fuss. What am I missing?

>There are two reasons I don't like these casts. One is that it is 
>tedious. The other is that when I cast, I tell the static type 
>system that I think I'm smarter than it is, and it will simply 
>believe me that $z is a decimal. If I'm wrong, this may result in an 
>error which I will not encounter until run time.
>

Casting presumes types. If we eliminate static typing from the 
language casting is no longer needed, just like in XSLT 1.0 where all 
the conversions are automatic.
-- 

+-----------------------+------------------------+-------------------+
| Elliotte Rusty Harold | elharo@metalab.unc.edu | Writer/Programmer |
+-----------------------+------------------------+-------------------+
|          The XML Bible, 2nd Edition (Hungry Minds, 2001)           |
|             http://www.cafeconleche.org/books/bible2/              |
|   http://www.amazon.com/exec/obidos/ISBN=0764547607/cafeaulaitA/   |
+----------------------------------+---------------------------------+
|  Read Cafe au Lait for Java News:  http://www.cafeaulait.org/      |
|  Read Cafe con Leche for XML News: http://www.cafeconleche.org/    |
+----------------------------------+---------------------------------+




 

News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 2001 XML.org. This site is hosted by OASIS