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

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

Subject: Re: What is the best way to cast integer to string in XSLT2?
From: "Dimitre Novatchev" <dnovatchev@xxxxxxxxx>
Date: Sun, 11 May 2003 16:59:26 +0200
c cast integer to string
Thanks a lot Jeni and Andrew,

> This is a good example of what I meant during my talk at XML Europe
> about life getting harder for XSLT users because of the strong typing
> in XPath 2.0. XPath 2.0 allows implicit casting:
>
>  1. from xdt:untypedAtomic (the type of untyped nodes) to any atomic
>     type
>
>  2. from any atomic type to its base type (up the atomic type
>     hierarchy)
>
>  3. from xs:decimal (and its subtypes) to xs:float or xs:double and
>     from xs:float to xs:double
>
> As you say, it is possible to cast values of most types into a string
> (exceptions are xs:QName and xs:NOTATION), but in terms of the type
> hierarchy used by XPath 2.0, it is not the case that every type is
> derived from xs:string. (I guess you're aware of the recent XML-Dev
> discussion on this topic.) So you have to perform the casting
> explicitly.

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. In C++ one can specify a constructor that takes
a single argument og another type, e.g.:

class complex
{
     double re, im;

  public:
     complex (double r) : re(r), im(0) {}

};

Then the programmer simply writes:

    complex a = 7;

instead of

    complex a = complex(7);


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.

>
> > 2. My current solution is to use
> >
> >   string(position())
> >
> > Is this the best/recommended solution?
>
> Yes. For atomic values like the integer returned by position(), it
> returns the same as xs:string(position()); the latter is just longer
> and requires an extra namespace declaration.


Thanks!


=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL




 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.