Hi,
That would base the type annotation on the lexical value. For
instance, the string '0' would be labelled as "integer" (given you
test for xs:integer before xs:string):
let $var := '0'
return
if ( $var castable as xs:integer )
then 'integer'
else if ( $var castable as xs:string )
then 'string'
else
'unknown type'
(: -> 'integer' :)
The operator "instance of" would solve that problem. But then, for
that purpose, there is the "typeswitch" instruction:
typeswitch ( '0' )
case xs:integer return
'integer'
case xs:string return
'string'
default return
'unknown type'
(: -> 'string' :)
Regards,
--
Florent Georges
http://fgeorges.org/
http://h2oconsulting.be/
On 29 July 2015 at 17:34, Eliot Kimber
ekimber@contrext.com wrote:
> I believe you need to use the "castable as" or "instance of" operators to
> determine the type, e.g.:
>
> let $typeName :=
> if ($somevar castable as xs:integer)
> then 'integer'
> else if ($somevar castable as xs:string)
> then 'string'
> else 'unknown type'
>
> Or something close to that. There is also "instance of", which might be
>
> I also found this paper, which might be interesting:
>
>
http://www.balisage.net/Proceedings/vol8/html/Holstege01/BalisageVol8-Holst
> ege01.html
>
> Cheers,
>
> E.
> ----
> Eliot Kimber, Owner
> Contrext, LLC
>
http://contrext.com
>
>
>
>
> On 7/29/15, 9:54 AM, "Rob Stapper"
> <basex-talk-bounces@mailman.uni-konstanz.de on behalf of
> r.stapper@lijbrandt.nl> wrote:
>
>>Hello,
>>
>>I must be overlooking something, so excuses in advance, but: How can I
>>retrieve the datatype of a variable?
>>
>>TIA,
>>Rob Stapper
>>
>>
>>
>>________________________________________
>>
>>
>>
>>
>>
https://www.avast.com/antivirus
>>
>>
>>
>> Dit e-mailbericht is gecontroleerd op virussen met Avast
>>antivirussoftware.
>>
>>www.avast.com
https://www.avast.com/antivirus
>>
>>
>>
>
>