1

Background:

I am trying to perform a query (using XQuery 3.0) on an attribute value (attrname) that might be either an xs:string or an xs:int, lets call it $a.

If $a is able to be parsed to an xs:int then I want to compare it against an xs:int variable $v (<, <=, =, etc.). Otherwise, if it is an xs:string I want to perform a different comparison.

XML Example

<root>
  <element attrname="1">this is an xs:int</element>
  <element attrname="A">this is an xs:string</element>
</root>

Pseudo-code

IF $a IS xs:int THEN
  DO SOMETHING
ELSE IF $a IS xs:string THEN
  DO SOMETHING ELSE

My Issue:

I am not able to find a proper way of evaluating if $a is an xs:int before performing any operation.

batista
  • 181
  • 2
  • 10

1 Answers1

4

You can use if ($a castable as xs:int) then expression1 else expression2.

Martin Honnen
  • 160,499
  • 6
  • 90
  • 110