xsl-list
[Top] [All Lists]

Re: number collapsing

2004-12-14 07:28:52

  <xsl:when test="$begin castable as 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, not quite, you are saying "if it looks like an integer" then....
Unkfortnately Xpath2 does not automatically cast between types anything
like as often as Xpath1 does, so if you have the string "123" then the
test is true as the string is _castable_ to an integer,
xs:integer("123") is the integer 123, not an error, but that cast
doesn't happen automatically:
"123" + 1 is an error (in Xpath 1 it would be 124)
you need to do
xs:integer("123") + 1 to get 124
similarly given

  <xsl:when test="$begin castable as xs:integer">

all you know is that xs:integer($begin) will give an integer not an
error, but you don't know that you can use $begin in integer operations:
 $begin + 1
is an error if $begin is "123"

That's why Mike suggested adding an explict cast.

David

________________________________________________________________________
This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



<Prev in Thread] Current Thread [Next in Thread>