[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: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Sun, 11 May 2003 14:41:33 +0100
c integer to string
Hi Dimitre,

> With Saxon 7.5 I'm getting an error on the following:
>
>      <xsl:value-of select="concat(position(), '. ', ., '&#xA;')"/>
>
> "Type error in first argument of call to concat():
>   Required type is xs:string; supplied value has type xs:integer"
>
> 1. Why doesn't the XSLT processor perform an implicit cast from
> integer to string? This is quite natural, as any atomic type has a
> string representation and can be converted to string.

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.

> 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.

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.