[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Re: What is the best way to cast integer to string

Subject: Re: Re: What is the best way to cast integer to string in XSLT2?
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Sun, 11 May 2003 22:09:00 +0100
cast double to string
Hi Dimitre,

> Do any examples exist when such implicit casting would be
> dangerous/counter-intuitive? If not, then it would be very useful to
> allow implicit casting to string.

I agree, but then I think that it would be useful to allow implicit
casting to a required type, whatever it is, if such a cast is
permitted. Those that support strong typing in XPath 2.0, on the other
hand, believe that it's useful to be told that you can't use an
integer where a string is expected.

There are lots of cases where there *is* implicit casting (of
xdt:untypedAtomic values) in XPath 2.0 and that casting is
counter-intuitive (to XPath 1.0 users). For example:

  @height > @weight

casts both attributes to strings and compares them lexicographically,
rather than doing a numeric comparison as in XPath 1.0, while:

  current-dateTime() + @delay

(where @delay is "PT30M", for example) will give you a type error
because the delay attribute is cast to an xs:double (even though you
can't actually add an xs:double to an xs:dateTime) and "PT30M" isn't a
valid double value.

Similarly:

  24 idiv (@indent + 3)

will give you a type error because the indent attribute is cast to an
xs:double, which means the result of (@indent + 3) is an xs:double,
which isn't a valid type for an operand to idiv.

Which I guess goes to show that implicit casting coupled with
polymorphic operators will always give some weird results.

> In cases like the current one I think such "conversion constructors"
> should be specified in the XPath data model. This makes writing and
> understanding a program much more easier.

The rules for casting between types are specified in the XPath/XQuery
Functions & Operators document (http://www.w3.org/TR/xpath-functions).
As I said above, personally I don't see why these rules can't be used
for implicit casting, but this seems to go against the strong typing
ethos of XPath 2.0.

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.