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

RE: number collapsing

Subject: RE: number collapsing
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Tue, 14 Dec 2004 15:07:10 -0000
xsl cast
> >>        <xsl:when test="$begin castable as xs:integer">
> >>          <xsl:variable name="begin2" select="$begin" 
> as="xs:integer"/>
> >
> > This may fail if $begin is a string. The string "123" is castable to
> > xs:integer, but not assignable to xs:integer.
> 
> I'm not following here.  Aren't I saying in the function "if 
> $begin is 
> an integer, then apply this logic to determine how to shorten 
> $end; if 
> not, then just print $end as is"?

No, you are saying "if $begin is capable of being cast to an integer, then
assign it to an integer, and then...". But the fact that $beging is capable
of being cast to an integer does not mean it is capable of being assigned to
an integer; having established that the cast is possible you must then do
the cast. The logic for "castable" is always


if (A castable as B)
  then f(A cast as B)
  else ...

Specifically, if $begin is a string in the form "123" then the "castable as"
test will succeed, but the assignment will fail. Assignment does not do an
implicit cast. (However, if $begin is untypedAtomic, then your logic works
correctly, because untypedAtomic is a "weak" type that is automatically
converted to the required type when necessary). 

Michael Kay
http://www.saxonica.com/

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.